From beea2a941470368a87b1816e455b1db366c1bbb9 Mon Sep 17 00:00:00 2001 From: "Yaxun (Sam) Liu" Date: Wed, 9 Jul 2025 08:53:10 -0400 Subject: [Clang] Respect MS layout attributes during CUDA/HIP device compilation (#146620) This patch fixes an issue where Microsoft-specific layout attributes, such as __declspec(empty_bases), were ignored during CUDA/HIP device compilation on a Windows host. This caused a critical memory layout mismatch between host and device objects, breaking libraries that rely on these attributes for ABI compatibility. The fix introduces a centralized hasMicrosoftRecordLayout() check within the TargetInfo class. This check is aware of the auxiliary (host) target and is set during TargetInfo::adjust if the host uses a Microsoft ABI. The empty_bases, layout_version, and msvc::no_unique_address attributes now use this centralized flag, ensuring device code respects them and maintains layout consistency with the host. Fixes: https://github.com/llvm/llvm-project/issues/146047 --- clang/lib/Frontend/CompilerInstance.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'clang/lib/Frontend/CompilerInstance.cpp') diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 09a66b6..6f8cc01 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -148,7 +148,7 @@ bool CompilerInstance::createTarget() { // Inform the target of the language options. // FIXME: We shouldn't need to do this, the target should be immutable once // created. This complexity should be lifted elsewhere. - getTarget().adjust(getDiagnostics(), getLangOpts()); + getTarget().adjust(getDiagnostics(), getLangOpts(), getAuxTarget()); if (auto *Aux = getAuxTarget()) getTarget().setAuxTarget(Aux); @@ -454,7 +454,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { getSourceManager(), *HeaderInfo, *this, /*IdentifierInfoLookup=*/nullptr, /*OwnsHeaderSearch=*/true, TUKind); - getTarget().adjust(getDiagnostics(), getLangOpts()); + getTarget().adjust(getDiagnostics(), getLangOpts(), getAuxTarget()); PP->Initialize(getTarget(), getAuxTarget()); if (PPOpts.DetailedRecord) -- cgit v1.1