[clang] 202ad47 - [clang][bytecode] SourceInfo::Source might be null (#115905)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 12 23:35:54 PST 2024
Author: Timm Baeder
Date: 2024-11-13T08:35:50+01:00
New Revision: 202ad47fe1bd652ee5cc7612e696a2479398c44f
URL: https://github.com/llvm/llvm-project/commit/202ad47fe1bd652ee5cc7612e696a2479398c44f
DIFF: https://github.com/llvm/llvm-project/commit/202ad47fe1bd652ee5cc7612e696a2479398c44f.diff
LOG: [clang][bytecode] SourceInfo::Source might be null (#115905)
This broke in 23fbaff9a3fd2b26418e0c2f10b701049399251f, but the old
.dyn_cast<> handled null.
Added:
Modified:
clang/lib/AST/ByteCode/Source.cpp
clang/lib/AST/ByteCode/Source.h
clang/test/SemaCXX/lambda-expressions.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Source.cpp b/clang/lib/AST/ByteCode/Source.cpp
index 55296ddd8c5583..d4ce7537f3d244 100644
--- a/clang/lib/AST/ByteCode/Source.cpp
+++ b/clang/lib/AST/ByteCode/Source.cpp
@@ -33,7 +33,7 @@ SourceRange SourceInfo::getRange() const {
}
const Expr *SourceInfo::asExpr() const {
- if (const auto *S = dyn_cast<const Stmt *>(Source))
+ if (const auto *S = dyn_cast_if_present<const Stmt *>(Source))
return dyn_cast<Expr>(S);
return nullptr;
}
diff --git a/clang/lib/AST/ByteCode/Source.h b/clang/lib/AST/ByteCode/Source.h
index 3b025535d00b19..c74cda919347c0 100644
--- a/clang/lib/AST/ByteCode/Source.h
+++ b/clang/lib/AST/ByteCode/Source.h
@@ -83,8 +83,12 @@ class SourceInfo final {
SourceLocation getLoc() const;
SourceRange getRange() const;
- const Stmt *asStmt() const { return dyn_cast<const Stmt *>(Source); }
- const Decl *asDecl() const { return dyn_cast<const Decl *>(Source); }
+ const Stmt *asStmt() const {
+ return dyn_cast_if_present<const Stmt *>(Source);
+ }
+ const Decl *asDecl() const {
+ return dyn_cast_if_present<const Decl *>(Source);
+ }
const Expr *asExpr() const;
operator bool() const { return !Source.isNull(); }
diff --git a/clang/test/SemaCXX/lambda-expressions.cpp b/clang/test/SemaCXX/lambda-expressions.cpp
index acf8d014a9896b..f3deb6ee3f4244 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -3,6 +3,11 @@
// RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify=expected,not-cxx03,expected-cxx14 -fblocks %s
// RUN: %clang_cc1 -std=c++17 -Wno-unused-value -verify=expected,not-cxx03 -ast-dump -fblocks %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -Wno-unused-value -fsyntax-only -verify=expected,not-cxx03,cxx03-cxx11,cxx11,expected-cxx14 -fblocks %s -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -std=c++03 -Wno-unused-value -fsyntax-only -verify=expected,cxx03,cxx03-cxx11,expected-cxx14 -fblocks %s -Ddecltype=__decltype -Dstatic_assert=_Static_assert -Wno-c++11-extensions -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify=expected,not-cxx03,expected-cxx14 -fblocks %s -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -std=c++17 -Wno-unused-value -verify=expected,not-cxx03 -ast-dump -fblocks %s -fexperimental-new-constant-interpreter| FileCheck %s
+
namespace std { class type_info; };
namespace ExplicitCapture {
More information about the cfe-commits
mailing list