diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index fc7511e913673..db3d74e124e7d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -191,6 +191,8 @@ Crash and bug fixes Improvements ^^^^^^^^^^^^ +- Support importing C++20 modules in clang-repl. + Moved checkers ^^^^^^^^^^^^^^ diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 8fc75e1cca039..1e671a7c46016 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -485,7 +485,7 @@ VALUE_LANGOPT(FuchsiaAPILevel, 32, 0, "Fuchsia API level") // on large _BitInts. BENIGN_VALUE_LANGOPT(MaxBitIntWidth, 32, 128, "Maximum width of a _BitInt") -LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process statements" +COMPATIBLE_LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process statements" "on the global scope, ignore EOF token and continue later on (thus " "avoid tearing the Lexer and etc. down). Controlled by " "-fincremental-extensions.") diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index a149d82153037..867f4c47eaece 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -3286,10 +3286,10 @@ DeclContext *ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader, if (auto *OID = dyn_cast(DC)) return OID->getDefinition(); - // We can see the TU here only if we have no Sema object. In that case, - // there's no TU scope to look in, so using the DC alone is sufficient. + // We can see the TU here only if we have no Sema object. It is possible + // we're in clang-repl so we still need to get the primary context. if (auto *TU = dyn_cast(DC)) - return TU; + return TU->getPrimaryContext(); return nullptr; } diff --git a/clang/test/Interpreter/cxx20-modules.cppm b/clang/test/Interpreter/cxx20-modules.cppm new file mode 100644 index 0000000000000..bc2b722f6b519 --- /dev/null +++ b/clang/test/Interpreter/cxx20-modules.cppm @@ -0,0 +1,31 @@ +// UNSUPPORTED: system-aix +// +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t +// +// RUN: %clang -std=c++20 %t/mod.cppm --precompile \ +// RUN: -o %t/mod.pcm +// RUN: %clang %t/mod.pcm -c -o %t/mod.o +// RUN: %clang -shared %t/mod.o -o %t/libmod.so +// +// RUN: cat %t/import.cpp | env LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH \ +// RUN: clang-repl -Xcc=-std=c++20 -Xcc=-fmodule-file=M=%t/mod.pcm \ +// RUN: | FileCheck %t/import.cpp + +//--- mod.cppm +export module M; +export const char* Hello() { + return "Hello Interpreter for Modules!"; +} + +//--- import.cpp + +%lib libmod.so + +import M; + +extern "C" int printf(const char *, ...); +printf("%s\n", Hello()); + +// CHECK: Hello Interpreter for Modules!