[llvm] r308966 - This patch enables the usage of constant Enum identifiers within Microsoft style inline assembly statements.

Alexander Kornienko via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 26 02:44:11 PDT 2017


FTR, this was reverted in r309005.

On Tue, Jul 25, 2017 at 7:49 PM, Kostya Serebryany via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Hi.
> This patch causes the msan bots to complain. Please fix or revert ASAP.
> http://lab.llvm.org:8011/builders/sanitizer-x86_64-
> linux-fast/builds/6702/steps/check-clang%20msan/logs/stdio
>
> Testing: 0 .. 10..
> FAIL: Clang :: CodeGen/ms_this.cpp (2142 of 11057)
> ******************** TEST 'Clang :: CodeGen/ms_this.cpp' FAILED ********************
> Script:
> --
> /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm_build_msan/./bin/clang -cc1 -internal-isystem /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm_build_msan/lib/clang/6.0.0/include -nostdsysteminc -triple x86_64-pc-win32 -fasm-blocks -emit-llvm /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/CodeGen/ms_this.cpp -o - | /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm_build_msan/./bin/FileCheck /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/CodeGen/ms_this.cpp
> --
> Exit Code: 2
>
> Command Output (stderr):
> --
> ==4713==WARNING: MemorySanitizer: use-of-uninitialized-value
>     #0 0x3143ba3 in (anonymous namespace)::X86AsmParser::ParseIntelIdentifier(llvm::MCExpr const*&, llvm::StringRef&, llvm::InlineAsmIdentifierInfo&, bool, llvm::SMLoc&) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:1664:7
>     #1 0x313f288 in (anonymous namespace)::X86AsmParser::ParseIntelExpression((anonymous namespace)::X86AsmParser::IntelExprStateMachine&, llvm::SMLoc&) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:1440:13
>     #2 0x31389e7 in (anonymous namespace)::X86AsmParser::ParseIntelBracExpression(unsigned int, llvm::SMLoc, long, bool, unsigned int) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:1555:7
>     #3 0x31307f8 in ParseIntelOperand /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:1961:12
>     #4 0x31307f8 in (anonymous namespace)::X86AsmParser::ParseOperand() /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:1225
>     #5 0x3118cda in (anonymous namespace)::X86AsmParser::ParseInstruction(llvm::ParseInstructionInfo&, llvm::StringRef, llvm::SMLoc, llvm::SmallVectorImpl<std::__1::unique_ptr<llvm::MCParsedAsmOperand, std::__1::default_delete<llvm::MCParsedAsmOperand> > >&) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:2510:44
>     #6 0x4bb9a48 in (anonymous namespace)::AsmParser::parseStatement((anonymous namespace)::ParseStatementInfo&, llvm::MCAsmParserSemaCallback*) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/lib/MC/MCParser/AsmParser.cpp:2034:42
>     #7 0x4ba63a3 in (anonymous namespace)::AsmParser::parseMSInlineAsm(void*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, unsigned int&, unsigned int&, llvm::SmallVectorImpl<std::__1::pair<void*, bool> >&, llvm::SmallVectorImpl<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >&, llvm::SmallVectorImpl<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >&, llvm::MCInstrInfo const*, llvm::MCInstPrinter const*, llvm::MCAsmParserSemaCallback&) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/lib/MC/MCParser/AsmParser.cpp:5343:25
>     #8 0x82f1100 in clang::Parser::ParseMicrosoftAsmStatement(clang::SourceLocation) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseStmtAsm.cpp:619:15
>     #9 0x82f6310 in clang::Parser::ParseAsmStatement(bool&) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseStmtAsm.cpp:682:12
>     #10 0x82d15d9 in clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::AllowedConstructsKind, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseStmt.cpp:277:11
>     #11 0x82cfff1 in clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::AllowedConstructsKind, clang::SourceLocation*) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseStmt.cpp:110:20
>     #12 0x82e677b in clang::Parser::ParseCompoundStatementBody(bool) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseStmt.cpp:1001:11
>     #13 0x82e859f in clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseStmt.cpp:1967:21
>     #14 0x811b151 in clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/Parser.cpp:1214:10
>     #15 0x8167f18 in clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, unsigned int, clang::SourceLocation*, clang::Parser::ForRangeInit*) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseDecl.cpp:1953:11
>     #16 0x8118d8c in clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/Parser.cpp:981:10
>     #17 0x8117646 in clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/Parser.cpp:997:12
>     #18 0x8114428 in clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/Parser.cpp:847:12
>     #19 0x8110552 in clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/Parser.cpp:615:12
>     #20 0x8101168 in clang::ParseAST(clang::Sema&, bool, bool) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseAST.cpp:147:18
>     #21 0x65ab84a in clang::FrontendAction::Execute() /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:902:8
>     #22 0x64e936c in clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:980:11
>     #23 0x6786441 in clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:251:25
>     #24 0x98efea in cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/tools/driver/cc1_main.cpp:221:13
>     #25 0x988444 in ExecuteCC1Tool /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/tools/driver/driver.cpp:306:12
>     #26 0x988444 in main /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/tools/driver/driver.cpp:387
>
>
> On Tue, Jul 25, 2017 at 3:44 AM, Matan Haroush via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: mharoush
>> Date: Tue Jul 25 03:44:09 2017
>> New Revision: 308966
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=308966&view=rev
>> Log:
>> This patch enables the usage of constant Enum identifiers within
>> Microsoft style inline assembly statements.
>>
>> Differential Revision:
>> https://reviews.llvm.org/D33277
>> https://reviews.llvm.org/D33278
>>
>>
>> Modified:
>>     llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h
>>     llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
>>
>> Modified: llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/
>> MC/MCParser/MCAsmParser.h?rev=308966&r1=308965&r2=308966&view=diff
>> ============================================================
>> ==================
>> --- llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h (original)
>> +++ llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h Tue Jul 25
>> 03:44:09 2017
>> @@ -35,17 +35,30 @@ class MCTargetAsmParser;
>>  class SourceMgr;
>>
>>  class InlineAsmIdentifierInfo {
>> +private:
>> +  enum IdDeclKind : uint8_t {
>> +    Default,
>> +    Variable,
>> +    ConstEnum,
>> +  };
>> +  IdDeclKind Kind;
>> +
>>  public:
>>    void *OpDecl;
>> -  bool IsVarDecl;
>>    unsigned Length, Size, Type;
>> -
>> +  APInt ConstIntValue;
>> +  bool isVarDecl() { return Kind == Variable; }
>> +  bool isConstEnum() { return Kind == ConstEnum; }
>> +  void setKindVariable() { Kind = Variable; }
>> +  void setKindConstEnum() { Kind = ConstEnum; }
>>    void clear() {
>>      OpDecl = nullptr;
>> -    IsVarDecl = false;
>> +    Kind = Default;
>>      Length = 1;
>>      Size = 0;
>>      Type = 0;
>> +    // On clear flush possibly old APInt value as a precaution;
>> +    ConstIntValue = APInt();
>>    }
>>  };
>>
>>
>> Modified: llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X8
>> 6/AsmParser/X86AsmParser.cpp?rev=308966&r1=308965&r2=308966&view=diff
>> ============================================================
>> ==================
>> --- llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp (original)
>> +++ llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp Tue Jul 25
>> 03:44:09 2017
>> @@ -749,7 +749,7 @@ private:
>>    std::unique_ptr<X86Operand> ParseIntelOffsetOfOperator();
>>    bool ParseIntelDotOperator(const MCExpr *Disp, const MCExpr *&NewDisp);
>>    unsigned IdentifyIntelOperator(StringRef Name);
>> -  unsigned ParseIntelOperator(unsigned OpKind);
>> +  unsigned ParseIntelOperator(unsigned OpKind, bool AddImmPrefix);
>>    std::unique_ptr<X86Operand>
>>    ParseIntelSegmentOverride(unsigned SegReg, SMLoc Start, unsigned
>> Size);
>>    std::unique_ptr<X86Operand> ParseRoundingModeOp(SMLoc Start, SMLoc
>> End);
>> @@ -1223,7 +1223,7 @@ std::unique_ptr<X86Operand> X86AsmParser
>>      InlineAsmIdentifierInfo &Info, bool AllowBetterSizeMatch) {
>>    // If we found a decl other than a VarDecl, then assume it is a
>> FuncDecl or
>>    // some other label reference.
>> -  if (isa<MCSymbolRefExpr>(Disp) && Info.OpDecl && !Info.IsVarDecl) {
>> +  if (isa<MCSymbolRefExpr>(Disp) && Info.OpDecl && !Info.isVarDecl()) {
>>      // Insert an explicit size if the user didn't have one.
>>      if (!Size) {
>>        Size = getPointerWidth();
>> @@ -1397,7 +1397,7 @@ bool X86AsmParser::ParseIntelExpression(
>>          if (OpKind == IOK_OFFSET)
>>            return Error(IdentLoc, "Dealing OFFSET operator as part of"
>>              "a compound immediate expression is yet to be supported");
>> -        int64_t Val = ParseIntelOperator(OpKind);
>> +        int64_t Val = ParseIntelOperator(OpKind,SM.getAddImmPrefix());
>>          if (!Val)
>>            return true;
>>          StringRef ErrMsg;
>> @@ -1407,11 +1407,38 @@ bool X86AsmParser::ParseIntelExpression(
>>              PrevTK == AsmToken::RBrac) {
>>            return false;
>>        } else {
>> -        InlineAsmIdentifierInfo &Info = SM.getIdentifierInfo();
>> -        if (ParseIntelIdentifier(Val, Identifier, Info,
>> +        InlineAsmIdentifierInfo Info;
>> +        if (ParseIntelIdentifier(Val, Identifier, Info,
>>                                   /*Unevaluated=*/false, End))
>> -          return true;
>> -        SM.onIdentifierExpr(Val, Identifier);
>> +          return true;
>> +        // Check if the parsed identifier was a constant Integer. Here we
>> +        // assume Val is of type MCConstantExpr only when it is safe to
>> replace
>> +        // the identifier with its constant value.
>> +        if (const MCConstantExpr *CE =
>> +                dyn_cast_or_null<const MCConstantExpr>(Val)) {
>> +          StringRef ErrMsg;
>> +          // Pass the enum identifier integer value to the SM calculator.
>> +          if (SM.onInteger(CE->getValue(), ErrMsg))
>> +            return Error(IdentLoc, ErrMsg);
>> +          // Match the behavior of integer tokens when getAddImmPrefix
>> flag is
>> +          // set.
>> +          if (SM.getAddImmPrefix()) {
>> +            assert(isParsingInlineAsm() &&
>> +                   "Expected to be parsing inline assembly.");
>> +            // A single rewrite of the integer value is preformed for
>> each enum
>> +            // identifier. This is only done when we are inside a
>> bracketed
>> +            // expression.
>> +            size_t Len = End.getPointer() - IdentLoc.getPointer();
>> +            InstInfo->AsmRewrites->emplace_back(AOK_Imm, IdentLoc, Len,
>> +                                                CE->getValue());
>> +            break;
>> +          }
>> +        } else {
>> +          // Notify the SM a variable identifier was found.
>> +          InlineAsmIdentifierInfo &SMInfo = SM.getIdentifierInfo();
>> +          SMInfo = Info;
>> +          SM.onIdentifierExpr(Val, Identifier);
>> +        }
>>        }
>>        break;
>>      }
>> @@ -1599,6 +1626,14 @@ bool X86AsmParser::ParseIntelIdentifier(
>>    assert((End.getPointer() == EndPtr || !Result) &&
>>           "frontend claimed part of a token?");
>>
>> +  // Check if the search yielded a constant integer (enum identifier).
>> +  if (Result && Info.isConstEnum()) {
>> +    // By creating MCConstantExpr we let the user of Val know it is safe
>> +    // to use as an explicit constant with value = ConstVal.
>> +    Val = MCConstantExpr::create(Info.ConstIntValue.getSExtValue(),
>> +                                 getParser().getContext());
>> +    return false;
>> +  }
>>    // If the identifier lookup was unsuccessful, assume that we are
>> dealing with
>>    // a label.
>>    if (!Result) {
>> @@ -1796,7 +1831,7 @@ unsigned X86AsmParser::IdentifyIntelOper
>>  /// variable.  A variable's size is the product of its LENGTH and TYPE.
>> The
>>  /// TYPE operator returns the size of a C or C++ type or variable. If the
>>  /// variable is an array, TYPE returns the size of a single element.
>> -unsigned X86AsmParser::ParseIntelOperator(unsigned OpKind) {
>> +unsigned X86AsmParser::ParseIntelOperator(unsigned OpKind, bool
>> AddImmPrefix) {
>>    MCAsmParser &Parser = getParser();
>>    const AsmToken &Tok = Parser.getTok();
>>    SMLoc TypeLoc = Tok.getLoc();
>> @@ -1822,12 +1857,17 @@ unsigned X86AsmParser::ParseIntelOperato
>>    case IOK_SIZE: CVal = Info.Size; break;
>>    case IOK_TYPE: CVal = Info.Type; break;
>>    }
>> -
>> -  // Rewrite the type operator and the C or C++ type or variable in
>> terms of an
>> -  // immediate.  E.g. TYPE foo -> $$4
>> -  unsigned Len = End.getPointer() - TypeLoc.getPointer();
>> -  InstInfo->AsmRewrites->emplace_back(AOK_Imm, TypeLoc, Len, CVal);
>> -
>> +
>> +  // Only when in bracketed mode, preform explicit rewrite. This is
>> requierd to
>> +  // avoid rewrite collision.
>> +  if (AddImmPrefix) {
>> +    // Rewrite the type operator and the C or C++ type or variable in
>> terms of
>> +    // an immediate. e.g. mov eax, [eax + SIZE _foo * $$4] ->
>> +    // mov eax, [eax + $$1 * $$4].
>> +    unsigned Len = End.getPointer() - TypeLoc.getPointer();
>> +    InstInfo->AsmRewrites->emplace_back(AOK_Imm, TypeLoc, Len, CVal);
>> +  }
>> +
>>    return CVal;
>>  }
>>
>> @@ -1898,14 +1938,8 @@ std::unique_ptr<X86Operand> X86AsmParser
>>    if (SM.getSym() && SM.getSym()->getKind() == MCExpr::Constant)
>>      SM.getSym()->evaluateAsAbsolute(Imm);
>>
>> -  if (StartTok.isNot(AsmToken::Identifier) &&
>> -      StartTok.isNot(AsmToken::String) && isParsingInlineAsm()) {
>> +  if (isParsingInlineAsm() && !isSymbol) {
>>      unsigned Len = Tok.getLoc().getPointer() - Start.getPointer();
>> -    if (StartTok.getString().size() == Len)
>> -      // Just add a prefix if this wasn't a complex immediate expression.
>> -      InstInfo->AsmRewrites->emplace_back(AOK_ImmPrefix, Start);
>> -    else
>> -      // Otherwise, rewrite the complex expression as a single immediate.
>>        InstInfo->AsmRewrites->emplace_back(AOK_Imm, Start, Len, Imm);
>>    }
>>
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170726/36f7c3c1/attachment.html>


More information about the llvm-commits mailing list