This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen][ObjC]
ClosedPublic

Authored by ahatanak on Apr 18 2017, 1:48 PM.

Details

Summary

This fixes a bug in EmitObjCForCollectionStmt which is causing clang to generate malformed IR.

When the following code (which I think is legal, at least when it is not compiled with ARC) is compiled:

$ cat test1.m

@interface Obj
@end
void bar(void);
void foo(Obj *o) {
  Obj *i;
  for (i in o) {
  thing:
    bar();
  }
  goto thing;
}

the compilation terminates with the messages "Instruction does not dominate all uses!".

This patch fixes the bug by using temporary local variables instead of PHI instructions and moving instructions to locations that dominate their uses.

The example I showed still fails to compile (with an assertion) when compiled with -fobjc-arc, but I think that is a separate bug.

rdar://problem/31670637

Diff Detail

Repository
rL LLVM

Event Timeline

ahatanak created this revision.Apr 18 2017, 1:48 PM
rjmccall edited edge metadata.Apr 18 2017, 2:08 PM

I wouldn't mind unconditionally banning this in JumpDiagnostics, actually.

ahatanak updated this revision to Diff 95667.Apr 18 2017, 6:15 PM

Unconditionally ban jumping into body of ObjC fast enumeration loop.

rjmccall accepted this revision.Apr 18 2017, 8:16 PM

Thanks, this looks great. A few tweaks about the diagnostic and LGTM.

include/clang/Basic/DiagnosticSemaKinds.td
4985 ↗(On Diff #95667)

Capitalization: "Objective-C"

It's probably better to just say "fast enumeration loop" and leave off "body".

This revision is now accepted and ready to land.Apr 18 2017, 8:16 PM
This revision was automatically updated to reflect the committed changes.