-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-cpp] Add support for anon constructors in anon structs. Fixes #1751 #1753
[clang-cpp] Add support for anon constructors in anon structs. Fixes #1751 #1753
Conversation
I've tried this change and it seems simpler. diff --git a/src/clang-c-frontend/clang_c_convert.cpp b/src/clang-c-frontend/clang_c_convert.cpp
index ae85035ba..bba58abb0 100644
--- a/src/clang-c-frontend/clang_c_convert.cpp
+++ b/src/clang-c-frontend/clang_c_convert.cpp
@@ -3408,6 +3408,7 @@ void clang_c_convertert::get_decl_name(
return;
}
+ case clang::Decl::CXXConstructor:
case clang::Decl::Var:
if (name.empty())
{ This change is also fixed:
|
@intrigus-lgtm: we have open positions within our research group. Please do get in touch if you're looking for a research position in software verification ;-) Here is my email address: lucas.cordeiro@manchester.ac.uk |
That change appears wrong to me. |
Yes, definitely bad. ESBMC maintains a set of symbols whose id should be unique in the so-called context. Symbols with the same id in different translation units are allowed (and handled by c_link()), but they better have the same definition (ODR). Within a single context, as is built by the frontend, the id must be unique. |
Yes, you are right. For reference, you can also verify that the constructor is valid using the following code, there doesn't seem to be a constructor call in your TCs. main (c:@F@main#):
// 20 file main9.cpp line 6 column 3 function main
struct __anon_struct_at_main9_cpp_main_6_3 unnamed_struct;
// 21 file main9.cpp line 6 column 3 function main
unnamed_struct={ .field1=10, .field2=2.050000e+1f }; #include <cassert>
int main()
{
// Define and initialize an unnamed struct
struct
{
int field1 = 10;
float field2 = 20.5;
} unnamed_struct;
// Access and verify the fields of the unnamed struct
assert(unnamed_struct.field1 == 10);
assert(unnamed_struct.field2 == 20.5f);
return 0;
} |
Well, I just learned this the hard way 😆 I added a testcase where the anon constructor is actually used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! This fixes two known-bug test cases. Could I ask you to please relabel them as CORE instead of KNOWNBUG in the respective test.desc files? They are located here:
- regression/esbmc-cpp/cpp/ch20_7
- regression/esbmc-cpp/gcc-template-tests/union1
Then the CI should be green and we're ready to go. Many thanks for your contributions!
I believe there should've been some c_link warnings in the log at least. It's not ideal, but I don't have a good solution right now except for just rejecting the input. Though I'm pretty sure that would break things elsewhere (e.g. one TU declaring |
Fixed the two known-bug cases. |
The ids were in the same TU and at the very same position. The only difference were the arguments to the constructor calls. (I initially ignored the arguments and only generated an id based on the name of the type. Therefore conflating constructors with different arguments) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a lot of duplicated code in this function, can you unify the naming generation of these switch cases?
case clang::Decl::CXXConstructor: | ||
if (name.empty()) | ||
{ | ||
// Anonymous constructor, generate a name based on the type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't use its type to generate the name, only its location. Please fix comment
I have created #1762 for that as well as the wrong comment. I don't have time to work on this right now and I don't think that any of that should really block this pr. |
It's a very small request and I prefer we don't add any more duplicated
code when we can easily not do it.
…On Wed, 27 Mar 2024, 16:50 intrigus-lgtm, ***@***.***> wrote:
I see a lot of duplicated code in this function, can you unify the naming
generation of these switch cases?
I have created #1762 <#1762> for
that as well as the wrong comment.
(All *existing* comments in that method are wrong)
I don't have time to work on this right now and I don't think that any of
that should really block this pr.
—
Reply to this email directly, view it on GitHub
<#1753 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKEJHZWW4LYMIUKQX43WT3Y2MIINAVCNFSM6AAAAABE4IXZDKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRTHA2DGMRSGY>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I'm really sorry, but I really don't know how to merge the switch cases. Also, instead of generating the id manually, it could be possible to always just use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my POV it looks good. Many thanks for adding the override in the C++ frontend. Btw. the CI is failing because it wants a formatting change. I've pushed it to this PR and hope that's OK with you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting this PR, @intrigus-lgtm.
Tentative fix for #1751