Skip to content
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

PR for llvm/llvm-project#79992 #79997

Merged
merged 1 commit into from
Feb 1, 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
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12752,7 +12752,8 @@ namespace {
}

if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(E)) {
HandleValue(OVE->getSourceExpr());
if (Expr *SE = OVE->getSourceExpr())
HandleValue(SE);
return;
}

Expand Down
8 changes: 5 additions & 3 deletions clang/lib/StaticAnalyzer/Core/Environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ static const Expr *ignoreTransparentExprs(const Expr *E) {

switch (E->getStmtClass()) {
case Stmt::OpaqueValueExprClass:
E = cast<OpaqueValueExpr>(E)->getSourceExpr();
break;
if (const Expr *SE = cast<OpaqueValueExpr>(E)->getSourceExpr()) {
E = SE;
break;
}
return E;
case Stmt::ExprWithCleanupsClass:
E = cast<ExprWithCleanups>(E)->getSubExpr();
break;
Expand Down Expand Up @@ -98,7 +101,6 @@ SVal Environment::getSVal(const EnvironmentEntry &Entry,
case Stmt::CXXBindTemporaryExprClass:
case Stmt::ExprWithCleanupsClass:
case Stmt::GenericSelectionExprClass:
case Stmt::OpaqueValueExprClass:
case Stmt::ConstantExprClass:
case Stmt::ParenExprClass:
case Stmt::SubstNonTypeTemplateParmExprClass:
Expand Down
13 changes: 13 additions & 0 deletions clang/test/Analysis/templates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,16 @@ namespace rdar13954714 {
// force instantiation
template void blockWithStatic<true>();
}

namespace structural_value_crash {
constexpr char abc[] = "abc";

template <const char* in>
void use_template_param() {
const char *p = in;
}

void force_instantiate() {
use_template_param<abc>();
}
}
17 changes: 17 additions & 0 deletions clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,20 @@ namespace ReportedRegression1 {
return dummy.exit_code();
}
}

namespace ReportedRegression2 {
const char str[] = "dummy";

struct S {
S operator+(const char*) const;
};

template <const char* in>
void fn() {
auto s = S{} + in;
}

void use() {
fn<str>();
}
}
Loading