r276350 - [CodeGen] Fix a crash when constant folding switch statement

Hans Wennborg via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 28 08:26:00 PDT 2016


I see, thanks.

I've taken a second look at the patch and it seems straight-forward to
me, so I've merged it in r276985.

Cheers,
Hans

On Wed, Jul 27, 2016 at 5:16 PM, David Majnemer
<david.majnemer at gmail.com> wrote:
> I hear that he is on vacation.
>
>
> On Wednesday, July 27, 2016, Hans Wennborg via cfe-commits
> <cfe-commits at lists.llvm.org> wrote:
>>
>> Richard: ping?
>>
>> On Fri, Jul 22, 2016 at 7:00 AM, Hans Wennborg <hans at chromium.org> wrote:
>> > Richard: should we merge this to 3.9?
>> >
>> > On Thu, Jul 21, 2016 at 6:31 PM, Erik Pilkington via cfe-commits
>> > <cfe-commits at lists.llvm.org> wrote:
>> >> Author: epilk
>> >> Date: Thu Jul 21 17:31:40 2016
>> >> New Revision: 276350
>> >>
>> >> URL: http://llvm.org/viewvc/llvm-project?rev=276350&view=rev
>> >> Log:
>> >> [CodeGen] Fix a crash when constant folding switch statement
>> >>
>> >> Differential revision: https://reviews.llvm.org/D22542
>> >>
>> >> Modified:
>> >>     cfe/trunk/lib/CodeGen/CGStmt.cpp
>> >>     cfe/trunk/test/CodeGenCXX/switch-case-folding-2.cpp
>> >>
>> >> Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
>> >> URL:
>> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=276350&r1=276349&r2=276350&view=diff
>> >>
>> >> ==============================================================================
>> >> --- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
>> >> +++ cfe/trunk/lib/CodeGen/CGStmt.cpp Thu Jul 21 17:31:40 2016
>> >> @@ -1264,6 +1264,14 @@ void CodeGenFunction::EmitCaseStmt(const
>> >>  }
>> >>
>> >>  void CodeGenFunction::EmitDefaultStmt(const DefaultStmt &S) {
>> >> +  // If there is no enclosing switch instance that we're aware of,
>> >> then this
>> >> +  // default statement can be elided. This situation only happens when
>> >> we've
>> >> +  // constant-folded the switch.
>> >> +  if (!SwitchInsn) {
>> >> +    EmitStmt(S.getSubStmt());
>> >> +    return;
>> >> +  }
>> >> +
>> >>    llvm::BasicBlock *DefaultBlock = SwitchInsn->getDefaultDest();
>> >>    assert(DefaultBlock->empty() &&
>> >>           "EmitDefaultStmt: Default block already defined?");
>> >>
>> >> Modified: cfe/trunk/test/CodeGenCXX/switch-case-folding-2.cpp
>> >> URL:
>> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/switch-case-folding-2.cpp?rev=276350&r1=276349&r2=276350&view=diff
>> >>
>> >> ==============================================================================
>> >> --- cfe/trunk/test/CodeGenCXX/switch-case-folding-2.cpp (original)
>> >> +++ cfe/trunk/test/CodeGenCXX/switch-case-folding-2.cpp Thu Jul 21
>> >> 17:31:40 2016
>> >> @@ -18,4 +18,13 @@ int main(void) {
>> >>   return test(5);
>> >>  }
>> >>
>> >> +void other_test() {
>> >> +  switch(0) {
>> >> +  case 0:
>> >> +    do {
>> >> +    default:;
>> >> +    } while(0);
>> >> +  }
>> >> +}
>> >> +
>> >>  // CHECK: call i32 (i8*, ...) @_Z6printfPKcz


More information about the cfe-commits mailing list