[all-commits] [llvm/llvm-project] 2f217a: [WebAssembly] Preserve constness for imported glob...
Changqing Jing via All-commits
all-commits at lists.llvm.org
Tue Jun 9 13:07:59 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 2f217a67295c120d7b97c1d8d6df71f35ebbd109
https://github.com/llvm/llvm-project/commit/2f217a67295c120d7b97c1d8d6df71f35ebbd109
Author: Changqing Jing <changqing.jing at bmw.com>
Date: 2026-06-09 (Tue, 09 Jun 2026)
Changed paths:
M llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
M llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
M llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
M llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
A llvm/test/CodeGen/WebAssembly/immutable-global-alias.ll
A llvm/test/CodeGen/WebAssembly/imported-const-global.ll
A llvm/test/CodeGen/WebAssembly/invalid-wasm-global-function-alias.ll
A llvm/test/CodeGen/WebAssembly/invalid-wasm-global-symbol.ll
Log Message:
-----------
[WebAssembly] Preserve constness for imported globals (#199507)
This fixes a WebAssembly backend bug where imported `const` globals lose
their
constness during lowering.
For a source like:
```c++
extern "C" {
extern const int [[clang::address_space(1)]] imported_g;
int goo() { return imported_g; }
}
```
In current main branch, the imported_g is lowered to mutable import
global.
```
(module
(type (;0;) (func (result i32)))
(import "env" "imported_g" (global (;0;) (mut i32)))
(func (;0;) (type 0) (result i32)
global.get 0)
(table (;0;) 1 1 funcref)
(memory (;0;) 2)
(export "memory" (memory 0))
(export "goo" (func 0))
(export "__indirect_function_table" (table 0)))
```
The root cause is that wasm global mutability was hard-coded during
symbol
typing, so the backend ignored `GlobalVariable::isConstant()`. This
patch
threads mutability through wasm global symbol typing and derives it from
`!GV->isConstant()`.
Both the asm-printer path and the MCInst-lowering path are updated,
because
either of them may initialize the wasm symbol first.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list