From 7ab99eba0f9925226abb98ec7fbd24828ee8576e Mon Sep 17 00:00:00 2001 From: Devajith Valaparambil Sreeramaswamy Date: Mon, 9 Mar 2026 18:17:34 +0100 Subject: [PATCH 1/2] [cling][AST] Refactor to use switch on TypeClass This will help keep unrelated changes away from the actual upgrade. --- interpreter/cling/lib/Utils/AST.cpp | 54 ++++++++++++----------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/interpreter/cling/lib/Utils/AST.cpp b/interpreter/cling/lib/Utils/AST.cpp index f1136a10ce000..4cd16d7ebdc24 100644 --- a/interpreter/cling/lib/Utils/AST.cpp +++ b/interpreter/cling/lib/Utils/AST.cpp @@ -560,21 +560,20 @@ namespace utils { } else { Decl* decl = nullptr; - const TypedefType* typedeftype = - dyn_cast_or_null(&(*desugared)); - const UsingType* usingtype = - dyn_cast_or_null(&(*desugared)); - if (typedeftype) { - decl = typedeftype->getDecl(); - } else if (usingtype) { - decl = usingtype->getFoundDecl(); - } else { - // There are probably other cases ... - const TagType* tagdecltype = dyn_cast_or_null(&(*desugared)); - if (tagdecltype) { - decl = tagdecltype->getDecl(); - } else { - decl = desugared->getAsCXXRecordDecl(); + if (!desugared.isNull()) { + const Type* desugaredTy = desugared.getTypePtr(); + switch (desugaredTy->getTypeClass()) { + case Type::Typedef: + decl = cast(desugaredTy)->getDecl(); + break; + case Type::Using: + decl = cast(desugaredTy)->getFoundDecl(); + break; + case Type::Record: + case Type::Enum: + decl = cast(desugaredTy)->getDecl(); + break; + default: decl = desugared->getAsCXXRecordDecl(); break; } } if (decl) { @@ -1142,22 +1141,15 @@ namespace utils { // in which case we want to add it ... but we can't really preserve // the typedef in this case ... - Decl *decl = nullptr; - const TypedefType* typedeftype = - dyn_cast_or_null(QT.getTypePtr()); - const UsingType* usingtype = - dyn_cast_or_null(QT.getTypePtr()); - if (typedeftype) { - decl = typedeftype->getDecl(); - } else if (usingtype) { - decl = usingtype->getFoundDecl(); - } else { - // There are probably other cases ... - const TagType* tagdecltype = dyn_cast_or_null(QT.getTypePtr()); - if (tagdecltype) { - decl = tagdecltype->getDecl(); - } else { - decl = QT->getAsCXXRecordDecl(); + Decl* decl = nullptr; + if (!QT.isNull()) { + const Type* QTTy = QT.getTypePtr(); + switch (QTTy->getTypeClass()) { + case Type::Typedef: decl = cast(QTTy)->getDecl(); break; + case Type::Using: decl = cast(QTTy)->getFoundDecl(); break; + case Type::Record: + case Type::Enum: decl = cast(QTTy)->getDecl(); break; + default: decl = QT->getAsCXXRecordDecl(); break; } } if (decl) { From 9c011807236dbd65c8ae5b51ead55826ae1f38ca Mon Sep 17 00:00:00 2001 From: Devajith Valaparambil Sreeramaswamy Date: Wed, 11 Mar 2026 15:23:09 +0100 Subject: [PATCH 2/2] [cling][test][lit] Remove deprecated `%T` Ref: https://github.com/llvm/llvm-project/commit/db8dad20b37f4befe054e586b40f8dd1eaeda842 https://github.com/llvm/llvm-project/commit/7ff6973f1ae91985bb6b5faa8658e81dbaadbd25 --- interpreter/cling/test/CodeGeneration/Symbols.C | 5 +++-- .../cling/test/CodeUnloading/PCH/VTables.C | 9 +++++---- interpreter/cling/test/Driver/CurrentDirRm.C | 7 ++++--- interpreter/cling/test/LibraryCall/call.C | 5 +++-- .../cling/test/LibraryCall/callable_lib.C | 5 +++-- interpreter/cling/test/Pragmas/add_env_path.C | 9 +++++---- interpreter/cling/test/Pragmas/load.C | 5 +++-- interpreter/cling/test/Prompt/OutputRedirect.C | 17 +++++++++-------- 8 files changed, 35 insertions(+), 27 deletions(-) diff --git a/interpreter/cling/test/CodeGeneration/Symbols.C b/interpreter/cling/test/CodeGeneration/Symbols.C index 87f083ea32a3c..8ec44839ff39d 100644 --- a/interpreter/cling/test/CodeGeneration/Symbols.C +++ b/interpreter/cling/test/CodeGeneration/Symbols.C @@ -6,8 +6,9 @@ // LICENSE.TXT for details. //------------------------------------------------------------------------------ -// RUN: clang -shared %fPIC -DCLING_EXPORT=%dllexport -DBUILD_SHARED %s -o%T/libSymbols%shlibext -// RUN: %cling --nologo -L%T -lSymbols %s | FileCheck %s +// RUN: rm -rf %t.dir && mkdir -p %t.dir +// RUN: clang -shared %fPIC -DCLING_EXPORT=%dllexport -DBUILD_SHARED %s -o%t.dir/libSymbols%shlibext +// RUN: %cling --nologo -L%t.dir -lSymbols %s | FileCheck %s // Check that weak symbols do not get re-emitted (ROOT-6124) extern "C" int printf(const char*,...); diff --git a/interpreter/cling/test/CodeUnloading/PCH/VTables.C b/interpreter/cling/test/CodeUnloading/PCH/VTables.C index 5386598dfd9ee..73f7f6d9f75c9 100644 --- a/interpreter/cling/test/CodeUnloading/PCH/VTables.C +++ b/interpreter/cling/test/CodeUnloading/PCH/VTables.C @@ -1,9 +1,10 @@ -// RUN: %mkdir "%T/Rel/Path" || true -// RUN: %rm "CompGen.h.pch" && %rm "%T/Rel/Path/Relative.pch" +// RUN: rm -rf %t.dir && mkdir -p %t.dir +// RUN: %mkdir "%t.dir/Rel/Path" || true +// RUN: %rm "CompGen.h.pch" && %rm "%t.dir/Rel/Path/Relative.pch" // RUN: clang -x c++-header -fexceptions -fcxx-exceptions -std=%std_cxx -pthread %S/Inputs/CompGen.h -o CompGen.h.pch -// RUN: clang -x c++-header -fexceptions -fcxx-exceptions -std=%std_cxx -pthread %S/Inputs/CompGen.h -o %T/Rel/Path/Relative.pch +// RUN: clang -x c++-header -fexceptions -fcxx-exceptions -std=%std_cxx -pthread %S/Inputs/CompGen.h -o %t.dir/Rel/Path/Relative.pch // RUN: cat %s | %cling -I%p -Xclang -include-pch -Xclang CompGen.h.pch 2>&1 | FileCheck %s -// RUN: cat %s | %cling -I%p -I%T/Rel/Path -include-pch Relative.pch 2>&1 | FileCheck %s +// RUN: cat %s | %cling -I%p -I%t.dir/Rel/Path -include-pch Relative.pch 2>&1 | FileCheck %s //.storeState "a" .x TriggerCompGen.h diff --git a/interpreter/cling/test/Driver/CurrentDirRm.C b/interpreter/cling/test/Driver/CurrentDirRm.C index d8ab6779d8ac1..744f7c0c26647 100644 --- a/interpreter/cling/test/Driver/CurrentDirRm.C +++ b/interpreter/cling/test/Driver/CurrentDirRm.C @@ -7,9 +7,10 @@ //------------------------------------------------------------------------------ // Removing the cwd on Unix works but on Windows cannot be done. -// RUN: %mkdir "%T/Remove" -// RUN: cd "%T/Remove" -// RUN: %rmdir "%T/Remove" +// RUN: rm -rf %t.dir && mkdir -p %t.dir +// RUN: %mkdir "%t.dir/Remove" +// RUN: cd "%t.dir/Remove" +// RUN: %rmdir "%t.dir/Remove" // RUN: %cling %s -Xclang -verify 2>&1 | FileCheck %s // UNSUPPORTED: system-windows diff --git a/interpreter/cling/test/LibraryCall/call.C b/interpreter/cling/test/LibraryCall/call.C index c01442b506667..21fd335a0d754 100644 --- a/interpreter/cling/test/LibraryCall/call.C +++ b/interpreter/cling/test/LibraryCall/call.C @@ -6,8 +6,9 @@ // LICENSE.TXT for details. //------------------------------------------------------------------------------ -// RUN: clang -shared -DCLING_EXPORT=%dllexport %S/call_lib.c -o%T/libcall_lib2%shlibext -// RUN: cat %s | %cling -L%T | FileCheck %s +// RUN: rm -rf %t.dir && mkdir -p %t.dir +// RUN: clang -shared -DCLING_EXPORT=%dllexport %S/call_lib.c -o%t.dir/libcall_lib2%shlibext +// RUN: cat %s | %cling -L%t.dir | FileCheck %s .L libcall_lib2 extern "C" int cling_testlibrary_function(); diff --git a/interpreter/cling/test/LibraryCall/callable_lib.C b/interpreter/cling/test/LibraryCall/callable_lib.C index 72a6bb16504db..ce847b6f58eee 100644 --- a/interpreter/cling/test/LibraryCall/callable_lib.C +++ b/interpreter/cling/test/LibraryCall/callable_lib.C @@ -6,8 +6,9 @@ // LICENSE.TXT for details. //------------------------------------------------------------------------------ -// RUN: clang -shared -DCLING_EXPORT=%dllexport %S/call_lib.c -o%T/libcall_lib%shlibext -// RUN: cat %s | %cling -L%T | FileCheck %s +// RUN: rm -rf %t.dir && mkdir -p %t.dir +// RUN: clang -shared -DCLING_EXPORT=%dllexport %S/call_lib.c -o%t.dir/libcall_lib%shlibext +// RUN: cat %s | %cling -L%t.dir | FileCheck %s .L libcall_lib extern "C" int cling_testlibrary_function(); diff --git a/interpreter/cling/test/Pragmas/add_env_path.C b/interpreter/cling/test/Pragmas/add_env_path.C index 99ac809e7f9bd..48badf5dcf8c2 100644 --- a/interpreter/cling/test/Pragmas/add_env_path.C +++ b/interpreter/cling/test/Pragmas/add_env_path.C @@ -6,10 +6,11 @@ // LICENSE.TXT for details. //------------------------------------------------------------------------------ -// RUN: %mkdir "%T/subdir" || true -// RUN: %rm "%T/subdir/libtest%shlibext" -// RUN: clang -DCLING_EXPORT=%dllexport -shared %S/call_lib.c -o %T/subdir/libtest%shlibext -// RUN: cat %s | %cling -I %S -DENVVAR_LIB="\"%/T/subdir\"" -DENVVAR_INC="\"%/p/subdir\"" -Xclang -verify 2>&1 | FileCheck %s +// RUN: rm -rf %t.dir && mkdir -p %t.dir +// RUN: %mkdir "%t.dir/subdir" || true +// RUN: %rm "%t.dir/subdir/libtest%shlibext" +// RUN: clang -DCLING_EXPORT=%dllexport -shared %S/call_lib.c -o %t.dir/subdir/libtest%shlibext +// RUN: cat %s | %cling -I %S -DENVVAR_LIB="\"%/t.dir/subdir\"" -DENVVAR_INC="\"%/p/subdir\"" -Xclang -verify 2>&1 | FileCheck %s extern "C" int cling_testlibrary_function(); diff --git a/interpreter/cling/test/Pragmas/load.C b/interpreter/cling/test/Pragmas/load.C index 7c3f0709fa796..5313e15fd4319 100644 --- a/interpreter/cling/test/Pragmas/load.C +++ b/interpreter/cling/test/Pragmas/load.C @@ -6,8 +6,9 @@ // LICENSE.TXT for details. //------------------------------------------------------------------------------ -// RUN: clang -shared -DCLING_EXPORT=%dllexport %S/call_lib.c -o%T/libcall_lib%shlibext -// RUN: cat %s | %cling -L %T -Xclang -verify 2>&1 | FileCheck %s +// RUN: rm -rf %t.dir && mkdir -p %t.dir +// RUN: clang -shared -DCLING_EXPORT=%dllexport %S/call_lib.c -o%t.dir/libcall_lib%shlibext +// RUN: cat %s | %cling -L %t.dir -Xclang -verify 2>&1 | FileCheck %s #pragma cling load("DoesNotExistPleaseRecover") // expected-error@input_line_12:1{{'DoesNotExistPleaseRecover' file not found}} diff --git a/interpreter/cling/test/Prompt/OutputRedirect.C b/interpreter/cling/test/Prompt/OutputRedirect.C index 1ddb1f1ac80e3..a292f1331557a 100644 --- a/interpreter/cling/test/Prompt/OutputRedirect.C +++ b/interpreter/cling/test/Prompt/OutputRedirect.C @@ -1,11 +1,12 @@ -// RUN: cat %s | %cling -DCLING_TMP="\"%/T\"" | FileCheck --check-prefix=CHECKOUT %s -// RUN: cat %T/outfile.txt | FileCheck --check-prefix=CHECK-REDIRECTOUT %s -// RUN: cat %T/errfile.txt | FileCheck --check-prefix=CHECK-REDIRECTERR %s -// RUN: cat %T/bothfile.txt | FileCheck --check-prefix=CHECK-REDIRECTBOTH %s -// RUN: cat %T/anotheroutfile.txt | FileCheck --check-prefix=CHECK-REDIRECTANOTHER %s -// RUN: cat %T/nospace.txt | FileCheck --check-prefix=CHECK-NOSPACE %s -// RUN: cat %s | %cling -DCLING_TMP="\"%/T\"" 2> %T/stderr.txt && cat %T/stderr.txt | FileCheck --check-prefix=CHECKERR %s -// RUN: cat %s | %cling -DCLING_TMP="\"%/T\"" 2>&1 | FileCheck --check-prefix=CHECKERR --check-prefix=CHECKOUT %s +// RUN: rm -rf %t.dir && mkdir -p %t.dir +// RUN: cat %s | %cling -DCLING_TMP="\"%/t.dir\"" | FileCheck --check-prefix=CHECKOUT %s +// RUN: cat %t.dir/outfile.txt | FileCheck --check-prefix=CHECK-REDIRECTOUT %s +// RUN: cat %t.dir/errfile.txt | FileCheck --check-prefix=CHECK-REDIRECTERR %s +// RUN: cat %t.dir/bothfile.txt | FileCheck --check-prefix=CHECK-REDIRECTBOTH %s +// RUN: cat %t.dir/anotheroutfile.txt | FileCheck --check-prefix=CHECK-REDIRECTANOTHER %s +// RUN: cat %t.dir/nospace.txt | FileCheck --check-prefix=CHECK-NOSPACE %s +// RUN: cat %s | %cling -DCLING_TMP="\"%/t.dir\"" 2> %t.dir/stderr.txt && cat %t.dir/stderr.txt | FileCheck --check-prefix=CHECKERR %s +// RUN: cat %s | %cling -DCLING_TMP="\"%/t.dir\"" 2>&1 | FileCheck --check-prefix=CHECKERR --check-prefix=CHECKOUT %s #include