[clang] f53f2f2 - Extend ptr32 support to be applied on typedef
Author: Ariel Burton Date: 2022-08-09T11:08:52-04:00 New Revision: f53f2f232f794a257c270f4c273b9c9000421c81 URL: https://github.com/llvm/llvm-project/commit/f53f2f232f794a257c270f4c273b9c9000421c81 DIFF: https://github.com/llvm/llvm-project/commit/f53f2f232f794a257c270f4c273b9c9000421c81.diff LOG: Extend ptr32 support to be applied on typedef Earlier, if the QualType was sugared, then we would error out as it was not a pointer type, for example, typedef int *int_star; int_star __ptr32 p; Now, if ptr32 is given we apply it if the raw Canonical Type (i.e., the desugared type) is a PointerType, instead of only checking whether the sugared type is a pointer type. As before, we still disallow ptr32 usage if the pointer is used as a pointer to a member. Differential Revision: https://reviews.llvm.org/D130123 Added: Modified: clang/lib/Sema/SemaType.cpp clang/test/CodeGen/address-space-ptr32.c clang/test/Sema/MicrosoftExtensions.c clang/test/Sema/MicrosoftExtensions.cpp Removed: diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 11a6715cd9d21..14b2d2e74f3f2 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -7158,17 +7158,25 @@ static bool handleMSPointerTypeQualifierAttr(TypeProcessingState &State, } std::bitset Attrs; - attr::Kind NewAttrKind = A->getKind(); QualType Desugared = Type; - const AttributedType *AT = dyn_cast(Type); - while (AT) { + for (;;) { +if (const TypedefType *TT = dyn_cast(Desugared)) { + Desugared = TT->desugar(); + continue; +} else if (const ElaboratedType *ET = dyn_cast(Desugared)) { + Desugared = ET->desugar(); + continue; +} +const AttributedType *AT = dyn_cast(Desugared); +if (!AT) + break; Attrs[AT->getAttrKind()] = true; Desugared = AT->getModifiedType(); -AT = dyn_cast(Desugared); } // You cannot specify duplicate type attributes, so if the attribute has // already been applied, flag it. + attr::Kind NewAttrKind = A->getKind(); if (Attrs[NewAttrKind]) { S.Diag(PAttr.getLoc(), diag::warn_duplicate_attribute_exact) << PAttr; return true; @@ -7189,14 +7197,11 @@ static bool handleMSPointerTypeQualifierAttr(TypeProcessingState &State, return true; } - // Pointer type qualifiers can only operate on pointer types, but not - // pointer-to-member types. - // - // FIXME: Should we really be disallowing this attribute if there is any - // type sugar between it and the pointer (other than attributes)? Eg, this - // disallows the attribute on a parenthesized pointer. - // And if so, should we really allow *any* type attribute? + // Check the raw (i.e., desugared) Canonical type to see if it + // is a pointer type. if (!isa(Desugared)) { +// Pointer type qualifiers can only operate on pointer types, but not +// pointer-to-member types. if (Type->isMemberPointerType()) S.Diag(PAttr.getLoc(), diag::err_attribute_no_member_pointers) << PAttr; else diff --git a/clang/test/CodeGen/address-space-ptr32.c b/clang/test/CodeGen/address-space-ptr32.c index a2914e39bee4d..618db6906351d 100644 --- a/clang/test/CodeGen/address-space-ptr32.c +++ b/clang/test/CodeGen/address-space-ptr32.c @@ -1,10 +1,40 @@ // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-windows-msvc -fms-extensions -emit-llvm < %s | FileCheck %s +_Static_assert(sizeof(void *) == 8, "sizeof(void *) has unexpected value. Expected 8."); + int foo(void) { + // CHECK: define dso_local i32 @foo + // CHECK: %a = alloca i32 (i32) addrspace(270)*, align 4 + // CHECK: ret i32 4 int (*__ptr32 a)(int); return sizeof(a); } -// CHECK: define dso_local i32 @foo -// CHECK: %a = alloca i32 (i32) addrspace(270)*, align 4 -// CHECK: ret i32 4 +int bar(void) { + // CHECK: define dso_local i32 @bar + // CHECK: %p = alloca i32 addrspace(270)*, align 4 + // CHECK: ret i32 4 + int *__ptr32 p; + return sizeof(p); +} + + +int baz(void) { + // CHECK: define dso_local i32 @baz + // CHECK: %p = alloca i32 addrspace(270)*, align 4 + // CHECK: ret i32 4 + typedef int *__ptr32 IP32_PTR; + + IP32_PTR p; + return sizeof(p); +} + +int fugu(void) { + // CHECK: define dso_local i32 @fugu + // CHECK: %p = alloca i32 addrspace(270)*, align 4 + // CHECK: ret i32 4 + typedef int *int_star; + + int_star __ptr32 p; + return sizeof(p); +} diff --git a/clang/test/Sema/MicrosoftExtensions.c b/clang/test/Sema/MicrosoftExtensions.c index d0ca16269cceb..50077d9031488 100644 --- a/clang/test/Sema/MicrosoftExtensions.c +++ b/clang/test/Sema/MicrosoftExtensions.c @@ -173,8 +173,28 @@ int * __ptr32 __ptr32 wrong8; // expected-warning {{attribute '__ptr32' is alrea int *(__ptr32 __sptr wrong9); // expected-error {{'__sptr' attribute only applies to pointer arguments}} // expected-error {{'__ptr32' attribute only ap
[clang] f46c41f - [SystemZ][z/OS] fix lit test related to alignment
Author: Nancy Wang Date: 2021-03-23T13:15:19-04:00 New Revision: f46c41febb88182f172d0260b55bd17e4c690a43 URL: https://github.com/llvm/llvm-project/commit/f46c41febb88182f172d0260b55bd17e4c690a43 DIFF: https://github.com/llvm/llvm-project/commit/f46c41febb88182f172d0260b55bd17e4c690a43.diff LOG: [SystemZ][z/OS] fix lit test related to alignment This patch is to fix lit test case failure relate to alignment, on z/OS, maximum alignment value for 64 bit mode is 16 and also fixed clang/test/Layout/itanium-union-bitfield.cpp, attribute ((aligned(4))) is needed for bit-field member in Union for z/OS because single bit-field has one byte alignment, this will make sure size and alignment will be correct value on z/OS. Differential Revision: https://reviews.llvm.org/D98793 Added: Modified: clang/test/AST/alignas_maybe_odr_cleanup.cpp clang/test/CodeGen/PR5060-align.c clang/test/Layout/itanium-union-bitfield.cpp Removed: diff --git a/clang/test/AST/alignas_maybe_odr_cleanup.cpp b/clang/test/AST/alignas_maybe_odr_cleanup.cpp index 3adef4cba1440..ed34930e98a05 100644 --- a/clang/test/AST/alignas_maybe_odr_cleanup.cpp +++ b/clang/test/AST/alignas_maybe_odr_cleanup.cpp @@ -8,7 +8,7 @@ // RUN: | FileCheck %s struct FOO { - static const int vec_align_bytes = 32; + static const int vec_align_bytes = 16; void foo() { double a alignas(vec_align_bytes); ; @@ -17,7 +17,7 @@ struct FOO { // CHECK: | `-AlignedAttr {{.*}} alignas // CHECK-NEXT: | `-ConstantExpr {{.*}} 'int' -// CHECK-NEXT: | |-value: Int 32 +// CHECK-NEXT: | |-value: Int 16 // CHECK-NEXT: | `-ImplicitCastExpr {{.*}} 'int' // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'const int' lvalue Var {{.*}} 'vec_align_bytes' 'const int' non_odr_use_constant // CHECK-NEXT: `-NullStmt {{.*}} diff --git a/clang/test/CodeGen/PR5060-align.c b/clang/test/CodeGen/PR5060-align.c index 34293a933aa9e..6e65175a71155 100644 --- a/clang/test/CodeGen/PR5060-align.c +++ b/clang/test/CodeGen/PR5060-align.c @@ -1,13 +1,13 @@ // RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s -// CHECK: @foo.p = internal global i8 0, align 32 +// CHECK: @foo.p = internal global i8 0, align 16 char *foo(void) { - static char p __attribute__((aligned(32))); + static char p __attribute__((aligned(16))); return &p; } void bar(long n) { - // CHECK: align 32 - char p[n] __attribute__((aligned(32))); + // CHECK: align 16 + char p[n] __attribute__((aligned(16))); } diff --git a/clang/test/Layout/itanium-union-bitfield.cpp b/clang/test/Layout/itanium-union-bitfield.cpp index 961bf5b6f3b44..febfc46dfee54 100644 --- a/clang/test/Layout/itanium-union-bitfield.cpp +++ b/clang/test/Layout/itanium-union-bitfield.cpp @@ -1,15 +1,23 @@ // RUN: %clang_cc1 -emit-llvm-only -triple %itanium_abi_triple -fdump-record-layouts %s 2>/dev/null \ // RUN:| FileCheck %s +// On z/OS, a bit-field has single byte alignment. Add aligned(4) on z/OS so the union has +// the same size & alignment as expected. +#ifdef __MVS__ +#define ALIGN4 __attribute__((aligned(4))) +#else +#define ALIGN4 +#endif + union A { - int f1: 3; + int f1 : 3 ALIGN4; A(); }; A::A() {} union B { - char f1: 35; + char f1 : 35 ALIGN4; B(); }; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 7e0cc45 - [SystemZ][z/OS] Save strings for CC_PRINT env vars
Author: Sean Perry Date: 2021-03-26T16:38:36-04:00 New Revision: 7e0cc45ced230b4ef3a9d8eaedfbe92e75f21916 URL: https://github.com/llvm/llvm-project/commit/7e0cc45ced230b4ef3a9d8eaedfbe92e75f21916 DIFF: https://github.com/llvm/llvm-project/commit/7e0cc45ced230b4ef3a9d8eaedfbe92e75f21916.diff LOG: [SystemZ][z/OS] Save strings for CC_PRINT env vars The contents of the string returned by getenv() is not guaranteed across calls to getenv(). The code to handle the CC_PRINT etc env vars calls getenv() and saves the results in just a char *. The string returned by getenv() needs to be copied and saved. Switching the type of the strings from char * to std::string will do this and manage the alloated memory. Differential Revision: https://reviews.llvm.org/D98554 Added: Modified: clang/include/clang/Driver/Driver.h clang/lib/Driver/Compilation.cpp clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/tools/driver/driver.cpp Removed: diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h index 54c20620910b3..469c000c952ca 100644 --- a/clang/include/clang/Driver/Driver.h +++ b/clang/include/clang/Driver/Driver.h @@ -157,16 +157,16 @@ class Driver { std::string HostBits, HostMachine, HostSystem, HostRelease; /// The file to log CC_PRINT_PROC_STAT_FILE output to, if enabled. - const char *CCPrintStatReportFilename; + std::string CCPrintStatReportFilename; /// The file to log CC_PRINT_OPTIONS output to, if enabled. - const char *CCPrintOptionsFilename; + std::string CCPrintOptionsFilename; /// The file to log CC_PRINT_HEADERS output to, if enabled. - const char *CCPrintHeadersFilename; + std::string CCPrintHeadersFilename; /// The file to log CC_LOG_DIAGNOSTICS output to, if enabled. - const char *CCLogDiagnosticsFilename; + std::string CCLogDiagnosticsFilename; /// A list of inputs and their types for the given arguments. typedef SmallVector, 16> diff --git a/clang/lib/Driver/Compilation.cpp b/clang/lib/Driver/Compilation.cpp index d330557390804..f28c23a59940d 100644 --- a/clang/lib/Driver/Compilation.cpp +++ b/clang/lib/Driver/Compilation.cpp @@ -170,10 +170,11 @@ int Compilation::ExecuteCommand(const Command &C, // Follow gcc implementation of CC_PRINT_OPTIONS; we could also cache the // output stream. -if (getDriver().CCPrintOptions && getDriver().CCPrintOptionsFilename) { +if (getDriver().CCPrintOptions && +!getDriver().CCPrintOptionsFilename.empty()) { std::error_code EC; OwnedStream.reset(new llvm::raw_fd_ostream( - getDriver().CCPrintOptionsFilename, EC, + getDriver().CCPrintOptionsFilename.c_str(), EC, llvm::sys::fs::OF_Append | llvm::sys::fs::OF_Text)); if (EC) { getDriver().Diag(diag::err_drv_cc_print_options_failure) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 0918ea455811c..171d3d5b5b88c 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -135,14 +135,13 @@ Driver::Driver(StringRef ClangExecutable, StringRef TargetTriple, : Diags(Diags), VFS(std::move(VFS)), Mode(GCCMode), SaveTemps(SaveTempsNone), BitcodeEmbed(EmbedNone), LTOMode(LTOK_None), ClangExecutable(ClangExecutable), SysRoot(DEFAULT_SYSROOT), - DriverTitle(Title), CCPrintStatReportFilename(nullptr), - CCPrintOptionsFilename(nullptr), CCPrintHeadersFilename(nullptr), - CCLogDiagnosticsFilename(nullptr), CCCPrintBindings(false), - CCPrintOptions(false), CCPrintHeaders(false), CCLogDiagnostics(false), - CCGenDiagnostics(false), CCPrintProcessStats(false), - TargetTriple(TargetTriple), CCCGenericGCCName(""), Saver(Alloc), - CheckInputsExist(true), GenReproducer(false), - SuppressMissingInputWarning(false) { + DriverTitle(Title), CCPrintStatReportFilename(), CCPrintOptionsFilename(), + CCPrintHeadersFilename(), CCLogDiagnosticsFilename(), + CCCPrintBindings(false), CCPrintOptions(false), CCPrintHeaders(false), + CCLogDiagnostics(false), CCGenDiagnostics(false), + CCPrintProcessStats(false), TargetTriple(TargetTriple), + CCCGenericGCCName(""), Saver(Alloc), CheckInputsExist(true), + GenReproducer(false), SuppressMissingInputWarning(false) { // Provide a sane fallback if no VFS is specified. if (!this->VFS) this->VFS = llvm::vfs::getRealFileSystem(); @@ -4057,7 +4056,7 @@ void Driver::BuildJobs(Compilation &C) const { else LinkingOutput = getDefaultImageName(); - if (!CCPrintStatReportFilename) { + if (CCPrintStatReportFilename.empty()) { using namespace llvm; // Human readable output. outs() << sys::path::filename(Cmd.getExecutable()) << ": " @@ -4080,7 +4079,7 @@ void Driver::BuildJobs(Compilation &C) const { << '\n';