[clang] [SystemZ][z/OS] Replace characters that are not supported by ASCII to EBCDIC conversion (PR #72906)
https://github.com/abhina-sree created https://github.com/llvm/llvm-project/pull/72906 This revision fixes the following error on z/OS. `LLVM ERROR: IO failure on output stream: EDC5122I Input/output error.` >From df0f7d9eb1d665c7ecce37878b041b8b7d47cfd8 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Mon, 20 Nov 2023 14:40:40 -0500 Subject: [PATCH] Replace characters that are not supported by ASCII to EBCDIC conversion --- clang/include/clang/Basic/AttrDocs.td | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 438d846c39eaa57..79e46fb7578b3c6 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -6701,7 +6701,7 @@ def ArmSmeStreamingCompatibleDocs : Documentation { let Category = DocCatArmSmeAttributes; let Content = [{ The ``__arm_streaming_compatible`` keyword applies to prototyped function types and -specifies that the function has a “streaming compatible interface”. This +specifies that the function has a "streaming compatible interface". This means that: * the function may be entered in either non-streaming mode (PSTATE.SM=0) or @@ -7495,7 +7495,7 @@ a **coroutine return type (CRT)**. A function ``R func(P1, .., PN)`` has a coroutine return type (CRT) ``R`` if ``R`` is marked by ``[[clang::coro_return_type]]`` and ``R`` has a promise type associated to it -(i.e., std::coroutine_traits::promise_type is a valid promise type). +(i.e., std::coroutine_traits::promise_type is a valid promise type). If the return type of a function is a ``CRT`` then the function must be a coroutine. Otherwise the program is invalid. It is allowed for a non-coroutine to return a ``CRT`` ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SystemZ][z/OS] Replace unconventional characters that are not within the ASCII range (PR #72906)
https://github.com/abhina-sree edited https://github.com/llvm/llvm-project/pull/72906 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SystemZ][z/OS] Replace unconventional characters that are not within the ASCII range (PR #72906)
https://github.com/abhina-sree edited https://github.com/llvm/llvm-project/pull/72906 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SystemZ][z/OS] Replace unconventional characters that are not within the ASCII range (PR #72906)
https://github.com/abhina-sree closed https://github.com/llvm/llvm-project/pull/72906 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [SystemZ][z/OS] Complete EBCDIC I/O support (PR #75212)
https://github.com/abhina-sree created https://github.com/llvm/llvm-project/pull/75212 This patch completes the support for EBCDIC I/O support on z/OS using the autoconversion functions. >From 3244136acf891cda7344afbfd16187ba96b029a8 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Tue, 12 Dec 2023 11:12:50 -0500 Subject: [PATCH] Continue adding EBCDIC I/O support --- clang/tools/c-arcmt-test/c-arcmt-test.c | 11 +++- clang/tools/c-index-test/c-index-test.c | 9 +++ llvm/include/llvm/Support/AutoConvert.h | 25 - llvm/lib/Support/AutoConvert.cpp| 73 + llvm/lib/Support/InitLLVM.cpp | 41 +- llvm/lib/Support/Unix/Program.inc | 5 ++ llvm/lib/Support/raw_ostream.cpp| 9 +++ llvm/utils/count/CMakeLists.txt | 4 ++ llvm/utils/count/count.c| 10 +++- 9 files changed, 170 insertions(+), 17 deletions(-) diff --git a/clang/tools/c-arcmt-test/c-arcmt-test.c b/clang/tools/c-arcmt-test/c-arcmt-test.c index 3bbb2d5d6a8564..00999f188c7dce 100644 --- a/clang/tools/c-arcmt-test/c-arcmt-test.c +++ b/clang/tools/c-arcmt-test/c-arcmt-test.c @@ -1,8 +1,9 @@ /* c-arcmt-test.c */ #include "clang-c/Index.h" -#include +#include "llvm/Support/AutoConvert.h" #include +#include #include #if defined(_WIN32) #include @@ -107,6 +108,14 @@ static void flush_atexit(void) { } int main(int argc, const char **argv) { +#ifdef __MVS__ + if (enableAutoConversion(fileno(stdout)) == -1) +fprintf(stderr, "Setting conversion on stdout failed\n"); + + if (enableAutoConversion(fileno(stderr)) == -1) +fprintf(stderr, "Setting conversion on stderr failed\n"); +#endif + thread_info client_data; atexit(flush_atexit); diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 2c0c9cb8eb5e42..6fa400a0675b7a 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -8,6 +8,7 @@ #include "clang-c/Documentation.h" #include "clang-c/Index.h" #include "clang/Config/config.h" +#include "llvm/Support/AutoConvert.h" #include #include #include @@ -5150,6 +5151,14 @@ static void flush_atexit(void) { int main(int argc, const char **argv) { thread_info client_data; +#ifdef __MVS__ + if (enableAutoConversion(fileno(stdout)) == -1) +fprintf(stderr, "Setting conversion on stdout failed\n"); + + if (enableAutoConversion(fileno(stderr)) == -1) +fprintf(stderr, "Setting conversion on stderr failed\n"); +#endif + atexit(flush_atexit); #ifdef CLANG_HAVE_LIBXML diff --git a/llvm/include/llvm/Support/AutoConvert.h b/llvm/include/llvm/Support/AutoConvert.h index bcf7473feac8f7..6608dd461d7265 100644 --- a/llvm/include/llvm/Support/AutoConvert.h +++ b/llvm/include/llvm/Support/AutoConvert.h @@ -15,10 +15,27 @@ #define LLVM_SUPPORT_AUTOCONVERT_H #ifdef __MVS__ -#define CCSID_IBM_1047 1047 -#define CCSID_UTF_8 1208 +#include <_Ccsid.h> +#ifdef __cplusplus #include +#endif // __cplusplus +#define CCSID_IBM_1047 1047 +#define CCSID_UTF_8 1208 +#define CCSID_ISO8859_1 819 + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus +int enableAutoConversion(int FD); +int disableAutoConversion(int FD); +int restoreStdHandleAutoConversion(int FD); +int overrideAutoConversion(int FD, char *Filetag); +#ifdef __cplusplus +} +#endif // __cplusplus + +#ifdef __cplusplus namespace llvm { /// \brief Disable the z/OS enhanced ASCII auto-conversion for the file @@ -30,10 +47,14 @@ std::error_code disableAutoConversion(int FD); /// codepage. std::error_code enableAutoConversion(int FD); +/// Restore the z/OS enhanced ASCII auto-conversion for the std handle. +std::error_code restoreStdHandleAutoConversion(int FD); + /// \brief Set the tag information for a file descriptor. std::error_code setFileTag(int FD, int CCSID, bool Text); } // namespace llvm +#endif // __cplusplus #endif // __MVS__ diff --git a/llvm/lib/Support/AutoConvert.cpp b/llvm/lib/Support/AutoConvert.cpp index 4fb7e242c34806..8170e553ac6e10 100644 --- a/llvm/lib/Support/AutoConvert.cpp +++ b/llvm/lib/Support/AutoConvert.cpp @@ -14,21 +14,36 @@ #ifdef __MVS__ #include "llvm/Support/AutoConvert.h" +#include #include #include +#include -std::error_code llvm::disableAutoConversion(int FD) { +static int savedStdHandleAutoConversionMode[3] = {-1, -1, -1}; + +int disableAutoConversion(int FD) { static const struct f_cnvrt Convert = { - SETCVTOFF,// cvtcmd - 0,// pccsid - (short)FT_BINARY, // fccsid + SETCVTOFF, // cvtcmd + 0, // pccsid + 0, // fccsid }; - if (fcntl(FD, F_CONTROL_CVT, &Convert) == -1) -return std::error_code(errno, std::generic_category()); - return std::error_code(); + + return fcntl(FD, F_CONTROL_CVT, &Convert); } -std::error_code llvm::enableAutoConversion(int FD) { +int restoreStdHandleAutoConversion(int FD) { + assert(FD
[llvm] [clang] [SystemZ][z/OS] Complete EBCDIC I/O support (PR #75212)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/75212 >From 3244136acf891cda7344afbfd16187ba96b029a8 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Tue, 12 Dec 2023 11:12:50 -0500 Subject: [PATCH 1/2] Continue adding EBCDIC I/O support --- clang/tools/c-arcmt-test/c-arcmt-test.c | 11 +++- clang/tools/c-index-test/c-index-test.c | 9 +++ llvm/include/llvm/Support/AutoConvert.h | 25 - llvm/lib/Support/AutoConvert.cpp| 73 + llvm/lib/Support/InitLLVM.cpp | 41 +- llvm/lib/Support/Unix/Program.inc | 5 ++ llvm/lib/Support/raw_ostream.cpp| 9 +++ llvm/utils/count/CMakeLists.txt | 4 ++ llvm/utils/count/count.c| 10 +++- 9 files changed, 170 insertions(+), 17 deletions(-) diff --git a/clang/tools/c-arcmt-test/c-arcmt-test.c b/clang/tools/c-arcmt-test/c-arcmt-test.c index 3bbb2d5d6a856..00999f188c7dc 100644 --- a/clang/tools/c-arcmt-test/c-arcmt-test.c +++ b/clang/tools/c-arcmt-test/c-arcmt-test.c @@ -1,8 +1,9 @@ /* c-arcmt-test.c */ #include "clang-c/Index.h" -#include +#include "llvm/Support/AutoConvert.h" #include +#include #include #if defined(_WIN32) #include @@ -107,6 +108,14 @@ static void flush_atexit(void) { } int main(int argc, const char **argv) { +#ifdef __MVS__ + if (enableAutoConversion(fileno(stdout)) == -1) +fprintf(stderr, "Setting conversion on stdout failed\n"); + + if (enableAutoConversion(fileno(stderr)) == -1) +fprintf(stderr, "Setting conversion on stderr failed\n"); +#endif + thread_info client_data; atexit(flush_atexit); diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 2c0c9cb8eb5e4..6fa400a0675b7 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -8,6 +8,7 @@ #include "clang-c/Documentation.h" #include "clang-c/Index.h" #include "clang/Config/config.h" +#include "llvm/Support/AutoConvert.h" #include #include #include @@ -5150,6 +5151,14 @@ static void flush_atexit(void) { int main(int argc, const char **argv) { thread_info client_data; +#ifdef __MVS__ + if (enableAutoConversion(fileno(stdout)) == -1) +fprintf(stderr, "Setting conversion on stdout failed\n"); + + if (enableAutoConversion(fileno(stderr)) == -1) +fprintf(stderr, "Setting conversion on stderr failed\n"); +#endif + atexit(flush_atexit); #ifdef CLANG_HAVE_LIBXML diff --git a/llvm/include/llvm/Support/AutoConvert.h b/llvm/include/llvm/Support/AutoConvert.h index bcf7473feac8f..6608dd461d726 100644 --- a/llvm/include/llvm/Support/AutoConvert.h +++ b/llvm/include/llvm/Support/AutoConvert.h @@ -15,10 +15,27 @@ #define LLVM_SUPPORT_AUTOCONVERT_H #ifdef __MVS__ -#define CCSID_IBM_1047 1047 -#define CCSID_UTF_8 1208 +#include <_Ccsid.h> +#ifdef __cplusplus #include +#endif // __cplusplus +#define CCSID_IBM_1047 1047 +#define CCSID_UTF_8 1208 +#define CCSID_ISO8859_1 819 + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus +int enableAutoConversion(int FD); +int disableAutoConversion(int FD); +int restoreStdHandleAutoConversion(int FD); +int overrideAutoConversion(int FD, char *Filetag); +#ifdef __cplusplus +} +#endif // __cplusplus + +#ifdef __cplusplus namespace llvm { /// \brief Disable the z/OS enhanced ASCII auto-conversion for the file @@ -30,10 +47,14 @@ std::error_code disableAutoConversion(int FD); /// codepage. std::error_code enableAutoConversion(int FD); +/// Restore the z/OS enhanced ASCII auto-conversion for the std handle. +std::error_code restoreStdHandleAutoConversion(int FD); + /// \brief Set the tag information for a file descriptor. std::error_code setFileTag(int FD, int CCSID, bool Text); } // namespace llvm +#endif // __cplusplus #endif // __MVS__ diff --git a/llvm/lib/Support/AutoConvert.cpp b/llvm/lib/Support/AutoConvert.cpp index 4fb7e242c3480..8170e553ac6e1 100644 --- a/llvm/lib/Support/AutoConvert.cpp +++ b/llvm/lib/Support/AutoConvert.cpp @@ -14,21 +14,36 @@ #ifdef __MVS__ #include "llvm/Support/AutoConvert.h" +#include #include #include +#include -std::error_code llvm::disableAutoConversion(int FD) { +static int savedStdHandleAutoConversionMode[3] = {-1, -1, -1}; + +int disableAutoConversion(int FD) { static const struct f_cnvrt Convert = { - SETCVTOFF,// cvtcmd - 0,// pccsid - (short)FT_BINARY, // fccsid + SETCVTOFF, // cvtcmd + 0, // pccsid + 0, // fccsid }; - if (fcntl(FD, F_CONTROL_CVT, &Convert) == -1) -return std::error_code(errno, std::generic_category()); - return std::error_code(); + + return fcntl(FD, F_CONTROL_CVT, &Convert); } -std::error_code llvm::enableAutoConversion(int FD) { +int restoreStdHandleAutoConversion(int FD) { + assert(FD == STDIN_FILENO || FD == STDOUT_FILENO || FD == STDERR_FILENO); + if (savedStdHandleAutoConversionMode[F
[clang] [llvm] [SystemZ][z/OS] Complete EBCDIC I/O support (PR #75212)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/75212 >From 7bac35e24c3de0ed8370055bc4e4f1ea27d8f694 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Tue, 12 Dec 2023 11:12:50 -0500 Subject: [PATCH 1/2] Continue adding EBCDIC I/O support --- clang/tools/c-arcmt-test/c-arcmt-test.c | 11 +++- clang/tools/c-index-test/c-index-test.c | 9 +++ llvm/include/llvm/Support/AutoConvert.h | 25 - llvm/lib/Support/AutoConvert.cpp| 73 + llvm/lib/Support/InitLLVM.cpp | 41 +- llvm/lib/Support/Unix/Program.inc | 5 ++ llvm/lib/Support/raw_ostream.cpp| 9 +++ llvm/utils/count/CMakeLists.txt | 4 ++ llvm/utils/count/count.c| 10 +++- 9 files changed, 170 insertions(+), 17 deletions(-) diff --git a/clang/tools/c-arcmt-test/c-arcmt-test.c b/clang/tools/c-arcmt-test/c-arcmt-test.c index 3bbb2d5d6a856..00999f188c7dc 100644 --- a/clang/tools/c-arcmt-test/c-arcmt-test.c +++ b/clang/tools/c-arcmt-test/c-arcmt-test.c @@ -1,8 +1,9 @@ /* c-arcmt-test.c */ #include "clang-c/Index.h" -#include +#include "llvm/Support/AutoConvert.h" #include +#include #include #if defined(_WIN32) #include @@ -107,6 +108,14 @@ static void flush_atexit(void) { } int main(int argc, const char **argv) { +#ifdef __MVS__ + if (enableAutoConversion(fileno(stdout)) == -1) +fprintf(stderr, "Setting conversion on stdout failed\n"); + + if (enableAutoConversion(fileno(stderr)) == -1) +fprintf(stderr, "Setting conversion on stderr failed\n"); +#endif + thread_info client_data; atexit(flush_atexit); diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 2c0c9cb8eb5e4..6fa400a0675b7 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -8,6 +8,7 @@ #include "clang-c/Documentation.h" #include "clang-c/Index.h" #include "clang/Config/config.h" +#include "llvm/Support/AutoConvert.h" #include #include #include @@ -5150,6 +5151,14 @@ static void flush_atexit(void) { int main(int argc, const char **argv) { thread_info client_data; +#ifdef __MVS__ + if (enableAutoConversion(fileno(stdout)) == -1) +fprintf(stderr, "Setting conversion on stdout failed\n"); + + if (enableAutoConversion(fileno(stderr)) == -1) +fprintf(stderr, "Setting conversion on stderr failed\n"); +#endif + atexit(flush_atexit); #ifdef CLANG_HAVE_LIBXML diff --git a/llvm/include/llvm/Support/AutoConvert.h b/llvm/include/llvm/Support/AutoConvert.h index bcf7473feac8f..6608dd461d726 100644 --- a/llvm/include/llvm/Support/AutoConvert.h +++ b/llvm/include/llvm/Support/AutoConvert.h @@ -15,10 +15,27 @@ #define LLVM_SUPPORT_AUTOCONVERT_H #ifdef __MVS__ -#define CCSID_IBM_1047 1047 -#define CCSID_UTF_8 1208 +#include <_Ccsid.h> +#ifdef __cplusplus #include +#endif // __cplusplus +#define CCSID_IBM_1047 1047 +#define CCSID_UTF_8 1208 +#define CCSID_ISO8859_1 819 + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus +int enableAutoConversion(int FD); +int disableAutoConversion(int FD); +int restoreStdHandleAutoConversion(int FD); +int overrideAutoConversion(int FD, char *Filetag); +#ifdef __cplusplus +} +#endif // __cplusplus + +#ifdef __cplusplus namespace llvm { /// \brief Disable the z/OS enhanced ASCII auto-conversion for the file @@ -30,10 +47,14 @@ std::error_code disableAutoConversion(int FD); /// codepage. std::error_code enableAutoConversion(int FD); +/// Restore the z/OS enhanced ASCII auto-conversion for the std handle. +std::error_code restoreStdHandleAutoConversion(int FD); + /// \brief Set the tag information for a file descriptor. std::error_code setFileTag(int FD, int CCSID, bool Text); } // namespace llvm +#endif // __cplusplus #endif // __MVS__ diff --git a/llvm/lib/Support/AutoConvert.cpp b/llvm/lib/Support/AutoConvert.cpp index 4fb7e242c3480..8170e553ac6e1 100644 --- a/llvm/lib/Support/AutoConvert.cpp +++ b/llvm/lib/Support/AutoConvert.cpp @@ -14,21 +14,36 @@ #ifdef __MVS__ #include "llvm/Support/AutoConvert.h" +#include #include #include +#include -std::error_code llvm::disableAutoConversion(int FD) { +static int savedStdHandleAutoConversionMode[3] = {-1, -1, -1}; + +int disableAutoConversion(int FD) { static const struct f_cnvrt Convert = { - SETCVTOFF,// cvtcmd - 0,// pccsid - (short)FT_BINARY, // fccsid + SETCVTOFF, // cvtcmd + 0, // pccsid + 0, // fccsid }; - if (fcntl(FD, F_CONTROL_CVT, &Convert) == -1) -return std::error_code(errno, std::generic_category()); - return std::error_code(); + + return fcntl(FD, F_CONTROL_CVT, &Convert); } -std::error_code llvm::enableAutoConversion(int FD) { +int restoreStdHandleAutoConversion(int FD) { + assert(FD == STDIN_FILENO || FD == STDOUT_FILENO || FD == STDERR_FILENO); + if (savedStdHandleAutoConversionMode[F
[clang] [llvm] [SystemZ][z/OS] Complete EBCDIC I/O support (PR #75212)
https://github.com/abhina-sree closed https://github.com/llvm/llvm-project/pull/75212 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures (PR #75339)
https://github.com/abhina-sree created https://github.com/llvm/llvm-project/pull/75339 This patch adds strnlen to the zOSSupport.h file to fix build failures in multiple files. >From 1b234e926dc6396fe4053f3c3463ed36e5d58778 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Wed, 13 Dec 2023 08:35:52 -0500 Subject: [PATCH] fix strnlen build failure for z/OS --- clang/lib/Lex/HeaderMap.cpp | 1 + llvm/include/llvm/Support/SystemZ/zOSSupport.h | 8 llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp| 1 + llvm/lib/ObjCopy/MachO/MachOObject.cpp | 1 + llvm/lib/ObjCopy/MachO/MachOReader.cpp | 1 + llvm/lib/ObjectYAML/MachOEmitter.cpp | 1 + llvm/lib/ObjectYAML/MachOYAML.cpp| 1 + llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 1 + llvm/tools/llvm-readobj/ELFDumper.cpp| 1 + llvm/tools/llvm-readobj/ObjDumper.cpp| 1 + llvm/tools/obj2yaml/macho2yaml.cpp | 1 + 11 files changed, 18 insertions(+) diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 22a1532c2d9383..adc56dc270e5f0 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -20,6 +20,7 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SwapByteOrder.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/Debug.h" #include #include diff --git a/llvm/include/llvm/Support/SystemZ/zOSSupport.h b/llvm/include/llvm/Support/SystemZ/zOSSupport.h index ee78147cb21554..f9a61f887d5dd1 100644 --- a/llvm/include/llvm/Support/SystemZ/zOSSupport.h +++ b/llvm/include/llvm/Support/SystemZ/zOSSupport.h @@ -35,5 +35,13 @@ inline pid_t wait4(pid_t pid, int *wstatus, int options, return Result; } +// z/OS Unix System Services does not have strnlen() support, so the strnlen() +// function is implemented here. +inline std::size_t strnlen(const char *S, std::size_t MaxLen) { + const char *PtrToNullChar = + static_cast(std::memchr(S, '\0', MaxLen)); + return PtrToNullChar ? PtrToNullChar - S : MaxLen; +} + #endif #endif diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp index 067ef39d90522f..a3d4ba3a94f7ac 100644 --- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp @@ -10,6 +10,7 @@ #include "llvm/Support/Alignment.h" #include "llvm/Support/Errc.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/SystemZ/zOSSupport.h" using namespace llvm; using namespace llvm::objcopy::macho; diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.cpp b/llvm/lib/ObjCopy/MachO/MachOObject.cpp index 9a4abadc8710a4..d593d6788e112f 100644 --- a/llvm/lib/ObjCopy/MachO/MachOObject.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOObject.cpp @@ -8,6 +8,7 @@ #include "MachOObject.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include using namespace llvm; diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.cpp b/llvm/lib/ObjCopy/MachO/MachOReader.cpp index 25f8c020cde94d..4549977c12c3db 100644 --- a/llvm/lib/ObjCopy/MachO/MachOReader.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOReader.cpp @@ -11,6 +11,7 @@ #include "llvm/BinaryFormat/MachO.h" #include "llvm/Object/MachO.h" #include "llvm/Support/Errc.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include using namespace llvm; diff --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp b/llvm/lib/ObjectYAML/MachOEmitter.cpp index 6bcc2cee27edb6..c08b389daea9c3 100644 --- a/llvm/lib/ObjectYAML/MachOEmitter.cpp +++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/Error.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/LEB128.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" diff --git a/llvm/lib/ObjectYAML/MachOYAML.cpp b/llvm/lib/ObjectYAML/MachOYAML.cpp index 86342c5501c708..82b2eaecec9be9 100644 --- a/llvm/lib/ObjectYAML/MachOYAML.cpp +++ b/llvm/lib/ObjectYAML/MachOYAML.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/MachO.h" #include "llvm/Support/Format.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/Host.h" diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp index 2d396df7337f89..7bb0218ed53386 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Program.h" #include "llvm/Support/Signals.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #ifdef __linux__ #ifdef HAVE_LIBPFM diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumpe
[clang] [llvm] [SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures (PR #75339)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/75339 >From 1b234e926dc6396fe4053f3c3463ed36e5d58778 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Wed, 13 Dec 2023 08:35:52 -0500 Subject: [PATCH 1/2] fix strnlen build failure for z/OS --- clang/lib/Lex/HeaderMap.cpp | 1 + llvm/include/llvm/Support/SystemZ/zOSSupport.h | 8 llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp| 1 + llvm/lib/ObjCopy/MachO/MachOObject.cpp | 1 + llvm/lib/ObjCopy/MachO/MachOReader.cpp | 1 + llvm/lib/ObjectYAML/MachOEmitter.cpp | 1 + llvm/lib/ObjectYAML/MachOYAML.cpp| 1 + llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 1 + llvm/tools/llvm-readobj/ELFDumper.cpp| 1 + llvm/tools/llvm-readobj/ObjDumper.cpp| 1 + llvm/tools/obj2yaml/macho2yaml.cpp | 1 + 11 files changed, 18 insertions(+) diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 22a1532c2d9383..adc56dc270e5f0 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -20,6 +20,7 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SwapByteOrder.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/Debug.h" #include #include diff --git a/llvm/include/llvm/Support/SystemZ/zOSSupport.h b/llvm/include/llvm/Support/SystemZ/zOSSupport.h index ee78147cb21554..f9a61f887d5dd1 100644 --- a/llvm/include/llvm/Support/SystemZ/zOSSupport.h +++ b/llvm/include/llvm/Support/SystemZ/zOSSupport.h @@ -35,5 +35,13 @@ inline pid_t wait4(pid_t pid, int *wstatus, int options, return Result; } +// z/OS Unix System Services does not have strnlen() support, so the strnlen() +// function is implemented here. +inline std::size_t strnlen(const char *S, std::size_t MaxLen) { + const char *PtrToNullChar = + static_cast(std::memchr(S, '\0', MaxLen)); + return PtrToNullChar ? PtrToNullChar - S : MaxLen; +} + #endif #endif diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp index 067ef39d90522f..a3d4ba3a94f7ac 100644 --- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp @@ -10,6 +10,7 @@ #include "llvm/Support/Alignment.h" #include "llvm/Support/Errc.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/SystemZ/zOSSupport.h" using namespace llvm; using namespace llvm::objcopy::macho; diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.cpp b/llvm/lib/ObjCopy/MachO/MachOObject.cpp index 9a4abadc8710a4..d593d6788e112f 100644 --- a/llvm/lib/ObjCopy/MachO/MachOObject.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOObject.cpp @@ -8,6 +8,7 @@ #include "MachOObject.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include using namespace llvm; diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.cpp b/llvm/lib/ObjCopy/MachO/MachOReader.cpp index 25f8c020cde94d..4549977c12c3db 100644 --- a/llvm/lib/ObjCopy/MachO/MachOReader.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOReader.cpp @@ -11,6 +11,7 @@ #include "llvm/BinaryFormat/MachO.h" #include "llvm/Object/MachO.h" #include "llvm/Support/Errc.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include using namespace llvm; diff --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp b/llvm/lib/ObjectYAML/MachOEmitter.cpp index 6bcc2cee27edb6..c08b389daea9c3 100644 --- a/llvm/lib/ObjectYAML/MachOEmitter.cpp +++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/Error.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/LEB128.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" diff --git a/llvm/lib/ObjectYAML/MachOYAML.cpp b/llvm/lib/ObjectYAML/MachOYAML.cpp index 86342c5501c708..82b2eaecec9be9 100644 --- a/llvm/lib/ObjectYAML/MachOYAML.cpp +++ b/llvm/lib/ObjectYAML/MachOYAML.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/MachO.h" #include "llvm/Support/Format.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/Host.h" diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp index 2d396df7337f89..7bb0218ed53386 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Program.h" #include "llvm/Support/Signals.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #ifdef __linux__ #ifdef HAVE_LIBPFM diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 96564211622d26..3cf7c5a3b18955 100644 --- a/llvm/tools/llvm-readobj/ELFDumpe
[clang] [llvm] [SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures (PR #75339)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/75339 >From 71695feb1770ff939c6571de98c965d87e03ad29 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Wed, 13 Dec 2023 08:35:52 -0500 Subject: [PATCH 1/2] fix strnlen build failure for z/OS --- clang/lib/Lex/HeaderMap.cpp | 1 + llvm/include/llvm/Support/SystemZ/zOSSupport.h | 8 llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp| 1 + llvm/lib/ObjCopy/MachO/MachOObject.cpp | 1 + llvm/lib/ObjCopy/MachO/MachOReader.cpp | 1 + llvm/lib/ObjectYAML/MachOEmitter.cpp | 1 + llvm/lib/ObjectYAML/MachOYAML.cpp| 1 + llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 1 + llvm/tools/llvm-readobj/ELFDumper.cpp| 1 + llvm/tools/llvm-readobj/ObjDumper.cpp| 1 + llvm/tools/obj2yaml/macho2yaml.cpp | 1 + 11 files changed, 18 insertions(+) diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 22a1532c2d9383..adc56dc270e5f0 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -20,6 +20,7 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SwapByteOrder.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/Debug.h" #include #include diff --git a/llvm/include/llvm/Support/SystemZ/zOSSupport.h b/llvm/include/llvm/Support/SystemZ/zOSSupport.h index ee78147cb21554..f9a61f887d5dd1 100644 --- a/llvm/include/llvm/Support/SystemZ/zOSSupport.h +++ b/llvm/include/llvm/Support/SystemZ/zOSSupport.h @@ -35,5 +35,13 @@ inline pid_t wait4(pid_t pid, int *wstatus, int options, return Result; } +// z/OS Unix System Services does not have strnlen() support, so the strnlen() +// function is implemented here. +inline std::size_t strnlen(const char *S, std::size_t MaxLen) { + const char *PtrToNullChar = + static_cast(std::memchr(S, '\0', MaxLen)); + return PtrToNullChar ? PtrToNullChar - S : MaxLen; +} + #endif #endif diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp index 067ef39d90522f..a3d4ba3a94f7ac 100644 --- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp @@ -10,6 +10,7 @@ #include "llvm/Support/Alignment.h" #include "llvm/Support/Errc.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/SystemZ/zOSSupport.h" using namespace llvm; using namespace llvm::objcopy::macho; diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.cpp b/llvm/lib/ObjCopy/MachO/MachOObject.cpp index 9a4abadc8710a4..d593d6788e112f 100644 --- a/llvm/lib/ObjCopy/MachO/MachOObject.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOObject.cpp @@ -8,6 +8,7 @@ #include "MachOObject.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include using namespace llvm; diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.cpp b/llvm/lib/ObjCopy/MachO/MachOReader.cpp index 25f8c020cde94d..4549977c12c3db 100644 --- a/llvm/lib/ObjCopy/MachO/MachOReader.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOReader.cpp @@ -11,6 +11,7 @@ #include "llvm/BinaryFormat/MachO.h" #include "llvm/Object/MachO.h" #include "llvm/Support/Errc.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include using namespace llvm; diff --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp b/llvm/lib/ObjectYAML/MachOEmitter.cpp index 6bcc2cee27edb6..c08b389daea9c3 100644 --- a/llvm/lib/ObjectYAML/MachOEmitter.cpp +++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/Error.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/LEB128.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" diff --git a/llvm/lib/ObjectYAML/MachOYAML.cpp b/llvm/lib/ObjectYAML/MachOYAML.cpp index 86342c5501c708..82b2eaecec9be9 100644 --- a/llvm/lib/ObjectYAML/MachOYAML.cpp +++ b/llvm/lib/ObjectYAML/MachOYAML.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/MachO.h" #include "llvm/Support/Format.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/Host.h" diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp index 2d396df7337f89..7bb0218ed53386 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Program.h" #include "llvm/Support/Signals.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #ifdef __linux__ #ifdef HAVE_LIBPFM diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 96564211622d26..3cf7c5a3b18955 100644 --- a/llvm/tools/llvm-readobj/ELFDumpe
[clang] [llvm] [SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures (PR #75339)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/75339 >From 71695feb1770ff939c6571de98c965d87e03ad29 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Wed, 13 Dec 2023 08:35:52 -0500 Subject: [PATCH 1/3] fix strnlen build failure for z/OS --- clang/lib/Lex/HeaderMap.cpp | 1 + llvm/include/llvm/Support/SystemZ/zOSSupport.h | 8 llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp| 1 + llvm/lib/ObjCopy/MachO/MachOObject.cpp | 1 + llvm/lib/ObjCopy/MachO/MachOReader.cpp | 1 + llvm/lib/ObjectYAML/MachOEmitter.cpp | 1 + llvm/lib/ObjectYAML/MachOYAML.cpp| 1 + llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 1 + llvm/tools/llvm-readobj/ELFDumper.cpp| 1 + llvm/tools/llvm-readobj/ObjDumper.cpp| 1 + llvm/tools/obj2yaml/macho2yaml.cpp | 1 + 11 files changed, 18 insertions(+) diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 22a1532c2d9383..adc56dc270e5f0 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -20,6 +20,7 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SwapByteOrder.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/Debug.h" #include #include diff --git a/llvm/include/llvm/Support/SystemZ/zOSSupport.h b/llvm/include/llvm/Support/SystemZ/zOSSupport.h index ee78147cb21554..f9a61f887d5dd1 100644 --- a/llvm/include/llvm/Support/SystemZ/zOSSupport.h +++ b/llvm/include/llvm/Support/SystemZ/zOSSupport.h @@ -35,5 +35,13 @@ inline pid_t wait4(pid_t pid, int *wstatus, int options, return Result; } +// z/OS Unix System Services does not have strnlen() support, so the strnlen() +// function is implemented here. +inline std::size_t strnlen(const char *S, std::size_t MaxLen) { + const char *PtrToNullChar = + static_cast(std::memchr(S, '\0', MaxLen)); + return PtrToNullChar ? PtrToNullChar - S : MaxLen; +} + #endif #endif diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp index 067ef39d90522f..a3d4ba3a94f7ac 100644 --- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp @@ -10,6 +10,7 @@ #include "llvm/Support/Alignment.h" #include "llvm/Support/Errc.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/SystemZ/zOSSupport.h" using namespace llvm; using namespace llvm::objcopy::macho; diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.cpp b/llvm/lib/ObjCopy/MachO/MachOObject.cpp index 9a4abadc8710a4..d593d6788e112f 100644 --- a/llvm/lib/ObjCopy/MachO/MachOObject.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOObject.cpp @@ -8,6 +8,7 @@ #include "MachOObject.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include using namespace llvm; diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.cpp b/llvm/lib/ObjCopy/MachO/MachOReader.cpp index 25f8c020cde94d..4549977c12c3db 100644 --- a/llvm/lib/ObjCopy/MachO/MachOReader.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOReader.cpp @@ -11,6 +11,7 @@ #include "llvm/BinaryFormat/MachO.h" #include "llvm/Object/MachO.h" #include "llvm/Support/Errc.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include using namespace llvm; diff --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp b/llvm/lib/ObjectYAML/MachOEmitter.cpp index 6bcc2cee27edb6..c08b389daea9c3 100644 --- a/llvm/lib/ObjectYAML/MachOEmitter.cpp +++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/Error.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/LEB128.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" diff --git a/llvm/lib/ObjectYAML/MachOYAML.cpp b/llvm/lib/ObjectYAML/MachOYAML.cpp index 86342c5501c708..82b2eaecec9be9 100644 --- a/llvm/lib/ObjectYAML/MachOYAML.cpp +++ b/llvm/lib/ObjectYAML/MachOYAML.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/MachO.h" #include "llvm/Support/Format.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/Host.h" diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp index 2d396df7337f89..7bb0218ed53386 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Program.h" #include "llvm/Support/Signals.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #ifdef __linux__ #ifdef HAVE_LIBPFM diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 96564211622d26..3cf7c5a3b18955 100644 --- a/llvm/tools/llvm-readobj/ELFDumpe
[clang] [llvm] [SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures (PR #75339)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/75339 >From 71695feb1770ff939c6571de98c965d87e03ad29 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Wed, 13 Dec 2023 08:35:52 -0500 Subject: [PATCH 1/4] fix strnlen build failure for z/OS --- clang/lib/Lex/HeaderMap.cpp | 1 + llvm/include/llvm/Support/SystemZ/zOSSupport.h | 8 llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp| 1 + llvm/lib/ObjCopy/MachO/MachOObject.cpp | 1 + llvm/lib/ObjCopy/MachO/MachOReader.cpp | 1 + llvm/lib/ObjectYAML/MachOEmitter.cpp | 1 + llvm/lib/ObjectYAML/MachOYAML.cpp| 1 + llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 1 + llvm/tools/llvm-readobj/ELFDumper.cpp| 1 + llvm/tools/llvm-readobj/ObjDumper.cpp| 1 + llvm/tools/obj2yaml/macho2yaml.cpp | 1 + 11 files changed, 18 insertions(+) diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 22a1532c2d9383..adc56dc270e5f0 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -20,6 +20,7 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SwapByteOrder.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/Debug.h" #include #include diff --git a/llvm/include/llvm/Support/SystemZ/zOSSupport.h b/llvm/include/llvm/Support/SystemZ/zOSSupport.h index ee78147cb21554..f9a61f887d5dd1 100644 --- a/llvm/include/llvm/Support/SystemZ/zOSSupport.h +++ b/llvm/include/llvm/Support/SystemZ/zOSSupport.h @@ -35,5 +35,13 @@ inline pid_t wait4(pid_t pid, int *wstatus, int options, return Result; } +// z/OS Unix System Services does not have strnlen() support, so the strnlen() +// function is implemented here. +inline std::size_t strnlen(const char *S, std::size_t MaxLen) { + const char *PtrToNullChar = + static_cast(std::memchr(S, '\0', MaxLen)); + return PtrToNullChar ? PtrToNullChar - S : MaxLen; +} + #endif #endif diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp index 067ef39d90522f..a3d4ba3a94f7ac 100644 --- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp @@ -10,6 +10,7 @@ #include "llvm/Support/Alignment.h" #include "llvm/Support/Errc.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/SystemZ/zOSSupport.h" using namespace llvm; using namespace llvm::objcopy::macho; diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.cpp b/llvm/lib/ObjCopy/MachO/MachOObject.cpp index 9a4abadc8710a4..d593d6788e112f 100644 --- a/llvm/lib/ObjCopy/MachO/MachOObject.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOObject.cpp @@ -8,6 +8,7 @@ #include "MachOObject.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include using namespace llvm; diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.cpp b/llvm/lib/ObjCopy/MachO/MachOReader.cpp index 25f8c020cde94d..4549977c12c3db 100644 --- a/llvm/lib/ObjCopy/MachO/MachOReader.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOReader.cpp @@ -11,6 +11,7 @@ #include "llvm/BinaryFormat/MachO.h" #include "llvm/Object/MachO.h" #include "llvm/Support/Errc.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include using namespace llvm; diff --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp b/llvm/lib/ObjectYAML/MachOEmitter.cpp index 6bcc2cee27edb6..c08b389daea9c3 100644 --- a/llvm/lib/ObjectYAML/MachOEmitter.cpp +++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/Error.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/LEB128.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" diff --git a/llvm/lib/ObjectYAML/MachOYAML.cpp b/llvm/lib/ObjectYAML/MachOYAML.cpp index 86342c5501c708..82b2eaecec9be9 100644 --- a/llvm/lib/ObjectYAML/MachOYAML.cpp +++ b/llvm/lib/ObjectYAML/MachOYAML.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/MachO.h" #include "llvm/Support/Format.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/Host.h" diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp index 2d396df7337f89..7bb0218ed53386 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Program.h" #include "llvm/Support/Signals.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #ifdef __linux__ #ifdef HAVE_LIBPFM diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 96564211622d26..3cf7c5a3b18955 100644 --- a/llvm/tools/llvm-readobj/ELFDumpe
[llvm] [clang] [SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures (PR #75339)
https://github.com/abhina-sree closed https://github.com/llvm/llvm-project/pull/75339 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SystemZ][z/OS] Add guard for dl_info and dladdr (PR #75637)
https://github.com/abhina-sree created https://github.com/llvm/llvm-project/pull/75637 This patch fixes the following build error on z/OS `error: unknown type name 'Dl_info'` by adding a guard to check if we have dladdr. >From 6b102c50136b8f49b2d678b06fb8f14f866cca70 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 15 Dec 2023 13:13:24 -0500 Subject: [PATCH] check if we have dlfcn.h and dladdr --- clang/tools/libclang/CIndexer.cpp | 8 +++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index 77da2e4fa5ead0..41f8a6f2dac5fb 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -125,13 +125,19 @@ const std::string &CIndexer::getClangResourcesPath() { #elif defined(_AIX) getClangResourcesPathImplAIX(LibClangPath); #else + bool pathNotFound = false; +#if defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR) Dl_info info; std::string Path; // This silly cast below avoids a C++ warning. if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) != 0) { // We now have the CIndex directory, locate clang relative to it. LibClangPath += info.dli_fname; - } else if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { + } else +pathNotFound = true; +#endif + if (pathNotFound && + !(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { // If we can't get the path using dladdr, try to get the main executable // path. This may be needed when we're statically linking libclang with // musl libc, for example. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SystemZ][z/OS] Add guard for dl_info and dladdr (PR #75637)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/75637 >From 6b102c50136b8f49b2d678b06fb8f14f866cca70 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 15 Dec 2023 13:13:24 -0500 Subject: [PATCH 1/2] check if we have dlfcn.h and dladdr --- clang/tools/libclang/CIndexer.cpp | 8 +++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index 77da2e4fa5ead0..41f8a6f2dac5fb 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -125,13 +125,19 @@ const std::string &CIndexer::getClangResourcesPath() { #elif defined(_AIX) getClangResourcesPathImplAIX(LibClangPath); #else + bool pathNotFound = false; +#if defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR) Dl_info info; std::string Path; // This silly cast below avoids a C++ warning. if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) != 0) { // We now have the CIndex directory, locate clang relative to it. LibClangPath += info.dli_fname; - } else if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { + } else +pathNotFound = true; +#endif + if (pathNotFound && + !(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { // If we can't get the path using dladdr, try to get the main executable // path. This may be needed when we're statically linking libclang with // musl libc, for example. >From a31b44ad737709a4550d622bb12565aa5acd6b76 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 15 Dec 2023 13:30:52 -0500 Subject: [PATCH 2/2] move Path down --- clang/tools/libclang/CIndexer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index 41f8a6f2dac5fb..41c55b59e19ca7 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -128,7 +128,6 @@ const std::string &CIndexer::getClangResourcesPath() { bool pathNotFound = false; #if defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR) Dl_info info; - std::string Path; // This silly cast below avoids a C++ warning. if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) != 0) { // We now have the CIndex directory, locate clang relative to it. @@ -136,6 +135,7 @@ const std::string &CIndexer::getClangResourcesPath() { } else pathNotFound = true; #endif + std::string Path; if (pathNotFound && !(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { // If we can't get the path using dladdr, try to get the main executable ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SystemZ][z/OS] Add guard for dl_info and dladdr (PR #75637)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/75637 >From 6b102c50136b8f49b2d678b06fb8f14f866cca70 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 15 Dec 2023 13:13:24 -0500 Subject: [PATCH 1/3] check if we have dlfcn.h and dladdr --- clang/tools/libclang/CIndexer.cpp | 8 +++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index 77da2e4fa5ead0..41f8a6f2dac5fb 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -125,13 +125,19 @@ const std::string &CIndexer::getClangResourcesPath() { #elif defined(_AIX) getClangResourcesPathImplAIX(LibClangPath); #else + bool pathNotFound = false; +#if defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR) Dl_info info; std::string Path; // This silly cast below avoids a C++ warning. if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) != 0) { // We now have the CIndex directory, locate clang relative to it. LibClangPath += info.dli_fname; - } else if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { + } else +pathNotFound = true; +#endif + if (pathNotFound && + !(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { // If we can't get the path using dladdr, try to get the main executable // path. This may be needed when we're statically linking libclang with // musl libc, for example. >From a31b44ad737709a4550d622bb12565aa5acd6b76 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 15 Dec 2023 13:30:52 -0500 Subject: [PATCH 2/3] move Path down --- clang/tools/libclang/CIndexer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index 41f8a6f2dac5fb..41c55b59e19ca7 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -128,7 +128,6 @@ const std::string &CIndexer::getClangResourcesPath() { bool pathNotFound = false; #if defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR) Dl_info info; - std::string Path; // This silly cast below avoids a C++ warning. if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) != 0) { // We now have the CIndex directory, locate clang relative to it. @@ -136,6 +135,7 @@ const std::string &CIndexer::getClangResourcesPath() { } else pathNotFound = true; #endif + std::string Path; if (pathNotFound && !(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { // If we can't get the path using dladdr, try to get the main executable >From 4954b4cc8be660c1682dec976677b922d530f1ac Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 15 Dec 2023 13:44:56 -0500 Subject: [PATCH 3/3] add include --- clang/tools/libclang/CIndexer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index 41c55b59e19ca7..30b799b1d69475 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -17,6 +17,7 @@ #include "clang/Driver/Driver.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" +#include "llvm/Config/config.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MD5.h" #include "llvm/Support/Path.h" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SystemZ][z/OS] Add guard for dl_info and dladdr (PR #75637)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/75637 >From fa5de46426920ed3592fcd0b0dd5b810b62d22c1 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 15 Dec 2023 13:13:24 -0500 Subject: [PATCH] check if we have dlfcn.h and dladdr --- clang/tools/libclang/CIndexer.cpp | 11 +-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index 77da2e4fa5ead0..6f6a3cdccf2528 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -17,6 +17,7 @@ #include "clang/Driver/Driver.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" +#include "llvm/Config/config.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MD5.h" #include "llvm/Support/Path.h" @@ -125,13 +126,19 @@ const std::string &CIndexer::getClangResourcesPath() { #elif defined(_AIX) getClangResourcesPathImplAIX(LibClangPath); #else + bool pathFound = false; +#if defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR) Dl_info info; - std::string Path; // This silly cast below avoids a C++ warning. if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) != 0) { // We now have the CIndex directory, locate clang relative to it. LibClangPath += info.dli_fname; - } else if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { +pathFound = true; + } +#endif + std::string Path; + if (!pathFound && + !(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { // If we can't get the path using dladdr, try to get the main executable // path. This may be needed when we're statically linking libclang with // musl libc, for example. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SystemZ][z/OS] Add guard for dl_info and dladdr (PR #75637)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/75637 >From 61385bf2fa5c7369812eed6d40d04599f2383ee0 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 15 Dec 2023 14:39:23 -0500 Subject: [PATCH] check if we have dlfcn.h and dladdr --- clang/tools/libclang/CIndexer.cpp | 28 ++-- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index 77da2e4fa5ead0..fafdd215bf705d 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -17,6 +17,7 @@ #include "clang/Driver/Driver.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" +#include "llvm/Config/config.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MD5.h" #include "llvm/Support/Path.h" @@ -125,21 +126,28 @@ const std::string &CIndexer::getClangResourcesPath() { #elif defined(_AIX) getClangResourcesPathImplAIX(LibClangPath); #else + bool pathFound = false; +#if defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR) Dl_info info; - std::string Path; // This silly cast below avoids a C++ warning. if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) != 0) { // We now have the CIndex directory, locate clang relative to it. LibClangPath += info.dli_fname; - } else if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { -// If we can't get the path using dladdr, try to get the main executable -// path. This may be needed when we're statically linking libclang with -// musl libc, for example. -LibClangPath += Path; - } else { -// It's rather unlikely we end up here. But it could happen, so report an -// error instead of crashing. -llvm::report_fatal_error("could not locate Clang resource path"); +pathFound = true; + } +#endif + std::string Path; + if (!pathFound) { +if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { + // If we can't get the path using dladdr, try to get the main executable + // path. This may be needed when we're statically linking libclang with + // musl libc, for example. + LibClangPath += Path; +} else { + // It's rather unlikely we end up here. But it could happen, so report an + // error instead of crashing. + llvm::report_fatal_error("could not locate Clang resource path"); +} } #endif ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SystemZ][z/OS] Add guard for dl_info and dladdr (PR #75637)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/75637 >From 61385bf2fa5c7369812eed6d40d04599f2383ee0 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 15 Dec 2023 14:39:23 -0500 Subject: [PATCH 1/2] check if we have dlfcn.h and dladdr --- clang/tools/libclang/CIndexer.cpp | 28 ++-- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index 77da2e4fa5ead0..fafdd215bf705d 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -17,6 +17,7 @@ #include "clang/Driver/Driver.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" +#include "llvm/Config/config.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MD5.h" #include "llvm/Support/Path.h" @@ -125,21 +126,28 @@ const std::string &CIndexer::getClangResourcesPath() { #elif defined(_AIX) getClangResourcesPathImplAIX(LibClangPath); #else + bool pathFound = false; +#if defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR) Dl_info info; - std::string Path; // This silly cast below avoids a C++ warning. if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) != 0) { // We now have the CIndex directory, locate clang relative to it. LibClangPath += info.dli_fname; - } else if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { -// If we can't get the path using dladdr, try to get the main executable -// path. This may be needed when we're statically linking libclang with -// musl libc, for example. -LibClangPath += Path; - } else { -// It's rather unlikely we end up here. But it could happen, so report an -// error instead of crashing. -llvm::report_fatal_error("could not locate Clang resource path"); +pathFound = true; + } +#endif + std::string Path; + if (!pathFound) { +if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { + // If we can't get the path using dladdr, try to get the main executable + // path. This may be needed when we're statically linking libclang with + // musl libc, for example. + LibClangPath += Path; +} else { + // It's rather unlikely we end up here. But it could happen, so report an + // error instead of crashing. + llvm::report_fatal_error("could not locate Clang resource path"); +} } #endif >From 5e16c335f627768edd408cbce16c8fa16c8efc5b Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Mon, 18 Dec 2023 09:54:28 -0500 Subject: [PATCH 2/2] address nit --- clang/tools/libclang/CIndexer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index fafdd215bf705d..0623ae69fe01ed 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -126,18 +126,18 @@ const std::string &CIndexer::getClangResourcesPath() { #elif defined(_AIX) getClangResourcesPathImplAIX(LibClangPath); #else - bool pathFound = false; + bool PathFound = false; #if defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR) Dl_info info; // This silly cast below avoids a C++ warning. if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) != 0) { // We now have the CIndex directory, locate clang relative to it. LibClangPath += info.dli_fname; -pathFound = true; +PathFound = true; } #endif std::string Path; - if (!pathFound) { + if (!PathFound) { if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) { // If we can't get the path using dladdr, try to get the main executable // path. This may be needed when we're statically linking libclang with ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SystemZ][z/OS] Add guard for dl_info and dladdr (PR #75637)
@@ -125,21 +126,28 @@ const std::string &CIndexer::getClangResourcesPath() { #elif defined(_AIX) getClangResourcesPathImplAIX(LibClangPath); #else + bool pathFound = false; abhina-sree wrote: thanks, done! https://github.com/llvm/llvm-project/pull/75637 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SystemZ][z/OS] Add guard for dl_info and dladdr (PR #75637)
https://github.com/abhina-sree closed https://github.com/llvm/llvm-project/pull/75637 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Use llvm-config.h in CIndexer.cpp instead of private header (PR #75928)
https://github.com/abhina-sree created https://github.com/llvm/llvm-project/pull/75928 Use llvm-config.h in CIndexer.cpp instead of private header >From 86e8d6f52da0b48b9e99b66a7440755507c9f9ed Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Tue, 19 Dec 2023 08:12:48 -0500 Subject: [PATCH] use llvm-config.h instead of private header --- clang/tools/libclang/CIndexer.cpp| 2 +- llvm/include/llvm/Config/llvm-config.h.cmake | 6 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index 0623ae69fe01ed..430147b2aa77af 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -17,7 +17,7 @@ #include "clang/Driver/Driver.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" -#include "llvm/Config/config.h" +#include "llvm/Config/llvm-config.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MD5.h" #include "llvm/Support/Path.h" diff --git a/llvm/include/llvm/Config/llvm-config.h.cmake b/llvm/include/llvm/Config/llvm-config.h.cmake index 6605ea60df99e1..483c5adc99ca80 100644 --- a/llvm/include/llvm/Config/llvm-config.h.cmake +++ b/llvm/include/llvm/Config/llvm-config.h.cmake @@ -198,4 +198,10 @@ /* Define if plugins enabled */ #cmakedefine LLVM_ENABLE_PLUGINS +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H} + +/* Define if dladdr() is available on this platform. */ +#cmakedefine HAVE_DLADDR ${HAVE_DLADDR} + #endif ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Use llvm-config.h in CIndexer.cpp instead of private header (PR #75928)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/75928 >From 86e8d6f52da0b48b9e99b66a7440755507c9f9ed Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Tue, 19 Dec 2023 08:12:48 -0500 Subject: [PATCH 1/2] use llvm-config.h instead of private header --- clang/tools/libclang/CIndexer.cpp| 2 +- llvm/include/llvm/Config/llvm-config.h.cmake | 6 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index 0623ae69fe01ed..430147b2aa77af 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -17,7 +17,7 @@ #include "clang/Driver/Driver.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" -#include "llvm/Config/config.h" +#include "llvm/Config/llvm-config.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MD5.h" #include "llvm/Support/Path.h" diff --git a/llvm/include/llvm/Config/llvm-config.h.cmake b/llvm/include/llvm/Config/llvm-config.h.cmake index 6605ea60df99e1..483c5adc99ca80 100644 --- a/llvm/include/llvm/Config/llvm-config.h.cmake +++ b/llvm/include/llvm/Config/llvm-config.h.cmake @@ -198,4 +198,10 @@ /* Define if plugins enabled */ #cmakedefine LLVM_ENABLE_PLUGINS +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H} + +/* Define if dladdr() is available on this platform. */ +#cmakedefine HAVE_DLADDR ${HAVE_DLADDR} + #endif >From caab4a4d1c7bd037e2bf58652d8cacca56455e51 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Tue, 19 Dec 2023 08:20:09 -0500 Subject: [PATCH 2/2] remove from old location --- llvm/include/llvm/Config/config.h.cmake | 6 -- 1 file changed, 6 deletions(-) diff --git a/llvm/include/llvm/Config/config.h.cmake b/llvm/include/llvm/Config/config.h.cmake index fc1f9bf342f8d5..d464263c190a73 100644 --- a/llvm/include/llvm/Config/config.h.cmake +++ b/llvm/include/llvm/Config/config.h.cmake @@ -50,15 +50,9 @@ don't. */ #cmakedefine01 HAVE_DECL_STRERROR_S -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H} - /* Define if dlopen() is available on this platform. */ #cmakedefine HAVE_DLOPEN ${HAVE_DLOPEN} -/* Define if dladdr() is available on this platform. */ -#cmakedefine HAVE_DLADDR ${HAVE_DLADDR} - /* Define to 1 if we can register EH frames on this platform. */ #cmakedefine HAVE_REGISTER_FRAME ${HAVE_REGISTER_FRAME} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SystemZ][z/OS] Add guard for dl_info and dladdr (PR #75637)
@@ -17,6 +17,7 @@ #include "clang/Driver/Driver.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" +#include "llvm/Config/config.h" abhina-sree wrote: Thanks, I created a fix for it here https://github.com/llvm/llvm-project/pull/75928 https://github.com/llvm/llvm-project/pull/75637 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] Use llvm-config.h in CIndexer.cpp instead of private header (PR #75928)
https://github.com/abhina-sree closed https://github.com/llvm/llvm-project/pull/75928 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SystemZ][z/OS] Add support for recognizing z/OS personality function in Clang (PR #76073)
https://github.com/abhina-sree approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/76073 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [CMake] Move check for dlfcn.h and dladdr to clang (PR #76163)
https://github.com/abhina-sree created https://github.com/llvm/llvm-project/pull/76163 This patch checks for the presence of dlfcn.h and dladdr in clang to be used in clang/tools/libclang/CIndexer.cpp >From 37a33f4f2458ed32cd0c53834044410c9a90c07f Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Thu, 21 Dec 2023 08:28:30 -0500 Subject: [PATCH 1/2] Revert "Use llvm-config.h in CIndexer.cpp instead of private header (#75928)" This reverts commit e86a02ce89c33f3fa4061fb4c67c3b05c69a72ab. --- clang/tools/libclang/CIndexer.cpp| 2 +- llvm/include/llvm/Config/config.h.cmake | 6 ++ llvm/include/llvm/Config/llvm-config.h.cmake | 6 -- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index 430147b2aa77af..0623ae69fe01ed 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -17,7 +17,7 @@ #include "clang/Driver/Driver.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" -#include "llvm/Config/llvm-config.h" +#include "llvm/Config/config.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MD5.h" #include "llvm/Support/Path.h" diff --git a/llvm/include/llvm/Config/config.h.cmake b/llvm/include/llvm/Config/config.h.cmake index d464263c190a73..fc1f9bf342f8d5 100644 --- a/llvm/include/llvm/Config/config.h.cmake +++ b/llvm/include/llvm/Config/config.h.cmake @@ -50,9 +50,15 @@ don't. */ #cmakedefine01 HAVE_DECL_STRERROR_S +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H} + /* Define if dlopen() is available on this platform. */ #cmakedefine HAVE_DLOPEN ${HAVE_DLOPEN} +/* Define if dladdr() is available on this platform. */ +#cmakedefine HAVE_DLADDR ${HAVE_DLADDR} + /* Define to 1 if we can register EH frames on this platform. */ #cmakedefine HAVE_REGISTER_FRAME ${HAVE_REGISTER_FRAME} diff --git a/llvm/include/llvm/Config/llvm-config.h.cmake b/llvm/include/llvm/Config/llvm-config.h.cmake index 483c5adc99ca80..6605ea60df99e1 100644 --- a/llvm/include/llvm/Config/llvm-config.h.cmake +++ b/llvm/include/llvm/Config/llvm-config.h.cmake @@ -198,10 +198,4 @@ /* Define if plugins enabled */ #cmakedefine LLVM_ENABLE_PLUGINS -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H} - -/* Define if dladdr() is available on this platform. */ -#cmakedefine HAVE_DLADDR ${HAVE_DLADDR} - #endif >From c21d00f03428154d7c1f2bee9a47bfd031ed476a Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Thu, 21 Dec 2023 10:43:05 -0500 Subject: [PATCH 2/2] detect dlfcn.h and dladdr in clang --- clang/CMakeLists.txt | 17 + clang/include/clang/Config/config.h.cmake | 6 ++ clang/tools/libclang/CIndexer.cpp | 4 ++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt index 2ca6db02e58791..9f814478c45503 100644 --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -167,6 +167,23 @@ endif() include(CheckIncludeFile) check_include_file(sys/resource.h CLANG_HAVE_RLIMITS) +# This check requires _GNU_SOURCE on linux +check_include_file(dlfcn.h CLANG_HAVE_DLFCN_H) +if( CLANG_HAVE_DLFCN_H ) + include(CheckLibraryExists) + include(CheckSymbolExists) + check_library_exists(dl dlopen "" HAVE_LIBDL) + if( HAVE_LIBDL ) +list(APPEND CMAKE_REQUIRED_LIBRARIES dl) + endif() + list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) + check_symbol_exists(dladdr dlfcn.h CLANG_HAVE_DLADDR) + list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) + if( HAVE_LIBDL ) +list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl) + endif() +endif() + set(CLANG_RESOURCE_DIR "" CACHE STRING "Relative directory from the Clang binary to its resource files.") diff --git a/clang/include/clang/Config/config.h.cmake b/clang/include/clang/Config/config.h.cmake index a54a26cd32ffe4..4015ac8040861c 100644 --- a/clang/include/clang/Config/config.h.cmake +++ b/clang/include/clang/Config/config.h.cmake @@ -57,6 +57,12 @@ /* Define if we have sys/resource.h (rlimits) */ #cmakedefine CLANG_HAVE_RLIMITS ${CLANG_HAVE_RLIMITS} +/* Define if we have dlfcn.h */ +#cmakedefine CLANG_HAVE_DLFCN_H ${CLANG_HAVE_DLFCN_H} + +/* Define if dladdr() is available on this platform. */ +#cmakedefine CLANG_HAVE_DLADDR ${CLANG_HAVE_DLADDR} + /* Linker version detected at compile time. */ #cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}" diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index 0623ae69fe01ed..12d9d418dea51d 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -14,10 +14,10 @@ #include "CXString.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/Version.h" +#include "clang/Config/config.h" #include "clang/Driver/Driver.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallSt
[clang] [SystemZ][z/OS] Add guard for dl_info and dladdr (PR #75637)
abhina-sree wrote: > Could we take other ways? I think they don't affect external API. > > 1. Detect stuff in `clang/Config/config.h` > 2. Migrate the special logic to `llvm/Support`. Thanks, I've created a patch here that detects the header in clang's config.h. Please let me know if this is a good approach https://github.com/llvm/llvm-project/pull/75637 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [CMake] Move check for dlfcn.h and dladdr to clang (PR #76163)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/76163 >From 4c1b811b3807e888445e8114c0755811deb17c3f Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Thu, 21 Dec 2023 08:28:30 -0500 Subject: [PATCH 1/2] Revert "Use llvm-config.h in CIndexer.cpp instead of private header (#75928)" This reverts commit e86a02ce89c33f3fa4061fb4c67c3b05c69a72ab. --- clang/tools/libclang/CIndexer.cpp| 2 +- llvm/include/llvm/Config/config.h.cmake | 6 ++ llvm/include/llvm/Config/llvm-config.h.cmake | 6 -- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index 430147b2aa77af..0623ae69fe01ed 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -17,7 +17,7 @@ #include "clang/Driver/Driver.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" -#include "llvm/Config/llvm-config.h" +#include "llvm/Config/config.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MD5.h" #include "llvm/Support/Path.h" diff --git a/llvm/include/llvm/Config/config.h.cmake b/llvm/include/llvm/Config/config.h.cmake index d464263c190a73..fc1f9bf342f8d5 100644 --- a/llvm/include/llvm/Config/config.h.cmake +++ b/llvm/include/llvm/Config/config.h.cmake @@ -50,9 +50,15 @@ don't. */ #cmakedefine01 HAVE_DECL_STRERROR_S +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H} + /* Define if dlopen() is available on this platform. */ #cmakedefine HAVE_DLOPEN ${HAVE_DLOPEN} +/* Define if dladdr() is available on this platform. */ +#cmakedefine HAVE_DLADDR ${HAVE_DLADDR} + /* Define to 1 if we can register EH frames on this platform. */ #cmakedefine HAVE_REGISTER_FRAME ${HAVE_REGISTER_FRAME} diff --git a/llvm/include/llvm/Config/llvm-config.h.cmake b/llvm/include/llvm/Config/llvm-config.h.cmake index 483c5adc99ca80..6605ea60df99e1 100644 --- a/llvm/include/llvm/Config/llvm-config.h.cmake +++ b/llvm/include/llvm/Config/llvm-config.h.cmake @@ -198,10 +198,4 @@ /* Define if plugins enabled */ #cmakedefine LLVM_ENABLE_PLUGINS -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H} - -/* Define if dladdr() is available on this platform. */ -#cmakedefine HAVE_DLADDR ${HAVE_DLADDR} - #endif >From 861872a3ceb58257aa69bad30af1b1d588b0bee7 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Thu, 21 Dec 2023 10:43:05 -0500 Subject: [PATCH 2/2] detect dlfcn.h and dladdr in clang --- clang/CMakeLists.txt | 17 + clang/include/clang/Config/config.h.cmake | 6 ++ clang/tools/libclang/CIndexer.cpp | 4 ++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt index 2ca6db02e58791..9f814478c45503 100644 --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -167,6 +167,23 @@ endif() include(CheckIncludeFile) check_include_file(sys/resource.h CLANG_HAVE_RLIMITS) +# This check requires _GNU_SOURCE on linux +check_include_file(dlfcn.h CLANG_HAVE_DLFCN_H) +if( CLANG_HAVE_DLFCN_H ) + include(CheckLibraryExists) + include(CheckSymbolExists) + check_library_exists(dl dlopen "" HAVE_LIBDL) + if( HAVE_LIBDL ) +list(APPEND CMAKE_REQUIRED_LIBRARIES dl) + endif() + list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) + check_symbol_exists(dladdr dlfcn.h CLANG_HAVE_DLADDR) + list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) + if( HAVE_LIBDL ) +list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl) + endif() +endif() + set(CLANG_RESOURCE_DIR "" CACHE STRING "Relative directory from the Clang binary to its resource files.") diff --git a/clang/include/clang/Config/config.h.cmake b/clang/include/clang/Config/config.h.cmake index a54a26cd32ffe4..4015ac8040861c 100644 --- a/clang/include/clang/Config/config.h.cmake +++ b/clang/include/clang/Config/config.h.cmake @@ -57,6 +57,12 @@ /* Define if we have sys/resource.h (rlimits) */ #cmakedefine CLANG_HAVE_RLIMITS ${CLANG_HAVE_RLIMITS} +/* Define if we have dlfcn.h */ +#cmakedefine CLANG_HAVE_DLFCN_H ${CLANG_HAVE_DLFCN_H} + +/* Define if dladdr() is available on this platform. */ +#cmakedefine CLANG_HAVE_DLADDR ${CLANG_HAVE_DLADDR} + /* Linker version detected at compile time. */ #cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}" diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index 0623ae69fe01ed..12d9d418dea51d 100644 --- a/clang/tools/libclang/CIndexer.cpp +++ b/clang/tools/libclang/CIndexer.cpp @@ -14,10 +14,10 @@ #include "CXString.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/Version.h" +#include "clang/Config/config.h" #include "clang/Driver/Driver.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" -#include "llvm/Config/config.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MD5.h" #incl
[llvm] [clang] [CMake] Move check for dlfcn.h and dladdr to clang (PR #76163)
abhina-sree wrote: CI failure is unrelated to my patch, so I will go ahead and commit https://github.com/llvm/llvm-project/pull/76163 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [CMake] Move check for dlfcn.h and dladdr to clang (PR #76163)
https://github.com/abhina-sree closed https://github.com/llvm/llvm-project/pull/76163 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [CMake] Move check for dlfcn.h and dladdr to clang (PR #76163)
abhina-sree wrote: > Can you say what motivated this? Change looks fine, but it looks like it > fixes a problem someone reported somewhere but this doesn't say what the > problem is. Yes, there was a concern about exposing prefix-less macros in the llvm-config.h here https://github.com/llvm/llvm-project/pull/75928#issuecomment-1865290992 https://github.com/llvm/llvm-project/pull/76163 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [NFC][SystemZ][z/OS] Rename autoconversion-related functions to be less generic (PR #107399)
https://github.com/abhina-sree created https://github.com/llvm/llvm-project/pull/107399 This patch renames the functions in AutoConvert.h/cpp to have a less generic name because they are z/OS specific. >From 34e044dc5677b345570a202dd0542440a7eee8d9 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Thu, 5 Sep 2024 09:16:11 -0400 Subject: [PATCH] [NFC][SystemZ][z/OS] Rename autoconversion-related functions to be less generic --- clang/tools/c-arcmt-test/c-arcmt-test.c | 4 ++-- clang/tools/c-index-test/c-index-test.c | 4 ++-- llvm/include/llvm/Support/AutoConvert.h | 14 +++--- llvm/lib/Support/AutoConvert.cpp| 20 ++-- llvm/lib/Support/InitLLVM.cpp | 10 +- llvm/lib/Support/MemoryBuffer.cpp | 2 +- llvm/lib/Support/Unix/Path.inc | 8 llvm/lib/Support/Unix/Program.inc | 2 +- llvm/lib/Support/raw_ostream.cpp| 4 ++-- llvm/utils/count/count.c| 4 ++-- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/clang/tools/c-arcmt-test/c-arcmt-test.c b/clang/tools/c-arcmt-test/c-arcmt-test.c index 00999f188c7dce..4d0c418714b950 100644 --- a/clang/tools/c-arcmt-test/c-arcmt-test.c +++ b/clang/tools/c-arcmt-test/c-arcmt-test.c @@ -109,10 +109,10 @@ static void flush_atexit(void) { int main(int argc, const char **argv) { #ifdef __MVS__ - if (enableAutoConversion(fileno(stdout)) == -1) + if (enablezOSAutoConversion(fileno(stdout)) == -1) fprintf(stderr, "Setting conversion on stdout failed\n"); - if (enableAutoConversion(fileno(stderr)) == -1) + if (enablezOSAutoConversion(fileno(stderr)) == -1) fprintf(stderr, "Setting conversion on stderr failed\n"); #endif diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index f472a67f3bc5b7..b48f44950ab754 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -5180,10 +5180,10 @@ int main(int argc, const char **argv) { thread_info client_data; #ifdef __MVS__ - if (enableAutoConversion(fileno(stdout)) == -1) + if (enablezOSAutoConversion(fileno(stdout)) == -1) fprintf(stderr, "Setting conversion on stdout failed\n"); - if (enableAutoConversion(fileno(stderr)) == -1) + if (enablezOSAutoConversion(fileno(stderr)) == -1) fprintf(stderr, "Setting conversion on stderr failed\n"); #endif diff --git a/llvm/include/llvm/Support/AutoConvert.h b/llvm/include/llvm/Support/AutoConvert.h index f4fe80b22a8760..6f45c4683f7775 100644 --- a/llvm/include/llvm/Support/AutoConvert.h +++ b/llvm/include/llvm/Support/AutoConvert.h @@ -27,9 +27,9 @@ #ifdef __cplusplus extern "C" { #endif // __cplusplus -int enableAutoConversion(int FD); -int disableAutoConversion(int FD); -int restoreStdHandleAutoConversion(int FD); +int enablezOSAutoConversion(int FD); +int disablezOSAutoConversion(int FD); +int restorezOSStdHandleAutoConversion(int FD); #ifdef __cplusplus } #endif // __cplusplus @@ -39,18 +39,18 @@ namespace llvm { /// \brief Disable the z/OS enhanced ASCII auto-conversion for the file /// descriptor. -std::error_code disableAutoConversion(int FD); +std::error_code disablezOSAutoConversion(int FD); /// \brief Query the z/OS enhanced ASCII auto-conversion status of a file /// descriptor and force the conversion if the file is not tagged with a /// codepage. -std::error_code enableAutoConversion(int FD); +std::error_code enablezOSAutoConversion(int FD); /// Restore the z/OS enhanced ASCII auto-conversion for the std handle. -std::error_code restoreStdHandleAutoConversion(int FD); +std::error_code restorezOSStdHandleAutoConversion(int FD); /// \brief Set the tag information for a file descriptor. -std::error_code setFileTag(int FD, int CCSID, bool Text); +std::error_code setzOSFileTag(int FD, int CCSID, bool Text); } // namespace llvm #endif // __cplusplus diff --git a/llvm/lib/Support/AutoConvert.cpp b/llvm/lib/Support/AutoConvert.cpp index c509284ee916ef..66570735f8fc88 100644 --- a/llvm/lib/Support/AutoConvert.cpp +++ b/llvm/lib/Support/AutoConvert.cpp @@ -22,7 +22,7 @@ static int savedStdHandleAutoConversionMode[3] = {-1, -1, -1}; -int disableAutoConversion(int FD) { +int disablezOSAutoConversion(int FD) { static const struct f_cnvrt Convert = { SETCVTOFF, // cvtcmd 0, // pccsid @@ -32,7 +32,7 @@ int disableAutoConversion(int FD) { return fcntl(FD, F_CONTROL_CVT, &Convert); } -int restoreStdHandleAutoConversion(int FD) { +int restorezOSStdHandleAutoConversion(int FD) { assert(FD == STDIN_FILENO || FD == STDOUT_FILENO || FD == STDERR_FILENO); if (savedStdHandleAutoConversionMode[FD] == -1) return 0; @@ -44,7 +44,7 @@ int restoreStdHandleAutoConversion(int FD) { return (fcntl(FD, F_CONTROL_CVT, &Cvt)); } -int enableAutoConversion(int FD) { +int enablezOSAutoConversion(int FD) { struct f_cnvrt Query = { QUERYCVT, // cvtcmd 0,
[clang] [llvm] [SystemZ][z/OS] Update autoconversion functions to improve support for UTF-8 (PR #98652)
@@ -52,6 +53,12 @@ std::error_code restoreStdHandleAutoConversion(int FD); /// \brief Set the tag information for a file descriptor. std::error_code setFileTag(int FD, int CCSID, bool Text); +// Get the the tag ccsid for a file name or a file descriptor. +ErrorOr<__ccsid_t> getFileTag(const char *FileName, const int FD = -1); + +// Query the file tag to determine if it needs conversion to UTF-8 codepage. +ErrorOr needConversion(const char *FileName, const int FD = -1); abhina-sree wrote: I've renamed the other functions in this file here https://github.com/llvm/llvm-project/pull/107399 https://github.com/llvm/llvm-project/pull/98652 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [NFC][SystemZ][z/OS] Rename autoconversion-related functions to be less generic (PR #107399)
https://github.com/abhina-sree closed https://github.com/llvm/llvm-project/pull/107399 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] Update autoconversion functions to improve support for UTF-8 (PR #98652)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/98652 >From e7be53314994b9a051ba2ff99dfd029937ebcc07 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 12 Jul 2024 11:17:24 -0400 Subject: [PATCH 1/3] update autoconversion functionality to fix error: source file is not valid UTF-8 --- clang/include/clang/Basic/FileEntry.h | 9 ++ clang/lib/Basic/SourceManager.cpp | 25 llvm/include/llvm/Support/AutoConvert.h | 7 + llvm/lib/Support/AutoConvert.cpp| 40 - llvm/lib/Support/MemoryBuffer.cpp | 16 -- llvm/lib/Support/VirtualFileSystem.cpp | 2 +- 6 files changed, 95 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 68d4bf60930037..1fe6c3617582ce 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -70,6 +70,11 @@ class FileEntryRef { const FileEntry &getFileEntry() const { return *getBaseMapEntry().second->V.get(); } +#ifdef __MVS__ + FileEntry &getFileEntry() { +return *getBaseMapEntry().second->V.get(); + } +#endif DirectoryEntryRef getDir() const { return ME->second->Dir; } inline off_t getSize() const; @@ -323,6 +328,10 @@ class FileEntry { StringRef tryGetRealPathName() const { return RealPathName; } off_t getSize() const { return Size; } +#ifdef __MVS__ + // Size may increase due to potential z/OS EBCDIC -> UTF-8 conversion. + void setSize(off_t NewSize) { Size = NewSize; } +#endif unsigned getUID() const { return UID; } const llvm::sys::fs::UniqueID &getUniqueID() const { return UniqueID; } time_t getModificationTime() const { return ModTime; } diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index d6ec26af80aadd..44b56a352dfc4e 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -24,6 +24,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/Allocator.h" +#include "llvm/Support/AutoConvert.h" #include "llvm/Support/Capacity.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Endian.h" @@ -166,8 +167,15 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM, // Unless this is a named pipe (in which case we can handle a mismatch), // check that the file's size is the same as in the file entry (which may // have come from a stat cache). +#ifndef __MVS__ if (!ContentsEntry->isNamedPipe() && Buffer->getBufferSize() != (size_t)ContentsEntry->getSize()) { +#else + // The buffer will always be larger than the file size on z/OS in the presence + // of characters outside the base character set. + if (!ContentsEntry->isNamedPipe() && + Buffer->getBufferSize() < (size_t)ContentsEntry->getSize()) { +#endif if (Diag.isDiagnosticInFlight()) Diag.SetDelayedDiagnostic(diag::err_file_modified, ContentsEntry->getName()); @@ -617,6 +625,23 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, StringRef Filename, return FileID::get(LoadedID); } unsigned FileSize = File.getSize(); +#ifdef __MVS__ + llvm::ErrorOr NeedConversion = + llvm::needConversion(Filename.str().c_str()); + if (NeedConversion && *NeedConversion) { +// Buffer size may increase due to potential z/OS EBCDIC to UTF-8 +// conversion. +if (std::optional Buffer = +File.getBufferOrNone(Diag, getFileManager())) { + unsigned BufSize = Buffer->getBufferSize(); + if (BufSize > FileSize) { +if (File.ContentsEntry.has_value()) + File.ContentsEntry->getFileEntry().setSize(BufSize); +FileSize = BufSize; + } +} + } +#endif if (!(NextLocalOffset + FileSize + 1 > NextLocalOffset && NextLocalOffset + FileSize + 1 <= CurrentLoadedOffset)) { Diag.Report(IncludePos, diag::err_sloc_space_too_large); diff --git a/llvm/include/llvm/Support/AutoConvert.h b/llvm/include/llvm/Support/AutoConvert.h index 6f45c4683f7775..a9b3e0357589bc 100644 --- a/llvm/include/llvm/Support/AutoConvert.h +++ b/llvm/include/llvm/Support/AutoConvert.h @@ -17,6 +17,7 @@ #ifdef __MVS__ #include <_Ccsid.h> #ifdef __cplusplus +#include "llvm/Support/ErrorOr.h" #include #endif // __cplusplus @@ -52,6 +53,12 @@ std::error_code restorezOSStdHandleAutoConversion(int FD); /// \brief Set the tag information for a file descriptor. std::error_code setzOSFileTag(int FD, int CCSID, bool Text); +// Get the the tag ccsid for a file name or a file descriptor. +ErrorOr<__ccsid_t> getFileTag(const char *FileName, const int FD = -1); + +// Query the file tag to determine if it needs conversion to UTF-8 codepage. +ErrorOr needConversion(const char *FileName, const int FD = -1); + } // namespace llvm #endif // __cplusplus diff --git a/llvm/lib/Support/AutoConvert.cpp b/llvm/lib/S
[clang] [clang-tools-extra] [llvm] [SystemZ][z/OS] Propagate IsText parameter to open text files as text (PR #107906)
https://github.com/abhina-sree created https://github.com/llvm/llvm-project/pull/107906 This patch adds an IsText parameter to the following functions openFileForRead, getBufferForFile, getBufferForFileImpl and determines whether a file is text by querying the file tag on z/OS. The default is set to OF_Text instead of OF_None, this change in value does not affect any other platforms other than z/OS. >From 27a06380d79fa8da5ed402cb8565877c634e4be6 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Mon, 9 Sep 2024 15:32:09 -0400 Subject: [PATCH] Propagate IsText parameter to openFileForRead function --- clang-tools-extra/clangd/FS.cpp | 4 +-- clang-tools-extra/clangd/Preamble.cpp | 4 +-- .../clangd/support/ThreadsafeFS.cpp | 2 +- .../clangd/unittests/ClangdTests.cpp | 2 +- clang/include/clang/Basic/FileManager.h | 8 +++--- .../DependencyScanningFilesystem.h| 2 +- clang/lib/Basic/FileManager.cpp | 12 - clang/lib/Basic/SourceManager.cpp | 14 -- clang/lib/Serialization/ASTReader.cpp | 3 ++- .../DependencyScanningFilesystem.cpp | 5 ++-- clang/unittests/Driver/DistroTest.cpp | 4 +-- clang/unittests/Driver/ToolChainTest.cpp | 2 +- clang/unittests/Frontend/PCHPreambleTest.cpp | 6 ++--- .../DependencyScannerTest.cpp | 4 +-- llvm/include/llvm/Support/AutoConvert.h | 6 + llvm/include/llvm/Support/VirtualFileSystem.h | 16 +++- llvm/lib/Support/AutoConvert.cpp | 26 +++ llvm/lib/Support/FileCollector.cpp| 4 +-- llvm/lib/Support/VirtualFileSystem.cpp| 21 --- .../Support/VirtualFileSystemTest.cpp | 6 ++--- 20 files changed, 100 insertions(+), 51 deletions(-) diff --git a/clang-tools-extra/clangd/FS.cpp b/clang-tools-extra/clangd/FS.cpp index 5729b9341d9d4b..bd3c6440c24b0f 100644 --- a/clang-tools-extra/clangd/FS.cpp +++ b/clang-tools-extra/clangd/FS.cpp @@ -64,8 +64,8 @@ PreambleFileStatusCache::getProducingFS( : ProxyFileSystem(std::move(FS)), StatCache(StatCache) {} llvm::ErrorOr> -openFileForRead(const llvm::Twine &Path) override { - auto File = getUnderlyingFS().openFileForRead(Path); +openFileForRead(const llvm::Twine &Path, bool IsText = true) override { + auto File = getUnderlyingFS().openFileForRead(Path, IsText); if (!File || !*File) return File; // Eagerly stat opened file, as the followup `status` call on the file diff --git a/clang-tools-extra/clangd/Preamble.cpp b/clang-tools-extra/clangd/Preamble.cpp index dd13b1a9e5613d..e970d01f3729f3 100644 --- a/clang-tools-extra/clangd/Preamble.cpp +++ b/clang-tools-extra/clangd/Preamble.cpp @@ -479,9 +479,9 @@ class TimerFS : public llvm::vfs::ProxyFileSystem { : ProxyFileSystem(std::move(FS)) {} llvm::ErrorOr> - openFileForRead(const llvm::Twine &Path) override { + openFileForRead(const llvm::Twine &Path, bool IsText = true) override { WallTimerRegion T(Timer); -auto FileOr = getUnderlyingFS().openFileForRead(Path); +auto FileOr = getUnderlyingFS().openFileForRead(Path, IsText); if (!FileOr) return FileOr; return std::make_unique(Timer, std::move(FileOr.get())); diff --git a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp index 7398e4258527ba..bc0b984e577cb8 100644 --- a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp +++ b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp @@ -29,7 +29,7 @@ class VolatileFileSystem : public llvm::vfs::ProxyFileSystem { : ProxyFileSystem(std::move(FS)) {} llvm::ErrorOr> - openFileForRead(const llvm::Twine &InPath) override { + openFileForRead(const llvm::Twine &InPath, bool IsText = true) override { llvm::SmallString<128> Path; InPath.toVector(Path); diff --git a/clang-tools-extra/clangd/unittests/ClangdTests.cpp b/clang-tools-extra/clangd/unittests/ClangdTests.cpp index 643b8e9f12d751..e86385c2072b34 100644 --- a/clang-tools-extra/clangd/unittests/ClangdTests.cpp +++ b/clang-tools-extra/clangd/unittests/ClangdTests.cpp @@ -1010,7 +1010,7 @@ TEST(ClangdTests, PreambleVFSStatCache) { : ProxyFileSystem(std::move(FS)), CountStats(CountStats) {} llvm::ErrorOr> -openFileForRead(const Twine &Path) override { +openFileForRead(const Twine &Path, bool IsText = true) override { ++CountStats[llvm::sys::path::filename(Path.str())]; return ProxyFileSystem::openFileForRead(Path); } diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index 527bbef24793ee..67a69fb79ccefe 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -286,21 +286,21 @@ class FileManager : public RefCountedBase { /// MemoryBuffer if successful, othe
[clang] [llvm] [SystemZ][z/OS] Update autoconversion functions to improve support for UTF-8 (PR #98652)
@@ -326,7 +326,7 @@ ErrorOr> RealFileSystem::openFileForRead(const Twine &Name) { SmallString<256> RealName, Storage; Expected FDOrErr = sys::fs::openNativeFileForRead( - adjustPath(Name, Storage), sys::fs::OF_None, &RealName); + adjustPath(Name, Storage), sys::fs::OF_Text, &RealName); abhina-sree wrote: I have created a separate PR https://github.com/llvm/llvm-project/pull/107906 to propagate an IsText flag to these functions which on z/OS will query the file tag to determine whether to open the file as text or binary. https://github.com/llvm/llvm-project/pull/98652 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] The real option name and not the alias used is displayed in msgs when using a config file (PR #107613)
https://github.com/abhina-sree approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/107613 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [SystemZ][z/OS] Propagate IsText parameter to open text files as text (PR #107906)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/107906 >From 758745c955471b0ad65cd3a33381f753e2b63797 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Mon, 9 Sep 2024 15:32:09 -0400 Subject: [PATCH] Propagate IsText parameter to openFileForRead function --- clang-tools-extra/clangd/FS.cpp | 4 +-- clang-tools-extra/clangd/Preamble.cpp | 4 +-- .../clangd/support/ThreadsafeFS.cpp | 2 +- .../clangd/unittests/ClangdTests.cpp | 2 +- clang/include/clang/Basic/FileManager.h | 8 +++--- .../DependencyScanningFilesystem.h| 2 +- clang/lib/Basic/FileManager.cpp | 12 - clang/lib/Basic/SourceManager.cpp | 14 -- clang/lib/Serialization/ASTReader.cpp | 3 ++- .../DependencyScanningFilesystem.cpp | 5 ++-- clang/unittests/Driver/DistroTest.cpp | 4 +-- clang/unittests/Driver/ToolChainTest.cpp | 2 +- clang/unittests/Frontend/PCHPreambleTest.cpp | 6 ++--- .../DependencyScannerTest.cpp | 4 +-- llvm/include/llvm/Support/AutoConvert.h | 6 + llvm/include/llvm/Support/VirtualFileSystem.h | 21 --- llvm/lib/Support/AutoConvert.cpp | 26 +++ llvm/lib/Support/FileCollector.cpp| 4 +-- llvm/lib/Support/VirtualFileSystem.cpp| 21 --- .../Support/VirtualFileSystemTest.cpp | 6 ++--- 20 files changed, 103 insertions(+), 53 deletions(-) diff --git a/clang-tools-extra/clangd/FS.cpp b/clang-tools-extra/clangd/FS.cpp index 5729b9341d9d4b..bd3c6440c24b0f 100644 --- a/clang-tools-extra/clangd/FS.cpp +++ b/clang-tools-extra/clangd/FS.cpp @@ -64,8 +64,8 @@ PreambleFileStatusCache::getProducingFS( : ProxyFileSystem(std::move(FS)), StatCache(StatCache) {} llvm::ErrorOr> -openFileForRead(const llvm::Twine &Path) override { - auto File = getUnderlyingFS().openFileForRead(Path); +openFileForRead(const llvm::Twine &Path, bool IsText = true) override { + auto File = getUnderlyingFS().openFileForRead(Path, IsText); if (!File || !*File) return File; // Eagerly stat opened file, as the followup `status` call on the file diff --git a/clang-tools-extra/clangd/Preamble.cpp b/clang-tools-extra/clangd/Preamble.cpp index dd13b1a9e5613d..e970d01f3729f3 100644 --- a/clang-tools-extra/clangd/Preamble.cpp +++ b/clang-tools-extra/clangd/Preamble.cpp @@ -479,9 +479,9 @@ class TimerFS : public llvm::vfs::ProxyFileSystem { : ProxyFileSystem(std::move(FS)) {} llvm::ErrorOr> - openFileForRead(const llvm::Twine &Path) override { + openFileForRead(const llvm::Twine &Path, bool IsText = true) override { WallTimerRegion T(Timer); -auto FileOr = getUnderlyingFS().openFileForRead(Path); +auto FileOr = getUnderlyingFS().openFileForRead(Path, IsText); if (!FileOr) return FileOr; return std::make_unique(Timer, std::move(FileOr.get())); diff --git a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp index 7398e4258527ba..bc0b984e577cb8 100644 --- a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp +++ b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp @@ -29,7 +29,7 @@ class VolatileFileSystem : public llvm::vfs::ProxyFileSystem { : ProxyFileSystem(std::move(FS)) {} llvm::ErrorOr> - openFileForRead(const llvm::Twine &InPath) override { + openFileForRead(const llvm::Twine &InPath, bool IsText = true) override { llvm::SmallString<128> Path; InPath.toVector(Path); diff --git a/clang-tools-extra/clangd/unittests/ClangdTests.cpp b/clang-tools-extra/clangd/unittests/ClangdTests.cpp index 643b8e9f12d751..e86385c2072b34 100644 --- a/clang-tools-extra/clangd/unittests/ClangdTests.cpp +++ b/clang-tools-extra/clangd/unittests/ClangdTests.cpp @@ -1010,7 +1010,7 @@ TEST(ClangdTests, PreambleVFSStatCache) { : ProxyFileSystem(std::move(FS)), CountStats(CountStats) {} llvm::ErrorOr> -openFileForRead(const Twine &Path) override { +openFileForRead(const Twine &Path, bool IsText = true) override { ++CountStats[llvm::sys::path::filename(Path.str())]; return ProxyFileSystem::openFileForRead(Path); } diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index 527bbef24793ee..67a69fb79ccefe 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -286,21 +286,21 @@ class FileManager : public RefCountedBase { /// MemoryBuffer if successful, otherwise returning null. llvm::ErrorOr> getBufferForFile(FileEntryRef Entry, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt); llvm::ErrorOr>
[clang] [clang-tools-extra] [lldb] [llvm] [SystemZ][z/OS] Propagate IsText parameter to open text files as text (PR #107906)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/107906 >From 758745c955471b0ad65cd3a33381f753e2b63797 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Mon, 9 Sep 2024 15:32:09 -0400 Subject: [PATCH 1/2] Propagate IsText parameter to openFileForRead function --- clang-tools-extra/clangd/FS.cpp | 4 +-- clang-tools-extra/clangd/Preamble.cpp | 4 +-- .../clangd/support/ThreadsafeFS.cpp | 2 +- .../clangd/unittests/ClangdTests.cpp | 2 +- clang/include/clang/Basic/FileManager.h | 8 +++--- .../DependencyScanningFilesystem.h| 2 +- clang/lib/Basic/FileManager.cpp | 12 - clang/lib/Basic/SourceManager.cpp | 14 -- clang/lib/Serialization/ASTReader.cpp | 3 ++- .../DependencyScanningFilesystem.cpp | 5 ++-- clang/unittests/Driver/DistroTest.cpp | 4 +-- clang/unittests/Driver/ToolChainTest.cpp | 2 +- clang/unittests/Frontend/PCHPreambleTest.cpp | 6 ++--- .../DependencyScannerTest.cpp | 4 +-- llvm/include/llvm/Support/AutoConvert.h | 6 + llvm/include/llvm/Support/VirtualFileSystem.h | 21 --- llvm/lib/Support/AutoConvert.cpp | 26 +++ llvm/lib/Support/FileCollector.cpp| 4 +-- llvm/lib/Support/VirtualFileSystem.cpp| 21 --- .../Support/VirtualFileSystemTest.cpp | 6 ++--- 20 files changed, 103 insertions(+), 53 deletions(-) diff --git a/clang-tools-extra/clangd/FS.cpp b/clang-tools-extra/clangd/FS.cpp index 5729b9341d9d4b..bd3c6440c24b0f 100644 --- a/clang-tools-extra/clangd/FS.cpp +++ b/clang-tools-extra/clangd/FS.cpp @@ -64,8 +64,8 @@ PreambleFileStatusCache::getProducingFS( : ProxyFileSystem(std::move(FS)), StatCache(StatCache) {} llvm::ErrorOr> -openFileForRead(const llvm::Twine &Path) override { - auto File = getUnderlyingFS().openFileForRead(Path); +openFileForRead(const llvm::Twine &Path, bool IsText = true) override { + auto File = getUnderlyingFS().openFileForRead(Path, IsText); if (!File || !*File) return File; // Eagerly stat opened file, as the followup `status` call on the file diff --git a/clang-tools-extra/clangd/Preamble.cpp b/clang-tools-extra/clangd/Preamble.cpp index dd13b1a9e5613d..e970d01f3729f3 100644 --- a/clang-tools-extra/clangd/Preamble.cpp +++ b/clang-tools-extra/clangd/Preamble.cpp @@ -479,9 +479,9 @@ class TimerFS : public llvm::vfs::ProxyFileSystem { : ProxyFileSystem(std::move(FS)) {} llvm::ErrorOr> - openFileForRead(const llvm::Twine &Path) override { + openFileForRead(const llvm::Twine &Path, bool IsText = true) override { WallTimerRegion T(Timer); -auto FileOr = getUnderlyingFS().openFileForRead(Path); +auto FileOr = getUnderlyingFS().openFileForRead(Path, IsText); if (!FileOr) return FileOr; return std::make_unique(Timer, std::move(FileOr.get())); diff --git a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp index 7398e4258527ba..bc0b984e577cb8 100644 --- a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp +++ b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp @@ -29,7 +29,7 @@ class VolatileFileSystem : public llvm::vfs::ProxyFileSystem { : ProxyFileSystem(std::move(FS)) {} llvm::ErrorOr> - openFileForRead(const llvm::Twine &InPath) override { + openFileForRead(const llvm::Twine &InPath, bool IsText = true) override { llvm::SmallString<128> Path; InPath.toVector(Path); diff --git a/clang-tools-extra/clangd/unittests/ClangdTests.cpp b/clang-tools-extra/clangd/unittests/ClangdTests.cpp index 643b8e9f12d751..e86385c2072b34 100644 --- a/clang-tools-extra/clangd/unittests/ClangdTests.cpp +++ b/clang-tools-extra/clangd/unittests/ClangdTests.cpp @@ -1010,7 +1010,7 @@ TEST(ClangdTests, PreambleVFSStatCache) { : ProxyFileSystem(std::move(FS)), CountStats(CountStats) {} llvm::ErrorOr> -openFileForRead(const Twine &Path) override { +openFileForRead(const Twine &Path, bool IsText = true) override { ++CountStats[llvm::sys::path::filename(Path.str())]; return ProxyFileSystem::openFileForRead(Path); } diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index 527bbef24793ee..67a69fb79ccefe 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -286,21 +286,21 @@ class FileManager : public RefCountedBase { /// MemoryBuffer if successful, otherwise returning null. llvm::ErrorOr> getBufferForFile(FileEntryRef Entry, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt); llvm::Error
[clang] [llvm] [SystemZ][z/OS] Update autoconversion functions to improve support for UTF-8 (PR #98652)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/98652 >From e7be53314994b9a051ba2ff99dfd029937ebcc07 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 12 Jul 2024 11:17:24 -0400 Subject: [PATCH 1/3] update autoconversion functionality to fix error: source file is not valid UTF-8 --- clang/include/clang/Basic/FileEntry.h | 9 ++ clang/lib/Basic/SourceManager.cpp | 25 llvm/include/llvm/Support/AutoConvert.h | 7 + llvm/lib/Support/AutoConvert.cpp| 40 - llvm/lib/Support/MemoryBuffer.cpp | 16 -- llvm/lib/Support/VirtualFileSystem.cpp | 2 +- 6 files changed, 95 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 68d4bf60930037..1fe6c3617582ce 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -70,6 +70,11 @@ class FileEntryRef { const FileEntry &getFileEntry() const { return *getBaseMapEntry().second->V.get(); } +#ifdef __MVS__ + FileEntry &getFileEntry() { +return *getBaseMapEntry().second->V.get(); + } +#endif DirectoryEntryRef getDir() const { return ME->second->Dir; } inline off_t getSize() const; @@ -323,6 +328,10 @@ class FileEntry { StringRef tryGetRealPathName() const { return RealPathName; } off_t getSize() const { return Size; } +#ifdef __MVS__ + // Size may increase due to potential z/OS EBCDIC -> UTF-8 conversion. + void setSize(off_t NewSize) { Size = NewSize; } +#endif unsigned getUID() const { return UID; } const llvm::sys::fs::UniqueID &getUniqueID() const { return UniqueID; } time_t getModificationTime() const { return ModTime; } diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index d6ec26af80aadd..44b56a352dfc4e 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -24,6 +24,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/Allocator.h" +#include "llvm/Support/AutoConvert.h" #include "llvm/Support/Capacity.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Endian.h" @@ -166,8 +167,15 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM, // Unless this is a named pipe (in which case we can handle a mismatch), // check that the file's size is the same as in the file entry (which may // have come from a stat cache). +#ifndef __MVS__ if (!ContentsEntry->isNamedPipe() && Buffer->getBufferSize() != (size_t)ContentsEntry->getSize()) { +#else + // The buffer will always be larger than the file size on z/OS in the presence + // of characters outside the base character set. + if (!ContentsEntry->isNamedPipe() && + Buffer->getBufferSize() < (size_t)ContentsEntry->getSize()) { +#endif if (Diag.isDiagnosticInFlight()) Diag.SetDelayedDiagnostic(diag::err_file_modified, ContentsEntry->getName()); @@ -617,6 +625,23 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, StringRef Filename, return FileID::get(LoadedID); } unsigned FileSize = File.getSize(); +#ifdef __MVS__ + llvm::ErrorOr NeedConversion = + llvm::needConversion(Filename.str().c_str()); + if (NeedConversion && *NeedConversion) { +// Buffer size may increase due to potential z/OS EBCDIC to UTF-8 +// conversion. +if (std::optional Buffer = +File.getBufferOrNone(Diag, getFileManager())) { + unsigned BufSize = Buffer->getBufferSize(); + if (BufSize > FileSize) { +if (File.ContentsEntry.has_value()) + File.ContentsEntry->getFileEntry().setSize(BufSize); +FileSize = BufSize; + } +} + } +#endif if (!(NextLocalOffset + FileSize + 1 > NextLocalOffset && NextLocalOffset + FileSize + 1 <= CurrentLoadedOffset)) { Diag.Report(IncludePos, diag::err_sloc_space_too_large); diff --git a/llvm/include/llvm/Support/AutoConvert.h b/llvm/include/llvm/Support/AutoConvert.h index 6f45c4683f7775..a9b3e0357589bc 100644 --- a/llvm/include/llvm/Support/AutoConvert.h +++ b/llvm/include/llvm/Support/AutoConvert.h @@ -17,6 +17,7 @@ #ifdef __MVS__ #include <_Ccsid.h> #ifdef __cplusplus +#include "llvm/Support/ErrorOr.h" #include #endif // __cplusplus @@ -52,6 +53,12 @@ std::error_code restorezOSStdHandleAutoConversion(int FD); /// \brief Set the tag information for a file descriptor. std::error_code setzOSFileTag(int FD, int CCSID, bool Text); +// Get the the tag ccsid for a file name or a file descriptor. +ErrorOr<__ccsid_t> getFileTag(const char *FileName, const int FD = -1); + +// Query the file tag to determine if it needs conversion to UTF-8 codepage. +ErrorOr needConversion(const char *FileName, const int FD = -1); + } // namespace llvm #endif // __cplusplus diff --git a/llvm/lib/Support/AutoConvert.cpp b/llvm/lib/S
[clang] [zOS] Turn CLANG_INTERPRETER_PLATFORM_CANNOT_CREATE_LLJIT on for zOS (PR #87797)
https://github.com/abhina-sree approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/87797 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [zOS] Turn CLANG_INTERPRETER_PLATFORM_CANNOT_CREATE_LLJIT on for zOS (PR #87797)
https://github.com/abhina-sree closed https://github.com/llvm/llvm-project/pull/87797 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #101024)
https://github.com/abhina-sree created https://github.com/llvm/llvm-project/pull/101024 The XPLINK calling convention is specified in the Language Environment Vendor Interface, chapter 22, (https://www.ibm.com/support/knowledgecenter/SSLTBW_2.4.0/com.ibm.zos.v2r4.cee/cee.htm) and in Redbook XPLink: OS/390 Extra Performance Linkage (http://www.redbooks.ibm.com/abstracts/sg245991.html?Open) >From e89f2e619fb7b4e5c942d7236768e79bb189aee8 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Mon, 29 Jul 2024 10:49:08 -0400 Subject: [PATCH] [SystemZ][z/OS] Implement z/OS XPLINK ABI --- clang/lib/CodeGen/CodeGenModule.cpp | 2 + clang/lib/CodeGen/TargetInfo.h| 4 + clang/lib/CodeGen/Targets/SystemZ.cpp | 291 ++ clang/test/CodeGen/zos-abi.c | 247 ++ clang/test/CodeGen/zos-abi.cpp| 24 +++ 5 files changed, 568 insertions(+) create mode 100644 clang/test/CodeGen/zos-abi.c create mode 100644 clang/test/CodeGen/zos-abi.cpp diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 63ed5b4dd0c31..49ff482168eb9 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -244,6 +244,8 @@ createTargetCodeGenInfo(CodeGenModule &CGM) { case llvm::Triple::systemz: { bool SoftFloat = CodeGenOpts.FloatABI == "soft"; bool HasVector = !SoftFloat && Target.getABI() == "vector"; +if (Triple.getOS() == llvm::Triple::ZOS) + return createSystemZ_ZOS_TargetCodeGenInfo(CGM, HasVector, SoftFloat); return createSystemZTargetCodeGenInfo(CGM, HasVector, SoftFloat); } diff --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h index 8f17c053f4783..eaa303963e8ee 100644 --- a/clang/lib/CodeGen/TargetInfo.h +++ b/clang/lib/CodeGen/TargetInfo.h @@ -541,6 +541,10 @@ std::unique_ptr createSystemZTargetCodeGenInfo(CodeGenModule &CGM, bool HasVector, bool SoftFloatABI); +std::unique_ptr +createSystemZ_ZOS_TargetCodeGenInfo(CodeGenModule &CGM, bool HasVector, +bool SoftFloatABI); + std::unique_ptr createTCETargetCodeGenInfo(CodeGenModule &CGM); diff --git a/clang/lib/CodeGen/Targets/SystemZ.cpp b/clang/lib/CodeGen/Targets/SystemZ.cpp index 4d61f51379346..9cc3df7350eea 100644 --- a/clang/lib/CodeGen/Targets/SystemZ.cpp +++ b/clang/lib/CodeGen/Targets/SystemZ.cpp @@ -10,6 +10,7 @@ #include "TargetInfo.h" #include "clang/Basic/Builtins.h" #include "llvm/IR/IntrinsicsS390.h" +#include using namespace clang; using namespace clang::CodeGen; @@ -532,9 +533,299 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const Type *Ty, return false; } + +//===--===// +// z/OS XPLINK ABI Implementation +//===--===// + +namespace { + +class ZOSXPLinkABIInfo : public ABIInfo { + const unsigned GPRBits = 64; + bool HasVector; + +public: + ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {} + + bool isPromotableIntegerType(QualType Ty) const; + bool isVectorArgumentType(QualType Ty) const; + bool isFPArgumentType(QualType Ty) const; + std::optional getFPTypeOfComplexLikeType(QualType Ty) const; + + ABIArgInfo classifyReturnType(QualType RetTy) const; + ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg) const; + + void computeInfo(CGFunctionInfo &FI) const override { +if (!getCXXABI().classifyReturnType(FI)) + FI.getReturnInfo() = classifyReturnType(FI.getReturnType()); + +unsigned NumRequiredArgs = FI.getNumRequiredArgs(); +unsigned ArgNo = 0; + +for (auto &I : FI.arguments()) { + bool IsNamedArg = ArgNo < NumRequiredArgs; + I.info = classifyArgumentType(I.type, IsNamedArg); + ++ArgNo; +} + } + + RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, + AggValueSlot Slot) const override; +}; + +class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo { +public: + ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector) + : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) { +SwiftInfo = +std::make_unique(CGT, /*SwiftErrorInRegister=*/false); + } +}; + +} // namespace + +// Return true if the ABI requires Ty to be passed sign- or zero- +// extended to 64 bits. +bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const { + // Treat an enum type as its underlying type. + if (const EnumType *EnumTy = Ty->getAs()) +Ty = EnumTy->getDecl()->getIntegerType(); + + // Promotable integer types are required to be promoted by the ABI. + if (getContext().isPromotableIntegerType(Ty)) +return true; + + if (const auto *EIT = Ty->getAs()) +if (EIT->getNumBits() < 64) + return true; + + // In addition to the usual promotable integer types, we also need to + // extend al
[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #91384)
abhina-sree wrote: I will be taking over this change from Fanbo here https://github.com/llvm/llvm-project/pull/101024. I will address the comments here on that PR. https://github.com/llvm/llvm-project/pull/91384 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #101024)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/101024 >From 9d30fcbac4ecdc592663d20a2b18b6b4e2ee873e Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Mon, 29 Jul 2024 10:49:08 -0400 Subject: [PATCH] [SystemZ][z/OS] Implement z/OS XPLINK ABI --- clang/lib/CodeGen/CodeGenModule.cpp | 2 + clang/lib/CodeGen/TargetInfo.h| 4 + clang/lib/CodeGen/Targets/SystemZ.cpp | 290 ++ clang/test/CodeGen/zos-abi.c | 247 ++ clang/test/CodeGen/zos-abi.cpp| 24 +++ 5 files changed, 567 insertions(+) create mode 100644 clang/test/CodeGen/zos-abi.c create mode 100644 clang/test/CodeGen/zos-abi.cpp diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 63ed5b4dd0c31..49ff482168eb9 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -244,6 +244,8 @@ createTargetCodeGenInfo(CodeGenModule &CGM) { case llvm::Triple::systemz: { bool SoftFloat = CodeGenOpts.FloatABI == "soft"; bool HasVector = !SoftFloat && Target.getABI() == "vector"; +if (Triple.getOS() == llvm::Triple::ZOS) + return createSystemZ_ZOS_TargetCodeGenInfo(CGM, HasVector, SoftFloat); return createSystemZTargetCodeGenInfo(CGM, HasVector, SoftFloat); } diff --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h index 8f17c053f4783..eaa303963e8ee 100644 --- a/clang/lib/CodeGen/TargetInfo.h +++ b/clang/lib/CodeGen/TargetInfo.h @@ -541,6 +541,10 @@ std::unique_ptr createSystemZTargetCodeGenInfo(CodeGenModule &CGM, bool HasVector, bool SoftFloatABI); +std::unique_ptr +createSystemZ_ZOS_TargetCodeGenInfo(CodeGenModule &CGM, bool HasVector, +bool SoftFloatABI); + std::unique_ptr createTCETargetCodeGenInfo(CodeGenModule &CGM); diff --git a/clang/lib/CodeGen/Targets/SystemZ.cpp b/clang/lib/CodeGen/Targets/SystemZ.cpp index 4d61f51379346..5bb91232a3285 100644 --- a/clang/lib/CodeGen/Targets/SystemZ.cpp +++ b/clang/lib/CodeGen/Targets/SystemZ.cpp @@ -10,6 +10,7 @@ #include "TargetInfo.h" #include "clang/Basic/Builtins.h" #include "llvm/IR/IntrinsicsS390.h" +#include using namespace clang; using namespace clang::CodeGen; @@ -532,9 +533,298 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const Type *Ty, return false; } +//===--===// +// z/OS XPLINK ABI Implementation +//===--===// + +namespace { + +class ZOSXPLinkABIInfo : public ABIInfo { + const unsigned GPRBits = 64; + bool HasVector; + +public: + ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {} + + bool isPromotableIntegerType(QualType Ty) const; + bool isVectorArgumentType(QualType Ty) const; + bool isFPArgumentType(QualType Ty) const; + std::optional getFPTypeOfComplexLikeType(QualType Ty) const; + + ABIArgInfo classifyReturnType(QualType RetTy) const; + ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg) const; + + void computeInfo(CGFunctionInfo &FI) const override { +if (!getCXXABI().classifyReturnType(FI)) + FI.getReturnInfo() = classifyReturnType(FI.getReturnType()); + +unsigned NumRequiredArgs = FI.getNumRequiredArgs(); +unsigned ArgNo = 0; + +for (auto &I : FI.arguments()) { + bool IsNamedArg = ArgNo < NumRequiredArgs; + I.info = classifyArgumentType(I.type, IsNamedArg); + ++ArgNo; +} + } + + RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, + AggValueSlot Slot) const override; +}; + +class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo { +public: + ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector) + : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) { +SwiftInfo = +std::make_unique(CGT, /*SwiftErrorInRegister=*/false); + } +}; + +} // namespace + +// Return true if the ABI requires Ty to be passed sign- or zero- +// extended to 64 bits. +bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const { + // Treat an enum type as its underlying type. + if (const EnumType *EnumTy = Ty->getAs()) +Ty = EnumTy->getDecl()->getIntegerType(); + + // Promotable integer types are required to be promoted by the ABI. + if (getContext().isPromotableIntegerType(Ty)) +return true; + + if (const auto *EIT = Ty->getAs()) +if (EIT->getNumBits() < 64) + return true; + + // In addition to the usual promotable integer types, we also need to + // extend all 32-bit types, since the ABI requires promotion to 64 bits. + if (const BuiltinType *BT = Ty->getAs()) +switch (BT->getKind()) { +case BuiltinType::Int: +case BuiltinType::UInt: + return true; +default: + break; +} + + return false; +} + +bool ZOSXPLinkABIInfo::isVectorArgumen
[clang] [z/OS] add support for z/OS system headers to clang std header wrappers (PR #89995)
https://github.com/abhina-sree approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/89995 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [z/OS] treat text files as text files so auto-conversion is done (PR #90128)
https://github.com/abhina-sree approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/90128 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] Update autoconversion functions to improve support for UTF-8 (PR #98652)
https://github.com/abhina-sree created https://github.com/llvm/llvm-project/pull/98652 This fixes the following error when reading source and header files: error: source file is not valid UTF-8 >From 539af083a22ccdeaa64ccc85d6ffc08b48c9432f Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 12 Jul 2024 11:17:24 -0400 Subject: [PATCH] update autoconversion functionality to fix error: source file is not valid UTF-8 --- clang/include/clang/Basic/FileEntry.h | 9 ++ clang/lib/Basic/SourceManager.cpp | 25 llvm/include/llvm/Support/AutoConvert.h | 7 + llvm/lib/Support/AutoConvert.cpp| 40 - llvm/lib/Support/MemoryBuffer.cpp | 16 -- llvm/lib/Support/VirtualFileSystem.cpp | 2 +- 6 files changed, 95 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 68d4bf6093003..56684cc8828d9 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -70,6 +70,11 @@ class FileEntryRef { const FileEntry &getFileEntry() const { return *getBaseMapEntry().second->V.get(); } +#ifdef __MVS__ + FileEntry &getFileEntry() { + return *getBaseMapEntry().second->V.get(); + } +#endif DirectoryEntryRef getDir() const { return ME->second->Dir; } inline off_t getSize() const; @@ -323,6 +328,10 @@ class FileEntry { StringRef tryGetRealPathName() const { return RealPathName; } off_t getSize() const { return Size; } +#ifdef __MVS__ + // Size may increase due to potential z/OS EBCDIC -> UTF-8 conversion. + void setSize(off_t NewSize) { Size = NewSize; } +#endif unsigned getUID() const { return UID; } const llvm::sys::fs::UniqueID &getUniqueID() const { return UniqueID; } time_t getModificationTime() const { return ModTime; } diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 533a9fe88a215..1b6197e4fa054 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -24,6 +24,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/Allocator.h" +#include "llvm/Support/AutoConvert.h" #include "llvm/Support/Capacity.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Endian.h" @@ -166,8 +167,15 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM, // Unless this is a named pipe (in which case we can handle a mismatch), // check that the file's size is the same as in the file entry (which may // have come from a stat cache). +#ifndef __MVS__ if (!ContentsEntry->isNamedPipe() && Buffer->getBufferSize() != (size_t)ContentsEntry->getSize()) { +#else + // The buffer will always be larger than the file size on z/OS in the presence + // of characters outside the base character set. + if (!ContentsEntry->isNamedPipe() && + Buffer->getBufferSize() < (size_t)ContentsEntry->getSize()) { +#endif if (Diag.isDiagnosticInFlight()) Diag.SetDelayedDiagnostic(diag::err_file_modified, ContentsEntry->getName()); @@ -616,6 +624,23 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, StringRef Filename, return FileID::get(LoadedID); } unsigned FileSize = File.getSize(); +#ifdef __MVS__ + llvm::ErrorOr NeedConversion = + llvm::needConversion(Filename.str().c_str()); + if (NeedConversion && *NeedConversion) { +// Buffer size may increase due to potential z/OS EBCDIC to UTF-8 +// conversion. +if (std::optional Buffer = + File.getBufferOrNone(Diag, getFileManager())) { + unsigned BufSize = Buffer->getBufferSize(); + if (BufSize > FileSize) { +if (File.ContentsEntry.has_value()) + File.ContentsEntry->getFileEntry().setSize(BufSize); +FileSize = BufSize; + } +} + } +#endif if (!(NextLocalOffset + FileSize + 1 > NextLocalOffset && NextLocalOffset + FileSize + 1 <= CurrentLoadedOffset)) { Diag.Report(IncludePos, diag::err_sloc_space_too_large); diff --git a/llvm/include/llvm/Support/AutoConvert.h b/llvm/include/llvm/Support/AutoConvert.h index f4fe80b22a876..784d8f2d3bf75 100644 --- a/llvm/include/llvm/Support/AutoConvert.h +++ b/llvm/include/llvm/Support/AutoConvert.h @@ -17,6 +17,7 @@ #ifdef __MVS__ #include <_Ccsid.h> #ifdef __cplusplus +#include "llvm/Support/ErrorOr.h" #include #endif // __cplusplus @@ -52,6 +53,12 @@ std::error_code restoreStdHandleAutoConversion(int FD); /// \brief Set the tag information for a file descriptor. std::error_code setFileTag(int FD, int CCSID, bool Text); +// Get the the tag ccsid for a file name or a file descriptor. +ErrorOr<__ccsid_t> getFileTag(const char *FileName, const int FD = -1); + +// Query the file tag to determine if it needs conversion to UTF-8 codepage. +ErrorOr needConversion(const char *FileName, const int FD = -1); + } // namespac
[clang] [llvm] [SystemZ][z/OS] Update autoconversion functions to improve support for UTF-8 (PR #98652)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/98652 >From 716a8c95d0059eaf616d9c179708ac4e02c17220 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 12 Jul 2024 11:17:24 -0400 Subject: [PATCH] update autoconversion functionality to fix error: source file is not valid UTF-8 --- clang/include/clang/Basic/FileEntry.h | 9 ++ clang/lib/Basic/SourceManager.cpp | 25 llvm/include/llvm/Support/AutoConvert.h | 7 + llvm/lib/Support/AutoConvert.cpp| 40 - llvm/lib/Support/MemoryBuffer.cpp | 16 -- llvm/lib/Support/VirtualFileSystem.cpp | 2 +- 6 files changed, 95 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 68d4bf6093003..1fe6c3617582c 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -70,6 +70,11 @@ class FileEntryRef { const FileEntry &getFileEntry() const { return *getBaseMapEntry().second->V.get(); } +#ifdef __MVS__ + FileEntry &getFileEntry() { +return *getBaseMapEntry().second->V.get(); + } +#endif DirectoryEntryRef getDir() const { return ME->second->Dir; } inline off_t getSize() const; @@ -323,6 +328,10 @@ class FileEntry { StringRef tryGetRealPathName() const { return RealPathName; } off_t getSize() const { return Size; } +#ifdef __MVS__ + // Size may increase due to potential z/OS EBCDIC -> UTF-8 conversion. + void setSize(off_t NewSize) { Size = NewSize; } +#endif unsigned getUID() const { return UID; } const llvm::sys::fs::UniqueID &getUniqueID() const { return UniqueID; } time_t getModificationTime() const { return ModTime; } diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 533a9fe88a215..6fc9902fb4758 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -24,6 +24,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/Allocator.h" +#include "llvm/Support/AutoConvert.h" #include "llvm/Support/Capacity.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Endian.h" @@ -166,8 +167,15 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM, // Unless this is a named pipe (in which case we can handle a mismatch), // check that the file's size is the same as in the file entry (which may // have come from a stat cache). +#ifndef __MVS__ if (!ContentsEntry->isNamedPipe() && Buffer->getBufferSize() != (size_t)ContentsEntry->getSize()) { +#else + // The buffer will always be larger than the file size on z/OS in the presence + // of characters outside the base character set. + if (!ContentsEntry->isNamedPipe() && + Buffer->getBufferSize() < (size_t)ContentsEntry->getSize()) { +#endif if (Diag.isDiagnosticInFlight()) Diag.SetDelayedDiagnostic(diag::err_file_modified, ContentsEntry->getName()); @@ -616,6 +624,23 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, StringRef Filename, return FileID::get(LoadedID); } unsigned FileSize = File.getSize(); +#ifdef __MVS__ + llvm::ErrorOr NeedConversion = + llvm::needConversion(Filename.str().c_str()); + if (NeedConversion && *NeedConversion) { +// Buffer size may increase due to potential z/OS EBCDIC to UTF-8 +// conversion. +if (std::optional Buffer = +File.getBufferOrNone(Diag, getFileManager())) { + unsigned BufSize = Buffer->getBufferSize(); + if (BufSize > FileSize) { +if (File.ContentsEntry.has_value()) + File.ContentsEntry->getFileEntry().setSize(BufSize); +FileSize = BufSize; + } +} + } +#endif if (!(NextLocalOffset + FileSize + 1 > NextLocalOffset && NextLocalOffset + FileSize + 1 <= CurrentLoadedOffset)) { Diag.Report(IncludePos, diag::err_sloc_space_too_large); diff --git a/llvm/include/llvm/Support/AutoConvert.h b/llvm/include/llvm/Support/AutoConvert.h index f4fe80b22a876..784d8f2d3bf75 100644 --- a/llvm/include/llvm/Support/AutoConvert.h +++ b/llvm/include/llvm/Support/AutoConvert.h @@ -17,6 +17,7 @@ #ifdef __MVS__ #include <_Ccsid.h> #ifdef __cplusplus +#include "llvm/Support/ErrorOr.h" #include #endif // __cplusplus @@ -52,6 +53,12 @@ std::error_code restoreStdHandleAutoConversion(int FD); /// \brief Set the tag information for a file descriptor. std::error_code setFileTag(int FD, int CCSID, bool Text); +// Get the the tag ccsid for a file name or a file descriptor. +ErrorOr<__ccsid_t> getFileTag(const char *FileName, const int FD = -1); + +// Query the file tag to determine if it needs conversion to UTF-8 codepage. +ErrorOr needConversion(const char *FileName, const int FD = -1); + } // namespace llvm #endif // __cplusplus diff --git a/llvm/lib/Support/AutoConvert.cpp b/llvm/lib/Support/AutoConve
[clang] [llvm] [SystemZ][z/OS] Update autoconversion functions to improve support for UTF-8 (PR #98652)
https://github.com/abhina-sree edited https://github.com/llvm/llvm-project/pull/98652 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] Update autoconversion functions to improve support for UTF-8 (PR #98652)
@@ -326,7 +326,7 @@ ErrorOr> RealFileSystem::openFileForRead(const Twine &Name) { SmallString<256> RealName, Storage; Expected FDOrErr = sys::fs::openNativeFileForRead( - adjustPath(Name, Storage), sys::fs::OF_None, &RealName); + adjustPath(Name, Storage), sys::fs::OF_Text, &RealName); abhina-sree wrote: That's a good point, I will look into that, thanks! https://github.com/llvm/llvm-project/pull/98652 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [z/OS] add support for z/OS system headers to clang std header wrappers (PR #89995)
https://github.com/abhina-sree closed https://github.com/llvm/llvm-project/pull/89995 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [z/OS] treat text files as text files so auto-conversion is done (PR #90128)
https://github.com/abhina-sree closed https://github.com/llvm/llvm-project/pull/90128 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] __ptr32 support for z/OS (PR #101696)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/101696 >From 0246fe8e7f8d93ad3e37ff770a18bd1928552b5f Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 2 Aug 2024 11:44:44 -0400 Subject: [PATCH] __ptr32 support for z/OS --- clang/include/clang/Basic/LangOptions.def | 1 + clang/include/clang/Basic/TokenKinds.def | 3 +- clang/include/clang/Driver/Options.td | 4 + clang/lib/AST/ItaniumMangle.cpp | 8 +- clang/lib/Basic/IdentifierTable.cpp | 18 +- clang/lib/Basic/Targets/SystemZ.h | 40 ++- clang/lib/Frontend/CompilerInvocation.cpp | 11 + clang/lib/Sema/SemaType.cpp | 3 +- .../SystemZ/zos-mixed-ptr-sizes-definitions.c | 54 .../SystemZ/zos-mixed-ptr-sizes-malloc.c | 84 + .../SystemZ/zos-mixed-ptr-sizes-sizeof.c | 94 ++ .../CodeGen/SystemZ/zos-mixed-ptr-sizes.c | 298 ++ clang/test/CodeGen/target-data.c | 2 +- .../zos-mangle-ptr-size-address-space.cpp | 17 + clang/test/Sema/ZOSExtensions.cpp | 119 +++ clang/test/Sema/attr-print-zos.c | 31 ++ .../Target/SystemZ/SystemZTargetMachine.cpp | 8 + 17 files changed, 785 insertions(+), 10 deletions(-) create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes-definitions.c create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes-malloc.c create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes-sizeof.c create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes.c create mode 100644 clang/test/CodeGenCXX/zos-mangle-ptr-size-address-space.cpp create mode 100644 clang/test/Sema/ZOSExtensions.cpp create mode 100644 clang/test/Sema/attr-print-zos.c diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 0035092ce0d863..c276c98d57db7b 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -91,6 +91,7 @@ LANGOPT(C2y , 1, 0, "C2y") LANGOPT(MSVCCompat, 1, 0, "Microsoft Visual C++ full compatibility mode") LANGOPT(Kernel, 1, 0, "Kernel mode") LANGOPT(MicrosoftExt , 1, 0, "Microsoft C++ extensions") +LANGOPT(ZOSExt, 1, 0, "z/OS extensions") LANGOPT(AsmBlocks , 1, 0, "Microsoft inline asm blocks") LANGOPT(Borland , 1, 0, "Borland extensions") LANGOPT(CPlusPlus , 1, 0, "C++") diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def index 7e638dc1ddcdba..9cb8a34ac15575 100644 --- a/clang/include/clang/Basic/TokenKinds.def +++ b/clang/include/clang/Basic/TokenKinds.def @@ -292,6 +292,7 @@ PUNCTUATOR(caretcaret,"^^") // CHAR8SUPPORT - This is a keyword if 'char8_t' is a built-in type // KEYFIXEDPOINT - This is a keyword according to the N1169 fixed point // extension. +// KEYZOS - This is a keyword in C/C++ on z/OS // KEYWORD(auto, KEYALL) KEYWORD(break , KEYALL) @@ -722,7 +723,7 @@ KEYWORD(__funcref , KEYALL) // Microsoft extensions which should be disabled in strict conformance mode KEYWORD(__ptr64 , KEYMS) -KEYWORD(__ptr32 , KEYMS) +KEYWORD(__ptr32 , KEYMS | KEYZOS) KEYWORD(__sptr, KEYMS) KEYWORD(__uptr, KEYMS) KEYWORD(__w64 , KEYMS) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index f690467bb82cd3..00b8f7c5635e2c 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3065,6 +3065,10 @@ dll version.}]>; def fms_omit_default_lib : Joined<["-"], "fms-omit-default-lib">, Group, Flags<[]>, Visibility<[ClangOption, CLOption]>; +def fzos_extensions : Flag<["-"], "fzos-extensions">, Group, Visibility<[ClangOption, CC1Option]>, + HelpText<"Accept some non-standard constructs supported by the z/OS compiler">; +def fno_zos_extensions : Flag<["-"], "fno-zos-extensions">, Group, Visibility<[ClangOption, CC1Option]>, + HelpText<"Do not accept non-standard constructs supported by the z/OS compiler">; defm delayed_template_parsing : BoolFOption<"delayed-template-parsing", LangOpts<"DelayedTemplateParsing">, DefaultFalse, PosFlag ::= U //::= U +llvm::Triple Triple = getASTContext().getTargetInfo().getTriple(); + SmallString<64> ASString; LangAS AS = Quals.getAddressSpace(); @@ -2795,7 +2797,11 @@ void CXXNameMangler::mangleQualifiers(Qualifiers Quals, const DependentAddressSp ASString = "ptr32_sptr"; break; case LangAS::ptr32_uptr: -ASString = "ptr32_uptr"; +// For z/OS, there are no special mangling rules applied to the ptr32 +// qualifier. Ex: void fo
[clang] [NFC] Format TokenKey enum (PR #101700)
https://github.com/abhina-sree created https://github.com/llvm/llvm-project/pull/101700 This is to fix the suggested formatting error seen here https://github.com/llvm/llvm-project/pull/96063 >From be425ea61ed9b45839e5dff517797cd1c1e42c5a Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 2 Aug 2024 11:56:22 -0400 Subject: [PATCH] [NFC] format TokenKey enum --- clang/lib/Basic/IdentifierTable.cpp | 86 ++--- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp index 4f7ccaf4021d6..81e7e6d3fcfda 100644 --- a/clang/lib/Basic/IdentifierTable.cpp +++ b/clang/lib/Basic/IdentifierTable.cpp @@ -81,49 +81,49 @@ IdentifierTable::IdentifierTable(const LangOptions &LangOpts, // Constants for TokenKinds.def namespace { - enum TokenKey : unsigned { -KEYC99= 0x1, -KEYCXX= 0x2, -KEYCXX11 = 0x4, -KEYGNU= 0x8, -KEYMS = 0x10, -BOOLSUPPORT = 0x20, -KEYALTIVEC= 0x40, -KEYNOCXX = 0x80, -KEYBORLAND= 0x100, -KEYOPENCLC= 0x200, -KEYC23= 0x400, -KEYNOMS18 = 0x800, -KEYNOOPENCL = 0x1000, -WCHARSUPPORT = 0x2000, -HALFSUPPORT = 0x4000, -CHAR8SUPPORT = 0x8000, -KEYOBJC = 0x1, -KEYZVECTOR= 0x2, -KEYCOROUTINES = 0x4, -KEYMODULES= 0x8, -KEYCXX20 = 0x10, -KEYOPENCLCXX = 0x20, -KEYMSCOMPAT = 0x40, -KEYSYCL = 0x80, -KEYCUDA = 0x100, -KEYHLSL = 0x200, -KEYFIXEDPOINT = 0x400, -KEYMAX= KEYFIXEDPOINT, // The maximum key -KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX20, -KEYALL = (KEYMAX | (KEYMAX-1)) & ~KEYNOMS18 & - ~KEYNOOPENCL // KEYNOMS18 and KEYNOOPENCL are used to exclude. - }; - - /// How a keyword is treated in the selected standard. This enum is ordered - /// intentionally so that the value that 'wins' is the most 'permissive'. - enum KeywordStatus { -KS_Unknown, // Not yet calculated. Used when figuring out the status. -KS_Disabled,// Disabled -KS_Future, // Is a keyword in future standard -KS_Extension, // Is an extension -KS_Enabled, // Enabled - }; +enum TokenKey : unsigned { + KEYC99= 0x1, + KEYCXX= 0x2, + KEYCXX11 = 0x4, + KEYGNU= 0x8, + KEYMS = 0x10, + BOOLSUPPORT = 0x20, + KEYALTIVEC= 0x40, + KEYNOCXX = 0x80, + KEYBORLAND= 0x100, + KEYOPENCLC= 0x200, + KEYC23= 0x400, + KEYNOMS18 = 0x800, + KEYNOOPENCL = 0x1000, + WCHARSUPPORT = 0x2000, + HALFSUPPORT = 0x4000, + CHAR8SUPPORT = 0x8000, + KEYOBJC = 0x1, + KEYZVECTOR= 0x2, + KEYCOROUTINES = 0x4, + KEYMODULES= 0x8, + KEYCXX20 = 0x10, + KEYOPENCLCXX = 0x20, + KEYMSCOMPAT = 0x40, + KEYSYCL = 0x80, + KEYCUDA = 0x100, + KEYHLSL = 0x200, + KEYFIXEDPOINT = 0x400, + KEYMAX= KEYFIXEDPOINT, // The maximum key + KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX20, + KEYALL = (KEYMAX | (KEYMAX-1)) & ~KEYNOMS18 & + ~KEYNOOPENCL // KEYNOMS18 and KEYNOOPENCL are used to exclude. +}; + +/// How a keyword is treated in the selected standard. This enum is ordered +/// intentionally so that the value that 'wins' is the most 'permissive'. +enum KeywordStatus { + KS_Unknown, // Not yet calculated. Used when figuring out the status. + KS_Disabled,// Disabled + KS_Future, // Is a keyword in future standard + KS_Extension, // Is an extension + KS_Enabled, // Enabled +}; } // namespace ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] Format TokenKey enum (PR #101700)
https://github.com/abhina-sree edited https://github.com/llvm/llvm-project/pull/101700 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] Format TokenKey enum (PR #101700)
https://github.com/abhina-sree edited https://github.com/llvm/llvm-project/pull/101700 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] Format TokenKey enum (PR #101700)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/101700 >From 647b7c492ae814d4bada1435f3c41b700f093b64 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 2 Aug 2024 11:56:22 -0400 Subject: [PATCH] [NFC] format TokenKey enum --- clang/lib/Basic/IdentifierTable.cpp | 86 ++--- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp index 4f7ccaf4021d6..9cf081e9e26c1 100644 --- a/clang/lib/Basic/IdentifierTable.cpp +++ b/clang/lib/Basic/IdentifierTable.cpp @@ -81,49 +81,49 @@ IdentifierTable::IdentifierTable(const LangOptions &LangOpts, // Constants for TokenKinds.def namespace { - enum TokenKey : unsigned { -KEYC99= 0x1, -KEYCXX= 0x2, -KEYCXX11 = 0x4, -KEYGNU= 0x8, -KEYMS = 0x10, -BOOLSUPPORT = 0x20, -KEYALTIVEC= 0x40, -KEYNOCXX = 0x80, -KEYBORLAND= 0x100, -KEYOPENCLC= 0x200, -KEYC23= 0x400, -KEYNOMS18 = 0x800, -KEYNOOPENCL = 0x1000, -WCHARSUPPORT = 0x2000, -HALFSUPPORT = 0x4000, -CHAR8SUPPORT = 0x8000, -KEYOBJC = 0x1, -KEYZVECTOR= 0x2, -KEYCOROUTINES = 0x4, -KEYMODULES= 0x8, -KEYCXX20 = 0x10, -KEYOPENCLCXX = 0x20, -KEYMSCOMPAT = 0x40, -KEYSYCL = 0x80, -KEYCUDA = 0x100, -KEYHLSL = 0x200, -KEYFIXEDPOINT = 0x400, -KEYMAX= KEYFIXEDPOINT, // The maximum key -KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX20, -KEYALL = (KEYMAX | (KEYMAX-1)) & ~KEYNOMS18 & - ~KEYNOOPENCL // KEYNOMS18 and KEYNOOPENCL are used to exclude. - }; - - /// How a keyword is treated in the selected standard. This enum is ordered - /// intentionally so that the value that 'wins' is the most 'permissive'. - enum KeywordStatus { -KS_Unknown, // Not yet calculated. Used when figuring out the status. -KS_Disabled,// Disabled -KS_Future, // Is a keyword in future standard -KS_Extension, // Is an extension -KS_Enabled, // Enabled - }; +enum TokenKey : unsigned { + KEYC99 = 0x1, + KEYCXX = 0x2, + KEYCXX11 = 0x4, + KEYGNU = 0x8, + KEYMS = 0x10, + BOOLSUPPORT = 0x20, + KEYALTIVEC = 0x40, + KEYNOCXX = 0x80, + KEYBORLAND = 0x100, + KEYOPENCLC = 0x200, + KEYC23 = 0x400, + KEYNOMS18 = 0x800, + KEYNOOPENCL = 0x1000, + WCHARSUPPORT = 0x2000, + HALFSUPPORT = 0x4000, + CHAR8SUPPORT = 0x8000, + KEYOBJC = 0x1, + KEYZVECTOR = 0x2, + KEYCOROUTINES = 0x4, + KEYMODULES = 0x8, + KEYCXX20 = 0x10, + KEYOPENCLCXX = 0x20, + KEYMSCOMPAT = 0x40, + KEYSYCL = 0x80, + KEYCUDA = 0x100, + KEYHLSL = 0x200, + KEYFIXEDPOINT = 0x400, + KEYMAX = KEYFIXEDPOINT, // The maximum key + KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX20, + KEYALL = (KEYMAX | (KEYMAX - 1)) & ~KEYNOMS18 & + ~KEYNOOPENCL // KEYNOMS18 and KEYNOOPENCL are used to exclude. +}; + +/// How a keyword is treated in the selected standard. This enum is ordered +/// intentionally so that the value that 'wins' is the most 'permissive'. +enum KeywordStatus { + KS_Unknown, // Not yet calculated. Used when figuring out the status. + KS_Disabled, // Disabled + KS_Future,// Is a keyword in future standard + KS_Extension, // Is an extension + KS_Enabled, // Enabled +}; } // namespace ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] Format TokenKey enum (PR #101700)
https://github.com/abhina-sree closed https://github.com/llvm/llvm-project/pull/101700 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] __ptr32 support for z/OS (PR #101696)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/101696 >From 20a999cf221064c5d160fca8a118707bcb0d199a Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 2 Aug 2024 11:44:44 -0400 Subject: [PATCH] __ptr32 support for z/OS --- clang/include/clang/Basic/LangOptions.def | 1 + clang/include/clang/Basic/TokenKinds.def | 3 +- clang/include/clang/Driver/Options.td | 4 + clang/lib/AST/ItaniumMangle.cpp | 8 +- clang/lib/Basic/IdentifierTable.cpp | 18 +- clang/lib/Basic/Targets/SystemZ.h | 40 ++- clang/lib/Frontend/CompilerInvocation.cpp | 11 + clang/lib/Sema/SemaType.cpp | 3 +- .../SystemZ/zos-mixed-ptr-sizes-definitions.c | 54 .../SystemZ/zos-mixed-ptr-sizes-malloc.c | 84 + .../SystemZ/zos-mixed-ptr-sizes-sizeof.c | 94 ++ .../CodeGen/SystemZ/zos-mixed-ptr-sizes.c | 298 ++ clang/test/CodeGen/target-data.c | 2 +- .../zos-mangle-ptr-size-address-space.cpp | 17 + clang/test/Sema/ZOSExtensions.cpp | 119 +++ clang/test/Sema/attr-print-zos.c | 31 ++ .../Target/SystemZ/SystemZTargetMachine.cpp | 8 + 17 files changed, 785 insertions(+), 10 deletions(-) create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes-definitions.c create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes-malloc.c create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes-sizeof.c create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes.c create mode 100644 clang/test/CodeGenCXX/zos-mangle-ptr-size-address-space.cpp create mode 100644 clang/test/Sema/ZOSExtensions.cpp create mode 100644 clang/test/Sema/attr-print-zos.c diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 6945f8b01e91cd..54e689a7a42213 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -91,6 +91,7 @@ LANGOPT(C2y , 1, 0, "C2y") LANGOPT(MSVCCompat, 1, 0, "Microsoft Visual C++ full compatibility mode") LANGOPT(Kernel, 1, 0, "Kernel mode") LANGOPT(MicrosoftExt , 1, 0, "Microsoft C++ extensions") +LANGOPT(ZOSExt, 1, 0, "z/OS extensions") LANGOPT(AsmBlocks , 1, 0, "Microsoft inline asm blocks") LANGOPT(Borland , 1, 0, "Borland extensions") LANGOPT(CPlusPlus , 1, 0, "C++") diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def index 2cea64e2bd590b..421dbb413fed93 100644 --- a/clang/include/clang/Basic/TokenKinds.def +++ b/clang/include/clang/Basic/TokenKinds.def @@ -292,6 +292,7 @@ PUNCTUATOR(caretcaret,"^^") // CHAR8SUPPORT - This is a keyword if 'char8_t' is a built-in type // KEYFIXEDPOINT - This is a keyword according to the N1169 fixed point // extension. +// KEYZOS - This is a keyword in C/C++ on z/OS // KEYWORD(auto, KEYALL) KEYWORD(break , KEYALL) @@ -725,7 +726,7 @@ KEYWORD(__funcref , KEYALL) // Microsoft extensions which should be disabled in strict conformance mode KEYWORD(__ptr64 , KEYMS) -KEYWORD(__ptr32 , KEYMS) +KEYWORD(__ptr32 , KEYMS | KEYZOS) KEYWORD(__sptr, KEYMS) KEYWORD(__uptr, KEYMS) KEYWORD(__w64 , KEYMS) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 9bc84168c29608..cbb301ba3bd9c0 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3066,6 +3066,10 @@ dll version.}]>; def fms_omit_default_lib : Joined<["-"], "fms-omit-default-lib">, Group, Flags<[]>, Visibility<[ClangOption, CLOption]>; +def fzos_extensions : Flag<["-"], "fzos-extensions">, Group, Visibility<[ClangOption, CC1Option]>, + HelpText<"Accept some non-standard constructs supported by the z/OS compiler">; +def fno_zos_extensions : Flag<["-"], "fno-zos-extensions">, Group, Visibility<[ClangOption, CC1Option]>, + HelpText<"Do not accept non-standard constructs supported by the z/OS compiler">; defm delayed_template_parsing : BoolFOption<"delayed-template-parsing", LangOpts<"DelayedTemplateParsing">, DefaultFalse, PosFlag ::= U //::= U +llvm::Triple Triple = getASTContext().getTargetInfo().getTriple(); + SmallString<64> ASString; LangAS AS = Quals.getAddressSpace(); @@ -2795,7 +2797,11 @@ void CXXNameMangler::mangleQualifiers(Qualifiers Quals, const DependentAddressSp ASString = "ptr32_sptr"; break; case LangAS::ptr32_uptr: -ASString = "ptr32_uptr"; +// For z/OS, there are no special mangling rules applied to the ptr32 +// qualifier. Ex: void fo
[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #101024)
@@ -532,9 +532,371 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const Type *Ty, return false; } +//===--===// +// z/OS XPLINK ABI Implementation +//===--===// + +namespace { + +class ZOSXPLinkABIInfo : public ABIInfo { + const unsigned GPRBits = 64; + bool HasVector; + +public: + ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {} + + bool isPromotableIntegerType(QualType Ty) const; + bool isVectorArgumentType(QualType Ty) const; + bool isFPArgumentType(QualType Ty) const; + QualType getSingleElementType(QualType Ty) const; + QualType getFPTypeOfComplexLikeType(QualType Ty) const; + + ABIArgInfo classifyReturnType(QualType RetTy) const; + ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg) const; + + void computeInfo(CGFunctionInfo &FI) const override { +if (!getCXXABI().classifyReturnType(FI)) + FI.getReturnInfo() = classifyReturnType(FI.getReturnType()); + +unsigned NumRequiredArgs = FI.getNumRequiredArgs(); +unsigned ArgNo = 0; + +for (auto &I : FI.arguments()) { + bool IsNamedArg = ArgNo < NumRequiredArgs; + I.info = classifyArgumentType(I.type, IsNamedArg); + ++ArgNo; +} + } + + RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, + AggValueSlot Slot) const override; +}; + +class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo { +public: + ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector) + : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) { +SwiftInfo = +std::make_unique(CGT, /*SwiftErrorInRegister=*/false); + } +}; + +} // namespace + +// Return true if the ABI requires Ty to be passed sign- or zero- +// extended to 64 bits. +bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const { + // Treat an enum type as its underlying type. + if (const EnumType *EnumTy = Ty->getAs()) +Ty = EnumTy->getDecl()->getIntegerType(); + + // Promotable integer types are required to be promoted by the ABI. + if (getContext().isPromotableIntegerType(Ty)) +return true; + + if (const auto *EIT = Ty->getAs()) +if (EIT->getNumBits() < 64) + return true; + + // In addition to the usual promotable integer types, we also need to + // extend all 32-bit types, since the ABI requires promotion to 64 bits. + if (const BuiltinType *BT = Ty->getAs()) +switch (BT->getKind()) { +case BuiltinType::Int: +case BuiltinType::UInt: + return true; +default: + break; +} + + return false; +} + +bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const { + return (HasVector && Ty->isVectorType() && + getContext().getTypeSize(Ty) <= 128); +} + +bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const { + if (const BuiltinType *BT = Ty->getAs()) +switch (BT->getKind()) { +case BuiltinType::Float: +case BuiltinType::Double: +case BuiltinType::LongDouble: + return true; +default: + return false; +} + + return false; +} + +QualType ZOSXPLinkABIInfo::getSingleElementType(QualType Ty) const { + // Unions just containing a floating point type, e.g. union { float f1, f2; }; + // are treated as a single floating point number. Check if the union only + // consists of a single type (handling embedded unions recursively), and + // return that type. + if (const RecordType *RT = Ty->getAsUnionType()) { +QualType Found; +// Check the fields. +const RecordDecl *RD = RT->getDecl(); +for (const auto *FD : RD->fields()) { + if (Found.isNull()) +Found = getSingleElementType(FD->getType()); + else if (Found != getSingleElementType(FD->getType())) +return Ty; +} +return Found.isNull() ? Ty : Found; + } + + const RecordType *RT = Ty->getAs(); + + if (RT && RT->isStructureOrClassType()) { +const RecordDecl *RD = RT->getDecl(); +QualType Found; + +// If this is a C++ record, check the bases first. +if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) + if (CXXRD->hasDefinition()) +for (const auto &I : CXXRD->bases()) { + QualType Base = I.getType(); + + // Empty bases don't affect things either way. + if (isEmptyRecord(getContext(), Base, true)) +continue; + + if (!Found.isNull()) +return Ty; + Found = getSingleElementType(Base); +} + +// Check the fields. +for (const auto *FD : RD->fields()) { + QualType FT = FD->getType(); + + // Ignore empty fields. + if (isEmptyField(getContext(), FD, true)) +continue; + + if (!Found.isNull()) +return Ty; + + // Treat single element arrays as the element. + while (const ConstantArrayType *AT = + getContext().getAsConstantArrayType(FT)) { +if (AT->getZEx
[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #101024)
@@ -532,9 +532,371 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const Type *Ty, return false; } +//===--===// +// z/OS XPLINK ABI Implementation +//===--===// + +namespace { + +class ZOSXPLinkABIInfo : public ABIInfo { + const unsigned GPRBits = 64; + bool HasVector; + +public: + ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {} + + bool isPromotableIntegerType(QualType Ty) const; + bool isVectorArgumentType(QualType Ty) const; + bool isFPArgumentType(QualType Ty) const; + QualType getSingleElementType(QualType Ty) const; + QualType getFPTypeOfComplexLikeType(QualType Ty) const; + + ABIArgInfo classifyReturnType(QualType RetTy) const; + ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg) const; + + void computeInfo(CGFunctionInfo &FI) const override { +if (!getCXXABI().classifyReturnType(FI)) + FI.getReturnInfo() = classifyReturnType(FI.getReturnType()); + +unsigned NumRequiredArgs = FI.getNumRequiredArgs(); +unsigned ArgNo = 0; + +for (auto &I : FI.arguments()) { + bool IsNamedArg = ArgNo < NumRequiredArgs; + I.info = classifyArgumentType(I.type, IsNamedArg); + ++ArgNo; +} + } + + RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, + AggValueSlot Slot) const override; +}; + +class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo { +public: + ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector) + : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) { +SwiftInfo = +std::make_unique(CGT, /*SwiftErrorInRegister=*/false); + } +}; + +} // namespace + +// Return true if the ABI requires Ty to be passed sign- or zero- +// extended to 64 bits. +bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const { + // Treat an enum type as its underlying type. + if (const EnumType *EnumTy = Ty->getAs()) +Ty = EnumTy->getDecl()->getIntegerType(); + + // Promotable integer types are required to be promoted by the ABI. + if (getContext().isPromotableIntegerType(Ty)) +return true; + + if (const auto *EIT = Ty->getAs()) +if (EIT->getNumBits() < 64) + return true; + + // In addition to the usual promotable integer types, we also need to + // extend all 32-bit types, since the ABI requires promotion to 64 bits. + if (const BuiltinType *BT = Ty->getAs()) +switch (BT->getKind()) { +case BuiltinType::Int: +case BuiltinType::UInt: + return true; +default: + break; +} + + return false; +} + +bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const { + return (HasVector && Ty->isVectorType() && + getContext().getTypeSize(Ty) <= 128); +} + +bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const { + if (const BuiltinType *BT = Ty->getAs()) +switch (BT->getKind()) { +case BuiltinType::Float: +case BuiltinType::Double: +case BuiltinType::LongDouble: + return true; +default: + return false; +} + + return false; +} + +QualType ZOSXPLinkABIInfo::getSingleElementType(QualType Ty) const { + // Unions just containing a floating point type, e.g. union { float f1, f2; }; + // are treated as a single floating point number. Check if the union only + // consists of a single type (handling embedded unions recursively), and + // return that type. + if (const RecordType *RT = Ty->getAsUnionType()) { +QualType Found; +// Check the fields. +const RecordDecl *RD = RT->getDecl(); +for (const auto *FD : RD->fields()) { + if (Found.isNull()) +Found = getSingleElementType(FD->getType()); + else if (Found != getSingleElementType(FD->getType())) +return Ty; +} +return Found.isNull() ? Ty : Found; + } + + const RecordType *RT = Ty->getAs(); + + if (RT && RT->isStructureOrClassType()) { +const RecordDecl *RD = RT->getDecl(); +QualType Found; + +// If this is a C++ record, check the bases first. +if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) + if (CXXRD->hasDefinition()) +for (const auto &I : CXXRD->bases()) { + QualType Base = I.getType(); + + // Empty bases don't affect things either way. + if (isEmptyRecord(getContext(), Base, true)) +continue; + + if (!Found.isNull()) +return Ty; + Found = getSingleElementType(Base); +} + +// Check the fields. +for (const auto *FD : RD->fields()) { + QualType FT = FD->getType(); + + // Ignore empty fields. + if (isEmptyField(getContext(), FD, true)) +continue; + + if (!Found.isNull()) +return Ty; + + // Treat single element arrays as the element. + while (const ConstantArrayType *AT = + getContext().getAsConstantArrayType(FT)) { +if (AT->getZEx
[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #101024)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/101024 >From 9d30fcbac4ecdc592663d20a2b18b6b4e2ee873e Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Mon, 29 Jul 2024 10:49:08 -0400 Subject: [PATCH 1/4] [SystemZ][z/OS] Implement z/OS XPLINK ABI --- clang/lib/CodeGen/CodeGenModule.cpp | 2 + clang/lib/CodeGen/TargetInfo.h| 4 + clang/lib/CodeGen/Targets/SystemZ.cpp | 290 ++ clang/test/CodeGen/zos-abi.c | 247 ++ clang/test/CodeGen/zos-abi.cpp| 24 +++ 5 files changed, 567 insertions(+) create mode 100644 clang/test/CodeGen/zos-abi.c create mode 100644 clang/test/CodeGen/zos-abi.cpp diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 63ed5b4dd0c31..49ff482168eb9 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -244,6 +244,8 @@ createTargetCodeGenInfo(CodeGenModule &CGM) { case llvm::Triple::systemz: { bool SoftFloat = CodeGenOpts.FloatABI == "soft"; bool HasVector = !SoftFloat && Target.getABI() == "vector"; +if (Triple.getOS() == llvm::Triple::ZOS) + return createSystemZ_ZOS_TargetCodeGenInfo(CGM, HasVector, SoftFloat); return createSystemZTargetCodeGenInfo(CGM, HasVector, SoftFloat); } diff --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h index 8f17c053f4783..eaa303963e8ee 100644 --- a/clang/lib/CodeGen/TargetInfo.h +++ b/clang/lib/CodeGen/TargetInfo.h @@ -541,6 +541,10 @@ std::unique_ptr createSystemZTargetCodeGenInfo(CodeGenModule &CGM, bool HasVector, bool SoftFloatABI); +std::unique_ptr +createSystemZ_ZOS_TargetCodeGenInfo(CodeGenModule &CGM, bool HasVector, +bool SoftFloatABI); + std::unique_ptr createTCETargetCodeGenInfo(CodeGenModule &CGM); diff --git a/clang/lib/CodeGen/Targets/SystemZ.cpp b/clang/lib/CodeGen/Targets/SystemZ.cpp index 4d61f51379346..5bb91232a3285 100644 --- a/clang/lib/CodeGen/Targets/SystemZ.cpp +++ b/clang/lib/CodeGen/Targets/SystemZ.cpp @@ -10,6 +10,7 @@ #include "TargetInfo.h" #include "clang/Basic/Builtins.h" #include "llvm/IR/IntrinsicsS390.h" +#include using namespace clang; using namespace clang::CodeGen; @@ -532,9 +533,298 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const Type *Ty, return false; } +//===--===// +// z/OS XPLINK ABI Implementation +//===--===// + +namespace { + +class ZOSXPLinkABIInfo : public ABIInfo { + const unsigned GPRBits = 64; + bool HasVector; + +public: + ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {} + + bool isPromotableIntegerType(QualType Ty) const; + bool isVectorArgumentType(QualType Ty) const; + bool isFPArgumentType(QualType Ty) const; + std::optional getFPTypeOfComplexLikeType(QualType Ty) const; + + ABIArgInfo classifyReturnType(QualType RetTy) const; + ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg) const; + + void computeInfo(CGFunctionInfo &FI) const override { +if (!getCXXABI().classifyReturnType(FI)) + FI.getReturnInfo() = classifyReturnType(FI.getReturnType()); + +unsigned NumRequiredArgs = FI.getNumRequiredArgs(); +unsigned ArgNo = 0; + +for (auto &I : FI.arguments()) { + bool IsNamedArg = ArgNo < NumRequiredArgs; + I.info = classifyArgumentType(I.type, IsNamedArg); + ++ArgNo; +} + } + + RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, + AggValueSlot Slot) const override; +}; + +class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo { +public: + ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector) + : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) { +SwiftInfo = +std::make_unique(CGT, /*SwiftErrorInRegister=*/false); + } +}; + +} // namespace + +// Return true if the ABI requires Ty to be passed sign- or zero- +// extended to 64 bits. +bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const { + // Treat an enum type as its underlying type. + if (const EnumType *EnumTy = Ty->getAs()) +Ty = EnumTy->getDecl()->getIntegerType(); + + // Promotable integer types are required to be promoted by the ABI. + if (getContext().isPromotableIntegerType(Ty)) +return true; + + if (const auto *EIT = Ty->getAs()) +if (EIT->getNumBits() < 64) + return true; + + // In addition to the usual promotable integer types, we also need to + // extend all 32-bit types, since the ABI requires promotion to 64 bits. + if (const BuiltinType *BT = Ty->getAs()) +switch (BT->getKind()) { +case BuiltinType::Int: +case BuiltinType::UInt: + return true; +default: + break; +} + + return false; +} + +bool ZOSXPLinkABIInfo::isVectorArg
[clang] [llvm] [SystemZ][z/OS] __ptr32 support for z/OS (PR #101696)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/101696 >From f6e1481fb323352a4f6ce3728424d6990f72a800 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 2 Aug 2024 11:44:44 -0400 Subject: [PATCH] __ptr32 support for z/OS --- clang/include/clang/Basic/LangOptions.def | 1 + clang/include/clang/Basic/TokenKinds.def | 3 +- clang/include/clang/Driver/Options.td | 4 + clang/lib/AST/ItaniumMangle.cpp | 8 +- clang/lib/Basic/IdentifierTable.cpp | 18 +- clang/lib/Basic/Targets/SystemZ.h | 40 ++- clang/lib/Frontend/CompilerInvocation.cpp | 11 + clang/lib/Sema/SemaType.cpp | 3 +- .../SystemZ/zos-mixed-ptr-sizes-definitions.c | 54 .../SystemZ/zos-mixed-ptr-sizes-malloc.c | 84 + .../SystemZ/zos-mixed-ptr-sizes-sizeof.c | 94 ++ .../CodeGen/SystemZ/zos-mixed-ptr-sizes.c | 298 ++ clang/test/CodeGen/target-data.c | 2 +- .../zos-mangle-ptr-size-address-space.cpp | 17 + clang/test/Sema/ZOSExtensions.cpp | 119 +++ clang/test/Sema/attr-print-zos.c | 31 ++ .../Target/SystemZ/SystemZTargetMachine.cpp | 8 + 17 files changed, 785 insertions(+), 10 deletions(-) create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes-definitions.c create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes-malloc.c create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes-sizeof.c create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes.c create mode 100644 clang/test/CodeGenCXX/zos-mangle-ptr-size-address-space.cpp create mode 100644 clang/test/Sema/ZOSExtensions.cpp create mode 100644 clang/test/Sema/attr-print-zos.c diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 6945f8b01e91c..54e689a7a4221 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -91,6 +91,7 @@ LANGOPT(C2y , 1, 0, "C2y") LANGOPT(MSVCCompat, 1, 0, "Microsoft Visual C++ full compatibility mode") LANGOPT(Kernel, 1, 0, "Kernel mode") LANGOPT(MicrosoftExt , 1, 0, "Microsoft C++ extensions") +LANGOPT(ZOSExt, 1, 0, "z/OS extensions") LANGOPT(AsmBlocks , 1, 0, "Microsoft inline asm blocks") LANGOPT(Borland , 1, 0, "Borland extensions") LANGOPT(CPlusPlus , 1, 0, "C++") diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def index 2cea64e2bd590..421dbb413fed9 100644 --- a/clang/include/clang/Basic/TokenKinds.def +++ b/clang/include/clang/Basic/TokenKinds.def @@ -292,6 +292,7 @@ PUNCTUATOR(caretcaret,"^^") // CHAR8SUPPORT - This is a keyword if 'char8_t' is a built-in type // KEYFIXEDPOINT - This is a keyword according to the N1169 fixed point // extension. +// KEYZOS - This is a keyword in C/C++ on z/OS // KEYWORD(auto, KEYALL) KEYWORD(break , KEYALL) @@ -725,7 +726,7 @@ KEYWORD(__funcref , KEYALL) // Microsoft extensions which should be disabled in strict conformance mode KEYWORD(__ptr64 , KEYMS) -KEYWORD(__ptr32 , KEYMS) +KEYWORD(__ptr32 , KEYMS | KEYZOS) KEYWORD(__sptr, KEYMS) KEYWORD(__uptr, KEYMS) KEYWORD(__w64 , KEYMS) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 9bc84168c2960..cbb301ba3bd9c 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3066,6 +3066,10 @@ dll version.}]>; def fms_omit_default_lib : Joined<["-"], "fms-omit-default-lib">, Group, Flags<[]>, Visibility<[ClangOption, CLOption]>; +def fzos_extensions : Flag<["-"], "fzos-extensions">, Group, Visibility<[ClangOption, CC1Option]>, + HelpText<"Accept some non-standard constructs supported by the z/OS compiler">; +def fno_zos_extensions : Flag<["-"], "fno-zos-extensions">, Group, Visibility<[ClangOption, CC1Option]>, + HelpText<"Do not accept non-standard constructs supported by the z/OS compiler">; defm delayed_template_parsing : BoolFOption<"delayed-template-parsing", LangOpts<"DelayedTemplateParsing">, DefaultFalse, PosFlag ::= U //::= U +llvm::Triple Triple = getASTContext().getTargetInfo().getTriple(); + SmallString<64> ASString; LangAS AS = Quals.getAddressSpace(); @@ -2795,7 +2797,11 @@ void CXXNameMangler::mangleQualifiers(Qualifiers Quals, const DependentAddressSp ASString = "ptr32_sptr"; break; case LangAS::ptr32_uptr: -ASString = "ptr32_uptr"; +// For z/OS, there are no special mangling rules applied to the ptr32 +// qualifier. Ex: void foo(int
[clang] [llvm] [SystemZ][z/OS] __ptr32 support for z/OS (PR #101696)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/101696 >From f6e1481fb323352a4f6ce3728424d6990f72a800 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 2 Aug 2024 11:44:44 -0400 Subject: [PATCH 1/2] __ptr32 support for z/OS --- clang/include/clang/Basic/LangOptions.def | 1 + clang/include/clang/Basic/TokenKinds.def | 3 +- clang/include/clang/Driver/Options.td | 4 + clang/lib/AST/ItaniumMangle.cpp | 8 +- clang/lib/Basic/IdentifierTable.cpp | 18 +- clang/lib/Basic/Targets/SystemZ.h | 40 ++- clang/lib/Frontend/CompilerInvocation.cpp | 11 + clang/lib/Sema/SemaType.cpp | 3 +- .../SystemZ/zos-mixed-ptr-sizes-definitions.c | 54 .../SystemZ/zos-mixed-ptr-sizes-malloc.c | 84 + .../SystemZ/zos-mixed-ptr-sizes-sizeof.c | 94 ++ .../CodeGen/SystemZ/zos-mixed-ptr-sizes.c | 298 ++ clang/test/CodeGen/target-data.c | 2 +- .../zos-mangle-ptr-size-address-space.cpp | 17 + clang/test/Sema/ZOSExtensions.cpp | 119 +++ clang/test/Sema/attr-print-zos.c | 31 ++ .../Target/SystemZ/SystemZTargetMachine.cpp | 8 + 17 files changed, 785 insertions(+), 10 deletions(-) create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes-definitions.c create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes-malloc.c create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes-sizeof.c create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes.c create mode 100644 clang/test/CodeGenCXX/zos-mangle-ptr-size-address-space.cpp create mode 100644 clang/test/Sema/ZOSExtensions.cpp create mode 100644 clang/test/Sema/attr-print-zos.c diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 6945f8b01e91cd..54e689a7a42213 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -91,6 +91,7 @@ LANGOPT(C2y , 1, 0, "C2y") LANGOPT(MSVCCompat, 1, 0, "Microsoft Visual C++ full compatibility mode") LANGOPT(Kernel, 1, 0, "Kernel mode") LANGOPT(MicrosoftExt , 1, 0, "Microsoft C++ extensions") +LANGOPT(ZOSExt, 1, 0, "z/OS extensions") LANGOPT(AsmBlocks , 1, 0, "Microsoft inline asm blocks") LANGOPT(Borland , 1, 0, "Borland extensions") LANGOPT(CPlusPlus , 1, 0, "C++") diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def index 2cea64e2bd590b..421dbb413fed93 100644 --- a/clang/include/clang/Basic/TokenKinds.def +++ b/clang/include/clang/Basic/TokenKinds.def @@ -292,6 +292,7 @@ PUNCTUATOR(caretcaret,"^^") // CHAR8SUPPORT - This is a keyword if 'char8_t' is a built-in type // KEYFIXEDPOINT - This is a keyword according to the N1169 fixed point // extension. +// KEYZOS - This is a keyword in C/C++ on z/OS // KEYWORD(auto, KEYALL) KEYWORD(break , KEYALL) @@ -725,7 +726,7 @@ KEYWORD(__funcref , KEYALL) // Microsoft extensions which should be disabled in strict conformance mode KEYWORD(__ptr64 , KEYMS) -KEYWORD(__ptr32 , KEYMS) +KEYWORD(__ptr32 , KEYMS | KEYZOS) KEYWORD(__sptr, KEYMS) KEYWORD(__uptr, KEYMS) KEYWORD(__w64 , KEYMS) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 9bc84168c29608..cbb301ba3bd9c0 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3066,6 +3066,10 @@ dll version.}]>; def fms_omit_default_lib : Joined<["-"], "fms-omit-default-lib">, Group, Flags<[]>, Visibility<[ClangOption, CLOption]>; +def fzos_extensions : Flag<["-"], "fzos-extensions">, Group, Visibility<[ClangOption, CC1Option]>, + HelpText<"Accept some non-standard constructs supported by the z/OS compiler">; +def fno_zos_extensions : Flag<["-"], "fno-zos-extensions">, Group, Visibility<[ClangOption, CC1Option]>, + HelpText<"Do not accept non-standard constructs supported by the z/OS compiler">; defm delayed_template_parsing : BoolFOption<"delayed-template-parsing", LangOpts<"DelayedTemplateParsing">, DefaultFalse, PosFlag ::= U //::= U +llvm::Triple Triple = getASTContext().getTargetInfo().getTriple(); + SmallString<64> ASString; LangAS AS = Quals.getAddressSpace(); @@ -2795,7 +2797,11 @@ void CXXNameMangler::mangleQualifiers(Qualifiers Quals, const DependentAddressSp ASString = "ptr32_sptr"; break; case LangAS::ptr32_uptr: -ASString = "ptr32_uptr"; +// For z/OS, there are no special mangling rules applied to the ptr32 +// qualifier. Ex: voi
[clang] [llvm] [SystemZ][z/OS] __ptr32 support for z/OS (PR #101696)
@@ -211,6 +215,9 @@ static KeywordStatus getKeywordStatusHelper(const LangOptions &LangOpts, case KEYNOMS18: // The disable behavior for this is handled in getKeywordStatus. return KS_Unknown; + case KEYNOZOS: +// The disable behavior for this is handled in getKeywordStatus. +return KS_Unknown; abhina-sree wrote: Thanks, this is done! https://github.com/llvm/llvm-project/pull/101696 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] __ptr32 support for z/OS (PR #101696)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/101696 >From f6e1481fb323352a4f6ce3728424d6990f72a800 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 2 Aug 2024 11:44:44 -0400 Subject: [PATCH 1/3] __ptr32 support for z/OS --- clang/include/clang/Basic/LangOptions.def | 1 + clang/include/clang/Basic/TokenKinds.def | 3 +- clang/include/clang/Driver/Options.td | 4 + clang/lib/AST/ItaniumMangle.cpp | 8 +- clang/lib/Basic/IdentifierTable.cpp | 18 +- clang/lib/Basic/Targets/SystemZ.h | 40 ++- clang/lib/Frontend/CompilerInvocation.cpp | 11 + clang/lib/Sema/SemaType.cpp | 3 +- .../SystemZ/zos-mixed-ptr-sizes-definitions.c | 54 .../SystemZ/zos-mixed-ptr-sizes-malloc.c | 84 + .../SystemZ/zos-mixed-ptr-sizes-sizeof.c | 94 ++ .../CodeGen/SystemZ/zos-mixed-ptr-sizes.c | 298 ++ clang/test/CodeGen/target-data.c | 2 +- .../zos-mangle-ptr-size-address-space.cpp | 17 + clang/test/Sema/ZOSExtensions.cpp | 119 +++ clang/test/Sema/attr-print-zos.c | 31 ++ .../Target/SystemZ/SystemZTargetMachine.cpp | 8 + 17 files changed, 785 insertions(+), 10 deletions(-) create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes-definitions.c create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes-malloc.c create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes-sizeof.c create mode 100644 clang/test/CodeGen/SystemZ/zos-mixed-ptr-sizes.c create mode 100644 clang/test/CodeGenCXX/zos-mangle-ptr-size-address-space.cpp create mode 100644 clang/test/Sema/ZOSExtensions.cpp create mode 100644 clang/test/Sema/attr-print-zos.c diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 6945f8b01e91cd..54e689a7a42213 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -91,6 +91,7 @@ LANGOPT(C2y , 1, 0, "C2y") LANGOPT(MSVCCompat, 1, 0, "Microsoft Visual C++ full compatibility mode") LANGOPT(Kernel, 1, 0, "Kernel mode") LANGOPT(MicrosoftExt , 1, 0, "Microsoft C++ extensions") +LANGOPT(ZOSExt, 1, 0, "z/OS extensions") LANGOPT(AsmBlocks , 1, 0, "Microsoft inline asm blocks") LANGOPT(Borland , 1, 0, "Borland extensions") LANGOPT(CPlusPlus , 1, 0, "C++") diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def index 2cea64e2bd590b..421dbb413fed93 100644 --- a/clang/include/clang/Basic/TokenKinds.def +++ b/clang/include/clang/Basic/TokenKinds.def @@ -292,6 +292,7 @@ PUNCTUATOR(caretcaret,"^^") // CHAR8SUPPORT - This is a keyword if 'char8_t' is a built-in type // KEYFIXEDPOINT - This is a keyword according to the N1169 fixed point // extension. +// KEYZOS - This is a keyword in C/C++ on z/OS // KEYWORD(auto, KEYALL) KEYWORD(break , KEYALL) @@ -725,7 +726,7 @@ KEYWORD(__funcref , KEYALL) // Microsoft extensions which should be disabled in strict conformance mode KEYWORD(__ptr64 , KEYMS) -KEYWORD(__ptr32 , KEYMS) +KEYWORD(__ptr32 , KEYMS | KEYZOS) KEYWORD(__sptr, KEYMS) KEYWORD(__uptr, KEYMS) KEYWORD(__w64 , KEYMS) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 9bc84168c29608..cbb301ba3bd9c0 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3066,6 +3066,10 @@ dll version.}]>; def fms_omit_default_lib : Joined<["-"], "fms-omit-default-lib">, Group, Flags<[]>, Visibility<[ClangOption, CLOption]>; +def fzos_extensions : Flag<["-"], "fzos-extensions">, Group, Visibility<[ClangOption, CC1Option]>, + HelpText<"Accept some non-standard constructs supported by the z/OS compiler">; +def fno_zos_extensions : Flag<["-"], "fno-zos-extensions">, Group, Visibility<[ClangOption, CC1Option]>, + HelpText<"Do not accept non-standard constructs supported by the z/OS compiler">; defm delayed_template_parsing : BoolFOption<"delayed-template-parsing", LangOpts<"DelayedTemplateParsing">, DefaultFalse, PosFlag ::= U //::= U +llvm::Triple Triple = getASTContext().getTargetInfo().getTriple(); + SmallString<64> ASString; LangAS AS = Quals.getAddressSpace(); @@ -2795,7 +2797,11 @@ void CXXNameMangler::mangleQualifiers(Qualifiers Quals, const DependentAddressSp ASString = "ptr32_sptr"; break; case LangAS::ptr32_uptr: -ASString = "ptr32_uptr"; +// For z/OS, there are no special mangling rules applied to the ptr32 +// qualifier. Ex: voi
[clang] [llvm] [SystemZ][z/OS] __ptr32 support for z/OS (PR #101696)
@@ -3650,6 +3650,14 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts, GenerateArg(Consumer, OPT_ftrigraphs); } + if (T.isOSzOS()) { +if (!Opts.ZOSExt) + GenerateArg(Consumer, OPT_fno_zos_extensions); + } else { +if (Opts.ZOSExt) + GenerateArg(Consumer, OPT_fzos_extensions); + } abhina-sree wrote: Thanks, I refactored the code a bit https://github.com/llvm/llvm-project/pull/101696 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] __ptr32 support for z/OS (PR #101696)
abhina-sree wrote: Enabling __ptr32 keyword to support in Clang for z/OS. It is represented by addrspace(1) in LLVM IR. Unlike existing implementation, __ptr32 is not mangled into symbol names for z/OS. https://github.com/llvm/llvm-project/pull/101696 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] __ptr32 support for z/OS (PR #101696)
https://github.com/abhina-sree closed https://github.com/llvm/llvm-project/pull/101696 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] Remove unnecessary copy of Triple in ItaniumMangle.cpp (PR #102469)
https://github.com/abhina-sree created https://github.com/llvm/llvm-project/pull/102469 Remove unnecessary copy of Triple in ItaniumMangle.cpp >From e5139d8079471ac6e6f0d76f36ed7ef593fff1b7 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Thu, 8 Aug 2024 09:57:03 -0400 Subject: [PATCH] [NFC] Remove unnecessary copy of Triple in ItaniumMangle.cpp --- clang/lib/AST/ItaniumMangle.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index dc317f2a7870b..976670d1efa56 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -2727,8 +2727,6 @@ void CXXNameMangler::mangleQualifiers(Qualifiers Quals, const DependentAddressSp //::= U //::= U -llvm::Triple Triple = getASTContext().getTargetInfo().getTriple(); - SmallString<64> ASString; LangAS AS = Quals.getAddressSpace(); @@ -2800,7 +2798,7 @@ void CXXNameMangler::mangleQualifiers(Qualifiers Quals, const DependentAddressSp // For z/OS, there are no special mangling rules applied to the ptr32 // qualifier. Ex: void foo(int * __ptr32 p) -> _Z3f2Pi. The mangling for // "p" is treated the same as a regular integer pointer. -if (!Triple.isOSzOS()) +if (!getASTContext().getTargetInfo().getTriple().isOSzOS()) ASString = "ptr32_uptr"; break; case LangAS::ptr64: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] Remove unnecessary copy of Triple in ItaniumMangle.cpp (PR #102469)
https://github.com/abhina-sree edited https://github.com/llvm/llvm-project/pull/102469 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] __ptr32 support for z/OS (PR #101696)
@@ -2727,6 +2727,8 @@ void CXXNameMangler::mangleQualifiers(Qualifiers Quals, const DependentAddressSp //::= U //::= U +llvm::Triple Triple = getASTContext().getTargetInfo().getTriple(); abhina-sree wrote: Thanks for catching, I fixed this here https://github.com/llvm/llvm-project/pull/102469 https://github.com/llvm/llvm-project/pull/101696 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] Remove unnecessary copy of Triple in ItaniumMangle.cpp (PR #102469)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/102469 >From e5139d8079471ac6e6f0d76f36ed7ef593fff1b7 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Thu, 8 Aug 2024 09:57:03 -0400 Subject: [PATCH 1/2] [NFC] Remove unnecessary copy of Triple in ItaniumMangle.cpp --- clang/lib/AST/ItaniumMangle.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index dc317f2a7870b..976670d1efa56 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -2727,8 +2727,6 @@ void CXXNameMangler::mangleQualifiers(Qualifiers Quals, const DependentAddressSp //::= U //::= U -llvm::Triple Triple = getASTContext().getTargetInfo().getTriple(); - SmallString<64> ASString; LangAS AS = Quals.getAddressSpace(); @@ -2800,7 +2798,7 @@ void CXXNameMangler::mangleQualifiers(Qualifiers Quals, const DependentAddressSp // For z/OS, there are no special mangling rules applied to the ptr32 // qualifier. Ex: void foo(int * __ptr32 p) -> _Z3f2Pi. The mangling for // "p" is treated the same as a regular integer pointer. -if (!Triple.isOSzOS()) +if (!getASTContext().getTargetInfo().getTriple().isOSzOS()) ASString = "ptr32_uptr"; break; case LangAS::ptr64: >From f488d931227fb0f19d5237de7a68942680c66a0b Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Thu, 8 Aug 2024 10:05:50 -0400 Subject: [PATCH 2/2] fix another use as well --- clang/lib/Sema/SemaType.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 91c8f18648fa4..08020f9f88927 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -7057,7 +7057,6 @@ static bool handleMSPointerTypeQualifierAttr(TypeProcessingState &State, // Add address space to type based on its attributes. LangAS ASIdx = LangAS::Default; - llvm::Triple Triple = S.Context.getTargetInfo().getTriple(); uint64_t PtrWidth = S.Context.getTargetInfo().getPointerWidth(LangAS::Default); if (PtrWidth == 32) { @@ -7066,7 +7065,7 @@ static bool handleMSPointerTypeQualifierAttr(TypeProcessingState &State, else if (Attrs[attr::UPtr]) ASIdx = LangAS::ptr32_uptr; } else if (PtrWidth == 64 && Attrs[attr::Ptr32]) { -if (Triple.isOSzOS() || Attrs[attr::UPtr]) +if (S.Context.getTargetInfo().getTriple().isOSzOS() || Attrs[attr::UPtr]) ASIdx = LangAS::ptr32_uptr; else ASIdx = LangAS::ptr32_sptr; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] Remove unnecessary copy of Triples (PR #102469)
https://github.com/abhina-sree edited https://github.com/llvm/llvm-project/pull/102469 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] Remove unnecessary copy of Triples (PR #102469)
https://github.com/abhina-sree edited https://github.com/llvm/llvm-project/pull/102469 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] Remove unnecessary copy of Triples (PR #102469)
https://github.com/abhina-sree closed https://github.com/llvm/llvm-project/pull/102469 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SystemZ][z/OS] Implement z/OS XPLINK ABI (PR #101024)
@@ -532,9 +532,371 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const Type *Ty, return false; } +//===--===// +// z/OS XPLINK ABI Implementation +//===--===// + +namespace { + +class ZOSXPLinkABIInfo : public ABIInfo { + const unsigned GPRBits = 64; + bool HasVector; + +public: + ZOSXPLinkABIInfo(CodeGenTypes &CGT, bool HV) : ABIInfo(CGT), HasVector(HV) {} + + bool isPromotableIntegerType(QualType Ty) const; + bool isVectorArgumentType(QualType Ty) const; + bool isFPArgumentType(QualType Ty) const; + QualType getSingleElementType(QualType Ty) const; + QualType getFPTypeOfComplexLikeType(QualType Ty) const; + + ABIArgInfo classifyReturnType(QualType RetTy) const; + ABIArgInfo classifyArgumentType(QualType ArgTy, bool IsNamedArg) const; + + void computeInfo(CGFunctionInfo &FI) const override { +if (!getCXXABI().classifyReturnType(FI)) + FI.getReturnInfo() = classifyReturnType(FI.getReturnType()); + +unsigned NumRequiredArgs = FI.getNumRequiredArgs(); +unsigned ArgNo = 0; + +for (auto &I : FI.arguments()) { + bool IsNamedArg = ArgNo < NumRequiredArgs; + I.info = classifyArgumentType(I.type, IsNamedArg); + ++ArgNo; +} + } + + RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, + AggValueSlot Slot) const override; +}; + +class ZOSXPLinkTargetCodeGenInfo : public TargetCodeGenInfo { +public: + ZOSXPLinkTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector) + : TargetCodeGenInfo(std::make_unique(CGT, HasVector)) { +SwiftInfo = +std::make_unique(CGT, /*SwiftErrorInRegister=*/false); + } +}; + +} // namespace + +// Return true if the ABI requires Ty to be passed sign- or zero- +// extended to 64 bits. +bool ZOSXPLinkABIInfo::isPromotableIntegerType(QualType Ty) const { + // Treat an enum type as its underlying type. + if (const EnumType *EnumTy = Ty->getAs()) +Ty = EnumTy->getDecl()->getIntegerType(); + + // Promotable integer types are required to be promoted by the ABI. + if (getContext().isPromotableIntegerType(Ty)) +return true; + + if (const auto *EIT = Ty->getAs()) +if (EIT->getNumBits() < 64) + return true; + + // In addition to the usual promotable integer types, we also need to + // extend all 32-bit types, since the ABI requires promotion to 64 bits. + if (const BuiltinType *BT = Ty->getAs()) +switch (BT->getKind()) { +case BuiltinType::Int: +case BuiltinType::UInt: + return true; +default: + break; +} + + return false; +} + +bool ZOSXPLinkABIInfo::isVectorArgumentType(QualType Ty) const { + return (HasVector && Ty->isVectorType() && + getContext().getTypeSize(Ty) <= 128); +} + +bool ZOSXPLinkABIInfo::isFPArgumentType(QualType Ty) const { + if (const BuiltinType *BT = Ty->getAs()) +switch (BT->getKind()) { +case BuiltinType::Float: +case BuiltinType::Double: +case BuiltinType::LongDouble: + return true; +default: + return false; +} + + return false; +} + +QualType ZOSXPLinkABIInfo::getSingleElementType(QualType Ty) const { + // Unions just containing a floating point type, e.g. union { float f1, f2; }; + // are treated as a single floating point number. Check if the union only + // consists of a single type (handling embedded unions recursively), and + // return that type. + if (const RecordType *RT = Ty->getAsUnionType()) { +QualType Found; +// Check the fields. +const RecordDecl *RD = RT->getDecl(); +for (const auto *FD : RD->fields()) { + if (Found.isNull()) +Found = getSingleElementType(FD->getType()); + else if (Found != getSingleElementType(FD->getType())) +return Ty; +} +return Found.isNull() ? Ty : Found; + } + + const RecordType *RT = Ty->getAs(); + + if (RT && RT->isStructureOrClassType()) { +const RecordDecl *RD = RT->getDecl(); +QualType Found; + +// If this is a C++ record, check the bases first. +if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) + if (CXXRD->hasDefinition()) +for (const auto &I : CXXRD->bases()) { + QualType Base = I.getType(); + + // Empty bases don't affect things either way. + if (isEmptyRecord(getContext(), Base, true)) +continue; + + if (!Found.isNull()) +return Ty; + Found = getSingleElementType(Base); +} + +// Check the fields. +for (const auto *FD : RD->fields()) { + QualType FT = FD->getType(); + + // Ignore empty fields. + if (isEmptyField(getContext(), FD, true)) +continue; + + if (!Found.isNull()) +return Ty; + + // Treat single element arrays as the element. + while (const ConstantArrayType *AT = + getContext().getAsConstantArrayType(FT)) { +if (AT->getZEx
[clang] [SystemZ][z/OS] Add z/OS customization file (PR #111182)
https://github.com/abhina-sree approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/82 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [lldb] [llvm] Propagate IsText parameter to openFileForRead function (PR #110661)
abhina-sree wrote: > https://github.com/llvm/llvm-project/blob/main/clang/lib/Lex/PPDirectives.cpp#L3964-L3990 Yes I think we still require specifying the Text/Binary parameter based on the context of where it is called. I will look into adding the new virtual functions as an alternative solution https://github.com/llvm/llvm-project/pull/110661 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [lldb] [llvm] Propagate IsText parameter to openFileForRead function (PR #110661)
abhina-sree wrote: > The default is set to OF_Text instead of OF_None, this change in value does > not affect any other platforms other than z/OS. Setting this parameter > correctly is required to open files on z/OS in the correct encoding. The > IsText parameter is based on the context of where we open files, for example, > the embed directive requires that files always be opened in binary even > though they might be tagged as text. Thanks for your patience. I've put up this PR https://github.com/llvm/llvm-project/pull/111723 to implement your suggestion. I kept the IsText parameter in the getBufferForFile, getBufferForFileImpl because it already has other attributes like IsVolatile, RequiresNullTerminator but created a new virtual function for openFileForReadBinary which greatly reduces the number of files touched compared to this PR. The current `#embed` lit tests seem to work without additional changes but I will experiment with creating a testcase with inputs that are non-ascii to expose any issues https://github.com/llvm/llvm-project/pull/110661 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile (PR #111723)
@@ -302,6 +305,17 @@ class RealFileSystem : public FileSystem { return Storage; } + ErrorOr> openFileForRead(const Twine &Name, abhina-sree wrote: I don't think I'm able to mark it static because it calls adjustPath which is non-static https://github.com/llvm/llvm-project/pull/111723 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile (PR #111723)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/111723 >From 8443744a40bd1397155ea9d91fbe720a8826139d Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Wed, 9 Oct 2024 13:23:41 -0400 Subject: [PATCH 1/2] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile --- clang/include/clang/Basic/FileManager.h | 8 +++ clang/lib/Basic/FileManager.cpp | 12 +-- clang/lib/Lex/HeaderMap.cpp | 4 +++- clang/lib/Serialization/ASTReader.cpp | 3 ++- llvm/include/llvm/Support/VirtualFileSystem.h | 13 ++-- llvm/lib/Support/VirtualFileSystem.cpp| 21 +-- 6 files changed, 45 insertions(+), 16 deletions(-) diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index ce4e8c1fbe16eb..d987fb05a94a37 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -292,21 +292,21 @@ class FileManager : public RefCountedBase { /// MemoryBuffer if successful, otherwise returning null. llvm::ErrorOr> getBufferForFile(FileEntryRef Entry, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt); llvm::ErrorOr> getBufferForFile(StringRef Filename, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt) const { return getBufferForFileImpl(Filename, /*FileSize=*/MaybeLimit.value_or(-1), -isVolatile, RequiresNullTerminator); +isVolatile, RequiresNullTerminator, IsText); } private: llvm::ErrorOr> getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile, - bool RequiresNullTerminator) const; + bool RequiresNullTerminator, bool IsText) const; DirectoryEntry *&getRealDirEntry(const llvm::vfs::Status &Status); diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 6097b85a03064b..27075cefafdc2f 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -530,7 +530,7 @@ void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) { llvm::ErrorOr> FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, - bool RequiresNullTerminator, + bool RequiresNullTerminator, bool IsText, std::optional MaybeLimit) { const FileEntry *Entry = &FE.getFileEntry(); // If the content is living on the file entry, return a reference to it. @@ -558,21 +558,21 @@ FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, // Otherwise, open the file. return getBufferForFileImpl(Filename, FileSize, isVolatile, - RequiresNullTerminator); + RequiresNullTerminator, IsText); } llvm::ErrorOr> FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize, - bool isVolatile, - bool RequiresNullTerminator) const { + bool isVolatile, bool RequiresNullTerminator, + bool IsText) const { if (FileSystemOpts.WorkingDir.empty()) return FS->getBufferForFile(Filename, FileSize, RequiresNullTerminator, -isVolatile); +isVolatile, IsText); SmallString<128> FilePath(Filename); FixupRelativePath(FilePath); return FS->getBufferForFile(FilePath, FileSize, RequiresNullTerminator, - isVolatile); + isVolatile, IsText); } /// getStatValue - Get the 'stat' information for the specified path, diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 00bf880726ee3e..35c68b304a4523 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -54,7 +54,9 @@ std::unique_ptr HeaderMap::Create(FileEntryRef FE, FileManager &FM) { unsigned FileSize = FE.getSize(); if (FileSize <= sizeof(HMapHeader)) return nullptr; - auto FileBuffer = FM.getBufferForFile(FE); + auto FileBuffer = + FM.getBufferForFile(FE, /*IsVolatile=*/false, + /*RequiresNullTerminator=*/true, /*IsText=*/false); if (!FileBuffer || !*FileBuffer) return nullptr; bool NeedsByteSwap; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 5c4f8d0e9c46cd..769b85dc318072 100644 --- a/clang/lib/Serialization/A
[clang] [llvm] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile (PR #111723)
@@ -324,6 +330,17 @@ ErrorOr RealFileSystem::status(const Twine &Path) { ErrorOr> RealFileSystem::openFileForRead(const Twine &Name) { + SmallString<256> RealName, Storage; abhina-sree wrote: I've created a private function for both functions to call, thanks! https://github.com/llvm/llvm-project/pull/111723 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile (PR #111723)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/111723 >From c1676e48a587e10ba54c28e99192fd5e6a36f72e Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Wed, 9 Oct 2024 13:23:41 -0400 Subject: [PATCH] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile --- clang/include/clang/Basic/FileManager.h | 8 ++--- clang/lib/Basic/FileManager.cpp | 12 +++ clang/lib/Lex/HeaderMap.cpp | 4 ++- clang/lib/Serialization/ASTReader.cpp | 3 +- llvm/include/llvm/Support/VirtualFileSystem.h | 13 ++-- llvm/lib/Support/VirtualFileSystem.cpp| 31 +-- 6 files changed, 48 insertions(+), 23 deletions(-) diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index ce4e8c1fbe16eb..d987fb05a94a37 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -292,21 +292,21 @@ class FileManager : public RefCountedBase { /// MemoryBuffer if successful, otherwise returning null. llvm::ErrorOr> getBufferForFile(FileEntryRef Entry, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt); llvm::ErrorOr> getBufferForFile(StringRef Filename, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt) const { return getBufferForFileImpl(Filename, /*FileSize=*/MaybeLimit.value_or(-1), -isVolatile, RequiresNullTerminator); +isVolatile, RequiresNullTerminator, IsText); } private: llvm::ErrorOr> getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile, - bool RequiresNullTerminator) const; + bool RequiresNullTerminator, bool IsText) const; DirectoryEntry *&getRealDirEntry(const llvm::vfs::Status &Status); diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 6097b85a03064b..27075cefafdc2f 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -530,7 +530,7 @@ void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) { llvm::ErrorOr> FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, - bool RequiresNullTerminator, + bool RequiresNullTerminator, bool IsText, std::optional MaybeLimit) { const FileEntry *Entry = &FE.getFileEntry(); // If the content is living on the file entry, return a reference to it. @@ -558,21 +558,21 @@ FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, // Otherwise, open the file. return getBufferForFileImpl(Filename, FileSize, isVolatile, - RequiresNullTerminator); + RequiresNullTerminator, IsText); } llvm::ErrorOr> FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize, - bool isVolatile, - bool RequiresNullTerminator) const { + bool isVolatile, bool RequiresNullTerminator, + bool IsText) const { if (FileSystemOpts.WorkingDir.empty()) return FS->getBufferForFile(Filename, FileSize, RequiresNullTerminator, -isVolatile); +isVolatile, IsText); SmallString<128> FilePath(Filename); FixupRelativePath(FilePath); return FS->getBufferForFile(FilePath, FileSize, RequiresNullTerminator, - isVolatile); + isVolatile, IsText); } /// getStatValue - Get the 'stat' information for the specified path, diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 00bf880726ee3e..35c68b304a4523 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -54,7 +54,9 @@ std::unique_ptr HeaderMap::Create(FileEntryRef FE, FileManager &FM) { unsigned FileSize = FE.getSize(); if (FileSize <= sizeof(HMapHeader)) return nullptr; - auto FileBuffer = FM.getBufferForFile(FE); + auto FileBuffer = + FM.getBufferForFile(FE, /*IsVolatile=*/false, + /*RequiresNullTerminator=*/true, /*IsText=*/false); if (!FileBuffer || !*FileBuffer) return nullptr; bool NeedsByteSwap; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 5c4f8d0e9c46cd..769b85dc318072 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++
[clang] [llvm] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile (PR #111723)
@@ -117,8 +117,12 @@ FileSystem::~FileSystem() = default; ErrorOr> FileSystem::getBufferForFile(const llvm::Twine &Name, int64_t FileSize, - bool RequiresNullTerminator, bool IsVolatile) { - auto F = openFileForRead(Name); + bool RequiresNullTerminator, bool IsVolatile, + bool IsText) { + auto openFileFunctionPointer = &FileSystem::openFileForRead; + if (!IsText) +openFileFunctionPointer = &FileSystem::openFileForReadBinary; abhina-sree wrote: Thanks this is done https://github.com/llvm/llvm-project/pull/111723 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile (PR #111723)
https://github.com/abhina-sree created https://github.com/llvm/llvm-project/pull/111723 This patch adds an IsText parameter to the following getBufferForFile, getBufferForFileImpl. We introduce a new virtual function openFileForReadBinary which defaults to openFileForRead except in RealFileSystem which uses the OF_None flag instead of OF_Text. The default is set to OF_Text instead of OF_None, this change in value does not affect any other platforms other than z/OS. Setting this parameter correctly is required to open files on z/OS in the correct encoding. The IsText parameter is based on the context of where we open files, for example, in the ASTReader, HeaderMap requires that files always be opened in binary even though they might be tagged as text. >From 8443744a40bd1397155ea9d91fbe720a8826139d Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Wed, 9 Oct 2024 13:23:41 -0400 Subject: [PATCH] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile --- clang/include/clang/Basic/FileManager.h | 8 +++ clang/lib/Basic/FileManager.cpp | 12 +-- clang/lib/Lex/HeaderMap.cpp | 4 +++- clang/lib/Serialization/ASTReader.cpp | 3 ++- llvm/include/llvm/Support/VirtualFileSystem.h | 13 ++-- llvm/lib/Support/VirtualFileSystem.cpp| 21 +-- 6 files changed, 45 insertions(+), 16 deletions(-) diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index ce4e8c1fbe16eb..d987fb05a94a37 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -292,21 +292,21 @@ class FileManager : public RefCountedBase { /// MemoryBuffer if successful, otherwise returning null. llvm::ErrorOr> getBufferForFile(FileEntryRef Entry, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt); llvm::ErrorOr> getBufferForFile(StringRef Filename, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt) const { return getBufferForFileImpl(Filename, /*FileSize=*/MaybeLimit.value_or(-1), -isVolatile, RequiresNullTerminator); +isVolatile, RequiresNullTerminator, IsText); } private: llvm::ErrorOr> getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile, - bool RequiresNullTerminator) const; + bool RequiresNullTerminator, bool IsText) const; DirectoryEntry *&getRealDirEntry(const llvm::vfs::Status &Status); diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 6097b85a03064b..27075cefafdc2f 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -530,7 +530,7 @@ void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) { llvm::ErrorOr> FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, - bool RequiresNullTerminator, + bool RequiresNullTerminator, bool IsText, std::optional MaybeLimit) { const FileEntry *Entry = &FE.getFileEntry(); // If the content is living on the file entry, return a reference to it. @@ -558,21 +558,21 @@ FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, // Otherwise, open the file. return getBufferForFileImpl(Filename, FileSize, isVolatile, - RequiresNullTerminator); + RequiresNullTerminator, IsText); } llvm::ErrorOr> FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize, - bool isVolatile, - bool RequiresNullTerminator) const { + bool isVolatile, bool RequiresNullTerminator, + bool IsText) const { if (FileSystemOpts.WorkingDir.empty()) return FS->getBufferForFile(Filename, FileSize, RequiresNullTerminator, -isVolatile); +isVolatile, IsText); SmallString<128> FilePath(Filename); FixupRelativePath(FilePath); return FS->getBufferForFile(FilePath, FileSize, RequiresNullTerminator, - isVolatile); + isVolatile, IsText); } /// getStatValue - Get the 'stat' information for the specified path, diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 00bf880726ee3e..35c68b304a4523 100644 --- a/clang/lib/Le
[clang] [llvm] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile (PR #111723)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/111723 >From c1676e48a587e10ba54c28e99192fd5e6a36f72e Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Wed, 9 Oct 2024 13:23:41 -0400 Subject: [PATCH 1/2] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile --- clang/include/clang/Basic/FileManager.h | 8 ++--- clang/lib/Basic/FileManager.cpp | 12 +++ clang/lib/Lex/HeaderMap.cpp | 4 ++- clang/lib/Serialization/ASTReader.cpp | 3 +- llvm/include/llvm/Support/VirtualFileSystem.h | 13 ++-- llvm/lib/Support/VirtualFileSystem.cpp| 31 +-- 6 files changed, 48 insertions(+), 23 deletions(-) diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index ce4e8c1fbe16eb..d987fb05a94a37 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -292,21 +292,21 @@ class FileManager : public RefCountedBase { /// MemoryBuffer if successful, otherwise returning null. llvm::ErrorOr> getBufferForFile(FileEntryRef Entry, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt); llvm::ErrorOr> getBufferForFile(StringRef Filename, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt) const { return getBufferForFileImpl(Filename, /*FileSize=*/MaybeLimit.value_or(-1), -isVolatile, RequiresNullTerminator); +isVolatile, RequiresNullTerminator, IsText); } private: llvm::ErrorOr> getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile, - bool RequiresNullTerminator) const; + bool RequiresNullTerminator, bool IsText) const; DirectoryEntry *&getRealDirEntry(const llvm::vfs::Status &Status); diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 6097b85a03064b..27075cefafdc2f 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -530,7 +530,7 @@ void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) { llvm::ErrorOr> FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, - bool RequiresNullTerminator, + bool RequiresNullTerminator, bool IsText, std::optional MaybeLimit) { const FileEntry *Entry = &FE.getFileEntry(); // If the content is living on the file entry, return a reference to it. @@ -558,21 +558,21 @@ FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, // Otherwise, open the file. return getBufferForFileImpl(Filename, FileSize, isVolatile, - RequiresNullTerminator); + RequiresNullTerminator, IsText); } llvm::ErrorOr> FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize, - bool isVolatile, - bool RequiresNullTerminator) const { + bool isVolatile, bool RequiresNullTerminator, + bool IsText) const { if (FileSystemOpts.WorkingDir.empty()) return FS->getBufferForFile(Filename, FileSize, RequiresNullTerminator, -isVolatile); +isVolatile, IsText); SmallString<128> FilePath(Filename); FixupRelativePath(FilePath); return FS->getBufferForFile(FilePath, FileSize, RequiresNullTerminator, - isVolatile); + isVolatile, IsText); } /// getStatValue - Get the 'stat' information for the specified path, diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 00bf880726ee3e..35c68b304a4523 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -54,7 +54,9 @@ std::unique_ptr HeaderMap::Create(FileEntryRef FE, FileManager &FM) { unsigned FileSize = FE.getSize(); if (FileSize <= sizeof(HMapHeader)) return nullptr; - auto FileBuffer = FM.getBufferForFile(FE); + auto FileBuffer = + FM.getBufferForFile(FE, /*IsVolatile=*/false, + /*RequiresNullTerminator=*/true, /*IsText=*/false); if (!FileBuffer || !*FileBuffer) return nullptr; bool NeedsByteSwap; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 5c4f8d0e9c46cd..769b85dc318072 100644 --- a/clang/lib/Serialization/ASTReader.cpp
[clang] [llvm] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile (PR #111723)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/111723 >From c1676e48a587e10ba54c28e99192fd5e6a36f72e Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Wed, 9 Oct 2024 13:23:41 -0400 Subject: [PATCH 1/2] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile --- clang/include/clang/Basic/FileManager.h | 8 ++--- clang/lib/Basic/FileManager.cpp | 12 +++ clang/lib/Lex/HeaderMap.cpp | 4 ++- clang/lib/Serialization/ASTReader.cpp | 3 +- llvm/include/llvm/Support/VirtualFileSystem.h | 13 ++-- llvm/lib/Support/VirtualFileSystem.cpp| 31 +-- 6 files changed, 48 insertions(+), 23 deletions(-) diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index ce4e8c1fbe16eb..d987fb05a94a37 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -292,21 +292,21 @@ class FileManager : public RefCountedBase { /// MemoryBuffer if successful, otherwise returning null. llvm::ErrorOr> getBufferForFile(FileEntryRef Entry, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt); llvm::ErrorOr> getBufferForFile(StringRef Filename, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt) const { return getBufferForFileImpl(Filename, /*FileSize=*/MaybeLimit.value_or(-1), -isVolatile, RequiresNullTerminator); +isVolatile, RequiresNullTerminator, IsText); } private: llvm::ErrorOr> getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile, - bool RequiresNullTerminator) const; + bool RequiresNullTerminator, bool IsText) const; DirectoryEntry *&getRealDirEntry(const llvm::vfs::Status &Status); diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 6097b85a03064b..27075cefafdc2f 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -530,7 +530,7 @@ void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) { llvm::ErrorOr> FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, - bool RequiresNullTerminator, + bool RequiresNullTerminator, bool IsText, std::optional MaybeLimit) { const FileEntry *Entry = &FE.getFileEntry(); // If the content is living on the file entry, return a reference to it. @@ -558,21 +558,21 @@ FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, // Otherwise, open the file. return getBufferForFileImpl(Filename, FileSize, isVolatile, - RequiresNullTerminator); + RequiresNullTerminator, IsText); } llvm::ErrorOr> FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize, - bool isVolatile, - bool RequiresNullTerminator) const { + bool isVolatile, bool RequiresNullTerminator, + bool IsText) const { if (FileSystemOpts.WorkingDir.empty()) return FS->getBufferForFile(Filename, FileSize, RequiresNullTerminator, -isVolatile); +isVolatile, IsText); SmallString<128> FilePath(Filename); FixupRelativePath(FilePath); return FS->getBufferForFile(FilePath, FileSize, RequiresNullTerminator, - isVolatile); + isVolatile, IsText); } /// getStatValue - Get the 'stat' information for the specified path, diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 00bf880726ee3e..35c68b304a4523 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -54,7 +54,9 @@ std::unique_ptr HeaderMap::Create(FileEntryRef FE, FileManager &FM) { unsigned FileSize = FE.getSize(); if (FileSize <= sizeof(HMapHeader)) return nullptr; - auto FileBuffer = FM.getBufferForFile(FE); + auto FileBuffer = + FM.getBufferForFile(FE, /*IsVolatile=*/false, + /*RequiresNullTerminator=*/true, /*IsText=*/false); if (!FileBuffer || !*FileBuffer) return nullptr; bool NeedsByteSwap; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 5c4f8d0e9c46cd..769b85dc318072 100644 --- a/clang/lib/Serialization/ASTReader.cpp
[clang] [llvm] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile (PR #111723)
abhina-sree wrote: > @abhina-sree do you plan to modify embed in this PR? Actually Sean has pointed out that if we pass in non-ascii inputs, the tests do in fact fail. So I will look into passing the IsText parameter in the necessary functions. Thanks for pointing this out! https://github.com/llvm/llvm-project/pull/111723 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile (PR #111723)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/111723 >From c1676e48a587e10ba54c28e99192fd5e6a36f72e Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Wed, 9 Oct 2024 13:23:41 -0400 Subject: [PATCH 1/3] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile --- clang/include/clang/Basic/FileManager.h | 8 ++--- clang/lib/Basic/FileManager.cpp | 12 +++ clang/lib/Lex/HeaderMap.cpp | 4 ++- clang/lib/Serialization/ASTReader.cpp | 3 +- llvm/include/llvm/Support/VirtualFileSystem.h | 13 ++-- llvm/lib/Support/VirtualFileSystem.cpp| 31 +-- 6 files changed, 48 insertions(+), 23 deletions(-) diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index ce4e8c1fbe16eb..d987fb05a94a37 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -292,21 +292,21 @@ class FileManager : public RefCountedBase { /// MemoryBuffer if successful, otherwise returning null. llvm::ErrorOr> getBufferForFile(FileEntryRef Entry, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt); llvm::ErrorOr> getBufferForFile(StringRef Filename, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt) const { return getBufferForFileImpl(Filename, /*FileSize=*/MaybeLimit.value_or(-1), -isVolatile, RequiresNullTerminator); +isVolatile, RequiresNullTerminator, IsText); } private: llvm::ErrorOr> getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile, - bool RequiresNullTerminator) const; + bool RequiresNullTerminator, bool IsText) const; DirectoryEntry *&getRealDirEntry(const llvm::vfs::Status &Status); diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 6097b85a03064b..27075cefafdc2f 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -530,7 +530,7 @@ void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) { llvm::ErrorOr> FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, - bool RequiresNullTerminator, + bool RequiresNullTerminator, bool IsText, std::optional MaybeLimit) { const FileEntry *Entry = &FE.getFileEntry(); // If the content is living on the file entry, return a reference to it. @@ -558,21 +558,21 @@ FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, // Otherwise, open the file. return getBufferForFileImpl(Filename, FileSize, isVolatile, - RequiresNullTerminator); + RequiresNullTerminator, IsText); } llvm::ErrorOr> FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize, - bool isVolatile, - bool RequiresNullTerminator) const { + bool isVolatile, bool RequiresNullTerminator, + bool IsText) const { if (FileSystemOpts.WorkingDir.empty()) return FS->getBufferForFile(Filename, FileSize, RequiresNullTerminator, -isVolatile); +isVolatile, IsText); SmallString<128> FilePath(Filename); FixupRelativePath(FilePath); return FS->getBufferForFile(FilePath, FileSize, RequiresNullTerminator, - isVolatile); + isVolatile, IsText); } /// getStatValue - Get the 'stat' information for the specified path, diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 00bf880726ee3e..35c68b304a4523 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -54,7 +54,9 @@ std::unique_ptr HeaderMap::Create(FileEntryRef FE, FileManager &FM) { unsigned FileSize = FE.getSize(); if (FileSize <= sizeof(HMapHeader)) return nullptr; - auto FileBuffer = FM.getBufferForFile(FE); + auto FileBuffer = + FM.getBufferForFile(FE, /*IsVolatile=*/false, + /*RequiresNullTerminator=*/true, /*IsText=*/false); if (!FileBuffer || !*FileBuffer) return nullptr; bool NeedsByteSwap; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 5c4f8d0e9c46cd..769b85dc318072 100644 --- a/clang/lib/Serialization/ASTReader.cpp
[clang] [llvm] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile (PR #111723)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/111723 >From c1676e48a587e10ba54c28e99192fd5e6a36f72e Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Wed, 9 Oct 2024 13:23:41 -0400 Subject: [PATCH 1/2] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile --- clang/include/clang/Basic/FileManager.h | 8 ++--- clang/lib/Basic/FileManager.cpp | 12 +++ clang/lib/Lex/HeaderMap.cpp | 4 ++- clang/lib/Serialization/ASTReader.cpp | 3 +- llvm/include/llvm/Support/VirtualFileSystem.h | 13 ++-- llvm/lib/Support/VirtualFileSystem.cpp| 31 +-- 6 files changed, 48 insertions(+), 23 deletions(-) diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index ce4e8c1fbe16eb..d987fb05a94a37 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -292,21 +292,21 @@ class FileManager : public RefCountedBase { /// MemoryBuffer if successful, otherwise returning null. llvm::ErrorOr> getBufferForFile(FileEntryRef Entry, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt); llvm::ErrorOr> getBufferForFile(StringRef Filename, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt) const { return getBufferForFileImpl(Filename, /*FileSize=*/MaybeLimit.value_or(-1), -isVolatile, RequiresNullTerminator); +isVolatile, RequiresNullTerminator, IsText); } private: llvm::ErrorOr> getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile, - bool RequiresNullTerminator) const; + bool RequiresNullTerminator, bool IsText) const; DirectoryEntry *&getRealDirEntry(const llvm::vfs::Status &Status); diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 6097b85a03064b..27075cefafdc2f 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -530,7 +530,7 @@ void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) { llvm::ErrorOr> FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, - bool RequiresNullTerminator, + bool RequiresNullTerminator, bool IsText, std::optional MaybeLimit) { const FileEntry *Entry = &FE.getFileEntry(); // If the content is living on the file entry, return a reference to it. @@ -558,21 +558,21 @@ FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, // Otherwise, open the file. return getBufferForFileImpl(Filename, FileSize, isVolatile, - RequiresNullTerminator); + RequiresNullTerminator, IsText); } llvm::ErrorOr> FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize, - bool isVolatile, - bool RequiresNullTerminator) const { + bool isVolatile, bool RequiresNullTerminator, + bool IsText) const { if (FileSystemOpts.WorkingDir.empty()) return FS->getBufferForFile(Filename, FileSize, RequiresNullTerminator, -isVolatile); +isVolatile, IsText); SmallString<128> FilePath(Filename); FixupRelativePath(FilePath); return FS->getBufferForFile(FilePath, FileSize, RequiresNullTerminator, - isVolatile); + isVolatile, IsText); } /// getStatValue - Get the 'stat' information for the specified path, diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 00bf880726ee3e..35c68b304a4523 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -54,7 +54,9 @@ std::unique_ptr HeaderMap::Create(FileEntryRef FE, FileManager &FM) { unsigned FileSize = FE.getSize(); if (FileSize <= sizeof(HMapHeader)) return nullptr; - auto FileBuffer = FM.getBufferForFile(FE); + auto FileBuffer = + FM.getBufferForFile(FE, /*IsVolatile=*/false, + /*RequiresNullTerminator=*/true, /*IsText=*/false); if (!FileBuffer || !*FileBuffer) return nullptr; bool NeedsByteSwap; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 5c4f8d0e9c46cd..769b85dc318072 100644 --- a/clang/lib/Serialization/ASTReader.cpp
[clang] [llvm] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile (PR #111723)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/111723 >From c1676e48a587e10ba54c28e99192fd5e6a36f72e Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Wed, 9 Oct 2024 13:23:41 -0400 Subject: [PATCH 1/3] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile --- clang/include/clang/Basic/FileManager.h | 8 ++--- clang/lib/Basic/FileManager.cpp | 12 +++ clang/lib/Lex/HeaderMap.cpp | 4 ++- clang/lib/Serialization/ASTReader.cpp | 3 +- llvm/include/llvm/Support/VirtualFileSystem.h | 13 ++-- llvm/lib/Support/VirtualFileSystem.cpp| 31 +-- 6 files changed, 48 insertions(+), 23 deletions(-) diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index ce4e8c1fbe16eb..d987fb05a94a37 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -292,21 +292,21 @@ class FileManager : public RefCountedBase { /// MemoryBuffer if successful, otherwise returning null. llvm::ErrorOr> getBufferForFile(FileEntryRef Entry, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt); llvm::ErrorOr> getBufferForFile(StringRef Filename, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt) const { return getBufferForFileImpl(Filename, /*FileSize=*/MaybeLimit.value_or(-1), -isVolatile, RequiresNullTerminator); +isVolatile, RequiresNullTerminator, IsText); } private: llvm::ErrorOr> getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile, - bool RequiresNullTerminator) const; + bool RequiresNullTerminator, bool IsText) const; DirectoryEntry *&getRealDirEntry(const llvm::vfs::Status &Status); diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 6097b85a03064b..27075cefafdc2f 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -530,7 +530,7 @@ void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) { llvm::ErrorOr> FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, - bool RequiresNullTerminator, + bool RequiresNullTerminator, bool IsText, std::optional MaybeLimit) { const FileEntry *Entry = &FE.getFileEntry(); // If the content is living on the file entry, return a reference to it. @@ -558,21 +558,21 @@ FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, // Otherwise, open the file. return getBufferForFileImpl(Filename, FileSize, isVolatile, - RequiresNullTerminator); + RequiresNullTerminator, IsText); } llvm::ErrorOr> FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize, - bool isVolatile, - bool RequiresNullTerminator) const { + bool isVolatile, bool RequiresNullTerminator, + bool IsText) const { if (FileSystemOpts.WorkingDir.empty()) return FS->getBufferForFile(Filename, FileSize, RequiresNullTerminator, -isVolatile); +isVolatile, IsText); SmallString<128> FilePath(Filename); FixupRelativePath(FilePath); return FS->getBufferForFile(FilePath, FileSize, RequiresNullTerminator, - isVolatile); + isVolatile, IsText); } /// getStatValue - Get the 'stat' information for the specified path, diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 00bf880726ee3e..35c68b304a4523 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -54,7 +54,9 @@ std::unique_ptr HeaderMap::Create(FileEntryRef FE, FileManager &FM) { unsigned FileSize = FE.getSize(); if (FileSize <= sizeof(HMapHeader)) return nullptr; - auto FileBuffer = FM.getBufferForFile(FE); + auto FileBuffer = + FM.getBufferForFile(FE, /*IsVolatile=*/false, + /*RequiresNullTerminator=*/true, /*IsText=*/false); if (!FileBuffer || !*FileBuffer) return nullptr; bool NeedsByteSwap; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 5c4f8d0e9c46cd..769b85dc318072 100644 --- a/clang/lib/Serialization/ASTReader.cpp
[clang] [llvm] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile (PR #111723)
abhina-sree wrote: @cor3ntin, I've added support for #embed handling now, I've added a z/OS only testcase clang/test/Preprocessor/embed_zos.c which is a copy of clang/test/Preprocessor/embed_art.c except it changes the file tag to be non-ascii which is now working with the latest commit. https://github.com/llvm/llvm-project/pull/111723 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile (PR #111723)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/111723 >From c1676e48a587e10ba54c28e99192fd5e6a36f72e Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Wed, 9 Oct 2024 13:23:41 -0400 Subject: [PATCH 1/3] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile --- clang/include/clang/Basic/FileManager.h | 8 ++--- clang/lib/Basic/FileManager.cpp | 12 +++ clang/lib/Lex/HeaderMap.cpp | 4 ++- clang/lib/Serialization/ASTReader.cpp | 3 +- llvm/include/llvm/Support/VirtualFileSystem.h | 13 ++-- llvm/lib/Support/VirtualFileSystem.cpp| 31 +-- 6 files changed, 48 insertions(+), 23 deletions(-) diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index ce4e8c1fbe16eb..d987fb05a94a37 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -292,21 +292,21 @@ class FileManager : public RefCountedBase { /// MemoryBuffer if successful, otherwise returning null. llvm::ErrorOr> getBufferForFile(FileEntryRef Entry, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt); llvm::ErrorOr> getBufferForFile(StringRef Filename, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt) const { return getBufferForFileImpl(Filename, /*FileSize=*/MaybeLimit.value_or(-1), -isVolatile, RequiresNullTerminator); +isVolatile, RequiresNullTerminator, IsText); } private: llvm::ErrorOr> getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile, - bool RequiresNullTerminator) const; + bool RequiresNullTerminator, bool IsText) const; DirectoryEntry *&getRealDirEntry(const llvm::vfs::Status &Status); diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 6097b85a03064b..27075cefafdc2f 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -530,7 +530,7 @@ void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) { llvm::ErrorOr> FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, - bool RequiresNullTerminator, + bool RequiresNullTerminator, bool IsText, std::optional MaybeLimit) { const FileEntry *Entry = &FE.getFileEntry(); // If the content is living on the file entry, return a reference to it. @@ -558,21 +558,21 @@ FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, // Otherwise, open the file. return getBufferForFileImpl(Filename, FileSize, isVolatile, - RequiresNullTerminator); + RequiresNullTerminator, IsText); } llvm::ErrorOr> FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize, - bool isVolatile, - bool RequiresNullTerminator) const { + bool isVolatile, bool RequiresNullTerminator, + bool IsText) const { if (FileSystemOpts.WorkingDir.empty()) return FS->getBufferForFile(Filename, FileSize, RequiresNullTerminator, -isVolatile); +isVolatile, IsText); SmallString<128> FilePath(Filename); FixupRelativePath(FilePath); return FS->getBufferForFile(FilePath, FileSize, RequiresNullTerminator, - isVolatile); + isVolatile, IsText); } /// getStatValue - Get the 'stat' information for the specified path, diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 00bf880726ee3e..35c68b304a4523 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -54,7 +54,9 @@ std::unique_ptr HeaderMap::Create(FileEntryRef FE, FileManager &FM) { unsigned FileSize = FE.getSize(); if (FileSize <= sizeof(HMapHeader)) return nullptr; - auto FileBuffer = FM.getBufferForFile(FE); + auto FileBuffer = + FM.getBufferForFile(FE, /*IsVolatile=*/false, + /*RequiresNullTerminator=*/true, /*IsText=*/false); if (!FileBuffer || !*FileBuffer) return nullptr; bool NeedsByteSwap; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 5c4f8d0e9c46cd..769b85dc318072 100644 --- a/clang/lib/Serialization/ASTReader.cpp
[clang] [llvm] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile (PR #111723)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/111723 >From c1676e48a587e10ba54c28e99192fd5e6a36f72e Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Wed, 9 Oct 2024 13:23:41 -0400 Subject: [PATCH 1/3] [SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile --- clang/include/clang/Basic/FileManager.h | 8 ++--- clang/lib/Basic/FileManager.cpp | 12 +++ clang/lib/Lex/HeaderMap.cpp | 4 ++- clang/lib/Serialization/ASTReader.cpp | 3 +- llvm/include/llvm/Support/VirtualFileSystem.h | 13 ++-- llvm/lib/Support/VirtualFileSystem.cpp| 31 +-- 6 files changed, 48 insertions(+), 23 deletions(-) diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index ce4e8c1fbe16eb..d987fb05a94a37 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -292,21 +292,21 @@ class FileManager : public RefCountedBase { /// MemoryBuffer if successful, otherwise returning null. llvm::ErrorOr> getBufferForFile(FileEntryRef Entry, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt); llvm::ErrorOr> getBufferForFile(StringRef Filename, bool isVolatile = false, - bool RequiresNullTerminator = true, + bool RequiresNullTerminator = true, bool IsText = true, std::optional MaybeLimit = std::nullopt) const { return getBufferForFileImpl(Filename, /*FileSize=*/MaybeLimit.value_or(-1), -isVolatile, RequiresNullTerminator); +isVolatile, RequiresNullTerminator, IsText); } private: llvm::ErrorOr> getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile, - bool RequiresNullTerminator) const; + bool RequiresNullTerminator, bool IsText) const; DirectoryEntry *&getRealDirEntry(const llvm::vfs::Status &Status); diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 6097b85a03064b..27075cefafdc2f 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -530,7 +530,7 @@ void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) { llvm::ErrorOr> FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, - bool RequiresNullTerminator, + bool RequiresNullTerminator, bool IsText, std::optional MaybeLimit) { const FileEntry *Entry = &FE.getFileEntry(); // If the content is living on the file entry, return a reference to it. @@ -558,21 +558,21 @@ FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, // Otherwise, open the file. return getBufferForFileImpl(Filename, FileSize, isVolatile, - RequiresNullTerminator); + RequiresNullTerminator, IsText); } llvm::ErrorOr> FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize, - bool isVolatile, - bool RequiresNullTerminator) const { + bool isVolatile, bool RequiresNullTerminator, + bool IsText) const { if (FileSystemOpts.WorkingDir.empty()) return FS->getBufferForFile(Filename, FileSize, RequiresNullTerminator, -isVolatile); +isVolatile, IsText); SmallString<128> FilePath(Filename); FixupRelativePath(FilePath); return FS->getBufferForFile(FilePath, FileSize, RequiresNullTerminator, - isVolatile); + isVolatile, IsText); } /// getStatValue - Get the 'stat' information for the specified path, diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 00bf880726ee3e..35c68b304a4523 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -54,7 +54,9 @@ std::unique_ptr HeaderMap::Create(FileEntryRef FE, FileManager &FM) { unsigned FileSize = FE.getSize(); if (FileSize <= sizeof(HMapHeader)) return nullptr; - auto FileBuffer = FM.getBufferForFile(FE); + auto FileBuffer = + FM.getBufferForFile(FE, /*IsVolatile=*/false, + /*RequiresNullTerminator=*/true, /*IsText=*/false); if (!FileBuffer || !*FileBuffer) return nullptr; bool NeedsByteSwap; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 5c4f8d0e9c46cd..769b85dc318072 100644 --- a/clang/lib/Serialization/ASTReader.cpp
[clang] Use the XL pragma pack semantics on z/OS (PR #111053)
https://github.com/abhina-sree approved this pull request. LGTM, can we add [SystemZ][z/OS] in the title to make it consistent with other PRs https://github.com/llvm/llvm-project/pull/111053 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits