Author Topic: Build Code::Blocks with Clang  (Read 7912 times)

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Build Code::Blocks with Clang
« on: December 10, 2012, 10:43:58 pm »
I tested building Code::Blocks with Clang, and this was required to get it to compile:
Code
Index: src/plugins/contrib/lib_finder/librariesdlg.cpp
===================================================================
--- src/plugins/contrib/lib_finder/librariesdlg.cpp (revision 8648)
+++ src/plugins/contrib/lib_finder/librariesdlg.cpp (working copy)
@@ -90,10 +90,11 @@
 
 LibrariesDlg::LibrariesDlg(wxWindow* parent, TypedResults& knownLibraries)
     : m_KnownLibraries(knownLibraries)
-    , m_WorkingCopy(knownLibraries)
     , m_SelectedConfig(0)
     , m_WhileUpdating(false)
 {
+    for (int i = 0; i < rtCount; ++i)
+        m_WorkingCopy[i] = knownLibraries[i];
     //(*Initialize(LibrariesDlg)
     wxBoxSizer* BoxSizer4;
     wxStaticBoxSizer* StaticBoxSizer2;
Index: src/plugins/contrib/profiler/cbprofiler.cpp
===================================================================
--- src/plugins/contrib/profiler/cbprofiler.cpp (revision 8648)
+++ src/plugins/contrib/profiler/cbprofiler.cpp (working copy)
@@ -101,18 +101,18 @@
     if (project->GetBuildTargetsCount() > 1)
     {
         // more than one executable target? ask...
-        wxString choices[project->GetBuildTargetsCount()];
+        wxArrayString choices;
         wxString active_target = project->GetActiveBuildTarget();
         int selected = 0;
         for (int i=0; i<project->GetBuildTargetsCount(); ++i)
         {
-            choices[i] = project->GetBuildTarget(i)->GetTitle();
+            choices.Add(project->GetBuildTarget(i)->GetTitle());
             if (choices[i] == active_target)
                 selected = i;
         }
         wxSingleChoiceDialog dialog(Manager::Get()->GetAppWindow(),
                                     _("Select the target you want to profile"),
-                                    _("Select Target"),project->GetBuildTargetsCount(),choices);
+                                    _("Select Target"), choices);
         dialog.SetSelection(selected);
         if (dialog.ShowModal() != wxID_OK)
             return -1;
Index: src/sdk/wxscintilla/src/PlatWX.cpp
===================================================================
--- src/sdk/wxscintilla/src/PlatWX.cpp (revision 8648)
+++ src/sdk/wxscintilla/src/PlatWX.cpp (working copy)
@@ -301,10 +301,11 @@
 /* C::B begin */
     // Since Point now has float as x and y, it seems no longer to be interchangeable with wxPoint,
     // and the polygon is not drawn, so we convert it explicitely
-    wxPoint points[npts];
+    wxPoint* points = new wxPoint[npts];
     for (int i = 0; i < npts; ++i)
         points[i] = wxPoint(pts[i].x, pts[i].y);
     hDC->DrawPolygon(npts, points);
+    delete [] points;
 /* C::B end */
 }

These changes are from my inspection of Clang's warnings:
Code
Index: src/plugins/contrib/dragscroll/dragscrollcfg.cpp
===================================================================
--- src/plugins/contrib/dragscroll/dragscrollcfg.cpp (revision 8648)
+++ src/plugins/contrib/dragscroll/dragscrollcfg.cpp (working copy)
@@ -93,15 +93,13 @@
 
  Sensitivity = new wxSlider( this, wxID_ANY, 8, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_AUTOTICKS|wxSL_HORIZONTAL|wxSL_LABELS|wxSL_TOP );
 #if wxCHECK_VERSION(2,9,0)
- if ( 1 ) Sensitivity->SetTickFreq(1);
+ Sensitivity->SetTickFreq(1);
 #else
- if ( 1 ) Sensitivity->SetTickFreq(1,0);
+ Sensitivity->SetTickFreq(1,0);
 #endif
