possible silent bad code generation with inline static data member in clang-cl
| Bugzilla Link | 41409 |
| Resolution | DUPLICATE |
| Resolved on | Apr 19, 2019 23:58 |
| Version | 8.0 |
| OS | other |
| CC | @davidbolvansky,@zygoloid,@rnk,@TNorthover |
Extended Description
// header.h
#include
struct A { A() { std::cout << "ctor " << this << std::endl; } ~A() { std::cout << "dtor " << this << std::endl; } void f() { std::cout << "f " << this << std::endl; } };
struct S { inline static A a; // C++17 inline variable, thus also a definition };
// TU1.cpp
#include "header.h"
int main() { S::a.f(); }
// TU2.cpp
#include "header.h"
// TU3.cpp
#include "header.h"
// TU4.cpp
#include "header.h"
This program prints (with some random address):
ctor 010D4020 ctor 010D4020 ctor 010D4020 ctor 010D4020 f 010D4020 dtor 010D4020 dtor 010D4020 dtor 010D4020 dtor 010D4020
These are four initializations for the one and only object of A (in fact one per TU) instead of exactly one (as C++17 demands).
The program should print:
ctor 010D4020 f 010D4020 dtor 010D4020
I first reported this bug for clang-cl 6 (bug 37903 and bug 38171).
MSVC had the same bug, but Microsoft has fixed it (at least in VS2019): https://developercommunity.visualstudio.com/content/problem/261624/multiple-initializations-of-inline-static-data-mem.html
See also https://stackoverflow.com/q/50982390/8731417.
I wonder why this bug has not been fixed yet because to me it seems pretty serious. Do I rate that wrong?
*** This bug has been marked as a duplicate of bug llvm/llvm-project#37251 *** It is now marked as fixed and not as a duplicate. I find that misleading.
According to the email I received, you were the one who marked it fixed in comment #2. I'll set it back to duplicate.
*** This bug has been marked as a duplicate of bug llvm/llvm-project#37251 *** Yes, weird, it was me, I can see it in the history. But I swear I did not do this consciously. It would not make any sense at all. I use Firefox. Is this problematic? I hope I don't change it again with this reply...
*** This bug has been marked as a duplicate of bug llvm/llvm-project#37251 *** It is now marked as fixed and not as a duplicate. I find that misleading.
According to the email I received, you were the one who marked it fixed in comment #2. I'll set it back to duplicate.
*** This bug has been marked as a duplicate of bug llvm/llvm-project#37251 ***
I know it's frustrating when bugs don't get the attention you think they deserve, but creating intentional duplicates isn't the way to fix it.
You might try getting people interested in other venues like llvm-dev or the IRC channel.
*** This bug has been marked as a duplicate of bug llvm/llvm-project#37251 *** It is now marked as fixed and not as a duplicate. I find that misleading.
Consider writing a post about this bug on the cfe-dev mailing list I could probably do that, although I don't know this list and what it's exactly good for. But, I don't know, somehow it just does not feel right to me.
If this bug was really overlooked (which is just my suspicion) and it remains so because it was only marked as a duplicate, so be it.
Otherwise, if Richard et al. have already decided that this bug is not critical, so be it. I'm not in a position to put a gun against their heads.
Otherwise, it will be fixed in the not too distant future.
I think my job as a mere user of clang who occasionally reports a bug is done. And since VS2019 is released, I can always switch to the latest cl that does not have this bug (of course, it has a few other bugs instead, but that's another story...).
Thanks anyway for suggesting.
Consider writing a post about this bug on the cfe-dev mailing list
I know it's frustrating when bugs don't get the attention you think they deserve, but creating intentional duplicates isn't the way to fix it.
You might try getting people interested in other venues like llvm-dev or the IRC channel.
*** This bug has been marked as a duplicate of bug llvm/llvm-project#37251 ***
Tim, you're misjudging me. There is no frustration at all. Instead, there are concerns that this bug and its severity may have been overlooked.
Let me explain.
If you should happen to know this bug, you can safely work around it in your own code: simply don't use this new C++17 language feature. However, if you include library header files, you no longer have control over the bug because a library might use this new feature.
It gets worse if you do not know this bug. I assume this applies to virtually all programmers except me. Since clang is known as the most compliant and least buggy compiler of the big 3, they would not hesitate to use this new feature.
What's the end result? In a best case scenario, this bug has absolutely no effect in a program. In a worst case scenario, a program silently runs amok.
My personal opinion on the latter is the following: silent bad code generation is the worst of all evil. It must never happen. A bug that can silently generate bad code should have the highest priority.
Now, if you look at my two bug reports for clang-cl 6 and 7 you'll see that this bug had exactly zero attention over a nine-month period. There are no comments from others, and the CC list is virtually empty. So I suspected the possibility that this bug was overlooked.
I decided to wait for clang-cl 8. If the bug is still there, I would report it for clang-cl 8, too, but under a possibly better fitting heading that clearly indicates what this bug could do to a program (silently generate bad code). My hope was (and still is) that you guys who actually do all the work definitely know this bug.
Honestly, I don't think this decision is inappropriate or wrong.
Of course, you guys can still judge the severity of this bug differently than I do. Finally, it's your decision, not mine. Since I'm not involved in the development of clang, I would have to accept that and hope for the best case scenario in my programs until the bug is fixed.
OK, I think based on this answer you now know that I basically do not act prematurely.
I know it's frustrating when bugs don't get the attention you think they deserve, but creating intentional duplicates isn't the way to fix it.
You might try getting people interested in other venues like llvm-dev or the IRC channel.
*** This bug has been marked as a duplicate of bug llvm/llvm-project#37251 ***