[llvm] r342631 - [IR] Add a boolean field in DILocation to know if a line must covered or not

Calixte Denizet via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 24 10:33:36 PDT 2018


Hi,

I fixed this issue in this patch:
https://reviews.llvm.org/D49853
and the tests:
https://reviews.llvm.org/D49854

Calixte

Le lun. 24 sept. 2018 à 19:01, Eric Christopher <echristo at gmail.com> a
écrit :

> From taking a look at the changes in https://reviews.llvm.org/rL342718 I
> have some concerns about this patch.
>
> (Besides the fact that I'm also not a fan of the new boolean argument to
> DILocation - at a minimum that should be an enum)
>
> One of the changes from that patch has:
>
> // CHECK-NEXT: 1: 1:void func(int K) {}
>
> to
>
> // CHECK-NEXT: -: 1:void func(int K) {}
>
> even though func is still being called - but with no code executed. The
> brace location does provide the knowledge that a function isn't unused
> which we lose as part of this work.
>
> Thoughts from others?
>
> Thanks!
>
> -eric
>
> On Thu, Sep 20, 2018 at 1:54 AM Calixte Denizet via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: calixte
>> Date: Thu Sep 20 01:53:06 2018
>> New Revision: 342631
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=342631&view=rev
>> Log:
>> [IR] Add a boolean field in DILocation to know if a line must covered or
>> not
>>
>> Summary:
>> Some lines have a hit counter where they should not have one.
>> For example, in C++, some cleanup is adding at the end of a scope
>> represented by a '}'.
>> So such a line has a hit counter where a user expects to not have one.
>> The goal of the patch is to add this information in DILocation which is
>> used to get the covered lines in GCOVProfiling.cpp.
>> A following patch in clang will add this information when generating IR (
>> https://reviews.llvm.org/D49916).
>>
>> Reviewers: marco-c, davidxl, vsk, javed.absar, rnk
>>
>> Reviewed By: rnk
>>
>> Subscribers: eraman, xur, danielcdh, aprantl, rnk, dblaikie, #debug-info,
>> vsk, llvm-commits, sylvestre.ledru
>>
>> Tags: #debug-info
>>
>> Differential Revision: https://reviews.llvm.org/D49915
>>
>> Added:
>>     llvm/trunk/test/Bitcode/DILocation-implicit-code.ll
>>     llvm/trunk/test/Bitcode/DILocation-implicit-code.ll.bc
>> Modified:
>>     llvm/trunk/docs/SourceLevelDebugging.rst
>>     llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
>>     llvm/trunk/include/llvm/IR/DebugLoc.h
>>     llvm/trunk/include/llvm/IR/Metadata.h
>>     llvm/trunk/lib/AsmParser/LLParser.cpp
>>     llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
>>     llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp
>>     llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
>>     llvm/trunk/lib/IR/AsmWriter.cpp
>>     llvm/trunk/lib/IR/DebugInfoMetadata.cpp
>>     llvm/trunk/lib/IR/DebugLoc.cpp
>>     llvm/trunk/lib/IR/LLVMContextImpl.h
>>     llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
>>     llvm/trunk/test/Assembler/dilocation.ll
>>
>> Modified: llvm/trunk/docs/SourceLevelDebugging.rst
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/SourceLevelDebugging.rst?rev=342631&r1=342630&r2=342631&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/docs/SourceLevelDebugging.rst (original)
>> +++ llvm/trunk/docs/SourceLevelDebugging.rst Thu Sep 20 01:53:06 2018
>> @@ -429,8 +429,23 @@ instruction.  One can extract line numbe
>>      unsigned Line = Loc->getLine();
>>      StringRef File = Loc->getFilename();
>>      StringRef Dir = Loc->getDirectory();
>> +    bool ImplicitCode = Loc->isImplicitCode();
>>    }
>>
>> +When the flag ImplicitCode is true then it means that the Instruction
>> has been
>> +added by the front-end but doesn't correspond to source code written by
>> the user. For example
>> +
>> +.. code-block:: c++
>> +
>> +  if (MyBoolean) {
>> +    MyObject MO;
>> +    ...
>> +  }
>> +
>> +At the end of the scope the MyObject's destructor is called but it isn't
>> written
>> +explicitly. This information is useful to avoid to have counters on
>> brackets when
>> +making code coverage.
>> +
>>  C/C++ global variable information
>>  ---------------------------------
>>
>>
>> Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=342631&r1=342630&r2=342631&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
>> +++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Thu Sep 20 01:53:06
>> 2018
>> @@ -1396,19 +1396,20 @@ class DILocation : public MDNode {
>>    friend class MDNode;
>>
>>    DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
>> -             unsigned Column, ArrayRef<Metadata *> MDs);
>> +             unsigned Column, ArrayRef<Metadata *> MDs, bool
>> ImplicitCode);
>>    ~DILocation() { dropAllReferences(); }
>>
>>    static DILocation *getImpl(LLVMContext &Context, unsigned Line,
>>                               unsigned Column, Metadata *Scope,
>> -                             Metadata *InlinedAt, StorageType Storage,
>> -                             bool ShouldCreate = true);
>> +                             Metadata *InlinedAt, bool ImplicitCode,
>> +                             StorageType Storage, bool ShouldCreate =
>> true);
>>    static DILocation *getImpl(LLVMContext &Context, unsigned Line,
>>                               unsigned Column, DILocalScope *Scope,
>> -                             DILocation *InlinedAt, StorageType Storage,
>> -                             bool ShouldCreate = true) {
>> +                             DILocation *InlinedAt, bool ImplicitCode,
>> +                             StorageType Storage, bool ShouldCreate =
>> true) {
>>      return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
>> -                   static_cast<Metadata *>(InlinedAt), Storage,
>> ShouldCreate);
>> +                   static_cast<Metadata *>(InlinedAt), ImplicitCode,
>> Storage,
>> +                   ShouldCreate);
>>    }
>>
>>    /// With a given unsigned int \p U, use up to 13 bits to represent it.
>> @@ -1437,7 +1438,7 @@ class DILocation : public MDNode {
>>      // Get the raw scope/inlinedAt since it is possible to invoke this on
>>      // a DILocation containing temporary metadata.
>>      return getTemporary(getContext(), getLine(), getColumn(),
>> getRawScope(),
>> -                        getRawInlinedAt());
>> +                        getRawInlinedAt(), isImplicitCode());
>>    }
>>
>>  public:
>> @@ -1446,12 +1447,13 @@ public:
>>
>>    DEFINE_MDNODE_GET(DILocation,
>>                      (unsigned Line, unsigned Column, Metadata *Scope,
>> -                     Metadata *InlinedAt = nullptr),
>> -                    (Line, Column, Scope, InlinedAt))
>> +                     Metadata *InlinedAt = nullptr, bool ImplicitCode =
>> false),
>> +                    (Line, Column, Scope, InlinedAt, ImplicitCode))
>>    DEFINE_MDNODE_GET(DILocation,
>>                      (unsigned Line, unsigned Column, DILocalScope *Scope,
>> -                     DILocation *InlinedAt = nullptr),
>> -                    (Line, Column, Scope, InlinedAt))
>> +                     DILocation *InlinedAt = nullptr,
>> +                     bool ImplicitCode = false),
>> +                    (Line, Column, Scope, InlinedAt, ImplicitCode))
>>
>>    /// Return a (temporary) clone of this.
>>    TempDILocation clone() const { return cloneImpl(); }
>> @@ -1464,6 +1466,15 @@ public:
>>      return cast_or_null<DILocation>(getRawInlinedAt());
>>    }
>>
>> +  /// Check if the location corresponds to an implicit code.
>> +  /// When the ImplicitCode flag is true, it means that the Instruction
>> +  /// with this DILocation has been added by the front-end but it hasn't
>> been
>> +  /// written explicitly by the user (e.g. cleanup stuff in C++ put on a
>> closing
>> +  /// bracket). It's useful for code coverage to not show a counter on
>> "empty"
>> +  /// lines.
>> +  bool isImplicitCode() const { return ImplicitCode; }
>> +  void setImplicitCode(bool ImplicitCode) { this->ImplicitCode =
>> ImplicitCode; }
>> +
>>    DIFile *getFile() const { return getScope()->getFile(); }
>>    StringRef getFilename() const { return getScope()->getFilename(); }
>>    StringRef getDirectory() const { return getScope()->getDirectory(); }
>>
>> Modified: llvm/trunk/include/llvm/IR/DebugLoc.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugLoc.h?rev=342631&r1=342630&r2=342631&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/include/llvm/IR/DebugLoc.h (original)
>> +++ llvm/trunk/include/llvm/IR/DebugLoc.h Thu Sep 20 01:53:06 2018
>> @@ -78,7 +78,8 @@ namespace llvm {
>>      ///
>>      /// FIXME: Remove this.  Users should use DILocation::get().
>>      static DebugLoc get(unsigned Line, unsigned Col, const MDNode *Scope,
>> -                        const MDNode *InlinedAt = nullptr);
>> +                        const MDNode *InlinedAt = nullptr,
>> +                        bool ImplicitCode = false);
>>
>>      enum { ReplaceLastInlinedAt = true };
>>      /// Rebuild the entire inlined-at chain for this instruction so that
>> the top of
>> @@ -112,6 +113,10 @@ namespace llvm {
>>      /// Return \c this as a bar \a MDNode.
>>      MDNode *getAsMDNode() const { return Loc; }
>>
>> +    /// Check if the DebugLoc corresponds to an implicit code.
>> +    bool isImplicitCode() const;
>> +    void setImplicitCode(bool ImplicitCode);
>> +
>>      bool operator==(const DebugLoc &DL) const { return Loc == DL.Loc; }
>>      bool operator!=(const DebugLoc &DL) const { return Loc != DL.Loc; }
>>
>>
>> Modified: llvm/trunk/include/llvm/IR/Metadata.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Metadata.h?rev=342631&r1=342630&r2=342631&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/include/llvm/IR/Metadata.h (original)
>> +++ llvm/trunk/include/llvm/IR/Metadata.h Thu Sep 20 01:53:06 2018
>> @@ -66,9 +66,11 @@ protected:
>>    enum StorageType { Uniqued, Distinct, Temporary };
>>
>>    /// Storage flag for non-uniqued, otherwise unowned, metadata.
>> -  unsigned char Storage;
>> +  unsigned char Storage : 7;
>>    // TODO: expose remaining bits to subclasses.
>>
>> +  unsigned char ImplicitCode : 1;
>> +
>>    unsigned short SubclassData16 = 0;
>>    unsigned SubclassData32 = 0;
>>
>> @@ -80,7 +82,7 @@ public:
>>
>>  protected:
>>    Metadata(unsigned ID, StorageType Storage)
>> -      : SubclassID(ID), Storage(Storage) {
>> +      : SubclassID(ID), Storage(Storage), ImplicitCode(false) {
>>      static_assert(sizeof(*this) == 8, "Metadata fields poorly packed");
>>    }
>>
>>
>> Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=342631&r1=342630&r2=342631&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
>> +++ llvm/trunk/lib/AsmParser/LLParser.cpp Thu Sep 20 01:53:06 2018
>> @@ -4228,18 +4228,21 @@ bool LLParser::ParseSpecializedMDNode(MD
>>    (IsDistinct ? CLASS::getDistinct ARGS : CLASS::get ARGS)
>>
>>  /// ParseDILocationFields:
>> -///   ::= !DILocation(line: 43, column: 8, scope: !5, inlinedAt: !6)
>> +///   ::= !DILocation(line: 43, column: 8, scope: !5, inlinedAt: !6,
>> +///   isImplicitCode: true)
>>  bool LLParser::ParseDILocation(MDNode *&Result, bool IsDistinct) {
>>  #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED)
>>       \
>>    OPTIONAL(line, LineField, );
>>        \
>>    OPTIONAL(column, ColumnField, );
>>        \
>>    REQUIRED(scope, MDField, (/* AllowNull */ false));
>>        \
>> -  OPTIONAL(inlinedAt, MDField, );
>> +  OPTIONAL(inlinedAt, MDField, );
>>       \
>> +  OPTIONAL(isImplicitCode, MDBoolField, (false));
>>    PARSE_MD_FIELDS();
>>  #undef VISIT_MD_FIELDS
>>
>> -  Result = GET_OR_DISTINCT(
>> -      DILocation, (Context, line.Val, column.Val, scope.Val,
>> inlinedAt.Val));
>> +  Result =
>> +      GET_OR_DISTINCT(DILocation, (Context, line.Val, column.Val,
>> scope.Val,
>> +                                   inlinedAt.Val, isImplicitCode.Val));
>>    return false;
>>  }
>>
>>
>> Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=342631&r1=342630&r2=342631&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
>> +++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Thu Sep 20 01:53:06
>> 2018
>> @@ -3516,6 +3516,7 @@ Error BitcodeReader::parseFunctionBody(F
>>
>>        unsigned Line = Record[0], Col = Record[1];
>>        unsigned ScopeID = Record[2], IAID = Record[3];
>> +      bool isImplicitCode = Record.size() == 5 && Record[4];
>>
>>        MDNode *Scope = nullptr, *IA = nullptr;
>>        if (ScopeID) {
>> @@ -3528,7 +3529,7 @@ Error BitcodeReader::parseFunctionBody(F
>>          if (!IA)
>>            return error("Invalid record");
>>        }
>> -      LastLoc = DebugLoc::get(Line, Col, Scope, IA);
>> +      LastLoc = DebugLoc::get(Line, Col, Scope, IA, isImplicitCode);
>>        I->setDebugLoc(LastLoc);
>>        I = nullptr;
>>        continue;
>>
>> Modified: llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp?rev=342631&r1=342630&r2=342631&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp (original)
>> +++ llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp Thu Sep 20 01:53:06
>> 2018
>> @@ -1139,7 +1139,7 @@ Error MetadataLoader::MetadataLoaderImpl
>>      break;
>>    }
>>    case bitc::METADATA_LOCATION: {
>> -    if (Record.size() != 5)
>> +    if (Record.size() != 6)
>>        return error("Invalid record");
>>
>>      IsDistinct = Record[0];
>> @@ -1147,8 +1147,10 @@ Error MetadataLoader::MetadataLoaderImpl
>>      unsigned Column = Record[2];
>>      Metadata *Scope = getMD(Record[3]);
>>      Metadata *InlinedAt = getMDOrNull(Record[4]);
>> +    bool ImplicitCode = Record[5];
>>      MetadataList.assignValue(
>> -        GET_OR_DISTINCT(DILocation, (Context, Line, Column, Scope,
>> InlinedAt)),
>> +        GET_OR_DISTINCT(DILocation, (Context, Line, Column, Scope,
>> InlinedAt,
>> +                                     ImplicitCode)),
>>          NextMetadataNo);
>>      NextMetadataNo++;
>>      break;
>>
>> Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=342631&r1=342630&r2=342631&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
>> +++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Thu Sep 20 01:53:06
>> 2018
>> @@ -1403,6 +1403,7 @@ unsigned ModuleBitcodeWriter::createDILo
>>    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
>>    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
>>    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
>> +  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
>>    return Stream.EmitAbbrev(std::move(Abbv));
>>  }
>>
>> @@ -1417,6 +1418,7 @@ void ModuleBitcodeWriter::writeDILocatio
>>    Record.push_back(N->getColumn());
>>    Record.push_back(VE.getMetadataID(N->getScope()));
>>    Record.push_back(VE.getMetadataOrNullID(N->getInlinedAt()));
>> +  Record.push_back(N->isImplicitCode());
>>
>>    Stream.EmitRecord(bitc::METADATA_LOCATION, Record, Abbrev);
>>    Record.clear();
>> @@ -3093,6 +3095,7 @@ void ModuleBitcodeWriter::writeFunction(
>>        Vals.push_back(DL->getColumn());
>>        Vals.push_back(VE.getMetadataOrNullID(DL->getScope()));
>>        Vals.push_back(VE.getMetadataOrNullID(DL->getInlinedAt()));
>> +      Vals.push_back(DL->isImplicitCode());
>>        Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals);
>>        Vals.clear();
>>
>>
>> Modified: llvm/trunk/lib/IR/AsmWriter.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=342631&r1=342630&r2=342631&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/IR/AsmWriter.cpp (original)
>> +++ llvm/trunk/lib/IR/AsmWriter.cpp Thu Sep 20 01:53:06 2018
>> @@ -1754,6 +1754,8 @@ static void writeDILocation(raw_ostream
>>    Printer.printInt("column", DL->getColumn());
>>    Printer.printMetadata("scope", DL->getRawScope(), /* ShouldSkipNull */
>> false);
>>    Printer.printMetadata("inlinedAt", DL->getRawInlinedAt());
>> +  Printer.printBool("isImplicitCode", DL->isImplicitCode(),
>> +                    /* Default */ false);
>>    Out << ")";
>>  }
>>
>>
>> Modified: llvm/trunk/lib/IR/DebugInfoMetadata.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfoMetadata.cpp?rev=342631&r1=342630&r2=342631&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/IR/DebugInfoMetadata.cpp (original)
>> +++ llvm/trunk/lib/IR/DebugInfoMetadata.cpp Thu Sep 20 01:53:06 2018
>> @@ -23,7 +23,8 @@
>>  using namespace llvm;
>>
>>  DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned
>> Line,
>> -                       unsigned Column, ArrayRef<Metadata *> MDs)
>> +                       unsigned Column, ArrayRef<Metadata *> MDs,
>> +                       bool ImplicitCode)
>>      : MDNode(C, DILocationKind, Storage, MDs) {
>>    assert((MDs.size() == 1 || MDs.size() == 2) &&
>>           "Expected a scope and optional inlined-at");
>> @@ -33,6 +34,8 @@ DILocation::DILocation(LLVMContext &C, S
>>
>>    SubclassData32 = Line;
>>    SubclassData16 = Column;
>> +
>> +  setImplicitCode(ImplicitCode);
>>  }
>>
>>  static void adjustColumn(unsigned &Column) {
>> @@ -43,15 +46,15 @@ static void adjustColumn(unsigned &Colum
>>
>>  DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
>>                                  unsigned Column, Metadata *Scope,
>> -                                Metadata *InlinedAt, StorageType Storage,
>> -                                bool ShouldCreate) {
>> +                                Metadata *InlinedAt, bool ImplicitCode,
>> +                                StorageType Storage, bool ShouldCreate) {
>>    // Fixup column.
>>    adjustColumn(Column);
>>
>>    if (Storage == Uniqued) {
>> -    if (auto *N =
>> -            getUniqued(Context.pImpl->DILocations,
>> -                       DILocationInfo::KeyTy(Line, Column, Scope,
>> InlinedAt)))
>> +    if (auto *N = getUniqued(Context.pImpl->DILocations,
>> +                             DILocationInfo::KeyTy(Line, Column, Scope,
>> +                                                   InlinedAt,
>> ImplicitCode)))
>>        return N;
>>      if (!ShouldCreate)
>>        return nullptr;
>> @@ -63,8 +66,8 @@ DILocation *DILocation::getImpl(LLVMCont
>>    Ops.push_back(Scope);
>>    if (InlinedAt)
>>      Ops.push_back(InlinedAt);
>> -  return storeImpl(new (Ops.size())
>> -                       DILocation(Context, Storage, Line, Column, Ops),
>> +  return storeImpl(new (Ops.size()) DILocation(Context, Storage, Line,
>> Column,
>> +                                               Ops, ImplicitCode),
>>                     Storage, Context.pImpl->DILocations);
>>  }
>>
>>
>> Modified: llvm/trunk/lib/IR/DebugLoc.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugLoc.cpp?rev=342631&r1=342630&r2=342631&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/IR/DebugLoc.cpp (original)
>> +++ llvm/trunk/lib/IR/DebugLoc.cpp Thu Sep 20 01:53:06 2018
>> @@ -56,15 +56,28 @@ DebugLoc DebugLoc::getFnDebugLoc() const
>>    return DebugLoc();
>>  }
>>
>> +bool DebugLoc::isImplicitCode() const {
>> +  if (DILocation *Loc = get()) {
>> +    return Loc->isImplicitCode();
>> +  }
>> +  return true;
>> +}
>> +
>> +void DebugLoc::setImplicitCode(bool ImplicitCode) {
>> +  if (DILocation *Loc = get()) {
>> +    Loc->setImplicitCode(ImplicitCode);
>> +  }
>> +}
>> +
>>  DebugLoc DebugLoc::get(unsigned Line, unsigned Col, const MDNode *Scope,
>> -                       const MDNode *InlinedAt) {
>> +                       const MDNode *InlinedAt, bool ImplicitCode) {
>>    // If no scope is available, this is an unknown location.
>>    if (!Scope)
>>      return DebugLoc();
>>
>>    return DILocation::get(Scope->getContext(), Line, Col,
>>                           const_cast<MDNode *>(Scope),
>> -                         const_cast<MDNode *>(InlinedAt));
>> +                         const_cast<MDNode *>(InlinedAt), ImplicitCode);
>>  }
>>
>>  DebugLoc DebugLoc::appendInlinedAt(DebugLoc DL, DILocation *InlinedAt,
>>
>> Modified: llvm/trunk/lib/IR/LLVMContextImpl.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContextImpl.h?rev=342631&r1=342630&r2=342631&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/IR/LLVMContextImpl.h (original)
>> +++ llvm/trunk/lib/IR/LLVMContextImpl.h Thu Sep 20 01:53:06 2018
>> @@ -280,21 +280,24 @@ template <> struct MDNodeKeyImpl<DILocat
>>    unsigned Column;
>>    Metadata *Scope;
>>    Metadata *InlinedAt;
>> +  bool ImplicitCode;
>>
>>    MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
>> -                Metadata *InlinedAt)
>> -      : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {}
>> +                Metadata *InlinedAt, bool ImplicitCode)
>> +      : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt),
>> +        ImplicitCode(ImplicitCode) {}
>>    MDNodeKeyImpl(const DILocation *L)
>>        : Line(L->getLine()), Column(L->getColumn()),
>> Scope(L->getRawScope()),
>> -        InlinedAt(L->getRawInlinedAt()) {}
>> +        InlinedAt(L->getRawInlinedAt()),
>> ImplicitCode(L->isImplicitCode()) {}
>>
>>    bool isKeyOf(const DILocation *RHS) const {
>>      return Line == RHS->getLine() && Column == RHS->getColumn() &&
>> -           Scope == RHS->getRawScope() && InlinedAt ==
>> RHS->getRawInlinedAt();
>> +           Scope == RHS->getRawScope() && InlinedAt ==
>> RHS->getRawInlinedAt() &&
>> +           ImplicitCode == RHS->isImplicitCode();
>>    }
>>
>>    unsigned getHashValue() const {
>> -    return hash_combine(Line, Column, Scope, InlinedAt);
>> +    return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode);
>>    }
>>  };
>>
>>
>> Modified: llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp?rev=342631&r1=342630&r2=342631&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp (original)
>> +++ llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp Thu Sep
>> 20 01:53:06 2018
>> @@ -593,7 +593,8 @@ void GCOVProfiler::emitProfileNotes() {
>>              continue;
>>
>>            // Artificial lines such as calls to the global constructors.
>> -          if (Loc.getLine() == 0) continue;
>> +          if (Loc.getLine() == 0 || Loc.isImplicitCode())
>> +            continue;
>>
>>            if (Line == Loc.getLine()) continue;
>>            Line = Loc.getLine();
>>
>> Modified: llvm/trunk/test/Assembler/dilocation.ll
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/dilocation.ll?rev=342631&r1=342630&r2=342631&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/test/Assembler/dilocation.ll (original)
>> +++ llvm/trunk/test/Assembler/dilocation.ll Thu Sep 20 01:53:06 2018
>> @@ -1,10 +1,10 @@
>>  ; RUN: llvm-as < %s | llvm-dis | FileCheck %s
>>  ; RUN: verify-uselistorder %s
>>
>> -; CHECK: !named = !{!0, !2, !3, !3, !4, !4, !5, !5, !6}
>> -!named = !{!0, !2, !3, !4, !5, !6, !7, !8, !9}
>> +; CHECK: !named = !{!0, !2, !3, !3, !4, !4, !5, !5, !6, !7, !8}
>> +!named = !{!0, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11}
>>
>> -!llvm.module.flags = !{!10}
>> +!llvm.module.flags = !{!12}
>>  !llvm.dbg.cu = !{!1}
>>
>>  ; CHECK: !0 = distinct !DISubprogram(
>> @@ -32,4 +32,9 @@
>>  ; CHECK-NEXT: !6 = !DILocation(line: 4294967295, column: 65535, scope:
>> !0)
>>  !9 = !DILocation(line: 4294967295, column: 65535, scope: !0)
>>
>> -!10 = !{i32 2, !"Debug Info Version", i32 3}
>> +!10 = !DILocation(scope: !0, column: 0, line: 0, isImplicitCode: true)
>> +!11 = !DILocation(scope: !0, column: 0, line: 1, isImplicitCode: false)
>> +; CHECK-NEXT: !7 = !DILocation(line: 0, scope: !0, isImplicitCode: true)
>> +; CHECK-NEXT: !8 = !DILocation(line: 1, scope: !0)
>> +
>> +!12 = !{i32 2, !"Debug Info Version", i32 3}
>>
>> Added: llvm/trunk/test/Bitcode/DILocation-implicit-code.ll
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/DILocation-implicit-code.ll?rev=342631&view=auto
>>
>> ==============================================================================
>> --- llvm/trunk/test/Bitcode/DILocation-implicit-code.ll (added)
>> +++ llvm/trunk/test/Bitcode/DILocation-implicit-code.ll Thu Sep 20
>> 01:53:06 2018
>> @@ -0,0 +1,190 @@
>> +; RUN: llvm-dis %s.bc -o - | FileCheck %s
>> +; ModuleID = 'DILocation-implicit-code.cpp'
>> +source_filename = "DILocation-implicit-code.cpp"
>> +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
>> +target triple = "x86_64-unknown-linux-gnu"
>> +
>> +%struct.A = type { i8 }
>> +
>> +$_ZN1AC2Ev = comdat any
>> +
>> +$_ZN1A3fooEi = comdat any
>> +
>> + at _ZTIi = external dso_local constant i8*
>> +
>> +; Function Attrs: noinline optnone uwtable
>> +define dso_local void @_Z5test1v() #0 personality i8* bitcast (i32
>> (...)* @__gxx_personality_v0 to i8*) !dbg !7 {
>> +entry:
>> +  %retval = alloca %struct.A, align 1
>> +  %a = alloca %struct.A, align 1
>> +  %exn.slot = alloca i8*
>> +  %ehselector.slot = alloca i32
>> +  %undef.agg.tmp = alloca %struct.A, align 1
>> +  %e = alloca i32, align 4
>> +  %undef.agg.tmp3 = alloca %struct.A, align 1
>> +  call void @_ZN1AC2Ev(%struct.A* %a), !dbg !9
>> +  invoke void @_ZN1A3fooEi(%struct.A* %a, i32 0)
>> +          to label %invoke.cont unwind label %lpad, !dbg !10
>> +
>> +invoke.cont:                                      ; preds = %entry
>> +  br label %return, !dbg !11
>> +
>> +lpad:                                             ; preds = %entry
>> +  %0 = landingpad { i8*, i32 }
>> +          catch i8* bitcast (i8** @_ZTIi to i8*), !dbg !12
>> +  %1 = extractvalue { i8*, i32 } %0, 0, !dbg !12
>> +  store i8* %1, i8** %exn.slot, align 8, !dbg !12
>> +  %2 = extractvalue { i8*, i32 } %0, 1, !dbg !12
>> +  store i32 %2, i32* %ehselector.slot, align 4, !dbg !12
>> +  br label %catch.dispatch, !dbg !12
>> +
>> +catch.dispatch:                                   ; preds = %lpad
>> +  %sel = load i32, i32* %ehselector.slot, align 4, !dbg !13
>> +  %3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*))
>> #4, !dbg !13
>> +  %matches = icmp eq i32 %sel, %3, !dbg !13
>> +  br i1 %matches, label %catch, label %eh.resume, !dbg !13
>> +
>> +catch:                                            ; preds =
>> %catch.dispatch
>> +  %exn = load i8*, i8** %exn.slot, align 8, !dbg !13
>> +  %4 = call i8* @__cxa_begin_catch(i8* %exn) #4, !dbg !13
>> +  %5 = bitcast i8* %4 to i32*, !dbg !13
>> +  %6 = load i32, i32* %5, align 4, !dbg !13
>> +  store i32 %6, i32* %e, align 4, !dbg !13
>> +  %7 = load i32, i32* %e, align 4, !dbg !14
>> +  invoke void @_ZN1A3fooEi(%struct.A* %a, i32 %7)
>> +          to label %invoke.cont2 unwind label %lpad1, !dbg !15
>> +
>> +invoke.cont2:                                     ; preds = %catch
>> +  call void @__cxa_end_catch() #4, !dbg !16
>> +  br label %return
>> +
>> +lpad1:                                            ; preds = %catch
>> +  %8 = landingpad { i8*, i32 }
>> +          cleanup, !dbg !12
>> +  %9 = extractvalue { i8*, i32 } %8, 0, !dbg !12
>> +  store i8* %9, i8** %exn.slot, align 8, !dbg !12
>> +  %10 = extractvalue { i8*, i32 } %8, 1, !dbg !12
>> +  store i32 %10, i32* %ehselector.slot, align 4, !dbg !12
>> +  call void @__cxa_end_catch() #4, !dbg !16
>> +  br label %eh.resume, !dbg !16
>> +
>> +try.cont:                                         ; No predecessors!
>> +  call void @llvm.trap(), !dbg !16
>> +  unreachable, !dbg !16
>> +
>> +return:                                           ; preds =
>> %invoke.cont2, %invoke.cont
>> +  ret void, !dbg !12
>> +
>> +eh.resume:                                        ; preds = %lpad1,
>> %catch.dispatch
>> +  %exn4 = load i8*, i8** %exn.slot, align 8, !dbg !13
>> +  %sel5 = load i32, i32* %ehselector.slot, align 4, !dbg !13
>> +  %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn4, 0, !dbg !13
>> +  %lpad.val6 = insertvalue { i8*, i32 } %lpad.val, i32 %sel5, 1, !dbg !13
>> +  resume { i8*, i32 } %lpad.val6, !dbg !13
>> +}
>> +
>> +; Function Attrs: noinline nounwind optnone uwtable
>> +define linkonce_odr dso_local void @_ZN1AC2Ev(%struct.A* %this)
>> unnamed_addr #1 comdat align 2 !dbg !17 {
>> +entry:
>> +  %this.addr = alloca %struct.A*, align 8
>> +  store %struct.A* %this, %struct.A** %this.addr, align 8
>> +  %this1 = load %struct.A*, %struct.A** %this.addr, align 8
>> +  ret void, !dbg !18
>> +}
>> +
>> +; Function Attrs: noinline optnone uwtable
>> +define linkonce_odr dso_local void @_ZN1A3fooEi(%struct.A* %this, i32
>> %i) #0 comdat align 2 !dbg !19 {
>> +entry:
>> +  %retval = alloca %struct.A, align 1
>> +  %this.addr = alloca %struct.A*, align 8
>> +  %i.addr = alloca i32, align 4
>> +  store %struct.A* %this, %struct.A** %this.addr, align 8
>> +  store i32 %i, i32* %i.addr, align 4
>> +  %this1 = load %struct.A*, %struct.A** %this.addr, align 8
>> +  %0 = load i32, i32* %i.addr, align 4, !dbg !20
>> +  %cmp = icmp eq i32 %0, 0, !dbg !21
>> +  br i1 %cmp, label %if.then, label %if.end, !dbg !20
>> +
>> +if.then:                                          ; preds = %entry
>> +  %exception = call i8* @__cxa_allocate_exception(i64 4) #4, !dbg !22
>> +  %1 = bitcast i8* %exception to i32*, !dbg !22
>> +  store i32 1, i32* %1, align 16, !dbg !22
>> +  call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to
>> i8*), i8* null) #5, !dbg !22
>> +  unreachable, !dbg !22
>> +
>> +if.end:                                           ; preds = %entry
>> +  ret void, !dbg !23
>> +}
>> +
>> +declare dso_local i32 @__gxx_personality_v0(...)
>> +
>> +; Function Attrs: nounwind readnone
>> +declare i32 @llvm.eh.typeid.for(i8*) #2
>> +
>> +declare dso_local i8* @__cxa_begin_catch(i8*)
>> +
>> +declare dso_local void @__cxa_end_catch()
>> +
>> +; Function Attrs: noreturn nounwind
>> +declare void @llvm.trap() #3
>> +
>> +; Function Attrs: noinline optnone uwtable
>> +define dso_local void @_Z5test2v() #0 !dbg !24 {
>> +entry:
>> +  %a = alloca %struct.A, align 1
>> +  %b = alloca %struct.A, align 1
>> +  %undef.agg.tmp = alloca %struct.A, align 1
>> +  call void @_ZN1AC2Ev(%struct.A* %a), !dbg !25
>> +  call void @_ZN1A3fooEi(%struct.A* %a, i32 1), !dbg !26
>> +  ret void, !dbg !27
>> +}
>> +
>> +declare dso_local i8* @__cxa_allocate_exception(i64)
>> +
>> +declare dso_local void @__cxa_throw(i8*, i8*, i8*)
>> +
>> +attributes #0 = { noinline optnone uwtable
>> "correctly-rounded-divide-sqrt-fp-math"="false"
>> "disable-tail-calls"="false" "less-precise-fpmad"="false"
>> "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"
>> "no-infs-fp-math"="false" "no-jump-tables"="false"
>> "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false"
>> "no-trapping-math"="false" "stack-protector-buffer-size"="8"
>> "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87"
>> "unsafe-fp-math"="false" "use-soft-float"="false" }
>> +attributes #1 = { noinline nounwind optnone uwtable
>> "correctly-rounded-divide-sqrt-fp-math"="false"
>> "disable-tail-calls"="false" "less-precise-fpmad"="false"
>> "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"
>> "no-infs-fp-math"="false" "no-jump-tables"="false"
>> "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false"
>> "no-trapping-math"="false" "stack-protector-buffer-size"="8"
>> "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87"
>> "unsafe-fp-math"="false" "use-soft-float"="false" }
>> +attributes #2 = { nounwind readnone }
>> +attributes #3 = { noreturn nounwind }
>> +attributes #4 = { nounwind }
>> +attributes #5 = { noreturn }
>> +
>> +!llvm.dbg.cu = !{!0}
>> +!llvm.module.flags = !{!3, !4, !5}
>> +!llvm.ident = !{!6}
>> +
>> +; CHECK: !DILocation(line: 20, column: 1, scope: !{{[0-9]+}},
>> isImplicitCode: true)
>> +; CHECK: !DILocation(line: 17, column: 5, scope: !{{[0-9]+}},
>> isImplicitCode: true)
>> +; CHECK: !DILocation(line: 19, column: 5, scope: !{{[0-9]+}},
>> isImplicitCode: true)
>> +; CHECK: !DILocation(line: 3, column: 10, scope: !{{[0-9]+}},
>> isImplicitCode: true)
>> +; CHECK: !DILocation(line: 25, column: 1, scope: !{{[0-9]+}},
>> isImplicitCode: true)
>> +
>> +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1,
>> producer: "clang version 8.0.0 (trunk 342445)", isOptimized: false,
>> runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2, nameTableKind:
>> None)
>> +!1 = !DIFile(filename: "DILocation-implicit-code.cpp", directory: "/tmp")
>> +!2 = !{}
>> +!3 = !{i32 2, !"Dwarf Version", i32 4}
>> +!4 = !{i32 2, !"Debug Info Version", i32 3}
>> +!5 = !{i32 1, !"wchar_size", i32 4}
>> +!6 = !{!"clang version 8.0.0 (trunk 342445)"}
>> +!7 = distinct !DISubprogram(name: "test1", scope: !1, file: !1, line:
>> 13, type: !8, isLocal: false, isDefinition: true, scopeLine: 13, flags:
>> DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
>> +!8 = !DISubroutineType(types: !2)
>> +!9 = !DILocation(line: 14, column: 7, scope: !7)
>> +!10 = !DILocation(line: 16, column: 18, scope: !7)
>> +!11 = !DILocation(line: 16, column: 9, scope: !7)
>> +!12 = !DILocation(line: 20, column: 1, scope: !7, isImplicitCode: true)
>> +!13 = !DILocation(line: 17, column: 5, scope: !7, isImplicitCode: true)
>> +!14 = !DILocation(line: 18, column: 22, scope: !7)
>> +!15 = !DILocation(line: 18, column: 18, scope: !7)
>> +!16 = !DILocation(line: 19, column: 5, scope: !7, isImplicitCode: true)
>> +!17 = distinct !DISubprogram(name: "A", scope: !1, file: !1, line: 3,
>> type: !8, isLocal: false, isDefinition: true, scopeLine: 3, flags:
>> DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
>> +!18 = !DILocation(line: 3, column: 10, scope: !17, isImplicitCode: true)
>> +!19 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 4,
>> type: !8, isLocal: false, isDefinition: true, scopeLine: 4, flags:
>> DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
>> +!20 = !DILocation(line: 5, column: 13, scope: !19)
>> +!21 = !DILocation(line: 5, column: 15, scope: !19)
>> +!22 = !DILocation(line: 6, column: 13, scope: !19)
>> +!23 = !DILocation(line: 9, column: 9, scope: !19)
>> +!24 = distinct !DISubprogram(name: "test2", scope: !1, file: !1, line:
>> 22, type: !8, isLocal: false, isDefinition: true, scopeLine: 22, flags:
>> DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
>> +!25 = !DILocation(line: 23, column: 7, scope: !24)
>> +!26 = !DILocation(line: 24, column: 13, scope: !24)
>> +!27 = !DILocation(line: 25, column: 1, scope: !24, isImplicitCode: true)
>>
>> Added: llvm/trunk/test/Bitcode/DILocation-implicit-code.ll.bc
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/DILocation-implicit-code.ll.bc?rev=342631&view=auto
>>
>> ==============================================================================
>> Binary files llvm/trunk/test/Bitcode/DILocation-implicit-code.ll.bc
>> (added) and llvm/trunk/test/Bitcode/DILocation-implicit-code.ll.bc Thu Sep
>> 20 01:53:06 2018 differ
>>
>>
>> _______________________________________________
>> 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/20180924/2c004468/attachment.html>


More information about the llvm-commits mailing list