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

Reid Kleckner rnk at google.com
Wed Oct 30 15:38:18 PDT 2013


    - Make it only active in -fms-extensions.

http://llvm-reviews.chandlerc.com/D1989

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D1989?vs=5067&id=5275#toc

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/Builtins.h
  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
@@ -670,11 +670,12 @@
 BUILTIN(__builtin_index, "c*cC*i", "Fn")
 BUILTIN(__builtin_rindex, "c*cC*i", "Fn")
 
-// Microsoft builtins.
-BUILTIN(__assume, "vb", "n")
-BUILTIN(__noop, "v.", "n")
-BUILTIN(__debugbreak, "v", "n")
-
+// Microsoft builtins.  These are only active with -fms-extensions.
+// They are not library builtins despire our use of LIBBUILTIN.
+LIBBUILTIN(_alloca,      "v*z", "n", 0, ALL_MS_LANGUAGES)
+LIBBUILTIN(__assume,     "vb",  "n", 0, ALL_MS_LANGUAGES)
+LIBBUILTIN(__noop,       "v.",  "n", 0, ALL_MS_LANGUAGES)
+LIBBUILTIN(__debugbreak, "v",   "n", 0, ALL_MS_LANGUAGES)
 
 // C99 library functions
 // C99 stdlib.h
Index: include/clang/Basic/Builtins.h
===================================================================
--- include/clang/Basic/Builtins.h
+++ include/clang/Basic/Builtins.h
@@ -35,8 +35,10 @@
     C_LANG = 0x2,    // builtin for c only.
     CXX_LANG = 0x4,  // builtin for cplusplus only.
     OBJC_LANG = 0x8, // builtin for objective-c and objective-c++
+    MS_LANG = 0x10,  // builtin requires MS mode.
     ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
-    ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG   // builtin requires GNU mode.
+    ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG,  // builtin requires GNU mode.
+    ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG     // builtin requires MS mode.
   };
   
 namespace Builtin {
Index: lib/CodeGen/CGBuiltin.cpp
===================================================================
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -604,6 +604,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.2.patch
Type: text/x-patch
Size: 2895 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131030/43043285/attachment.bin>


More information about the cfe-commits mailing list