From 89ccb7a55c723d37db929958328de4efa1736f71 Mon Sep 17 00:00:00 2001 From: Axel Naumann Date: Thu, 11 Nov 2021 16:08:27 +0100 Subject: [PATCH 1/3] [cling] Provide C value printer, adopted from Ruben De Smet! --- .../lib/Interpreter/ValueExtractionSynthesizer.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/interpreter/cling/lib/Interpreter/ValueExtractionSynthesizer.cpp b/interpreter/cling/lib/Interpreter/ValueExtractionSynthesizer.cpp index fc5685722a25d..8eb5a5f276721 100644 --- a/interpreter/cling/lib/Interpreter/ValueExtractionSynthesizer.cpp +++ b/interpreter/cling/lib/Interpreter/ValueExtractionSynthesizer.cpp @@ -22,6 +22,16 @@ #include "clang/Sema/Sema.h" #include "clang/Sema/SemaDiagnostic.h" +// Implements the CValueExtractionPrinter interface. +extern "C" { + CLING_LIB_EXPORT + void cling_SetValueNoAlloc(void * /*cling::Value* V*/) { + } + CLING_LIB_EXPORT + void cling_SetValueWithAlloc(void * /*cling::Value* V*/) { + } +} + using namespace clang; namespace cling { @@ -430,6 +440,10 @@ namespace { return VSError(m_Sema, E, "cling::runtime::gCling"); if (!(NSD = utils::Lookup::Namespace(m_Sema, "internal", NSD))) return VSError(m_Sema, E, "cling::runtime::internal namespace"); + } else { + // C, ObjC,... + if (!(NSD = utils::Lookup::Namespace(m_Sema, "cling"))) + return VSError(m_Sema, E, "cling namespace"); } LookupResult R(*m_Sema, &m_Context->Idents.get("setValueNoAlloc"), SourceLocation(), Sema::LookupOrdinaryName, From 8296fc1657fb8f8bf2db9463474954161ba1a8d6 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Sat, 13 Apr 2024 12:46:04 +0200 Subject: [PATCH 2/3] [cling] add tests for C mode ValuePrinting Fixes https://github.com/root-project/cling/issues/364 Fixes https://github.com/root-project/cling/issues/419 --- interpreter/cling/test/Driver/C.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/interpreter/cling/test/Driver/C.c b/interpreter/cling/test/Driver/C.c index ee302920495b4..2f82c02a7fa5f 100644 --- a/interpreter/cling/test/Driver/C.c +++ b/interpreter/cling/test/Driver/C.c @@ -11,13 +11,13 @@ // Validate cling C mode. -// Fix value printing! - int printf(const char*,...); printf("CHECK 123 %p\n", gCling); // CHECK: CHECK 123 -12 // expected-error {{ValueExtractionSynthesizer could not find: 'cling::runtime::internal::setValueNoAlloc'.}} - -32 // expected-error {{ValueExtractionSynthesizer could not find: 'cling::runtime::internal::setValueNoAlloc'.}} +int i = 1 // CHECK: (int) 1 +sizeof(int) // CHECK: 4 +int x = sizeof(int); +printf("CHECK %d\n", x); // CHECK: CHECK 4 +// expected-no-diagnostics .q From 9e915d80415acdb93c23c45238f77fec1c5eab14 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Sat, 13 Apr 2024 12:49:53 +0200 Subject: [PATCH 3/3] [cling] fix c print test missing data type return --- interpreter/cling/test/Driver/C.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interpreter/cling/test/Driver/C.c b/interpreter/cling/test/Driver/C.c index 2f82c02a7fa5f..05201877e8dd8 100644 --- a/interpreter/cling/test/Driver/C.c +++ b/interpreter/cling/test/Driver/C.c @@ -15,7 +15,7 @@ int printf(const char*,...); printf("CHECK 123 %p\n", gCling); // CHECK: CHECK 123 int i = 1 // CHECK: (int) 1 -sizeof(int) // CHECK: 4 +sizeof(int) // CHECK: (unsigned long) 4 int x = sizeof(int); printf("CHECK %d\n", x); // CHECK: CHECK 4