llvm / llvm/llvm-project

Offloading handles invalid mode attributes incorrectly

Open
#216,334 5 comments 0 reactions 0 assignees View on GitHub
clang:codegen clang:frontend confirmed cuda miscompilation openmp SYCL
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The semantic handling for `mode` has a special carve-out for failures on offloading devices: https://github.com/llvm/llvm-project/blob/81ac5c7c26efb70ffaffb91b26053437093ee085/clang/lib/Sema/SemaDeclAttr.cpp#L5228

However, as discovered during review of https://github.com/llvm/llvm-project/pull/214497, nothing ends up diagnosing the invalid mode. Instead, the attribute is dropped on the floor and we just codegen with whatever the underlying type is without the mode attribute. e.g., https://godbolt.org/z/rYG9KqhbK

```c
typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));

[[clang::sycl_external]]
void sef() {
__cfloat128 __attribute__ ((__mode__ (__TC__))) a;
}
```

if you look at the IR produced, you'll see:

```llvm
define spir_func void @_Z3sefv() #0 !dbg !6 {
%a = alloca { float, float }, align 4
```

so we're allocating a pair of 32-bit floats instead of a pair of 128-bit floats.

Contributor guide

Open the contributing guide

Research direction

Start in clang/lib/Sema/SemaDeclAttr.cpp around the linked mode-attribute handling, then reproduce the issue with the provided C example and inspect its generated LLVM IR. Trace why the invalid mode on an offloading device is dropped without a diagnostic; done means the invalid attribute is diagnosed instead of silently codegening with the underlying type.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.