[all-commits] [llvm/llvm-project] 6bf6ba: [Clang][ARM][Sema] Check validity of ldrexd/strexd...

Douglas via All-commits all-commits at lists.llvm.org
Mon Oct 27 08:03:54 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6bf6babb30488df340337923573c562553128706
      https://github.com/llvm/llvm-project/commit/6bf6babb30488df340337923573c562553128706
  Author: Douglas <Douglas.Gliner at sony.com>
  Date:   2025-10-27 (Mon, 27 Oct 2025)

  Changed paths:
    M clang/include/clang/Basic/BuiltinsARM.def
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/Sema/SemaARM.cpp
    M clang/test/CodeGen/builtins-arm-exclusive.c
    M clang/test/CodeGenCXX/builtins-arm-exclusive.cpp
    M clang/test/Sema/builtins-arm-exclusive-124.c
    M clang/test/Sema/builtins-arm-exclusive-4.c
    M clang/test/Sema/builtins-arm-exclusive-none.c
    M clang/test/Sema/builtins-arm-exclusive.c

  Log Message:
  -----------
  [Clang][ARM][Sema] Check validity of ldrexd/strexd builtin calls (#164919)

This change enables validation checks against the following two ARM
atomic builtins:
```
__builtin_arm_ldrexd
__builtin_arm_strexd
```

Previously, no checks existed for these builtins, so under a release
compiler, it would be possible to emit `ldrexd`/`strexd` under ARM
targets which set the LDREX mask (returned via `getARMLDREXMask`) to
signify these as unsupported instructions.

For example, the following would compile with errors:
```c
> type atomics.c
long long func(void) {
    long long num = 0;
    __builtin_arm_strex(42, &num);
    return __builtin_arm_ldrex(&num);
}
```
```
> clang --target=armv7m-linux-gnueabi -S atomics.c -o -
atomics.c:3:5: error: address argument to load or store exclusive builtin must be a pointer to 1,2
      or 4 byte type ('volatile long long *' invalid)
    3 |     __builtin_arm_strex(42, &num);
      |     ^
atomics.c:4:12: error: address argument to load or store exclusive builtin must be a pointer to 1,2
      or 4 byte type ('const volatile long long *' invalid)
    4 |     return __builtin_arm_ldrex(&num);
      |            ^
2 errors generated.
```

However, a similar program would compile without errors:
```c
> type atomics.c
long long func(void) {
    long long num = 0;
    __builtin_arm_strexd(42, &num);
    return __builtin_arm_ldrexd(&num);
}
```
```
> clang --target=armv7m-linux-gnueabi -S atomics.c -o -
...
        strexd  r1, r2, r3, [r0]
        ldrexd  r0, r1, [r0]
...
```

With this change, we now have appropriate compile-time errors:
```
> clang --target=armv7m-linux-gnueabi -S atomics.c -o -
atomics.c:3:5: error: load and store exclusive builtins are not available on this architecture
    3 |     __builtin_arm_strexd(42, &num);
      |     ^                        ~~~~
atomics.c:4:12: error: load and store exclusive builtins are not available on this architecture
    4 |     return __builtin_arm_ldrexd(&num);
      |            ^                    ~~~~
2 errors generated.
```



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