[cfe-commits] r173364 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaStmtAsm.cpp test/Sema/ms-inline-asm-invalid-arch.c

Chad Rosier mcrosier at apple.com
Thu Jan 24 12:24:34 PST 2013


Author: mcrosier
Date: Thu Jan 24 14:24:34 2013
New Revision: 173364

URL: http://llvm.org/viewvc/llvm-project?rev=173364&view=rev
Log:
[ms-inline asm] Add an error when trying to compile MS-style inline assembly
for an unsupported architecture.
rdar://13063988

Added:
    cfe/trunk/test/Sema/ms-inline-asm-invalid-arch.c
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaStmtAsm.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=173364&r1=173363&r2=173364&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jan 24 14:24:34 2013
@@ -5241,6 +5241,8 @@
     "invalid use of a cast in a inline asm context requiring an l-value: "
     "remove the cast or build with -fheinous-gnu-extensions">;
   def err_inline_ms_asm_parsing : Error<"%0">;
+  def err_msasm_unsupported_arch : Error<
+    "Unsupported architecture '%0' for MS-style inline assembly">;
 
   def warn_asm_label_on_auto_decl : Warning<
     "ignored asm label '%0' on automatic variable">;

Modified: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=173364&r1=173363&r2=173364&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmtAsm.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp Thu Jan 24 14:24:34 2013
@@ -580,8 +580,15 @@
   SmallVector<Expr*, 4> Exprs;
   SmallVector<StringRef, 4> ClobberRefs;
 
+  llvm::Triple TheTriple = Context.getTargetInfo().getTriple();
+  llvm::Triple::ArchType ArchTy = TheTriple.getArch();
+  bool UnsupportedArch = ArchTy != llvm::Triple::x86 &&
+    ArchTy != llvm::Triple::x86_64;
+  if (UnsupportedArch)
+    Diag(AsmLoc, diag::err_msasm_unsupported_arch) << TheTriple.getArchName();
+    
   // Empty asm statements don't need to instantiate the AsmParser, etc.
-  if (AsmToks.empty()) {
+  if (UnsupportedArch || AsmToks.empty()) {
     StringRef EmptyAsmStr;
     MSAsmStmt *NS =
       new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, /*IsSimple*/ true,
@@ -598,7 +605,7 @@
 
   // Get the target specific parser.
   std::string Error;
-  const std::string &TT = Context.getTargetInfo().getTriple().getTriple();
+  const std::string &TT = TheTriple.getTriple();
   const llvm::Target *TheTarget(llvm::TargetRegistry::lookupTarget(TT, Error));
 
   OwningPtr<llvm::MCAsmInfo> MAI(TheTarget->createMCAsmInfo(TT));

Added: cfe/trunk/test/Sema/ms-inline-asm-invalid-arch.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ms-inline-asm-invalid-arch.c?rev=173364&view=auto
==============================================================================
--- cfe/trunk/test/Sema/ms-inline-asm-invalid-arch.c (added)
+++ cfe/trunk/test/Sema/ms-inline-asm-invalid-arch.c Thu Jan 24 14:24:34 2013
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 %s -triple powerpc64-unknown-linux-gnu -fasm-blocks -verify -fsyntax-only
+
+void f() {
+  __asm nop // expected-error {{Unsupported architecture 'powerpc64' for MS-style inline assembly}}
+}





More information about the cfe-commits mailing list