- if ( 1 ) Sensitivity->SetPageSize(1);
- if ( 0 ) Sensitivity->SetLineSize(0);
- if ( 0 ) Sensitivity->SetThumbLength(0);
- if ( 1 ) Sensitivity->SetTick(1);
- if ( 1 ) Sensitivity->SetSelection(1,10);
+ Sensitivity->SetPageSize(1);
+ Sensitivity->SetTick(1);
+ Sensitivity->SetSelection(1,10);
  bSizer7->Add( Sensitivity, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 5 );
 
  bSizer7->Add( 0, 0, 1, wxEXPAND, 0 );
@@ -111,15 +109,13 @@
 
  MouseToLineRatio = new wxSlider( this, wxID_ANY, 30, 10, 100, wxDefaultPosition, wxDefaultSize, wxSL_AUTOTICKS|wxSL_HORIZONTAL|wxSL_LABELS|wxSL_TOP );
 #if wxCHECK_VERSION(2,9,0)
- if ( 1 ) MouseToLineRatio->SetTickFreq(10);
+ MouseToLineRatio->SetTickFreq(10);
 #else
- if ( 1 ) MouseToLineRatio->SetTickFreq(10,10);
+ MouseToLineRatio->SetTickFreq(10,10);
 #endif
- if ( 1 ) MouseToLineRatio->SetPageSize(10);
- if ( 0 ) MouseToLineRatio->SetLineSize(0);
- if ( 0 ) MouseToLineRatio->SetThumbLength(0);
- if ( 1 ) MouseToLineRatio->SetTick(10);
- if ( 1 ) MouseToLineRatio->SetSelection(10,100);
+ MouseToLineRatio->SetPageSize(10);
+ MouseToLineRatio->SetTick(10);
+ MouseToLineRatio->SetSelection(10,100);
  bSizer7->Add( MouseToLineRatio, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 5 );
 
  bSizer7->Add( 0, 0, 1, wxEXPAND, 0 );
@@ -130,15 +126,15 @@
  MouseContextDelay = new wxSlider( this, wxID_ANY, 50, 10, 500, wxDefaultPosition, wxDefaultSize, wxSL_AUTOTICKS|wxSL_HORIZONTAL|wxSL_LABELS|wxSL_TOP );
  // Above values are: default mil delay, min, max
 #if wxCHECK_VERSION(2,9,0)
- if ( 1 ) MouseContextDelay->SetTickFreq(10);
+ MouseContextDelay->SetTickFreq(10);
 #else
- if ( 1 ) MouseContextDelay->SetTickFreq(10,10);
+ MouseContextDelay->SetTickFreq(10,10);
 #endif
- if ( 1 ) MouseContextDelay->SetPageSize(10);
- if ( 1 ) MouseContextDelay->SetLineSize(10);
- if ( 1 ) MouseContextDelay->SetThumbLength(10);
- if ( 1 ) MouseContextDelay->SetTick(100);
- if ( 1 ) MouseContextDelay->SetSelection(10,500);
+ MouseContextDelay->SetPageSize(10);
+ MouseContextDelay->SetLineSize(10);
+ MouseContextDelay->SetThumbLength(10);
+ MouseContextDelay->SetTick(100);
+ MouseContextDelay->SetSelection(10,500);
  bSizer7->Add( MouseContextDelay, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 5 );
 
  bSizer7->Add( 0, 0, 1, wxEXPAND, 0 );
Index: src/plugins/contrib/codesnippets/FileImport.h
===================================================================
--- src/plugins/contrib/codesnippets/FileImport.h (revision 8648)
+++ src/plugins/contrib/codesnippets/FileImport.h (working copy)
@@ -43,7 +43,7 @@
         // ::wxCopyFile (filename, (destDir + dirname - rootSrcDir))
         //wxPrintf(_T("OnFile[%s] to [%s]\n"), filename.c_str(), ConvertToDestinationPath(filename).c_str());
         int rc = ::wxCopyFile (filename, ConvertToDestinationPath (filename));
-        if (not rc) ; //wxPrintf(_T("Copy failed for[%s]"), filename.c_str());
+        // if (not rc) wxPrintf(_T("Copy failed for[%s]"), filename.c_str());
         return wxDIR_CONTINUE;
     }
 
Index: src/plugins/contrib/ToolsPlus/se_globals.cpp
===================================================================
--- src/plugins/contrib/ToolsPlus/se_globals.cpp (revision 8648)
+++ src/plugins/contrib/ToolsPlus/se_globals.cpp (working copy)
@@ -1,15 +1,15 @@
 #include "se_globals.h"
 
