This is an archive of the discontinued LLVM Phabricator instance.

Fixing a clang crash with duplicate mangled name
ClosedPublic

Authored by ygao on Mar 17 2015, 6:48 PM.

Details

Reviewers
ygao
Summary

Hi,
The following test case crashes in different places depending on whether or not -femit-all-decls is passed
on the command-line. I am thinking that moving the err_duplicate_mangled_name diagnostic from
EmitGlobalFunctionDefinition() into EmitGlobal() should fix the issue.

$ clang -S -emit-llvm -o - test.cpp
$ clang -S -femit-all-decls -emit-llvm -o - test.cpp

// test.cpp
extern "C" int printf(const char *, ...);

void foo(void) __asm("_ZN1SC2Ev");
void foo(void) { }

struct S {

S() {
  printf("S constructor\n");
};

} var;
// end test.cpp

What do you think?

  • Gao

Diff Detail

Event Timeline

ygao updated this revision to Diff 22151.Mar 17 2015, 6:48 PM
ygao retitled this revision from to Fixing a clang crash with duplicate mangled name.
ygao updated this object.
ygao edited the test plan for this revision. (Show Details)
ygao added subscribers: Unknown Object (MLST), akyrtzi.
ygao updated this revision to Diff 22204.Mar 18 2015, 12:36 PM
ygao added a comment.Mar 23 2015, 12:53 PM

A gentle ping.

I don’t see a crash with your test case (TOT r233459), is it crashing with a different invocation ?
And after fully applying the patch the error is not emitted , and the test case fails.

Also FYI, from your test case, if I generate assembly file, I can see:

fatal error: error in backend: '__ZN1SC2Ev' label emitted multiple times to assembly file

But this is only if I add an extra underscore for the __asm label.

ygao added a comment.Mar 27 2015, 7:08 PM

Hi Argyrios,
What target triple did you use to build clang? My configuration is as follows:

$ build/Debug+Asserts/bin/clang --version
clang version 3.7.0 (trunk 233464)
Target: x86_64-unknown-linux-gnu
Thread model: posix

$ build/Debug+Asserts/bin/clang -S -emit-llvm -o - D8405.cpp 
llvm/lib/IR/Value.cpp:325: void llvm::Value::replaceAllUsesWith(llvm::Value*): Assertion `New->getType() == getType() && "replaceAllUses of value with new value of different type!"' failed.
ygao updated this revision to Diff 23447.Apr 8 2015, 3:43 PM

Re-based the patch to trunk r234180.
And a gentle ping.

ygao added a comment.Apr 8 2015, 3:52 PM

A Darwin-targeted clang may not crash with the original test case, because the __asm() renaming on Darwin prepends
'\01' to the new function name. The following test case should crash on Darwin.

$ clang -S -emit-llvm -o - test.cpp
$ clang -S -femit-all-decls -emit-llvm -o - test.cpp

// test.cpp
extern "C" int printf(const char *, ...);

extern "C" {

void _ZN1SC2Ev(void) { }

}

struct S {

S() {
  printf("S constructor\n");
};

} var;

Committed in r234767, thanks!

ygao accepted this revision.Apr 14 2015, 10:54 AM
ygao added a reviewer: ygao.
This revision is now accepted and ready to land.Apr 14 2015, 10:54 AM
ygao closed this revision.Apr 14 2015, 10:55 AM