This is an archive of the discontinued LLVM Phabricator instance.

Bug 20788 - bugpoint does not respect the "Alias must point to a definition"
ClosedPublic

Authored by npjdesres on May 6 2015, 8:05 AM.

Details

Reviewers
npjdesres
Summary

Fix bug 20788.

GlobalAliases may reference function definitions, but not function declarations.

bugpoint would sometimes create invalid IR by deleting a function's body (thus mutating a function definition into a declaration) without first 'fixing' any GlobalAliases that reference that function definition.

This patch iteratively prevents that issue. Before deleting a function's body, it scans the module for GlobalAliases which reference that function. When found, it eliminates them using replaceAllUsesWith.

Diff Detail

Event Timeline

npjdesres updated this revision to Diff 25046.May 6 2015, 8:05 AM
npjdesres retitled this revision from to Bug 20788 - bugpoint does not respect the "Alias must point to a definition" .
npjdesres updated this object.
npjdesres edited the test plan for this revision. (Show Details)
npjdesres changed the visibility from "Public (No Login Required)" to "npjdesres (Nick Johnson)".
npjdesres changed the visibility from "npjdesres (Nick Johnson)" to "Public (No Login Required)".
npjdesres added a subscriber: Unknown Object (MLST).
hfinkel added a subscriber: hfinkel.May 6 2015, 8:24 AM

This generally looks good, thanks!; you seem unfamiliar with our general coding conventions, so I've made a number of style comments.

tools/bugpoint/ExtractFunction.cpp
217

declaration -> definition

219

space after for

223

space after for

223

i -> I

224

space after if, no spaced around expression
(same below)

229

General convention would be to use 'e' instead of 'N' here.

230

No spaces around parameter expression.

npjdesres updated this revision to Diff 25062.May 6 2015, 10:07 AM

LLVM style guidelines

How should I recruit an appropriate reviewer?

So, once the issues are fixed, i actually think this is pretty
obviously correct.
I have a bunch of code i will try it on that currently does not work
with bugpoint for this very reason.

I thought my updated diff #25062 fixed the all issues. Are there other issues?

I have a .bc file (old, admittedly, but passes opt -verify), on which
bugpoint does not work, even with this patch.

After a bunch of cutdowns, it gets:
Checking for crash with only these blocks: .lr.ph .loopexit
_ZN4llvm11SmallVectorIPN5clang6driver6ActionELj3EED1Ev.exit: Alias
must point to a definition
void (%"class.clang::DiagnosticNoteRenderer"*)*
@_ZN5clang22DiagnosticNoteRendererD1Ev
Alias must point to a definition
void (%"class.clang::DiagnosticNoteRenderer"*)*
@_ZN5clang22DiagnosticNoteRendererD2Ev
Alias must point to a definition
void (%"class.llvm::ReturnInst"*)* @_ZN4llvm10ReturnInstD1Ev
Alias must point to a definition

...
etc

I've put it here:
https://drive.google.com/file/d/0BzaAhp8ViDJ6elZEWXF4TVgydU0/view?usp=sharing

(I just made a pass crash if F.size() < 50, and ran it to get bugpoint
to start going :P)

npjdesres updated this revision to Diff 25771.May 14 2015, 7:18 AM

@dberlin: your testcase demonstrates that a GlobalAlias may refer to any kind of ConstantExpr, whereas my previous patch incorrectly assumed that the aliasee must be an llvm::Function.

Consequently, the test on line 194 needs a ->stripPointerCasts(). My latest patch handles that testcase correctly.

@dberlin: you mentioned you have many test cases. Would you be so kind as to run this latest patch on them? Thanks,

I still get the same crash on bugpoint with this patch, though
slightly further along

Checking for crash with only these blocks: ._crit_edge
_ZN12_GLOBAL__N_111StmtPrinter9PrintExprEPN5clang4ExprE.exit ... <25
total>: Alias must point to a definition
void (%"class.clang::DiagnosticNoteRenderer"*)*
@_ZN5clang22DiagnosticNoteRendererD1Ev
Alias must point to a definition
void (%"class.clang::DiagnosticNoteRenderer"*)*
@_ZN5clang22DiagnosticNoteRendererD2Ev
Alias must point to a definition
void (%"class.llvm::ReturnInst"*)* @_ZN4llvm10ReturnInstD1Ev
Alias must point to a definition
void (%"class.llvm::ReturnInst"*)* @_ZN4llvm10ReturnInstD2Ev
Alias must point to a definition
void (%"class.llvm::AllocaInst"*)* @_ZN4llvm10AllocaInstD1Ev
Alias must point to a definition
void (%"class.llvm::AllocaInst"*)* @_ZN4llvm10AllocaInstD2Ev
Alias must point to a definition
void (%"class.llvm::ModulePass"*)* @_ZN4llvm10ModulePassD1Ev
Alias must point to a definition
void (%"class.llvm::ModulePass"*)* @_ZN4llvm10ModulePassD2Ev
Alias must point to a definition
void (%"class.llvm::ImmutablePass"*)* @_ZN4llvm13ImmutablePassD1Ev
Alias must point to a definition
void (%"class.llvm::ImmutablePass"*)* @_ZN4llvm13ImmutablePassD2Ev
Alias must point to a definition
void (%"class.llvm::raw_null_ostream"*)* @_ZN4llvm16raw_null_ostreamD1Ev
Alias must point to a definition
void (%"class.llvm::raw_null_ostream"*)* @_ZN4llvm16raw_null_ostreamD2Ev
./opt: bugpoint-input-b1bae24.bc: error: input module is broken!
simplifycfg failed!

npjdesres updated this revision to Diff 25795.May 14 2015, 11:35 AM

@dberlin: I'm unable to recreate your crash. However, I have a hunch that it pertains to aliases to global variables, rather than aliases to functions.

The new patch (attached) eliminates aliases before calls to GV->setInitializer(nullptr).

This one works properly for me on that file.

So LGTM.

npjdesres accepted this revision.Nov 20 2015, 8:58 AM
npjdesres added a reviewer: npjdesres.

Sorry, I had forgotten about this diff.

LGTM too. I do not have commit privs.

This revision is now accepted and ready to land.Nov 20 2015, 8:58 AM
hfinkel closed this revision.Nov 26 2015, 11:27 AM

Rebased, and committed: r254171.