Skip to content

Commit 202ad47

Browse files
authored
[clang][bytecode] SourceInfo::Source might be null (#115905)
This broke in 23fbaff, but the old .dyn_cast<> handled null.
1 parent fcacda8 commit 202ad47

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

clang/lib/AST/ByteCode/Source.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SourceRange SourceInfo::getRange() const {
3333
}
3434

3535
const Expr *SourceInfo::asExpr() const {
36-
if (const auto *S = dyn_cast<const Stmt *>(Source))
36+
if (const auto *S = dyn_cast_if_present<const Stmt *>(Source))
3737
return dyn_cast<Expr>(S);
3838
return nullptr;
3939
}

clang/lib/AST/ByteCode/Source.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ class SourceInfo final {
8383
SourceLocation getLoc() const;
8484
SourceRange getRange() const;
8585

86-
const Stmt *asStmt() const { return dyn_cast<const Stmt *>(Source); }
87-
const Decl *asDecl() const { return dyn_cast<const Decl *>(Source); }
86+
const Stmt *asStmt() const {
87+
return dyn_cast_if_present<const Stmt *>(Source);
88+
}
89+
const Decl *asDecl() const {
90+
return dyn_cast_if_present<const Decl *>(Source);
91+
}
8892
const Expr *asExpr() const;
8993

9094
operator bool() const { return !Source.isNull(); }

clang/test/SemaCXX/lambda-expressions.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
// RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify=expected,not-cxx03,expected-cxx14 -fblocks %s
44
// RUN: %clang_cc1 -std=c++17 -Wno-unused-value -verify=expected,not-cxx03 -ast-dump -fblocks %s | FileCheck %s
55

6+
// 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
7+
// 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
8+
// RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify=expected,not-cxx03,expected-cxx14 -fblocks %s -fexperimental-new-constant-interpreter
9+
// RUN: %clang_cc1 -std=c++17 -Wno-unused-value -verify=expected,not-cxx03 -ast-dump -fblocks %s -fexperimental-new-constant-interpreter| FileCheck %s
10+
611
namespace std { class type_info; };
712

813
namespace ExplicitCapture {

0 commit comments

Comments
 (0)