Skip to content

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

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

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/AST/ByteCode/Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions clang/lib/AST/ByteCode/Source.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down
5 changes: 5 additions & 0 deletions clang/test/SemaCXX/lambda-expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading