This is an archive of the discontinued LLVM Phabricator instance.

Bug fix: use dyn_cast_or_null instead of dyn_cast
ClosedPublic

Authored by hulx2000 on Feb 11 2016, 10:12 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

hulx2000 retitled this revision from to Bug fix: check nullptr before call dyn_cast.
hulx2000 updated this object.
hulx2000 set the repository for this revision to rL LLVM.
hulx2000 added a subscriber: llvm-commits.
arsenm added a subscriber: arsenm.Feb 11 2016, 10:14 AM

You could also use dyn_cast_or_null

mcrosier added inline comments.
lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
828 ↗(On Diff #47676)

You might consider using dyn_cast_or_null(), so you can reduce indent and fold the null checks into the inner if condition.

test/CodeGen/AArch64/gep-nullptr.ll
6 ↗(On Diff #47676)

Can you please simplify some of the names, so this is more human readable?

29 ↗(On Diff #47676)

Please drop the attribute/metadata if it's not relevant to reproducing the issue.

hulx2000 retitled this revision from Bug fix: check nullptr before call dyn_cast to Bug fix: use dyn_cast_or_null instead of dyn_cast.
hulx2000 updated this object.
hulx2000 marked an inline comment as done.
mcrosier added inline comments.Feb 12 2016, 1:33 PM
lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
829 ↗(On Diff #47850)

I believe you still need to add the nullptr checks for FirstGEP and SecondGEP.

hulx2000 marked an inline comment as done.Feb 12 2016, 5:12 PM
hulx2000 marked an inline comment as done.Feb 15 2016, 11:39 AM
hulx2000 added inline comments.
lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
829 ↗(On Diff #47853)

Thanks, Chad:

That's not needed because I checked in isLegalToSwapOperand().

Can you please cleanup the test case to be more human readable?

Is the test just verifying that we don't get a compiler ICE due to dereferencing a nullptr? If so, please add a comment to the test case expressing this.

lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
829 ↗(On Diff #47853)

Okay, that's fine.

test/CodeGen/AArch64/gep-nullptr.ll
10 ↗(On Diff #47853)

Is the lifetime intrinsic relevant to the test?

17 ↗(On Diff #47853)

You should probably use a CHECK-LABEL directive like

; CHECK-LABEL: test

mehdi_amini added inline comments.
test/CodeGen/AArch64/gep-nullptr.ll
2 ↗(On Diff #47853)

Why is an assert build required?

hulx2000 marked an inline comment as done.
hulx2000 marked 3 inline comments as done.
hulx2000 marked an inline comment as done.Feb 18 2016, 4:46 PM
mcrosier accepted this revision.Feb 18 2016, 5:54 PM
mcrosier added a reviewer: mcrosier.

LGTM.

This revision is now accepted and ready to land.Feb 18 2016, 5:54 PM
This revision was automatically updated to reflect the committed changes.