Skip to content

[TCling] Do not add decls for control statements if already annotated #15368

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 2 commits into from
Oct 31, 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
6 changes: 6 additions & 0 deletions core/metacling/src/TClingCallbacks.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,12 @@ bool TClingCallbacks::tryResolveAtRuntimeInternal(LookupResult &R, Scope *S) {
return false;
}

// Prevent redundant declarations for control statements (e.g., for, if, while)
// that have already been annotated.
if (auto annot = Wrapper->getAttr<AnnotateAttr>())
if (annot->getAnnotation().equals("__ResolveAtRuntime") && S->isControlScope())
return false;

VarDecl* Result = VarDecl::Create(C, TU, Loc, Loc, II, C.DependentTy,
/*TypeSourceInfo*/nullptr, SC_None);

Expand Down
13 changes: 13 additions & 0 deletions core/metacling/test/TClingTests.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,16 @@ TEST_F(TClingTests, RefreshNSShadowing)
gInterpreter->Declare("namespace std { namespace Detail {} }; auto c = TClass::GetClass(\"Detail\");");
gInterpreter->ProcessLine("namespace Detail {}");
}

// #8367
TEST_F(TClingTests, UndeclaredIdentifierCrash)
{
auto expectedError = R"(error: use of undeclared identifier 'i'
for(i=0; i < 0;); // the second usage of `i` was enough to get a segfault
^
)";
using namespace ROOT::TestSupport;
CheckDiagsRAII diagRAII;
diagRAII.requiredDiag(kError, "cling", expectedError, false);
gInterpreter->ProcessLine("for(i=0; i < 0;); // the second usage of `i` was enough to get a segfault");
}
Loading