[cfe-commits] r158653 - in /cfe/trunk: include/clang/Basic/Attr.td lib/CodeGen/CodeGenModule.cpp lib/Parse/ParseDecl.cpp lib/Sema/SemaDeclAttr.cpp test/CodeGen/forceinline.c
Michael J. Spencer
bigcheesegs at gmail.com
Mon Jun 18 00:00:48 PDT 2012
Author: mspencer
Date: Mon Jun 18 02:00:48 2012
New Revision: 158653
URL: http://llvm.org/viewvc/llvm-project?rev=158653&view=rev
Log:
[MSExtensions] Add support for __forceinline.
__forceinline is a combination of the inline keyword and __attribute__((always_inline))
Added:
cfe/trunk/test/CodeGen/forceinline.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=158653&r1=158652&r2=158653&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Mon Jun 18 02:00:48 2012
@@ -824,6 +824,10 @@
let Spellings = ["dllimport"];
}
+def ForceInline : InheritableAttr {
+ let Spellings = ["__forceinline"];
+}
+
def Win64 : InheritableAttr {
let Spellings = ["__w64"];
}
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=158653&r1=158652&r2=158653&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Jun 18 02:00:48 2012
@@ -518,7 +518,7 @@
F->addFnAttr(llvm::Attribute::NoInline);
// (noinline wins over always_inline, and we can't specify both in IR)
- if (D->hasAttr<AlwaysInlineAttr>() &&
+ if ((D->hasAttr<AlwaysInlineAttr>() || D->hasAttr<ForceInlineAttr>()) &&
!F->hasFnAttr(llvm::Attribute::NoInline))
F->addFnAttr(llvm::Attribute::AlwaysInline);
@@ -935,7 +935,7 @@
if (getFunctionLinkage(F) != llvm::Function::AvailableExternallyLinkage)
return true;
if (CodeGenOpts.OptimizationLevel == 0 &&
- !F->hasAttr<AlwaysInlineAttr>())
+ !F->hasAttr<AlwaysInlineAttr>() && !F->hasAttr<ForceInlineAttr>())
return false;
// PR9614. Avoid cases where the source code is lying to us. An available
// externally function should have an equivalent function somewhere else,
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=158653&r1=158652&r2=158653&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Jun 18 02:00:48 2012
@@ -2251,9 +2251,14 @@
continue;
// Microsoft single token adornments.
- case tok::kw___forceinline:
- // FIXME: Add handling here!
- break;
+ case tok::kw___forceinline: {
+ isInvalid = DS.SetFunctionSpecInline(Loc, PrevSpec, DiagID);
+ IdentifierInfo *AttrName = Tok.getIdentifierInfo();
+ SourceLocation AttrNameLoc = ConsumeToken();
+ DS.getAttributes().addNew(AttrName, AttrNameLoc, 0, AttrNameLoc, 0,
+ SourceLocation(), 0, 0);
+ continue;
+ }
case tok::kw___ptr64:
case tok::kw___ptr32:
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=158653&r1=158652&r2=158653&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Jun 18 02:00:48 2012
@@ -3888,6 +3888,13 @@
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
}
+static void handleForceInlineAttr(Sema &S, Decl *D, const AttributeList &Attr) {
+ if (S.LangOpts.MicrosoftExt)
+ D->addAttr(::new (S.Context) ForceInlineAttr(Attr.getRange(), S.Context));
+ else
+ S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
+}
+
//===----------------------------------------------------------------------===//
// Top Level Sema Entry Points
//===----------------------------------------------------------------------===//
@@ -4082,6 +4089,9 @@
case AttributeList::AT_ptr64:
handlePortabilityAttr(S, D, Attr);
break;
+ case AttributeList::AT_forceinline:
+ handleForceInlineAttr(S, D, Attr);
+ break;
// Thread safety attributes:
case AttributeList::AT_guarded_var:
Added: cfe/trunk/test/CodeGen/forceinline.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/forceinline.c?rev=158653&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/forceinline.c (added)
+++ cfe/trunk/test/CodeGen/forceinline.c Mon Jun 18 02:00:48 2012
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple i686-win32 -emit-llvm -fms-extensions < %s | FileCheck %s
+
+void bar() {
+}
+
+// CHECK-NOT: foo
+__forceinline void foo() {
+ bar();
+}
+
+void i_want_bar() {
+// CHECK: call void @bar
+ foo();
+}
More information about the cfe-commits
mailing list