[DynInst_API:] [PATCH 2/2] Let Dyninst itself be compiled with Clang on Linux


Date: Tue, 19 Nov 2013 14:52:12 -0800
From: Josh Stone <jistone@xxxxxxxxxx>
Subject: [DynInst_API:] [PATCH 2/2] Let Dyninst itself be compiled with Clang on Linux
With clang-3.3-0.10.rc3.fc19.x86_64 and libstdc++-4.8.2-1.fc19.x86_64,
the fixes required were as follows:

- cmake files looking for CMAKE_COMPILER_IS_GNUCXX need to also
  recognize CMAKE_CXX_COMPILER_ID "Clang".

- The ListHash macro had a pointer->int cast that halted Clang.

- Several templates in rose/*InstructionSemantics.h couldn't be resolved
  implicitly; they're now either made explicit or converted to typename.

- ppc32::cr0.val() is apparently not const enough for Clang as a
  template parameter; changed to ppc32::icr0.
---
 cmake/c++11.cmake                              |  2 +-
 cmake/optimization.cmake                       |  2 +-
 cmake/visibility.cmake                         |  2 +-
 cmake/warnings.cmake                           |  3 +++
 common/src/List.h                              |  2 +-
 common/src/keylist.h                           |  2 +-
 dataflowAPI/rose/powerpcInstructionSemantics.h |  8 ++++----
 dataflowAPI/rose/x86InstructionSemantics.h     | 12 ++++++------
 instructionAPI/src/InstructionDecoder-power.h  |  2 +-
 9 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/cmake/c++11.cmake b/cmake/c++11.cmake
index 0eeeeaf..41c42dc 100644
--- a/cmake/c++11.cmake
+++ b/cmake/c++11.cmake
@@ -9,7 +9,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
        set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
     endif()
 elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
 elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
 else ()
diff --git a/cmake/optimization.cmake b/cmake/optimization.cmake
index bac42ec..dde0345 100644
--- a/cmake/optimization.cmake
+++ b/cmake/optimization.cmake
@@ -1,4 +1,4 @@
-if (CMAKE_COMPILER_IS_GNUCXX)
+if (CMAKE_COMPILER_IS_GNUCXX  OR  "${CMAKE_C_COMPILER_ID}" MATCHES Clang)
 set (CMAKE_C_FLAGS_DEBUG "-O0 -g")
 set (CMAKE_C_FLAGS_RELEASE "-O2")
 set (CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
diff --git a/cmake/visibility.cmake b/cmake/visibility.cmake
index c875293..8c39128 100644
--- a/cmake/visibility.cmake
+++ b/cmake/visibility.cmake
@@ -1,4 +1,4 @@
-if(CMAKE_COMPILER_IS_GNUCXX)
+if(CMAKE_COMPILER_IS_GNUCXX  OR  "${CMAKE_C_COMPILER_ID}" MATCHES Clang)
     set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
     set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
     message(STATUS "Found g++, enabling -fvisibility=hidden")
diff --git a/cmake/warnings.cmake b/cmake/warnings.cmake
index 1b37e03..7a2c21d 100644
--- a/cmake/warnings.cmake
+++ b/cmake/warnings.cmake
@@ -1,6 +1,9 @@
 if (CMAKE_COMPILER_IS_GNUCXX)
 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W -Wall -Wpointer-arith -Wcast-qual -Wcast-align")
 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wpointer-arith -Wcast-qual -Woverloaded-virtual -Wcast-align -Wno-non-template-friend")
+elseif ("${CMAKE_C_COMPILER_ID}" MATCHES Clang)
+set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W -Wall -Wpointer-arith -Wcast-qual")
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wpointer-arith -Wcast-qual -Woverloaded-virtual")
 elseif (MSVC)
 # ...
 endif()
diff --git a/common/src/List.h b/common/src/List.h
index ef984b0..6aba042 100644
--- a/common/src/List.h
+++ b/common/src/List.h
@@ -46,7 +46,7 @@
 #define DO_INLINE_F
 #endif
 
-#define ListHash(ptr, size) (((unsigned int)(ptr) % (unsigned int)(size)))
+#define ListHash(ptr, size) (((unsigned int)(intptr_t)(ptr) % (unsigned int)(size)))
 
 template <class DataType> class List;
 template <class DataType, class KeyType> class ListBase;
diff --git a/common/src/keylist.h b/common/src/keylist.h
index ec020ae..d89ea39 100644
--- a/common/src/keylist.h
+++ b/common/src/keylist.h
@@ -72,7 +72,7 @@ typedef int KYL_BOOL;
 
 #pragma interface
 
-#define ListHash(ptr, size) (((unsigned int)(ptr) % (unsigned int)(size)))
+#define ListHash(ptr, size) (((unsigned int)(intptr_t)(ptr) % (unsigned int)(size)))
 
 template <class Type> class KeyList;
 
diff --git a/dataflowAPI/rose/powerpcInstructionSemantics.h b/dataflowAPI/rose/powerpcInstructionSemantics.h
index e4ad5c6..a05d35d 100644
--- a/dataflowAPI/rose/powerpcInstructionSemantics.h
+++ b/dataflowAPI/rose/powerpcInstructionSemantics.h
@@ -28,8 +28,8 @@ struct PowerpcInstructionSemantics {
     return policy.template number<Len>(v);
   }
 
-  template <size_t From, size_t To, size_t Len>
-  Word(To - From) extract(Word(Len) w) {
+  template <size_t From, size_t To, typename W>
+  Word(To - From) extract(W w) {
     return policy.template extract<From, To>(w);
   }
 
@@ -449,7 +449,7 @@ build_mask(uint8_t mb_value, uint8_t me_value)
            SgAsmExpression* RA = binaryAdd->get_lhs();
 
            Word(32) effectiveAddress = readEffectiveAddress(operands[1]);
-           writeMemory(effectiveAddress,read32(operands[0]),policy.true_());
+           writeMemory<32>(effectiveAddress,read32(operands[0]),policy.true_());
            write32(RA,effectiveAddress);
            break;
          }
@@ -989,7 +989,7 @@ build_mask(uint8_t mb_value, uint8_t me_value)
         // For 32-bit case we can ignore value of L
  
            Word(32) RA = read32(operands[2]);
-           Word(32) SI = policy.signExtend<16,32>(extract<0,16>(read32(operands[3])));
+           Word(32) SI = signExtend<16,32>(extract<0,16>(read32(operands[3])));
 
            Word(32) carries = number<32>(0);
 
diff --git a/dataflowAPI/rose/x86InstructionSemantics.h b/dataflowAPI/rose/x86InstructionSemantics.h
index 95253f7..5c5f53c 100644
--- a/dataflowAPI/rose/x86InstructionSemantics.h
+++ b/dataflowAPI/rose/x86InstructionSemantics.h
@@ -104,8 +104,8 @@ struct X86InstructionSemantics {
     }
     
 
-    template <size_t Len>
-    Word(Len) invertMaybe(const Word(Len)& w, bool inv) {
+    template <typename W>
+    W invertMaybe(const W& w, bool inv) {
         if (inv) {
             return policy.invert(w);
         } else {
@@ -118,8 +118,8 @@ struct X86InstructionSemantics {
         return policy.template number<Len>(v);
     }
 
-    template <size_t From, size_t To, size_t Len>
-        Word(To - From) extract(Word(Len) w) {
+    template <size_t From, size_t To, typename W>
+        Word(To - From) extract(W w) {
         return policy.template extract<From, To>(w);
     }
 
@@ -1742,7 +1742,7 @@ struct X86InstructionSemantics {
             case x86_aaa: {
                 ROSE_ASSERT(operands.size() == 0);
                 Word(1) incAh = policy.or_(policy.readFlag(x86_flag_af),
-                                           greaterOrEqualToTen(extract<0, 4>(policy.readGPR(x86_gpr_ax))));
+                                           greaterOrEqualToTen<4>(extract<0, 4>(policy.readGPR(x86_gpr_ax))));
                 updateGPRLowWord(x86_gpr_ax,
                                  policy.concat(policy.add(policy.ite(incAh, number<4>(6), number<4>(0)),
                                                           extract<0, 4>(policy.readGPR(x86_gpr_ax))),
@@ -1761,7 +1761,7 @@ struct X86InstructionSemantics {
             case x86_aas: {
                 ROSE_ASSERT(operands.size() == 0);
                 Word(1) decAh = policy.or_(policy.readFlag(x86_flag_af),
-                                           greaterOrEqualToTen(extract<0, 4>(policy.readGPR(x86_gpr_ax))));
+                                           greaterOrEqualToTen<4>(extract<0, 4>(policy.readGPR(x86_gpr_ax))));
                 updateGPRLowWord(x86_gpr_ax,
                                  policy.concat(policy.add(policy.ite(decAh, number<4>(-6), number<4>(0)),
                                                           extract<0, 4>(policy.readGPR(x86_gpr_ax))),
diff --git a/instructionAPI/src/InstructionDecoder-power.h b/instructionAPI/src/InstructionDecoder-power.h
index d383074..a86f8e3 100644
--- a/instructionAPI/src/InstructionDecoder-power.h
+++ b/instructionAPI/src/InstructionDecoder-power.h
@@ -187,7 +187,7 @@ namespace Dyninst {
                 }
 
                 
-                template<unsigned int low, unsigned int high, unsigned int base = ppc32::cr0.val(),
+                template<unsigned int low, unsigned int high, unsigned int base = ppc32::icr0,
                     unsigned int curCR = high - low>
                 struct translateBitFieldToCR
                 {
-- 
1.8.3.1

[← Prev in Thread] Current Thread [Next in Thread→]