]> granicus.if.org Git - clang/commitdiff
add a testcase for PR12094 and fix a crash on pointer to incomplete type,
authorChris Lattner <sabre@nondot.org>
Sun, 4 Mar 2012 00:52:12 +0000 (00:52 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 4 Mar 2012 00:52:12 +0000 (00:52 +0000)
reported by Richard Smith.

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

lib/CodeGen/CGBuiltin.cpp
test/CodeGen/builtin-memfns.c

index d17ca780fce1bc915d11694de601f2d21da84c75..5b0664101f0318735a5179555d59d25ead3030b4 100644 (file)
@@ -1264,9 +1264,13 @@ unsigned CodeGenFunction::GetPointeeAlignment(const Expr *Addr) {
   // 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)) {
index fb4d7200752de9a26052ed29f3c357bfcfc8fee3..e4389f6211421cbef9a026ab12aab30022823fab 100644 (file)
@@ -48,3 +48,14 @@ void test5(char *P, char *Q) {
 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)
+}