-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][AVR] Fix basic type size/alignment values to match avr-gcc. #111290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
cc @aykevl |
@llvm/pr-subscribers-clang Author: Alex Rønne Petersen (alexrp) ChangesCloses #102172. Full diff: https://github.com/llvm/llvm-project/pull/111290.diff 4 Files Affected:
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index 57783850606290..e7469e1e989128 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -87,6 +87,7 @@ enum class FloatModeKind {
struct TransferrableTargetInfo {
unsigned char PointerWidth, PointerAlign;
unsigned char BoolWidth, BoolAlign;
+ unsigned char ShortWidth, ShortAlign;
unsigned char IntWidth, IntAlign;
unsigned char HalfWidth, HalfAlign;
unsigned char BFloat16Width, BFloat16Align;
@@ -497,13 +498,10 @@ class TargetInfo : public TransferrableTargetInfo,
unsigned getCharWidth() const { return 8; } // FIXME
unsigned getCharAlign() const { return 8; } // FIXME
- /// Return the size of 'signed short' and 'unsigned short' for this
- /// target, in bits.
- unsigned getShortWidth() const { return 16; } // FIXME
-
- /// Return the alignment of 'signed short' and 'unsigned short' for
- /// this target.
- unsigned getShortAlign() const { return 16; } // FIXME
+ /// getShortWidth/Align - Return the size of 'signed short' and
+ /// 'unsigned short' for this target, in bits.
+ unsigned getShortWidth() const { return ShortWidth; }
+ unsigned getShortAlign() const { return ShortAlign; }
/// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
/// this target, in bits.
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 92195333821097..145ca545854da7 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -70,6 +70,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
HasStrictFP = false;
PointerWidth = PointerAlign = 32;
BoolWidth = BoolAlign = 8;
+ ShortWidth = ShortAlign = 16;
IntWidth = IntAlign = 32;
LongWidth = LongAlign = 32;
LongLongWidth = LongLongAlign = 64;
@@ -437,6 +438,7 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
// what these normally are for the target.
// We also define long long and long double here, although the
// OpenCL standard only mentions these as "reserved".
+ ShortWidth = ShortAlign = 16;
IntWidth = IntAlign = 32;
LongWidth = LongAlign = 64;
LongLongWidth = LongLongAlign = 128;
diff --git a/clang/lib/Basic/Targets/AVR.h b/clang/lib/Basic/Targets/AVR.h
index feeb04f37eeba7..0a2f51747f8a7f 100644
--- a/clang/lib/Basic/Targets/AVR.h
+++ b/clang/lib/Basic/Targets/AVR.h
@@ -29,6 +29,8 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo {
TLSSupported = false;
PointerWidth = 16;
PointerAlign = 8;
+ ShortWidth = 16;
+ ShortAlign = 8;
IntWidth = 16;
IntAlign = 8;
LongWidth = 32;
@@ -65,6 +67,8 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo {
return std::nullopt;
}
+ bool allowsLargerPreferedTypeAlignment() const override { return false; }
+
BuiltinVaListKind getBuiltinVaListKind() const override {
return TargetInfo::VoidPtrBuiltinVaList;
}
diff --git a/clang/test/Sema/avr-size-align.c b/clang/test/Sema/avr-size-align.c
new file mode 100644
index 00000000000000..9fe94410c91c49
--- /dev/null
+++ b/clang/test/Sema/avr-size-align.c
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 %s -triple avr -fsyntax-only
+
+_Static_assert(sizeof(char) == 1, "sizeof(char) == 1");
+_Static_assert(_Alignof(char) == 1, "_Alignof(char) == 1");
+_Static_assert(__alignof(char) == 1, "__alignof(char) == 1");
+
+_Static_assert(sizeof(short) == 2, "sizeof(short) == 2");
+_Static_assert(_Alignof(short) == 1, "_Alignof(short) == 1");
+_Static_assert(__alignof(short) == 1, "__alignof(short) == 1");
+
+_Static_assert(sizeof(unsigned short) == 2, "sizeof(unsigned short) == 2");
+_Static_assert(_Alignof(unsigned short) == 1, "_Alignof(unsigned short) == 1");
+_Static_assert(__alignof(unsigned short) == 1, "__alignof(unsigned short) == 1");
+
+_Static_assert(sizeof(int) == 2, "sizeof(int) == 2");
+_Static_assert(_Alignof(int) == 1, "_Alignof(int) == 1");
+_Static_assert(__alignof(int) == 1, "__alignof(int) == 1");
+
+_Static_assert(sizeof(unsigned int) == 2, "sizeof(unsigned int) == 2");
+_Static_assert(_Alignof(unsigned int) == 1, "_Alignof(unsigned int) == 1");
+_Static_assert(__alignof(unsigned int) == 1, "__alignof(unsigned int) == 1");
+
+_Static_assert(sizeof(long) == 4, "sizeof(long) == 4");
+_Static_assert(_Alignof(long) == 1, "_Alignof(long) == 1");
+_Static_assert(__alignof(long) == 1, "__alignof(long) == 1");
+
+_Static_assert(sizeof(unsigned long) == 4, "sizeof(unsigned long) == 4");
+_Static_assert(_Alignof(unsigned long) == 1, "_Alignof(unsigned long) == 1");
+_Static_assert(__alignof(unsigned long) == 1, "__alignof(unsigned long) == 1");
+
+_Static_assert(sizeof(long long) == 8, "sizeof(long long) == 8");
+_Static_assert(_Alignof(long long) == 1, "_Alignof(long long) == 1");
+_Static_assert(__alignof(long long) == 1, "__alignof(long long) == 1");
+
+_Static_assert(sizeof(unsigned long long) == 8, "sizeof(unsigned long long) == 8");
+_Static_assert(_Alignof(unsigned long long) == 1, "_Alignof(unsigned long long) == 1");
+_Static_assert(__alignof(unsigned long long) == 1, "__alignof(unsigned long long) == 1");
+
+_Static_assert(sizeof(float) == 4, "sizeof(float) == 4");
+_Static_assert(_Alignof(float) == 1, "_Alignof(float) == 1");
+_Static_assert(__alignof(float) == 1, "__alignof(float) == 1");
+
+_Static_assert(sizeof(double) == 4, "sizeof(double) == 4");
+_Static_assert(_Alignof(double) == 1, "_Alignof(double) == 1");
+_Static_assert(__alignof(double) == 1, "__alignof(double) == 1");
+
+_Static_assert(sizeof(long double) == 4, "sizeof(long double) == 4");
+_Static_assert(_Alignof(long double) == 1, "_Alignof(long double) == 1");
+_Static_assert(__alignof(long double) == 1, "__alignof(long double) == 1");
|
ebf2d15
to
fae208b
Compare
ping |
fae208b
to
20fd5ea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with this code, but this looks reasonable to me.
@benshi001 can you also take a look?
Also CC @Patryk27
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me as well!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/27/builds/809 Here is the relevant piece of the build log for the reference
|
Closes #102172.
Note: I don't have commit access.