-wxString GetParentDir(const wxString &path)
+/*wxString GetParentDir(const wxString& path)
 {
-    wxString parent=wxFileName(parent).GetPath(0);
+    wxString parent=wxFileName(path).GetPath(0);
     if(path==parent||parent.IsEmpty())
         return wxEmptyString;
     else
         return parent;
 }
 
-bool DirIsChildOf(const wxString &path, const wxString &/*child*/)
+bool DirIsChildOf(const wxString& path, const wxString& child)
 {
     wxString parent=path;
     while(!parent.IsEmpty())
@@ -19,7 +19,7 @@
         parent=GetParentDir(parent);
     }
     return false;
-}
+}*/
 
 bool WildCardListMatch(wxString list, wxString name, bool strip)
 {
Index: src/plugins/contrib/ToolsPlus/se_globals.h
===================================================================
--- src/plugins/contrib/ToolsPlus/se_globals.h (revision 8648)
+++ src/plugins/contrib/ToolsPlus/se_globals.h (working copy)
@@ -10,7 +10,7 @@
 #include <sdk.h>
 #ifndef CB_PRECOMP
     #include <wx/filename.h>
-
+
     #include <editorbase.h>
     #include <editormanager.h>
     #include <logmanager.h>
@@ -20,9 +20,9 @@
     #include <cbproject.h>
 #endif
 
-wxString GetParentDir(const wxString &path);
+//wxString GetParentDir(const wxString &path);
 
-bool DirIsChildOf(const wxString &path, const wxString &child);
+//bool DirIsChildOf(const wxString &path, const wxString &child);
 
 bool WildCardListMatch(wxString list, wxString name, bool strip=true);
 
Index: src/plugins/contrib/keybinder/menuutils.cpp
===================================================================
--- src/plugins/contrib/keybinder/menuutils.cpp (revision 8648)
+++ src/plugins/contrib/keybinder/menuutils.cpp (working copy)
@@ -71,7 +71,7 @@
     return id;
 }
 
-namespace
+/*namespace
 {
 // ----------------------------------------------------------------------------
 int FindMenuDuplicateCount(wxMenuBar *p, wxString &str)
@@ -90,7 +90,7 @@
 
     return count;
 }
-}
+}*/
 // ----------------------------------------------------------------------------
 int FindMenuDuplicateItems(wxMenu* pMenu, wxString& rStr, int& rCount)
 // ----------------------------------------------------------------------------
Index: src/plugins/contrib/keybinder/menuutils.h
===================================================================
--- src/plugins/contrib/keybinder/menuutils.h (revision 8648)
+++ src/plugins/contrib/keybinder/menuutils.h (working copy)
@@ -30,7 +30,7 @@
 //int /*-lf-WXDLLIMPEXP_KEYBINDER*/ wxFindMenuItem(wxMenuBar *, const wxString &strMenuItemName);
 
 int wxFindMenuItem(wxMenuBar *, const wxString &strMenuItemName);
-int FindMenuDuplicateCount(wxMenuBar *p, const wxString &str);
+//int FindMenuDuplicateCount(wxMenuBar *p, const wxString &str);
 int FindMenuDuplicateItems(wxMenu* pMenu, wxString& rStr, int& rCount);
 wxString GetFullMenuPath(int);
 
Index: src/plugins/contrib/keybinder/keybinder.cpp
===================================================================
--- src/plugins/contrib/keybinder/keybinder.cpp (revision 8648)
+++ src/plugins/contrib/keybinder/keybinder.cpp (working copy)
@@ -2578,7 +2578,7 @@
     // This routine is screwing up unix, and its never called on MSW
     // so.. forget it //(pecan 2006/9/23)
     return ;
-
+/*
  wxString oldname = m_kBinder.GetName();
         // on unix, this routine is being entered with oldname == ""
         // We're not going to save the blank temp profile anyway
@@ -2594,7 +2594,7 @@
 
  // change the name of the current profile
  m_kBinder.SetName(newname);
-
+*/
 #if 0
  // and the string of the combobox...
  int n = m_pKeyProfiles->FindString(oldname);
