Skip to content

[Sema] Fix format-strings test on 32-bit Arm#178450

Merged
luporl merged 1 commit intollvm:mainfrom
luporl:fix-arm-tests
Jan 29, 2026
Merged

[Sema] Fix format-strings test on 32-bit Arm#178450
luporl merged 1 commit intollvm:mainfrom
luporl:fix-arm-tests

Conversation

@luporl
Copy link
Copy Markdown
Contributor

@luporl luporl commented Jan 28, 2026

No description provided.

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jan 28, 2026
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Jan 28, 2026

@llvm/pr-subscribers-clang

Author: Leandro Lupori (luporl)

Changes

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

1 Files Affected:

  • (modified) clang/test/Sema/format-strings.c (+10)
diff --git a/clang/test/Sema/format-strings.c b/clang/test/Sema/format-strings.c
index cdac83fc0bb91..3a2c2701cfcfc 100644
--- a/clang/test/Sema/format-strings.c
+++ b/clang/test/Sema/format-strings.c
@@ -3,10 +3,12 @@
 // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -triple=x86_64-unknown-fuchsia %s
 // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -triple=x86_64-linux-android %s
 
+#include <limits.h>
 #include <stdarg.h>
 #include <stddef.h>
 #define __need_wint_t
 #include <stddef.h> // For wint_t and wchar_t
+#include <stdint.h>
 
 typedef struct _FILE FILE;
 int fprintf(FILE *, const char *restrict, ...);
@@ -986,8 +988,16 @@ void test_promotion(void) {
 
 void test_bool(_Bool b, _Bool* bp)
 {
+#if SIZE_MAX != UINT_MAX
   printf("%zu", b); // expected-warning-re{{format specifies type 'size_t' (aka '{{.+}}') but the argument has type '_Bool'}}
+#else
+  printf("%zu", b); // no-warning
+#endif
+#if PTRDIFF_MAX != INT_MAX
   printf("%td", b); // expected-warning-re{{format specifies type 'ptrdiff_t' (aka '{{.+}}') but the argument has type '_Bool'}}
+#else
+  printf("%td", b); // no-warning
+#endif
   printf("%jd", b); // expected-warning-re{{format specifies type 'intmax_t' (aka '{{.+}}') but the argument has type '_Bool'}}
   printf("%lld", b); // expected-warning{{format specifies type 'long long' but the argument has type '_Bool'}}
   printf("%ld", b); // expected-warning{{format specifies type 'long' but the argument has type '_Bool'}}

@luporl
Copy link
Copy Markdown
Contributor Author

luporl commented Jan 29, 2026

I'm merging this PR to fix the buildbots. If necessary, the tests can be improved later.

@luporl luporl merged commit 312078b into llvm:main Jan 29, 2026
12 checks passed
@luporl luporl deleted the fix-arm-tests branch January 29, 2026 13:45
honeygoyal pushed a commit to honeygoyal/llvm-project that referenced this pull request Jan 30, 2026
sshrestha-aa pushed a commit to sshrestha-aa/llvm-project that referenced this pull request Feb 4, 2026
@azhan92
Copy link
Copy Markdown
Contributor

azhan92 commented Feb 6, 2026

This PR is causing the test to fail on AIX: https://lab.llvm.org/buildbot/#/builders/64/builds/7039

It seems that the warning still occurs even when size_t/ptrdiff_t have the same size as int:

File /home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/Sema/format-strings.c Line 994: format specifies type 'size_t' (aka 'unsigned long') but the argument has type '_Bool'
# |   File /home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/Sema/format-strings.c Line 999: format specifies type 'ptrdiff_t' (aka 'long') but the argument has type '_Bool'
# | 2 errors generated.

@luporl
Copy link
Copy Markdown
Contributor Author

luporl commented Feb 6, 2026

This PR is causing the test to fail on AIX: https://lab.llvm.org/buildbot/#/builders/64/builds/7039

It seems that the warning still occurs even when size_t/ptrdiff_t have the same size as int:

File /home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/Sema/format-strings.c Line 994: format specifies type 'size_t' (aka 'unsigned long') but the argument has type '_Bool'
# |   File /home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/Sema/format-strings.c Line 999: format specifies type 'ptrdiff_t' (aka 'long') but the argument has type '_Bool'
# | 2 errors generated.

Interesting. It seems both int and long have 64 bits on AIX, but since they are different types the warning still occurs.

Does the following work on AIX?

#if SIZE_MAX > UINT_MAX || UINT_MAX == ULONG_MAX
  printf("%zu", b); // expected-warning-re{{format specifies type 'size_t' (aka '{{.+}}') but the argument has type '_Bool'}}
#else
  printf("%zu", b); // no-warning
#endif
#if PTRDIFF_MAX > INT_MAX || INT_MAX == LONG_MAX
  printf("%td", b); // expected-warning-re{{format specifies type 'ptrdiff_t' (aka '{{.+}}') but the argument has type '_Bool'}}
#else
  printf("%td", b); // no-warning
#endif

@azhan92
Copy link
Copy Markdown
Contributor

azhan92 commented Feb 6, 2026

This PR is causing the test to fail on AIX: https://lab.llvm.org/buildbot/#/builders/64/builds/7039
It seems that the warning still occurs even when size_t/ptrdiff_t have the same size as int:

File /home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/Sema/format-strings.c Line 994: format specifies type 'size_t' (aka 'unsigned long') but the argument has type '_Bool'
# |   File /home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/Sema/format-strings.c Line 999: format specifies type 'ptrdiff_t' (aka 'long') but the argument has type '_Bool'
# | 2 errors generated.

Interesting. It seems both int and long have 64 bits on AIX, but since they are different types the warning still occurs.

Does the following work on AIX?

#if SIZE_MAX > UINT_MAX || UINT_MAX == ULONG_MAX
  printf("%zu", b); // expected-warning-re{{format specifies type 'size_t' (aka '{{.+}}') but the argument has type '_Bool'}}
#else
  printf("%zu", b); // no-warning
#endif
#if PTRDIFF_MAX > INT_MAX || INT_MAX == LONG_MAX
  printf("%td", b); // expected-warning-re{{format specifies type 'ptrdiff_t' (aka '{{.+}}') but the argument has type '_Bool'}}
#else
  printf("%td", b); // no-warning
#endif

Thanks, yes it does.

@luporl
Copy link
Copy Markdown
Contributor Author

luporl commented Feb 9, 2026

@azhan92 It should be fixed by #180566.
Unfortunately, the code snippet above doesn't work for ARMv7.
The condition was getting too complicated, so I just skipped the warnings for 32-bit Arm.

@azhan92
Copy link
Copy Markdown
Contributor

azhan92 commented Feb 9, 2026

@azhan92 It should be fixed by #180566. Unfortunately, the code snippet above doesn't work for ARMv7. The condition was getting too complicated, so I just skipped the warnings for 32-bit Arm.

Thanks for the fix.

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.

3 participants