[PATCH] Recognize _alloca as an alias for the alloca builtin
Hal Finkel
hfinkel at anl.gov
Tue Oct 22 10:04:25 PDT 2013
----- Original Message -----
> 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.
I think that we could add some kind of logic to Sema::CorrectTypo to account for this. Either using some flag to create a set of 'hidden builtins' that won't contribute to typo correction, or just by special-casing this particular issue (there is, for example, already a special case for "vector" in there).
-Hal
>
> 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'}}
> }
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
--
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory
More information about the cfe-commits
mailing list