Page MenuHomePhabricator

[LLVM] Use dyn_cast instead of cast for objects that require it
Needs ReviewPublic

Authored by gAlfonso-bit on Dec 6 2022, 12:50 PM.

Details

Reviewers
MaskRay
Summary

These places should use dyn_cast instead of cast as they are inside conditionals and have dyn_cast used on them in other places

Diff Detail

Unit TestsFailed

TimeTest
60,040 msx64 debian > libFuzzer.libFuzzer::minimize_crash.test
Script: -- : 'RUN: at line 1'; /var/lib/buildkite-agent/builds/llvm-project/build/./bin/clang --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/var/lib/buildkite-agent/builds/llvm-project/compiler-rt/lib/fuzzer -m64 /var/lib/buildkite-agent/builds/llvm-project/compiler-rt/test/fuzzer/NullDerefTest.cpp -o /var/lib/buildkite-agent/builds/llvm-project/build/projects/compiler-rt/test/fuzzer/X86_64DefaultLinuxConfig/Output/minimize_crash.test.tmp-NullDerefTest

Event Timeline

gAlfonso-bit created this revision.Dec 6 2022, 12:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 6 2022, 12:50 PM
gAlfonso-bit requested review of this revision.Dec 6 2022, 12:50 PM

I agree that the call site uses are somewhat problematic, but cast has stronger guarantee. Do you have a test case to trigger a code path that dyn_cast returns nullptr? If not, the if statement should just be replaced with unconditional cast.

llvm/lib/Object/ELFObjectFile.cpp
802–803

This can just used cast and delete llvm_unreachable

I agree that the call site uses are somewhat problematic, but cast has stronger guarantee. Do you have a test case to trigger a code path that dyn_cast returns nullptr? If not, the if statement should just be replaced with unconditional cast.

Done!

gAlfonso-bit marked an inline comment as done.Dec 6 2022, 3:54 PM
MaskRay added inline comments.Dec 6 2022, 3:57 PM
llvm/utils/TableGen/DecoderEmitter.cpp
2111 ↗(On Diff #480661)

See the reverted ba59ec2843f99f19d55d7cd9f9ac536fb038fdab: this change seems wrong.

gAlfonso-bit marked an inline comment as done.Dec 6 2022, 5:03 PM