Skip to content

[clang][test] Try to fix Sema/format-strings.c on i686#181800

Merged
tbaederr merged 1 commit intollvm:mainfrom
tbaederr:format-strings
Feb 23, 2026
Merged

[clang][test] Try to fix Sema/format-strings.c on i686#181800
tbaederr merged 1 commit intollvm:mainfrom
tbaederr:format-strings

Conversation

@tbaederr
Copy link
Copy Markdown
Contributor

#180566 did this for 32bit arm, but this still breaks for us downstream on i686 with:

# .---command stderr------------
# | error: 'expected-warning' diagnostics expected but not seen: 
# |   File /builddir/build/BUILD/llvm-project/clang/test/Sema/format-strings.c Line 990: format specifies type 'size_t' (aka '{{.+}}') but the argument has type '_Bool'
# |   File /builddir/build/BUILD/llvm-project/clang/test/Sema/format-strings.c Line 991: format specifies type 'ptrdiff_t' (aka '{{.+}}') but the argument has type '_Bool'
# | 2 errors generated.
# `-----------------------------

@tbaederr tbaederr requested review from azhan92 and luporl February 17, 2026 11:10
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Feb 17, 2026
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Feb 17, 2026

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

#180566 did this for 32bit arm, but this still breaks for us downstream on i686 with:

# .---command stderr------------
# | error: 'expected-warning' diagnostics expected but not seen: 
# |   File /builddir/build/BUILD/llvm-project/clang/test/Sema/format-strings.c Line 990: format specifies type 'size_t' (aka '{{.+}}') but the argument has type '_Bool'
# |   File /builddir/build/BUILD/llvm-project/clang/test/Sema/format-strings.c Line 991: format specifies type 'ptrdiff_t' (aka '{{.+}}') but the argument has type '_Bool'
# | 2 errors generated.
# `-----------------------------

Full diff: https://github.com/llvm/llvm-project/pull/181800.diff

1 Files Affected:

  • (modified) clang/test/Sema/format-strings.c (+1-1)
diff --git a/clang/test/Sema/format-strings.c b/clang/test/Sema/format-strings.c
index 07bac7095ee82..96159afefebd7 100644
--- a/clang/test/Sema/format-strings.c
+++ b/clang/test/Sema/format-strings.c
@@ -986,7 +986,7 @@ void test_promotion(void) {
 
 void test_bool(_Bool b, _Bool* bp)
 {
-#ifndef __arm__
+#ifdef __LP64__
   printf("%zu", b); // expected-warning-re{{format specifies type 'size_t' (aka '{{.+}}') but the argument has type '_Bool'}}
   printf("%td", b); // expected-warning-re{{format specifies type 'ptrdiff_t' (aka '{{.+}}') but the argument has type '_Bool'}}
 #else

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 17, 2026

🪟 Windows x64 Test Results

  • 54285 tests passed
  • 2302 tests skipped

✅ The build succeeded and all tests passed.

@tbaederr tbaederr force-pushed the format-strings branch 2 times, most recently from 54ca20a to 9df0b64 Compare February 17, 2026 13:21
void test_bool(_Bool b, _Bool* bp)
{
#ifndef __arm__
#if defined(__LP64__) || defined(_WIN32)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for ARMv7 and AArch64, but I'm not sure about AIX.

Although I don't have AIX hardware to test this PR, I had a previous fix that failed on AIX because it has 64-bit integers and longs, so it seems to be ILP64 instead of LP64, and the warnings are displayed on it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just hardcode all triples this test should run with and drop any run lines using the default triple?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a good option to me, to avoid unintentionally breaking other platforms. But I only fixed a failure on 32-bit Arm buildbots, caused by this test. I also don't know which triples this test should be run with.

Perhaps @YexuanXiao, @cor3ntin, and @zyn0217 can give better feedback on this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the Clang preprocessor defines convenient SIZEOF macros, so we can write this as #if __SIZEOF_INT__ != __SIZEOF_SIZE_T__. I think that should be robust.

I checked that this works for all of -triple=powerpc64-ibm-aix-xcoff, -triple=i686-unknown-linux-gnu, -triple=x86_64-pc-windows-msvc and -triple=i686-pc-windows-msvc.

The current check in this PR fails on -triple=i686-pc-windows-msvc.

@YexuanXiao
Copy link
Copy Markdown
Contributor

I didn't realize at the time that these two lines of tests were invalid on so many platforms. To avoid potential failures, I think it's acceptable to limit them to triples known to produce warnings.

Comment on lines 992 to 994
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Remove the #else.

It looks like the originally problematic triple was powerpc-ibm-aix, where the warning occurs despite the types having the same size, because they're still different types. We should just omit these no-warning lines to avoid the issue.

llvm#180566 did this for 32bit arm,
but this still breaks for us downstream on i686 with:
```
```
@tbaederr tbaederr merged commit 4c795db into llvm:main Feb 23, 2026
10 checks passed
HendrikHuebner pushed a commit to HendrikHuebner/llvm-project that referenced this pull request Mar 10, 2026
llvm#180566 did this for 32bit arm,
but this still breaks for us downstream on i686 with:
```
# .---command stderr------------
# | error: 'expected-warning' diagnostics expected but not seen: 
# |   File /builddir/build/BUILD/llvm-project/clang/test/Sema/format-strings.c Line 990: format specifies type 'size_t' (aka '{{.+}}') but the argument has type '_Bool'
# |   File /builddir/build/BUILD/llvm-project/clang/test/Sema/format-strings.c Line 991: format specifies type 'ptrdiff_t' (aka '{{.+}}') but the argument has type '_Bool'
# | 2 errors generated.
# `-----------------------------
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants