From ae07378ff9bf4af9bdd97a4607437ace4c32b7e7 Mon Sep 17 00:00:00 2001 From: Chad Rosier Date: Thu, 24 Jan 2013 20:24:34 +0000 Subject: [PATCH] [ms-inline asm] Add an error when trying to compile MS-style inline assembly for an unsupported architecture. rdar://13063988 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173364 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ lib/Sema/SemaStmtAsm.cpp | 11 +++++++++-- test/Sema/ms-inline-asm-invalid-arch.c | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/Sema/ms-inline-asm-invalid-arch.c diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index b9d0c98962..74f9b48149 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -5241,6 +5241,8 @@ let CategoryName = "Inline Assembly Issue" in { "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">; diff --git a/lib/Sema/SemaStmtAsm.cpp b/lib/Sema/SemaStmtAsm.cpp index 4646ef7b38..5624a54089 100644 --- a/lib/Sema/SemaStmtAsm.cpp +++ b/lib/Sema/SemaStmtAsm.cpp @@ -580,8 +580,15 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, SmallVector Exprs; SmallVector 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 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, // 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 MAI(TheTarget->createMCAsmInfo(TT)); diff --git a/test/Sema/ms-inline-asm-invalid-arch.c b/test/Sema/ms-inline-asm-invalid-arch.c new file mode 100644 index 0000000000..0870fcb2a7 --- /dev/null +++ b/test/Sema/ms-inline-asm-invalid-arch.c @@ -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}} +} -- 2.40.0