[cfe-commits] r151993 - in /cfe/trunk: lib/CodeGen/CGBuiltin.cpp test/CodeGen/builtin-memfns.c

Chris Lattner sabre at nondot.org
Sat Mar 3 16:52:12 PST 2012


Author: lattner
Date: Sat Mar  3 18:52:12 2012
New Revision: 151993

URL: http://llvm.org/viewvc/llvm-project?rev=151993&view=rev
Log:
add a testcase for PR12094 and fix a crash on pointer to incomplete type,
reported by Richard Smith.

Modified:
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp
    cfe/trunk/test/CodeGen/builtin-memfns.c

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=151993&r1=151992&r2=151993&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Sat Mar  3 18:52:12 2012
@@ -1264,9 +1264,13 @@
   // Check if the type is a pointer.  The implicit cast operand might not be.
   while (Addr->getType()->isPointerType()) {
     QualType PtTy = Addr->getType()->getPointeeType();
-    unsigned NewA = getContext().getTypeAlignInChars(PtTy).getQuantity();
-    if (NewA > Align)
-      Align = NewA;
+    
+    // Can't get alignment of incomplete types.
+    if (!PtTy->isIncompleteType()) {
+      unsigned NewA = getContext().getTypeAlignInChars(PtTy).getQuantity();
+      if (NewA > Align)
+        Align = NewA;
+    }
 
     // If the address is an implicit cast, repeat with the cast operand.
     if (const ImplicitCastExpr *CastAddr = dyn_cast<ImplicitCastExpr>(Addr)) {

Modified: cfe/trunk/test/CodeGen/builtin-memfns.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtin-memfns.c?rev=151993&r1=151992&r2=151993&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/builtin-memfns.c (original)
+++ cfe/trunk/test/CodeGen/builtin-memfns.c Sat Mar  3 18:52:12 2012
@@ -48,3 +48,14 @@
 int test6(char *X) {
   return __builtin___memcpy_chk(X, X, 42, 42) != 0;
 }
+
+// CHECK: @test7
+// PR12094
+int test7(int *p) {
+  // CHECK: call void @llvm.memset{{.*}}256, i32 4, i1 false)
+  __builtin_memset(p, 0, 256);  // Should be alignment = 4
+  struct snd_pcm_hw_params_t* hwparams;  // incomplete type.
+
+  __builtin_memset(hwparams, 0, 256);  // No crash alignment = 1
+  // CHECK: call void @llvm.memset{{.*}}256, i32 1, i1 false)
+}





More information about the cfe-commits mailing list