Currently when including stdbool.h and altivec.h declaration of vector bool leads to
errors due to bool being expanded to '_Bool`. This patch allows the parser
to recognize _Bool.
Details
- Reviewers
cebowleratibm hubert.reinterpretcast bmahjour uweigand Everybody0523 - Group Reviewers
Restricted Project Restricted Project - Commits
- rG8fa168fc50ba: Parse vector bool when stdbool.h and altivec.h are included
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/test/Parser/altivec-bool.c | ||
---|---|---|
11 ↗ | (On Diff #343641) | Do we not want the test case to provide a similar define to what stdbool.h does? |
clang/test/Parser/altivec-bool.c | ||
---|---|---|
11 ↗ | (On Diff #343641) | Is using eg adding cases such as: __vector _Bool char bc; what you meant? Added those in just now. |
- clean up code per comments
- Add test case for Z targets since that target is also affected
Minor nitpick, but is there a term that encompasses both the Z Vector syntax and altivec? Since the test checks both Z and PPC it's a little odd that the test's filename only references altivec.
This means the implementation now deviates from the documented vector extension syntax, right? I guess it's strictly an extension of the documented syntax, but that may still lead to incompatibilities with other compilers for the platform. If we want to make such a change, should it be synchronized with e.g. GCC, XL, etc. ?
GCC and XL already accept this syntax on Linux on Power and AIX.
For example this simple test case:
#include <stdbool.h> #include <altivec.h> vector bool char bc;
Can compile with GCC 9/10 and XLC 16.1 on Linux on Power. On AIX, GCC 8.3 on AIX and XLC 16.1 can also compile it successfully. Latest main trunk clang throws up an error on those platforms.
From offline conversation it looks like XLC on z/OS can also compile the test case. @Everybody0523 can confirm for sure.
Interesting. On Z using GCC I currently get this error:
vbool.c:2:1: error: invalid vector type for attribute ‘vector_size’ 2 | vector _Bool x;
But looking at the GCC sources, it seems we actually intended to support this use as well, there's just a bug. Given that, I think I'd be fine with adding this to LLVM -- I'll make sure the GCC bug gets fixed as well.
Thank you for looking at GCC on Z. That was the only case where I didn't have information from.
xlc on z/OS will compile
vector _Bool char bc;
on any language level high enough to recognize _Bool as a valid keyword.
LGTM with comment.
clang/test/Parser/altivec-zvector-bool.c | ||
---|---|---|
21–24 | I think having these as declarations of the names used above is beneficial because it confirms that the types formed using the bool spelling are compatible with the same using the _Bool spelling. |
But looking at the GCC sources, it seems we actually intended to support this use as well, there's just a bug. Given that, I think I'd be fine with adding this to LLVM -- I'll make sure the GCC bug gets fixed as well.
I've fixed the GCC issue now: https://gcc.gnu.org/pipermail/gcc-patches/2021-May/570561.html
Minor nit: remove (inconsistently applied) extra parentheses.