Page MenuHomePhabricator

Avoid assert when a non-static member function is qualified with __unaligned
ClosedPublic

Authored by rogfer01 on Apr 12 2017, 6:38 AM.

Details

Summary

Under -fms-extensions __unaligned is a type-qualifier that can be applied to a non-static member function declaration.

This causes an assertion when mangling the name under Itanium, where that qualifier is not mangled.

This patch justs makes the minimal change to avoid the crash and avoid mangling __unaligned.

The test just makes sure the clash is actually detected.

Diff Detail

Repository
rL LLVM

Event Timeline

rogfer01 created this revision.Apr 12 2017, 6:38 AM
aaron.ballman accepted this revision.Apr 13 2017, 6:45 AM

This seems reasonable to me, but you should wait for confirmation before committing (I'm not as familiar with the mangler as others are).

test/CodeGenCXX/unaligned-duplicated-mangle-name.cpp
16 ↗(On Diff #94962)

Might as well put this note with the declaration rather than using an offset for the message.

This revision is now accepted and ready to land.Apr 13 2017, 6:45 AM
ahatanak added inline comments.
test/CodeGenCXX/unaligned-duplicated-mangle-name.cpp
15 ↗(On Diff #94962)

Do you know why clang doesn't error out until it reaches IRGen when compiling this test? I found it interesting that Sema detects the redeclaration and errors out when the function is marked "restrict", but doesn't do so when it's marked "unaligned".

clang::Sema::IsOverload explicitly forbids the __restrict case for the qualifier of non-static member functions. I assume __unaligned is not forbidden because the MSVC ABI does encode this qualifier while the Itanium ABI currently does not.

This patch just makes the attached test case fail like the one below:

// Compile with        "-target x86_64-unknown-linux-gnu -x c++ -fms-extensions" 
// and compare it with "-target x86_64-pc-windows-msvc -x c++ -fms-extensions" 
void foo(__unaligned int* a) { }
void foo(int *a) { }

Regards.

I see, thank you for the explanation.

This revision was automatically updated to reflect the committed changes.