LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 28391 - ASAN incorrectly flags ODR violation on C++17 inline variables when one definition is compiled in C++14.
Summary: ASAN incorrectly flags ODR violation on C++17 inline variables when one defin...
Status: RESOLVED INVALID
Alias: None
Product: compiler-rt
Classification: Unclassified
Component: compiler-rt (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-01 17:09 PDT by Eric Fiselier
Modified: 2017-08-30 10:05 PDT (History)
5 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Fiselier 2016-07-01 17:09:46 PDT
Reproducer:
// Steps to reproduce:
// clang++ -std=c++14 -fsanitize=address -DTU_ONE -shared -fPIC -o libfoo.so test.cpp
// clang++ -std=c++1z -fsanitize=address test.cpp libfoo.so
// ./a.out
// EXPECTED: exit success
// ACTUAL:  AddressSanitizer: odr-violation
struct Foo {
 static constexpr bool inline_var = true;
};
#ifdef TU_ONE
constexpr bool Foo::inline_var;
#else
void test(const bool&) {}
int main() {
    test(Foo::inline_var);
}
#endif

In the above reproducer the main program generates a definition for Foo::inline_var according to the C++17 inline variable rules. The program then links to a library compiled as C++14 which provides the explicit definition for `Foo::inline_bool`. When this program is run ASAN will emit an odr-violation diagnostic for 'inline_bool'.

I believe this diagnostic is a false positive even though one of the two definitions was not compiled with C++17 inline variable semantics.
Comment 1 Reid Kleckner 2016-07-01 17:14:46 PDT
I think the bug is that C++17 introduces an ABI break with C++14 by changing the linkage of inline_var from external to linkonce_odr.
Comment 2 Dmitry Vyukov 2017-08-30 06:45:49 PDT
Not as asan bug, the ODR violation is real.
Comment 3 Dmitry Vyukov 2017-08-30 06:46:23 PDT
Not _an_ asan bug
Comment 4 David Blaikie 2017-08-30 10:05:09 PDT
(In reply to Reid Kleckner from comment #1)
> I think the bug is that C++17 introduces an ABI break with C++14 by changing
> the linkage of inline_var from external to linkonce_odr.

Is that an ABI break though? If the external definition and linkonce_odr definition are linked together the link will succeed, right? (the linkonce_odr will be dropped in favor of the external definition)

(maybe this is fine for ELF/maybe some other object formats but not in LLVM IR? Not sure what the semantics of linking a Module with  a linkonce_odr definition with a Module with an external/strong definition are)

I mean it's a break if you do it the other way - ship your C++17 library to someone building as C++14. But if you ship your C++14 library to people building with your headers as C++17? That seems like it might thread the needle & be 'good'-ish?