[clang] b0b0a53 - Write original source language when writing and reading AST (#209353)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 23 05:13:19 PDT 2026
Author: Ariel-Burton
Date: 2026-07-23T08:13:14-04:00
New Revision: b0b0a53e670bf15075c34514d82ce2a2c32c167a
URL: https://github.com/llvm/llvm-project/commit/b0b0a53e670bf15075c34514d82ce2a2c32c167a
DIFF: https://github.com/llvm/llvm-project/commit/b0b0a53e670bf15075c34514d82ce2a2c32c167a.diff
LOG: Write original source language when writing and reading AST (#209353)
FAIL: Clang :: Frontend/ast-main.c
FAIL: Clang :: Frontend/ast-main.cpp
were failing on z/OS; this change fixes these lit failures.
The issue here is that on z/OS the original source code language needs
to be passed through to the IR so that the backend can encode this
information in the PPA2 in the object file. That means that it needs to
be exported to the AST so that going from saved AST -> IR will carry the
language through.
Added:
clang/test/CodeGen/SystemZ/zos-check-lanuage.c
Modified:
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
Removed:
################################################################################
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 3455b729be696..35dd5fa3f2c09 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -6669,6 +6669,7 @@ bool ASTReader::ParseLanguageOptions(const RecordData &Record,
bool AllowCompatibleDifferences) {
LangOptions LangOpts;
unsigned Idx = 0;
+ LangOpts.LangStd = static_cast<LangStandard::Kind>(Record[Idx++]);
#define LANGOPT(Name, Bits, Default, Compatibility, Description) \
LangOpts.Name = Record[Idx++];
#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 9d362b1eed920..28cbd08b017aa 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1608,6 +1608,7 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, StringRef isysroot) {
// Language options.
Record.clear();
const LangOptions &LangOpts = PP.getLangOpts();
+ Record.push_back(static_cast<unsigned>(LangOpts.LangStd));
const uint64_t LanguageOptionValues[] = {
#define LANGOPT(Name, Bits, Default, Compatibility, Description) LangOpts.Name,
#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \
diff --git a/clang/test/CodeGen/SystemZ/zos-check-lanuage.c b/clang/test/CodeGen/SystemZ/zos-check-lanuage.c
new file mode 100644
index 0000000000000..a3ea41a5bd809
--- /dev/null
+++ b/clang/test/CodeGen/SystemZ/zos-check-lanuage.c
@@ -0,0 +1,27 @@
+//
+// This is based on Clang :: Frontend/ast-main.c,
+// but targeted for z/OS, and checking only that the langauge comes through.
+// We do not check that the entire IR is identical.
+// We also check C++.
+
+// The %clang_cc1 -emit-pch does the same as %clang -emit-ast.
+// The -x ast in the second invocation of each pair confirms we are reading ast.
+
+// RUN: %clang_cc1 -triple s390x-none-zos -emit-pch -o %t.ast %s
+// RUN: %clang_cc1 -triple s390x-none-zos -emit-llvm -o - -x ast - < %t.ast | FileCheck --check-prefix=CHECK-C %s
+
+// check that the langage attribute has come through
+// CHECK-C: !"zos_cu_language", !"C"}
+
+
+// RUN: %clang_cc1 -triple s390x-none-zos -emit-pch -o %t.ast -x c++ %s
+// RUN: %clang_cc1 -triple s390x-none-zos -emit-llvm -o - -x ast - < %t.ast | FileCheck --check-prefix CHECK-CPP %s
+
+// check that the langage attribute has come through
+// CHECK-CPP: !"zos_cu_language", !"C++"}
+
+
+
+int main(void) {
+ return 0;
+}
More information about the cfe-commits
mailing list