PPC 32-bit _SIZE_TYPE__ macro
Testcase:
#include<stdio.h>
typedef unsigned short size_t;
int main() {
printf("Hehe");
}
Compile options:
clang --target=ppc32 size_t.c
or
clang -c --target=ppc32 size_t.c -dM -E | grep SIZE_TYPE
Error:
<source>:2:24: error: typedef redefinition with different types ('unsigned short' vs 'unsigned long')
typedef unsigned short size_t;
^
/opt/clang/15.0.0/include/stddef.h:46:23: note: previous definition is here
typedef __SIZE_TYPE__ size_t;
^
1 error generated.
Compiler returned: 1
The __SIZE_TYPE__ macro is defined as unsigned long on PPC 32-bit (with it being 4 bytes wide, same as unsigned int). Is there any specific reason as to why PPC 32-bit is using long instead of int? ARM 32-bit and X86 both use int (again, all cases are 4 bytes wide).
Looking at https://github.com/llvm/llvm-project/blob/llvmorg-14.0.4/clang/lib/Basic/Targets/PPC.h#L376 and https://github.com/llvm/llvm-project/blob/llvmorg-14.0.4/clang/lib/Basic/Targets/PPC.h#L381 it would make sense to me that __SIZE_TYPE__ would be unsigned int on Linux, but that's not the case.
Summary: Is the fact that SizeType is UnsignedLong on the llvm::Triple::Linux, instead of UnsignedInt a bug or something intended?
"--target=ppc32" is baremetal, not Linux. I doubt anyone has thought about the right default for baremetal PPC.
(To target Linux, you'd normally use something like "--target=powerpc-linux-gnu".)
That makes sense, thank you.
I assume the default SizeType, for ppc32 baremetal, comes from Basic/TargetInfo.cpp, right? In which cases, it is UnsignedLong.
Do you think a fix should be in place to change ppc32 to unsigned int?
Defaulting to unsigned int probably makes sense? Well, unless there's some existing baremetal PPC libraries that expect it to be unsigned long. Not sure what's out there.
The freestanding supplement to the Power Architecture 32-bit Application Binary Interface Supplement 1.0 - Embedded has this on page 95:
The following integer types are defined in headers required to be provided by freestanding implementations, or have their limits defined in such headers, and shall have the following definitions. Note: Freestanding implementations need not provide the types
sig_atomic_tandwint_t.
typedef int ptrdiff_t;typedef unsigned int size_t;
GCC for the 32-bit powerpc-eabi target defines __SIZE_TYPE__ as specified above, so that suggests the Clang __SIZE_TYPE__ definition for the same target should change to match. (Otherwise C++ symbols involving the type will mange differently.)
@llvm/issue-subscribers-clang-frontend
Issue can be closed and same is fixed in alteast
clang -c --target=ppc32-linux test.c -dM -E | grep SIZE_TYPE
#define SIZE_TYPE unsigned int $clang --version clang version 16.0.0.1 Target: x86_64-unknown-linux-elf Thread model: posix