[clang] [llvm] [driver] Make --version show if assertions, etc. are enabled (PR #87585)
https://github.com/porglezomp closed https://github.com/llvm/llvm-project/pull/87585 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [driver] Make --version show if assertions, etc. are enabled (PR #87585)
https://github.com/porglezomp updated https://github.com/llvm/llvm-project/pull/87585 >From a104ff0a445dfe5c6e6cfcf3734f6c0942eca082 Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Thu, 28 Mar 2024 13:58:19 -0700 Subject: [PATCH 01/10] [driver] Make --version show if assertions, etc. are enabled It's useful to have some significant build options visible in the version when investigating problems with a specific compiler artifact. This makes it easy to see if assertions, expensive checks, sanitizers, etc. are enabled when checking a compiler version. --- clang/lib/Driver/Driver.cpp | 38 + clang/test/Driver/version-build-config.test | 6 2 files changed, 44 insertions(+) create mode 100644 clang/test/Driver/version-build-config.test diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 7a53764364ce4d..37180efb7ea67b 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -2002,6 +2002,44 @@ void Driver::PrintVersion(const Compilation , raw_ostream ) const { // Print out the install directory. OS << "InstalledDir: " << Dir << '\n'; + // Print out build configuration options that impact the compiler's runtime + // behavior. Intended for identifying the source of issues when reproducing + // changes. + std::vector BuildOptions = { +#if !__OPTIMIZE__ + "+unoptimized", +#endif +#ifndef NDEBUG + "+assertions", +#endif +#ifdef EXPENSIVE_CHECKS + "+expensive-checks", +#endif +#if __has_feature(address_sanitizer) + "+asan", +#endif +#if __has_feature(undefined_behavior_sanitizer) + "+ubsan", +#endif +#if __has_feature(memory_sanitizer) + "+msan", +#endif +#if __has_feature(dataflow_sanitizer) + "+dfsan", +#endif + }; + if (!BuildOptions.empty()) { +OS << "Build configuration: "; +bool FirstOption = true; +for (const auto : BuildOptions) { + if (!FirstOption) +OS << ", "; + OS << Option; + FirstOption = false; +} +OS << '\n'; + } + // If configuration files were used, print their paths. for (auto ConfigFile : ConfigFiles) OS << "Configuration file: " << ConfigFile << '\n'; diff --git a/clang/test/Driver/version-build-config.test b/clang/test/Driver/version-build-config.test new file mode 100644 index 00..3d183f372908ea --- /dev/null +++ b/clang/test/Driver/version-build-config.test @@ -0,0 +1,6 @@ +# REQUIRES: asserts +# RUN: %clang --version 2>&1 | FileCheck %s + +# CHECK: clang version +# When assertions are enabled, we should have a build configuration line that reflects that +# CHECK: Build configuration: {{.*}}+assertions >From efc90ba92c29f1cd14f508f56a82a1f03f960401 Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Wed, 3 Apr 2024 22:01:39 -0700 Subject: [PATCH 02/10] Address review feedback --- clang/lib/Driver/Driver.cpp | 31 ++- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 37180efb7ea67b..680c58e4ea43d8 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -2005,38 +2005,35 @@ void Driver::PrintVersion(const Compilation , raw_ostream ) const { // Print out build configuration options that impact the compiler's runtime // behavior. Intended for identifying the source of issues when reproducing // changes. - std::vector BuildOptions = { -#if !__OPTIMIZE__ - "+unoptimized", + SmallVector BuildOptions = { +#if __GNUC__ && !__OPTIMIZE__ +// FIXME: __OPTIMIZE__ is not available on MSVC, this will never show there +"+unoptimized", #endif #ifndef NDEBUG - "+assertions", +"+assertions", #endif #ifdef EXPENSIVE_CHECKS - "+expensive-checks", +"+expensive-checks", #endif #if __has_feature(address_sanitizer) - "+asan", +"+asan", #endif #if __has_feature(undefined_behavior_sanitizer) - "+ubsan", +"+ubsan", #endif #if __has_feature(memory_sanitizer) - "+msan", +"+msan", #endif #if __has_feature(dataflow_sanitizer) - "+dfsan", +"+dfsan", #endif }; if (!BuildOptions.empty()) { -OS << "Build configuration: "; -bool FirstOption = true; -for (const auto : BuildOptions) { - if (!FirstOption) -OS << ", "; - OS << Option; - FirstOption = false; -} +OS << "Build config: "; +llvm::interleaveComma(BuildOptions, OS, [](const StringRef ) { +OS << Option; +}); OS << '\n'; } >From 1213ba2f965a0577fc6504e967ae17346da4ef4f Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Wed, 3 Apr 2024 22:02:19 -0700 Subject: [PATCH 03/10] Move LLVM_IS_DEBUG_BUILD into Support/CommandLine.h Allow us to reuse this logic in the feature printing. --- clang/lib/Driver/Driver.cpp | 3 +-- llvm/include/llvm/Support/CommandLine.h | 22 ++ llvm/lib/Support/CommandLine.cpp| 22 --
[clang] [llvm] [driver] Make --version show if assertions, etc. are enabled (PR #87585)
https://github.com/porglezomp updated https://github.com/llvm/llvm-project/pull/87585 >From a104ff0a445dfe5c6e6cfcf3734f6c0942eca082 Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Thu, 28 Mar 2024 13:58:19 -0700 Subject: [PATCH 1/9] [driver] Make --version show if assertions, etc. are enabled It's useful to have some significant build options visible in the version when investigating problems with a specific compiler artifact. This makes it easy to see if assertions, expensive checks, sanitizers, etc. are enabled when checking a compiler version. --- clang/lib/Driver/Driver.cpp | 38 + clang/test/Driver/version-build-config.test | 6 2 files changed, 44 insertions(+) create mode 100644 clang/test/Driver/version-build-config.test diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 7a53764364ce4d..37180efb7ea67b 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -2002,6 +2002,44 @@ void Driver::PrintVersion(const Compilation , raw_ostream ) const { // Print out the install directory. OS << "InstalledDir: " << Dir << '\n'; + // Print out build configuration options that impact the compiler's runtime + // behavior. Intended for identifying the source of issues when reproducing + // changes. + std::vector BuildOptions = { +#if !__OPTIMIZE__ + "+unoptimized", +#endif +#ifndef NDEBUG + "+assertions", +#endif +#ifdef EXPENSIVE_CHECKS + "+expensive-checks", +#endif +#if __has_feature(address_sanitizer) + "+asan", +#endif +#if __has_feature(undefined_behavior_sanitizer) + "+ubsan", +#endif +#if __has_feature(memory_sanitizer) + "+msan", +#endif +#if __has_feature(dataflow_sanitizer) + "+dfsan", +#endif + }; + if (!BuildOptions.empty()) { +OS << "Build configuration: "; +bool FirstOption = true; +for (const auto : BuildOptions) { + if (!FirstOption) +OS << ", "; + OS << Option; + FirstOption = false; +} +OS << '\n'; + } + // If configuration files were used, print their paths. for (auto ConfigFile : ConfigFiles) OS << "Configuration file: " << ConfigFile << '\n'; diff --git a/clang/test/Driver/version-build-config.test b/clang/test/Driver/version-build-config.test new file mode 100644 index 00..3d183f372908ea --- /dev/null +++ b/clang/test/Driver/version-build-config.test @@ -0,0 +1,6 @@ +# REQUIRES: asserts +# RUN: %clang --version 2>&1 | FileCheck %s + +# CHECK: clang version +# When assertions are enabled, we should have a build configuration line that reflects that +# CHECK: Build configuration: {{.*}}+assertions >From efc90ba92c29f1cd14f508f56a82a1f03f960401 Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Wed, 3 Apr 2024 22:01:39 -0700 Subject: [PATCH 2/9] Address review feedback --- clang/lib/Driver/Driver.cpp | 31 ++- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 37180efb7ea67b..680c58e4ea43d8 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -2005,38 +2005,35 @@ void Driver::PrintVersion(const Compilation , raw_ostream ) const { // Print out build configuration options that impact the compiler's runtime // behavior. Intended for identifying the source of issues when reproducing // changes. - std::vector BuildOptions = { -#if !__OPTIMIZE__ - "+unoptimized", + SmallVector BuildOptions = { +#if __GNUC__ && !__OPTIMIZE__ +// FIXME: __OPTIMIZE__ is not available on MSVC, this will never show there +"+unoptimized", #endif #ifndef NDEBUG - "+assertions", +"+assertions", #endif #ifdef EXPENSIVE_CHECKS - "+expensive-checks", +"+expensive-checks", #endif #if __has_feature(address_sanitizer) - "+asan", +"+asan", #endif #if __has_feature(undefined_behavior_sanitizer) - "+ubsan", +"+ubsan", #endif #if __has_feature(memory_sanitizer) - "+msan", +"+msan", #endif #if __has_feature(dataflow_sanitizer) - "+dfsan", +"+dfsan", #endif }; if (!BuildOptions.empty()) { -OS << "Build configuration: "; -bool FirstOption = true; -for (const auto : BuildOptions) { - if (!FirstOption) -OS << ", "; - OS << Option; - FirstOption = false; -} +OS << "Build config: "; +llvm::interleaveComma(BuildOptions, OS, [](const StringRef ) { +OS << Option; +}); OS << '\n'; } >From 1213ba2f965a0577fc6504e967ae17346da4ef4f Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Wed, 3 Apr 2024 22:02:19 -0700 Subject: [PATCH 3/9] Move LLVM_IS_DEBUG_BUILD into Support/CommandLine.h Allow us to reuse this logic in the feature printing. --- clang/lib/Driver/Driver.cpp | 3 +-- llvm/include/llvm/Support/CommandLine.h | 22 ++ llvm/lib/Support/CommandLine.cpp| 22 -- 3
[clang] [llvm] [driver] Make --version show if assertions, etc. are enabled (PR #87585)
@@ -2734,6 +2734,48 @@ void cl::PrintHelpMessage(bool Hidden, bool Categorized) { CommonOptions->CategorizedHiddenPrinter.printHelp(); } +ArrayRef cl::getCompilerBuildConfig() { + static const StringRef Config[] = { porglezomp wrote: This fails to build when Config is empty https://github.com/llvm/llvm-project/pull/87585 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [driver] Make --version show if assertions, etc. are enabled (PR #87585)
https://github.com/porglezomp updated https://github.com/llvm/llvm-project/pull/87585 >From a104ff0a445dfe5c6e6cfcf3734f6c0942eca082 Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Thu, 28 Mar 2024 13:58:19 -0700 Subject: [PATCH 1/8] [driver] Make --version show if assertions, etc. are enabled It's useful to have some significant build options visible in the version when investigating problems with a specific compiler artifact. This makes it easy to see if assertions, expensive checks, sanitizers, etc. are enabled when checking a compiler version. --- clang/lib/Driver/Driver.cpp | 38 + clang/test/Driver/version-build-config.test | 6 2 files changed, 44 insertions(+) create mode 100644 clang/test/Driver/version-build-config.test diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 7a53764364ce4d..37180efb7ea67b 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -2002,6 +2002,44 @@ void Driver::PrintVersion(const Compilation , raw_ostream ) const { // Print out the install directory. OS << "InstalledDir: " << Dir << '\n'; + // Print out build configuration options that impact the compiler's runtime + // behavior. Intended for identifying the source of issues when reproducing + // changes. + std::vector BuildOptions = { +#if !__OPTIMIZE__ + "+unoptimized", +#endif +#ifndef NDEBUG + "+assertions", +#endif +#ifdef EXPENSIVE_CHECKS + "+expensive-checks", +#endif +#if __has_feature(address_sanitizer) + "+asan", +#endif +#if __has_feature(undefined_behavior_sanitizer) + "+ubsan", +#endif +#if __has_feature(memory_sanitizer) + "+msan", +#endif +#if __has_feature(dataflow_sanitizer) + "+dfsan", +#endif + }; + if (!BuildOptions.empty()) { +OS << "Build configuration: "; +bool FirstOption = true; +for (const auto : BuildOptions) { + if (!FirstOption) +OS << ", "; + OS << Option; + FirstOption = false; +} +OS << '\n'; + } + // If configuration files were used, print their paths. for (auto ConfigFile : ConfigFiles) OS << "Configuration file: " << ConfigFile << '\n'; diff --git a/clang/test/Driver/version-build-config.test b/clang/test/Driver/version-build-config.test new file mode 100644 index 00..3d183f372908ea --- /dev/null +++ b/clang/test/Driver/version-build-config.test @@ -0,0 +1,6 @@ +# REQUIRES: asserts +# RUN: %clang --version 2>&1 | FileCheck %s + +# CHECK: clang version +# When assertions are enabled, we should have a build configuration line that reflects that +# CHECK: Build configuration: {{.*}}+assertions >From efc90ba92c29f1cd14f508f56a82a1f03f960401 Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Wed, 3 Apr 2024 22:01:39 -0700 Subject: [PATCH 2/8] Address review feedback --- clang/lib/Driver/Driver.cpp | 31 ++- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 37180efb7ea67b..680c58e4ea43d8 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -2005,38 +2005,35 @@ void Driver::PrintVersion(const Compilation , raw_ostream ) const { // Print out build configuration options that impact the compiler's runtime // behavior. Intended for identifying the source of issues when reproducing // changes. - std::vector BuildOptions = { -#if !__OPTIMIZE__ - "+unoptimized", + SmallVector BuildOptions = { +#if __GNUC__ && !__OPTIMIZE__ +// FIXME: __OPTIMIZE__ is not available on MSVC, this will never show there +"+unoptimized", #endif #ifndef NDEBUG - "+assertions", +"+assertions", #endif #ifdef EXPENSIVE_CHECKS - "+expensive-checks", +"+expensive-checks", #endif #if __has_feature(address_sanitizer) - "+asan", +"+asan", #endif #if __has_feature(undefined_behavior_sanitizer) - "+ubsan", +"+ubsan", #endif #if __has_feature(memory_sanitizer) - "+msan", +"+msan", #endif #if __has_feature(dataflow_sanitizer) - "+dfsan", +"+dfsan", #endif }; if (!BuildOptions.empty()) { -OS << "Build configuration: "; -bool FirstOption = true; -for (const auto : BuildOptions) { - if (!FirstOption) -OS << ", "; - OS << Option; - FirstOption = false; -} +OS << "Build config: "; +llvm::interleaveComma(BuildOptions, OS, [](const StringRef ) { +OS << Option; +}); OS << '\n'; } >From 1213ba2f965a0577fc6504e967ae17346da4ef4f Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Wed, 3 Apr 2024 22:02:19 -0700 Subject: [PATCH 3/8] Move LLVM_IS_DEBUG_BUILD into Support/CommandLine.h Allow us to reuse this logic in the feature printing. --- clang/lib/Driver/Driver.cpp | 3 +-- llvm/include/llvm/Support/CommandLine.h | 22 ++ llvm/lib/Support/CommandLine.cpp| 22 -- 3
[clang] [llvm] [driver] Make --version show if assertions, etc. are enabled (PR #87585)
@@ -2734,6 +2734,39 @@ void cl::PrintHelpMessage(bool Hidden, bool Categorized) { CommonOptions->CategorizedHiddenPrinter.printHelp(); } +ArrayRef cl::CompilerBuildConfig = { porglezomp wrote: I footgunned here, this doesn't do lifetime extension so this array is a temporary despite being a global. Making this a function to additionally avoid having a static constructor. https://github.com/llvm/llvm-project/pull/87585 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [driver] Make --version show if assertions, etc. are enabled (PR #87585)
https://github.com/porglezomp edited https://github.com/llvm/llvm-project/pull/87585 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [driver] Make --version show if assertions, etc. are enabled (PR #87585)
@@ -2734,6 +2734,39 @@ void cl::PrintHelpMessage(bool Hidden, bool Categorized) { CommonOptions->CategorizedHiddenPrinter.printHelp(); } +ArrayRef cl::CompilerBuildConfig = { +#if LLVM_IS_DEBUG_BUILD +"+unoptimized", +#endif +#ifndef NDEBUG +"+assertions", +#endif +#ifdef EXPENSIVE_CHECKS +"+expensive-checks", +#endif +#if __has_feature(address_sanitizer) +"+asan", +#endif +#if __has_feature(undefined_behavior_sanitizer) porglezomp wrote: Good catch on TSan. I followed the documented list of `__has_feature` that I could see, I don't see `hwaddress_sanitizer` in the list here: https://clang.llvm.org/docs/LanguageExtensions.html#extensions-for-dynamic-analysis https://github.com/llvm/llvm-project/pull/87585 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [driver] Make --version show if assertions, etc. are enabled (PR #87585)
https://github.com/porglezomp updated https://github.com/llvm/llvm-project/pull/87585 >From a104ff0a445dfe5c6e6cfcf3734f6c0942eca082 Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Thu, 28 Mar 2024 13:58:19 -0700 Subject: [PATCH 1/7] [driver] Make --version show if assertions, etc. are enabled It's useful to have some significant build options visible in the version when investigating problems with a specific compiler artifact. This makes it easy to see if assertions, expensive checks, sanitizers, etc. are enabled when checking a compiler version. --- clang/lib/Driver/Driver.cpp | 38 + clang/test/Driver/version-build-config.test | 6 2 files changed, 44 insertions(+) create mode 100644 clang/test/Driver/version-build-config.test diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 7a53764364ce4d..37180efb7ea67b 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -2002,6 +2002,44 @@ void Driver::PrintVersion(const Compilation , raw_ostream ) const { // Print out the install directory. OS << "InstalledDir: " << Dir << '\n'; + // Print out build configuration options that impact the compiler's runtime + // behavior. Intended for identifying the source of issues when reproducing + // changes. + std::vector BuildOptions = { +#if !__OPTIMIZE__ + "+unoptimized", +#endif +#ifndef NDEBUG + "+assertions", +#endif +#ifdef EXPENSIVE_CHECKS + "+expensive-checks", +#endif +#if __has_feature(address_sanitizer) + "+asan", +#endif +#if __has_feature(undefined_behavior_sanitizer) + "+ubsan", +#endif +#if __has_feature(memory_sanitizer) + "+msan", +#endif +#if __has_feature(dataflow_sanitizer) + "+dfsan", +#endif + }; + if (!BuildOptions.empty()) { +OS << "Build configuration: "; +bool FirstOption = true; +for (const auto : BuildOptions) { + if (!FirstOption) +OS << ", "; + OS << Option; + FirstOption = false; +} +OS << '\n'; + } + // If configuration files were used, print their paths. for (auto ConfigFile : ConfigFiles) OS << "Configuration file: " << ConfigFile << '\n'; diff --git a/clang/test/Driver/version-build-config.test b/clang/test/Driver/version-build-config.test new file mode 100644 index 00..3d183f372908ea --- /dev/null +++ b/clang/test/Driver/version-build-config.test @@ -0,0 +1,6 @@ +# REQUIRES: asserts +# RUN: %clang --version 2>&1 | FileCheck %s + +# CHECK: clang version +# When assertions are enabled, we should have a build configuration line that reflects that +# CHECK: Build configuration: {{.*}}+assertions >From efc90ba92c29f1cd14f508f56a82a1f03f960401 Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Wed, 3 Apr 2024 22:01:39 -0700 Subject: [PATCH 2/7] Address review feedback --- clang/lib/Driver/Driver.cpp | 31 ++- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 37180efb7ea67b..680c58e4ea43d8 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -2005,38 +2005,35 @@ void Driver::PrintVersion(const Compilation , raw_ostream ) const { // Print out build configuration options that impact the compiler's runtime // behavior. Intended for identifying the source of issues when reproducing // changes. - std::vector BuildOptions = { -#if !__OPTIMIZE__ - "+unoptimized", + SmallVector BuildOptions = { +#if __GNUC__ && !__OPTIMIZE__ +// FIXME: __OPTIMIZE__ is not available on MSVC, this will never show there +"+unoptimized", #endif #ifndef NDEBUG - "+assertions", +"+assertions", #endif #ifdef EXPENSIVE_CHECKS - "+expensive-checks", +"+expensive-checks", #endif #if __has_feature(address_sanitizer) - "+asan", +"+asan", #endif #if __has_feature(undefined_behavior_sanitizer) - "+ubsan", +"+ubsan", #endif #if __has_feature(memory_sanitizer) - "+msan", +"+msan", #endif #if __has_feature(dataflow_sanitizer) - "+dfsan", +"+dfsan", #endif }; if (!BuildOptions.empty()) { -OS << "Build configuration: "; -bool FirstOption = true; -for (const auto : BuildOptions) { - if (!FirstOption) -OS << ", "; - OS << Option; - FirstOption = false; -} +OS << "Build config: "; +llvm::interleaveComma(BuildOptions, OS, [](const StringRef ) { +OS << Option; +}); OS << '\n'; } >From 1213ba2f965a0577fc6504e967ae17346da4ef4f Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Wed, 3 Apr 2024 22:02:19 -0700 Subject: [PATCH 3/7] Move LLVM_IS_DEBUG_BUILD into Support/CommandLine.h Allow us to reuse this logic in the feature printing. --- clang/lib/Driver/Driver.cpp | 3 +-- llvm/include/llvm/Support/CommandLine.h | 22 ++ llvm/lib/Support/CommandLine.cpp| 22 -- 3
[clang] [llvm] [driver] Make --version show if assertions, etc. are enabled (PR #87585)
https://github.com/porglezomp edited https://github.com/llvm/llvm-project/pull/87585 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [driver] Make --version show if assertions, etc. are enabled (PR #87585)
@@ -2002,6 +2002,44 @@ void Driver::PrintVersion(const Compilation , raw_ostream ) const { // Print out the install directory. OS << "InstalledDir: " << Dir << '\n'; + // Print out build configuration options that impact the compiler's runtime + // behavior. Intended for identifying the source of issues when reproducing + // changes. + std::vector BuildOptions = { porglezomp wrote: I moved this to a global variable to support the API, so I think `ArrayRef` ends up being the appropriate type in the end. https://github.com/llvm/llvm-project/pull/87585 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [driver] Make --version show if assertions, etc. are enabled (PR #87585)
@@ -2002,6 +2002,44 @@ void Driver::PrintVersion(const Compilation , raw_ostream ) const { // Print out the install directory. OS << "InstalledDir: " << Dir << '\n'; + // Print out build configuration options that impact the compiler's runtime + // behavior. Intended for identifying the source of issues when reproducing + // changes. + std::vector BuildOptions = { +#if !__OPTIMIZE__ + "+unoptimized", +#endif +#ifndef NDEBUG + "+assertions", +#endif +#ifdef EXPENSIVE_CHECKS + "+expensive-checks", +#endif +#if __has_feature(address_sanitizer) + "+asan", +#endif +#if __has_feature(undefined_behavior_sanitizer) + "+ubsan", +#endif +#if __has_feature(memory_sanitizer) + "+msan", +#endif +#if __has_feature(dataflow_sanitizer) + "+dfsan", +#endif + }; + if (!BuildOptions.empty()) { porglezomp wrote: Added this as `LLVM_VERSION_PRINTER_SHOW_BUILD_CONFIG` which defaults on, is there anything I should do to update the release scripts here or is that for someone else to do? https://github.com/llvm/llvm-project/pull/87585 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [driver] Make --version show if assertions, etc. are enabled (PR #87585)
porglezomp wrote: The result of those refactors I now have a new build option to support hiding the version, should I be touching the `utils/bazel` with this patch? https://github.com/llvm/llvm-project/pull/87585 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [driver] Make --version show if assertions, etc. are enabled (PR #87585)
https://github.com/porglezomp updated https://github.com/llvm/llvm-project/pull/87585 >From a104ff0a445dfe5c6e6cfcf3734f6c0942eca082 Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Thu, 28 Mar 2024 13:58:19 -0700 Subject: [PATCH 1/6] [driver] Make --version show if assertions, etc. are enabled It's useful to have some significant build options visible in the version when investigating problems with a specific compiler artifact. This makes it easy to see if assertions, expensive checks, sanitizers, etc. are enabled when checking a compiler version. --- clang/lib/Driver/Driver.cpp | 38 + clang/test/Driver/version-build-config.test | 6 2 files changed, 44 insertions(+) create mode 100644 clang/test/Driver/version-build-config.test diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 7a53764364ce4d..37180efb7ea67b 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -2002,6 +2002,44 @@ void Driver::PrintVersion(const Compilation , raw_ostream ) const { // Print out the install directory. OS << "InstalledDir: " << Dir << '\n'; + // Print out build configuration options that impact the compiler's runtime + // behavior. Intended for identifying the source of issues when reproducing + // changes. + std::vector BuildOptions = { +#if !__OPTIMIZE__ + "+unoptimized", +#endif +#ifndef NDEBUG + "+assertions", +#endif +#ifdef EXPENSIVE_CHECKS + "+expensive-checks", +#endif +#if __has_feature(address_sanitizer) + "+asan", +#endif +#if __has_feature(undefined_behavior_sanitizer) + "+ubsan", +#endif +#if __has_feature(memory_sanitizer) + "+msan", +#endif +#if __has_feature(dataflow_sanitizer) + "+dfsan", +#endif + }; + if (!BuildOptions.empty()) { +OS << "Build configuration: "; +bool FirstOption = true; +for (const auto : BuildOptions) { + if (!FirstOption) +OS << ", "; + OS << Option; + FirstOption = false; +} +OS << '\n'; + } + // If configuration files were used, print their paths. for (auto ConfigFile : ConfigFiles) OS << "Configuration file: " << ConfigFile << '\n'; diff --git a/clang/test/Driver/version-build-config.test b/clang/test/Driver/version-build-config.test new file mode 100644 index 00..3d183f372908ea --- /dev/null +++ b/clang/test/Driver/version-build-config.test @@ -0,0 +1,6 @@ +# REQUIRES: asserts +# RUN: %clang --version 2>&1 | FileCheck %s + +# CHECK: clang version +# When assertions are enabled, we should have a build configuration line that reflects that +# CHECK: Build configuration: {{.*}}+assertions >From efc90ba92c29f1cd14f508f56a82a1f03f960401 Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Wed, 3 Apr 2024 22:01:39 -0700 Subject: [PATCH 2/6] Address review feedback --- clang/lib/Driver/Driver.cpp | 31 ++- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 37180efb7ea67b..680c58e4ea43d8 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -2005,38 +2005,35 @@ void Driver::PrintVersion(const Compilation , raw_ostream ) const { // Print out build configuration options that impact the compiler's runtime // behavior. Intended for identifying the source of issues when reproducing // changes. - std::vector BuildOptions = { -#if !__OPTIMIZE__ - "+unoptimized", + SmallVector BuildOptions = { +#if __GNUC__ && !__OPTIMIZE__ +// FIXME: __OPTIMIZE__ is not available on MSVC, this will never show there +"+unoptimized", #endif #ifndef NDEBUG - "+assertions", +"+assertions", #endif #ifdef EXPENSIVE_CHECKS - "+expensive-checks", +"+expensive-checks", #endif #if __has_feature(address_sanitizer) - "+asan", +"+asan", #endif #if __has_feature(undefined_behavior_sanitizer) - "+ubsan", +"+ubsan", #endif #if __has_feature(memory_sanitizer) - "+msan", +"+msan", #endif #if __has_feature(dataflow_sanitizer) - "+dfsan", +"+dfsan", #endif }; if (!BuildOptions.empty()) { -OS << "Build configuration: "; -bool FirstOption = true; -for (const auto : BuildOptions) { - if (!FirstOption) -OS << ", "; - OS << Option; - FirstOption = false; -} +OS << "Build config: "; +llvm::interleaveComma(BuildOptions, OS, [](const StringRef ) { +OS << Option; +}); OS << '\n'; } >From 1213ba2f965a0577fc6504e967ae17346da4ef4f Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Wed, 3 Apr 2024 22:02:19 -0700 Subject: [PATCH 3/6] Move LLVM_IS_DEBUG_BUILD into Support/CommandLine.h Allow us to reuse this logic in the feature printing. --- clang/lib/Driver/Driver.cpp | 3 +-- llvm/include/llvm/Support/CommandLine.h | 22 ++ llvm/lib/Support/CommandLine.cpp| 22 -- 3
[clang] [include-mapping] Python fixes (PR #65401)
https://github.com/porglezomp closed https://github.com/llvm/llvm-project/pull/65401 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [include-mapping] Python fixes (PR #65401)
https://github.com/porglezomp review_requested https://github.com/llvm/llvm-project/pull/65401 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [include-mapping] Python fixes (PR #65401)
porglezomp wrote: Done https://github.com/llvm/llvm-project/pull/65401 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [include-mapping] Python fixes (PR #65401)
https://github.com/porglezomp resolved https://github.com/llvm/llvm-project/pull/65401 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [include-mapping] Python fixes (PR #65401)
https://github.com/porglezomp updated https://github.com/llvm/llvm-project/pull/65401: >From b8cac30c34d7c26dd3ec8e3e00678d2034e9f51c Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Tue, 5 Sep 2023 12:12:45 -0700 Subject: [PATCH 1/2] [include-mapping] Python fixes - Move the multiprocessing.Pool initializer to a top-level function, it was previously causing a pickle failure with my machine's python. - Change the `env python` to `env python3` for convenience --- clang/tools/include-mapping/cppreference_parser.py | 8 +--- clang/tools/include-mapping/gen_std.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/clang/tools/include-mapping/cppreference_parser.py b/clang/tools/include-mapping/cppreference_parser.py index cefdbeaf334e1c4..c1a1f9a86d05fc3 100644 --- a/clang/tools/include-mapping/cppreference_parser.py +++ b/clang/tools/include-mapping/cppreference_parser.py @@ -176,6 +176,10 @@ def _GetSymbols(pool, root_dir, index_page_name, namespace, variants_to_accept): return symbols +def signal_ignore_initializer(): +return signal.signal(signal.SIGINT, signal.SIG_IGN) + + def GetSymbols(parse_pages): """Get all symbols by parsing the given pages. @@ -192,9 +196,7 @@ def GetSymbols(parse_pages): symbols = [] # Run many workers to process individual symbol pages under the symbol index. # Don't allow workers to capture Ctrl-C. -pool = multiprocessing.Pool( -initializer=lambda: signal.signal(signal.SIGINT, signal.SIG_IGN) -) +pool = multiprocessing.Pool(initializer=signal_ignore_initializer) try: for root_dir, page_name, namespace in parse_pages: symbols.extend( diff --git a/clang/tools/include-mapping/gen_std.py b/clang/tools/include-mapping/gen_std.py index 57a5a6772ba894a..fcd3bd0d843ea16 100755 --- a/clang/tools/include-mapping/gen_std.py +++ b/clang/tools/include-mapping/gen_std.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # ===- gen_std.py - --*- python -*--===# # # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. >From a08344118d7a07067e8f39ac5441e4b99a44a220 Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Mon, 11 Sep 2023 15:29:51 -0700 Subject: [PATCH 2/2] fixup! [include-mapping] Python fixes --- clang/tools/include-mapping/cppreference_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/tools/include-mapping/cppreference_parser.py b/clang/tools/include-mapping/cppreference_parser.py index c1a1f9a86d05fc3..f2ea55384fac80c 100644 --- a/clang/tools/include-mapping/cppreference_parser.py +++ b/clang/tools/include-mapping/cppreference_parser.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # ===- cppreference_parser.py - --*- python -*--===# # # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [include-mapping] Python fixes (PR #65401)
https://github.com/porglezomp review_requested https://github.com/llvm/llvm-project/pull/65401 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [include-mapping] Python fixes (PR #65401)
https://github.com/porglezomp review_requested https://github.com/llvm/llvm-project/pull/65401 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [include-mapping] Python fixes (PR #65401)
https://github.com/porglezomp created https://github.com/llvm/llvm-project/pull/65401: I had to regenerate the include mapping while resolving a downstream merge conflict, and ran into two issue on my machine. These shouldn't change anything, just make things work on my config. - Move the `multiprocessing.Pool` initializer to a top-level function, it was previously causing a pickle failure with my machine's python, specifically complaining about having to pickle the lambda or a local function. Works fine with a top-level function. - Change the `env python` to `env python3` for convenience. The interpreter is installed as python3 on macOS. It looks like about 2/3 of the scripts in `clang/tools/` are using `env python3` over `env python` so the latter seems a reasonable change to make. >From b8cac30c34d7c26dd3ec8e3e00678d2034e9f51c Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Tue, 5 Sep 2023 12:12:45 -0700 Subject: [PATCH] [include-mapping] Python fixes - Move the multiprocessing.Pool initializer to a top-level function, it was previously causing a pickle failure with my machine's python. - Change the `env python` to `env python3` for convenience --- clang/tools/include-mapping/cppreference_parser.py | 8 +--- clang/tools/include-mapping/gen_std.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/clang/tools/include-mapping/cppreference_parser.py b/clang/tools/include-mapping/cppreference_parser.py index cefdbeaf334e1c4..c1a1f9a86d05fc3 100644 --- a/clang/tools/include-mapping/cppreference_parser.py +++ b/clang/tools/include-mapping/cppreference_parser.py @@ -176,6 +176,10 @@ def _GetSymbols(pool, root_dir, index_page_name, namespace, variants_to_accept): return symbols +def signal_ignore_initializer(): +return signal.signal(signal.SIGINT, signal.SIG_IGN) + + def GetSymbols(parse_pages): """Get all symbols by parsing the given pages. @@ -192,9 +196,7 @@ def GetSymbols(parse_pages): symbols = [] # Run many workers to process individual symbol pages under the symbol index. # Don't allow workers to capture Ctrl-C. -pool = multiprocessing.Pool( -initializer=lambda: signal.signal(signal.SIGINT, signal.SIG_IGN) -) +pool = multiprocessing.Pool(initializer=signal_ignore_initializer) try: for root_dir, page_name, namespace in parse_pages: symbols.extend( diff --git a/clang/tools/include-mapping/gen_std.py b/clang/tools/include-mapping/gen_std.py index 57a5a6772ba894a..fcd3bd0d843ea16 100755 --- a/clang/tools/include-mapping/gen_std.py +++ b/clang/tools/include-mapping/gen_std.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # ===- gen_std.py - --*- python -*--===# # # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 45ff63b - [Driver] Also warn about -mwatchos-version-min and -mtvos-version-min
Author: Cassie Jones Date: 2023-07-17T13:26:52-07:00 New Revision: 45ff63ba6112c199897b4117d54f19d28161b632 URL: https://github.com/llvm/llvm-project/commit/45ff63ba6112c199897b4117d54f19d28161b632 DIFF: https://github.com/llvm/llvm-project/commit/45ff63ba6112c199897b4117d54f19d28161b632.diff LOG: [Driver] Also warn about -mwatchos-version-min and -mtvos-version-min Sometimes users pass this option when targeting embedded architectures like armv7m on non-darwin platforms. This applies to watchOS and tvOS as well as iOS. Depends on D155407 Reviewed By: MaskRay, ahatanak Differential Revision: https://reviews.llvm.org/D155408 Added: Modified: clang/lib/Driver/ToolChains/Darwin.cpp clang/test/Driver/macho-embedded.c Removed: diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index a73f46bb320294..65bd6c6a7eb35a 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -26,6 +26,7 @@ #include "llvm/Support/Threading.h" #include "llvm/Support/VirtualFileSystem.h" #include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/Triple.h" #include // ::getenv using namespace clang::driver; @@ -85,10 +86,16 @@ void darwin::setTripleTypeForMachOArchName(llvm::Triple , StringRef Str, if (ArchKind == llvm::ARM::ArchKind::ARMV6M || ArchKind == llvm::ARM::ArchKind::ARMV7M || ArchKind == llvm::ARM::ArchKind::ARMV7EM) { -// Don't reject -mios-version-min= if we have an iOS triple. -if (T.isiOS()) +// Don't reject these -version-min= if we have the appropriate triple. +if (T.getOS() == llvm::Triple::IOS) for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ)) A->ignoreTargetSpecific(); +if (T.getOS() == llvm::Triple::WatchOS) + for (Arg *A : Args.filtered(options::OPT_mwatchos_version_min_EQ)) +A->ignoreTargetSpecific(); +if (T.getOS() == llvm::Triple::TvOS) + for (Arg *A : Args.filtered(options::OPT_mtvos_version_min_EQ)) +A->ignoreTargetSpecific(); T.setOS(llvm::Triple::UnknownOS); T.setObjectFormat(llvm::Triple::MachO); diff --git a/clang/test/Driver/macho-embedded.c b/clang/test/Driver/macho-embedded.c index 14b933ba256de0..bb4971203518b3 100644 --- a/clang/test/Driver/macho-embedded.c +++ b/clang/test/Driver/macho-embedded.c @@ -8,12 +8,17 @@ // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG +// RUN: %clang -arch armv7m --target=thumbv7-apple-watchos -mwatchos-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG +// RUN: %clang -arch armv7m --target=thumbv7-apple-tvos -mtvos-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG + +// RUN: %clang -arch armv7m --target=thumbv7-apple-tvos -mios-version-min=5 -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-MIXED // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios // CHECK-AAPCS: "-target-abi" "aapcs" // CHECK-APCS: "-target-abi" "apcs-gnu" -// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: '-mios-version-min=5' // CHECK-MACHO-EMBEDDED: "-triple" "{{thumbv[67]e?m}}-apple-unknown-macho" // CHECK-MACHO-EMBEDDED: "-mrelocation-model" "pic" +// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: '-m{{ios|watchos|tvos}}-version-min=5' +// CHECK-MACHO-EMBEDDED-MIXED: error: unsupported option '-mios-version-min=' for target 'thumbv7-apple-tvos' ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] f7ad7d1 - [Driver] Warn about all instances -mios-version-min not just the last
Author: Cassie Jones Date: 2023-07-16T16:45:49-07:00 New Revision: f7ad7d147b9c1e45e3f80f9e50be9984a8798e1a URL: https://github.com/llvm/llvm-project/commit/f7ad7d147b9c1e45e3f80f9e50be9984a8798e1a DIFF: https://github.com/llvm/llvm-project/commit/f7ad7d147b9c1e45e3f80f9e50be9984a8798e1a.diff LOG: [Driver] Warn about all instances -mios-version-min not just the last Follow-up to D155123, uniformly handle cases where there are duplicate -mios-verion-min arguments. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D155407 Added: Modified: clang/lib/Driver/ToolChains/Darwin.cpp clang/test/Driver/macho-embedded.c Removed: diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 0f9474c45822f8..a73f46bb320294 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -87,7 +87,7 @@ void darwin::setTripleTypeForMachOArchName(llvm::Triple , StringRef Str, ArchKind == llvm::ARM::ArchKind::ARMV7EM) { // Don't reject -mios-version-min= if we have an iOS triple. if (T.isiOS()) - if (Arg *A = Args.getLastArgNoClaim(options::OPT_mios_version_min_EQ)) + for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ)) A->ignoreTargetSpecific(); T.setOS(llvm::Triple::UnknownOS); diff --git a/clang/test/Driver/macho-embedded.c b/clang/test/Driver/macho-embedded.c index 6b93b967e25448..14b933ba256de0 100644 --- a/clang/test/Driver/macho-embedded.c +++ b/clang/test/Driver/macho-embedded.c @@ -7,6 +7,7 @@ // RUN: %clang -arch armv7em -target thumbv7-apple-darwin -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG +// RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 590eb76 - [test] Add C++ ext_vector_type tests
Author: Cassie Jones Date: 2023-05-22T15:58:01-07:00 New Revision: 590eb76ba3cd668baee7d06940ad820e89f830c4 URL: https://github.com/llvm/llvm-project/commit/590eb76ba3cd668baee7d06940ad820e89f830c4 DIFF: https://github.com/llvm/llvm-project/commit/590eb76ba3cd668baee7d06940ad820e89f830c4.diff LOG: [test] Add C++ ext_vector_type tests Add initial tests for the behavior of ext_vector_type vectors for vector vs scalar ops in C++. Their behavior doesn't agree with the behavior in C and what the behavior seems like it should be, these are baseline tests before implementing those changes. Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D151059 Added: Modified: clang/test/SemaCXX/vector.cpp Removed: diff --git a/clang/test/SemaCXX/vector.cpp b/clang/test/SemaCXX/vector.cpp index 9c6e2ebedf6ea..7c8ee89814e57 100644 --- a/clang/test/SemaCXX/vector.cpp +++ b/clang/test/SemaCXX/vector.cpp @@ -545,3 +545,230 @@ void triggerIntegerRankCheck() { auto b4 = (v4 >= 0x12); } #endif + +namespace all_operators { +typedef unsigned int v2u __attribute__((ext_vector_type(2))); +typedef float v2f __attribute__((ext_vector_type(2))); + +void test_int_vector_scalar(unsigned int ua, v2u v2ua) { + // Operators with one integer vector and one integer scalar operand. The scalar will splat. + (void)(v2ua + ua); + (void)(ua + v2ua); + (void)(v2ua - ua); + (void)(ua - v2ua); + (void)(v2ua * ua); + (void)(ua * v2ua); + (void)(v2ua / ua); + (void)(ua / v2ua); + (void)(v2ua % ua); + (void)(ua % v2ua); + + (void)(v2ua == ua); + (void)(ua == v2ua); + (void)(v2ua != ua); + (void)(ua != v2ua); + (void)(v2ua <= ua); + (void)(ua <= v2ua); + (void)(v2ua >= ua); + (void)(ua >= v2ua); + (void)(v2ua < ua); + (void)(ua < v2ua); + (void)(v2ua > ua); + (void)(ua > v2ua); + (void)(v2ua && ua); + (void)(ua && v2ua); + (void)(v2ua || ua); + (void)(ua || v2ua); + + (void)(v2ua & ua); + (void)(ua & v2ua); + (void)(v2ua | ua); + (void)(ua | v2ua); + (void)(v2ua ^ ua); + (void)(ua ^ v2ua); + (void)(v2ua << ua); + (void)(ua << v2ua); + (void)(v2ua >> ua); + (void)(ua >> v2ua); + + v2ua += ua; + v2ua -= ua; + v2ua *= ua; + v2ua /= ua; + v2ua %= ua; + v2ua &= ua; + v2ua |= ua; + v2ua ^= ua; + v2ua >>= ua; + v2ua <<= ua; + + ua += v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua -= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua *= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua /= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua %= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua &= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua |= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua ^= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua >>= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua <<= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} +} + +void test_float_vector_scalar(float fa, unsigned int ua, v2f v2fa) { + // Operators with one float vector and one float scalar operand. The scalar will splat. + (void)(v2fa + fa); + (void)(fa + v2fa); + (void)(v2fa - fa); + (void)(fa - v2fa); + (void)(v2fa * fa); + (void)(fa * v2fa); + (void)(v2fa / fa); + (void)(fa / v2fa); + (void)(v2fa % fa); // expected-error{{invalid operands to binary expression}} + (void)(fa % v2fa); // expected-error{{invalid operands to binary expression}} + + (void)(v2fa == fa); + (void)(fa == v2fa); + (void)(v2fa != fa); + (void)(fa != v2fa); + (void)(v2fa <= fa); + (void)(fa <= v2fa); + (void)(v2fa >= fa); + (void)(fa >= v2fa); + (void)(v2fa < fa); + (void)(fa < v2fa); + (void)(v2fa > fa); + (void)(fa > v2fa); + (void)(v2fa && fa); + (void)(fa && v2fa); + (void)(v2fa || fa); + (void)(fa || v2fa); + + (void)(v2fa & fa); // expected-error{{invalid operands to binary expression}} + (void)(fa & v2fa); // expected-error{{invalid operands to binary expression}} + (void)(v2fa | fa); // expected-error{{invalid operands to binary expression}} + (void)(fa | v2fa); // expected-error{{invalid operands to binary expression}} + (void)(v2fa ^ fa); // expected-error{{invalid operands to binary expression}} + (void)(fa ^ v2fa); // expected-error{{invalid operands to binary expression}} + (void)(v2fa << fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}} + (void)(v2fa << ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}} + (void)(fa << v2fa); // expected-error{{used type 'float' where integer is
[clang] b5b6896 - [test] Add more ext_vector_type tests for C
Author: Cassie Jones Date: 2023-05-22T15:08:14-07:00 New Revision: b5b689679e1e435b5c82832f468ed939c7b72021 URL: https://github.com/llvm/llvm-project/commit/b5b689679e1e435b5c82832f468ed939c7b72021 DIFF: https://github.com/llvm/llvm-project/commit/b5b689679e1e435b5c82832f468ed939c7b72021.diff LOG: [test] Add more ext_vector_type tests for C Test that all builtin operators type check successfully with one vector operand and one scalar operand. Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D151061 Added: Modified: clang/test/Sema/ext_vector_ops.c clang/test/Sema/vecshift.c Removed: diff --git a/clang/test/Sema/ext_vector_ops.c b/clang/test/Sema/ext_vector_ops.c index af4df07e14da9..5dc3047e145f1 100644 --- a/clang/test/Sema/ext_vector_ops.c +++ b/clang/test/Sema/ext_vector_ops.c @@ -25,3 +25,211 @@ void test1(v2u v2ua, v2s v2sa, v2f v2fa) { v2u *v2u_ptr = 0; v2s *v2s_ptr; } + +void test_int_vector_scalar(unsigned int ua, v2u v2ua) { + // Operations with one integer vector and one scalar. These splat the scalar. + (void)(v2ua + ua); + (void)(ua + v2ua); + (void)(v2ua - ua); + (void)(ua - v2ua); + (void)(v2ua * ua); + (void)(ua * v2ua); + (void)(v2ua / ua); + (void)(ua / v2ua); + (void)(v2ua % ua); + (void)(ua % v2ua); + + (void)(v2ua == ua); + (void)(ua == v2ua); + (void)(v2ua != ua); + (void)(ua != v2ua); + (void)(v2ua <= ua); + (void)(ua <= v2ua); + (void)(v2ua >= ua); + (void)(ua >= v2ua); + (void)(v2ua < ua); + (void)(ua < v2ua); + (void)(v2ua > ua); + (void)(ua > v2ua); + (void)(v2ua && ua); + (void)(ua && v2ua); + (void)(v2ua || ua); + (void)(ua || v2ua); + + (void)(v2ua & ua); + (void)(ua & v2ua); + (void)(v2ua | ua); + (void)(ua | v2ua); + (void)(v2ua ^ ua); + (void)(ua ^ v2ua); + (void)(v2ua << ua); + (void)(ua << v2ua); + (void)(v2ua >> ua); + (void)(ua >> v2ua); + + v2ua += ua; + v2ua -= ua; + v2ua *= ua; + v2ua /= ua; + v2ua %= ua; + v2ua &= ua; + v2ua |= ua; + v2ua ^= ua; + v2ua >>= ua; + v2ua <<= ua; + + ua += v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua -= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua *= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua /= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua %= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua &= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua |= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua ^= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua >>= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} + ua <<= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}} +} + +void test_float_vector_scalar(float fa, unsigned int ua, v2f v2fa) { + // Operations with one float vector and one scalar. These splat the scalar. + (void)(v2fa + fa); + (void)(fa + v2fa); + (void)(v2fa - fa); + (void)(fa - v2fa); + (void)(v2fa * fa); + (void)(fa * v2fa); + (void)(v2fa / fa); + (void)(fa / v2fa); + (void)(v2fa % fa); // expected-error{{invalid operands to binary expression}} + (void)(fa % v2fa); // expected-error{{invalid operands to binary expression}} + + (void)(v2fa == fa); + (void)(fa == v2fa); + (void)(v2fa != fa); + (void)(fa != v2fa); + (void)(v2fa <= fa); + (void)(fa <= v2fa); + (void)(v2fa >= fa); + (void)(fa >= v2fa); + (void)(v2fa < fa); + (void)(fa < v2fa); + (void)(v2fa > fa); + (void)(fa > v2fa); + (void)(v2fa && fa); + (void)(fa && v2fa); + (void)(v2fa || fa); + (void)(fa || v2fa); + + (void)(v2fa & fa); // expected-error{{invalid operands to binary expression}} + (void)(fa & v2fa); // expected-error{{invalid operands to binary expression}} + (void)(v2fa | fa); // expected-error{{invalid operands to binary expression}} + (void)(fa | v2fa); // expected-error{{invalid operands to binary expression}} + (void)(v2fa ^ fa); // expected-error{{invalid operands to binary expression}} + (void)(fa ^ v2fa); // expected-error{{invalid operands to binary expression}} + (void)(v2fa << fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}} + (void)(v2fa << ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}} + (void)(fa << v2fa); // expected-error{{used type 'float' where integer is required}} + (void)(ua << v2fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}} + (void)(v2fa >> fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}} + (void)(v2fa >>
[clang] ae8bbc4 - [clang] Require including config.h for CLANG_DEFAULT_STD_C
Author: Cassie Jones Date: 2022-05-14T01:48:14-07:00 New Revision: ae8bbc43f4709b910cd6c1e1ddc5bc854785a142 URL: https://github.com/llvm/llvm-project/commit/ae8bbc43f4709b910cd6c1e1ddc5bc854785a142 DIFF: https://github.com/llvm/llvm-project/commit/ae8bbc43f4709b910cd6c1e1ddc5bc854785a142.diff LOG: [clang] Require including config.h for CLANG_DEFAULT_STD_C This makes CLANG_DEFAULT_STD_C(XX) always be defined, defaulting to lang_unspecified, so you are forced to check its value instead of using an #ifdef. This should help avoid accidentally omitting the include in places where that's important, so that the default language version bug isn't re-introduced. Reviewed By: hokein, dexonsmith Differential Revision: https://reviews.llvm.org/D124974 Added: Modified: clang/include/clang/Config/config.h.cmake clang/lib/Basic/LangStandards.cpp Removed: diff --git a/clang/include/clang/Config/config.h.cmake b/clang/include/clang/Config/config.h.cmake index 680cc7310f76d..dfd2f757a185b 100644 --- a/clang/include/clang/Config/config.h.cmake +++ b/clang/include/clang/Config/config.h.cmake @@ -16,9 +16,21 @@ /* Default C/ObjC standard to use. */ #cmakedefine CLANG_DEFAULT_STD_C LangStandard::lang_${CLANG_DEFAULT_STD_C} +/* Always #define something so that missing the config.h #include at use sites + * becomes a compile error. + */ +#ifndef CLANG_DEFAULT_STD_C +#define CLANG_DEFAULT_STD_C LangStandard::lang_unspecified +#endif /* Default C++/ObjC++ standard to use. */ #cmakedefine CLANG_DEFAULT_STD_CXX LangStandard::lang_${CLANG_DEFAULT_STD_CXX} +/* Always #define something so that missing the config.h #include at use sites + * becomes a compile error. + */ +#ifndef CLANG_DEFAULT_STD_CXX +#define CLANG_DEFAULT_STD_CXX LangStandard::lang_unspecified +#endif /* Default C++ stdlib to use. */ #define CLANG_DEFAULT_CXX_STDLIB "${CLANG_DEFAULT_CXX_STDLIB}" diff --git a/clang/lib/Basic/LangStandards.cpp b/clang/lib/Basic/LangStandards.cpp index 6643af38ba01c..a21898dd3c627 100644 --- a/clang/lib/Basic/LangStandards.cpp +++ b/clang/lib/Basic/LangStandards.cpp @@ -58,30 +58,27 @@ LangStandard::Kind clang::getDefaultLanguageStandard(clang::Language Lang, return LangStandard::lang_cuda; case Language::Asm: case Language::C: -#if defined(CLANG_DEFAULT_STD_C) -return CLANG_DEFAULT_STD_C; -#else +if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified) + return CLANG_DEFAULT_STD_C; + // The PS4 uses C99 as the default C standard. if (T.isPS4()) return LangStandard::lang_gnu99; return LangStandard::lang_gnu17; -#endif case Language::ObjC: -#if defined(CLANG_DEFAULT_STD_C) -return CLANG_DEFAULT_STD_C; -#else +if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified) + return CLANG_DEFAULT_STD_C; + return LangStandard::lang_gnu11; -#endif case Language::CXX: case Language::ObjCXX: -#if defined(CLANG_DEFAULT_STD_CXX) -return CLANG_DEFAULT_STD_CXX; -#else +if (CLANG_DEFAULT_STD_CXX != LangStandard::lang_unspecified) + return CLANG_DEFAULT_STD_CXX; + if (T.isDriverKit()) return LangStandard::lang_gnucxx17; else return LangStandard::lang_gnucxx14; -#endif case Language::RenderScript: return LangStandard::lang_c99; case Language::HIP: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 2e27094 - [clang] Include clang config.h in LangStandards.cpp
Author: Cassie Jones Date: 2022-05-14T01:47:41-07:00 New Revision: 2e270947963659cf9db4099f42387144feb10fec URL: https://github.com/llvm/llvm-project/commit/2e270947963659cf9db4099f42387144feb10fec DIFF: https://github.com/llvm/llvm-project/commit/2e270947963659cf9db4099f42387144feb10fec.diff LOG: [clang] Include clang config.h in LangStandards.cpp This is necessary in order to pick up the default C/C++ standard from the CLANG_DEFAULT_STD_C(XX) defines. This fixes a bug that was introduced when this default language standard code was moved from Frontend to Basic, making compilers ignore the configured default language version override. Fixes a bug introduced by D121375. Reviewed By: hokein, dexonsmith Differential Revision: https://reviews.llvm.org/D124974 Added: Modified: clang/lib/Basic/LangStandards.cpp Removed: diff --git a/clang/lib/Basic/LangStandards.cpp b/clang/lib/Basic/LangStandards.cpp index 11599cf96b33a..6643af38ba01c 100644 --- a/clang/lib/Basic/LangStandards.cpp +++ b/clang/lib/Basic/LangStandards.cpp @@ -7,6 +7,7 @@ //===--===// #include "clang/Basic/LangStandard.h" +#include "clang/Config/config.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Triple.h" #include "llvm/Support/ErrorHandling.h" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits