Skip to content

[Clang][Wasm] Set __float128 alignment to 64 for emscripten #146494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Jul 1, 2025

https://reviews.llvm.org/D104808 set the alignment of long double to 64 bits. This is also the alignment specified in the LLVM data layout. However, the alignment of __float128 was left at 128 bits.

I assume that this was just an oversight, rather than an intentional divergence. The C ABI document currently does not make any statement about __float128: https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md

https://reviews.llvm.org/D104808 set the alignment of long double
to 64 bits. This is also the alignment specified in the LLVM data
layout. However, the alignment of __float128 was left at 128 bits.

I assume that this was just an oversight, rather than an intentional
divergence. The C ABI document currently does not make any statement
about `__float128`:
https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md
@nikic nikic requested review from sbc100 and sunfishcode July 1, 2025 09:28
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:codegen IR generation bugs: mangling, exceptions, etc. labels Jul 1, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 1, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Nikita Popov (nikic)

Changes

https://reviews.llvm.org/D104808 set the alignment of long double to 64 bits. This is also the alignment specified in the LLVM data layout. However, the alignment of __float128 was left at 128 bits.

I assume that this was just an oversight, rather than an intentional divergence. The C ABI document currently does not make any statement about __float128: https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md


Full diff: https://github.com/llvm/llvm-project/pull/146494.diff

2 Files Affected:

  • (modified) clang/lib/Basic/Targets/OSTargets.h (+1)
  • (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1-2)
diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h
index 5dac699c2bb45..30d861a7ca605 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -1002,6 +1002,7 @@ class LLVM_LIBRARY_VISIBILITY EmscriptenTargetInfo
     // Emscripten's ABI is unstable and we may change this back to 128 to match
     // the WebAssembly default in the future.
     this->LongDoubleAlign = 64;
+    this->Float128Align = 64;
   }
 };
 
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index e6d150f7e13d6..c8866f15745c2 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -388,8 +388,7 @@ static void checkDataLayoutConsistency(const TargetInfo &Target,
           llvm::Type::getFloatingPointTy(Context, *Target.LongDoubleFormat),
           Target.LongDoubleAlign);
   }
-  // FIXME: Wasm has a mismatch in f128 alignment between Clang and LLVM.
-  if (Target.hasFloat128Type() && !Triple.isWasm())
+  if (Target.hasFloat128Type())
     Check("__float128", llvm::Type::getFP128Ty(Context), Target.Float128Align);
   if (Target.hasIbm128Type())
     Check("__ibm128", llvm::Type::getPPC_FP128Ty(Context), Target.Ibm128Align);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen IR generation bugs: mangling, exceptions, etc. clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants