]> granicus.if.org Git - clang/commitdiff
The address of a vla is actually complex and requires a dereference.
authorEric Christopher <echristo@apple.com>
Tue, 8 May 2012 18:56:47 +0000 (18:56 +0000)
committerEric Christopher <echristo@apple.com>
Tue, 8 May 2012 18:56:47 +0000 (18:56 +0000)
Part of rdar://11352000

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

lib/CodeGen/CGDebugInfo.cpp
test/CodeGen/debug-info-vla.c [new file with mode: 0644]

index a546d6b80761230ab501863e2ceb5724cbae358d..2d76f9bc0b57e5c6519f72ff15a06ec9d89b85cb 100644 (file)
@@ -2289,8 +2289,25 @@ void CGDebugInfo::EmitDeclare(const VarDecl *VD, unsigned Tag,
         DBuilder.insertDeclare(Storage, D, Builder.GetInsertBlock());
       Call->setDebugLoc(llvm::DebugLoc::get(Line, Column, Scope));
       return;
-    } 
+    } else if (isa<VariableArrayType>(VD->getType())) {
+      // These are "complex" variables in that they need an op_deref.
       // Create the descriptor for the variable.
+      llvm::Value *Addr = llvm::ConstantInt::get(CGM.Int64Ty,
+                                                 llvm::DIBuilder::OpDeref);
+      llvm::DIVariable D =
+        DBuilder.createComplexVariable(Tag,
+                                       llvm::DIDescriptor(Scope),
+                                       Name, Unit, Line, Ty,
+                                       Addr, ArgNo);
+
+      // Insert an llvm.dbg.declare into the current block.
+      llvm::Instruction *Call =
+        DBuilder.insertDeclare(Storage, D, Builder.GetInsertBlock());
+      Call->setDebugLoc(llvm::DebugLoc::get(Line, Column, Scope));
+      return;
+    }
+    
+    // Create the descriptor for the variable.
     llvm::DIVariable D =
       DBuilder.createLocalVariable(Tag, llvm::DIDescriptor(Scope), 
                                    Name, Unit, Line, Ty, 
diff --git a/test/CodeGen/debug-info-vla.c b/test/CodeGen/debug-info-vla.c
new file mode 100644 (file)
index 0000000..20fb6aa
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -emit-llvm -g -triple x86_64-apple-darwin %s -o - | FileCheck %s
+
+// CHECK: metadata !{i32 {{.*}}, metadata {{.*}}, metadata !"vla", metadata {{.*}}, i32 7, metadata {{.*}}, i32 0, i32 0, i64 2} ; [ DW_TAG_auto_variable ]
+
+void testVLAwithSize(int s)
+{
+  int vla[s];
+  int i;
+  for (i = 0; i < s; i++) {
+    vla[i] = i*i;
+  }
+}