[clang] d3fd792 - Clarify some code based on static analysis complaints; NFC (#145679)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 26 03:55:51 PDT 2025
Author: Aaron Ballman
Date: 2025-06-26T06:55:48-04:00
New Revision: d3fd7921d4d7158a487bdc839c9fa6c3b650b997
URL: https://github.com/llvm/llvm-project/commit/d3fd7921d4d7158a487bdc839c9fa6c3b650b997
DIFF: https://github.com/llvm/llvm-project/commit/d3fd7921d4d7158a487bdc839c9fa6c3b650b997.diff
LOG: Clarify some code based on static analysis complaints; NFC (#145679)
In one case, we have a null pointer check that's unnecessary because the
only caller of the function already asserts the value is non-null.
In the other case, we've got an anti-pattern of `is` followed by `get`.
The logic was easier to repair by changing `get` to `cast`.
Neither case is a functional change.
Fixes #145525
Added:
Modified:
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/lib/Sema/SemaHLSL.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index f2e992fb7fa69..f954003bf5092 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -586,12 +586,12 @@ static void initializeBuffer(CodeGenModule &CGM, llvm::GlobalVariable *GV,
void CGHLSLRuntime::initializeBufferFromBinding(const HLSLBufferDecl *BufDecl,
llvm::GlobalVariable *GV,
HLSLResourceBindingAttr *RBA) {
+ assert(RBA && "expect a nonnull binding attribute");
llvm::Type *Int1Ty = llvm::Type::getInt1Ty(CGM.getLLVMContext());
auto *NonUniform = llvm::ConstantInt::get(Int1Ty, false);
auto *Index = llvm::ConstantInt::get(CGM.IntTy, 0);
auto *RangeSize = llvm::ConstantInt::get(CGM.IntTy, 1);
- auto *Space =
- llvm::ConstantInt::get(CGM.IntTy, RBA ? RBA->getSpaceNumber() : 0);
+ auto *Space = llvm::ConstantInt::get(CGM.IntTy, RBA->getSpaceNumber());
Value *Name = nullptr;
llvm::Intrinsic::ID IntrinsicID =
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 0974ccbf9267c..3470a39f201d1 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2418,7 +2418,7 @@ static bool CheckFloatOrHalfRepresentation(Sema *S, SourceLocation Loc,
clang::QualType PassedType) {
clang::QualType BaseType =
PassedType->isVectorType()
- ? PassedType->getAs<clang::VectorType>()->getElementType()
+ ? PassedType->castAs<clang::VectorType>()->getElementType()
: PassedType;
if (!BaseType->isHalfType() && !BaseType->isFloat32Type())
return S->Diag(Loc, diag::err_builtin_invalid_arg_type)
More information about the cfe-commits
mailing list