Index: src/plugins/contrib/HexEditor/FileContentDisk.cpp
===================================================================
--- src/plugins/contrib/HexEditor/FileContentDisk.cpp (revision 8648)
+++ src/plugins/contrib/HexEditor/FileContentDisk.cpp (working copy)
@@ -561,9 +561,9 @@
     //       (I mean to call this:  std::lower_bound( .. , offset, cmp() )
     struct cmp
     {
-        static inline bool f( OffsetT offset, const DataBlock* block1 )
+        static inline bool f( OffsetT offset_, const DataBlock* block1 )
         {
-            return block1->start > offset;
+            return block1->start > offset_;
         }
     };
 
Index: src/plugins/contrib/FileManager/se_globals.cpp
===================================================================
--- src/plugins/contrib/FileManager/se_globals.cpp (revision 8648)
+++ src/plugins/contrib/FileManager/se_globals.cpp (working copy)
@@ -1,15 +1,15 @@
 #include "se_globals.h"
 
-wxString GetParentDir(const wxString &path)
+/*wxString GetParentDir(const wxString& path)
 {
-    wxString parent=wxFileName(parent).GetPath(0);
+    wxString parent=wxFileName(path).GetPath(0);
     if(path==parent||parent.IsEmpty())
         return wxEmptyString;
     else
         return parent;
 }
 
-bool DirIsChildOf(const wxString &path, const wxString &/*child*/)
+bool DirIsChildOf(const wxString& path, const wxString& child)
 {
     wxString parent=path;
     while(!parent.IsEmpty())
@@ -19,7 +19,7 @@
         parent=GetParentDir(parent);
     }
     return false;
-}
+}*/
 
 bool WildCardListMatch(wxString list, wxString name, bool strip)
 {
Index: src/plugins/contrib/FileManager/se_globals.h
===================================================================
--- src/plugins/contrib/FileManager/se_globals.h (revision 8648)
+++ src/plugins/contrib/FileManager/se_globals.h (working copy)
@@ -19,9 +19,9 @@
     #include <manager.h>
 #endif
 
-wxString GetParentDir(const wxString &path);
+//wxString GetParentDir(const wxString &path);
 
-bool DirIsChildOf(const wxString &path, const wxString &child);
+//bool DirIsChildOf(const wxString &path, const wxString &child);
 
 bool WildCardListMatch(wxString list, wxString name, bool strip=false);
 

This was also warned about, but I do not quite understand the purpose of the function, so I may not have correctly fixed it:
Code
Index: src/plugins/contrib/headerfixup/helper.cpp
===================================================================
--- src/plugins/contrib/headerfixup/helper.cpp (revision 8648)
+++ src/plugins/contrib/headerfixup/helper.cpp (working copy)
@@ -60,12 +60,12 @@
                                const wxString& RemainingLine)
 {
   wxString s_Ch = NextCharInLine;
-  if ( !s_Ch.IsSameAs(ThisChar) && !s_Ch.Trim().IsEmpty() )
+  if ( !s_Ch.IsSameAs(ThisChar) && s_Ch.Trim().IsEmpty() )
   {
     wxString TrimmedLine(RemainingLine);
     TrimmedLine.Trim(false);
     if ( !TrimmedLine.IsEmpty() )
-      wxString s_Ch = TrimmedLine.GetChar(0);
+      s_Ch = TrimmedLine.GetChar(0);
   }
 
   if ( s_Ch.IsSameAs(ThisChar) )

sh (not bash) gives an error without this change:
Code
Index: src/update
===================================================================
--- src/update (revision 8648)
+++ src/update (working copy)
@@ -6,7 +6,7 @@
   LIBEXT="dll"
 else
   uname_str=$(uname)
-  if [ "$uname_str" == "Darwin" ] ; then
+  if [ "$uname_str" = "Darwin" ] ; then
     echo Updating Mac / Darwin version.
     EXEEXT=""
     LIBEXT="dylib"

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Build Code::Blocks with Clang
« Reply #1 on: December 10, 2012, 10:50:04 pm »
Is this under OSX? I'm currently testing building C::B with clang, too.
Gentoo Linux Clang/LLVM 3.1. I've tried building contrib plugins, yet.
But I have some patches to commit to make things a bit better.

Morten, is there a problem with this patch (it is taken straight from wxgtk's trunk)
Code
Index: src/sdk/wxscintilla/src/PlatWX.cpp
===================================================================
--- src/sdk/wxscintilla/src/PlatWX.cpp  (revision 8647)
+++ src/sdk/wxscintilla/src/PlatWX.cpp  (working copy)
@@ -298,14 +298,14 @@ void SurfaceImpl::Polygon(Point *pts, int npts, ColourDesired fore, ColourDesire
 {
     PenColour(fore);
     BrushColour(back);
-/* C::B begin */
-    // Since Point now has float as x and y, it seems no longer to be interchangeable with wxPoint,
-    // and the polygon is not drawn, so we convert it explicitely
-    wxPoint points[npts];
-    for (int i = 0; i < npts; ++i)
-        points[i] = wxPoint(pts[i].x, pts[i].y);
-    hDC->DrawPolygon(npts, points);
-/* C::B end */
+    wxPoint *p = new wxPoint[npts];
+
+    for (int i=0; i<npts; i++) {
+        p[i].x = pts[i].x;
+        p[i].y = pts[i].y;
+    }
+    hdc->DrawPolygon(npts, p);
+    delete [] p;
 }

 void SurfaceImpl::RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back)

BTW: Clang is slower on C::B's code than GCC 4.5. I've built only Codeblocks-unix.cbp. The time was 2:10 vs 1:20 on a core2quad.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Build Code::Blocks with Clang
« Reply #2 on: December 10, 2012, 11:07:58 pm »
Is this under OSX?
No; Ubuntu.  I got curious, and sudo apt-geted clang 3.0.  (I previously attempted to install Clang on Windows, both with precompiled and from source, but only succeeded in getting a headache.  Now I decided to try again on Linux.)

BTW: Clang is slower on C::B's code than GCC 4.5. I've built only Codeblocks-unix.cbp. The time was 2:10 vs 1:20 on a core2quad.
On Linux, Clang (for me) has been both slower and produced binaries that are about 30% larger.  What I had been testing for was to see if the warning/error messages were really that much better (as they claim).
On Windows, from my experience, both Clang and MSVC compile significantly faster than MinGW (although, I have yet to see if either can successfully build Code::Blocks).

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Build Code::Blocks with Clang
« Reply #3 on: December 10, 2012, 11:52:47 pm »
MSVC can't because this
Code
L"test" L"TEst"
is unsupported, at least by VC++<=9.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Build Code::Blocks with Clang
« Reply #4 on: December 11, 2012, 03:04:16 am »
BTW: Clang is slower on C::B's code than GCC 4.5. I've built only Codeblocks-unix.cbp. The time was 2:10 vs 1:20 on a core2quad.
On Linux, Clang (for me) has been both slower and [...]
Although, of note, my comparison is not exactly fair; GCC was with PCH, and Clang without (I still need read more documentation to see if I can get Clang to work with PCH).

Offline Martin K.

  • Multiple posting newcomer
  • *
  • Posts: 86
Re: Build Code::Blocks with Clang
« Reply #5 on: December 11, 2012, 06:43:10 am »
MSVC can't because this
Code
L"test" L"TEst"
is unsupported, at least by VC++<=9.

on MSVC 2010 this:

Code
int _tmain(int argc, _TCHAR* argv[])
{
wprintf (L"Hello" L" " L"World\n");

return 0;
}

works as expected and prints "Hello World"  :)

BTW: I have tested it on 2003 and 2005 also, and it works there too.

Martin
« Last Edit: December 11, 2012, 06:47:43 am by Martin K. »

Offline Martin K.

  • Multiple posting newcomer
  • *
  • Posts: 86
Re: Build Code::Blocks with Clang
« Reply #6 on: December 11, 2012, 08:16:35 am »
OK, i have found what you mean,
it cannot compile something like this:

Code
int _tmain(int argc, _TCHAR* argv[])
{
wprintf (_T("Hello" " " "World\n"));

return 0;
}


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Build Code::Blocks with Clang
« Reply #7 on: December 11, 2012, 10:00:23 am »
In fact the code is wxT("bla bla") wxT("bal bla")...

Alpha: I suppose my tests with clang are also without a pch.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]