[clang] 5e27487 - [clang][sema] TryStaticCast - use castAs<> instead of getAs<> to avoid dereference of nullptr
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 12 03:14:50 PST 2022
Author: Simon Pilgrim
Date: 2022-02-12T11:14:19Z
New Revision: 5e27487fc992cece0d703f0bd83480381764b77b
URL: https://github.com/llvm/llvm-project/commit/5e27487fc992cece0d703f0bd83480381764b77b
DIFF: https://github.com/llvm/llvm-project/commit/5e27487fc992cece0d703f0bd83480381764b77b.diff
LOG: [clang][sema] TryStaticCast - use castAs<> instead of getAs<> to avoid dereference of nullptr
The pointer is referenced immediately, so assert the cast is correct instead of returning nullptr
Added:
Modified:
clang/lib/Sema/SemaCast.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index e9c1116257d66..7d580dc5b6b3a 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -1356,7 +1356,7 @@ static TryCastResult TryStaticCast(Sema &Self, ExprResult &SrcExpr,
if (SrcType->isIntegralOrEnumerationType()) {
// [expr.static.cast]p10 If the enumeration type has a fixed underlying
// type, the value is first converted to that type by integral conversion
- const EnumType *Enum = DestType->getAs<EnumType>();
+ const EnumType *Enum = DestType->castAs<EnumType>();
Kind = Enum->getDecl()->isFixed() &&
Enum->getDecl()->getIntegerType()->isBooleanType()
? CK_IntegralToBoolean
More information about the cfe-commits
mailing list