diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index bc97ca18a2ebd..53cd43d63ea02 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -4361,11 +4361,9 @@ bool Lexer::LexTokenInternal(Token &Result, bool TokAtPhysicalStartOfLine) { FormTokenWithChars(Result, CurPtr, tok::hash); PP->HandleDirective(Result); - if (PP->hadModuleLoaderFatalFailure()) { + if (PP->hadModuleLoaderFatalFailure()) // With a fatal failure in the module loader, we abort parsing. - assert(Result.is(tok::eof) && "Preprocessor did not set tok:eof"); return true; - } // We parsed the directive; lex a token with the new state. return false; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 723dd99ffada2..6a7bc22d3b7b3 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -277,12 +277,17 @@ static bool checkLanguageOptions(const LangOptions &LangOpts, const LangOptions &ExistingLangOpts, DiagnosticsEngine *Diags, bool AllowCompatibleDifferences = true) { -#define LANGOPT(Name, Bits, Default, Description) \ - if (ExistingLangOpts.Name != LangOpts.Name) { \ - if (Diags) \ - Diags->Report(diag::err_pch_langopt_mismatch) \ - << Description << LangOpts.Name << ExistingLangOpts.Name; \ - return true; \ +#define LANGOPT(Name, Bits, Default, Description) \ + if (ExistingLangOpts.Name != LangOpts.Name) { \ + if (Diags) { \ + if (Bits == 1) \ + Diags->Report(diag::err_pch_langopt_mismatch) \ + << Description << LangOpts.Name << ExistingLangOpts.Name; \ + else \ + Diags->Report(diag::err_pch_langopt_value_mismatch) \ + << Description; \ + } \ + return true; \ } #define VALUE_LANGOPT(Name, Bits, Default, Description) \ diff --git a/clang/test/Modules/pr62359.cppm b/clang/test/Modules/pr62359.cppm new file mode 100644 index 0000000000000..4632457e57f18 --- /dev/null +++ b/clang/test/Modules/pr62359.cppm @@ -0,0 +1,43 @@ +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Hello.cppm -o %t/Hello.pcm +// RUN: not %clang_cc1 -std=c++20 -fopenmp %t/use.cpp -fmodule-file=hello=%t/Hello.pcm -fsyntax-only \ +// RUN: 2>&1 | FileCheck %t/use.cpp +// RUN: not %clang_cc1 -std=c++20 -fopenmp %t/use2.cpp -fmodule-file=hello=%t/Hello.pcm -fsyntax-only \ +// RUN: 2>&1 | FileCheck %t/use2.cpp +// +// RUN: %clang_cc1 -std=c++20 -fopenmp -emit-module-interface %t/Hello.cppm -o %t/Hello.pcm +// RUN: %clang_cc1 -std=c++20 -fopenmp %t/use.cpp -fmodule-file=hello=%t/Hello.pcm -fsyntax-only -verify +// RUN: %clang_cc1 -std=c++20 -fopenmp %t/use2.cpp -fmodule-file=hello=%t/Hello.pcm -fsyntax-only -verify + +//--- Hello.cppm +export module hello; +export void hello() { + +} + +//--- use.cpp +// expected-no-diagnostics +import hello; +int use() { + for(int i=0;i<10;i++) + hello(); + return 0; +} + +// CHECK: OpenMP{{.*}}differs in PCH file vs. current file + +//--- use2.cpp +// expected-no-diagnostics +import hello; +int use2() { +#pragma omp parallel for + for(int i=0;i<10;i++) + hello(); + return 0; +} + +// CHECK: OpenMP{{.*}}differs in PCH file vs. current file +// CHECK: use of undeclared identifier 'pragma'