[clang] [X86] [iamcu] Fix wrong alignment value for attr (aligned) with -miamcu (PR #80401)

via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 2 00:11:07 PST 2024


https://github.com/joyhou-hw created https://github.com/llvm/llvm-project/pull/80401

attribute ((aligned)) should be 4 for -miamcu.

relate: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66818

>From 02bb222e186b91c918f2375460e8e3bee2e75eb8 Mon Sep 17 00:00:00 2001
From: houzhenyu <houzhenyu at huawei.com>
Date: Fri, 2 Feb 2024 11:21:50 +0800
Subject: [PATCH] [X86] [iamcu] Fix wrong alignment value for attr (aligned)
 with -miamcu

attribute ((aligned)) should be 4 for -miamcu.
---
 clang/lib/Basic/Targets/X86.h  |  1 +
 clang/test/Sema/attr-aligned.c | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 1845f5a747af4..0adb1f3eacecb 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -634,6 +634,7 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_32TargetInfo : public X86_32TargetInfo {
       : X86_32TargetInfo(Triple, Opts) {
     this->WCharType = TargetInfo::UnsignedShort;
     DoubleAlign = LongLongAlign = 64;
+    DefaultAlignForAttributeAligned = 32;
     resetDataLayout("e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-"
                     "i128:128-f80:32-n8:16:32-a:0:32-S32",
                     "_");
diff --git a/clang/test/Sema/attr-aligned.c b/clang/test/Sema/attr-aligned.c
index 130840d46650d..b285ce3d0ed78 100644
--- a/clang/test/Sema/attr-aligned.c
+++ b/clang/test/Sema/attr-aligned.c
@@ -1,4 +1,12 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple i586-intel-elfiamcu -fsyntax-only -verify %s
+
+#ifdef __iamcu
+// expected-no-diagnostics
+struct dummy { int x __attribute__((aligned));  };
+int m0[__alignof__(struct dummy) == 4 ? 1 : -1];
+
+#else
 
 int x __attribute__((aligned(3))); // expected-error {{requested alignment is not a power of 2}}
 int y __attribute__((aligned(1ull << 33))); // expected-error {{requested alignment must be 4294967296 bytes or smaller}}
@@ -60,3 +68,5 @@ array_with_overaligned_struct F2;
 char f2[__alignof__(F2) == 16 ? 1 : -1] = { 0 };
 array_with_align_attr F3;
 char f3[__alignof__(F3) == 16 ? 1 : -1] = { 0 };
+
+#endif



More information about the cfe-commits mailing list