Skip to content

Commit d3fd792

Browse files
authored
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
1 parent a19ddff commit d3fd792

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,12 +586,12 @@ static void initializeBuffer(CodeGenModule &CGM, llvm::GlobalVariable *GV,
586586
void CGHLSLRuntime::initializeBufferFromBinding(const HLSLBufferDecl *BufDecl,
587587
llvm::GlobalVariable *GV,
588588
HLSLResourceBindingAttr *RBA) {
589+
assert(RBA && "expect a nonnull binding attribute");
589590
llvm::Type *Int1Ty = llvm::Type::getInt1Ty(CGM.getLLVMContext());
590591
auto *NonUniform = llvm::ConstantInt::get(Int1Ty, false);
591592
auto *Index = llvm::ConstantInt::get(CGM.IntTy, 0);
592593
auto *RangeSize = llvm::ConstantInt::get(CGM.IntTy, 1);
593-
auto *Space =
594-
llvm::ConstantInt::get(CGM.IntTy, RBA ? RBA->getSpaceNumber() : 0);
594+
auto *Space = llvm::ConstantInt::get(CGM.IntTy, RBA->getSpaceNumber());
595595
Value *Name = nullptr;
596596

597597
llvm::Intrinsic::ID IntrinsicID =

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2418,7 +2418,7 @@ static bool CheckFloatOrHalfRepresentation(Sema *S, SourceLocation Loc,
24182418
clang::QualType PassedType) {
24192419
clang::QualType BaseType =
24202420
PassedType->isVectorType()
2421-
? PassedType->getAs<clang::VectorType>()->getElementType()
2421+
? PassedType->castAs<clang::VectorType>()->getElementType()
24222422
: PassedType;
24232423
if (!BaseType->isHalfType() && !BaseType->isFloat32Type())
24242424
return S->Diag(Loc, diag::err_builtin_invalid_arg_type)

0 commit comments

Comments
 (0)