[clang] 813325e - [Clang][NFC] Change uses of getAs() to castAs() where the target type is assured. (#130188)

via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 6 15:12:24 PST 2025


Author: Tom Honermann
Date: 2025-03-06T18:12:20-05:00
New Revision: 813325e5d44c01f50aaca035629fcba8157fd5c0

URL: https://github.com/llvm/llvm-project/commit/813325e5d44c01f50aaca035629fcba8157fd5c0
DIFF: https://github.com/llvm/llvm-project/commit/813325e5d44c01f50aaca035629fcba8157fd5c0.diff

LOG: [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.

Added: 
    

Modified: 
    clang/lib/CodeGen/Targets/AArch64.cpp
    clang/lib/Sema/SemaTemplateVariadic.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/Targets/AArch64.cpp b/clang/lib/CodeGen/Targets/AArch64.cpp
index d6e0e720a0941..073ca3cc82690 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -763,7 +763,7 @@ bool AArch64ABIInfo::passAsPureScalableType(
     return false;
 
   bool isPredicate;
-  switch (Ty->getAs<BuiltinType>()->getKind()) {
+  switch (Ty->castAs<BuiltinType>()->getKind()) {
 #define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId)                    \
   case BuiltinType::Id:                                                        \
     isPredicate = false;                                                       \

diff  --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp
index fad00f7648848..d9256dbd07d7a 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -834,7 +834,7 @@ bool Sema::CheckParameterPacksForExpansion(
 
             if (TA.getKind() == TemplateArgument::Type)
               return !TA.getAsType()
-                          ->getAs<PackExpansionType>()
+                          ->castAs<PackExpansionType>()
                           ->getNumExpansions();
 
             if (TA.getKind() == TemplateArgument::Expression)


        


More information about the cfe-commits mailing list