diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Parse/ParseStmtAsm.cpp | 13 | ||||
-rw-r--r-- | clang/lib/Parse/Parser.cpp | 13 |
2 files changed, 18 insertions, 8 deletions
diff --git a/clang/lib/Parse/ParseStmtAsm.cpp b/clang/lib/Parse/ParseStmtAsm.cpp index 85eff1712d2..8ba9f15f0a4 100644 --- a/clang/lib/Parse/ParseStmtAsm.cpp +++ b/clang/lib/Parse/ParseStmtAsm.cpp @@ -616,10 +616,6 @@ StmtResult Parser::ParseAsmStatement(bool &msAsm) { return ParseMicrosoftAsmStatement(AsmLoc); } - // Check if GNU-style inline Asm is disabled. - if (!getLangOpts().GNUAsm) - Diag(AsmLoc, diag::err_gnu_inline_asm_disabled); - DeclSpec DS(AttrFactory); SourceLocation Loc = Tok.getLocation(); ParseTypeQualifierListOpt(DS, AR_VendorAttributesParsed); @@ -644,6 +640,15 @@ StmtResult Parser::ParseAsmStatement(bool &msAsm) { T.consumeOpen(); ExprResult AsmString(ParseAsmStringLiteral()); + + // Check if GNU-style InlineAsm is disabled. + // Error on anything other than empty string. + if (!(getLangOpts().GNUAsm || AsmString.isInvalid())) { + const auto *SL = cast<StringLiteral>(AsmString.get()); + if (!SL->getString().trim().empty()) + Diag(Loc, diag::err_gnu_inline_asm_disabled); + } + if (AsmString.isInvalid()) { // Consume up to and including the closing paren. T.skipToEnd(); diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index ed27a9e3953..697fda9215d 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -670,12 +670,17 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs, SourceLocation StartLoc = Tok.getLocation(); SourceLocation EndLoc; - // Check if GNU-style InlineAsm is disabled. - if (!getLangOpts().GNUAsm) - Diag(StartLoc, diag::err_gnu_inline_asm_disabled); - ExprResult Result(ParseSimpleAsm(&EndLoc)); + // Check if GNU-style InlineAsm is disabled. + // Empty asm string is allowed because it will not introduce + // any assembly code. + if (!(getLangOpts().GNUAsm || Result.isInvalid())) { + const auto *SL = cast<StringLiteral>(Result.get()); + if (!SL->getString().trim().empty()) + Diag(StartLoc, diag::err_gnu_inline_asm_disabled); + } + ExpectAndConsume(tok::semi, diag::err_expected_after, "top-level asm block"); |