[cfe-commits] r156407 - in /cfe/trunk: lib/CodeGen/CGDebugInfo.cpp test/CodeGen/debug-info-vla.c

Eric Christopher echristo at apple.com
Tue May 8 11:56:48 PDT 2012


Author: echristo
Date: Tue May  8 13:56:47 2012
New Revision: 156407

URL: http://llvm.org/viewvc/llvm-project?rev=156407&view=rev
Log:
The address of a vla is actually complex and requires a dereference.

Part of rdar://11352000

Added:
    cfe/trunk/test/CodeGen/debug-info-vla.c
Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=156407&r1=156406&r2=156407&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue May  8 13:56:47 2012
@@ -2289,8 +2289,25 @@
         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, 

Added: cfe/trunk/test/CodeGen/debug-info-vla.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-vla.c?rev=156407&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/debug-info-vla.c (added)
+++ cfe/trunk/test/CodeGen/debug-info-vla.c Tue May  8 13:56:47 2012
@@ -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;
+  }
+}





More information about the cfe-commits mailing list