Skip to content

[nsan][NFC] Use cast when dyn_cast is not needed. #101147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 1, 2024

Conversation

yingcong-wu
Copy link
Contributor

@yingcong-wu yingcong-wu commented Jul 30, 2024

Use cast instead to replace dyn_cast when dyn_cast is not needed/not checked.

Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

....

@llvmbot
Copy link
Member

llvmbot commented Jul 31, 2024

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Wu Yingcong (yingcong-wu)

Changes
  1. Avoid an auto copy
  2. use cast instead to replace dyn_cast when dyn_cast is not needed/not checked.

Full diff: https://github.com/llvm/llvm-project/pull/101147.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp (+2-2)
diff --git a/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp
index 832506f639a74..5872396669435 100644
--- a/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp
@@ -1715,7 +1715,7 @@ Value *NumericalStabilitySanitizer::createShadowValueWithOperandsAvailable(
                                Map.getShadow(BinOp->getOperand(1)));
 
   if (isa<UIToFPInst>(&Inst) || isa<SIToFPInst>(&Inst)) {
-    auto *Cast = dyn_cast<CastInst>(&Inst);
+    auto *Cast = cast<CastInst>(&Inst);
     return Builder.CreateCast(Cast->getOpcode(), Cast->getOperand(0),
                               ExtendedVT);
   }
@@ -2168,7 +2168,7 @@ bool NumericalStabilitySanitizer::sanitizeFunction(
 
   // The last pass populates shadow phis with shadow values.
   for (PHINode *Phi : OriginalPhis) {
-    PHINode *ShadowPhi = dyn_cast<PHINode>(ValueToShadow.getShadow(Phi));
+    PHINode *ShadowPhi = cast<PHINode>(ValueToShadow.getShadow(Phi));
     for (unsigned I : seq(Phi->getNumOperands())) {
       Value *V = Phi->getOperand(I);
       Value *Shadow = ValueToShadow.getShadow(V);

@yingcong-wu yingcong-wu requested a review from MaskRay July 31, 2024 02:38
Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The title can be made more descriptive. Perhaps [nsan] Use cast. NFC

@yingcong-wu yingcong-wu changed the title [nsan] minor fix for the nsan pass [nsan][NFC] Use cast instead of dyn_cast in some cases. Jul 31, 2024
@yingcong-wu yingcong-wu changed the title [nsan][NFC] Use cast instead of dyn_cast in some cases. [nsan][NFC] Use cast instead of dyn_cast when dyn_cast is not needed. Jul 31, 2024
@yingcong-wu yingcong-wu changed the title [nsan][NFC] Use cast instead of dyn_cast when dyn_cast is not needed. [nsan][NFC] Use cast when dyn_cast is not needed. Jul 31, 2024
@yingcong-wu yingcong-wu merged commit 430b90f into llvm:main Aug 1, 2024
9 checks passed
@yingcong-wu yingcong-wu deleted the yc/0730-nsan-minor-fix branch November 13, 2024 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants