[clang][bytecode] SourceInfo::Source might be null (#115905)

This broke in 23fbaff9a3fd2b26418e0c2f10b701049399251f, but the old
.dyn_cast<> handled null.
This commit is contained in:
Timm Baeder 2024-11-13 08:35:50 +01:00 committed by GitHub
parent fcacda899f
commit 202ad47fe1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 3 deletions

View File

@ -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;
}

View File

@ -83,8 +83,12 @@ public:
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(); }

View File

@ -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 {