[cfe-commits] r61291 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp lib/CodeGen/CGExprScalar.cpp test/CodeGen/vla.c
Eli Friedman
eli.friedman at gmail.com
Sat Dec 20 15:12:01 PST 2008
Author: efriedma
Date: Sat Dec 20 17:11:59 2008
New Revision: 61291
URL: http://llvm.org/viewvc/llvm-project?rev=61291&view=rev
Log:
Make VLAs usable, and make basic usage work correctly. Also, add a
simple test that actually does VLA codegen.
Note that despite the fact that the alloca isn't in the entry block, it
should dominate all uses; this is guaranteed by the restrictions on goto
into VLA scope in C99.
Added:
cfe/trunk/test/CodeGen/vla.c
Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=61291&r1=61290&r2=61291&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Sat Dec 20 17:11:59 2008
@@ -192,17 +192,9 @@
// Allocate memory for the array.
llvm::Value *VLA = Builder.CreateAlloca(llvm::Type::Int8Ty, VLASize, "vla");
- VLA = Builder.CreateBitCast(VLA, LElemPtrTy, "tmp");
-
- llvm::AllocaInst *Alloc =
- CreateTempAlloca(LElemPtrTy, D.getIdentifier()->getName());
-
- // FIXME: Volatile?
- Builder.CreateStore(VLA, Alloc);
-
- DeclPtr = Alloc;
+ DeclPtr = Builder.CreateBitCast(VLA, LElemPtrTy, "tmp");
}
-
+
llvm::Value *&DMEntry = LocalDeclMap[&D];
assert(DMEntry == 0 && "Decl already exists in localdeclmap!");
DMEntry = DeclPtr;
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=61291&r1=61290&r2=61291&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Sat Dec 20 17:11:59 2008
@@ -513,16 +513,14 @@
// FIXME: For now we assume that all source arrays map to LLVM arrays. This
// will not true when we add support for VLAs.
Value *V = EmitLValue(Op).getAddress(); // Bitfields can't be arrays.
-
- if (!(isa<llvm::PointerType>(V->getType()) &&
- isa<llvm::ArrayType>(cast<llvm::PointerType>(V->getType())
- ->getElementType()))) {
- CGF.ErrorUnsupported(E, "variable-length array cast", true);
- if (E->getType()->isVoidType())
- return 0;
- return llvm::UndefValue::get(CGF.ConvertType(E->getType()));
+
+ if (!Op->getType()->isVariableArrayType()) {
+ assert(isa<llvm::PointerType>(V->getType()) && "Expected pointer");
+ assert(isa<llvm::ArrayType>(cast<llvm::PointerType>(V->getType())
+ ->getElementType()) &&
+ "Expected pointer to array");
+ V = Builder.CreateStructGEP(V, 0, "arraydecay");
}
- V = Builder.CreateStructGEP(V, 0, "arraydecay");
// The resultant pointer type can be implicitly casted to other pointer
// types as well (e.g. void*) and can be implicitly converted to integer.
Added: cfe/trunk/test/CodeGen/vla.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/vla.c?rev=61291&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/vla.c (added)
+++ cfe/trunk/test/CodeGen/vla.c Sat Dec 20 17:11:59 2008
@@ -0,0 +1,10 @@
+// RUN: clang %s -emit-llvm -o %t
+
+int b(char* x);
+
+// Extremely basic VLA test
+void a(int x) {
+ char arry[x];
+ arry[0] = 10;
+ b(arry);
+}
More information about the cfe-commits
mailing list