<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/68700>68700</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] Wrong LLVM IR code for 'static' function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
pbalasubramanian-amd
</td>
</tr>
</table>
<pre>
Wrong LLVM IR code is generated for clang trunk.
>clang version 18.0.0 (https://github.com/llvm/llvm-project.git ac0dda894231e6281e7739aa0ea01a4e9697c747)
>Target: x86_64-unknown-linux-gnu
In the following test case, 'if' condition is failed and 'abort()' should not be called. But it is wrongly called in IR code.
**Compiler options used:** -O3 -emit-llvm -c -S
**Test case:**
```void abort(void);
struct s1 { double d; };
struct s2 { double d; };
union u { struct s1 x; struct s2 y; };
static double f(struct s1 *a, struct s2 *b)
//double f(struct s1 *a, struct s2 *b)
{
a->d = 1.0;
return b->d + 1.0;
}
int main()
{
union u a;
a.x.d = 0.0;
if (f (&a.x, &a.y) != 2.0)
abort ();
return 0;
}
```
**LLVM IR:**
Here 'abort()' is wrongly called in IR code.
```define dso_local i32 @main() local_unnamed_addr #0 !dbg !10 {
call void @llvm.dbg.value(metadata double 1.000000e+00, metadata !16, metadata !DIExpression()), !dbg !28
tail call void @abort() #3, !dbg !29
unreachable, !dbg !29
}
```
> [!NOTE]
> Without 'static' declaration, it is generating correct llvm IR code.
> ```
> define dso_local i32 @main() local_unnamed_addr #1 !dbg !38 {
> call void @llvm.dbg.value(metadata double 1.000000e+00, metadata !43, metadata !DIExpression()), !dbg !48
> ret i32 0, !dbg !49
> }
> ```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVllv4zYQ_jX0y8ACRco6HvwQrx10gW0XaBfdx2AkjmR2adKgqMT59wVly1fSK6ghSDA5x_d9Mzyw73VniZZssWKL9QyHsHV-ua_RYD_UHndoNdo57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