r313896 - [Sema] Fix using old initializer during switch statement transformation.
Volodymyr Sapsai via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 21 10:58:28 PDT 2017
Author: vsapsai
Date: Thu Sep 21 10:58:27 2017
New Revision: 313896
URL: http://llvm.org/viewvc/llvm-project?rev=313896&view=rev
Log:
[Sema] Fix using old initializer during switch statement transformation.
It fixes a crash in CodeGen when we are trying to generate code for
initializer expression created before template instantiation, like
CallExpr '<dependent type>'
|-UnresolvedLookupExpr '<overloaded function type>' lvalue (ADL) = 'parse'
`-DeclRefExpr 'Buffer<N>' lvalue ParmVar 'buffer' 'Buffer<N>'
rdar://problem/33888545
Reviewers: rsmith, ahatanak
Reviewed By: ahatanak
Subscribers: aemerson, kristof.beyls, cfe-commits
Differential Revision: https://reviews.llvm.org/D38009
Added:
cfe/trunk/test/SemaCXX/cxx1z-init-statement-template.cpp
Modified:
cfe/trunk/lib/Sema/TreeTransform.h
Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=313896&r1=313895&r2=313896&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Thu Sep 21 10:58:27 2017
@@ -6601,8 +6601,7 @@ TreeTransform<Derived>::TransformSwitchS
// 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();
Added: cfe/trunk/test/SemaCXX/cxx1z-init-statement-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-init-statement-template.cpp?rev=313896&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx1z-init-statement-template.cpp (added)
+++ cfe/trunk/test/SemaCXX/cxx1z-init-statement-template.cpp Thu Sep 21 10:58:27 2017
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -std=c++1z -verify -emit-llvm-only %s
+// expected-no-diagnostics
+
+// rdar://problem/33888545
+template <unsigned int BUFFER_SIZE> class Buffer {};
+
+class A {
+public:
+ int status;
+};
+
+template <unsigned int N> A parse(Buffer<N> buffer);
+
+template<unsigned int N>
+void init_in_if(Buffer<N> buffer) {
+ if (A a = parse(buffer); a.status > 0) {
+ }
+}
+
+template<unsigned int N>
+void init_in_switch(Buffer<N> buffer) {
+ switch (A a = parse(buffer); a.status) {
+ default:
+ break;
+ }
+}
+
+void test() {
+ Buffer<10> buffer;
+ init_in_if(buffer);
+ init_in_switch(buffer);
+}
More information about the cfe-commits
mailing list