[PATCH] D38009: [Sema] Fix using old initializer during switch statement transformation.
vsapsai created this revision. Herald added subscribers: kristof.beyls, aemerson. It fixes a crash in CodeGen when we are trying to generate code for initializer expression created before template instantiation, like CallExpr '' |-UnresolvedLookupExpr '' lvalue (ADL) = 'parse' `-DeclRefExpr 'Buffer' lvalue ParmVar 'buffer' 'Buffer' rdar://problem/33888545 https://reviews.llvm.org/D38009 Files: clang/lib/Sema/TreeTransform.h clang/test/SemaCXX/cxx1z-init-statement-template.cpp Index: clang/test/SemaCXX/cxx1z-init-statement-template.cpp === --- /dev/null +++ clang/test/SemaCXX/cxx1z-init-statement-template.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -std=c++1z -verify -emit-llvm-only %s +// expected-no-diagnostics + +// rdar://problem/33888545 +template class Buffer {}; + +class A { +public: + int status; +}; + +template A parse(Buffer buffer); + +template +void init_in_if(Buffer buffer) { + if (A a = parse(buffer); a.status > 0) { + } +} + +template +void init_in_switch(Buffer buffer) { + switch (A a = parse(buffer); a.status) { +default: + break; + } +} + +void test() { + Buffer<10> buffer; + init_in_if(buffer); + init_in_switch(buffer); +} Index: clang/lib/Sema/TreeTransform.h === --- clang/lib/Sema/TreeTransform.h +++ clang/lib/Sema/TreeTransform.h @@ -6601,8 +6601,7 @@ // Rebuild the switch statement. StmtResult Switch -= getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), - S->getInit(), Cond); += getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond); if (Switch.isInvalid()) return StmtError(); Index: clang/test/SemaCXX/cxx1z-init-statement-template.cpp === --- /dev/null +++ clang/test/SemaCXX/cxx1z-init-statement-template.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -std=c++1z -verify -emit-llvm-only %s +// expected-no-diagnostics + +// rdar://problem/33888545 +template class Buffer {}; + +class A { +public: + int status; +}; + +template A parse(Buffer buffer); + +template +void init_in_if(Buffer buffer) { + if (A a = parse(buffer); a.status > 0) { + } +} + +template +void init_in_switch(Buffer buffer) { + switch (A a = parse(buffer); a.status) { +default: + break; + } +} + +void test() { + Buffer<10> buffer; + init_in_if(buffer); + init_in_switch(buffer); +} Index: clang/lib/Sema/TreeTransform.h === --- clang/lib/Sema/TreeTransform.h +++ clang/lib/Sema/TreeTransform.h @@ -6601,8 +6601,7 @@ // Rebuild the switch statement. StmtResult Switch -= getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), - S->getInit(), Cond); += getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond); if (Switch.isInvalid()) return StmtError(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38009: [Sema] Fix using old initializer during switch statement transformation.
ahatanak accepted this revision. ahatanak added a comment. This revision is now accepted and ready to land. I think this is correct. https://reviews.llvm.org/D38009 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38009: [Sema] Fix using old initializer during switch statement transformation.
This revision was automatically updated to reflect the committed changes. Closed by commit rL313896: [Sema] Fix using old initializer during switch statement transformation. (authored by vsapsai). Changed prior to commit: https://reviews.llvm.org/D38009?vs=115754&id=116226#toc Repository: rL LLVM https://reviews.llvm.org/D38009 Files: cfe/trunk/lib/Sema/TreeTransform.h cfe/trunk/test/SemaCXX/cxx1z-init-statement-template.cpp Index: cfe/trunk/lib/Sema/TreeTransform.h === --- cfe/trunk/lib/Sema/TreeTransform.h +++ cfe/trunk/lib/Sema/TreeTransform.h @@ -6601,8 +6601,7 @@ // Rebuild the switch statement. StmtResult Switch -= getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), - S->getInit(), Cond); += getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond); if (Switch.isInvalid()) return StmtError(); Index: cfe/trunk/test/SemaCXX/cxx1z-init-statement-template.cpp === --- cfe/trunk/test/SemaCXX/cxx1z-init-statement-template.cpp +++ cfe/trunk/test/SemaCXX/cxx1z-init-statement-template.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -std=c++1z -verify -emit-llvm-only %s +// expected-no-diagnostics + +// rdar://problem/33888545 +template class Buffer {}; + +class A { +public: + int status; +}; + +template A parse(Buffer buffer); + +template +void init_in_if(Buffer buffer) { + if (A a = parse(buffer); a.status > 0) { + } +} + +template +void init_in_switch(Buffer buffer) { + switch (A a = parse(buffer); a.status) { +default: + break; + } +} + +void test() { + Buffer<10> buffer; + init_in_if(buffer); + init_in_switch(buffer); +} Index: cfe/trunk/lib/Sema/TreeTransform.h === --- cfe/trunk/lib/Sema/TreeTransform.h +++ cfe/trunk/lib/Sema/TreeTransform.h @@ -6601,8 +6601,7 @@ // Rebuild the switch statement. StmtResult Switch -= getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), - S->getInit(), Cond); += getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond); if (Switch.isInvalid()) return StmtError(); Index: cfe/trunk/test/SemaCXX/cxx1z-init-statement-template.cpp === --- cfe/trunk/test/SemaCXX/cxx1z-init-statement-template.cpp +++ cfe/trunk/test/SemaCXX/cxx1z-init-statement-template.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -std=c++1z -verify -emit-llvm-only %s +// expected-no-diagnostics + +// rdar://problem/33888545 +template class Buffer {}; + +class A { +public: + int status; +}; + +template A parse(Buffer buffer); + +template +void init_in_if(Buffer buffer) { + if (A a = parse(buffer); a.status > 0) { + } +} + +template +void init_in_switch(Buffer buffer) { + switch (A a = parse(buffer); a.status) { +default: + break; + } +} + +void test() { + Buffer<10> buffer; + init_in_if(buffer); + init_in_switch(buffer); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits