Skip to content

Commit 813325e

Browse files
authored
[Clang][NFC] Change uses of getAs() to castAs() where the target type is assured. (#130188)
Static analysis identified two uses of `getAs()` for which the result pointer was unconditionally dereferenced. Source code inspection confirmed that the target type is assured by prior checks. This change replaces these uses of `getAs()` with `castAs()`. The first case, in `clang/lib/CodeGen/Targets/AArch64.cpp`, performs a cast to `BuiltinType` following a check for `isBuiltinType()`. The second case, in `clang/lib/Sema/SemaTemplateVariadic.cpp`, performs a cast to `PackExpansionType` on the result of a call to `getAsType()` on an object of type `TemplateArgument` following confirmation that `isPackExpansion()` returned true and that `getKind()` returned `TemplateArgument::Type`. Inspection of `isPackExpansion()` revealed that it only returns true when the template argument kind is `TemplateArgument::Type` if `isa<PackExpansionType>(getAsType())` is true.
1 parent 93f0f3d commit 813325e

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

clang/lib/CodeGen/Targets/AArch64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ bool AArch64ABIInfo::passAsPureScalableType(
763763
return false;
764764

765765
bool isPredicate;
766-
switch (Ty->getAs<BuiltinType>()->getKind()) {
766+
switch (Ty->castAs<BuiltinType>()->getKind()) {
767767
#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
768768
case BuiltinType::Id: \
769769
isPredicate = false; \

clang/lib/Sema/SemaTemplateVariadic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ bool Sema::CheckParameterPacksForExpansion(
834834

835835
if (TA.getKind() == TemplateArgument::Type)
836836
return !TA.getAsType()
837-
->getAs<PackExpansionType>()
837+
->castAs<PackExpansionType>()
838838
->getNumExpansions();
839839

840840
if (TA.getKind() == TemplateArgument::Expression)

0 commit comments

Comments
 (0)