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

Reid Kleckner rnk at google.com
Wed Oct 30 16:37:56 PDT 2013


    - Finish requiring -fms-extensions for MS builtins.

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

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

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/Builtins.h
  lib/Basic/Builtins.cpp
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/builtin-ms-noop.cpp
  test/CodeGen/builtins.c

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/Basic/Builtins.cpp
===================================================================
--- lib/Basic/Builtins.cpp
+++ lib/Basic/Builtins.cpp
@@ -54,10 +54,12 @@
     llvm::StringRef(BuiltinInfo.HeaderName).equals("math.h");
   bool GnuModeUnsupported = !LangOpts.GNUMode &&
                             (BuiltinInfo.builtin_lang & GNU_LANG);
+  bool MSModeUnsupported = !LangOpts.MicrosoftExt &&
+                           (BuiltinInfo.builtin_lang & MS_LANG);
   bool ObjCUnsupported = !LangOpts.ObjC1 &&
                          BuiltinInfo.builtin_lang == OBJC_LANG;
   return !BuiltinsUnsupported && !MathBuiltinsUnsupported &&
-         !GnuModeUnsupported && !ObjCUnsupported;
+         !GnuModeUnsupported && !ObjCUnsupported && !MSModeUnsupported;
 }
 
 /// InitializeBuiltins - Mark the identifiers for all the builtins with their
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/builtin-ms-noop.cpp
===================================================================
--- test/CodeGen/builtin-ms-noop.cpp
+++ test/CodeGen/builtin-ms-noop.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple i686-pc-win32 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fms-extensions -triple i686-pc-win32 -emit-llvm %s -o - | FileCheck %s
 
 class A {
  public:
Index: test/CodeGen/builtins.c
===================================================================
--- test/CodeGen/builtins.c
+++ test/CodeGen/builtins.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -emit-llvm -o %t %s
 // RUN: not grep __builtin %t
-// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fms-extensions | FileCheck %s
 
 int printf(const char *, ...);
 
@@ -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
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1989.3.patch
Type: text/x-patch
Size: 4000 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131030/35bd25af/attachment.bin>


More information about the cfe-commits mailing list