Skip to content

[clang][Diagnostics] Add source range to uninitialized diagnostics #65896

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
Sep 11, 2023
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
6 changes: 4 additions & 2 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3711,7 +3711,8 @@ findSubobject(EvalInfo &Info, const Expr *E, const CompleteObject &Obj,
!isValidIndeterminateAccess(handler.AccessKind))) {
if (!Info.checkingPotentialConstantExpression())
Info.FFDiag(E, diag::note_constexpr_access_uninit)
<< handler.AccessKind << O->isIndeterminate();
<< handler.AccessKind << O->isIndeterminate()
<< E->getSourceRange();
return handler.failed();
}

Expand Down Expand Up @@ -4443,7 +4444,8 @@ struct CompoundAssignSubobjectHandler {
return foundVector(Subobj, SubobjType);
case APValue::Indeterminate:
Info.FFDiag(E, diag::note_constexpr_access_uninit)
<< /*read of=*/0 << /*uninitialized object=*/1;
<< /*read of=*/0 << /*uninitialized object=*/1
<< E->getLHS()->getSourceRange();
return false;
default:
// FIXME: can this happen?
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/AST/Interp/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,8 @@ bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
return true;

if (!S.checkingPotentialConstantExpression()) {
const SourceInfo &Loc = S.Current->getSource(OpPC);
S.FFDiag(Loc, diag::note_constexpr_access_uninit)
<< AK << /*uninitialized=*/true;
S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_access_uninit)
<< AK << /*uninitialized=*/true << S.Current->getRange(OpPC);
}
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/AST/Interp/InterpFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,8 @@ SourceLocation InterpFrame::getLocation(CodePtr PC) const {
}

SourceRange InterpFrame::getRange(CodePtr PC) const {
if (Func && Func->getDecl()->isImplicit() && Caller)
return Caller->getRange(RetPC);

return S.getRange(Func, PC);
}
8 changes: 8 additions & 0 deletions clang/test/Misc/constexpr-source-ranges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ int x = -1 + __INT_MAX__ + 2 + 3;
// CHECK: :{[[@LINE+1]]:9-[[@LINE+1]]:19}:
int a = -(1 << 31) + 1;
}


constexpr int uninit() {
int aaa;
// CHECK: :{[[@LINE+1]]:10-[[@LINE+1]]:13}:
return aaa;
}
static_assert(uninit() == 0, "");