-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Clang][NFC] Change uses of getAs() to castAs() where the target type is assured. #130188
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
[Clang][NFC] Change uses of getAs() to castAs() where the target type is assured. #130188
Conversation
… is assured. 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.
|
@llvm/pr-subscribers-backend-aarch64 @llvm/pr-subscribers-clang Author: Tom Honermann (tahonermann) ChangesStatic analysis identified two uses of The first case, in The second case, in Full diff: https://github.com/llvm/llvm-project/pull/130188.diff 2 Files Affected:
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)
|
|
@llvm/pr-subscribers-clang-codegen Author: Tom Honermann (tahonermann) ChangesStatic analysis identified two uses of The first case, in The second case, in Full diff: https://github.com/llvm/llvm-project/pull/130188.diff 2 Files Affected:
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)
|
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 ofgetAs()withcastAs().The first case, in
clang/lib/CodeGen/Targets/AArch64.cpp, performs a cast toBuiltinTypefollowing a check forisBuiltinType().The second case, in
clang/lib/Sema/SemaTemplateVariadic.cpp, performs a cast toPackExpansionTypeon the result of a call togetAsType()on an object of typeTemplateArgumentfollowing confirmation thatisPackExpansion()returned true and thatgetKind()returnedTemplateArgument::Type. Inspection ofisPackExpansion()revealed that it only returns true when the template argument kind isTemplateArgument::Typeifisa<PackExpansionType>(getAsType())is true.