[cfe-commits] r112819 - in /cfe/trunk: lib/CodeGen/ItaniumCXXABI.cpp test/CodeGenCXX/pointers-to-data-members.cpp

Douglas Gregor dgregor at apple.com
Thu Sep 2 08:00:30 PDT 2010


Author: dgregor
Date: Thu Sep  2 10:00:29 2010
New Revision: 112819

URL: http://llvm.org/viewvc/llvm-project?rev=112819&view=rev
Log:
Fix a crash involving pointer-to-data-members of boolean type. We were
constructing an LLVM PointerType directly from the "bool"'s LLVM type
(i1), which resulted in unfortunate pointer type i1*. The fix is to
build the LLVM PointerType from the corresponding Clang PointerType,
so that we get i8* in the case of a bool. 

John, please review. I also left a FIXME there because we seem to be
dropping "volatile", which would be rather unfortunate.

Modified:
    cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
    cfe/trunk/test/CodeGenCXX/pointers-to-data-members.cpp

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=112819&r1=112818&r2=112819&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Thu Sep  2 10:00:29 2010
@@ -305,8 +305,13 @@
 
   // Cast the address to the appropriate pointer type, adopting the
   // address space of the base pointer.
-  const llvm::Type *PType
-    = CGF.ConvertType(MPT->getPointeeType())->getPointerTo(AS);
+  // FIXME: We seem to be losing the "volatile" qualifier on the base pointer.
+  QualType PtrType = CGF.getContext().getPointerType(MPT->getPointeeType());
+  Qualifiers Qs = MPT->getPointeeType().getQualifiers();
+  if (AS)
+    Qs.addAddressSpace(AS);
+  PtrType = CGF.getContext().getQualifiedType(PtrType, Qs);
+  const llvm::Type *PType = CGF.ConvertType(PtrType);
   return Builder.CreateBitCast(Addr, PType);
 }
 

Modified: cfe/trunk/test/CodeGenCXX/pointers-to-data-members.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/pointers-to-data-members.cpp?rev=112819&r1=112818&r2=112819&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/pointers-to-data-members.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/pointers-to-data-members.cpp Thu Sep  2 10:00:29 2010
@@ -189,3 +189,17 @@
 A a;
 
 }
+
+namespace BoolPtrToMember {
+  struct X {
+    bool member;
+  };
+
+  // CHECK: define i8* @_ZN15BoolPtrToMember1fERNS_1XEMS0_b
+  bool &f(X &x, bool X::*member) {
+    // CHECK: {{bitcast.* to i8\*}}
+    // CHECK-NEXT: getelementptr inbounds i8*
+    // CHECK-NEXT: ret i8*
+    return x.*member;
+  }
+}





More information about the cfe-commits mailing list