From 4d0c9fa7474f8adedd7f471c18f22e4dbeefd190 Mon Sep 17 00:00:00 2001 From: Devajith Valaparambil Sreeramaswamy Date: Sun, 28 Apr 2024 12:54:22 +0200 Subject: [PATCH 1/2] [TCling] Do not add decls for control statements if already annotated --- core/metacling/src/TClingCallbacks.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/metacling/src/TClingCallbacks.cxx b/core/metacling/src/TClingCallbacks.cxx index edbd33107192a..5a6fe519f27b3 100644 --- a/core/metacling/src/TClingCallbacks.cxx +++ b/core/metacling/src/TClingCallbacks.cxx @@ -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()) + if (annot->getAnnotation().equals("__ResolveAtRuntime") && S->isControlScope()) + return false; + VarDecl* Result = VarDecl::Create(C, TU, Loc, Loc, II, C.DependentTy, /*TypeSourceInfo*/nullptr, SC_None); From 1c45df89d60ccb66440327fca9bb51ccfa56a906 Mon Sep 17 00:00:00 2001 From: Danilo Piparo Date: Wed, 25 Sep 2024 10:08:29 +0200 Subject: [PATCH 2/2] [TCling] Add test for root-project#8367 --- core/metacling/test/TClingTests.cxx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/metacling/test/TClingTests.cxx b/core/metacling/test/TClingTests.cxx index 5caba0a7ea2f0..171bd3322092c 100644 --- a/core/metacling/test/TClingTests.cxx +++ b/core/metacling/test/TClingTests.cxx @@ -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"); +}