]> granicus.if.org Git - clang/commitdiff
Fix a crash involving pointer-to-data-members of boolean type. We were
authorDouglas Gregor <dgregor@apple.com>
Thu, 2 Sep 2010 15:00:29 +0000 (15:00 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 2 Sep 2010 15:00:29 +0000 (15:00 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112819 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/ItaniumCXXABI.cpp
test/CodeGenCXX/pointers-to-data-members.cpp

index a1a53ad5e051e3e56fc6ee583732107ebf9fa995..85b52c632204ff89f7e61893f0cd8dfce104fecf 100644 (file)
@@ -305,8 +305,13 @@ llvm::Value *ItaniumCXXABI::EmitMemberDataPointerAddress(CodeGenFunction &CGF,
 
   // 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);
 }
 
index 60c1661e0602e01b415a2631ec1fd1e775c6f931..38c7d2815a08433c1881add39e5afa9d3789d397 100644 (file)
@@ -189,3 +189,17 @@ struct A {
 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;
+  }
+}