Issue 144312
Summary [Clang] C++ Modules: Setting section attribute on variable in module causes miscompilation
Labels clang
Assignees
Reporter Gurah
    Setting the output section of a variable by attribute in a module interface causes miscompilation. 
Code works fine if not using c++ modules or if removing section attribute.

**Example**
test.ccm:
```
export module test;

int foo  __attribute__((section(".data.foo"))) = 2;

export int get_foo()
{
	return foo;
}

export void set_foo(int val)
{
	foo = val;
}

```
main.cc:
```
import test;

int main()
{
	set_foo(5);
	return get_foo();
}
```

Compile and run:
clang++ -std=c++23 -O1 -c test.ccm -fmodule-output=test.pcm
clang++ -std=c++23 -O1 -c main.cc -fmodule-file=test=test.pcm
clang++ test.o main.o -o test
./test
echo $?

**Expected result:**
5

**Actual result:**
2

**Clang version**
clang++ --version
clang version 19.1.7
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to