[PATCH] Recognize _alloca as an alias for the alloca builtin

Alp Toker alp at nuanti.com
Wed Oct 30 15:50:36 PDT 2013


On 22/10/2013 00:14, Reid Kleckner wrote:
> 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.

Perhaps we shouldn't be suggesting underscore-prefixed typo corrections?

 1.

    17.6.4.3.2 Global names [global.names]

1 Certain sets of names and function signatures are always reserved to
the implementation:

  *

    ---  Each name that contains a double underscore _ _ or begins with
    an underscore followed by an uppercase

    letter (2.12) is reserved to the implementation for any use.

  *

    *---  Each name that begins with an underscore is reserved to the
    implementation for use as a name in the *

    **

    *global namespace. *

C++ International Standard
Alp.

>
> 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

-- 
http://www.nuanti.com
the browser experts

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131030/97886be7/attachment.html>


More information about the cfe-commits mailing list