[llvm] r342857 - llvm-diff: Fix crash on anonymous functions

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 24 01:37:33 PDT 2018


The test didn't pass for me, as the output was only "in the right
module", I think because the Twine was being stored.  r342864 fixes it
for me.

On Mon, Sep 24, 2018 at 6:42 AM, Matt Arsenault via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: arsenm
> Date: Sun Sep 23 21:42:13 2018
> New Revision: 342857
>
> URL: http://llvm.org/viewvc/llvm-project?rev=342857&view=rev
> Log:
> llvm-diff: Fix crash on anonymous functions
>
> Not sure what the correct behavior is for this.
> Skip them and report how many there were.
>
> Added:
>     llvm/trunk/test/tools/llvm-diff/anon-func.ll
> Modified:
>     llvm/trunk/tools/llvm-diff/DifferenceEngine.cpp
>
> Added: llvm/trunk/test/tools/llvm-diff/anon-func.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-diff/anon-func.ll?rev=342857&view=auto
> ==============================================================================
> --- llvm/trunk/test/tools/llvm-diff/anon-func.ll (added)
> +++ llvm/trunk/test/tools/llvm-diff/anon-func.ll Sun Sep 23 21:42:13 2018
> @@ -0,0 +1,8 @@
> +; RUN: llvm-diff %s %s 2>&1 | FileCheck %s
> +
> +; CHECK: not comparing 1 anonymous functions in the left module and 1 in the right module
> +
> +define void @0() {
> +  ret void
> +}
> +
>
> Modified: llvm/trunk/tools/llvm-diff/DifferenceEngine.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-diff/DifferenceEngine.cpp?rev=342857&r1=342856&r2=342857&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-diff/DifferenceEngine.cpp (original)
> +++ llvm/trunk/tools/llvm-diff/DifferenceEngine.cpp Sun Sep 23 21:42:13 2018
> @@ -686,9 +686,18 @@ void DifferenceEngine::diff(Module *L, M
>    StringSet<> LNames;
>    SmallVector<std::pair<Function*,Function*>, 20> Queue;
>
> +  unsigned LeftAnonCount = 0;
> +  unsigned RightAnonCount = 0;
> +
>    for (Module::iterator I = L->begin(), E = L->end(); I != E; ++I) {
>      Function *LFn = &*I;
> -    LNames.insert(LFn->getName());
> +    StringRef Name = LFn->getName();
> +    if (Name.empty()) {
> +      ++LeftAnonCount;
> +      continue;
> +    }
> +
> +    LNames.insert(Name);
>
>      if (Function *RFn = R->getFunction(LFn->getName()))
>        Queue.push_back(std::make_pair(LFn, RFn));
> @@ -698,10 +707,25 @@ void DifferenceEngine::diff(Module *L, M
>
>    for (Module::iterator I = R->begin(), E = R->end(); I != E; ++I) {
>      Function *RFn = &*I;
> -    if (!LNames.count(RFn->getName()))
> +    StringRef Name = RFn->getName();
> +    if (Name.empty()) {
> +      ++RightAnonCount;
> +      continue;
> +    }
> +
> +    if (!LNames.count(Name))
>        logf("function %r exists only in right module") << RFn;
>    }
>
> +
> +  if (LeftAnonCount != 0 || RightAnonCount != 0) {
> +    SmallString<32> Tmp;
> +    Twine Message = "not comparing " + Twine(LeftAnonCount) +
> +      " anonymous functions in the left module and " + Twine(RightAnonCount) +
> +      " in the right module";
> +    logf(Message.toStringRef(Tmp));
> +  }
> +
>    for (SmallVectorImpl<std::pair<Function*,Function*> >::iterator
>           I = Queue.begin(), E = Queue.end(); I != E; ++I)
>      diff(I->first, I->second);
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list