[PATCH] Recognize _alloca as an alias for the alloca builtin
Reid Kleckner
rnk at google.com
Mon Oct 21 16:14:21 PDT 2013
This has the unfortunate side effect of suggesting _alloca as a
typo-correction for malloc when it is undeclared, but I don't see a good
way around that.
http://llvm-reviews.chandlerc.com/D1989
Files:
include/clang/Basic/Builtins.def
lib/CodeGen/CGBuiltin.cpp
test/CodeGen/builtins.c
test/SemaCXX/no-implicit-builtin-decls.cpp
Index: include/clang/Basic/Builtins.def
===================================================================
--- include/clang/Basic/Builtins.def
+++ include/clang/Basic/Builtins.def
@@ -671,6 +671,7 @@
BUILTIN(__builtin_rindex, "c*cC*i", "Fn")
// Microsoft builtins.
+BUILTIN(_alloca, "v*z", "n")
BUILTIN(__assume, "vb", "n")
BUILTIN(__noop, "v.", "n")
BUILTIN(__debugbreak, "v", "n")
Index: lib/CodeGen/CGBuiltin.cpp
===================================================================
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -603,6 +603,7 @@
}
case Builtin::BIalloca:
+ case Builtin::BI_alloca:
case Builtin::BI__builtin_alloca: {
Value *Size = EmitScalarExpr(E->getArg(0));
return RValue::get(Builder.CreateAlloca(Builder.getInt8Ty(), Size));
Index: test/CodeGen/builtins.c
===================================================================
--- test/CodeGen/builtins.c
+++ test/CodeGen/builtins.c
@@ -210,3 +210,11 @@
// CHECK: call i64 @llvm.readcyclecounter()
return __builtin_readcyclecounter();
}
+
+// CHECK-LABEL: define void @test_alloca
+void test_alloca(int n) {
+ extern void capture(void *);
+ capture(_alloca(n));
+ // CHECK: alloca i8, i64 %
+ // CHECK: call void @capture
+}
Index: test/SemaCXX/no-implicit-builtin-decls.cpp
===================================================================
--- test/SemaCXX/no-implicit-builtin-decls.cpp
+++ test/SemaCXX/no-implicit-builtin-decls.cpp
@@ -1,6 +1,6 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
-void f() {
+void f() { // expected-note at +1 {{declared here}}
void *p = malloc(sizeof(int) * 10); // expected-error{{use of undeclared identifier 'malloc'}}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1989.1.patch
Type: text/x-patch
Size: 1695 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131021/5cb675d3/attachment.bin>
More information about the cfe-commits
mailing list