Factor out the actual variable allocation logic into a separate function, so we can call it multiple times from visitVarDecl() if the variable declaration is a DecompositionDecl().
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/test/AST/Interp/cxx17.cpp | ||
---|---|---|
8 | Clang doesn't seem to support volatile in constant expressions at all right now(?). Can you come up with a reproducer that works? All I get is errors about a non-literal type: https://godbolt.org/z/PbevGf3E8 |
clang/test/AST/Interp/cxx17.cpp | ||
---|---|---|
8 | Apologies, my mistake. In my enthusiasm I forgot that while constexpr volatile is a thing the variable is not usable in a constant expression. |
clang/lib/AST/Interp/ByteCodeExprGen.cpp | ||
---|---|---|
34–35 | The destructor for LocalScope already calls emitDestruction() which is a virtual function, so is this necessary? | |
1537–1539 | ||
1548–1551 | ||
1571–1572 | <uncertain>Is this correct? IIRC, the decomposition declaration is its own object, but the bindings themselves are references back to the decomposition declaration object directly and so they're not distinct objects themselves (they're more like aliases).</uncertain> |
clang/lib/AST/Interp/ByteCodeExprGen.cpp | ||
---|---|---|
1571–1572 | Is this not reflected in the individual bindings? What does it mean that the bindings aren't "distinct objects themselves"? |
clang/lib/AST/Interp/ByteCodeExprGen.cpp | ||
---|---|---|
1571–1572 | Bindings are basically a label back to an object. Taking the easy case of a structure being bound: struct S { int i, j; } s; int main() { auto [val1, val2] = s; return val1 + val2; } The way this works under the hood is akin to: struct S { int i, j; } s; int main() { S __s = s; // This is the decomposition declaration return __s.i + __s.j; // And the structured bindings give alternative names to the fields in the decomposition declaration } so there's no allocation made for val1 or val2 because they're not really objects, just names. You can see that in: https://godbolt.org/z/sdj3Mvqhb (note the LLVM IR, which is identical between foo and bar aside from debug info). |
clang/lib/AST/Interp/ByteCodeExprGen.cpp | ||
---|---|---|
1571–1572 | Ah, I see. I guess my way works as well, but yours is better, so I'll change the patch. I can basically replace the added stuff in VisitDeclRefExpr() by just return this->visit(BD->getBinding()) and that will give me the right thing. I hope that way I can remove some of the BindingDecl special cases I've added as well. Thanks! |
clang/lib/AST/Interp/ByteCodeExprGen.cpp | ||
---|---|---|
34–35 | Still wondering about this | |
1536 | Spurious whitespace change | |
clang/test/AST/Interp/cxx17.cpp | ||
31 | It's be helpful to have a test where a and b are modified to demonstrate we change the values in f as expected. e.g., return f.a + f.b; | |
54–56 | Spurious whitespace |
clang/lib/AST/Interp/ByteCodeExprGen.cpp | ||
---|---|---|
34–35 | You're right, removed it again. Thanks. |