From c69164917460ff717fd0b02649a3d7b0c5096088 Mon Sep 17 00:00:00 2001 From: Chad Rosier Date: Thu, 6 Sep 2012 19:56:25 +0000 Subject: [PATCH] [ms-inline asm] Output empty asm statements for the directives we don't handle. Otherwise, the AsmParser will explode if we try to generate an object files. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163345 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaStmtAsm.cpp | 17 +++++++---------- test/CodeGen/ms-inline-asm.c | 9 +++++++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/Sema/SemaStmtAsm.cpp b/lib/Sema/SemaStmtAsm.cpp index c6432ddc66..5cab02d924 100644 --- a/lib/Sema/SemaStmtAsm.cpp +++ b/lib/Sema/SemaStmtAsm.cpp @@ -454,11 +454,11 @@ static std::string buildMSAsmString(Sema &SemaRef, ArrayRef AsmToks, return Res.str(); } -#define DEF_SIMPLE_MSASM \ +#define DEF_SIMPLE_MSASM(STR) \ MSAsmStmt *NS = \ new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, /*IsSimple*/ true, \ /*IsVolatile*/ true, AsmToks, Inputs, Outputs, \ - InputExprs, OutputExprs, AsmString, Constraints, \ + InputExprs, OutputExprs, STR, Constraints, \ Clobbers, EndLoc); StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, @@ -478,11 +478,8 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SmallVector OutputExprNames; // Empty asm statements don't need to instantiate the AsmParser, etc. - if (AsmToks.empty()) { - StringRef AsmString; - DEF_SIMPLE_MSASM; - return Owned(NS); - } + StringRef EmptyAsmStr; + if (AsmToks.empty()) { DEF_SIMPLE_MSASM(EmptyAsmStr); return Owned(NS); } std::vector AsmStrings; std::vector > AsmTokRanges; @@ -495,7 +492,7 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, bool IsSimple = isSimpleMSAsm(Pieces, Context.getTargetInfo()); // AsmParser doesn't fully support these asm statements. - if (bailOnMSAsm(Pieces)) { DEF_SIMPLE_MSASM; return Owned(NS); } + if (bailOnMSAsm(Pieces)) { DEF_SIMPLE_MSASM(EmptyAsmStr); return Owned(NS); } // Initialize targets and assembly printers/parsers. llvm::InitializeAllTargetInfos(); @@ -549,7 +546,7 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, bool HadError = TargetParser->ParseInstruction(OpcodeStr.str(), IDLoc, Operands); // If we had an error parsing the operands, fail gracefully. - if (HadError) { DEF_SIMPLE_MSASM; return Owned(NS); } + if (HadError) { DEF_SIMPLE_MSASM(EmptyAsmStr); return Owned(NS); } // Match the MCInstr. unsigned Kind; @@ -559,7 +556,7 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, ErrorInfo, /*matchingInlineAsm*/ true); // If we had an error parsing the operands, fail gracefully. - if (HadError) { DEF_SIMPLE_MSASM; return Owned(NS); } + if (HadError) { DEF_SIMPLE_MSASM(EmptyAsmStr); return Owned(NS); } // Get the instruction descriptor. llvm::MCInst Inst = Instrs[0]; diff --git a/test/CodeGen/ms-inline-asm.c b/test/CodeGen/ms-inline-asm.c index 0a4e7775cf..43b3013824 100644 --- a/test/CodeGen/ms-inline-asm.c +++ b/test/CodeGen/ms-inline-asm.c @@ -96,6 +96,9 @@ unsigned t10(void) { void t11(void) { __asm EVEN __asm ALIGN +// CHECK: t11 +// CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind +// CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind } void t12(void) { @@ -104,6 +107,8 @@ void t12(void) { _emit 0x43 _emit 0x4B } +// CHECK: t12 +// CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind } void t13(void) { @@ -111,4 +116,8 @@ void t13(void) { __asm LENGTH arr ; sizeof(arr)/sizeof(arr[0]) __asm SIZE arr ; sizeof(arr) __asm TYPE arr ; sizeof(arr[0]) +// CHECK: t13 +// CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind +// CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind +// CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind } -- 2.40.0