[clang] [clang] Update -Wformat warnings for fixed-point format specifiers (PR #82855)
petrhosek wrote: > Do you know a libc implementation that actually implements `%k` `%r` and who > are the potential users? From a quick glance, gcc avr supports fixed-point > types but avr-libc doesn't seem to support %k %r. LLVM-libc will support them soon, PR should be coming next week. We have internal customers at Google that are starting to use fixed-point types in their embedded products. https://github.com/llvm/llvm-project/pull/82855 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add new flag -Wreturn-mismatch (PR #82872)
https://github.com/11happy created https://github.com/llvm/llvm-project/pull/82872 **Overview:** This pull request fixes #72116 where a new flag is introduced for compatibility with GCC 14, the functionality of -Wreturn-type is modified to split some of its behaviors into -Wreturn-mismatch **Testing:** - Tested the updated code. - Verified that other functionalities remain unaffected.  - Sample working: ``` int foo(int x){ x = 1; return; } ```  **Dependencies:** - No dependencies on other pull requests. >From 557ee75d60f0fdb4dd2b353c819b4f22f71b46d7 Mon Sep 17 00:00:00 2001 From: 11happy Date: Sat, 24 Feb 2024 13:50:30 +0530 Subject: [PATCH] add new flag -Wreturn-mismatch Signed-off-by: 11happy --- clang/include/clang/Basic/DiagnosticGroups.td| 1 + clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 +++--- clang/test/Analysis/null-deref-ps.c | 4 ++-- clang/test/CodeGen/statements.c | 2 +- clang/test/CodeGen/volatile-1.c | 2 +- clang/test/Sema/return-silent.c | 2 +- clang/test/Sema/return.c | 2 +- 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 6765721ae7002c..7a786a24083583 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -607,6 +607,7 @@ def RedundantMove : DiagGroup<"redundant-move">; def Register : DiagGroup<"register", [DeprecatedRegister]>; def ReturnTypeCLinkage : DiagGroup<"return-type-c-linkage">; def ReturnType : DiagGroup<"return-type", [ReturnTypeCLinkage]>; +def ReturnMismatch : DiagGroup<"return-mismatch">; def BindToTemporaryCopy : DiagGroup<"bind-to-temporary-copy", [CXX98CompatBindToTemporaryCopy]>; def SelfAssignmentField : DiagGroup<"self-assign-field">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 24d32cb87c89e2..7057b4b2123671 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10212,14 +10212,14 @@ def warn_second_parameter_to_va_arg_never_compatible : Warning< def warn_return_missing_expr : Warning< "non-void %select{function|method}1 %0 should return a value">, DefaultError, - InGroup; + InGroup; def ext_return_missing_expr : ExtWarn< "non-void %select{function|method}1 %0 should return a value">, DefaultError, - InGroup; + InGroup; def ext_return_has_expr : ExtWarn< "%select{void function|void method|constructor|destructor}1 %0 " "should not return a value">, - DefaultError, InGroup; + DefaultError, InGroup; def ext_return_has_void_expr : Extension< "void %select{function|method|block}1 %0 should not return void expression">; def err_return_init_list : Error< diff --git a/clang/test/Analysis/null-deref-ps.c b/clang/test/Analysis/null-deref-ps.c index d80de15c05a3fe..2682ad02ee37f9 100644 --- a/clang/test/Analysis/null-deref-ps.c +++ b/clang/test/Analysis/null-deref-ps.c @@ -1,5 +1,5 @@ -// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion -Wno-strict-prototypes -Wno-tautological-constant-compare -Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core -std=gnu99 -analyzer-purge=none -verify %s -Wno-error=return-type -// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion -Wno-strict-prototypes -Wno-tautological-constant-compare -Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core -std=gnu99 -verify %s -Wno-error=return-type +// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion -Wno-strict-prototypes -Wno-tautological-constant-compare -Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core -std=gnu99 -analyzer-purge=none -verify %s -Wno-error=return-type -Wno-error=return-mismatch +// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion -Wno-strict-prototypes -Wno-tautological-constant-compare -Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core -std=gnu99 -verify %s -Wno-error=return-type -Wno-error=return-mismatch typedef unsigned uintptr_t; diff --git a/clang/test/CodeGen/statements.c b/clang/test/CodeGen/statements.c index 07ae075d6d807e..76f4f254dfd1dc 100644 --- a/clang/test/CodeGen/statements.c +++ b/clang/test/CodeGen/statements.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -Wno-error=return-type -Wno-error=int-conversion %s -emit-llvm-only +// RUN: %clang_cc1 -Wno-error=return-type -Wno-error=return-mismatch -Wno-erro
[clang] Add new flag -Wreturn-mismatch (PR #82872)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Bhuminjay Soni (11happy) Changes **Overview:** This pull request fixes #72116 where a new flag is introduced for compatibility with GCC 14, the functionality of -Wreturn-type is modified to split some of its behaviors into -Wreturn-mismatch **Testing:** - Tested the updated code. - Verified that other functionalities remain unaffected.  - Sample working: ``` int foo(int x){ x = 1; return; } ```  **Dependencies:** - No dependencies on other pull requests. --- Full diff: https://github.com/llvm/llvm-project/pull/82872.diff 7 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticGroups.td (+1) - (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+3-3) - (modified) clang/test/Analysis/null-deref-ps.c (+2-2) - (modified) clang/test/CodeGen/statements.c (+1-1) - (modified) clang/test/CodeGen/volatile-1.c (+1-1) - (modified) clang/test/Sema/return-silent.c (+1-1) - (modified) clang/test/Sema/return.c (+1-1) ``diff diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 6765721ae7002c..7a786a24083583 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -607,6 +607,7 @@ def RedundantMove : DiagGroup<"redundant-move">; def Register : DiagGroup<"register", [DeprecatedRegister]>; def ReturnTypeCLinkage : DiagGroup<"return-type-c-linkage">; def ReturnType : DiagGroup<"return-type", [ReturnTypeCLinkage]>; +def ReturnMismatch : DiagGroup<"return-mismatch">; def BindToTemporaryCopy : DiagGroup<"bind-to-temporary-copy", [CXX98CompatBindToTemporaryCopy]>; def SelfAssignmentField : DiagGroup<"self-assign-field">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 24d32cb87c89e2..7057b4b2123671 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10212,14 +10212,14 @@ def warn_second_parameter_to_va_arg_never_compatible : Warning< def warn_return_missing_expr : Warning< "non-void %select{function|method}1 %0 should return a value">, DefaultError, - InGroup; + InGroup; def ext_return_missing_expr : ExtWarn< "non-void %select{function|method}1 %0 should return a value">, DefaultError, - InGroup; + InGroup; def ext_return_has_expr : ExtWarn< "%select{void function|void method|constructor|destructor}1 %0 " "should not return a value">, - DefaultError, InGroup; + DefaultError, InGroup; def ext_return_has_void_expr : Extension< "void %select{function|method|block}1 %0 should not return void expression">; def err_return_init_list : Error< diff --git a/clang/test/Analysis/null-deref-ps.c b/clang/test/Analysis/null-deref-ps.c index d80de15c05a3fe..2682ad02ee37f9 100644 --- a/clang/test/Analysis/null-deref-ps.c +++ b/clang/test/Analysis/null-deref-ps.c @@ -1,5 +1,5 @@ -// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion -Wno-strict-prototypes -Wno-tautological-constant-compare -Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core -std=gnu99 -analyzer-purge=none -verify %s -Wno-error=return-type -// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion -Wno-strict-prototypes -Wno-tautological-constant-compare -Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core -std=gnu99 -verify %s -Wno-error=return-type +// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion -Wno-strict-prototypes -Wno-tautological-constant-compare -Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core -std=gnu99 -analyzer-purge=none -verify %s -Wno-error=return-type -Wno-error=return-mismatch +// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -Wno-int-conversion -Wno-strict-prototypes -Wno-tautological-constant-compare -Wtautological-unsigned-zero-compare -analyzer-checker=core,deadcode,alpha.core -std=gnu99 -verify %s -Wno-error=return-type -Wno-error=return-mismatch typedef unsigned uintptr_t; diff --git a/clang/test/CodeGen/statements.c b/clang/test/CodeGen/statements.c index 07ae075d6d807e..76f4f254dfd1dc 100644 --- a/clang/test/CodeGen/statements.c +++ b/clang/test/CodeGen/statements.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -Wno-error=return-type -Wno-error=int-conversion %s -emit-llvm-only +// RUN: %clang_cc1 -Wno-error=return-type -Wno-error=return-mismatch -Wno-error=int-conversion %s -emit-llvm-only // REQUIRES: LP64 // Mismatched type between return and function result. diff --git a/clang/test/CodeGen/vola
[clang] fix unnecessary warning when using bitand with boolean operators (PR #81976)
11happy wrote: Humble Ping! https://github.com/llvm/llvm-project/pull/81976 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)
SimplyDanny wrote: For some reason, the designators on Windows come without the prepended dot. Instead, there is a NULL character in front. Very unclear to me why this is ... Anyway, the performed normalization seems to fix the inconsistency. The last build was successful. https://github.com/llvm/llvm-project/pull/80541 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] constify or staticify some fns (PR #82874)
https://github.com/urnathan created https://github.com/llvm/llvm-project/pull/82874 As mentioned in PR https://github.com/llvm/llvm-project/pull/65742, these functions do not alter the object -- and on one case don't even need it. Thus marking them static or const as appropriate. I constified a few more than I'd originally fallen over. >From ccc917e8a826bbefcd68df4e013edbd97bb19914 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Fri, 2 Feb 2024 08:01:21 -0500 Subject: [PATCH] [clang][NFC] constify or staticify some fns These functions do not alter the object -- and on one case don't even need it. Thus marking them static or const as appropriate. --- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 28 ++--- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp index 868ef810f3c4e8..7822903b89ce47 100644 --- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -95,7 +95,7 @@ struct CGRecordLowering { CGRecordLowering(CodeGenTypes &Types, const RecordDecl *D, bool Packed); // Short helper routines. /// Constructs a MemberInfo instance from an offset and llvm::Type *. - MemberInfo StorageInfo(CharUnits Offset, llvm::Type *Data) { + static MemberInfo StorageInfo(CharUnits Offset, llvm::Type *Data) { return MemberInfo(Offset, MemberInfo::Field, Data); } @@ -104,7 +104,7 @@ struct CGRecordLowering { /// fields of the same formal type. We want to emit a layout with /// these discrete storage units instead of combining them into a /// continuous run. - bool isDiscreteBitFieldABI() { + bool isDiscreteBitFieldABI() const { return Context.getTargetInfo().getCXXABI().isMicrosoft() || D->isMsStruct(Context); } @@ -121,22 +121,22 @@ struct CGRecordLowering { /// other bases, which complicates layout in specific ways. /// /// Note specifically that the ms_struct attribute doesn't change this. - bool isOverlappingVBaseABI() { + bool isOverlappingVBaseABI() const { return !Context.getTargetInfo().getCXXABI().isMicrosoft(); } /// Wraps llvm::Type::getIntNTy with some implicit arguments. - llvm::Type *getIntNType(uint64_t NumBits) { + llvm::Type *getIntNType(uint64_t NumBits) const { unsigned AlignedBits = llvm::alignTo(NumBits, Context.getCharWidth()); return llvm::Type::getIntNTy(Types.getLLVMContext(), AlignedBits); } /// Get the LLVM type sized as one character unit. - llvm::Type *getCharType() { + llvm::Type *getCharType() const { return llvm::Type::getIntNTy(Types.getLLVMContext(), Context.getCharWidth()); } /// Gets an llvm type of size NumChars and alignment 1. - llvm::Type *getByteArrayType(CharUnits NumChars) { + llvm::Type *getByteArrayType(CharUnits NumChars) const { assert(!NumChars.isZero() && "Empty byte arrays aren't allowed."); llvm::Type *Type = getCharType(); return NumChars == CharUnits::One() ? Type : @@ -144,7 +144,7 @@ struct CGRecordLowering { } /// Gets the storage type for a field decl and handles storage /// for itanium bitfields that are smaller than their declared type. - llvm::Type *getStorageType(const FieldDecl *FD) { + llvm::Type *getStorageType(const FieldDecl *FD) const { llvm::Type *Type = Types.ConvertTypeForMem(FD->getType()); if (!FD->isBitField()) return Type; if (isDiscreteBitFieldABI()) return Type; @@ -152,29 +152,29 @@ struct CGRecordLowering { (unsigned)Context.toBits(getSize(Type; } /// Gets the llvm Basesubobject type from a CXXRecordDecl. - llvm::Type *getStorageType(const CXXRecordDecl *RD) { + llvm::Type *getStorageType(const CXXRecordDecl *RD) const { return Types.getCGRecordLayout(RD).getBaseSubobjectLLVMType(); } - CharUnits bitsToCharUnits(uint64_t BitOffset) { + CharUnits bitsToCharUnits(uint64_t BitOffset) const { return Context.toCharUnitsFromBits(BitOffset); } - CharUnits getSize(llvm::Type *Type) { + CharUnits getSize(llvm::Type *Type) const { return CharUnits::fromQuantity(DataLayout.getTypeAllocSize(Type)); } - CharUnits getAlignment(llvm::Type *Type) { + CharUnits getAlignment(llvm::Type *Type) const { return CharUnits::fromQuantity(DataLayout.getABITypeAlign(Type)); } - bool isZeroInitializable(const FieldDecl *FD) { + bool isZeroInitializable(const FieldDecl *FD) const { return Types.isZeroInitializable(FD->getType()); } - bool isZeroInitializable(const RecordDecl *RD) { + bool isZeroInitializable(const RecordDecl *RD) const { return Types.isZeroInitializable(RD); } void appendPaddingBytes(CharUnits Size) { if (!Size.isZero()) FieldTypes.push_back(getByteArrayType(Size)); } - uint64_t getFieldBitOffset(const FieldDecl *FD) { + uint64_t getFieldBitOffset(const FieldDecl *FD) const { retur
[clang] [clang][NFC] constify or staticify some fns (PR #82874)
llvmbot wrote: @llvm/pr-subscribers-clang-codegen Author: Nathan Sidwell (urnathan) Changes As mentioned in PR https://github.com/llvm/llvm-project/pull/65742, these functions do not alter the object -- and on one case don't even need it. Thus marking them static or const as appropriate. I constified a few more than I'd originally fallen over. --- Full diff: https://github.com/llvm/llvm-project/pull/82874.diff 1 Files Affected: - (modified) clang/lib/CodeGen/CGRecordLayoutBuilder.cpp (+14-14) ``diff diff --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp index 868ef810f3c4e8..7822903b89ce47 100644 --- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -95,7 +95,7 @@ struct CGRecordLowering { CGRecordLowering(CodeGenTypes &Types, const RecordDecl *D, bool Packed); // Short helper routines. /// Constructs a MemberInfo instance from an offset and llvm::Type *. - MemberInfo StorageInfo(CharUnits Offset, llvm::Type *Data) { + static MemberInfo StorageInfo(CharUnits Offset, llvm::Type *Data) { return MemberInfo(Offset, MemberInfo::Field, Data); } @@ -104,7 +104,7 @@ struct CGRecordLowering { /// fields of the same formal type. We want to emit a layout with /// these discrete storage units instead of combining them into a /// continuous run. - bool isDiscreteBitFieldABI() { + bool isDiscreteBitFieldABI() const { return Context.getTargetInfo().getCXXABI().isMicrosoft() || D->isMsStruct(Context); } @@ -121,22 +121,22 @@ struct CGRecordLowering { /// other bases, which complicates layout in specific ways. /// /// Note specifically that the ms_struct attribute doesn't change this. - bool isOverlappingVBaseABI() { + bool isOverlappingVBaseABI() const { return !Context.getTargetInfo().getCXXABI().isMicrosoft(); } /// Wraps llvm::Type::getIntNTy with some implicit arguments. - llvm::Type *getIntNType(uint64_t NumBits) { + llvm::Type *getIntNType(uint64_t NumBits) const { unsigned AlignedBits = llvm::alignTo(NumBits, Context.getCharWidth()); return llvm::Type::getIntNTy(Types.getLLVMContext(), AlignedBits); } /// Get the LLVM type sized as one character unit. - llvm::Type *getCharType() { + llvm::Type *getCharType() const { return llvm::Type::getIntNTy(Types.getLLVMContext(), Context.getCharWidth()); } /// Gets an llvm type of size NumChars and alignment 1. - llvm::Type *getByteArrayType(CharUnits NumChars) { + llvm::Type *getByteArrayType(CharUnits NumChars) const { assert(!NumChars.isZero() && "Empty byte arrays aren't allowed."); llvm::Type *Type = getCharType(); return NumChars == CharUnits::One() ? Type : @@ -144,7 +144,7 @@ struct CGRecordLowering { } /// Gets the storage type for a field decl and handles storage /// for itanium bitfields that are smaller than their declared type. - llvm::Type *getStorageType(const FieldDecl *FD) { + llvm::Type *getStorageType(const FieldDecl *FD) const { llvm::Type *Type = Types.ConvertTypeForMem(FD->getType()); if (!FD->isBitField()) return Type; if (isDiscreteBitFieldABI()) return Type; @@ -152,29 +152,29 @@ struct CGRecordLowering { (unsigned)Context.toBits(getSize(Type; } /// Gets the llvm Basesubobject type from a CXXRecordDecl. - llvm::Type *getStorageType(const CXXRecordDecl *RD) { + llvm::Type *getStorageType(const CXXRecordDecl *RD) const { return Types.getCGRecordLayout(RD).getBaseSubobjectLLVMType(); } - CharUnits bitsToCharUnits(uint64_t BitOffset) { + CharUnits bitsToCharUnits(uint64_t BitOffset) const { return Context.toCharUnitsFromBits(BitOffset); } - CharUnits getSize(llvm::Type *Type) { + CharUnits getSize(llvm::Type *Type) const { return CharUnits::fromQuantity(DataLayout.getTypeAllocSize(Type)); } - CharUnits getAlignment(llvm::Type *Type) { + CharUnits getAlignment(llvm::Type *Type) const { return CharUnits::fromQuantity(DataLayout.getABITypeAlign(Type)); } - bool isZeroInitializable(const FieldDecl *FD) { + bool isZeroInitializable(const FieldDecl *FD) const { return Types.isZeroInitializable(FD->getType()); } - bool isZeroInitializable(const RecordDecl *RD) { + bool isZeroInitializable(const RecordDecl *RD) const { return Types.isZeroInitializable(RD); } void appendPaddingBytes(CharUnits Size) { if (!Size.isZero()) FieldTypes.push_back(getByteArrayType(Size)); } - uint64_t getFieldBitOffset(const FieldDecl *FD) { + uint64_t getFieldBitOffset(const FieldDecl *FD) const { return Layout.getFieldOffset(FD->getFieldIndex()); } // Layout routines. `` https://github.com/llvm/llvm-project/pull/82874 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cg
[clang] [clang][NFC] constify or staticify some fns (PR #82874)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Nathan Sidwell (urnathan) Changes As mentioned in PR https://github.com/llvm/llvm-project/pull/65742, these functions do not alter the object -- and on one case don't even need it. Thus marking them static or const as appropriate. I constified a few more than I'd originally fallen over. --- Full diff: https://github.com/llvm/llvm-project/pull/82874.diff 1 Files Affected: - (modified) clang/lib/CodeGen/CGRecordLayoutBuilder.cpp (+14-14) ``diff diff --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp index 868ef810f3c4e8..7822903b89ce47 100644 --- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -95,7 +95,7 @@ struct CGRecordLowering { CGRecordLowering(CodeGenTypes &Types, const RecordDecl *D, bool Packed); // Short helper routines. /// Constructs a MemberInfo instance from an offset and llvm::Type *. - MemberInfo StorageInfo(CharUnits Offset, llvm::Type *Data) { + static MemberInfo StorageInfo(CharUnits Offset, llvm::Type *Data) { return MemberInfo(Offset, MemberInfo::Field, Data); } @@ -104,7 +104,7 @@ struct CGRecordLowering { /// fields of the same formal type. We want to emit a layout with /// these discrete storage units instead of combining them into a /// continuous run. - bool isDiscreteBitFieldABI() { + bool isDiscreteBitFieldABI() const { return Context.getTargetInfo().getCXXABI().isMicrosoft() || D->isMsStruct(Context); } @@ -121,22 +121,22 @@ struct CGRecordLowering { /// other bases, which complicates layout in specific ways. /// /// Note specifically that the ms_struct attribute doesn't change this. - bool isOverlappingVBaseABI() { + bool isOverlappingVBaseABI() const { return !Context.getTargetInfo().getCXXABI().isMicrosoft(); } /// Wraps llvm::Type::getIntNTy with some implicit arguments. - llvm::Type *getIntNType(uint64_t NumBits) { + llvm::Type *getIntNType(uint64_t NumBits) const { unsigned AlignedBits = llvm::alignTo(NumBits, Context.getCharWidth()); return llvm::Type::getIntNTy(Types.getLLVMContext(), AlignedBits); } /// Get the LLVM type sized as one character unit. - llvm::Type *getCharType() { + llvm::Type *getCharType() const { return llvm::Type::getIntNTy(Types.getLLVMContext(), Context.getCharWidth()); } /// Gets an llvm type of size NumChars and alignment 1. - llvm::Type *getByteArrayType(CharUnits NumChars) { + llvm::Type *getByteArrayType(CharUnits NumChars) const { assert(!NumChars.isZero() && "Empty byte arrays aren't allowed."); llvm::Type *Type = getCharType(); return NumChars == CharUnits::One() ? Type : @@ -144,7 +144,7 @@ struct CGRecordLowering { } /// Gets the storage type for a field decl and handles storage /// for itanium bitfields that are smaller than their declared type. - llvm::Type *getStorageType(const FieldDecl *FD) { + llvm::Type *getStorageType(const FieldDecl *FD) const { llvm::Type *Type = Types.ConvertTypeForMem(FD->getType()); if (!FD->isBitField()) return Type; if (isDiscreteBitFieldABI()) return Type; @@ -152,29 +152,29 @@ struct CGRecordLowering { (unsigned)Context.toBits(getSize(Type; } /// Gets the llvm Basesubobject type from a CXXRecordDecl. - llvm::Type *getStorageType(const CXXRecordDecl *RD) { + llvm::Type *getStorageType(const CXXRecordDecl *RD) const { return Types.getCGRecordLayout(RD).getBaseSubobjectLLVMType(); } - CharUnits bitsToCharUnits(uint64_t BitOffset) { + CharUnits bitsToCharUnits(uint64_t BitOffset) const { return Context.toCharUnitsFromBits(BitOffset); } - CharUnits getSize(llvm::Type *Type) { + CharUnits getSize(llvm::Type *Type) const { return CharUnits::fromQuantity(DataLayout.getTypeAllocSize(Type)); } - CharUnits getAlignment(llvm::Type *Type) { + CharUnits getAlignment(llvm::Type *Type) const { return CharUnits::fromQuantity(DataLayout.getABITypeAlign(Type)); } - bool isZeroInitializable(const FieldDecl *FD) { + bool isZeroInitializable(const FieldDecl *FD) const { return Types.isZeroInitializable(FD->getType()); } - bool isZeroInitializable(const RecordDecl *RD) { + bool isZeroInitializable(const RecordDecl *RD) const { return Types.isZeroInitializable(RD); } void appendPaddingBytes(CharUnits Size) { if (!Size.isZero()) FieldTypes.push_back(getByteArrayType(Size)); } - uint64_t getFieldBitOffset(const FieldDecl *FD) { + uint64_t getFieldBitOffset(const FieldDecl *FD) const { return Layout.getFieldOffset(FD->getFieldIndex()); } // Layout routines. `` https://github.com/llvm/llvm-project/pull/82874 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/ma
[clang] [clang][NFC] constify or staticify some CGRecordLowering fns (PR #82874)
https://github.com/urnathan edited https://github.com/llvm/llvm-project/pull/82874 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add AlignConsecutiveTableGenCondOperatorColons option. (PR #82878)
https://github.com/hnakamura5 created https://github.com/llvm/llvm-project/pull/82878 To align colons inside TableGen !cond operators. >From d0ceab536cc9aa06ce5de1324eee1e3a05dac804 Mon Sep 17 00:00:00 2001 From: hnakamura5 Date: Sat, 24 Feb 2024 22:21:04 +0900 Subject: [PATCH] [clang-format] Add AlignConsecutiveTableGenCondOperatorColons option to align colons in tablegen cond operators. --- clang/docs/ClangFormatStyleOptions.rst| 140 ++ clang/include/clang/Format/Format.h | 12 ++ clang/lib/Format/Format.cpp | 3 + clang/lib/Format/WhitespaceManager.cpp| 18 ++- clang/lib/Format/WhitespaceManager.h | 8 + clang/unittests/Format/FormatTestTableGen.cpp | 21 +++ 6 files changed, 199 insertions(+), 3 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index fdf7bfaeaa4ec7..2cb55503038f66 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -955,6 +955,146 @@ the configuration (without a prefix: ``Auto``). } +.. _AlignConsecutiveTableGenCondOperatorColons: + +**AlignConsecutiveTableGenCondOperatorColons** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 19` :ref:`¶ ` + Style of aligning consecutive TableGen cond operator colons. + Align the colons of cases inside !cond operators. + + .. code-block:: c++ + +!cond(!eq(size, 1) : 1, + !eq(size, 16): 1, + true : 0) + + Nested configuration flags: + + Alignment options. + + They can also be read as a whole for compatibility. The choices are: + - None + - Consecutive + - AcrossEmptyLines + - AcrossComments + - AcrossEmptyLinesAndComments + + For example, to align across empty lines and not across comments, either + of these work. + + .. code-block:: c++ + +AlignConsecutiveMacros: AcrossEmptyLines + +AlignConsecutiveMacros: + Enabled: true + AcrossEmptyLines: true + AcrossComments: false + + * ``bool Enabled`` Whether aligning is enabled. + +.. code-block:: c++ + + #define SHORT_NAME 42 + #define LONGER_NAME 0x007f + #define EVEN_LONGER_NAME (2) + #define foo(x) (x * x) + #define bar(y, z)(y + z) + + int a= 1; + int somelongname = 2; + double c = 3; + + int : 1; + int b: 12; + int ccc : 8; + + int = 12; + float b = 23; + std::string ccc; + + * ``bool AcrossEmptyLines`` Whether to align across empty lines. + +.. code-block:: c++ + + true: + int a= 1; + int somelongname = 2; + double c = 3; + + int d= 3; + + false: + int a= 1; + int somelongname = 2; + double c = 3; + + int d = 3; + + * ``bool AcrossComments`` Whether to align across comments. + +.. code-block:: c++ + + true: + int d= 3; + /* A comment. */ + double e = 4; + + false: + int d = 3; + /* A comment. */ + double e = 4; + + * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments +like ``+=`` are aligned along with ``=``. + +.. code-block:: c++ + + true: + a &= 2; + bbb = 2; + + false: + a &= 2; + bbb = 2; + + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are +aligned. + +.. code-block:: c++ + + true: + unsigned i; + int &r; + int *p; + int (*f)(); + + false: + unsigned i; + int &r; + int *p; + int (*f)(); + + * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment +operators are left-padded to the same length as long ones in order to +put all assignment operators to the right of the left hand side. + +.. code-block:: c++ + + true: + a >>= 2; + bbb = 2; + + a = 2; + bbb >>= 2; + + false: + a >>= 2; + bbb = 2; + + a = 2; + bbb >>= 2; + + .. _AlignEscapedNewlines: **AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``) :versionbadge:`clang-format 5` :ref:`¶ ` diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index e9b2160a7b9243..11853d23f2b42b 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -414,6 +414,16 @@ struct FormatStyle { /// \version 17 ShortCaseStatementsAlignmentStyle AlignConsecutiveShortCaseStatements; + /// Style of aligning consecutive TableGen cond operator colons. + /// Align the colons of cases inside !cond operators. + /// \code + /// !cond(!eq(size, 1) : 1, + /// !eq(size, 16): 1, + /// true : 0) + /// \endcode + /// \version 19 + AlignConsecutiveStyle Alig
[clang] [clang-format] Add AlignConsecutiveTableGenCondOperatorColons option. (PR #82878)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: Hirofumi Nakamura (hnakamura5) Changes To align colons inside TableGen !cond operators. --- Full diff: https://github.com/llvm/llvm-project/pull/82878.diff 6 Files Affected: - (modified) clang/docs/ClangFormatStyleOptions.rst (+140) - (modified) clang/include/clang/Format/Format.h (+12) - (modified) clang/lib/Format/Format.cpp (+3) - (modified) clang/lib/Format/WhitespaceManager.cpp (+15-3) - (modified) clang/lib/Format/WhitespaceManager.h (+8) - (modified) clang/unittests/Format/FormatTestTableGen.cpp (+21) ``diff diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index fdf7bfaeaa4ec7..2cb55503038f66 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -955,6 +955,146 @@ the configuration (without a prefix: ``Auto``). } +.. _AlignConsecutiveTableGenCondOperatorColons: + +**AlignConsecutiveTableGenCondOperatorColons** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 19` :ref:`¶ ` + Style of aligning consecutive TableGen cond operator colons. + Align the colons of cases inside !cond operators. + + .. code-block:: c++ + +!cond(!eq(size, 1) : 1, + !eq(size, 16): 1, + true : 0) + + Nested configuration flags: + + Alignment options. + + They can also be read as a whole for compatibility. The choices are: + - None + - Consecutive + - AcrossEmptyLines + - AcrossComments + - AcrossEmptyLinesAndComments + + For example, to align across empty lines and not across comments, either + of these work. + + .. code-block:: c++ + +AlignConsecutiveMacros: AcrossEmptyLines + +AlignConsecutiveMacros: + Enabled: true + AcrossEmptyLines: true + AcrossComments: false + + * ``bool Enabled`` Whether aligning is enabled. + +.. code-block:: c++ + + #define SHORT_NAME 42 + #define LONGER_NAME 0x007f + #define EVEN_LONGER_NAME (2) + #define foo(x) (x * x) + #define bar(y, z)(y + z) + + int a= 1; + int somelongname = 2; + double c = 3; + + int : 1; + int b: 12; + int ccc : 8; + + int = 12; + float b = 23; + std::string ccc; + + * ``bool AcrossEmptyLines`` Whether to align across empty lines. + +.. code-block:: c++ + + true: + int a= 1; + int somelongname = 2; + double c = 3; + + int d= 3; + + false: + int a= 1; + int somelongname = 2; + double c = 3; + + int d = 3; + + * ``bool AcrossComments`` Whether to align across comments. + +.. code-block:: c++ + + true: + int d= 3; + /* A comment. */ + double e = 4; + + false: + int d = 3; + /* A comment. */ + double e = 4; + + * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments +like ``+=`` are aligned along with ``=``. + +.. code-block:: c++ + + true: + a &= 2; + bbb = 2; + + false: + a &= 2; + bbb = 2; + + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are +aligned. + +.. code-block:: c++ + + true: + unsigned i; + int &r; + int *p; + int (*f)(); + + false: + unsigned i; + int &r; + int *p; + int (*f)(); + + * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment +operators are left-padded to the same length as long ones in order to +put all assignment operators to the right of the left hand side. + +.. code-block:: c++ + + true: + a >>= 2; + bbb = 2; + + a = 2; + bbb >>= 2; + + false: + a >>= 2; + bbb = 2; + + a = 2; + bbb >>= 2; + + .. _AlignEscapedNewlines: **AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``) :versionbadge:`clang-format 5` :ref:`¶ ` diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index e9b2160a7b9243..11853d23f2b42b 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -414,6 +414,16 @@ struct FormatStyle { /// \version 17 ShortCaseStatementsAlignmentStyle AlignConsecutiveShortCaseStatements; + /// Style of aligning consecutive TableGen cond operator colons. + /// Align the colons of cases inside !cond operators. + /// \code + /// !cond(!eq(size, 1) : 1, + /// !eq(size, 16): 1, + /// true : 0) + /// \endcode + /// \version 19 + AlignConsecutiveStyle AlignConsecutiveTableGenCondOperatorColons; + /// Different styles for aligning escaped newlines. enum EscapedNewlineAlignmentStyle : int8_t { /// Don't align escaped newlines. @@ -4804,6 +4814,8
[clang] [clang-format] Support of TableGen formatting. (PR #76059)
hnakamura5 wrote: Alignment option for cond operator: https://github.com/llvm/llvm-project/pull/82878. https://github.com/llvm/llvm-project/pull/76059 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Extract Function: add hoisting support (PR #75533)
5chmidti wrote: Ping https://github.com/llvm/llvm-project/pull/75533 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] fix extract-to-function for overloaded operators (PR #81640)
5chmidti wrote: Ping https://github.com/llvm/llvm-project/pull/81640 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] remove (clang::)ast_matchers:: namespace from AST matcher args for docs (PR #81437)
5chmidti wrote: Ping https://github.com/llvm/llvm-project/pull/81437 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm-ar][Archive] Use getDefaultTargetTriple instead of host triple for the fallback archive format. (PR #82888)
https://github.com/cjacek created https://github.com/llvm/llvm-project/pull/82888 As suggested by @gbreynoo in #82642. >From 3f23b5ed11ef7453c64da562ad47701cc77ee3e0 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Sat, 24 Feb 2024 01:16:45 +0100 Subject: [PATCH] [llvm-ar][Archive] Use getDefaultTargetTriple instead of host triple for the fallback archive format. --- .../ClangOffloadPackager.cpp | 2 +- llvm/include/llvm/Object/Archive.h | 2 +- llvm/lib/Object/Archive.cpp | 4 ++-- llvm/lib/Object/ArchiveWriter.cpp| 2 +- llvm/tools/llvm-ar/llvm-ar.cpp | 16 +++- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp b/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp index c36a5aa58cee50..c6d5b31ab512cb 100644 --- a/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp +++ b/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp @@ -197,7 +197,7 @@ static Error unbundleImages() { if (Error E = writeArchive( Args["file"], Members, SymtabWritingMode::NormalSymtab, - Archive::getDefaultKindForHost(), true, false, nullptr)) + Archive::getDefaultKind(), true, false, nullptr)) return E; } else if (Args.count("file")) { if (Extracted.size() > 1) diff --git a/llvm/include/llvm/Object/Archive.h b/llvm/include/llvm/Object/Archive.h index 66f07939b11050..a3165c3235e0ed 100644 --- a/llvm/include/llvm/Object/Archive.h +++ b/llvm/include/llvm/Object/Archive.h @@ -338,7 +338,7 @@ class Archive : public Binary { Kind kind() const { return (Kind)Format; } bool isThin() const { return IsThin; } - static object::Archive::Kind getDefaultKindForHost(); + static object::Archive::Kind getDefaultKind(); static object::Archive::Kind getDefaultKindForTriple(Triple &T); child_iterator child_begin(Error &Err, bool SkipInternal = true) const; diff --git a/llvm/lib/Object/Archive.cpp b/llvm/lib/Object/Archive.cpp index d3fdcd9ee88111..6139d9996bdad3 100644 --- a/llvm/lib/Object/Archive.cpp +++ b/llvm/lib/Object/Archive.cpp @@ -979,8 +979,8 @@ object::Archive::Kind Archive::getDefaultKindForTriple(Triple &T) { return object::Archive::K_GNU; } -object::Archive::Kind Archive::getDefaultKindForHost() { - Triple HostTriple(sys::getProcessTriple()); +object::Archive::Kind Archive::getDefaultKind() { + Triple HostTriple(sys::getDefaultTargetTriple()); return getDefaultKindForTriple(HostTriple); } diff --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp index 02f72521c8b544..978eff64e5ee7d 100644 --- a/llvm/lib/Object/ArchiveWriter.cpp +++ b/llvm/lib/Object/ArchiveWriter.cpp @@ -91,7 +91,7 @@ object::Archive::Kind NewArchiveMember::detectKindFromObject() const { } } - return object::Archive::getDefaultKindForHost(); + return object::Archive::getDefaultKind(); } Expected diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp index c58a85c695dacf..0c4392baacd052 100644 --- a/llvm/tools/llvm-ar/llvm-ar.cpp +++ b/llvm/tools/llvm-ar/llvm-ar.cpp @@ -671,7 +671,7 @@ Expected> getAsBinary(const Archive::Child &C, } template static bool isValidInBitMode(const A &Member) { - if (object::Archive::getDefaultKindForHost() != object::Archive::K_AIXBIG) + if (object::Archive::getDefaultKind() != object::Archive::K_AIXBIG) return true; LLVMContext Context; Expected> BinOrErr = getAsBinary(Member, &Context); @@ -1037,10 +1037,10 @@ static void performWriteOperation(ArchiveOperation Operation, } } else if (NewMembersP) Kind = !NewMembersP->empty() ? NewMembersP->front().detectKindFromObject() - : object::Archive::getDefaultKindForHost(); + : object::Archive::getDefaultKind(); else Kind = !NewMembers.empty() ? NewMembers.front().detectKindFromObject() - : object::Archive::getDefaultKindForHost(); + : object::Archive::getDefaultKind(); break; case GNU: Kind = object::Archive::K_GNU; @@ -1335,7 +1335,7 @@ static int ar_main(int argc, char **argv) { // Get BitMode from enviorment variable "OBJECT_MODE" for AIX OS, if // specified. - if (object::Archive::getDefaultKindForHost() == object::Archive::K_AIXBIG) { + if (object::Archive::getDefaultKind() == object::Archive::K_AIXBIG) { BitMode = getBitMode(getenv("OBJECT_MODE")); if (BitMode == BitModeTy::Unknown) BitMode = BitModeTy::Bit32; @@ -1397,8 +1397,7 @@ static int ar_main(int argc, char **argv) { continue; if (strncmp(*ArgIt, "-X", 2) == 0) { - if (object::Archive::getDefaultKindForHost() == - object::Archive::K_AIXBIG) { + if (object::Archive::getDefaultKind() == object::Archive::K_AIXBIG
[clang] [llvm] [llvm-ar][Archive] Use getDefaultTargetTriple instead of host triple for the fallback archive format. (PR #82888)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Jacek Caban (cjacek) Changes As suggested by @gbreynoo in #82642. --- Full diff: https://github.com/llvm/llvm-project/pull/82888.diff 5 Files Affected: - (modified) clang/tools/clang-offload-packager/ClangOffloadPackager.cpp (+1-1) - (modified) llvm/include/llvm/Object/Archive.h (+1-1) - (modified) llvm/lib/Object/Archive.cpp (+2-2) - (modified) llvm/lib/Object/ArchiveWriter.cpp (+1-1) - (modified) llvm/tools/llvm-ar/llvm-ar.cpp (+7-9) ``diff diff --git a/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp b/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp index c36a5aa58cee50..c6d5b31ab512cb 100644 --- a/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp +++ b/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp @@ -197,7 +197,7 @@ static Error unbundleImages() { if (Error E = writeArchive( Args["file"], Members, SymtabWritingMode::NormalSymtab, - Archive::getDefaultKindForHost(), true, false, nullptr)) + Archive::getDefaultKind(), true, false, nullptr)) return E; } else if (Args.count("file")) { if (Extracted.size() > 1) diff --git a/llvm/include/llvm/Object/Archive.h b/llvm/include/llvm/Object/Archive.h index 66f07939b11050..a3165c3235e0ed 100644 --- a/llvm/include/llvm/Object/Archive.h +++ b/llvm/include/llvm/Object/Archive.h @@ -338,7 +338,7 @@ class Archive : public Binary { Kind kind() const { return (Kind)Format; } bool isThin() const { return IsThin; } - static object::Archive::Kind getDefaultKindForHost(); + static object::Archive::Kind getDefaultKind(); static object::Archive::Kind getDefaultKindForTriple(Triple &T); child_iterator child_begin(Error &Err, bool SkipInternal = true) const; diff --git a/llvm/lib/Object/Archive.cpp b/llvm/lib/Object/Archive.cpp index d3fdcd9ee88111..6139d9996bdad3 100644 --- a/llvm/lib/Object/Archive.cpp +++ b/llvm/lib/Object/Archive.cpp @@ -979,8 +979,8 @@ object::Archive::Kind Archive::getDefaultKindForTriple(Triple &T) { return object::Archive::K_GNU; } -object::Archive::Kind Archive::getDefaultKindForHost() { - Triple HostTriple(sys::getProcessTriple()); +object::Archive::Kind Archive::getDefaultKind() { + Triple HostTriple(sys::getDefaultTargetTriple()); return getDefaultKindForTriple(HostTriple); } diff --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp index 02f72521c8b544..978eff64e5ee7d 100644 --- a/llvm/lib/Object/ArchiveWriter.cpp +++ b/llvm/lib/Object/ArchiveWriter.cpp @@ -91,7 +91,7 @@ object::Archive::Kind NewArchiveMember::detectKindFromObject() const { } } - return object::Archive::getDefaultKindForHost(); + return object::Archive::getDefaultKind(); } Expected diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp index c58a85c695dacf..0c4392baacd052 100644 --- a/llvm/tools/llvm-ar/llvm-ar.cpp +++ b/llvm/tools/llvm-ar/llvm-ar.cpp @@ -671,7 +671,7 @@ Expected> getAsBinary(const Archive::Child &C, } template static bool isValidInBitMode(const A &Member) { - if (object::Archive::getDefaultKindForHost() != object::Archive::K_AIXBIG) + if (object::Archive::getDefaultKind() != object::Archive::K_AIXBIG) return true; LLVMContext Context; Expected> BinOrErr = getAsBinary(Member, &Context); @@ -1037,10 +1037,10 @@ static void performWriteOperation(ArchiveOperation Operation, } } else if (NewMembersP) Kind = !NewMembersP->empty() ? NewMembersP->front().detectKindFromObject() - : object::Archive::getDefaultKindForHost(); + : object::Archive::getDefaultKind(); else Kind = !NewMembers.empty() ? NewMembers.front().detectKindFromObject() - : object::Archive::getDefaultKindForHost(); + : object::Archive::getDefaultKind(); break; case GNU: Kind = object::Archive::K_GNU; @@ -1335,7 +1335,7 @@ static int ar_main(int argc, char **argv) { // Get BitMode from enviorment variable "OBJECT_MODE" for AIX OS, if // specified. - if (object::Archive::getDefaultKindForHost() == object::Archive::K_AIXBIG) { + if (object::Archive::getDefaultKind() == object::Archive::K_AIXBIG) { BitMode = getBitMode(getenv("OBJECT_MODE")); if (BitMode == BitModeTy::Unknown) BitMode = BitModeTy::Bit32; @@ -1397,8 +1397,7 @@ static int ar_main(int argc, char **argv) { continue; if (strncmp(*ArgIt, "-X", 2) == 0) { - if (object::Archive::getDefaultKindForHost() == - object::Archive::K_AIXBIG) { + if (object::Archive::getDefaultKind() == object::Archive::K_AIXBIG) { Match = *(*ArgIt + 2) != '\0' ? *ArgIt + 2 : *(++ArgIt); BitMode = getBitMode(Match); if (BitMode == BitModeTy::Unknown) @@ -1437,8 +1436,7 @@ static int ranlib_main(int argc, char
[clang] [llvm] [transforms] Inline simple variadic functions (PR #81058)
https://github.com/jhuber6 edited https://github.com/llvm/llvm-project/pull/81058 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [transforms] Inline simple variadic functions (PR #81058)
https://github.com/jhuber6 commented: Some nits, mostly just formatting and naming that hasn't been updated. I agree overall that we should just put this in some canonical form and rely on other LLVM passes to take care of things like inlining. Eager to have this functionality in, so hopefully we can keep this moving. https://github.com/llvm/llvm-project/pull/81058 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [transforms] Inline simple variadic functions (PR #81058)
@@ -0,0 +1,701 @@ +//===-- ExpandVariadicsPass.cpp *- C++ -*-=// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This is an optimisation pass for variadic functions. If called from codegen, +// it can serve as the implementation of variadic functions for a given target. +// +// The target-dependent parts are in namespace VariadicABIInfo. Enabling a new +// target means adding a case to VariadicABIInfo::create() along with tests. +// +// The module pass using that information is class ExpandVariadics. +// +// The strategy is: +// 1. Test whether a variadic function is sufficiently simple +// 2. If it was, calls to it can be replaced with calls to a different function +// 3. If it wasn't, try to split it into a simple function and a remainder +// 4. Optionally rewrite the varadic function calling convention as well +// +// This pass considers "sufficiently simple" to mean a variadic function that +// calls into a different function taking a va_list to do the real work. For +// example, libc might implement fprintf as a single basic block calling into +// vfprintf. This pass can then rewrite call to the variadic into some code +// to construct a target-specific value to use for the va_list and a call +// into the non-variadic implementation function. There's a test for that. +// +// Most other variadic functions whose definition is known can be converted into +// that form. Create a new internal function taking a va_list where the original +// took a ... parameter. Move the blocks across. Create a new block containing a +// va_start that calls into the new function. This is nearly target independent. +// +// Where this transform is consistent with the ABI, e.g. AMDGPU or NVPTX, or +// where the ABI can be chosen to align with this transform, the function +// interface can be rewritten along with calls to unknown variadic functions. +// +// The aggregate effect is to unblock other transforms, most critically the +// general purpose inliner. Known calls to variadic functions become zero cost. +// +// This pass does define some target specific information which is partially +// redundant with other parts of the compiler. In particular, the call frame +// it builds must be the exact complement of the va_arg lowering performed +// by clang. The va_list construction is similar to work done by the backend +// for targets that lower variadics there, though distinct in that this pass +// constructs the pieces using alloca instead of relative to stack pointers. +// +// Consistency with clang is primarily tested by emitting va_arg using clang +// then expanding the variadic functions using this pass, followed by trying +// to constant fold the functions to no-ops. +// +// Target specific behaviour is tested in IR - mainly checking that values are +// put into positions in call frames that make sense for that particular target. +// +//===--===// + +#include "llvm/Transforms/IPO/ExpandVariadics.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/CodeGen/Passes.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/IntrinsicInst.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/PassManager.h" +#include "llvm/InitializePasses.h" +#include "llvm/Pass.h" +#include "llvm/TargetParser/Triple.h" + +#define DEBUG_TYPE "expand-variadics" + +using namespace llvm; + +namespace { +namespace VariadicABIInfo { + +// calling convention for passing as valist object, same as it would be in C +// aarch64 uses byval +enum class ValistCc { value, pointer, /*byval*/ }; + +struct Interface { +protected: + Interface(uint32_t MinAlign, uint32_t MaxAlign) + : MinAlign(MinAlign), MaxAlign(MaxAlign) {} + +public: + virtual ~Interface() {} + const uint32_t MinAlign; + const uint32_t MaxAlign; + + // Most ABIs use a void* or char* for va_list, others can specialise + virtual Type *vaListType(LLVMContext &Ctx) { +return PointerType::getUnqual(Ctx); + } + + // Lots of targets use a void* pointed at a buffer for va_list. + // Some use more complicated iterator constructs. + // This interface seeks to express both. + // Ideally it would be a compile time error for a derived class + // to override only one of valistOnStack, initializeVAList. + + // How the vaListType is passed + virtual ValistCc valistCc() { return ValistCc::value; } + + // The valist might need to be stack allocated. + virtual bool valistOnStack() { return false; } + + virtual void initializeVAList(LLVMContext &Ctx, IRBuilder<> &Builder, +AllocaInst * /*va_list*/, Value * /*buffer*/) { +// Function needs to be implemented
[clang] [llvm] [transforms] Inline simple variadic functions (PR #81058)
@@ -0,0 +1,701 @@ +//===-- ExpandVariadicsPass.cpp *- C++ -*-=// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This is an optimisation pass for variadic functions. If called from codegen, +// it can serve as the implementation of variadic functions for a given target. +// +// The target-dependent parts are in namespace VariadicABIInfo. Enabling a new +// target means adding a case to VariadicABIInfo::create() along with tests. +// +// The module pass using that information is class ExpandVariadics. +// +// The strategy is: +// 1. Test whether a variadic function is sufficiently simple +// 2. If it was, calls to it can be replaced with calls to a different function +// 3. If it wasn't, try to split it into a simple function and a remainder +// 4. Optionally rewrite the varadic function calling convention as well +// +// This pass considers "sufficiently simple" to mean a variadic function that +// calls into a different function taking a va_list to do the real work. For +// example, libc might implement fprintf as a single basic block calling into +// vfprintf. This pass can then rewrite call to the variadic into some code +// to construct a target-specific value to use for the va_list and a call +// into the non-variadic implementation function. There's a test for that. +// +// Most other variadic functions whose definition is known can be converted into +// that form. Create a new internal function taking a va_list where the original +// took a ... parameter. Move the blocks across. Create a new block containing a +// va_start that calls into the new function. This is nearly target independent. +// +// Where this transform is consistent with the ABI, e.g. AMDGPU or NVPTX, or +// where the ABI can be chosen to align with this transform, the function +// interface can be rewritten along with calls to unknown variadic functions. +// +// The aggregate effect is to unblock other transforms, most critically the +// general purpose inliner. Known calls to variadic functions become zero cost. +// +// This pass does define some target specific information which is partially +// redundant with other parts of the compiler. In particular, the call frame +// it builds must be the exact complement of the va_arg lowering performed +// by clang. The va_list construction is similar to work done by the backend +// for targets that lower variadics there, though distinct in that this pass +// constructs the pieces using alloca instead of relative to stack pointers. +// +// Consistency with clang is primarily tested by emitting va_arg using clang +// then expanding the variadic functions using this pass, followed by trying +// to constant fold the functions to no-ops. +// +// Target specific behaviour is tested in IR - mainly checking that values are +// put into positions in call frames that make sense for that particular target. +// +//===--===// + +#include "llvm/Transforms/IPO/ExpandVariadics.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/CodeGen/Passes.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/IntrinsicInst.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/PassManager.h" +#include "llvm/InitializePasses.h" +#include "llvm/Pass.h" +#include "llvm/TargetParser/Triple.h" + +#define DEBUG_TYPE "expand-variadics" + +using namespace llvm; + +namespace { +namespace VariadicABIInfo { + +// calling convention for passing as valist object, same as it would be in C +// aarch64 uses byval +enum class ValistCc { value, pointer, /*byval*/ }; + +struct Interface { +protected: + Interface(uint32_t MinAlign, uint32_t MaxAlign) + : MinAlign(MinAlign), MaxAlign(MaxAlign) {} + +public: + virtual ~Interface() {} + const uint32_t MinAlign; + const uint32_t MaxAlign; + + // Most ABIs use a void* or char* for va_list, others can specialise + virtual Type *vaListType(LLVMContext &Ctx) { +return PointerType::getUnqual(Ctx); + } + + // Lots of targets use a void* pointed at a buffer for va_list. + // Some use more complicated iterator constructs. + // This interface seeks to express both. + // Ideally it would be a compile time error for a derived class + // to override only one of valistOnStack, initializeVAList. + + // How the vaListType is passed + virtual ValistCc valistCc() { return ValistCc::value; } + + // The valist might need to be stack allocated. + virtual bool valistOnStack() { return false; } + + virtual void initializeVAList(LLVMContext &Ctx, IRBuilder<> &Builder, +AllocaInst * /*va_list*/, Value * /*buffer*/) { +// Function needs to be implemented
[clang] [llvm] [transforms] Inline simple variadic functions (PR #81058)
@@ -0,0 +1,698 @@ +//===-- ExpandVariadicsPass.cpp *- C++ -*-=// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This is an optimisation pass for variadic functions. If called from codegen, +// it can serve as the implementation of variadic functions for a given target. +// +// The target-dependent parts are in namespace VariadicABIInfo. Enabling a new +// target means adding a case to VariadicABIInfo::create() along with tests. +// +// The module pass using that information is class ExpandVariadics. +// +// The strategy is: +// 1. Test whether a variadic function is sufficiently simple +// 2. If it was, calls to it can be replaced with calls to a different function +// 3. If it wasn't, try to split it into a simple function and a remainder +// 4. Optionally rewrite the varadic function calling convention as well +// +// This pass considers "sufficiently simple" to mean a variadic function that +// calls into a different function taking a va_list to do the real work. For +// example, libc might implement fprintf as a single basic block calling into +// vfprintf. This pass can then rewrite call to the variadic into some code +// to construct a target-specific value to use for the va_list and a call +// into the non-variadic implementation function. There's a test for that. +// +// Most other variadic functions whose definition is known can be converted into +// that form. Create a new internal function taking a va_list where the original +// took a ... parameter. Move the blocks across. Create a new block containing a +// va_start that calls into the new function. This is nearly target independent. +// +// Where this transform is consistent with the ABI, e.g. AMDGPU or NVPTX, or +// where the ABI can be chosen to align with this transform, the function +// interface can be rewritten along with calls to unknown variadic functions. +// +// The aggregate effect is to unblock other transforms, most critically the +// general purpose inliner. Known calls to variadic functions become zero cost. +// +// This pass does define some target specific information which is partially +// redundant with other parts of the compiler. In particular, the call frame +// it builds must be the exact complement of the va_arg lowering performed +// by clang. The va_list construction is similar to work done by the backend +// for targets that lower variadics there, though distinct in that this pass +// constructs the pieces using alloca instead of relative to stack pointers. +// +// Consistency with clang is primarily tested by emitting va_arg using clang +// then expanding the variadic functions using this pass, followed by trying +// to constant fold the functions to no-ops. +// +// Target specific behaviour is tested in IR - mainly checking that values are +// put into positions in call frames that make sense for that particular target. +// +//===--===// + +#include "llvm/Transforms/IPO/ExpandVariadics.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/CodeGen/Passes.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/IntrinsicInst.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/PassManager.h" +#include "llvm/InitializePasses.h" +#include "llvm/Pass.h" +#include "llvm/TargetParser/Triple.h" + +#define DEBUG_TYPE "expand-variadics" + +using namespace llvm; + +namespace { +namespace VariadicABIInfo { + +// calling convention for passing as valist object, same as it would be in C +// aarch64 uses byval +enum class valistCC { value, pointer, /*byval*/ }; + +struct Interface { +protected: + Interface(uint32_t MinAlign, uint32_t MaxAlign) + : MinAlign(MinAlign), MaxAlign(MaxAlign) {} + +public: + virtual ~Interface() {} + const uint32_t MinAlign; + const uint32_t MaxAlign; + + // Most ABIs use a void* or char* for va_list, others can specialise + virtual Type *vaListType(LLVMContext &Ctx) { +return PointerType::getUnqual(Ctx); + } + + // How the vaListType is passed + virtual valistCC vaListCC() { return valistCC::value; } + + // The valist might need to be stack allocated. + virtual bool valistOnStack() { return false; } + + virtual void initializeVAList(LLVMContext &Ctx, IRBuilder<> &Builder, +AllocaInst * /*va_list*/, Value * /*buffer*/) { +// Function needs to be implemented if valist is on the stack +assert(!valistOnStack()); +__builtin_unreachable(); + } + + // All targets currently implemented use a ptr for the valist parameter + Type *vaListParameterType(LLVMContext &Ctx) { +return PointerType::getUnqual(Ctx); + } + + bool VAEndIsNop() { return
[clang] [OpenMP] Clang Codegen Interop : Accept multiple init (PR #82604)
https://github.com/SunilKuravinakop updated https://github.com/llvm/llvm-project/pull/82604 >From 6444ef3f60a9f8ed8b3f413997259fe5006396b7 Mon Sep 17 00:00:00 2001 From: Sunil Kuravinakop Date: Tue, 20 Feb 2024 11:29:49 -0600 Subject: [PATCH 1/3] Accept multiple init clauses in interop directive. Changes to be committed: modified: clang/lib/CodeGen/CGStmtOpenMP.cpp --- clang/lib/CodeGen/CGStmtOpenMP.cpp | 30 ++ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index 8fd74697de3c0f..c512b0bd851f7a 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -7023,19 +7023,25 @@ void CodeGenFunction::EmitOMPInteropDirective(const OMPInteropDirective &S) { S.getSingleClause())) && "OMPNowaitClause clause is used separately in OMPInteropDirective."); - if (const auto *C = S.getSingleClause()) { -llvm::Value *InteropvarPtr = -EmitLValue(C->getInteropVar()).getPointer(*this); -llvm::omp::OMPInteropType InteropType = llvm::omp::OMPInteropType::Unknown; -if (C->getIsTarget()) { - InteropType = llvm::omp::OMPInteropType::Target; -} else { - assert(C->getIsTargetSync() && "Expected interop-type target/targetsync"); - InteropType = llvm::omp::OMPInteropType::TargetSync; + auto It = S.getClausesOfKind(); + if (!It.empty()) { +// Look at the multiple init clauses +for (auto C : It) { + llvm::Value *InteropvarPtr = + EmitLValue(C->getInteropVar()).getPointer(*this); + llvm::omp::OMPInteropType InteropType = + llvm::omp::OMPInteropType::Unknown; + if (C->getIsTarget()) { +InteropType = llvm::omp::OMPInteropType::Target; + } else { +assert(C->getIsTargetSync() && + "Expected interop-type target/targetsync"); +InteropType = llvm::omp::OMPInteropType::TargetSync; + } + OMPBuilder.createOMPInteropInit(Builder, InteropvarPtr, InteropType, + Device, NumDependences, DependenceList, + Data.HasNowaitClause); } -OMPBuilder.createOMPInteropInit(Builder, InteropvarPtr, InteropType, Device, -NumDependences, DependenceList, -Data.HasNowaitClause); } else if (const auto *C = S.getSingleClause()) { llvm::Value *InteropvarPtr = EmitLValue(C->getInteropVar()).getPointer(*this); >From f4779f0dfd0fbf3a9e851f3df276840f254d87a7 Mon Sep 17 00:00:00 2001 From: Sunil Kuravinakop Date: Sat, 24 Feb 2024 00:41:03 -0600 Subject: [PATCH 2/3] Adding a testcase for interop_codegen.cpp to check "init" clause being provided twice. This check is being done only for AMD GPU. Changes to be committed: new file: clang/test/OpenMP/interop_codegen.cpp --- clang/test/OpenMP/interop_codegen.cpp | 30 +++ 1 file changed, 30 insertions(+) create mode 100644 clang/test/OpenMP/interop_codegen.cpp diff --git a/clang/test/OpenMP/interop_codegen.cpp b/clang/test/OpenMP/interop_codegen.cpp new file mode 100644 index 00..6277db27bd4da8 --- /dev/null +++ b/clang/test/OpenMP/interop_codegen.cpp @@ -0,0 +1,30 @@ +// expected-no-diagnostics +// REQUIRES: amdgpu-registered-target +// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -o - | FileCheck %s + +#ifndef HEADER +#define HEADER + +typedef void *omp_interop_t; +#define omp_interop_none 0 +#define omp_ipr_fr_id -1 +typedef long omp_intptr_t; +#define NULL 0 + +extern omp_intptr_t omp_get_interop_int(const omp_interop_t, int, int *); + +int main() { + omp_interop_t i1 = omp_interop_none; + omp_interop_t obj = omp_interop_none; + + #pragma omp interop init(targetsync: i1) init(targetsync: obj) + int id = (int )omp_get_interop_int(obj, omp_ipr_fr_id, NULL); + int id1 = (int )omp_get_interop_int(i1, omp_ipr_fr_id, NULL); + + +} +#endif + +// CHECK-LABEL: define {{.+}}main{{.+}} +// CHECK: call {{.+}}__tgt_interop_init({{.+}}i1{{.*}}) +// CHECK: call {{.+}}__tgt_interop_init({{.+}}obj{{.*}}) >From f7ddf6eb5df9ec9a1f84e5918f05854465ca74bc Mon Sep 17 00:00:00 2001 From: Sunil Kuravinakop Date: Sat, 24 Feb 2024 05:27:19 -0600 Subject: [PATCH 3/3] Added -fopenmp-targets=nvptx64-nvidia-cuda & -fopenmp-targets=powerpc64le-ibm-linux-gnu. Changes to be committed: modified: clang/test/OpenMP/interop_codegen.cpp --- clang/test/OpenMP/interop_codegen.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/test/OpenMP/interop_codegen.cpp b/clang/test/OpenMP/interop_codegen.cpp index 6277db27bd4da8..e814fd9b23d47c 100644 --- a/clang/test/OpenMP/interop_codegen.cpp +++ b/clang/test/OpenMP/interop_codegen.cpp @@ -1,6 +1,7 @@ // expected-no-diagnostics -/
[clang] 8e22fff - [clang] Remove trailing whitespace
Author: Nathan Sidwell Date: 2024-02-24T12:25:08-05:00 New Revision: 8e22fffc85b36784146041499b716cec74285660 URL: https://github.com/llvm/llvm-project/commit/8e22fffc85b36784146041499b716cec74285660 DIFF: https://github.com/llvm/llvm-project/commit/8e22fffc85b36784146041499b716cec74285660.diff LOG: [clang] Remove trailing whitespace Fix commit 66f6929fec3ae Added: Modified: clang/docs/HLSL/ExpectedDifferences.rst Removed: diff --git a/clang/docs/HLSL/ExpectedDifferences.rst b/clang/docs/HLSL/ExpectedDifferences.rst index 60001b22dc7920..d1b6010f10f43a 100644 --- a/clang/docs/HLSL/ExpectedDifferences.rst +++ b/clang/docs/HLSL/ExpectedDifferences.rst @@ -93,7 +93,7 @@ behavior between Clang and DXC. Some examples include: fma(X, Y, Z); // DXC: Fails to resolve no known conversion from float to double. // Clang: Resolves to fma(double,double,double). #endif - + double D = dot(A, B); // DXC: Resolves to dot(double3, double3), fails DXIL Validation. // FXC: Expands to compute double dot product with fmul/fadd // Clang: Resolves to dot(float3, float3), emits conversion warnings. @@ -102,7 +102,7 @@ behavior between Clang and DXC. Some examples include: .. note:: - In Clang, a conscious decision was made to exclude the ``dot(vector, vector)`` + In Clang, a conscious decision was made to exclude the ``dot(vector, vector)`` overload and allow overload resolution to resolve the ``vector`` overload. This approach provides ``-Wconversion`` diagnostic notifying the user of the conversion rather than silently altering ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] constify or staticify some CGRecordLowering fns (PR #82874)
https://github.com/urnathan updated https://github.com/llvm/llvm-project/pull/82874 >From 792c608cc55d89552cf86d058796825a1f428f5d Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Fri, 2 Feb 2024 08:01:21 -0500 Subject: [PATCH] [clang][NFC] constify or staticify some fns These functions do not alter the object -- and on one case don't even need it. Thus marking them static or const as appropriate. --- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 28 ++--- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp index 868ef810f3c4e8..7822903b89ce47 100644 --- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -95,7 +95,7 @@ struct CGRecordLowering { CGRecordLowering(CodeGenTypes &Types, const RecordDecl *D, bool Packed); // Short helper routines. /// Constructs a MemberInfo instance from an offset and llvm::Type *. - MemberInfo StorageInfo(CharUnits Offset, llvm::Type *Data) { + static MemberInfo StorageInfo(CharUnits Offset, llvm::Type *Data) { return MemberInfo(Offset, MemberInfo::Field, Data); } @@ -104,7 +104,7 @@ struct CGRecordLowering { /// fields of the same formal type. We want to emit a layout with /// these discrete storage units instead of combining them into a /// continuous run. - bool isDiscreteBitFieldABI() { + bool isDiscreteBitFieldABI() const { return Context.getTargetInfo().getCXXABI().isMicrosoft() || D->isMsStruct(Context); } @@ -121,22 +121,22 @@ struct CGRecordLowering { /// other bases, which complicates layout in specific ways. /// /// Note specifically that the ms_struct attribute doesn't change this. - bool isOverlappingVBaseABI() { + bool isOverlappingVBaseABI() const { return !Context.getTargetInfo().getCXXABI().isMicrosoft(); } /// Wraps llvm::Type::getIntNTy with some implicit arguments. - llvm::Type *getIntNType(uint64_t NumBits) { + llvm::Type *getIntNType(uint64_t NumBits) const { unsigned AlignedBits = llvm::alignTo(NumBits, Context.getCharWidth()); return llvm::Type::getIntNTy(Types.getLLVMContext(), AlignedBits); } /// Get the LLVM type sized as one character unit. - llvm::Type *getCharType() { + llvm::Type *getCharType() const { return llvm::Type::getIntNTy(Types.getLLVMContext(), Context.getCharWidth()); } /// Gets an llvm type of size NumChars and alignment 1. - llvm::Type *getByteArrayType(CharUnits NumChars) { + llvm::Type *getByteArrayType(CharUnits NumChars) const { assert(!NumChars.isZero() && "Empty byte arrays aren't allowed."); llvm::Type *Type = getCharType(); return NumChars == CharUnits::One() ? Type : @@ -144,7 +144,7 @@ struct CGRecordLowering { } /// Gets the storage type for a field decl and handles storage /// for itanium bitfields that are smaller than their declared type. - llvm::Type *getStorageType(const FieldDecl *FD) { + llvm::Type *getStorageType(const FieldDecl *FD) const { llvm::Type *Type = Types.ConvertTypeForMem(FD->getType()); if (!FD->isBitField()) return Type; if (isDiscreteBitFieldABI()) return Type; @@ -152,29 +152,29 @@ struct CGRecordLowering { (unsigned)Context.toBits(getSize(Type; } /// Gets the llvm Basesubobject type from a CXXRecordDecl. - llvm::Type *getStorageType(const CXXRecordDecl *RD) { + llvm::Type *getStorageType(const CXXRecordDecl *RD) const { return Types.getCGRecordLayout(RD).getBaseSubobjectLLVMType(); } - CharUnits bitsToCharUnits(uint64_t BitOffset) { + CharUnits bitsToCharUnits(uint64_t BitOffset) const { return Context.toCharUnitsFromBits(BitOffset); } - CharUnits getSize(llvm::Type *Type) { + CharUnits getSize(llvm::Type *Type) const { return CharUnits::fromQuantity(DataLayout.getTypeAllocSize(Type)); } - CharUnits getAlignment(llvm::Type *Type) { + CharUnits getAlignment(llvm::Type *Type) const { return CharUnits::fromQuantity(DataLayout.getABITypeAlign(Type)); } - bool isZeroInitializable(const FieldDecl *FD) { + bool isZeroInitializable(const FieldDecl *FD) const { return Types.isZeroInitializable(FD->getType()); } - bool isZeroInitializable(const RecordDecl *RD) { + bool isZeroInitializable(const RecordDecl *RD) const { return Types.isZeroInitializable(RD); } void appendPaddingBytes(CharUnits Size) { if (!Size.isZero()) FieldTypes.push_back(getByteArrayType(Size)); } - uint64_t getFieldBitOffset(const FieldDecl *FD) { + uint64_t getFieldBitOffset(const FieldDecl *FD) const { return Layout.getFieldOffset(FD->getFieldIndex()); } // Layout routines. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Clang Codegen Interop : Accept multiple init (PR #82604)
https://github.com/SunilKuravinakop updated https://github.com/llvm/llvm-project/pull/82604 >From 6444ef3f60a9f8ed8b3f413997259fe5006396b7 Mon Sep 17 00:00:00 2001 From: Sunil Kuravinakop Date: Tue, 20 Feb 2024 11:29:49 -0600 Subject: [PATCH 1/3] Accept multiple init clauses in interop directive. Changes to be committed: modified: clang/lib/CodeGen/CGStmtOpenMP.cpp --- clang/lib/CodeGen/CGStmtOpenMP.cpp | 30 ++ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index 8fd74697de3c0f..c512b0bd851f7a 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -7023,19 +7023,25 @@ void CodeGenFunction::EmitOMPInteropDirective(const OMPInteropDirective &S) { S.getSingleClause())) && "OMPNowaitClause clause is used separately in OMPInteropDirective."); - if (const auto *C = S.getSingleClause()) { -llvm::Value *InteropvarPtr = -EmitLValue(C->getInteropVar()).getPointer(*this); -llvm::omp::OMPInteropType InteropType = llvm::omp::OMPInteropType::Unknown; -if (C->getIsTarget()) { - InteropType = llvm::omp::OMPInteropType::Target; -} else { - assert(C->getIsTargetSync() && "Expected interop-type target/targetsync"); - InteropType = llvm::omp::OMPInteropType::TargetSync; + auto It = S.getClausesOfKind(); + if (!It.empty()) { +// Look at the multiple init clauses +for (auto C : It) { + llvm::Value *InteropvarPtr = + EmitLValue(C->getInteropVar()).getPointer(*this); + llvm::omp::OMPInteropType InteropType = + llvm::omp::OMPInteropType::Unknown; + if (C->getIsTarget()) { +InteropType = llvm::omp::OMPInteropType::Target; + } else { +assert(C->getIsTargetSync() && + "Expected interop-type target/targetsync"); +InteropType = llvm::omp::OMPInteropType::TargetSync; + } + OMPBuilder.createOMPInteropInit(Builder, InteropvarPtr, InteropType, + Device, NumDependences, DependenceList, + Data.HasNowaitClause); } -OMPBuilder.createOMPInteropInit(Builder, InteropvarPtr, InteropType, Device, -NumDependences, DependenceList, -Data.HasNowaitClause); } else if (const auto *C = S.getSingleClause()) { llvm::Value *InteropvarPtr = EmitLValue(C->getInteropVar()).getPointer(*this); >From f4779f0dfd0fbf3a9e851f3df276840f254d87a7 Mon Sep 17 00:00:00 2001 From: Sunil Kuravinakop Date: Sat, 24 Feb 2024 00:41:03 -0600 Subject: [PATCH 2/3] Adding a testcase for interop_codegen.cpp to check "init" clause being provided twice. This check is being done only for AMD GPU. Changes to be committed: new file: clang/test/OpenMP/interop_codegen.cpp --- clang/test/OpenMP/interop_codegen.cpp | 30 +++ 1 file changed, 30 insertions(+) create mode 100644 clang/test/OpenMP/interop_codegen.cpp diff --git a/clang/test/OpenMP/interop_codegen.cpp b/clang/test/OpenMP/interop_codegen.cpp new file mode 100644 index 00..6277db27bd4da8 --- /dev/null +++ b/clang/test/OpenMP/interop_codegen.cpp @@ -0,0 +1,30 @@ +// expected-no-diagnostics +// REQUIRES: amdgpu-registered-target +// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -o - | FileCheck %s + +#ifndef HEADER +#define HEADER + +typedef void *omp_interop_t; +#define omp_interop_none 0 +#define omp_ipr_fr_id -1 +typedef long omp_intptr_t; +#define NULL 0 + +extern omp_intptr_t omp_get_interop_int(const omp_interop_t, int, int *); + +int main() { + omp_interop_t i1 = omp_interop_none; + omp_interop_t obj = omp_interop_none; + + #pragma omp interop init(targetsync: i1) init(targetsync: obj) + int id = (int )omp_get_interop_int(obj, omp_ipr_fr_id, NULL); + int id1 = (int )omp_get_interop_int(i1, omp_ipr_fr_id, NULL); + + +} +#endif + +// CHECK-LABEL: define {{.+}}main{{.+}} +// CHECK: call {{.+}}__tgt_interop_init({{.+}}i1{{.*}}) +// CHECK: call {{.+}}__tgt_interop_init({{.+}}obj{{.*}}) >From f7ddf6eb5df9ec9a1f84e5918f05854465ca74bc Mon Sep 17 00:00:00 2001 From: Sunil Kuravinakop Date: Sat, 24 Feb 2024 05:27:19 -0600 Subject: [PATCH 3/3] Added -fopenmp-targets=nvptx64-nvidia-cuda & -fopenmp-targets=powerpc64le-ibm-linux-gnu. Changes to be committed: modified: clang/test/OpenMP/interop_codegen.cpp --- clang/test/OpenMP/interop_codegen.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/test/OpenMP/interop_codegen.cpp b/clang/test/OpenMP/interop_codegen.cpp index 6277db27bd4da8..e814fd9b23d47c 100644 --- a/clang/test/OpenMP/interop_codegen.cpp +++ b/clang/test/OpenMP/interop_codegen.cpp @@ -1,6 +1,7 @@ // expected-no-diagnostics -/
[clang] [OpenMP] Clang Codegen Interop : Accept multiple init (PR #82604)
@@ -7023,19 +7023,25 @@ void CodeGenFunction::EmitOMPInteropDirective(const OMPInteropDirective &S) { S.getSingleClause())) && "OMPNowaitClause clause is used separately in OMPInteropDirective."); - if (const auto *C = S.getSingleClause()) { -llvm::Value *InteropvarPtr = -EmitLValue(C->getInteropVar()).getPointer(*this); -llvm::omp::OMPInteropType InteropType = llvm::omp::OMPInteropType::Unknown; -if (C->getIsTarget()) { - InteropType = llvm::omp::OMPInteropType::Target; -} else { - assert(C->getIsTargetSync() && "Expected interop-type target/targetsync"); - InteropType = llvm::omp::OMPInteropType::TargetSync; + auto It = S.getClausesOfKind(); + if (!It.empty()) { +// Look at the multiple init clauses +for (auto C : It) { alexey-bataev wrote: Expand 'auto' here https://github.com/llvm/llvm-project/pull/82604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Clang Codegen Interop : Accept multiple init (PR #82604)
@@ -7023,19 +7023,25 @@ void CodeGenFunction::EmitOMPInteropDirective(const OMPInteropDirective &S) { S.getSingleClause())) && "OMPNowaitClause clause is used separately in OMPInteropDirective."); - if (const auto *C = S.getSingleClause()) { -llvm::Value *InteropvarPtr = -EmitLValue(C->getInteropVar()).getPointer(*this); -llvm::omp::OMPInteropType InteropType = llvm::omp::OMPInteropType::Unknown; -if (C->getIsTarget()) { - InteropType = llvm::omp::OMPInteropType::Target; -} else { - assert(C->getIsTargetSync() && "Expected interop-type target/targetsync"); - InteropType = llvm::omp::OMPInteropType::TargetSync; + auto It = S.getClausesOfKind(); + if (!It.empty()) { +// Look at the multiple init clauses +for (auto C : It) { SunilKuravinakop wrote: For the Iterator variable `It` `auto It` is preferable rather than `llvm::iterator_range > It` https://github.com/llvm/llvm-project/pull/82604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)
SimplyDanny wrote: The rebased branch fails again with another error. Something seems odd with the Windows build ... https://github.com/llvm/llvm-project/pull/80541 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Clang Codegen Interop : Accept multiple init (PR #82604)
@@ -7023,19 +7023,25 @@ void CodeGenFunction::EmitOMPInteropDirective(const OMPInteropDirective &S) { S.getSingleClause())) && "OMPNowaitClause clause is used separately in OMPInteropDirective."); - if (const auto *C = S.getSingleClause()) { -llvm::Value *InteropvarPtr = -EmitLValue(C->getInteropVar()).getPointer(*this); -llvm::omp::OMPInteropType InteropType = llvm::omp::OMPInteropType::Unknown; -if (C->getIsTarget()) { - InteropType = llvm::omp::OMPInteropType::Target; -} else { - assert(C->getIsTargetSync() && "Expected interop-type target/targetsync"); - InteropType = llvm::omp::OMPInteropType::TargetSync; + auto It = S.getClausesOfKind(); + if (!It.empty()) { +// Look at the multiple init clauses +for (auto C : It) { alexey-bataev wrote: C is just OMPClause * here, not an iterator https://github.com/llvm/llvm-project/pull/82604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Clang Codegen Interop : Accept multiple init (PR #82604)
@@ -7023,19 +7023,25 @@ void CodeGenFunction::EmitOMPInteropDirective(const OMPInteropDirective &S) { S.getSingleClause())) && "OMPNowaitClause clause is used separately in OMPInteropDirective."); - if (const auto *C = S.getSingleClause()) { -llvm::Value *InteropvarPtr = -EmitLValue(C->getInteropVar()).getPointer(*this); -llvm::omp::OMPInteropType InteropType = llvm::omp::OMPInteropType::Unknown; -if (C->getIsTarget()) { - InteropType = llvm::omp::OMPInteropType::Target; -} else { - assert(C->getIsTargetSync() && "Expected interop-type target/targetsync"); - InteropType = llvm::omp::OMPInteropType::TargetSync; + auto It = S.getClausesOfKind(); + if (!It.empty()) { +// Look at the multiple init clauses +for (auto C : It) { alexey-bataev wrote: I asking about auto for C, not for It. https://github.com/llvm/llvm-project/pull/82604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Clang Codegen Interop : Accept multiple init (PR #82604)
https://github.com/SunilKuravinakop updated https://github.com/llvm/llvm-project/pull/82604 >From 6444ef3f60a9f8ed8b3f413997259fe5006396b7 Mon Sep 17 00:00:00 2001 From: Sunil Kuravinakop Date: Tue, 20 Feb 2024 11:29:49 -0600 Subject: [PATCH 1/4] Accept multiple init clauses in interop directive. Changes to be committed: modified: clang/lib/CodeGen/CGStmtOpenMP.cpp --- clang/lib/CodeGen/CGStmtOpenMP.cpp | 30 ++ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index 8fd74697de3c0f..c512b0bd851f7a 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -7023,19 +7023,25 @@ void CodeGenFunction::EmitOMPInteropDirective(const OMPInteropDirective &S) { S.getSingleClause())) && "OMPNowaitClause clause is used separately in OMPInteropDirective."); - if (const auto *C = S.getSingleClause()) { -llvm::Value *InteropvarPtr = -EmitLValue(C->getInteropVar()).getPointer(*this); -llvm::omp::OMPInteropType InteropType = llvm::omp::OMPInteropType::Unknown; -if (C->getIsTarget()) { - InteropType = llvm::omp::OMPInteropType::Target; -} else { - assert(C->getIsTargetSync() && "Expected interop-type target/targetsync"); - InteropType = llvm::omp::OMPInteropType::TargetSync; + auto It = S.getClausesOfKind(); + if (!It.empty()) { +// Look at the multiple init clauses +for (auto C : It) { + llvm::Value *InteropvarPtr = + EmitLValue(C->getInteropVar()).getPointer(*this); + llvm::omp::OMPInteropType InteropType = + llvm::omp::OMPInteropType::Unknown; + if (C->getIsTarget()) { +InteropType = llvm::omp::OMPInteropType::Target; + } else { +assert(C->getIsTargetSync() && + "Expected interop-type target/targetsync"); +InteropType = llvm::omp::OMPInteropType::TargetSync; + } + OMPBuilder.createOMPInteropInit(Builder, InteropvarPtr, InteropType, + Device, NumDependences, DependenceList, + Data.HasNowaitClause); } -OMPBuilder.createOMPInteropInit(Builder, InteropvarPtr, InteropType, Device, -NumDependences, DependenceList, -Data.HasNowaitClause); } else if (const auto *C = S.getSingleClause()) { llvm::Value *InteropvarPtr = EmitLValue(C->getInteropVar()).getPointer(*this); >From f4779f0dfd0fbf3a9e851f3df276840f254d87a7 Mon Sep 17 00:00:00 2001 From: Sunil Kuravinakop Date: Sat, 24 Feb 2024 00:41:03 -0600 Subject: [PATCH 2/4] Adding a testcase for interop_codegen.cpp to check "init" clause being provided twice. This check is being done only for AMD GPU. Changes to be committed: new file: clang/test/OpenMP/interop_codegen.cpp --- clang/test/OpenMP/interop_codegen.cpp | 30 +++ 1 file changed, 30 insertions(+) create mode 100644 clang/test/OpenMP/interop_codegen.cpp diff --git a/clang/test/OpenMP/interop_codegen.cpp b/clang/test/OpenMP/interop_codegen.cpp new file mode 100644 index 00..6277db27bd4da8 --- /dev/null +++ b/clang/test/OpenMP/interop_codegen.cpp @@ -0,0 +1,30 @@ +// expected-no-diagnostics +// REQUIRES: amdgpu-registered-target +// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -o - | FileCheck %s + +#ifndef HEADER +#define HEADER + +typedef void *omp_interop_t; +#define omp_interop_none 0 +#define omp_ipr_fr_id -1 +typedef long omp_intptr_t; +#define NULL 0 + +extern omp_intptr_t omp_get_interop_int(const omp_interop_t, int, int *); + +int main() { + omp_interop_t i1 = omp_interop_none; + omp_interop_t obj = omp_interop_none; + + #pragma omp interop init(targetsync: i1) init(targetsync: obj) + int id = (int )omp_get_interop_int(obj, omp_ipr_fr_id, NULL); + int id1 = (int )omp_get_interop_int(i1, omp_ipr_fr_id, NULL); + + +} +#endif + +// CHECK-LABEL: define {{.+}}main{{.+}} +// CHECK: call {{.+}}__tgt_interop_init({{.+}}i1{{.*}}) +// CHECK: call {{.+}}__tgt_interop_init({{.+}}obj{{.*}}) >From f7ddf6eb5df9ec9a1f84e5918f05854465ca74bc Mon Sep 17 00:00:00 2001 From: Sunil Kuravinakop Date: Sat, 24 Feb 2024 05:27:19 -0600 Subject: [PATCH 3/4] Added -fopenmp-targets=nvptx64-nvidia-cuda & -fopenmp-targets=powerpc64le-ibm-linux-gnu. Changes to be committed: modified: clang/test/OpenMP/interop_codegen.cpp --- clang/test/OpenMP/interop_codegen.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/test/OpenMP/interop_codegen.cpp b/clang/test/OpenMP/interop_codegen.cpp index 6277db27bd4da8..e814fd9b23d47c 100644 --- a/clang/test/OpenMP/interop_codegen.cpp +++ b/clang/test/OpenMP/interop_codegen.cpp @@ -1,6 +1,7 @@ // expected-no-diagnostics -/
[clang] [clang-format] Add AlignConsecutiveTableGenCondOperatorColons option. (PR #82878)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/82878 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add AlignConsecutiveTableGenCondOperatorColons option. (PR #82878)
@@ -849,7 +851,12 @@ void WhitespaceManager::alignConsecutiveAssignments() { } void WhitespaceManager::alignConsecutiveBitFields() { - if (!Style.AlignConsecutiveBitFields.Enabled) + alignConsecutiveColons(Style.AlignConsecutiveBitFields, TT_BitFieldColon); +} + +void WhitespaceManager::alignConsecutiveColons( +const FormatStyle::AlignConsecutiveStyle &AlignStyle, TokenType Type) { HazardyKnusperkeks wrote: ```suggestion FormatStyle::AlignConsecutiveStyle AlignStyle, TokenType Type) { ``` No need for the reference. https://github.com/llvm/llvm-project/pull/82878 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add AlignConsecutiveTableGenCondOperatorColons option. (PR #82878)
https://github.com/HazardyKnusperkeks edited https://github.com/llvm/llvm-project/pull/82878 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Diagnostic] Don't warn about binary literals when using C23. (PR #80244)
collinfunk wrote: > Thank you for this PR. This change should have some tests to verify the > behavior is correct. I am a little surprised that this does not change any > existing tests but maybe we don't have good test coverage. Hi, thanks for the review. Sorry for the lack of tests. I'm not super familiar with LLVM's code and didn't know how to add them. In any case, I believe that this issue was fixed in the following pull requests along with better Diagnostic groups: https://github.com/llvm/llvm-project/pull/81658 Can you double check and make sure I am not mistaken? Thanks. https://github.com/llvm/llvm-project/pull/80244 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Update -Wformat warnings for fixed-point format specifiers (PR #82855)
https://github.com/MaskRay approved this pull request. https://github.com/llvm/llvm-project/pull/82855 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)
@@ -0,0 +1,26 @@ +/* === vadefs.h ---=== + * + * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. + * See https://llvm.org/LICENSE.txt for license information. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + * + *===---=== + */ + +/* Only include this if we are aiming for MSVC compatibility. */ MaskRay wrote: Newer lib/Headers changes prefer `//`-style comments. Do we need `/* */`? https://github.com/llvm/llvm-project/pull/75711 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)
MaskRay wrote: I am not familiar with the MSVC ecosystem, but the change looks reasonable. Thanks! https://github.com/llvm/llvm-project/pull/75711 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)
@@ -0,0 +1,16 @@ +// REQUIRES: arm-registered-target + +// RUN: %clang -flto -target thumbv7m-unknown-unknown-eabi -mbranch-protection=pac-ret %s -S -o - 2>&1 | FileCheck %s MaskRay wrote: prefer `--target=` for new tests For codegen tests we prefer `%clang_cc1` to `%clang` https://github.com/llvm/llvm-project/pull/82819 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)
@@ -138,58 +163,79 @@ void run_foo_tml() { // CHECK: resolver_return1: // CHECK-NEXT:ret ptr @_ZN7MyClassIisE7foo_tmlEv._Mfrintts // CHECK: resolver_else2: -// CHECK-NEXT:ret ptr @_ZN7MyClassIisE7foo_tmlEv +// CHECK-NEXT:ret ptr @_ZN7MyClassIisE7foo_tmlEv.default +// +// // CHECK-LABEL: @_ZN7MyClassIfsE7foo_tmlEv( // CHECK-NEXT: entry: // CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8 // CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:ret i32 3 +// +// // CHECK-LABEL: @_ZN7MyClassIdfE7foo_tmlEv( // CHECK-NEXT: entry: // CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8 // CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:ret i32 4 +// +// // CHECK-LABEL: @_ZN7MyClassIssE7foo_tmlEv._Mfrintts( // CHECK-NEXT: entry: // CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8 // CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:ret i32 1 +// +// // CHECK-LABEL: @_ZN7MyClassIssE7foo_tmlEv._MssbsMsme-f64f64( // CHECK-NEXT: entry: // CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8 // CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:ret i32 1 +// +// // CHECK-LABEL: @_ZN7MyClassIssE7foo_tmlEv.default( // CHECK-NEXT: entry: // CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8 // CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:ret i32 1 +// +// // CHECK-LABEL: @_ZN7MyClassIisE7foo_tmlEv._Mfrintts( // CHECK-NEXT: entry: // CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8 // CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:ret i32 2 +// +// // CHECK-LABEL: @_ZN7MyClassIisE7foo_tmlEv._MssbsMsme-f64f64( // CHECK-NEXT: entry: // CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8 // CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:ret i32 2 +// +// // CHECK-LABEL: @_ZN7MyClassIisE7foo_tmlEv.default( // CHECK-NEXT: entry: // CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8 // CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:ret i32 2 - -// CHECK: attributes #0 = { mustprogress noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+fp-armv8,+fullfp16,+neon" } -// CHECK: attributes #1 = { mustprogress noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" } -// CHECK: attributes #2 = { mustprogress noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+ls64" } -// CHECK: attributes #3 = { mustprogress noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+fptoint" } -// CHECK: attributes #4 = { mustprogress noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme,+sme-f64f64" } +// +//. +// CHECK: attributes #[[ATTR0:[0-9]+]] = { mustprogress noinline nounwind optnone "branch-protection-pauth-lr"="false" "branch-target-enforcement"="false" "guarded-control-stack"="false" "no-trapping-math"="true" "sign-return-address"="none" "stack-protector-buffer-size"="8" "target-features"="+fp-armv8,+fullfp16,+neon" } +// CHECK: attributes #[[ATTR1:[0-9]+]] = { mustprogress noinline nounwind optnone "branch-protection-pauth-lr"="false" "branch-target-enforcement"="false" "guarded-control-stack"="false" "no-trapping-math"="true" "sign-return-address"="none" "stack-protector-buffer-size"="8" } +// CHECK: attributes #[[ATTR2:[0-9]+]] = { mustprogress noinline nounwind optnone "branch-protection-pauth-lr"="false" "branch-target-enforcement"="false" "guarded-control-stack"="false" "no-trapping-math"="true" "sign-return-address"="none" "stack-protector-buffer-size"="8" "target-features"="+ls64" } +// CHECK: attributes #[[ATTR3:[0-9]+]] = { mustprogress noinline nounwind optnone "branch-protection-pauth-lr"="false" "branch-target-enforcement"="false" "guarded-control-stack"="false" "no-trapping-math"="true" "sign-return-address"="none" "stack-protector-buffer-size"="8" "target-features"="+fptoint" } +// CHECK: attributes #[[ATTR4:[0-9]+]] = { mustprogress noinline nounwind optnone "branch-protection-pauth-lr"="
[clang] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)
@@ -138,58 +163,79 @@ void run_foo_tml() { // CHECK: resolver_return1: // CHECK-NEXT:ret ptr @_ZN7MyClassIisE7foo_tmlEv._Mfrintts // CHECK: resolver_else2: -// CHECK-NEXT:ret ptr @_ZN7MyClassIisE7foo_tmlEv +// CHECK-NEXT:ret ptr @_ZN7MyClassIisE7foo_tmlEv.default +// +// // CHECK-LABEL: @_ZN7MyClassIfsE7foo_tmlEv( // CHECK-NEXT: entry: // CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8 // CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:[[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8 // CHECK-NEXT:ret i32 3 +// MaskRay wrote: Unneeded changes? https://github.com/llvm/llvm-project/pull/82819 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang] Fixes for LIT testing of FLANG_RUNTIME_F128_MATH_LIB build. (PR #82832)
https://github.com/vzakhari updated https://github.com/llvm/llvm-project/pull/82832 >From ef2b9e87295688743771f1a64b15aa6fee6499df Mon Sep 17 00:00:00 2001 From: Slava Zakharin Date: Fri, 23 Feb 2024 13:08:49 -0800 Subject: [PATCH 1/2] [flang] Fixes for LIT testing of FLANG_RUNTIME_F128_MATH_LIB build. Follow-up for #81971 to fix the disabled LIT test and add LIT tests for lowering of the added math intrinsics. --- clang/lib/Driver/ToolChains/CommonArgs.cpp| 15 flang/test/Driver/linker-flags.f90| 34 +-- flang/test/Lower/Intrinsics/cabs_real16.f90 | 10 ++ .../Lower/Intrinsics/missing-math-runtime.f90 | 12 +++ flang/test/Lower/Intrinsics/sin_real16.f90| 9 + flang/test/Lower/Intrinsics/sqrt_real16.f90 | 9 + flang/test/lit.cfg.py | 21 flang/test/lit.site.cfg.py.in | 1 + 8 files changed, 87 insertions(+), 24 deletions(-) create mode 100644 flang/test/Lower/Intrinsics/cabs_real16.f90 create mode 100644 flang/test/Lower/Intrinsics/sin_real16.f90 create mode 100644 flang/test/Lower/Intrinsics/sqrt_real16.f90 diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 347b250260c4c4..faceee85a2f8dc 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1316,13 +1316,16 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args, // add the correct libraries to link against as dependents in the object // file. if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) { -StringRef f128LibName = TC.getDriver().getFlangF128MathLibrary(); -f128LibName.consume_front_insensitive("lib"); -if (!f128LibName.empty()) { +StringRef F128LibName = TC.getDriver().getFlangF128MathLibrary(); +F128LibName.consume_front_insensitive("lib"); +if (!F128LibName.empty()) { + bool AsNeeded = !TC.getTriple().isOSAIX(); CmdArgs.push_back("-lFortranFloat128Math"); - addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/true); - CmdArgs.push_back(Args.MakeArgString("-l" + f128LibName)); - addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false); + if (AsNeeded) +addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/true); + CmdArgs.push_back(Args.MakeArgString("-l" + F128LibName)); + if (AsNeeded) +addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false); } CmdArgs.push_back("-lFortranRuntime"); CmdArgs.push_back("-lFortranDecimal"); diff --git a/flang/test/Driver/linker-flags.f90 b/flang/test/Driver/linker-flags.f90 index 5e00520fcc098c..4d3d528b5e99e0 100644 --- a/flang/test/Driver/linker-flags.f90 +++ b/flang/test/Driver/linker-flags.f90 @@ -2,15 +2,15 @@ ! invocation. These libraries are added on top of other standard runtime ! libraries that the Clang driver will include. -! RUN: %flang -### --target=ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX -! RUN: %flang -### --target=aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,DARWIN -! RUN: %flang -### --target=sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX -! RUN: %flang -### --target=x86_64-unknown-freebsd %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX -! RUN: %flang -### --target=x86_64-unknown-netbsd %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX -! RUN: %flang -### --target=x86_64-unknown-openbsd %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX -! RUN: %flang -### --target=x86_64-unknown-dragonfly %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX -! RUN: %flang -### --target=x86_64-unknown-haiku %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,HAIKU -! RUN: %flang -### --target=x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MINGW +! RUN: %flang -### --target=ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,UNIX-F128%f128-lib +! RUN: %flang -### --target=aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,DARWIN,DARWIN-F128%f128-lib +! RUN: %flang -### --target=sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,SOLARIS-F128%f128-lib +! RUN: %flang -### --target=x86_64-unknown-freebsd %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,UNIX-F128%f128-lib +! RUN: %flang -### --target=x86_64-unknown-netbsd %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,UNIX-F128%f128-lib +! RUN: %flang -### --target=x86_64-unknown-openbsd %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,UNIX-F128%f128-lib +! RUN: %flang -### --target=x86_64-unknown-dragonfly %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,UNIX-F128%
[clang] [clang] Update -Wformat warnings for fixed-point format specifiers (PR #82855)
https://github.com/petrhosek approved this pull request. https://github.com/llvm/llvm-project/pull/82855 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Update -Wformat warnings for fixed-point format specifiers (PR #82855)
@@ -2981,6 +2981,10 @@ class ASTContext : public RefCountedBase { // corresponding saturated type for a given fixed point type. QualType getCorrespondingSaturatedType(QualType Ty) const; + // Per ISO N1169, this method accepts fixed point types and returns the petrhosek wrote: ```suggestion // Per ISO/IEC TR 18037:2008, this method accepts fixed point types and returns the ``` https://github.com/llvm/llvm-project/pull/82855 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Update -Wformat warnings for fixed-point format specifiers (PR #82855)
https://github.com/petrhosek deleted https://github.com/llvm/llvm-project/pull/82855 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Update -Wformat warnings for fixed-point format specifiers (PR #82855)
@@ -2981,6 +2981,10 @@ class ASTContext : public RefCountedBase { // corresponding saturated type for a given fixed point type. QualType getCorrespondingSaturatedType(QualType Ty) const; + // Per ISO N1169, this method accepts fixed point types and returns the + // corresponding non-saturated type for a given fixed point type. petrhosek wrote: ```suggestion // Per ISO/IEC TR 18037:2008, this method accepts fixed point types and // returns the corresponding non-saturated type for a given fixed point type. ``` https://github.com/llvm/llvm-project/pull/82855 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [APINotes] Upstream Sema logic to apply API Notes to decls (PR #78445)
https://github.com/compnerd edited https://github.com/llvm/llvm-project/pull/78445 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [APINotes] Upstream Sema logic to apply API Notes to decls (PR #78445)
@@ -0,0 +1,989 @@ +//===--- SemaAPINotes.cpp - API Notes Handling ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file implements the mapping from API notes to declaration attributes. +// +//===--===// + +#include "clang/APINotes/APINotesReader.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Lex/Lexer.h" +#include "clang/Sema/SemaInternal.h" + +using namespace clang; + +namespace { +enum class IsActive_t : bool { Inactive, Active }; +enum class IsReplacement_t : bool { Original, Replacement }; compnerd wrote: I'd consider renaming these now with the `enum class`: ```suggestion enum class State : bool { Inactive, Active }; enum class SubstitutionType : bool { Original, Replacement }; ``` https://github.com/llvm/llvm-project/pull/78445 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [APINotes] Upstream Sema logic to apply API Notes to decls (PR #78445)
@@ -0,0 +1,989 @@ +//===--- SemaAPINotes.cpp - API Notes Handling ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file implements the mapping from API notes to declaration attributes. +// +//===--===// + +#include "clang/APINotes/APINotesReader.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Lex/Lexer.h" +#include "clang/Sema/SemaInternal.h" + +using namespace clang; + +namespace { +enum class IsActive_t : bool { Inactive, Active }; +enum class IsReplacement_t : bool { Original, Replacement }; + +struct VersionedInfoMetadata { + /// An empty version refers to unversioned metadata. + VersionTuple Version; + unsigned IsActive : 1; + unsigned IsReplacement : 1; + + VersionedInfoMetadata(VersionTuple Version, IsActive_t Active, +IsReplacement_t Replacement) + : Version(Version), IsActive(Active == IsActive_t::Active), +IsReplacement(Replacement == IsReplacement_t::Replacement) {} +}; +} // end anonymous namespace + +/// Determine whether this is a multi-level pointer type. +static bool isIndirectPointerType(QualType Type) { + QualType Pointee = Type->getPointeeType(); + if (Pointee.isNull()) +return false; + + return Pointee->isAnyPointerType() || Pointee->isObjCObjectPointerType() || + Pointee->isMemberPointerType(); +} + +/// Apply nullability to the given declaration. +static void applyNullability(Sema &S, Decl *D, NullabilityKind Nullability, + VersionedInfoMetadata Metadata) { + if (!Metadata.IsActive) +return; + + auto IsUnmodified = [&](Decl *D, QualType QT, + NullabilityKind Nullability) -> bool { +QualType Original = QT; +S.CheckImplicitNullabilityTypeSpecifier(QT, Nullability, D->getLocation(), +isa(D), +/*OverrideExisting=*/true); +return QT.getTypePtr() == Original.getTypePtr(); + }; + + if (auto Function = dyn_cast(D)) { +if (!IsUnmodified(D, Function->getReturnType(), Nullability)) { compnerd wrote: An alternative to consider: rename the function to `IsModified` and return the negated value so simplify the callees. https://github.com/llvm/llvm-project/pull/78445 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [APINotes] Upstream Sema logic to apply API Notes to decls (PR #78445)
https://github.com/compnerd approved this pull request. Most of the new comments are nits and small readability tweaks. I still would like to avoid the double `dyn_cast` checks, but I don't know if this is worth holding up on at that point. Thank you for the multiple rounds on this and sorry about the delay, the length made it daunting. https://github.com/llvm/llvm-project/pull/78445 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [APINotes] Upstream Sema logic to apply API Notes to decls (PR #78445)
@@ -0,0 +1,989 @@ +//===--- SemaAPINotes.cpp - API Notes Handling ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file implements the mapping from API notes to declaration attributes. +// +//===--===// + +#include "clang/APINotes/APINotesReader.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Lex/Lexer.h" +#include "clang/Sema/SemaInternal.h" + +using namespace clang; + +namespace { +enum class IsActive_t : bool { Inactive, Active }; +enum class IsReplacement_t : bool { Original, Replacement }; + +struct VersionedInfoMetadata { + /// An empty version refers to unversioned metadata. + VersionTuple Version; + unsigned IsActive : 1; + unsigned IsReplacement : 1; + + VersionedInfoMetadata(VersionTuple Version, IsActive_t Active, +IsReplacement_t Replacement) + : Version(Version), IsActive(Active == IsActive_t::Active), +IsReplacement(Replacement == IsReplacement_t::Replacement) {} +}; +} // end anonymous namespace + +/// Determine whether this is a multi-level pointer type. +static bool isIndirectPointerType(QualType Type) { + QualType Pointee = Type->getPointeeType(); + if (Pointee.isNull()) +return false; + + return Pointee->isAnyPointerType() || Pointee->isObjCObjectPointerType() || + Pointee->isMemberPointerType(); +} + +/// Apply nullability to the given declaration. +static void applyNullability(Sema &S, Decl *D, NullabilityKind Nullability, + VersionedInfoMetadata Metadata) { + if (!Metadata.IsActive) +return; + + auto IsUnmodified = [&](Decl *D, QualType QT, + NullabilityKind Nullability) -> bool { +QualType Original = QT; +S.CheckImplicitNullabilityTypeSpecifier(QT, Nullability, D->getLocation(), +isa(D), +/*OverrideExisting=*/true); +return QT.getTypePtr() == Original.getTypePtr(); + }; + + if (auto Function = dyn_cast(D)) { +if (!IsUnmodified(D, Function->getReturnType(), Nullability)) { + QualType FnType = Function->getType(); + Function->setType(FnType); +} + } else if (auto Method = dyn_cast(D)) { +QualType Type = Method->getReturnType(); +if (!IsUnmodified(D, Type, Nullability)) { + Method->setReturnType(Type); + + // Make it a context-sensitive keyword if we can. + if (!isIndirectPointerType(Type)) +Method->setObjCDeclQualifier(Decl::ObjCDeclQualifier( +Method->getObjCDeclQualifier() | Decl::OBJC_TQ_CSNullability)); +} + } else if (auto Value = dyn_cast(D)) { +QualType Type = Value->getType(); +if (!IsUnmodified(D, Type, Nullability)) { + Value->setType(Type); + + // Make it a context-sensitive keyword if we can. + if (auto Parm = dyn_cast(D)) { +if (Parm->isObjCMethodParameter() && !isIndirectPointerType(Type)) + Parm->setObjCDeclQualifier(Decl::ObjCDeclQualifier( + Parm->getObjCDeclQualifier() | Decl::OBJC_TQ_CSNullability)); + } +} + } else if (auto Property = dyn_cast(D)) { +QualType Type = Property->getType(); +if (!IsUnmodified(D, Type, Nullability)) { + Property->setType(Type, Property->getTypeSourceInfo()); + + // Make it a property attribute if we can. + if (!isIndirectPointerType(Type)) +Property->setPropertyAttributes( +ObjCPropertyAttribute::kind_null_resettable); +} + } +} + +/// Copy a string into ASTContext-allocated memory. +static StringRef ASTAllocateString(ASTContext &Ctx, StringRef String) { + void *mem = Ctx.Allocate(String.size(), alignof(char *)); + memcpy(mem, String.data(), String.size()); + return StringRef(static_cast(mem), String.size()); +} + +static AttributeCommonInfo getPlaceholderAttrInfo() { + return AttributeCommonInfo(SourceRange(), + AttributeCommonInfo::UnknownAttribute, + {AttributeCommonInfo::AS_GNU, + /*Spelling*/ 0, /*IsAlignas*/ false, + /*IsRegularKeywordAttribute*/ false}); +} + +namespace { +template struct AttrKindFor {}; + +#define ATTR(X) \ + template <> struct AttrKindFor { \ +static const attr::Kind value = attr::X; \ + }; +#include "clang/Basic/AttrList.inc" + +/// Handle an attribute introduced by API notes. +/// +/// \param IsAddition Whether we shoul
[clang] [APINotes] Upstream Sema logic to apply API Notes to decls (PR #78445)
@@ -0,0 +1,989 @@ +//===--- SemaAPINotes.cpp - API Notes Handling ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file implements the mapping from API notes to declaration attributes. +// +//===--===// + +#include "clang/APINotes/APINotesReader.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Lex/Lexer.h" +#include "clang/Sema/SemaInternal.h" + +using namespace clang; + +namespace { +enum class IsActive_t : bool { Inactive, Active }; +enum class IsReplacement_t : bool { Original, Replacement }; + +struct VersionedInfoMetadata { + /// An empty version refers to unversioned metadata. + VersionTuple Version; + unsigned IsActive : 1; + unsigned IsReplacement : 1; + + VersionedInfoMetadata(VersionTuple Version, IsActive_t Active, +IsReplacement_t Replacement) + : Version(Version), IsActive(Active == IsActive_t::Active), +IsReplacement(Replacement == IsReplacement_t::Replacement) {} +}; +} // end anonymous namespace + +/// Determine whether this is a multi-level pointer type. +static bool isIndirectPointerType(QualType Type) { + QualType Pointee = Type->getPointeeType(); + if (Pointee.isNull()) +return false; + + return Pointee->isAnyPointerType() || Pointee->isObjCObjectPointerType() || + Pointee->isMemberPointerType(); +} + +/// Apply nullability to the given declaration. +static void applyNullability(Sema &S, Decl *D, NullabilityKind Nullability, + VersionedInfoMetadata Metadata) { + if (!Metadata.IsActive) +return; + + auto IsUnmodified = [&](Decl *D, QualType QT, + NullabilityKind Nullability) -> bool { +QualType Original = QT; +S.CheckImplicitNullabilityTypeSpecifier(QT, Nullability, D->getLocation(), +isa(D), +/*OverrideExisting=*/true); +return QT.getTypePtr() == Original.getTypePtr(); + }; + + if (auto Function = dyn_cast(D)) { +if (!IsUnmodified(D, Function->getReturnType(), Nullability)) { + QualType FnType = Function->getType(); + Function->setType(FnType); +} + } else if (auto Method = dyn_cast(D)) { +QualType Type = Method->getReturnType(); +if (!IsUnmodified(D, Type, Nullability)) { + Method->setReturnType(Type); + + // Make it a context-sensitive keyword if we can. + if (!isIndirectPointerType(Type)) +Method->setObjCDeclQualifier(Decl::ObjCDeclQualifier( +Method->getObjCDeclQualifier() | Decl::OBJC_TQ_CSNullability)); +} + } else if (auto Value = dyn_cast(D)) { +QualType Type = Value->getType(); +if (!IsUnmodified(D, Type, Nullability)) { + Value->setType(Type); + + // Make it a context-sensitive keyword if we can. + if (auto Parm = dyn_cast(D)) { +if (Parm->isObjCMethodParameter() && !isIndirectPointerType(Type)) + Parm->setObjCDeclQualifier(Decl::ObjCDeclQualifier( + Parm->getObjCDeclQualifier() | Decl::OBJC_TQ_CSNullability)); + } +} + } else if (auto Property = dyn_cast(D)) { +QualType Type = Property->getType(); +if (!IsUnmodified(D, Type, Nullability)) { + Property->setType(Type, Property->getTypeSourceInfo()); + + // Make it a property attribute if we can. + if (!isIndirectPointerType(Type)) +Property->setPropertyAttributes( +ObjCPropertyAttribute::kind_null_resettable); +} + } +} + +/// Copy a string into ASTContext-allocated memory. +static StringRef ASTAllocateString(ASTContext &Ctx, StringRef String) { + void *mem = Ctx.Allocate(String.size(), alignof(char *)); + memcpy(mem, String.data(), String.size()); + return StringRef(static_cast(mem), String.size()); +} + +static AttributeCommonInfo getPlaceholderAttrInfo() { + return AttributeCommonInfo(SourceRange(), + AttributeCommonInfo::UnknownAttribute, + {AttributeCommonInfo::AS_GNU, + /*Spelling*/ 0, /*IsAlignas*/ false, + /*IsRegularKeywordAttribute*/ false}); +} + +namespace { +template struct AttrKindFor {}; + +#define ATTR(X) \ + template <> struct AttrKindFor { \ +static const attr::Kind value = attr::X; \ + }; +#include "clang/Basic/AttrList.inc" + +/// Handle an attribute introduced by API notes. +/// +/// \param IsAddition Whether we shoul
[clang] [APINotes] Upstream Sema logic to apply API Notes to decls (PR #78445)
@@ -0,0 +1,989 @@ +//===--- SemaAPINotes.cpp - API Notes Handling ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file implements the mapping from API notes to declaration attributes. +// +//===--===// + +#include "clang/APINotes/APINotesReader.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Lex/Lexer.h" +#include "clang/Sema/SemaInternal.h" + +using namespace clang; + +namespace { +enum class IsActive_t : bool { Inactive, Active }; +enum class IsReplacement_t : bool { Original, Replacement }; + +struct VersionedInfoMetadata { + /// An empty version refers to unversioned metadata. + VersionTuple Version; + unsigned IsActive : 1; + unsigned IsReplacement : 1; + + VersionedInfoMetadata(VersionTuple Version, IsActive_t Active, +IsReplacement_t Replacement) + : Version(Version), IsActive(Active == IsActive_t::Active), +IsReplacement(Replacement == IsReplacement_t::Replacement) {} +}; +} // end anonymous namespace + +/// Determine whether this is a multi-level pointer type. +static bool isIndirectPointerType(QualType Type) { + QualType Pointee = Type->getPointeeType(); + if (Pointee.isNull()) +return false; + + return Pointee->isAnyPointerType() || Pointee->isObjCObjectPointerType() || + Pointee->isMemberPointerType(); +} + +/// Apply nullability to the given declaration. +static void applyNullability(Sema &S, Decl *D, NullabilityKind Nullability, + VersionedInfoMetadata Metadata) { + if (!Metadata.IsActive) +return; + + auto IsUnmodified = [&](Decl *D, QualType QT, + NullabilityKind Nullability) -> bool { +QualType Original = QT; +S.CheckImplicitNullabilityTypeSpecifier(QT, Nullability, D->getLocation(), +isa(D), +/*OverrideExisting=*/true); +return QT.getTypePtr() == Original.getTypePtr(); + }; + + if (auto Function = dyn_cast(D)) { +if (!IsUnmodified(D, Function->getReturnType(), Nullability)) { + QualType FnType = Function->getType(); + Function->setType(FnType); +} + } else if (auto Method = dyn_cast(D)) { +QualType Type = Method->getReturnType(); +if (!IsUnmodified(D, Type, Nullability)) { + Method->setReturnType(Type); + + // Make it a context-sensitive keyword if we can. + if (!isIndirectPointerType(Type)) +Method->setObjCDeclQualifier(Decl::ObjCDeclQualifier( +Method->getObjCDeclQualifier() | Decl::OBJC_TQ_CSNullability)); +} + } else if (auto Value = dyn_cast(D)) { +QualType Type = Value->getType(); +if (!IsUnmodified(D, Type, Nullability)) { + Value->setType(Type); + + // Make it a context-sensitive keyword if we can. + if (auto Parm = dyn_cast(D)) { +if (Parm->isObjCMethodParameter() && !isIndirectPointerType(Type)) + Parm->setObjCDeclQualifier(Decl::ObjCDeclQualifier( + Parm->getObjCDeclQualifier() | Decl::OBJC_TQ_CSNullability)); + } +} + } else if (auto Property = dyn_cast(D)) { +QualType Type = Property->getType(); +if (!IsUnmodified(D, Type, Nullability)) { + Property->setType(Type, Property->getTypeSourceInfo()); + + // Make it a property attribute if we can. + if (!isIndirectPointerType(Type)) +Property->setPropertyAttributes( +ObjCPropertyAttribute::kind_null_resettable); +} + } +} + +/// Copy a string into ASTContext-allocated memory. +static StringRef ASTAllocateString(ASTContext &Ctx, StringRef String) { + void *mem = Ctx.Allocate(String.size(), alignof(char *)); + memcpy(mem, String.data(), String.size()); + return StringRef(static_cast(mem), String.size()); +} + +static AttributeCommonInfo getPlaceholderAttrInfo() { + return AttributeCommonInfo(SourceRange(), + AttributeCommonInfo::UnknownAttribute, + {AttributeCommonInfo::AS_GNU, + /*Spelling*/ 0, /*IsAlignas*/ false, + /*IsRegularKeywordAttribute*/ false}); +} + +namespace { +template struct AttrKindFor {}; + +#define ATTR(X) \ + template <> struct AttrKindFor { \ +static const attr::Kind value = attr::X; \ + }; +#include "clang/Basic/AttrList.inc" + +/// Handle an attribute introduced by API notes. +/// +/// \param IsAddition Whether we shoul
[clang] [APINotes] Upstream Sema logic to apply API Notes to decls (PR #78445)
@@ -0,0 +1,989 @@ +//===--- SemaAPINotes.cpp - API Notes Handling ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file implements the mapping from API notes to declaration attributes. +// +//===--===// + +#include "clang/APINotes/APINotesReader.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Lex/Lexer.h" +#include "clang/Sema/SemaInternal.h" + +using namespace clang; + +namespace { +enum class IsActive_t : bool { Inactive, Active }; +enum class IsReplacement_t : bool { Original, Replacement }; + +struct VersionedInfoMetadata { + /// An empty version refers to unversioned metadata. + VersionTuple Version; + unsigned IsActive : 1; + unsigned IsReplacement : 1; + + VersionedInfoMetadata(VersionTuple Version, IsActive_t Active, +IsReplacement_t Replacement) + : Version(Version), IsActive(Active == IsActive_t::Active), +IsReplacement(Replacement == IsReplacement_t::Replacement) {} +}; +} // end anonymous namespace + +/// Determine whether this is a multi-level pointer type. +static bool isIndirectPointerType(QualType Type) { + QualType Pointee = Type->getPointeeType(); + if (Pointee.isNull()) +return false; + + return Pointee->isAnyPointerType() || Pointee->isObjCObjectPointerType() || + Pointee->isMemberPointerType(); +} + +/// Apply nullability to the given declaration. +static void applyNullability(Sema &S, Decl *D, NullabilityKind Nullability, + VersionedInfoMetadata Metadata) { + if (!Metadata.IsActive) +return; + + auto IsUnmodified = [&](Decl *D, QualType QT, + NullabilityKind Nullability) -> bool { +QualType Original = QT; +S.CheckImplicitNullabilityTypeSpecifier(QT, Nullability, D->getLocation(), +isa(D), +/*OverrideExisting=*/true); +return QT.getTypePtr() == Original.getTypePtr(); + }; + + if (auto Function = dyn_cast(D)) { +if (!IsUnmodified(D, Function->getReturnType(), Nullability)) { + QualType FnType = Function->getType(); + Function->setType(FnType); +} + } else if (auto Method = dyn_cast(D)) { +QualType Type = Method->getReturnType(); +if (!IsUnmodified(D, Type, Nullability)) { + Method->setReturnType(Type); + + // Make it a context-sensitive keyword if we can. + if (!isIndirectPointerType(Type)) +Method->setObjCDeclQualifier(Decl::ObjCDeclQualifier( +Method->getObjCDeclQualifier() | Decl::OBJC_TQ_CSNullability)); +} + } else if (auto Value = dyn_cast(D)) { +QualType Type = Value->getType(); +if (!IsUnmodified(D, Type, Nullability)) { + Value->setType(Type); + + // Make it a context-sensitive keyword if we can. + if (auto Parm = dyn_cast(D)) { +if (Parm->isObjCMethodParameter() && !isIndirectPointerType(Type)) + Parm->setObjCDeclQualifier(Decl::ObjCDeclQualifier( + Parm->getObjCDeclQualifier() | Decl::OBJC_TQ_CSNullability)); + } +} + } else if (auto Property = dyn_cast(D)) { +QualType Type = Property->getType(); +if (!IsUnmodified(D, Type, Nullability)) { + Property->setType(Type, Property->getTypeSourceInfo()); + + // Make it a property attribute if we can. + if (!isIndirectPointerType(Type)) +Property->setPropertyAttributes( +ObjCPropertyAttribute::kind_null_resettable); +} + } +} + +/// Copy a string into ASTContext-allocated memory. +static StringRef ASTAllocateString(ASTContext &Ctx, StringRef String) { + void *mem = Ctx.Allocate(String.size(), alignof(char *)); + memcpy(mem, String.data(), String.size()); + return StringRef(static_cast(mem), String.size()); +} + +static AttributeCommonInfo getPlaceholderAttrInfo() { + return AttributeCommonInfo(SourceRange(), + AttributeCommonInfo::UnknownAttribute, + {AttributeCommonInfo::AS_GNU, + /*Spelling*/ 0, /*IsAlignas*/ false, + /*IsRegularKeywordAttribute*/ false}); +} + +namespace { +template struct AttrKindFor {}; + +#define ATTR(X) \ + template <> struct AttrKindFor { \ +static const attr::Kind value = attr::X; \ + }; +#include "clang/Basic/AttrList.inc" + +/// Handle an attribute introduced by API notes. +/// +/// \param IsAddition Whether we shoul
[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)
MaxEW707 wrote: I will need someone to commit on my behalf since I do not have write access. > lgtm, and good to land provided you do a quick re-check to confirm that this > doesn't tank compile times now with that part included. Thanks! The include times below are done with the following source file using a locally release build of clang, `-ftime-trace`, and msvc stl shipped with MSVC 1939. ``` #include #include #include ``` clang-cl.exe without `yvals_core.h` shadowing takes ~1,344 ms in the frontend. `intrin.h` took ~955 ms to parse. clang-cl.exe with `yvals_core.h` shadowing takes ~395 ms in the frontend. `intrin0.h` took ~1.4 ms to parse. https://github.com/llvm/llvm-project/pull/75711 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)
@@ -0,0 +1,26 @@ +/* === vadefs.h ---=== + * + * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. + * See https://llvm.org/LICENSE.txt for license information. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + * + *===---=== + */ + +/* Only include this if we are aiming for MSVC compatibility. */ MaxEW707 wrote: We do not need `/* */`. I was just copying from the other files in this folder for the copyright header and clang-format didn't complain. I'll give the style guide a read and get this fixed :). https://github.com/llvm/llvm-project/pull/75711 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)
https://github.com/MaxEW707 edited https://github.com/llvm/llvm-project/pull/75711 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cc53707 - LLVMInstrumentation: Simplify mcdc.tvbitmap.update with GEP.
Author: NAKAMURA Takumi Date: 2024-02-25T11:21:46+09:00 New Revision: cc53707a5c104eb7789829ecdb2e3ae2be1a42da URL: https://github.com/llvm/llvm-project/commit/cc53707a5c104eb7789829ecdb2e3ae2be1a42da DIFF: https://github.com/llvm/llvm-project/commit/cc53707a5c104eb7789829ecdb2e3ae2be1a42da.diff LOG: LLVMInstrumentation: Simplify mcdc.tvbitmap.update with GEP. Added: Modified: clang/test/Profile/c-mcdc-class.cpp clang/test/Profile/c-mcdc-logicalop-ternary.c clang/test/Profile/c-mcdc-nested-ternary.c clang/test/Profile/c-mcdc-not.c clang/test/Profile/c-mcdc.c llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp llvm/test/Instrumentation/InstrProfiling/mcdc.ll Removed: diff --git a/clang/test/Profile/c-mcdc-class.cpp b/clang/test/Profile/c-mcdc-class.cpp index 2206a39ee4ffb4..6aab55add32807 100644 --- a/clang/test/Profile/c-mcdc-class.cpp +++ b/clang/test/Profile/c-mcdc-class.cpp @@ -54,9 +54,7 @@ Value::~Value(void) { // UPDATE FINAL BITMASK WITH RESULT. // MCDCCTOR-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4 // MCDCCTOR: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3 -// MCDCCTOR: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64 -// MCDCCTOR: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm__ZN5ValueC2Ev to i64), %[[LAB2]] -// MCDCCTOR: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr +// MCDCCTOR: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm__ZN5ValueC2Ev, i32 %[[LAB1]] // MCDCCTOR: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7 // MCDCCTOR: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8 // MCDCCTOR: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]] @@ -93,9 +91,7 @@ Value::~Value(void) { // UPDATE FINAL BITMASK WITH RESULT. // MCDCDTOR-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4 // MCDCDTOR: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3 -// MCDCDTOR: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64 -// MCDCDTOR: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm__ZN5ValueD2Ev to i64), %[[LAB2]] -// MCDCDTOR: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr +// MCDCDTOR: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm__ZN5ValueD2Ev, i32 %[[LAB1]] // MCDCDTOR: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7 // MCDCDTOR: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8 // MCDCDTOR: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]] diff --git a/clang/test/Profile/c-mcdc-logicalop-ternary.c b/clang/test/Profile/c-mcdc-logicalop-ternary.c index 558643f422021c..3e6b6b1e380d1e 100644 --- a/clang/test/Profile/c-mcdc-logicalop-ternary.c +++ b/clang/test/Profile/c-mcdc-logicalop-ternary.c @@ -20,9 +20,7 @@ int test(int a, int b, int c, int d, int e, int f) { // MCDC-LABEL: cond.true: // MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4 // MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3 -// MCDC: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64 -// MCDC: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm_test to i64), %[[LAB2]] -// MCDC: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr +// MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm_test, i32 %[[LAB1]] // MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7 // MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8 // MCDC: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]] @@ -38,9 +36,7 @@ int test(int a, int b, int c, int d, int e, int f) { // MCDC-LABEL: land.end: // MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4 // MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3 -// MCDC: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64 -// MCDC: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr getelementptr inbounds ([3 x i8], ptr @__profbm_test, i32 0, i32 1) to i64), %[[LAB2]] -// MCDC: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr +// MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr getelementptr inbounds ([3 x i8], ptr @__profbm_test, i32 0, i32 1), i32 %[[LAB1]] // MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7 // MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8 // MCDC: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]] @@ -52,9 +48,7 @@ int test(int a, int b, int c, int d, int e, int f) { // MCDC-LABEL: cond.false: // MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4 // MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3 -// MCDC: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64 -// MCDC: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm_test to i64), %[[LAB2]] -// MCDC: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr +// MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm_test, i32 %[[LAB1]] // MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7 // MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8 // MCDC: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]] @@ -70,9 +64,7 @@ int test(int a, int b, int c, int d, int e, int f) { // MCDC-LABEL: lor.end: // MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i
[clang] [clang-format] Limit how much work guessLanguage() can do (PR #78925)
HighCommander4 wrote: > I thought the `GuessObjC` flag would allow clangd to skip the guessing ObjC > part for those "users who merely use these libraries (and so may open them in > the editor to look at the header, but will not try to format it)". Ok, I see what you're getting at. Clangd calls into `guessLanguage()` via `format::getStyle()` which [calls `guessLanguage()`](https://searchfox.org/llvm/rev/60a904b2ad9842b93cc5fa0ad5bda5e22c550b7e/clang/lib/Format/Format.cpp#3956). I audited clangd's code to see what it uses the returned `FormatStyle` for: 1. When hovering over a symbol, we call `format::reformat()` on the code snippet shown in the hover (e.g. definition of the variable whose use you are hovering over). 2. Formatting edits (via `format::cleanupAroundReplacements()` and `format::formatReplacements()`) made by various clangd operations (e.g. accepting a code completion proposal, performing a rename or other code action, etc.) 3. Inserting new `#include` directives (e.g. associated with a code completion proposal, or a quick-fix for a diagnostic). For this one, clangd inspects `IncludeStyle` manually to choose an insertion point. 4. Formatting the whole file (or a selected range of text) using `format::reformat()`. Of these, (1) is the only one that can be triggered without modifying the file. So, if `format::getStyle()` had a `GuessObjC` parameter (which it propagated into `guessLanguage()`), I think we could refactor things such that (1) used `GuessObjC=false` and the others used `GuessObjC=true`. (We may even be able to use `GuessObjC=false` for (2) and (3), since those are just formatting a small amount of code.) @owenca if you're ok in principle with this libFormat API extension (adding an optional `GuessObjC` parameter to `format::getStyle()`), I'm happy to try prototyping these changes in clangd. https://github.com/llvm/llvm-project/pull/78925 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits