From 628fc8476a3ae11d3db92fca44fe5b6d2b512812 Mon Sep 17 00:00:00 2001 From: Uwe Dolinsky Date: Mon, 4 Aug 2025 19:35:36 +0100 Subject: [PATCH 1/3] [NATIEVCPU] fix for assert re datalayout --- clang/lib/Basic/Targets/NativeCPU.cpp | 16 ++++++++++++++-- clang/lib/Basic/Targets/NativeCPU.h | 3 +++ .../CodeGenSYCL/native_cpu_target_features.cpp | 5 +++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/NativeCPU.cpp b/clang/lib/Basic/Targets/NativeCPU.cpp index 4fdc8661a47c5..b1ef0031b7b37 100644 --- a/clang/lib/Basic/Targets/NativeCPU.cpp +++ b/clang/lib/Basic/Targets/NativeCPU.cpp @@ -62,8 +62,6 @@ NativeCPUTargetInfo::NativeCPUTargetInfo(const llvm::Triple &Triple, resetDataLayout("e"); } else { HostTarget = AllocateTarget(HostTriple, Opts); - copyAuxTarget(&*HostTarget); - resetDataLayout(HostTarget->getDataLayoutString()); } } @@ -73,3 +71,17 @@ void NativeCPUTargetInfo::setAuxTarget(const TargetInfo *Aux) { getTargetOpts() = Aux->getTargetOpts(); resetDataLayout(Aux->getDataLayoutString()); } + +// A target may initialise its DataLayoutString and potentially other features in +// in `handleTargetFeatures` (as opposed to its constructor), so we can only +// copy the features and query DataLayoutString after that function was called. +bool NativeCPUTargetInfo::handleTargetFeatures( + std::vector &Features, DiagnosticsEngine &Diags) { + if (HostTarget) { + if (!HostTarget->handleTargetFeatures(Features, Diags)) + return false; + copyAuxTarget(&*HostTarget); + resetDataLayout(HostTarget->getDataLayoutString()); + } + return true; +} diff --git a/clang/lib/Basic/Targets/NativeCPU.h b/clang/lib/Basic/Targets/NativeCPU.h index cb2c71ebe39be..92981a5fd701f 100644 --- a/clang/lib/Basic/Targets/NativeCPU.h +++ b/clang/lib/Basic/Targets/NativeCPU.h @@ -56,6 +56,9 @@ class LLVM_LIBRARY_VISIBILITY NativeCPUTargetInfo final : public TargetInfo { return TargetInfo::checkCallingConvention(CC); } + bool handleTargetFeatures(std::vector &Features, + DiagnosticsEngine &Diags) override; + protected: void setAuxTarget(const TargetInfo *Aux) override; diff --git a/clang/test/CodeGenSYCL/native_cpu_target_features.cpp b/clang/test/CodeGenSYCL/native_cpu_target_features.cpp index 61df1a9e4f071..8e5596b91c76e 100644 --- a/clang/test/CodeGenSYCL/native_cpu_target_features.cpp +++ b/clang/test/CodeGenSYCL/native_cpu_target_features.cpp @@ -5,6 +5,11 @@ // This is not sensible but check that we do not crash. // RUN: %clang_cc1 -triple native_cpu -aux-triple native_cpu -fsycl-is-device -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,NOX86,NOAVX +// Ensures NativeCPU does not cause a compiler assert when querying the host +// target's DataLayoutString, which used to happen on ARM which initializes +// DataLayoutString not in its constructor but afterwards. +// RUN: %clang_cc1 -cc1 -fsycl-is-device -triple native_cpu -aux-triple aarch64-arm-none-eabi -emit-llvm-bc -o %t %s + #include "Inputs/sycl.hpp" using namespace sycl; From 892fc72f6a69b4465e367eaf15eb939a49ee4248 Mon Sep 17 00:00:00 2001 From: Uwe Dolinsky Date: Mon, 4 Aug 2025 20:10:53 +0100 Subject: [PATCH 2/3] [NATIVECPU] removed unneded cc1 --- clang/test/CodeGenSYCL/native_cpu_target_features.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/CodeGenSYCL/native_cpu_target_features.cpp b/clang/test/CodeGenSYCL/native_cpu_target_features.cpp index 8e5596b91c76e..0d6162ff6d282 100644 --- a/clang/test/CodeGenSYCL/native_cpu_target_features.cpp +++ b/clang/test/CodeGenSYCL/native_cpu_target_features.cpp @@ -8,7 +8,7 @@ // Ensures NativeCPU does not cause a compiler assert when querying the host // target's DataLayoutString, which used to happen on ARM which initializes // DataLayoutString not in its constructor but afterwards. -// RUN: %clang_cc1 -cc1 -fsycl-is-device -triple native_cpu -aux-triple aarch64-arm-none-eabi -emit-llvm-bc -o %t %s +// RUN: %clang_cc1 -fsycl-is-device -triple native_cpu -aux-triple aarch64-arm-none-eabi -emit-llvm-bc -o %t %s #include "Inputs/sycl.hpp" using namespace sycl; From bb5b3e947a4aacaa30234fd5e828d4f10287ef76 Mon Sep 17 00:00:00 2001 From: Uwe Dolinsky Date: Tue, 5 Aug 2025 10:18:16 +0100 Subject: [PATCH 3/3] [NATIVECPU] format fix --- clang/lib/Basic/Targets/NativeCPU.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 clang/lib/Basic/Targets/NativeCPU.cpp diff --git a/clang/lib/Basic/Targets/NativeCPU.cpp b/clang/lib/Basic/Targets/NativeCPU.cpp old mode 100644 new mode 100755 index b1ef0031b7b37..9f2e126d1e15c --- a/clang/lib/Basic/Targets/NativeCPU.cpp +++ b/clang/lib/Basic/Targets/NativeCPU.cpp @@ -72,7 +72,7 @@ void NativeCPUTargetInfo::setAuxTarget(const TargetInfo *Aux) { resetDataLayout(Aux->getDataLayoutString()); } -// A target may initialise its DataLayoutString and potentially other features in +// A target may initialise its DataLayoutString and potentially other features // in `handleTargetFeatures` (as opposed to its constructor), so we can only // copy the features and query DataLayoutString after that function was called. bool NativeCPUTargetInfo::handleTargetFeatures(