r224504 - Fix for PR21915: assert on multidimensional VLA in function arguments.

Alexey Bataev a.bataev at hotmail.com
Wed Dec 17 22:54:53 PST 2014


Author: abataev
Date: Thu Dec 18 00:54:53 2014
New Revision: 224504

URL: http://llvm.org/viewvc/llvm-project?rev=224504&view=rev
Log:
Fix for PR21915: assert on multidimensional VLA in function arguments.
Fixed assertion on type checking for arguments and parameters on function call if arguments are pointers to VLA
Differential Revision: http://reviews.llvm.org/D6655

Added:
    cfe/trunk/test/CodeGen/vlt_to_pointer.c   (with props)
    cfe/trunk/test/CodeGenCXX/vlt_to_reference.cpp   (with props)
Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=224504&r1=224503&r2=224504&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Thu Dec 18 00:54:53 2014
@@ -2746,28 +2746,13 @@ public:
                 E = CallArgTypeInfo->param_type_end();
            I != E; ++I, ++Arg) {
         assert(Arg != ArgEnd && "Running over edge of argument list!");
-#ifndef NDEBUG
-        QualType ArgType = *I;
-        QualType ActualArgType = Arg->getType();
-        if (ArgType->isPointerType() && ActualArgType->isPointerType()) {
-          QualType ActualBaseType =
-              ActualArgType->getAs<PointerType>()->getPointeeType();
-          QualType ArgBaseType =
-              ArgType->getAs<PointerType>()->getPointeeType();
-          if (ArgBaseType->isVariableArrayType()) {
-            if (const VariableArrayType *VAT =
-                    getContext().getAsVariableArrayType(ActualBaseType)) {
-              if (!VAT->getSizeExpr())
-                ActualArgType = ArgType;
-            }
-          }
-        }
-        assert(getContext()
-                       .getCanonicalType(ArgType.getNonReferenceType())
-                       .getTypePtr() ==
-                   getContext().getCanonicalType(ActualArgType).getTypePtr() &&
-               "type mismatch in call argument!");
-#endif
+        assert(
+            ((*I)->isVariablyModifiedType() ||
+             getContext()
+                     .getCanonicalType((*I).getNonReferenceType())
+                     .getTypePtr() ==
+                 getContext().getCanonicalType(Arg->getType()).getTypePtr()) &&
+            "type mismatch in call argument!");
         ArgTypes.push_back(*I);
       }
     }

Added: cfe/trunk/test/CodeGen/vlt_to_pointer.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/vlt_to_pointer.c?rev=224504&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/vlt_to_pointer.c (added)
+++ cfe/trunk/test/CodeGen/vlt_to_pointer.c Thu Dec 18 00:54:53 2014
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
+
+int c[1][3*2];
+// CHECK: @{{.+}} = {{.*}} global [1 x [6 x {{i[0-9]+}}]] zeroinitializer
+
+// CHECK-LABEL: @f
+int f(int * const m, int (**v)[*m * 2])
+{
+    return &(c[0][*m]) == &((*v)[0][*m]);
+    // CHECK: icmp
+    // CHECK: ret i{{[0-9]+}}
+}
+
+// CHECK-LABEL: @test
+int test(int n, int (*(*fn)(void))[n]) {
+  return (*fn())[0];
+}
+
+// CHECK-LABEL: @main
+int main()
+{
+    int m = 3;
+    int (*d)[3*2] = c;
+    int (*fn[m])(void);
+    return f(&m, &d) + test(m, &fn);
+
+    // CHECK: call {{.+}} @f(
+    // CHECK: ret i{{[0-9]+}}
+}
+

Propchange: cfe/trunk/test/CodeGen/vlt_to_pointer.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/CodeGen/vlt_to_pointer.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Rev URL

Propchange: cfe/trunk/test/CodeGen/vlt_to_pointer.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cfe/trunk/test/CodeGenCXX/vlt_to_reference.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vlt_to_reference.cpp?rev=224504&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/vlt_to_reference.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/vlt_to_reference.cpp Thu Dec 18 00:54:53 2014
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
+
+// CHECK-LABEL: @main
+
+struct dyn_array { 
+    int size;
+    int data[];
+};
+
+int foo(dyn_array **&d) {
+  return (*d)->data[1];
+}
+
+int main()
+{
+    dyn_array **d;
+    return foo(d);
+
+    // CHECK: call {{.+}} @{{.+}}foo{{.+}}(
+    // CHECK: ret i{{[0-9]+}}
+}
+

Propchange: cfe/trunk/test/CodeGenCXX/vlt_to_reference.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/CodeGenCXX/vlt_to_reference.cpp
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Rev URL

Propchange: cfe/trunk/test/CodeGenCXX/vlt_to_reference.cpp
------------------------------------------------------------------------------
    svn:mime-type = text/plain





More information about the cfe-commits mailing list