[clang] [llvm] [llvm][Triple] Add `Environment` members and parsing for glibc/musl parity. (PR #107664)
wzssyqa wrote: > My understanding is that all of these `musl*` environments have been added to > GCC and LLVM on an as-needed basis for toolchains, not necessarily because > musl itself needs them. Do you have interesting to add them to GCC? I guess we need to add config.sub/config.guess first. https://github.com/llvm/llvm-project/pull/107664 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)
@@ -443,6 +443,426 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) { return false; } +AST_MATCHER_P(CallExpr, hasNumArgs, unsigned, Num) { + return Node.getNumArgs() == Num; +} + +namespace libc_func_matchers { +// Under `libc_func_matchers`, define a set of matchers that match unsafe +// functions in libc and unsafe calls to them. + +// A tiny parser to strip off common prefix and suffix of libc function names +// in real code. +// +// Given a function name, `matchName` returns `CoreName` according to the +// following grammar: +// +// LibcName := CoreName | CoreName + "_s" +// MatchingName := "__builtin_" + LibcName | +// "__builtin___" + LibcName + "_chk" | +// "__asan_" + LibcName +// +struct LibcFunNamePrefixSuffixParser { + StringRef matchName(StringRef FunName, bool isBuiltin) { +// Try to match __builtin_: +if (isBuiltin && FunName.starts_with("__builtin_")) + // Then either it is __builtin_LibcName or __builtin___LibcName_chk or + // no match: + return matchLibcNameOrBuiltinChk( + FunName.drop_front(10 /* truncate "__builtin_" */)); +// Try to match __asan_: +if (FunName.starts_with("__asan_")) + return matchLibcName(FunName.drop_front(7 /* truncate of "__asan_" */)); +return matchLibcName(FunName); + } + + // Parameter `Name` is the substring after stripping off the prefix + // "__builtin_". + StringRef matchLibcNameOrBuiltinChk(StringRef Name) { +if (Name.starts_with("__") && Name.ends_with("_chk")) + return matchLibcName( + Name.drop_front(2).drop_back(4) /* truncate "__" and "_chk" */); +return matchLibcName(Name); + } + + StringRef matchLibcName(StringRef Name) { +if (Name.ends_with("_s")) + return Name.drop_back(2 /* truncate "_s" */); +return Name; + } +}; + +// A pointer type expression is known to be null-terminated, if it has the +// form: E.c_str(), for any expression E of `std::string` type. +static bool isNullTermPointer(const Expr *Ptr) { + if (isa(Ptr->IgnoreParenImpCasts())) +return true; + if (isa(Ptr->IgnoreParenImpCasts())) +return true; + if (auto *MCE = dyn_cast(Ptr->IgnoreParenImpCasts())) { +const CXXMethodDecl *MD = MCE->getMethodDecl(); +const CXXRecordDecl *RD = MCE->getRecordDecl()->getCanonicalDecl(); + +if (MD && RD && RD->isInStdNamespace()) + if (MD->getName() == "c_str" && RD->getName() == "basic_string") +return true; + } + return false; +} + +// Return true iff at least one of following cases holds: +// 1. Format string is a literal and there is an unsafe pointer argument +// corresponding to an `s` specifier; +// 2. Format string is not a literal and there is least an unsafe pointer +// argument (including the formatter argument). +// +// `UnsafeArg` is the output argument that will be set only if this function +// returns true. +static bool hasUnsafeFormatOrSArg(const CallExpr *Call, const Expr *&UnsafeArg, + const unsigned FmtArgIdx, ASTContext &Ctx, + bool isKprintf = false) { + class StringFormatStringHandler + : public analyze_format_string::FormatStringHandler { +const CallExpr *Call; +unsigned FmtArgIdx; +const Expr *&UnsafeArg; + + public: +StringFormatStringHandler(const CallExpr *Call, unsigned FmtArgIdx, + const Expr *&UnsafeArg) +: Call(Call), FmtArgIdx(FmtArgIdx), UnsafeArg(UnsafeArg) {} + +bool HandlePrintfSpecifier(const analyze_printf::PrintfSpecifier &FS, + const char *startSpecifier, + unsigned specifierLen, + const TargetInfo &Target) override { + if (FS.getConversionSpecifier().getKind() == + analyze_printf::PrintfConversionSpecifier::sArg) { +unsigned ArgIdx = FS.getPositionalArgIndex() + FmtArgIdx; + +if (0 < ArgIdx && ArgIdx < Call->getNumArgs()) + if (!isNullTermPointer(Call->getArg(ArgIdx))) { +UnsafeArg = Call->getArg(ArgIdx); // output +// returning false stops parsing immediately +return false; + } + } + return true; // continue parsing +} + }; + + const Expr *Fmt = Call->getArg(FmtArgIdx); + + if (auto *SL = dyn_cast(Fmt->IgnoreParenImpCasts())) { +StringRef FmtStr = SL->getString(); +StringFormatStringHandler Handler(Call, FmtArgIdx, UnsafeArg); + +return analyze_format_string::ParsePrintfString( +Handler, FmtStr.begin(), FmtStr.end(), Ctx.getLangOpts(), +Ctx.getTargetInfo(), isKprintf); + } + // If format is not a string literal, we cannot analyze the format string. + // In this case, this call is considered unsafe if at least one argument + // (including the format argument) is unsafe pointer. + return llvm::any_of( + llvm::make_range(Call->arg_begin(
[clang] [llvm] [DirectX] Remove trivially dead functions at linkage finalize (PR #106146)
llvmbot wrote: @llvm/pr-subscribers-hlsl Author: Greg Roth (pow2clk) Changes Functions are not removed even when made internal by DXILFinalizeLinkage The removal code is called from alwaysinliner and globalopt, which are invoked too early to remove functions made internal by this pass. This adds a check similar to that in alwaysinliner that removes trivially dead functions after being marked internal. It refactors that code a bit to make it simpler including reversing what is stored in the work queue. Not sure how to test this. To test all the interactions between alwaysinliner, DXILfinalizelinkage and any other optimization passes, it kinda needs to be end-to-end. Fixes #106139 --- Full diff: https://github.com/llvm/llvm-project/pull/106146.diff 3 Files Affected: - (added) clang/test/CodeGenHLSL/remove-internal-unused.hlsl (+47) - (modified) llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp (+8-8) - (added) llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll (+80) ``diff diff --git a/clang/test/CodeGenHLSL/remove-internal-unused.hlsl b/clang/test/CodeGenHLSL/remove-internal-unused.hlsl new file mode 100644 index 00..85c114618a1e0e --- /dev/null +++ b/clang/test/CodeGenHLSL/remove-internal-unused.hlsl @@ -0,0 +1,47 @@ +// RUN: %clang -target dxil-pc-shadermodel6.0-compute -S -o - %s | FileCheck %s +// RUN: %clang -target dxil-pc-shadermodel6.3-library -S -o - %s | FileCheck %s + +// Verify that internal linkage unused functions are removed + +RWBuffer buf; + +// Never called functions should be removed. +// CHECK-NOT: define{{.*}}uncalledFor +void uncalledFor() { + buf[1] = 1; +} + +// Never called but exported functions should remain. +// CHECK: define void @"?exported@@YAXXZ"() +export void exported() { + buf[1] = 1; +} + +// Never called but noinlined functions should remain. +// CHECK: define internal void @"?noinlined@@YAXXZ"() +__attribute__((noinline)) void noinlined() { + buf[1] = 1; +} + +// Called functions marked noinline should remain. +// CHECK: define internal void @"?calledAndNoinlined@@YAXXZ"() +__attribute__((noinline)) void calledAndNoinlined() { + buf[1] = 1; +} + +// Called functions that get inlined by default should be removed. +// CHECK-NOT: define{{.*}}calledAndInlined +void calledAndInlined() { + buf[1] = 1; +} + + +// Entry point functions should remain. +// CHECK: define{{.*}}main +[numthreads(1,1,1)] +[shader("compute")] +void main() { + calledAndInlined(); + calledAndNoinlined(); + buf[0] = 0; +} \ No newline at end of file diff --git a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp index d315d9bd16f439..59b30f965bf951 100644 --- a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp +++ b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp @@ -19,20 +19,20 @@ using namespace llvm; static bool finalizeLinkage(Module &M) { - SmallPtrSet EntriesAndExports; + SmallPtrSet Funcs; // Find all entry points and export functions for (Function &EF : M.functions()) { -if (!EF.hasFnAttribute("hlsl.shader") && !EF.hasFnAttribute("hlsl.export")) +if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export")) continue; -EntriesAndExports.insert(&EF); +Funcs.insert(&EF); } - for (Function &F : M.functions()) { -if (F.getLinkage() == GlobalValue::ExternalLinkage && -!EntriesAndExports.contains(&F)) { - F.setLinkage(GlobalValue::InternalLinkage); -} + for (Function *F : Funcs) { +if (F->getLinkage() == GlobalValue::ExternalLinkage) + F->setLinkage(GlobalValue::InternalLinkage); +if (F->hasFnAttribute(Attribute::AlwaysInline) && F->isDefTriviallyDead()) + M.getFunctionList().erase(F); } return false; diff --git a/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll new file mode 100644 index 00..df5934355664d1 --- /dev/null +++ b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll @@ -0,0 +1,80 @@ +; RUN: opt -S -dxil-finalize-linkage -mtriple=dxil-unknown-shadermodel6.5-compute %s | FileCheck %s +; RUN: llc %s --filetype=asm -o - | FileCheck %s + +target triple = "dxilv1.5-pc-shadermodel6.5-compute" + +; Confirm that DXILFinalizeLinkage will remove functions that have compatible +; linkage and are not called from anywhere. This should be any function that +; is not explicitly marked noinline or export and is not an entry point. + +; Not called nor marked with any linking or inlining attributes. +; CHECK-NOT: define {{.*}}doNothingNothing +define void @"?doNothingNothing@@YAXXZ"() #0 { +entry: + ret void +} + +; Marked internal, this should be removed. +; CHECK-NOT: define {{.*}}doNothingInternally +define internal void @"?doNothingInternally@@YAXXZ"() #0 { +entry: + ret void +} + +; Marked external, which should become internal and be removed. +; CHECK-NOT: define {{.*}}doNothingExtern
[clang] [llvm] [DirectX] Remove trivially dead functions at linkage finalize (PR #106146)
@@ -19,20 +19,20 @@ using namespace llvm; static bool finalizeLinkage(Module &M) { - SmallPtrSet EntriesAndExports; + SmallPtrSet Funcs; // Find all entry points and export functions for (Function &EF : M.functions()) { -if (!EF.hasFnAttribute("hlsl.shader") && !EF.hasFnAttribute("hlsl.export")) +if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export")) continue; -EntriesAndExports.insert(&EF); +Funcs.insert(&EF); } - for (Function &F : M.functions()) { -if (F.getLinkage() == GlobalValue::ExternalLinkage && -!EntriesAndExports.contains(&F)) { - F.setLinkage(GlobalValue::InternalLinkage); -} + for (Function *F : Funcs) { +if (F->getLinkage() == GlobalValue::ExternalLinkage) + F->setLinkage(GlobalValue::InternalLinkage); +if (F->hasFnAttribute(Attribute::AlwaysInline) && F->isDefTriviallyDead()) python3kgae wrote: Could we remove F which is isDefTriviallyDead() but not AlwaysInline here? https://github.com/llvm/llvm-project/pull/106146 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [DirectX] Remove trivially dead functions at linkage finalize (PR #106146)
https://github.com/pow2clk edited https://github.com/llvm/llvm-project/pull/106146 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [DirectX] Remove trivially dead functions at linkage finalize (PR #106146)
https://github.com/pow2clk edited https://github.com/llvm/llvm-project/pull/106146 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [DirectX] Remove trivially dead functions at linkage finalize (PR #106146)
llvmbot wrote: @llvm/pr-subscribers-backend-directx Author: Greg Roth (pow2clk) Changes Functions are not removed even when made internal by DXILFinalizeLinkage The removal code is called from alwaysinliner and globalopt, which are invoked too early to remove functions made internal by this pass. This adds a check similar to that in alwaysinliner that removes trivially dead functions after being marked internal. It refactors that code a bit to make it simpler including reversing what is stored in the work queue. Not sure how to test this. To test all the interactions between alwaysinliner, DXILfinalizelinkage and any other optimization passes, it kinda needs to be end-to-end. Fixes #106139 --- Full diff: https://github.com/llvm/llvm-project/pull/106146.diff 3 Files Affected: - (added) clang/test/CodeGenHLSL/remove-internal-unused.hlsl (+47) - (modified) llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp (+8-8) - (added) llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll (+80) ``diff diff --git a/clang/test/CodeGenHLSL/remove-internal-unused.hlsl b/clang/test/CodeGenHLSL/remove-internal-unused.hlsl new file mode 100644 index 00..85c114618a1e0e --- /dev/null +++ b/clang/test/CodeGenHLSL/remove-internal-unused.hlsl @@ -0,0 +1,47 @@ +// RUN: %clang -target dxil-pc-shadermodel6.0-compute -S -o - %s | FileCheck %s +// RUN: %clang -target dxil-pc-shadermodel6.3-library -S -o - %s | FileCheck %s + +// Verify that internal linkage unused functions are removed + +RWBuffer buf; + +// Never called functions should be removed. +// CHECK-NOT: define{{.*}}uncalledFor +void uncalledFor() { + buf[1] = 1; +} + +// Never called but exported functions should remain. +// CHECK: define void @"?exported@@YAXXZ"() +export void exported() { + buf[1] = 1; +} + +// Never called but noinlined functions should remain. +// CHECK: define internal void @"?noinlined@@YAXXZ"() +__attribute__((noinline)) void noinlined() { + buf[1] = 1; +} + +// Called functions marked noinline should remain. +// CHECK: define internal void @"?calledAndNoinlined@@YAXXZ"() +__attribute__((noinline)) void calledAndNoinlined() { + buf[1] = 1; +} + +// Called functions that get inlined by default should be removed. +// CHECK-NOT: define{{.*}}calledAndInlined +void calledAndInlined() { + buf[1] = 1; +} + + +// Entry point functions should remain. +// CHECK: define{{.*}}main +[numthreads(1,1,1)] +[shader("compute")] +void main() { + calledAndInlined(); + calledAndNoinlined(); + buf[0] = 0; +} \ No newline at end of file diff --git a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp index d315d9bd16f439..59b30f965bf951 100644 --- a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp +++ b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp @@ -19,20 +19,20 @@ using namespace llvm; static bool finalizeLinkage(Module &M) { - SmallPtrSet EntriesAndExports; + SmallPtrSet Funcs; // Find all entry points and export functions for (Function &EF : M.functions()) { -if (!EF.hasFnAttribute("hlsl.shader") && !EF.hasFnAttribute("hlsl.export")) +if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export")) continue; -EntriesAndExports.insert(&EF); +Funcs.insert(&EF); } - for (Function &F : M.functions()) { -if (F.getLinkage() == GlobalValue::ExternalLinkage && -!EntriesAndExports.contains(&F)) { - F.setLinkage(GlobalValue::InternalLinkage); -} + for (Function *F : Funcs) { +if (F->getLinkage() == GlobalValue::ExternalLinkage) + F->setLinkage(GlobalValue::InternalLinkage); +if (F->hasFnAttribute(Attribute::AlwaysInline) && F->isDefTriviallyDead()) + M.getFunctionList().erase(F); } return false; diff --git a/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll new file mode 100644 index 00..df5934355664d1 --- /dev/null +++ b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll @@ -0,0 +1,80 @@ +; RUN: opt -S -dxil-finalize-linkage -mtriple=dxil-unknown-shadermodel6.5-compute %s | FileCheck %s +; RUN: llc %s --filetype=asm -o - | FileCheck %s + +target triple = "dxilv1.5-pc-shadermodel6.5-compute" + +; Confirm that DXILFinalizeLinkage will remove functions that have compatible +; linkage and are not called from anywhere. This should be any function that +; is not explicitly marked noinline or export and is not an entry point. + +; Not called nor marked with any linking or inlining attributes. +; CHECK-NOT: define {{.*}}doNothingNothing +define void @"?doNothingNothing@@YAXXZ"() #0 { +entry: + ret void +} + +; Marked internal, this should be removed. +; CHECK-NOT: define {{.*}}doNothingInternally +define internal void @"?doNothingInternally@@YAXXZ"() #0 { +entry: + ret void +} + +; Marked external, which should become internal and be removed. +; CHECK-NOT: define {{.*}}doNo
[clang] [llvm] [DirectX] Remove trivially dead functions at linkage finalize (PR #106146)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Greg Roth (pow2clk) Changes Functions are not removed even when made internal by DXILFinalizeLinkage The removal code is called from alwaysinliner and globalopt, which are invoked too early to remove functions made internal by this pass. This adds a check similar to that in alwaysinliner that removes trivially dead functions after being marked internal. It refactors that code a bit to make it simpler including reversing what is stored in the work queue. Not sure how to test this. To test all the interactions between alwaysinliner, DXILfinalizelinkage and any other optimization passes, it kinda needs to be end-to-end. Fixes #106139 --- Full diff: https://github.com/llvm/llvm-project/pull/106146.diff 3 Files Affected: - (added) clang/test/CodeGenHLSL/remove-internal-unused.hlsl (+47) - (modified) llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp (+8-8) - (added) llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll (+80) ``diff diff --git a/clang/test/CodeGenHLSL/remove-internal-unused.hlsl b/clang/test/CodeGenHLSL/remove-internal-unused.hlsl new file mode 100644 index 00..85c114618a1e0e --- /dev/null +++ b/clang/test/CodeGenHLSL/remove-internal-unused.hlsl @@ -0,0 +1,47 @@ +// RUN: %clang -target dxil-pc-shadermodel6.0-compute -S -o - %s | FileCheck %s +// RUN: %clang -target dxil-pc-shadermodel6.3-library -S -o - %s | FileCheck %s + +// Verify that internal linkage unused functions are removed + +RWBuffer buf; + +// Never called functions should be removed. +// CHECK-NOT: define{{.*}}uncalledFor +void uncalledFor() { + buf[1] = 1; +} + +// Never called but exported functions should remain. +// CHECK: define void @"?exported@@YAXXZ"() +export void exported() { + buf[1] = 1; +} + +// Never called but noinlined functions should remain. +// CHECK: define internal void @"?noinlined@@YAXXZ"() +__attribute__((noinline)) void noinlined() { + buf[1] = 1; +} + +// Called functions marked noinline should remain. +// CHECK: define internal void @"?calledAndNoinlined@@YAXXZ"() +__attribute__((noinline)) void calledAndNoinlined() { + buf[1] = 1; +} + +// Called functions that get inlined by default should be removed. +// CHECK-NOT: define{{.*}}calledAndInlined +void calledAndInlined() { + buf[1] = 1; +} + + +// Entry point functions should remain. +// CHECK: define{{.*}}main +[numthreads(1,1,1)] +[shader("compute")] +void main() { + calledAndInlined(); + calledAndNoinlined(); + buf[0] = 0; +} \ No newline at end of file diff --git a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp index d315d9bd16f439..59b30f965bf951 100644 --- a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp +++ b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp @@ -19,20 +19,20 @@ using namespace llvm; static bool finalizeLinkage(Module &M) { - SmallPtrSet EntriesAndExports; + SmallPtrSet Funcs; // Find all entry points and export functions for (Function &EF : M.functions()) { -if (!EF.hasFnAttribute("hlsl.shader") && !EF.hasFnAttribute("hlsl.export")) +if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export")) continue; -EntriesAndExports.insert(&EF); +Funcs.insert(&EF); } - for (Function &F : M.functions()) { -if (F.getLinkage() == GlobalValue::ExternalLinkage && -!EntriesAndExports.contains(&F)) { - F.setLinkage(GlobalValue::InternalLinkage); -} + for (Function *F : Funcs) { +if (F->getLinkage() == GlobalValue::ExternalLinkage) + F->setLinkage(GlobalValue::InternalLinkage); +if (F->hasFnAttribute(Attribute::AlwaysInline) && F->isDefTriviallyDead()) + M.getFunctionList().erase(F); } return false; diff --git a/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll new file mode 100644 index 00..df5934355664d1 --- /dev/null +++ b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll @@ -0,0 +1,80 @@ +; RUN: opt -S -dxil-finalize-linkage -mtriple=dxil-unknown-shadermodel6.5-compute %s | FileCheck %s +; RUN: llc %s --filetype=asm -o - | FileCheck %s + +target triple = "dxilv1.5-pc-shadermodel6.5-compute" + +; Confirm that DXILFinalizeLinkage will remove functions that have compatible +; linkage and are not called from anywhere. This should be any function that +; is not explicitly marked noinline or export and is not an entry point. + +; Not called nor marked with any linking or inlining attributes. +; CHECK-NOT: define {{.*}}doNothingNothing +define void @"?doNothingNothing@@YAXXZ"() #0 { +entry: + ret void +} + +; Marked internal, this should be removed. +; CHECK-NOT: define {{.*}}doNothingInternally +define internal void @"?doNothingInternally@@YAXXZ"() #0 { +entry: + ret void +} + +; Marked external, which should become internal and be removed. +; CHECK-NOT: define {{.*}}doNothingExter
[clang] [llvm] Tentative fix for not removing newly internal functions (PR #106146)
https://github.com/pow2clk ready_for_review https://github.com/llvm/llvm-project/pull/106146 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Tentative fix for not removing newly internal functions (PR #106146)
https://github.com/pow2clk updated https://github.com/llvm/llvm-project/pull/106146 >From 40224473a7b43bc4ffe2024ab51196c2130bedc7 Mon Sep 17 00:00:00 2001 From: Greg Roth Date: Sun, 25 Aug 2024 12:00:03 -0600 Subject: [PATCH] [DirectX] Remove trivially dead functions at linkage finalize Functions are not removed even when made internal by DXILFinalizeLinkage The removal code is called from alwaysinliner and globalopt, which are invoked too early to remove functions made internal by this pass. This adds a check similar to that in alwaysinliner that removes trivially dead functions after being marked internal. It refactors that code a bit to make it simpler including reversing what is stored in the work queue. Tests both the pass in isolation and the full inlining, linkage finalization, and function removal process. Fixes #106139 --- .../CodeGenHLSL/remove-internal-unused.hlsl | 47 +++ .../Target/DirectX/DXILFinalizeLinkage.cpp| 16 ++-- .../DirectX/finalize-linkage-remove-dead.ll | 80 +++ 3 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 clang/test/CodeGenHLSL/remove-internal-unused.hlsl create mode 100644 llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll diff --git a/clang/test/CodeGenHLSL/remove-internal-unused.hlsl b/clang/test/CodeGenHLSL/remove-internal-unused.hlsl new file mode 100644 index 00..85c114618a1e0e --- /dev/null +++ b/clang/test/CodeGenHLSL/remove-internal-unused.hlsl @@ -0,0 +1,47 @@ +// RUN: %clang -target dxil-pc-shadermodel6.0-compute -S -o - %s | FileCheck %s +// RUN: %clang -target dxil-pc-shadermodel6.3-library -S -o - %s | FileCheck %s + +// Verify that internal linkage unused functions are removed + +RWBuffer buf; + +// Never called functions should be removed. +// CHECK-NOT: define{{.*}}uncalledFor +void uncalledFor() { + buf[1] = 1; +} + +// Never called but exported functions should remain. +// CHECK: define void @"?exported@@YAXXZ"() +export void exported() { + buf[1] = 1; +} + +// Never called but noinlined functions should remain. +// CHECK: define internal void @"?noinlined@@YAXXZ"() +__attribute__((noinline)) void noinlined() { + buf[1] = 1; +} + +// Called functions marked noinline should remain. +// CHECK: define internal void @"?calledAndNoinlined@@YAXXZ"() +__attribute__((noinline)) void calledAndNoinlined() { + buf[1] = 1; +} + +// Called functions that get inlined by default should be removed. +// CHECK-NOT: define{{.*}}calledAndInlined +void calledAndInlined() { + buf[1] = 1; +} + + +// Entry point functions should remain. +// CHECK: define{{.*}}main +[numthreads(1,1,1)] +[shader("compute")] +void main() { + calledAndInlined(); + calledAndNoinlined(); + buf[0] = 0; +} \ No newline at end of file diff --git a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp index d315d9bd16f439..59b30f965bf951 100644 --- a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp +++ b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp @@ -19,20 +19,20 @@ using namespace llvm; static bool finalizeLinkage(Module &M) { - SmallPtrSet EntriesAndExports; + SmallPtrSet Funcs; // Find all entry points and export functions for (Function &EF : M.functions()) { -if (!EF.hasFnAttribute("hlsl.shader") && !EF.hasFnAttribute("hlsl.export")) +if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export")) continue; -EntriesAndExports.insert(&EF); +Funcs.insert(&EF); } - for (Function &F : M.functions()) { -if (F.getLinkage() == GlobalValue::ExternalLinkage && -!EntriesAndExports.contains(&F)) { - F.setLinkage(GlobalValue::InternalLinkage); -} + for (Function *F : Funcs) { +if (F->getLinkage() == GlobalValue::ExternalLinkage) + F->setLinkage(GlobalValue::InternalLinkage); +if (F->hasFnAttribute(Attribute::AlwaysInline) && F->isDefTriviallyDead()) + M.getFunctionList().erase(F); } return false; diff --git a/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll new file mode 100644 index 00..df5934355664d1 --- /dev/null +++ b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll @@ -0,0 +1,80 @@ +; RUN: opt -S -dxil-finalize-linkage -mtriple=dxil-unknown-shadermodel6.5-compute %s | FileCheck %s +; RUN: llc %s --filetype=asm -o - | FileCheck %s + +target triple = "dxilv1.5-pc-shadermodel6.5-compute" + +; Confirm that DXILFinalizeLinkage will remove functions that have compatible +; linkage and are not called from anywhere. This should be any function that +; is not explicitly marked noinline or export and is not an entry point. + +; Not called nor marked with any linking or inlining attributes. +; CHECK-NOT: define {{.*}}doNothingNothing +define void @"?doNothingNothing@@YAXXZ"() #0 { +entry: + ret void +} + +; Marked internal, this should be removed. +; CHECK-NOT: def
[clang] [llvm] adding clang codegen (PR #109331)
@@ -18824,6 +18824,40 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: { retType, CGM.getHLSLRuntime().getSignIntrinsic(), ArrayRef{Op0}, nullptr, "hlsl.sign"); } + // This should only be called when targeting DXIL + case Builtin::BI__builtin_hlsl_asuint_splitdouble: { + +assert((E->getArg(0)->getType()->isDoubleType() || spall wrote: Shouldn't this assert use && here instead of || because all of those need to be true? As it is now if any of them are true the assert won't be triggered, and the code should assert if any one of them are false. https://github.com/llvm/llvm-project/pull/109331 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Inliner] Propagate more attributes to params when inlining (PR #91101)
goldsteinn wrote: > Okay, the bug is from the fact that we simplify the values in `VMap` which > can mean that even if `VMap.lookup(InnerCB)` exists, it doesn't imply that > `NewInnerCB` is actually the same function. This is really only an issue for > intrins which can simplify but is an active bug: > https://godbolt.org/z/r873jTdvM > > introduced in: #95888 :( > > I think this bug shows up in other places we propagate i.e: > https://godbolt.org/z/zzbMvW5cq > > Here we may create UB by propagating the `nonnull` back to `%p1()`. > > I think the necessary fix is something along the lines of checking that the > new callbase calls the same function. I will have a patch up shortly. Fix at: https://github.com/llvm/llvm-project/pull/109347 https://github.com/llvm/llvm-project/pull/91101 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)
@@ -8573,7 +8661,10 @@ class LValueExprEvaluator bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E); bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E); bool VisitMemberExpr(const MemberExpr *E); - bool VisitStringLiteral(const StringLiteral *E) { return Success(E); } + bool VisitStringLiteral(const StringLiteral *E) { +uint64_t Version = Info.getASTContext().getNextStringLiteralVersion(); efriedma-quic wrote: getNextStringLiteralVersion() returns unsigned, not uint64_t? https://github.com/llvm/llvm-project/pull/109208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Inliner] Propagate more attributes to params when inlining (PR #91101)
goldsteinn wrote: > Reproducer: > > ``` > ; bin/opt -passes=inline reduced.ll -S > target datalayout = > "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" > target triple = "x86_64-unknown-linux-gnu" > > define i64 @caller(ptr %p1, ptr %p2) { > %1 = call i64 %p1(ptr %p2) > %2 = call i64 @callee(i64 %1) > ret i64 %2 > } > > define i64 @callee(i64 range(i64 0, 7) %0) { > %i = tail call i64 @llvm.umin.i64(i64 %0, i64 %0) > ret i64 %i > } > ``` > > ``` > Attribute after last parameter! > %1 = call i64 %p1(ptr range(i64 0, 7) %p2) > LLVM ERROR: Broken module found, compilation aborted! > PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ > and include the crash backtrace. > Stack dump: > 0. Program arguments: bin/opt -passes=inline reduced.ll -S > 1. Running pass "verify" on module "reduced.ll" > #0 0x7fdd0dc14782 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) > (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x214782) > #1 0x7fdd0dc1164f llvm::sys::RunSignalHandlers() > (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x21164f) > #2 0x7fdd0dc11795 SignalHandler(int) Signals.cpp:0:0 > #3 0x7fdd0d642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) > #4 0x7fdd0d6969fc __pthread_kill_implementation > ./nptl/pthread_kill.c:44:76 > #5 0x7fdd0d6969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10 > #6 0x7fdd0d6969fc pthread_kill ./nptl/pthread_kill.c:89:10 > #7 0x7fdd0d642476 gsignal ./signal/../sysdeps/posix/raise.c:27:6 > #8 0x7fdd0d6287f3 abort ./stdlib/abort.c:81:7 > #9 0x7fdd0da6d70f llvm::report_fatal_error(llvm::Twine const&, bool) > (.cold) ErrorHandling.cpp:0:0 > #10 0x7fdd0db1cc90 unsigned long std::uniform_int_distribution long>::operator()(std::random_device&, > std::uniform_int_distribution::param_type const&) (.isra.0) > ExponentialBackoff.cpp:0:0 > #11 0x7fdd06596958 > (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x396958) > #12 0x7fdd0de84645 llvm::detail::PassModel llvm::VerifierPass, llvm::AnalysisManager>::run(llvm::Module&, > llvm::AnalysisManager&) > (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x1f645) > #13 0x7fdd06553d9a llvm::PassManager llvm::AnalysisManager>::run(llvm::Module&, > llvm::AnalysisManager&) > (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x353d9a) > #14 0x7fdd0de921b1 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, > llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, > llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, > llvm::ArrayRef, llvm::ArrayRef (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, > llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) > (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x2d1b1) > #15 0x7fdd0de9d934 optMain > (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x38934) > #16 0x7fdd0d629d90 __libc_start_call_main > ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16 > #17 0x7fdd0d629e40 call_init ./csu/../csu/libc-start.c:128:20 > #18 0x7fdd0d629e40 __libc_start_main ./csu/../csu/libc-start.c:379:5 > #19 0x5d8d8cac3095 _start (bin/opt+0x1095) > Aborted (core dumped) > ``` Okay, the bug is from the fact that we simplify the values in `VMap` which can mean that even if `VMap.lookup(InnerCB)` exists, it doesn't imply that `NewInnerCB` is actually the same function. This is really only an issue for intrins which can simplify but is an active bug: https://godbolt.org/z/r873jTdvM introduced in: https://github.com/llvm/llvm-project/pull/95888 :( I think this bug shows up in other places we propagate i.e: https://godbolt.org/z/zzbMvW5cq Here we may create UB by propagating the `nonnull` back to `%p1()`. I think the necessary fix is something along the lines of checking that the new callbase calls the same function. I will have a patch up shortly. https://github.com/llvm/llvm-project/pull/91101 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][FMV] Support target_version (PR #99040)
@@ -3056,6 +3056,45 @@ bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D, enum SecondParam { None }; enum ThirdParam { Target, TargetClones, TargetVersion }; llvm::SmallVector Features; + if (Context.getTargetInfo().getTriple().isRISCV()) { + +llvm::SmallVector AttrStrs; +AttrStr.split(AttrStrs, ';'); + +bool IsPriority = false; topperc wrote: `hasPriority` is a better name than `isPriority` https://github.com/llvm/llvm-project/pull/99040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][FMV] Support target_version (PR #99040)
@@ -3056,6 +3056,45 @@ bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D, enum SecondParam { None }; enum ThirdParam { Target, TargetClones, TargetVersion }; llvm::SmallVector Features; + if (Context.getTargetInfo().getTriple().isRISCV()) { + +llvm::SmallVector AttrStrs; +AttrStr.split(AttrStrs, ';'); + +bool IsPriority = false; +bool IsDefault = false; +for (auto &AttrStr : AttrStrs) { + // Only support arch=+ext,... syntax. topperc wrote: What if someone writes `arch=rv64gc;default;` do we error for that? https://github.com/llvm/llvm-project/pull/99040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][FMV] Support target_version (PR #99040)
@@ -4268,8 +4268,12 @@ void CodeGenModule::emitMultiVersionFunctions() { } else if (const auto *TVA = CurFD->getAttr()) { if (TVA->isDefaultVersion() && IsDefined) ShouldEmitResolver = true; -TVA->getFeatures(Feats); llvm::Function *Func = createFunction(CurFD); +if (getTarget().getTriple().isRISCV()) { + Feats.push_back(TVA->getName()); +} else { + TVA->getFeatures(Feats); topperc wrote: Add an assert here that the target is AArch64 https://github.com/llvm/llvm-project/pull/99040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][FMV] Support target_version (PR #99040)
@@ -15501,8 +15511,10 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D, FD->setInvalidDecl(); } if (const auto *Attr = FD->getAttr()) { -if (!Context.getTargetInfo().hasFeature("fmv") && -!Attr->isDefaultVersion()) { +if (Context.getTargetInfo().getTriple().isRISCV()) { topperc wrote: Should we check AArch64 in the original `if` instead? https://github.com/llvm/llvm-project/pull/99040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV][FMV] Support target_version (PR #99040)
@@ -14270,9 +14270,16 @@ void ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap, Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, Features); } } else if (const auto *TV = FD->getAttr()) { -llvm::SmallVector Feats; -TV->getFeatures(Feats); -std::vector Features = getFMVBackendFeaturesFor(Feats); +std::vector Features; +if (Target->getTriple().isRISCV()) { + ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(TV->getName()); + Features.insert(Features.begin(), ParsedAttr.Features.begin(), + ParsedAttr.Features.end()); +} else { + llvm::SmallVector Feats; topperc wrote: Add an assert here that the triple is AArch64 https://github.com/llvm/llvm-project/pull/99040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV][VCIX] Add vcix_state to GNU inline assembly register set (PR #106914)
@@ -44,7 +44,7 @@ ArrayRef RISCVTargetInfo::getGCCRegNames() const { "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", // CSRs - "fflags", "frm", "vtype", "vl", "vxsat", "vxrm" + "fflags", "frm", "vtype", "vl", "vxsat", "vxrm", "sf_vcix_state" topperc wrote: @4vtomat we should override that function for this register. https://github.com/llvm/llvm-project/pull/106914 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] - Add libclangSerialization to clang driver unittests (PR #109329)
Prabhuk wrote: I just merged my revert PR https://github.com/llvm/llvm-project/pull/109340 I'll investigate further on the cause for the warning that shows up in the build bots causing the test failure https://github.com/llvm/llvm-project/pull/109329 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Revert "[Driver] Add toolchain for X86_64 UEFI target" (PR #109340)
https://github.com/Prabhuk closed https://github.com/llvm/llvm-project/pull/109340 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] d2df2e4 - Revert "[Driver] Add toolchain for X86_64 UEFI target" (#109340)
Author: Prabhuk Date: 2024-09-19T15:28:07-07:00 New Revision: d2df2e41cae1413050935d6d27094569c29c473f URL: https://github.com/llvm/llvm-project/commit/d2df2e41cae1413050935d6d27094569c29c473f DIFF: https://github.com/llvm/llvm-project/commit/d2df2e41cae1413050935d6d27094569c29c473f.diff LOG: Revert "[Driver] Add toolchain for X86_64 UEFI target" (#109340) Reverts llvm/llvm-project#76838 Appears to be causing failures in MAC builders. First reverting the patch and will investigate after. Added: Modified: clang/lib/Basic/Targets.cpp clang/lib/Basic/Targets/OSTargets.h clang/lib/Basic/Targets/X86.h clang/lib/Driver/CMakeLists.txt clang/lib/Driver/Driver.cpp clang/unittests/Driver/ToolChainTest.cpp Removed: clang/lib/Driver/ToolChains/UEFI.cpp clang/lib/Driver/ToolChains/UEFI.h clang/test/CodeGen/X86/uefi-data-layout.c clang/test/Driver/uefi-constructed-args.c diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 4917ef015941be..0b8e565345b6a4 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -613,9 +613,6 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, case llvm::Triple::Solaris: return std::make_unique>(Triple, Opts); -case llvm::Triple::UEFI: - return std::make_unique(Triple, Opts); - case llvm::Triple::Win32: { switch (Triple.getEnvironment()) { case llvm::Triple::Cygnus: diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index a83d6464e789d6..0a4f06967fff5a 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -778,21 +778,6 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo { } }; -// UEFI target -template -class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { -protected: - void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} - -public: - UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) - : OSTargetInfo(Triple, Opts) { -this->WCharType = TargetInfo::UnsignedShort; -this->WIntType = TargetInfo::UnsignedShort; - } -}; - void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts, MacroBuilder &Builder); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index a99ae62984c7d5..79fd5867cf6673 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -814,43 +814,6 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { } }; -// x86-64 UEFI target -class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo -: public UEFITargetInfo { -public: - UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) - : UEFITargetInfo(Triple, Opts) { -this->TheCXXABI.set(TargetCXXABI::Microsoft); -this->MaxTLSAlign = 8192u * this->getCharWidth(); -this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-" - "i64:64-i128:128-f80:128-n8:16:32:64-S128"); - } - - void getTargetDefines(const LangOptions &Opts, -MacroBuilder &Builder) const override { -getOSDefines(Opts, X86TargetInfo::getTriple(), Builder); - } - - BuiltinVaListKind getBuiltinVaListKind() const override { -return TargetInfo::CharPtrBuiltinVaList; - } - - CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { -switch (CC) { -case CC_C: -case CC_Win64: - return CCCR_OK; -default: - return CCCR_Warning; -} - } - - TargetInfo::CallingConvKind - getCallingConvKind(bool ClangABICompat4) const override { -return CCK_MicrosoftWin64; - } -}; - // x86-64 Windows target class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo : public WindowsTargetInfo { diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 4fd10bf671512f..32a4378ab499fa 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -78,7 +78,6 @@ add_clang_library(clangDriver ToolChains/Solaris.cpp ToolChains/SPIRV.cpp ToolChains/TCE.cpp - ToolChains/UEFI.cpp ToolChains/VEToolchain.cpp ToolChains/WebAssembly.cpp ToolChains/XCore.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 95723b9209d125..efe398dd531da7 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -45,7 +45,6 @@ #include "ToolChains/SPIRV.h" #include "ToolChains/Solaris.h" #include "ToolChains/TCE.h" -#include "ToolChains/UEFI.h" #include "ToolChains/VEToolchain.h" #include "ToolChains/WebAssembly.h" #include "ToolChains/XCore.h" @@ -6417,9 +6416,6 @@ const ToolChain &Driver::getToolCh
[clang] Revert "[Driver] Add toolchain for X86_64 UEFI target" (PR #109340)
https://github.com/Prabhuk reopened https://github.com/llvm/llvm-project/pull/109340 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] - Add libclangSerialization to clang driver unittests (PR #109329)
Prabhuk wrote: It seems like we are still seeing failures: https://lab.llvm.org/buildbot/#/builders/190/builds/6112 https://github.com/llvm/llvm-project/pull/109329 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [X86] Use X86AS::GS and X86AS::FS instead of 256 and 257. NFC (PR #109342)
llvmbot wrote: @llvm/pr-subscribers-backend-x86 Author: Craig Topper (topperc) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/109342.diff 4 Files Affected: - (modified) clang/lib/CodeGen/CMakeLists.txt (+1) - (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+3-3) - (modified) llvm/lib/Target/X86/X86ISelLoweringCall.cpp (+3-2) - (modified) llvm/lib/Target/X86/X86WinEHState.cpp (+2-2) ``diff diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt index aa0c871c5352a8..868ec847b9634b 100644 --- a/clang/lib/CodeGen/CMakeLists.txt +++ b/clang/lib/CodeGen/CMakeLists.txt @@ -144,6 +144,7 @@ add_clang_library(clangCodeGen VarBypassDetector.cpp DEPENDS + vt_gen intrinsics_gen ClangDriverOptions # These generated headers are included transitively. diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 9637e96c21cf52..b9c9e5703849ae 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -18925,7 +18925,7 @@ static SDValue LowerToTLSExecModel(GlobalAddressSDNode *GA, SelectionDAG &DAG, // Get the Thread Pointer, which is %gs:0 (32-bit) or %fs:0 (64-bit). Value *Ptr = Constant::getNullValue( - PointerType::get(*DAG.getContext(), is64Bit ? 257 : 256)); + PointerType::get(*DAG.getContext(), is64Bit ? X86AS::FS : X86AS::GS)); SDValue ThreadPointer = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), DAG.getIntPtrConstant(0, dl), @@ -19070,8 +19070,8 @@ X86TargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { // %gs:0x58 (64-bit). On MinGW, __tls_array is not available, so directly // use its literal value of 0x2C. Value *Ptr = Constant::getNullValue( -Subtarget.is64Bit() ? PointerType::get(*DAG.getContext(), 256) -: PointerType::get(*DAG.getContext(), 257)); +Subtarget.is64Bit() ? PointerType::get(*DAG.getContext(), X86AS::GS) +: PointerType::get(*DAG.getContext(), X86AS::FS)); SDValue TlsArray = Subtarget.is64Bit() ? DAG.getIntPtrConstant(0x58, dl) diff --git a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp index 43dcaefc623bea..b9124658028da4 100644 --- a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp +++ b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp @@ -524,8 +524,9 @@ X86TargetLowering::findRepresentativeClass(const TargetRegisterInfo *TRI, unsigned X86TargetLowering::getAddressSpace() const { if (Subtarget.is64Bit()) -return (getTargetMachine().getCodeModel() == CodeModel::Kernel) ? 256 : 257; - return 256; +return (getTargetMachine().getCodeModel() == CodeModel::Kernel) ? X86AS::GS +: X86AS::FS; + return X86AS::GS; } static bool hasStackGuardSlotTLS(const Triple &TargetTriple) { diff --git a/llvm/lib/Target/X86/X86WinEHState.cpp b/llvm/lib/Target/X86/X86WinEHState.cpp index 578d653c1e0ada..963d613ddbfe7d 100644 --- a/llvm/lib/Target/X86/X86WinEHState.cpp +++ b/llvm/lib/Target/X86/X86WinEHState.cpp @@ -423,7 +423,7 @@ void WinEHStatePass::linkExceptionRegistration(IRBuilder<> &Builder, // Handler = Handler Builder.CreateStore(Handler, Builder.CreateStructGEP(LinkTy, Link, 1)); // Next = [fs:00] - Constant *FSZero = Constant::getNullValue(PointerType::get(C, 257)); + Constant *FSZero = Constant::getNullValue(PointerType::get(C, X86AS::FS)); Value *Next = Builder.CreateLoad(PointerType::getUnqual(C), FSZero); Builder.CreateStore(Next, Builder.CreateStructGEP(LinkTy, Link, 0)); // [fs:00] = Link @@ -443,7 +443,7 @@ void WinEHStatePass::unlinkExceptionRegistration(IRBuilder<> &Builder) { // [fs:00] = Link->Next Value *Next = Builder.CreateLoad(PointerType::getUnqual(C), Builder.CreateStructGEP(LinkTy, Link, 0)); - Constant *FSZero = Constant::getNullValue(PointerType::get(C, 257)); + Constant *FSZero = Constant::getNullValue(PointerType::get(C, X86AS::FS)); Builder.CreateStore(Next, FSZero); } `` https://github.com/llvm/llvm-project/pull/109342 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [X86] Use X86AS::GS and X86AS::FS instead of 256 and 257. NFC (PR #109342)
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/109342 None >From bc0a290b1e139f32225bc55fc99027b34c4f1bd6 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 19 Sep 2024 15:13:55 -0700 Subject: [PATCH] [X86] Use X86AS::GS and X86AS::FS instead of 256 and 257. NFC --- clang/lib/CodeGen/CMakeLists.txt| 1 + llvm/lib/Target/X86/X86ISelLowering.cpp | 6 +++--- llvm/lib/Target/X86/X86ISelLoweringCall.cpp | 5 +++-- llvm/lib/Target/X86/X86WinEHState.cpp | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt index aa0c871c5352a8..868ec847b9634b 100644 --- a/clang/lib/CodeGen/CMakeLists.txt +++ b/clang/lib/CodeGen/CMakeLists.txt @@ -144,6 +144,7 @@ add_clang_library(clangCodeGen VarBypassDetector.cpp DEPENDS + vt_gen intrinsics_gen ClangDriverOptions # These generated headers are included transitively. diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 9637e96c21cf52..b9c9e5703849ae 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -18925,7 +18925,7 @@ static SDValue LowerToTLSExecModel(GlobalAddressSDNode *GA, SelectionDAG &DAG, // Get the Thread Pointer, which is %gs:0 (32-bit) or %fs:0 (64-bit). Value *Ptr = Constant::getNullValue( - PointerType::get(*DAG.getContext(), is64Bit ? 257 : 256)); + PointerType::get(*DAG.getContext(), is64Bit ? X86AS::FS : X86AS::GS)); SDValue ThreadPointer = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), DAG.getIntPtrConstant(0, dl), @@ -19070,8 +19070,8 @@ X86TargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { // %gs:0x58 (64-bit). On MinGW, __tls_array is not available, so directly // use its literal value of 0x2C. Value *Ptr = Constant::getNullValue( -Subtarget.is64Bit() ? PointerType::get(*DAG.getContext(), 256) -: PointerType::get(*DAG.getContext(), 257)); +Subtarget.is64Bit() ? PointerType::get(*DAG.getContext(), X86AS::GS) +: PointerType::get(*DAG.getContext(), X86AS::FS)); SDValue TlsArray = Subtarget.is64Bit() ? DAG.getIntPtrConstant(0x58, dl) diff --git a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp index 43dcaefc623bea..b9124658028da4 100644 --- a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp +++ b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp @@ -524,8 +524,9 @@ X86TargetLowering::findRepresentativeClass(const TargetRegisterInfo *TRI, unsigned X86TargetLowering::getAddressSpace() const { if (Subtarget.is64Bit()) -return (getTargetMachine().getCodeModel() == CodeModel::Kernel) ? 256 : 257; - return 256; +return (getTargetMachine().getCodeModel() == CodeModel::Kernel) ? X86AS::GS +: X86AS::FS; + return X86AS::GS; } static bool hasStackGuardSlotTLS(const Triple &TargetTriple) { diff --git a/llvm/lib/Target/X86/X86WinEHState.cpp b/llvm/lib/Target/X86/X86WinEHState.cpp index 578d653c1e0ada..963d613ddbfe7d 100644 --- a/llvm/lib/Target/X86/X86WinEHState.cpp +++ b/llvm/lib/Target/X86/X86WinEHState.cpp @@ -423,7 +423,7 @@ void WinEHStatePass::linkExceptionRegistration(IRBuilder<> &Builder, // Handler = Handler Builder.CreateStore(Handler, Builder.CreateStructGEP(LinkTy, Link, 1)); // Next = [fs:00] - Constant *FSZero = Constant::getNullValue(PointerType::get(C, 257)); + Constant *FSZero = Constant::getNullValue(PointerType::get(C, X86AS::FS)); Value *Next = Builder.CreateLoad(PointerType::getUnqual(C), FSZero); Builder.CreateStore(Next, Builder.CreateStructGEP(LinkTy, Link, 0)); // [fs:00] = Link @@ -443,7 +443,7 @@ void WinEHStatePass::unlinkExceptionRegistration(IRBuilder<> &Builder) { // [fs:00] = Link->Next Value *Next = Builder.CreateLoad(PointerType::getUnqual(C), Builder.CreateStructGEP(LinkTy, Link, 0)); - Constant *FSZero = Constant::getNullValue(PointerType::get(C, 257)); + Constant *FSZero = Constant::getNullValue(PointerType::get(C, X86AS::FS)); Builder.CreateStore(Next, FSZero); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 7db641a - [clang] Don't call raw_string_ostream::flush() (NFC)
Author: Youngsuk Kim Date: 2024-09-19T17:18:10-05:00 New Revision: 7db641af13670aa1f1ecd3106eda3ce447afd752 URL: https://github.com/llvm/llvm-project/commit/7db641af13670aa1f1ecd3106eda3ce447afd752 DIFF: https://github.com/llvm/llvm-project/commit/7db641af13670aa1f1ecd3106eda3ce447afd752.diff LOG: [clang] Don't call raw_string_ostream::flush() (NFC) Don't call raw_string_ostream::flush(), which is essentially a no-op. As specified in the docs, raw_string_ostream is always unbuffered Added: Modified: clang/include/clang/AST/StmtDataCollectors.td clang/lib/AST/DataCollection.cpp clang/lib/AST/TemplateName.cpp clang/lib/Basic/Module.cpp clang/lib/CodeGen/BackendUtil.cpp clang/lib/CodeGen/CodeGenPGO.cpp clang/lib/Driver/Job.cpp clang/lib/Driver/ToolChains/HIPUtility.cpp clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaLookup.cpp clang/lib/Sema/SemaTemplateDeduction.cpp clang/lib/StaticAnalyzer/Core/CheckerManager.cpp clang/lib/Tooling/CommonOptionsParser.cpp clang/lib/Tooling/Core/Replacement.cpp clang/lib/Tooling/Refactoring/AtomicChange.cpp clang/lib/Tooling/Transformer/Stencil.cpp clang/unittests/Basic/SarifTest.cpp clang/unittests/Frontend/TextDiagnosticTest.cpp Removed: diff --git a/clang/include/clang/AST/StmtDataCollectors.td b/clang/include/clang/AST/StmtDataCollectors.td index 922dd2a20d59c2..abf4b5f34d3491 100644 --- a/clang/include/clang/AST/StmtDataCollectors.td +++ b/clang/include/clang/AST/StmtDataCollectors.td @@ -55,7 +55,6 @@ class CallExpr { // Add a padding character so that 'foo()' != 'foo()'. OS << '\n'; } -OS.flush(); addData(ArgString); } diff --git a/clang/lib/AST/DataCollection.cpp b/clang/lib/AST/DataCollection.cpp index d3f2c22e9cc3a8..786821ded98c39 100644 --- a/clang/lib/AST/DataCollection.cpp +++ b/clang/lib/AST/DataCollection.cpp @@ -41,7 +41,6 @@ std::string getMacroStack(SourceLocation Loc, ASTContext &Context) { printMacroName(MacroStackStream, Context, Loc); Loc = SM.getImmediateMacroCallerLoc(Loc); } - MacroStackStream.flush(); return MacroStack; } diff --git a/clang/lib/AST/TemplateName.cpp b/clang/lib/AST/TemplateName.cpp index 044a1a92469aca..c27b07ad6c6f87 100644 --- a/clang/lib/AST/TemplateName.cpp +++ b/clang/lib/AST/TemplateName.cpp @@ -439,6 +439,5 @@ const StreamingDiagnostic &clang::operator<<(const StreamingDiagnostic &DB, OS << '\''; N.print(OS, PrintingPolicy(LO)); OS << '\''; - OS.flush(); return DB << NameStr; } diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp index 90b7b0d24bb6a0..fee372bce3a367 100644 --- a/clang/lib/Basic/Module.cpp +++ b/clang/lib/Basic/Module.cpp @@ -252,7 +252,6 @@ std::string Module::getFullModuleName(bool AllowStringLiterals) const { llvm::raw_string_ostream Out(Result); printModuleId(Out, Names.rbegin(), Names.rend(), AllowStringLiterals); - Out.flush(); return Result; } diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 8492e5ab73e183..fa49763e312f13 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -352,7 +352,6 @@ static std::string flattenClangCommandLine(ArrayRef Args, llvm::sys::printArg(OS, Arg, /*Quote=*/true); PrintedOneArg = true; } - OS.flush(); return FlatCmdLine; } diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 2bc0fe909efd14..b745ad37fc96b1 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -1134,7 +1134,6 @@ void CodeGenPGO::emitCounterRegionMapping(const Decl *D) { *CGM.getCoverageMapping(), CGM.getContext().getSourceManager(), CGM.getLangOpts(), RegionCounterMap.get(), RegionMCDCState.get()); MappingGen.emitCounterMapping(D, OS); - OS.flush(); if (CoverageMapping.empty()) return; @@ -1155,7 +1154,6 @@ CodeGenPGO::emitEmptyCounterMapping(const Decl *D, StringRef Name, CGM.getContext().getSourceManager(), CGM.getLangOpts()); MappingGen.emitEmptyMapping(D, OS); - OS.flush(); if (CoverageMapping.empty()) return; diff --git a/clang/lib/Driver/Job.cpp b/clang/lib/Driver/Job.cpp index a6c1581be79626..fe2f7242b04a51 100644 --- a/clang/lib/Driver/Job.cpp +++ b/clang/lib/Driver/Job.cpp @@ -343,7 +343,6 @@ int Command::Execute(ArrayRef> Redirects, writeResponseFile(SS); buildArgvForResponseFile(Argv); Argv.push_back(nullptr); -SS.flush(); // Save the response file in the appropriate encoding if (std::error_code EC = writeFileWithEncoding( diff --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp b/clang/lib/Driver/ToolChains/HIPUtility.cpp index 1b707376dea819..b3adfe654
[clang] [llvm] Tentative fix for not removing newly internal functions (PR #106146)
https://github.com/pow2clk updated https://github.com/llvm/llvm-project/pull/106146 >From 70d4b5de3e9a214d50560f047b334de7f0818167 Mon Sep 17 00:00:00 2001 From: Greg Roth Date: Sun, 25 Aug 2024 12:00:03 -0600 Subject: [PATCH] [DirectX] Remove trivially dead functions at linkage finalize Functions are not removed even when made internal by DXILFinalizeLinkage The removal code is called from alwaysinliner and globalopt, which are invoked too early to remove functions made internal by this pass. This adds a check similar to that in alwaysinliner that removes trivially dead functions after being marked internal. It refactors that code a bit to make it simpler including reversing what is stored in the work queue. Tests both the pass in isolation and the full inlining, linkage finalization, and function removal process. Fixes #106139 --- .../CodeGenHLSL/remove-internal-unused.hlsl | 47 +++ .../Target/DirectX/DXILFinalizeLinkage.cpp| 16 ++-- .../DirectX/finalize-linkage-remove-dead.ll | 80 +++ 3 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 clang/test/CodeGenHLSL/remove-internal-unused.hlsl create mode 100644 llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll diff --git a/clang/test/CodeGenHLSL/remove-internal-unused.hlsl b/clang/test/CodeGenHLSL/remove-internal-unused.hlsl new file mode 100644 index 00..85c114618a1e0e --- /dev/null +++ b/clang/test/CodeGenHLSL/remove-internal-unused.hlsl @@ -0,0 +1,47 @@ +// RUN: %clang -target dxil-pc-shadermodel6.0-compute -S -o - %s | FileCheck %s +// RUN: %clang -target dxil-pc-shadermodel6.3-library -S -o - %s | FileCheck %s + +// Verify that internal linkage unused functions are removed + +RWBuffer buf; + +// Never called functions should be removed. +// CHECK-NOT: define{{.*}}uncalledFor +void uncalledFor() { + buf[1] = 1; +} + +// Never called but exported functions should remain. +// CHECK: define void @"?exported@@YAXXZ"() +export void exported() { + buf[1] = 1; +} + +// Never called but noinlined functions should remain. +// CHECK: define internal void @"?noinlined@@YAXXZ"() +__attribute__((noinline)) void noinlined() { + buf[1] = 1; +} + +// Called functions marked noinline should remain. +// CHECK: define internal void @"?calledAndNoinlined@@YAXXZ"() +__attribute__((noinline)) void calledAndNoinlined() { + buf[1] = 1; +} + +// Called functions that get inlined by default should be removed. +// CHECK-NOT: define{{.*}}calledAndInlined +void calledAndInlined() { + buf[1] = 1; +} + + +// Entry point functions should remain. +// CHECK: define{{.*}}main +[numthreads(1,1,1)] +[shader("compute")] +void main() { + calledAndInlined(); + calledAndNoinlined(); + buf[0] = 0; +} \ No newline at end of file diff --git a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp index d315d9bd16f439..59b30f965bf951 100644 --- a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp +++ b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp @@ -19,20 +19,20 @@ using namespace llvm; static bool finalizeLinkage(Module &M) { - SmallPtrSet EntriesAndExports; + SmallPtrSet Funcs; // Find all entry points and export functions for (Function &EF : M.functions()) { -if (!EF.hasFnAttribute("hlsl.shader") && !EF.hasFnAttribute("hlsl.export")) +if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export")) continue; -EntriesAndExports.insert(&EF); +Funcs.insert(&EF); } - for (Function &F : M.functions()) { -if (F.getLinkage() == GlobalValue::ExternalLinkage && -!EntriesAndExports.contains(&F)) { - F.setLinkage(GlobalValue::InternalLinkage); -} + for (Function *F : Funcs) { +if (F->getLinkage() == GlobalValue::ExternalLinkage) + F->setLinkage(GlobalValue::InternalLinkage); +if (F->hasFnAttribute(Attribute::AlwaysInline) && F->isDefTriviallyDead()) + M.getFunctionList().erase(F); } return false; diff --git a/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll new file mode 100644 index 00..df5934355664d1 --- /dev/null +++ b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll @@ -0,0 +1,80 @@ +; RUN: opt -S -dxil-finalize-linkage -mtriple=dxil-unknown-shadermodel6.5-compute %s | FileCheck %s +; RUN: llc %s --filetype=asm -o - | FileCheck %s + +target triple = "dxilv1.5-pc-shadermodel6.5-compute" + +; Confirm that DXILFinalizeLinkage will remove functions that have compatible +; linkage and are not called from anywhere. This should be any function that +; is not explicitly marked noinline or export and is not an entry point. + +; Not called nor marked with any linking or inlining attributes. +; CHECK-NOT: define {{.*}}doNothingNothing +define void @"?doNothingNothing@@YAXXZ"() #0 { +entry: + ret void +} + +; Marked internal, this should be removed. +; CHECK-NOT: def
[clang] [llvm] Tentative fix for not removing newly internal functions (PR #106146)
https://github.com/pow2clk updated https://github.com/llvm/llvm-project/pull/106146 >From 1e39029007dee5825810965fa39f26996ec9b7aa Mon Sep 17 00:00:00 2001 From: Greg Roth Date: Sun, 25 Aug 2024 12:00:03 -0600 Subject: [PATCH] [DirectX] Remove trivially dead functions at linkage finalize Functions are not removed even when made internal by DXILFinalizeLinkage The removal code is called from alwaysinliner and globalopt, which are invoked too early to remove functions made internal by this pass. This adds a check similar to that in alwaysinliner that removes trivially dead functions after being marked internal. It refactors that code a bit to make it simpler including reversing what is stored in the work queue. Tests both the pass in isolation and the full inlining, linkage finalization, and function removal process. Fixes #106139 --- .../CodeGenHLSL/remove-internal-unused.hlsl | 47 +++ .../Target/DirectX/DXILFinalizeLinkage.cpp| 16 ++-- .../DirectX/finalize-linkage-remove-dead.ll | 80 +++ 3 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 clang/test/CodeGenHLSL/remove-internal-unused.hlsl create mode 100644 llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll diff --git a/clang/test/CodeGenHLSL/remove-internal-unused.hlsl b/clang/test/CodeGenHLSL/remove-internal-unused.hlsl new file mode 100644 index 00..85c114618a1e0e --- /dev/null +++ b/clang/test/CodeGenHLSL/remove-internal-unused.hlsl @@ -0,0 +1,47 @@ +// RUN: %clang -target dxil-pc-shadermodel6.0-compute -S -o - %s | FileCheck %s +// RUN: %clang -target dxil-pc-shadermodel6.3-library -S -o - %s | FileCheck %s + +// Verify that internal linkage unused functions are removed + +RWBuffer buf; + +// Never called functions should be removed. +// CHECK-NOT: define{{.*}}uncalledFor +void uncalledFor() { + buf[1] = 1; +} + +// Never called but exported functions should remain. +// CHECK: define void @"?exported@@YAXXZ"() +export void exported() { + buf[1] = 1; +} + +// Never called but noinlined functions should remain. +// CHECK: define internal void @"?noinlined@@YAXXZ"() +__attribute__((noinline)) void noinlined() { + buf[1] = 1; +} + +// Called functions marked noinline should remain. +// CHECK: define internal void @"?calledAndNoinlined@@YAXXZ"() +__attribute__((noinline)) void calledAndNoinlined() { + buf[1] = 1; +} + +// Called functions that get inlined by default should be removed. +// CHECK-NOT: define{{.*}}calledAndInlined +void calledAndInlined() { + buf[1] = 1; +} + + +// Entry point functions should remain. +// CHECK: define{{.*}}main +[numthreads(1,1,1)] +[shader("compute")] +void main() { + calledAndInlined(); + calledAndNoinlined(); + buf[0] = 0; +} \ No newline at end of file diff --git a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp index d315d9bd16f439..59b30f965bf951 100644 --- a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp +++ b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp @@ -19,20 +19,20 @@ using namespace llvm; static bool finalizeLinkage(Module &M) { - SmallPtrSet EntriesAndExports; + SmallPtrSet Funcs; // Find all entry points and export functions for (Function &EF : M.functions()) { -if (!EF.hasFnAttribute("hlsl.shader") && !EF.hasFnAttribute("hlsl.export")) +if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export")) continue; -EntriesAndExports.insert(&EF); +Funcs.insert(&EF); } - for (Function &F : M.functions()) { -if (F.getLinkage() == GlobalValue::ExternalLinkage && -!EntriesAndExports.contains(&F)) { - F.setLinkage(GlobalValue::InternalLinkage); -} + for (Function *F : Funcs) { +if (F->getLinkage() == GlobalValue::ExternalLinkage) + F->setLinkage(GlobalValue::InternalLinkage); +if (F->hasFnAttribute(Attribute::AlwaysInline) && F->isDefTriviallyDead()) + M.getFunctionList().erase(F); } return false; diff --git a/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll new file mode 100644 index 00..df5934355664d1 --- /dev/null +++ b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll @@ -0,0 +1,80 @@ +; RUN: opt -S -dxil-finalize-linkage -mtriple=dxil-unknown-shadermodel6.5-compute %s | FileCheck %s +; RUN: llc %s --filetype=asm -o - | FileCheck %s + +target triple = "dxilv1.5-pc-shadermodel6.5-compute" + +; Confirm that DXILFinalizeLinkage will remove functions that have compatible +; linkage and are not called from anywhere. This should be any function that +; is not explicitly marked noinline or export and is not an entry point. + +; Not called nor marked with any linking or inlining attributes. +; CHECK-NOT: define {{.*}}doNothingNothing +define void @"?doNothingNothing@@YAXXZ"() #0 { +entry: + ret void +} + +; Marked internal, this should be removed. +; CHECK-NOT: def
[clang] [DebugInfo] Correct the line attribution for IF branches (PR #108300)
https://github.com/dwblaikie approved this pull request. Fair enough https://github.com/llvm/llvm-project/pull/108300 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] - Add libclangSerialization to clang driver unittests (PR #109329)
Prabhuk wrote: I am holding off of on my revert PR to see if the current build bot with this patch goes through successfully! Thanks again Pranav. https://github.com/llvm/llvm-project/pull/109329 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Revert "[Driver] Add toolchain for X86_64 UEFI target" (PR #109340)
Prabhuk wrote: https://github.com/llvm/llvm-project/commit/221f15fc145d46289781206f241ae564cd9510f0 attemps to fix the failure caused by the Driver PR. Holding off of on the revert to see if the fix is successful. https://github.com/llvm/llvm-project/pull/109340 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [mlir] Make MMIWP not have ownership over MMI + Make MMI Only Use an External MCContext (PR #105541)
matinraayai wrote: > sorry for the delay > > after looking at MMI/MCContext, I agree that MMI shouldn't own MCContext, but > do we even need a reference from MMI to MCContext? they are different layers > of codegen IIUC. if it's possible to completely separate them we should do > that (please correct me if this doesn't make sense since I haven't spent too > much time in codegen) @aeubanks It's not impossible to separate them completely. `MCContext` is needed during initialization and finalization of the `MachineModuleInfoWrapperPass` (and its new pass manager variant) to set the diagnostics handler. In theory, you can just pass the context to the wrapper pass instead. @arsenm any thoughts on this? https://github.com/llvm/llvm-project/pull/105541 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Revert "[Driver] Add toolchain for X86_64 UEFI target" (PR #109340)
https://github.com/Prabhuk closed https://github.com/llvm/llvm-project/pull/109340 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] riscv: Support -mstack-protector-guard=tls (PR #108942)
@@ -3644,13 +3645,28 @@ static void RenderSSPOptions(const Driver &D, const ToolChain &TC, << A->getOption().getName() << Value << "sysreg global"; return; } +if (EffectiveTriple.isRISCV()) { + if (Value != "tls" && Value != "global") { topperc wrote: Is this also enabling "global" as a value? Is that supported in the backend? https://github.com/llvm/llvm-project/pull/108942 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] - Add libclangSerialization to clang driver unittests (PR #109329)
Prabhuk wrote: Thank you Pranav! This looks like a reasonable fix to me. I just created a revert PR though since I cannot test this right away locally. https://github.com/llvm/llvm-project/pull/109329 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Loads] Check context instruction for context-sensitive derefability (PR #109277)
efriedma-quic wrote: Please update the documentation for isSafeToSpeculativelyExecute() to specify the semantics in the case where the operands of the instruction don't dominate CtxI. https://github.com/llvm/llvm-project/pull/109277 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Revert "[Driver] Add toolchain for X86_64 UEFI target" (PR #109340)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Prabhuk (Prabhuk) Changes Reverts llvm/llvm-project#76838 Appears to be causing failures in MAC builders. First reverting the patch and will investigate after. --- Full diff: https://github.com/llvm/llvm-project/pull/109340.diff 10 Files Affected: - (modified) clang/lib/Basic/Targets.cpp (-3) - (modified) clang/lib/Basic/Targets/OSTargets.h (-15) - (modified) clang/lib/Basic/Targets/X86.h (-37) - (modified) clang/lib/Driver/CMakeLists.txt (-1) - (modified) clang/lib/Driver/Driver.cpp (-4) - (removed) clang/lib/Driver/ToolChains/UEFI.cpp (-88) - (removed) clang/lib/Driver/ToolChains/UEFI.h (-59) - (removed) clang/test/CodeGen/X86/uefi-data-layout.c (-3) - (removed) clang/test/Driver/uefi-constructed-args.c (-13) - (modified) clang/unittests/Driver/ToolChainTest.cpp (-21) ``diff diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 4917ef015941be..0b8e565345b6a4 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -613,9 +613,6 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, case llvm::Triple::Solaris: return std::make_unique>(Triple, Opts); -case llvm::Triple::UEFI: - return std::make_unique(Triple, Opts); - case llvm::Triple::Win32: { switch (Triple.getEnvironment()) { case llvm::Triple::Cygnus: diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index a83d6464e789d6..0a4f06967fff5a 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -778,21 +778,6 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo { } }; -// UEFI target -template -class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { -protected: - void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} - -public: - UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) - : OSTargetInfo(Triple, Opts) { -this->WCharType = TargetInfo::UnsignedShort; -this->WIntType = TargetInfo::UnsignedShort; - } -}; - void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts, MacroBuilder &Builder); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index a99ae62984c7d5..79fd5867cf6673 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -814,43 +814,6 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { } }; -// x86-64 UEFI target -class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo -: public UEFITargetInfo { -public: - UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) - : UEFITargetInfo(Triple, Opts) { -this->TheCXXABI.set(TargetCXXABI::Microsoft); -this->MaxTLSAlign = 8192u * this->getCharWidth(); -this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-" - "i64:64-i128:128-f80:128-n8:16:32:64-S128"); - } - - void getTargetDefines(const LangOptions &Opts, -MacroBuilder &Builder) const override { -getOSDefines(Opts, X86TargetInfo::getTriple(), Builder); - } - - BuiltinVaListKind getBuiltinVaListKind() const override { -return TargetInfo::CharPtrBuiltinVaList; - } - - CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { -switch (CC) { -case CC_C: -case CC_Win64: - return CCCR_OK; -default: - return CCCR_Warning; -} - } - - TargetInfo::CallingConvKind - getCallingConvKind(bool ClangABICompat4) const override { -return CCK_MicrosoftWin64; - } -}; - // x86-64 Windows target class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo : public WindowsTargetInfo { diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 4fd10bf671512f..32a4378ab499fa 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -78,7 +78,6 @@ add_clang_library(clangDriver ToolChains/Solaris.cpp ToolChains/SPIRV.cpp ToolChains/TCE.cpp - ToolChains/UEFI.cpp ToolChains/VEToolchain.cpp ToolChains/WebAssembly.cpp ToolChains/XCore.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 95723b9209d125..efe398dd531da7 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -45,7 +45,6 @@ #include "ToolChains/SPIRV.h" #include "ToolChains/Solaris.h" #include "ToolChains/TCE.h" -#include "ToolChains/UEFI.h" #include "ToolChains/VEToolchain.h" #include "ToolChains/WebAssembly.h" #include "ToolChains/XCore.h" @@ -6417,9 +6416,6 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::Mesa3D: TC = std::make_unique(*this, Target, Args); break; -case llvm::Tr
[clang] Revert "[Driver] Add toolchain for X86_64 UEFI target" (PR #109340)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-backend-x86 Author: Prabhuk (Prabhuk) Changes Reverts llvm/llvm-project#76838 Appears to be causing failures in MAC builders. First reverting the patch and will investigate after. --- Full diff: https://github.com/llvm/llvm-project/pull/109340.diff 10 Files Affected: - (modified) clang/lib/Basic/Targets.cpp (-3) - (modified) clang/lib/Basic/Targets/OSTargets.h (-15) - (modified) clang/lib/Basic/Targets/X86.h (-37) - (modified) clang/lib/Driver/CMakeLists.txt (-1) - (modified) clang/lib/Driver/Driver.cpp (-4) - (removed) clang/lib/Driver/ToolChains/UEFI.cpp (-88) - (removed) clang/lib/Driver/ToolChains/UEFI.h (-59) - (removed) clang/test/CodeGen/X86/uefi-data-layout.c (-3) - (removed) clang/test/Driver/uefi-constructed-args.c (-13) - (modified) clang/unittests/Driver/ToolChainTest.cpp (-21) ``diff diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 4917ef015941be..0b8e565345b6a4 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -613,9 +613,6 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, case llvm::Triple::Solaris: return std::make_unique>(Triple, Opts); -case llvm::Triple::UEFI: - return std::make_unique(Triple, Opts); - case llvm::Triple::Win32: { switch (Triple.getEnvironment()) { case llvm::Triple::Cygnus: diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index a83d6464e789d6..0a4f06967fff5a 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -778,21 +778,6 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo { } }; -// UEFI target -template -class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { -protected: - void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} - -public: - UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) - : OSTargetInfo(Triple, Opts) { -this->WCharType = TargetInfo::UnsignedShort; -this->WIntType = TargetInfo::UnsignedShort; - } -}; - void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts, MacroBuilder &Builder); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index a99ae62984c7d5..79fd5867cf6673 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -814,43 +814,6 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { } }; -// x86-64 UEFI target -class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo -: public UEFITargetInfo { -public: - UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) - : UEFITargetInfo(Triple, Opts) { -this->TheCXXABI.set(TargetCXXABI::Microsoft); -this->MaxTLSAlign = 8192u * this->getCharWidth(); -this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-" - "i64:64-i128:128-f80:128-n8:16:32:64-S128"); - } - - void getTargetDefines(const LangOptions &Opts, -MacroBuilder &Builder) const override { -getOSDefines(Opts, X86TargetInfo::getTriple(), Builder); - } - - BuiltinVaListKind getBuiltinVaListKind() const override { -return TargetInfo::CharPtrBuiltinVaList; - } - - CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { -switch (CC) { -case CC_C: -case CC_Win64: - return CCCR_OK; -default: - return CCCR_Warning; -} - } - - TargetInfo::CallingConvKind - getCallingConvKind(bool ClangABICompat4) const override { -return CCK_MicrosoftWin64; - } -}; - // x86-64 Windows target class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo : public WindowsTargetInfo { diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 4fd10bf671512f..32a4378ab499fa 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -78,7 +78,6 @@ add_clang_library(clangDriver ToolChains/Solaris.cpp ToolChains/SPIRV.cpp ToolChains/TCE.cpp - ToolChains/UEFI.cpp ToolChains/VEToolchain.cpp ToolChains/WebAssembly.cpp ToolChains/XCore.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 95723b9209d125..efe398dd531da7 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -45,7 +45,6 @@ #include "ToolChains/SPIRV.h" #include "ToolChains/Solaris.h" #include "ToolChains/TCE.h" -#include "ToolChains/UEFI.h" #include "ToolChains/VEToolchain.h" #include "ToolChains/WebAssembly.h" #include "ToolChains/XCore.h" @@ -6417,9 +6416,6 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::Mesa3D: TC = std::make_unique(*this, Target, Args);
[clang] Revert "[Driver] Add toolchain for X86_64 UEFI target" (PR #109340)
https://github.com/Prabhuk created https://github.com/llvm/llvm-project/pull/109340 Reverts llvm/llvm-project#76838 Appears to be causing failures in MAC builders. First reverting the patch and will investigate after. >From 7830c3e9d61e168a1de1fa2b33acc3fd4e22f2ed Mon Sep 17 00:00:00 2001 From: Prabhuk Date: Thu, 19 Sep 2024 14:53:55 -0700 Subject: [PATCH] Revert "[Driver] Add toolchain for X86_64 UEFI target (#76838)" This reverts commit d1335fb86466221b0499db5fc8f158f1f64d9542. --- clang/lib/Basic/Targets.cpp | 3 - clang/lib/Basic/Targets/OSTargets.h | 15 clang/lib/Basic/Targets/X86.h | 37 -- clang/lib/Driver/CMakeLists.txt | 1 - clang/lib/Driver/Driver.cpp | 4 -- clang/lib/Driver/ToolChains/UEFI.cpp | 88 --- clang/lib/Driver/ToolChains/UEFI.h| 59 --- clang/test/CodeGen/X86/uefi-data-layout.c | 3 - clang/test/Driver/uefi-constructed-args.c | 13 clang/unittests/Driver/ToolChainTest.cpp | 21 -- 10 files changed, 244 deletions(-) delete mode 100644 clang/lib/Driver/ToolChains/UEFI.cpp delete mode 100644 clang/lib/Driver/ToolChains/UEFI.h delete mode 100644 clang/test/CodeGen/X86/uefi-data-layout.c delete mode 100644 clang/test/Driver/uefi-constructed-args.c diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 4917ef015941be..0b8e565345b6a4 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -613,9 +613,6 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, case llvm::Triple::Solaris: return std::make_unique>(Triple, Opts); -case llvm::Triple::UEFI: - return std::make_unique(Triple, Opts); - case llvm::Triple::Win32: { switch (Triple.getEnvironment()) { case llvm::Triple::Cygnus: diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index a83d6464e789d6..0a4f06967fff5a 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -778,21 +778,6 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo { } }; -// UEFI target -template -class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { -protected: - void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} - -public: - UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) - : OSTargetInfo(Triple, Opts) { -this->WCharType = TargetInfo::UnsignedShort; -this->WIntType = TargetInfo::UnsignedShort; - } -}; - void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts, MacroBuilder &Builder); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index a99ae62984c7d5..79fd5867cf6673 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -814,43 +814,6 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { } }; -// x86-64 UEFI target -class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo -: public UEFITargetInfo { -public: - UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) - : UEFITargetInfo(Triple, Opts) { -this->TheCXXABI.set(TargetCXXABI::Microsoft); -this->MaxTLSAlign = 8192u * this->getCharWidth(); -this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-" - "i64:64-i128:128-f80:128-n8:16:32:64-S128"); - } - - void getTargetDefines(const LangOptions &Opts, -MacroBuilder &Builder) const override { -getOSDefines(Opts, X86TargetInfo::getTriple(), Builder); - } - - BuiltinVaListKind getBuiltinVaListKind() const override { -return TargetInfo::CharPtrBuiltinVaList; - } - - CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { -switch (CC) { -case CC_C: -case CC_Win64: - return CCCR_OK; -default: - return CCCR_Warning; -} - } - - TargetInfo::CallingConvKind - getCallingConvKind(bool ClangABICompat4) const override { -return CCK_MicrosoftWin64; - } -}; - // x86-64 Windows target class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo : public WindowsTargetInfo { diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 4fd10bf671512f..32a4378ab499fa 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -78,7 +78,6 @@ add_clang_library(clangDriver ToolChains/Solaris.cpp ToolChains/SPIRV.cpp ToolChains/TCE.cpp - ToolChains/UEFI.cpp ToolChains/VEToolchain.cpp ToolChains/WebAssembly.cpp ToolChains/XCore.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 95723b9209d125..efe398dd531da7 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Drive
[clang] [Driver] Add toolchain for X86_64 UEFI target (PR #76838)
Prabhuk wrote: I am going to revert this and check the failures after. https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] riscv: Support -mstack-protector-guard=tls (PR #108942)
@@ -3681,6 +3698,11 @@ static void RenderSSPOptions(const Driver &D, const ToolChain &TC, D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Value; return; } +if (EffectiveTriple.isRISCV() && Value != "tp") { + D.Diag(diag::err_drv_invalid_value_with_suggestion) topperc wrote: Is there a test for this error? https://github.com/llvm/llvm-project/pull/108942 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 221f15f - [Clang] - Add libclangSerialization to clang driver unittests (#109329)
Author: Pranav Bhandarkar Date: 2024-09-19T16:51:08-05:00 New Revision: 221f15fc145d46289781206f241ae564cd9510f0 URL: https://github.com/llvm/llvm-project/commit/221f15fc145d46289781206f241ae564cd9510f0 DIFF: https://github.com/llvm/llvm-project/commit/221f15fc145d46289781206f241ae564cd9510f0.diff LOG: [Clang] - Add libclangSerialization to clang driver unittests (#109329) This PR is a fix for issue [#109328](https://github.com/llvm/llvm-project/issues/109328). libclangSerializaton.so is needed for building clang driver unittests after https://github.com/llvm/llvm-project/pull/76838 was merged. Needed for builds with `BUILD_SHARED_LIBS=ON` Added: Modified: clang/unittests/Driver/CMakeLists.txt Removed: diff --git a/clang/unittests/Driver/CMakeLists.txt b/clang/unittests/Driver/CMakeLists.txt index 752037f78fb147..efdd07ea238890 100644 --- a/clang/unittests/Driver/CMakeLists.txt +++ b/clang/unittests/Driver/CMakeLists.txt @@ -22,4 +22,5 @@ clang_target_link_libraries(ClangDriverTests clangDriver clangBasic clangFrontend # For TextDiagnosticPrinter. + clangSerialization ) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] - Add libclangSerialization to clang driver unittests (PR #109329)
https://github.com/bhandarkar-pranav closed https://github.com/llvm/llvm-project/pull/109329 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add toolchain for X86_64 UEFI target (PR #76838)
bhandarkar-pranav wrote: > Looks like this breaks tests on Mac: http://45.33.8.238/macm1/92471/step_6.txt > > Please take a look and revert for now if it takes a while to fix. @nico I cannot access the link from my work VPN, but if this is the issue (https://github.com/llvm/llvm-project/issues/109328) then here is a fix (https://github.com/llvm/llvm-project/pull/109329) https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lld] [llvm] [mlir] [IR] Introduce `T` to `DataLayout` to represent flat address space if a target supports it (PR #108786)
efriedma-quic wrote: > If DataLayout is still a good place, then it might be just about whether we > call it a flat address space, or optimizable address space, and nothing would > be different from what is done in this PR. We've avoided putting optimization properties in the DataLayout in the past. The interactions with LTO mean we want the DataLayout for a given subtarget to be stable. In this particular case, a target's "flat" address-space can't really ever change, though, so it's probably fine. > There are cases where you need a safe (portable?) default that the target can > perhaps optimise, but, absent that, would at least work, and at the moment > there's no handy way to query that generically (or from Clang). The use-cases currently under discussion, and LangRef itself, don't require the flat address-space to have any particular semantics; the only property it has is "operations using it are slower". What semantics do you need, and where do you need them? https://github.com/llvm/llvm-project/pull/108786 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] [MallocChecker] Fix Store modification in `checkPreCall` (PR #109337)
https://github.com/pskrgag created https://github.com/llvm/llvm-project/pull/109337 This is small follow-up for #106081 While trying to add sanity check for `Enviroment` and `Store` being consistent during `checkPostCall` and `checkPreCall` I found out that `MallocChecker` still violates that rule. The problem lies in `FreeMemAux`, which invalidates freed region while being called from `preGetdelim`. This invalidation was added to prevent "use of uninitialized memory" for malloc and friends while `unix.Malloc` is disabled. Fix adds another bool flag to `FreeMemAux` to control invalidation from call-site and set it to false in `preGetdelim` >From 2645cf0333590c6d30b93958494e6b4f60b423c4 Mon Sep 17 00:00:00 2001 From: Pavel Skripkin Date: Fri, 20 Sep 2024 00:21:03 +0300 Subject: [PATCH 1/2] make MallocChecker not modify state in checkPreCall --- .../StaticAnalyzer/Checkers/MallocChecker.cpp | 55 ++- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 81ec8e1b516986..7a265d3bbcda47 100644 --- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -668,7 +668,8 @@ class MallocChecker [[nodiscard]] ProgramStateRef FreeMemAux(CheckerContext &C, const CallEvent &Call, ProgramStateRef State, unsigned Num, bool Hold, bool &IsKnownToBeAllocated, - AllocationFamily Family, bool ReturnsNullOnFailure = false) const; + AllocationFamily Family, bool Invalidate = true, + bool ReturnsNullOnFailure = false) const; /// Models memory deallocation. /// @@ -694,7 +695,8 @@ class MallocChecker [[nodiscard]] ProgramStateRef FreeMemAux(CheckerContext &C, const Expr *ArgExpr, const CallEvent &Call, ProgramStateRef State, bool Hold, bool &IsKnownToBeAllocated, - AllocationFamily Family, bool ReturnsNullOnFailure = false, + AllocationFamily Family, bool Invalidate = true, + bool ReturnsNullOnFailure = false, std::optional ArgValOpt = {}) const; // TODO: Needs some refactoring, as all other deallocation modeling @@ -1474,9 +1476,10 @@ void MallocChecker::preGetdelim(ProgramStateRef State, const CallEvent &Call, // We do not need this value here, as FreeMemAux will take care // of reporting any violation of the preconditions. bool IsKnownToBeAllocated = false; - State = FreeMemAux(C, Call.getArgExpr(0), Call, State, false, - IsKnownToBeAllocated, AllocationFamily(AF_Malloc), false, - LinePtr); + State = + FreeMemAux(C, Call.getArgExpr(0), Call, State, false, + IsKnownToBeAllocated, AllocationFamily(AF_Malloc), + /*Invalidate=*/false, /*ReturnsNullOnFailure=*/false, LinePtr); if (State) C.addTransition(State); } @@ -1793,6 +1796,7 @@ void MallocChecker::checkPostObjCMessage(const ObjCMethodCall &Call, ProgramStateRef State = FreeMemAux(C, Call.getArgExpr(0), Call, C.getState(), /*Hold=*/true, IsKnownToBeAllocatedMemory, AllocationFamily(AF_Malloc), + /*Invalidate=*/false, /*ReturnsNullOnFailure=*/true); C.addTransition(State); @@ -1986,12 +1990,11 @@ ProgramStateRef MallocChecker::FreeMemAttr(CheckerContext &C, return State; } -ProgramStateRef MallocChecker::FreeMemAux(CheckerContext &C, - const CallEvent &Call, - ProgramStateRef State, unsigned Num, - bool Hold, bool &IsKnownToBeAllocated, - AllocationFamily Family, - bool ReturnsNullOnFailure) const { +ProgramStateRef +MallocChecker::FreeMemAux(CheckerContext &C, const CallEvent &Call, + ProgramStateRef State, unsigned Num, bool Hold, + bool &IsKnownToBeAllocated, AllocationFamily Family, + bool Invalidate, bool ReturnsNullOnFailure) const { if (!State) return nullptr; @@ -1999,7 +2002,8 @@ ProgramStateRef MallocChecker::FreeMemAux(CheckerContext &C, return nullptr; return FreeMemAux(C, Call.getArgExpr(Num), Call, State, Hold, -IsKnownToBeAllocated, Family, ReturnsNullOnFailure); +IsKnownToBeAllocated, Family, Invalidate, +ReturnsNullOnFailure); } /// Checks if the previous call to free on the given symbol failed - if free @@ -2134,12 +2138,11 @@ static void printExpectedDeallocName(raw_ostream &os, AllocationFamily Family) { } } -ProgramStateRef -MallocChecker::FreeMemAux(CheckerContext &C, const Expr *Arg
[clang] [analyzer] [MallocChecker] Fix Store modification in `checkPreCall` (PR #109337)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-static-analyzer-1 Author: Pavel Skripkin (pskrgag) Changes This is small follow-up for #106081 While trying to add sanity check for `Enviroment` and `Store` being consistent during `checkPostCall` and `checkPreCall` I found out that `MallocChecker` still violates that rule. The problem lies in `FreeMemAux`, which invalidates freed region while being called from `preGetdelim`. This invalidation was added to prevent "use of uninitialized memory" for malloc and friends while `unix.Malloc` is disabled. Fix adds another bool flag to `FreeMemAux` to control invalidation from call-site and set it to false in `preGetdelim` --- Full diff: https://github.com/llvm/llvm-project/pull/109337.diff 2 Files Affected: - (modified) clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (+30-25) - (modified) clang/test/Analysis/NewDelete-intersections.mm (+9) ``diff diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 81ec8e1b516986..7a265d3bbcda47 100644 --- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -668,7 +668,8 @@ class MallocChecker [[nodiscard]] ProgramStateRef FreeMemAux(CheckerContext &C, const CallEvent &Call, ProgramStateRef State, unsigned Num, bool Hold, bool &IsKnownToBeAllocated, - AllocationFamily Family, bool ReturnsNullOnFailure = false) const; + AllocationFamily Family, bool Invalidate = true, + bool ReturnsNullOnFailure = false) const; /// Models memory deallocation. /// @@ -694,7 +695,8 @@ class MallocChecker [[nodiscard]] ProgramStateRef FreeMemAux(CheckerContext &C, const Expr *ArgExpr, const CallEvent &Call, ProgramStateRef State, bool Hold, bool &IsKnownToBeAllocated, - AllocationFamily Family, bool ReturnsNullOnFailure = false, + AllocationFamily Family, bool Invalidate = true, + bool ReturnsNullOnFailure = false, std::optional ArgValOpt = {}) const; // TODO: Needs some refactoring, as all other deallocation modeling @@ -1474,9 +1476,10 @@ void MallocChecker::preGetdelim(ProgramStateRef State, const CallEvent &Call, // We do not need this value here, as FreeMemAux will take care // of reporting any violation of the preconditions. bool IsKnownToBeAllocated = false; - State = FreeMemAux(C, Call.getArgExpr(0), Call, State, false, - IsKnownToBeAllocated, AllocationFamily(AF_Malloc), false, - LinePtr); + State = + FreeMemAux(C, Call.getArgExpr(0), Call, State, false, + IsKnownToBeAllocated, AllocationFamily(AF_Malloc), + /*Invalidate=*/false, /*ReturnsNullOnFailure=*/false, LinePtr); if (State) C.addTransition(State); } @@ -1793,6 +1796,7 @@ void MallocChecker::checkPostObjCMessage(const ObjCMethodCall &Call, ProgramStateRef State = FreeMemAux(C, Call.getArgExpr(0), Call, C.getState(), /*Hold=*/true, IsKnownToBeAllocatedMemory, AllocationFamily(AF_Malloc), + /*Invalidate=*/false, /*ReturnsNullOnFailure=*/true); C.addTransition(State); @@ -1986,12 +1990,11 @@ ProgramStateRef MallocChecker::FreeMemAttr(CheckerContext &C, return State; } -ProgramStateRef MallocChecker::FreeMemAux(CheckerContext &C, - const CallEvent &Call, - ProgramStateRef State, unsigned Num, - bool Hold, bool &IsKnownToBeAllocated, - AllocationFamily Family, - bool ReturnsNullOnFailure) const { +ProgramStateRef +MallocChecker::FreeMemAux(CheckerContext &C, const CallEvent &Call, + ProgramStateRef State, unsigned Num, bool Hold, + bool &IsKnownToBeAllocated, AllocationFamily Family, + bool Invalidate, bool ReturnsNullOnFailure) const { if (!State) return nullptr; @@ -1999,7 +2002,8 @@ ProgramStateRef MallocChecker::FreeMemAux(CheckerContext &C, return nullptr; return FreeMemAux(C, Call.getArgExpr(Num), Call, State, Hold, -IsKnownToBeAllocated, Family, ReturnsNullOnFailure); +IsKnownToBeAllocated, Family, Invalidate, +ReturnsNullOnFailure); } /// Checks if the previous call to free on the given symbol failed - if free @@ -2134,12 +2138,11 @@ static void printExpectedDeallocName(raw_ostream &os, AllocationFamily Family) { } } -ProgramStateRef -MallocChecker::FreeMemAux(CheckerContext &C, const Expr *ArgExpr, - con
[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)
https://github.com/tarunprabhu updated https://github.com/llvm/llvm-project/pull/102975 >From f0801cb9e3caeb41a078bc091b9ed624695c83e4 Mon Sep 17 00:00:00 2001 From: Tarun Prabhu Date: Mon, 12 Aug 2024 14:32:08 -0600 Subject: [PATCH 1/6] [clang][flang][mlir] Support -frecord-command-line option Add support for the -frecord-command-line option that will produce the llvm.commandline metadata which will eventually be saved in the object file. This behavior is also supported in clang. Some refactoring of the code in flang to handle these command line options was carried out. The corresponding -grecord-command-line option which saves the command line in the debug information has not yet been enabled for flang. --- clang/include/clang/Driver/Options.td | 14 ++-- clang/lib/Driver/CMakeLists.txt | 1 + clang/lib/Driver/ToolChains/Clang.cpp | 48 ++-- clang/lib/Driver/ToolChains/CommonUtils.cpp | 76 +++ clang/lib/Driver/ToolChains/CommonUtils.h | 44 +++ clang/lib/Driver/ToolChains/Flang.cpp | 15 flang/include/flang/Frontend/CodeGenOptions.h | 3 + flang/include/flang/Lower/Bridge.h| 12 ++- .../Optimizer/Dialect/Support/FIRContext.h| 6 ++ flang/lib/Frontend/CompilerInvocation.cpp | 6 ++ flang/lib/Frontend/FrontendActions.cpp| 2 +- flang/lib/Lower/Bridge.cpp| 8 +- .../Optimizer/Dialect/Support/FIRContext.cpp | 16 flang/test/Driver/frecord-command-line.f90| 16 flang/test/Lower/record-command-line.f90 | 9 +++ flang/tools/bbc/CMakeLists.txt| 1 + flang/tools/bbc/bbc.cpp | 10 ++- .../mlir/Dialect/LLVMIR/LLVMDialect.td| 1 + .../include/mlir/Target/LLVMIR/ModuleImport.h | 4 + .../mlir/Target/LLVMIR/ModuleTranslation.h| 3 + mlir/lib/Target/LLVMIR/ModuleImport.cpp | 19 + mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 17 + mlir/test/Target/LLVMIR/Import/commandline.ll | 6 ++ mlir/test/Target/LLVMIR/commandline.mlir | 6 ++ 24 files changed, 284 insertions(+), 59 deletions(-) create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.cpp create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.h create mode 100644 flang/test/Driver/frecord-command-line.f90 create mode 100644 flang/test/Lower/record-command-line.f90 create mode 100644 mlir/test/Target/LLVMIR/Import/commandline.ll create mode 100644 mlir/test/Target/LLVMIR/commandline.mlir diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index aa3ae92fb6ae78..11dd17aa7af9a0 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1994,16 +1994,18 @@ def fparse_all_comments : Flag<["-"], "fparse-all-comments">, Group, MarshallingInfoFlag>; def frecord_command_line : Flag<["-"], "frecord-command-line">, - DocBrief<[{Generate a section named ".GCC.command.line" containing the clang + DocBrief<[{Generate a section named ".GCC.command.line" containing the driver command-line. After linking, the section may contain multiple command lines, which will be individually terminated by null bytes. Separate arguments within a command line are combined with spaces; spaces and backslashes within an argument are escaped with backslashes. This format differs from the format of the equivalent section produced by GCC with the -frecord-gcc-switches flag. This option is currently only supported on ELF targets.}]>, - Group; + Group, + Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>; def fno_record_command_line : Flag<["-"], "fno-record-command-line">, - Group; + Group, + Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>; def : Flag<["-"], "frecord-gcc-switches">, Alias; def : Flag<["-"], "fno-record-gcc-switches">, Alias; def fcommon : Flag<["-"], "fcommon">, Group, @@ -7141,6 +7143,9 @@ def mrelocation_model : Separate<["-"], "mrelocation-model">, NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", "DynamicNoPIC"]>, MarshallingInfoEnum, "PIC_">; def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">; +def record_command_line : Separate<["-"], "record-command-line">, + HelpText<"The string to embed in the .LLVM.command.line section.">, + MarshallingInfoString>; } // let Visibility = [CC1Option, CC1AsOption, FC1Option] @@ -7161,9 +7166,6 @@ def debugger_tuning_EQ : Joined<["-"], "debugger-tuning=">, def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">, HelpText<"The string to embed in the Dwarf debug flags record.">, MarshallingInfoString>; -def record_command_line : Separate<["-"], "record-command-line">, - HelpText<"The string to embed in the .LLVM.command.line section.">, - MarshallingInfoString>; def compress_debug_sections_EQ : Joined<["-", "--"], "compress-debug-sections=">, HelpText<"DWARF debug sections compression type">, Values<"none,zlib,zstd">
[clang] [llvm] riscv: Support -mstack-protector-guard=tls (PR #108942)
@@ -0,0 +1,19 @@ +; RUN: llc -mtriple=riscv64-unknown-elf < %s | \ topperc wrote: Use `llvm/utils/update_llc_test_checks.py` to generate the checks. https://github.com/llvm/llvm-project/pull/108942 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)
zygoloid wrote: > I'm happy once SOME level of solution for the index-starting-value is done > (`NextStringLiteralVersion=rand()` 🤡). I think the avoided collisions is > worth a touch of effort, but not much more. Um. So. I added a test for this before I started working on a fix, and ... the test passes. It turns out that the existing implementation already works: while we do have some support for importing computed constant values, we always recompute constants locally before using them as inputs to further local constant evaluations, so we produce a local numbering even for what appear to be imported constants. We would need to do something different here if we ever change that, but we now have test coverage for it, so we should notice. > I think there is some concern from others about `opaque` that should probably > be settled on, but I'm happy with whatever all of you come up with, even if > it is `opaque`. I hope I've addressed that by including the value of the pointer in the diagnostic. https://github.com/llvm/llvm-project/pull/109208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)
https://github.com/zygoloid updated https://github.com/llvm/llvm-project/pull/109208 >From 81193568c17a89f6cf42f43a82fb1fbf0f90184d Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 18 Sep 2024 21:59:56 + Subject: [PATCH 01/13] Implement current CWG direction for string literal comparisons. Track the identity of each string literal object produced by evaluation with a global version number. Accept comparisons between literals of the same version, and between literals of different versions that cannot possibly be placed in overlapping storage. Treat the remaining comparisons as non-constant. --- clang/include/clang/AST/ASTContext.h | 11 ++ .../include/clang/Basic/DiagnosticASTKinds.td | 2 + clang/lib/AST/ExprConstant.cpp| 119 +++--- clang/test/AST/ByteCode/builtin-functions.cpp | 3 +- clang/test/AST/ByteCode/cxx20.cpp | 20 ++- clang/test/SemaCXX/builtins.cpp | 2 +- .../SemaCXX/constant-expression-cxx11.cpp | 36 -- 7 files changed, 154 insertions(+), 39 deletions(-) diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index b65a1f7dff5bc1..6170bcd4f15ae3 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -324,6 +324,13 @@ class ASTContext : public RefCountedBase { /// This is lazily created. This is intentionally not serialized. mutable llvm::StringMap StringLiteralCache; + /// The next string literal "version" to allocate during constant evaluation. + /// This is used to distinguish between repeated evaluations of the same + /// string literal. + /// + /// TODO: Ensure version numbers don't collide when deserialized. + unsigned NextStringLiteralVersion = 0; + /// MD5 hash of CUID. It is calculated when first used and cached by this /// data member. mutable std::string CUIDHash; @@ -3278,6 +3285,10 @@ class ASTContext : public RefCountedBase { /// PredefinedExpr to cache evaluated results. StringLiteral *getPredefinedStringLiteralFromCache(StringRef Key) const; + /// Return the next version number to be used for a string literal evaluated + /// as part of constant evaluation. + unsigned getNextStringLiteralVersion() { return NextStringLiteralVersion++; } + /// Return a declaration for the global GUID object representing the given /// GUID value. MSGuidDecl *getMSGuidDecl(MSGuidDeclParts Parts) const; diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td b/clang/include/clang/Basic/DiagnosticASTKinds.td index 21a307d1e89878..76e693f6b4a6ca 100644 --- a/clang/include/clang/Basic/DiagnosticASTKinds.td +++ b/clang/include/clang/Basic/DiagnosticASTKinds.td @@ -96,6 +96,8 @@ def note_constexpr_pointer_constant_comparison : Note< "at runtime">; def note_constexpr_literal_comparison : Note< "comparison of addresses of literals has unspecified value">; +def note_constexpr_opaque_call_comparison : Note< + "comparison against opaque constant has unspecified value">; def note_constexpr_pointer_weak_comparison : Note< "comparison against address of weak declaration '%0' can only be performed " "at runtime">; diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 6387e375dda79c..d9384a7c125a82 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -54,8 +54,10 @@ #include "clang/Basic/DiagnosticSema.h" #include "clang/Basic/TargetInfo.h" #include "llvm/ADT/APFixedPoint.h" +#include "llvm/ADT/Sequence.h" #include "llvm/ADT/SmallBitVector.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Debug.h" #include "llvm/Support/SaveAndRestore.h" #include "llvm/Support/SipHash.h" @@ -2061,8 +2063,8 @@ static bool EvaluateIgnoredValue(EvalInfo &Info, const Expr *E) { return true; } -/// Should this call expression be treated as a no-op? -static bool IsNoOpCall(const CallExpr *E) { +/// Should this call expression be treated as forming an opaque constant? +static bool IsOpaqueConstantCall(const CallExpr *E) { unsigned Builtin = E->getBuiltinCallee(); return (Builtin == Builtin::BI__builtin___CFStringMakeConstantString || Builtin == Builtin::BI__builtin___NSStringMakeConstantString || @@ -2070,6 +2072,12 @@ static bool IsNoOpCall(const CallExpr *E) { Builtin == Builtin::BI__builtin_function_start); } +static bool IsOpaqueConstantCall(const LValue &LVal) { + auto *BaseExpr = + llvm::dyn_cast_or_null(LVal.Base.dyn_cast()); + return BaseExpr && IsOpaqueConstantCall(BaseExpr); +} + static bool IsGlobalLValue(APValue::LValueBase B) { // C++11 [expr.const]p3 An address constant expression is a prvalue core // constant expression of pointer type that evaluates to... @@ -2115,7 +2123,7 @@ static bool IsGlobalLValue(APValue::LValueBase B) { case Expr::ObjCBoxedExprClass: return cast(E)->isExpressibleAsConstantInitializer(); c
[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)
https://github.com/zygoloid updated https://github.com/llvm/llvm-project/pull/109208 >From 81193568c17a89f6cf42f43a82fb1fbf0f90184d Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 18 Sep 2024 21:59:56 + Subject: [PATCH 01/12] Implement current CWG direction for string literal comparisons. Track the identity of each string literal object produced by evaluation with a global version number. Accept comparisons between literals of the same version, and between literals of different versions that cannot possibly be placed in overlapping storage. Treat the remaining comparisons as non-constant. --- clang/include/clang/AST/ASTContext.h | 11 ++ .../include/clang/Basic/DiagnosticASTKinds.td | 2 + clang/lib/AST/ExprConstant.cpp| 119 +++--- clang/test/AST/ByteCode/builtin-functions.cpp | 3 +- clang/test/AST/ByteCode/cxx20.cpp | 20 ++- clang/test/SemaCXX/builtins.cpp | 2 +- .../SemaCXX/constant-expression-cxx11.cpp | 36 -- 7 files changed, 154 insertions(+), 39 deletions(-) diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index b65a1f7dff5bc1..6170bcd4f15ae3 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -324,6 +324,13 @@ class ASTContext : public RefCountedBase { /// This is lazily created. This is intentionally not serialized. mutable llvm::StringMap StringLiteralCache; + /// The next string literal "version" to allocate during constant evaluation. + /// This is used to distinguish between repeated evaluations of the same + /// string literal. + /// + /// TODO: Ensure version numbers don't collide when deserialized. + unsigned NextStringLiteralVersion = 0; + /// MD5 hash of CUID. It is calculated when first used and cached by this /// data member. mutable std::string CUIDHash; @@ -3278,6 +3285,10 @@ class ASTContext : public RefCountedBase { /// PredefinedExpr to cache evaluated results. StringLiteral *getPredefinedStringLiteralFromCache(StringRef Key) const; + /// Return the next version number to be used for a string literal evaluated + /// as part of constant evaluation. + unsigned getNextStringLiteralVersion() { return NextStringLiteralVersion++; } + /// Return a declaration for the global GUID object representing the given /// GUID value. MSGuidDecl *getMSGuidDecl(MSGuidDeclParts Parts) const; diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td b/clang/include/clang/Basic/DiagnosticASTKinds.td index 21a307d1e89878..76e693f6b4a6ca 100644 --- a/clang/include/clang/Basic/DiagnosticASTKinds.td +++ b/clang/include/clang/Basic/DiagnosticASTKinds.td @@ -96,6 +96,8 @@ def note_constexpr_pointer_constant_comparison : Note< "at runtime">; def note_constexpr_literal_comparison : Note< "comparison of addresses of literals has unspecified value">; +def note_constexpr_opaque_call_comparison : Note< + "comparison against opaque constant has unspecified value">; def note_constexpr_pointer_weak_comparison : Note< "comparison against address of weak declaration '%0' can only be performed " "at runtime">; diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 6387e375dda79c..d9384a7c125a82 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -54,8 +54,10 @@ #include "clang/Basic/DiagnosticSema.h" #include "clang/Basic/TargetInfo.h" #include "llvm/ADT/APFixedPoint.h" +#include "llvm/ADT/Sequence.h" #include "llvm/ADT/SmallBitVector.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Debug.h" #include "llvm/Support/SaveAndRestore.h" #include "llvm/Support/SipHash.h" @@ -2061,8 +2063,8 @@ static bool EvaluateIgnoredValue(EvalInfo &Info, const Expr *E) { return true; } -/// Should this call expression be treated as a no-op? -static bool IsNoOpCall(const CallExpr *E) { +/// Should this call expression be treated as forming an opaque constant? +static bool IsOpaqueConstantCall(const CallExpr *E) { unsigned Builtin = E->getBuiltinCallee(); return (Builtin == Builtin::BI__builtin___CFStringMakeConstantString || Builtin == Builtin::BI__builtin___NSStringMakeConstantString || @@ -2070,6 +2072,12 @@ static bool IsNoOpCall(const CallExpr *E) { Builtin == Builtin::BI__builtin_function_start); } +static bool IsOpaqueConstantCall(const LValue &LVal) { + auto *BaseExpr = + llvm::dyn_cast_or_null(LVal.Base.dyn_cast()); + return BaseExpr && IsOpaqueConstantCall(BaseExpr); +} + static bool IsGlobalLValue(APValue::LValueBase B) { // C++11 [expr.const]p3 An address constant expression is a prvalue core // constant expression of pointer type that evaluates to... @@ -2115,7 +2123,7 @@ static bool IsGlobalLValue(APValue::LValueBase B) { case Expr::ObjCBoxedExprClass: return cast(E)->isExpressibleAsConstantInitializer(); c
[clang] Add missing deps edge: CodeGenAction.cpp.o -> GenVT.inc (PR #109306)
https://github.com/etcwilde closed https://github.com/llvm/llvm-project/pull/109306 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] c3fe727 - Add missing deps edge: CodeGenAction.cpp.o -> GenVT.inc (#109306)
Author: Evan Wilde Date: 2024-09-19T14:14:18-07:00 New Revision: c3fe727181818d3efdd2ce96598bfe6a2d3ffb83 URL: https://github.com/llvm/llvm-project/commit/c3fe727181818d3efdd2ce96598bfe6a2d3ffb83 DIFF: https://github.com/llvm/llvm-project/commit/c3fe727181818d3efdd2ce96598bfe6a2d3ffb83.diff LOG: Add missing deps edge: CodeGenAction.cpp.o -> GenVT.inc (#109306) CodeGenAction.cpp.o depends on generating GenVT.inc before trying to compile it through the following header chain: ``` GenVT.inc MachineValueType.h LowLevelType.h MachineMemOperand.h MachineInstr.h MachineBasicBlock.h MachineFunctionPass.h MachineOptimizationRemarkEmitter.h CodeGenAction.cpp ``` There is a dependency edge through LLVMCodeGenTypes, but that edge is applied to the clangCodeGen link step, not the compile step of the files that make up clangCodeGen. Usually the compile and link are close enough in the build that GenVT.inc is scheduled early enough that it exists by the time we're compiling CodeGenAction.cpp.o, but on machines with high core counts, it seems to be more prevalent that the scheduling works out just right to expose the missing edge. I've only been able to reproduce this on machines with at least 64 cores (but even then it was not reliable). Additionally, llvm-tblgen depends on GenVT.inc, so to see the missing dependency edge, one must be using a pre-built tablegen binary. Adding the missing dependency edge to ensure that GenVT.inc is generated before trying to compile CodeGenAction.cpp.o. Found by inspecting the dependency graph generated from Ninja with: ```sh cmake -G 'Ninja' \ ... -DLLVM_TABLEGEN= \ -DCLANG_TABLEGEN= \ -DLLVM_ENABLE_PROJECTS=clang \ ... ninja -t graph \ tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/CodeGenAction.cpp.o | dot -Tpdf > CodeGenAction.pdf ``` Added: Modified: clang/lib/CodeGen/CMakeLists.txt Removed: diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt index aa0c871c5352a8..868ec847b9634b 100644 --- a/clang/lib/CodeGen/CMakeLists.txt +++ b/clang/lib/CodeGen/CMakeLists.txt @@ -144,6 +144,7 @@ add_clang_library(clangCodeGen VarBypassDetector.cpp DEPENDS + vt_gen intrinsics_gen ClangDriverOptions # These generated headers are included transitively. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add missing deps edge: CodeGenAction.cpp.o -> GenVT.inc (PR #109306)
https://github.com/jroelofs approved this pull request. https://github.com/llvm/llvm-project/pull/109306 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Check initializer of zero-size fields for nullptr (PR #109271)
@@ -0,0 +1,11 @@ +// RUN: %clang_cc1 %s -emit-llvm -triple x86_64-linux-gnu -o - | FileCheck %s --check-prefixes=CHECK +// RUN: %clang_cc1 -x c++ %s -emit-llvm -triple x86_64-linux-gnu -o - | FileCheck %s --check-prefixes=CHECK-CXX + +union Foo { + struct Empty {} val; +}; + +union Foo foo = {}; + +// CHECK: @foo = {{.*}}global %union.Foo undef, align 1 efriedma-quic wrote: Generated code seems okay. I mean, it's the same thing we've always generated for similar constructs. I'd prefer to integrate this into some existing codegen test if we can, though... https://github.com/llvm/llvm-project/pull/109271 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Check initializer of zero-size fields for nullptr (PR #109271)
@@ -738,7 +738,7 @@ bool ConstStructBuilder::Build(const InitListExpr *ILE, bool AllowOverwrite) { // Zero-sized fields are not emitted, but their initializers may still // prevent emission of this struct as a constant. if (isEmptyFieldForLayout(CGM.getContext(), Field)) { - if (Init->HasSideEffects(CGM.getContext())) + if (Init && Init->HasSideEffects(CGM.getContext())) efriedma-quic wrote: Maybe we should look at making InitListExpr handling more consistent, though... it looks like we generate an implicit initializer expression for C++ classes, but not other cases. But this should do the right thing. https://github.com/llvm/llvm-project/pull/109271 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][wasm] Replace the target integer add saturate intrinsics with the equivalent generic `__builtin_elementwise_add_sat` intrinsics (PR #109269)
https://github.com/tlively approved this pull request. LGTM. FWIW, I'm not aware of any special reason why `wasm_sub_sat` should be any different. https://github.com/llvm/llvm-project/pull/109269 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add toolchain for X86_64 UEFI target (PR #76838)
nico wrote: Looks like this breaks tests on Mac: http://45.33.8.238/macm1/92471/step_6.txt Please take a look and revert for now if it takes a while to fix. https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][wasm] Replace the target iminmax intrinsics with the equivalent generic `__builtin_elementwise_min/max` intrinsics (PR #109259)
https://github.com/tlively approved this pull request. Great, thank you! https://github.com/llvm/llvm-project/pull/109259 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] adding clang codegen (PR #109331)
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/109331 >From 8f21239c496cc4ce273bafb2c2dd5a22de16a0c3 Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Thu, 19 Sep 2024 00:13:51 + Subject: [PATCH] adding clang codegen --- clang/include/clang/Basic/Builtins.td | 6 ++ clang/lib/CodeGen/CGBuiltin.cpp | 36 +++- clang/lib/CodeGen/CGHLSLRuntime.h | 1 - clang/lib/Headers/hlsl/hlsl_intrinsics.h | 20 +++ clang/lib/Sema/SemaHLSL.cpp | 56 --- .../builtins/asuint-splitdouble.hlsl | 9 +++ llvm/include/llvm/IR/IntrinsicsDirectX.td | 5 ++ llvm/lib/Target/DirectX/DXIL.td | 1 + .../Target/DirectX/DXILIntrinsicExpansion.cpp | 13 + 9 files changed, 137 insertions(+), 10 deletions(-) create mode 100644 clang/test/CodeGenHLSL/builtins/asuint-splitdouble.hlsl diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 8c5d7ad763bf97..b38957f6e3f15d 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4788,6 +4788,12 @@ def HLSLStep: LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } +def HLSLAsUintSplitDouble: LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_hlsl_asuint_splitdouble"]; + let Attributes = [NoThrow, Const]; + let Prototype = "void(...)"; +} + // Builtins for XRay. def XRayCustomEvent : Builtin { let Spellings = ["__xray_customevent"]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index e2711f1ba70239..256a497c2506a4 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -18824,6 +18824,40 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: { retType, CGM.getHLSLRuntime().getSignIntrinsic(), ArrayRef{Op0}, nullptr, "hlsl.sign"); } + // This should only be called when targeting DXIL + case Builtin::BI__builtin_hlsl_asuint_splitdouble: { + +assert((E->getArg(0)->getType()->isDoubleType() || +E->getArg(1)->getType()->isUnsignedIntegerType() || +E->getArg(2)->getType()->isUnsignedIntegerType()) && + "asuint operands types mismatch"); + +Value *Op0 = EmitScalarExpr(E->getArg(0)); + +llvm::Type *retType = llvm::StructType::get(Int32Ty, Int32Ty); +if (Op0->getType()->isVectorTy()) { + auto *XVecTy = E->getArg(0)->getType()->getAs(); + + llvm::VectorType *i32VecTy = llvm::VectorType::get( + Int32Ty, ElementCount::getFixed(XVecTy->getNumElements())); + + retType = llvm::StructType::get(i32VecTy, i32VecTy); +} + +auto ptr = CreateMemTemp(E->getArg(1)->getType()); +EmitAnyExprToMem(E->getArg(1), ptr, Qualifiers(), /*init*/ true); +Address x = EmitPointerWithAlignment(E->getArg(1)); + +CallInst *CI = +Builder.CreateIntrinsic(retType, llvm::Intrinsic::dx_asuint_splitdouble, +{Op0}, nullptr, "hlsl.asuint"); + +// Value* arg1 = Builder.CreateExtractValue(CI, 1); + +// Address y = EmitPointerWithAlignment(E->getArg(2)); +// Builder.CreateLoad(ptr); +// return Builder.CreateStore(arg1, ptr); + } } return nullptr; } @@ -22398,4 +22432,4 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID, llvm::Function *F = CGM.getIntrinsic(ID, IntrinsicTypes); return Builder.CreateCall(F, Ops, ""); -} +} \ No newline at end of file diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h index a8aabca7348ffb..74876657646d07 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.h +++ b/clang/lib/CodeGen/CGHLSLRuntime.h @@ -87,7 +87,6 @@ class CGHLSLRuntime { GENERATE_HLSL_INTRINSIC_FUNCTION(SDot, sdot) GENERATE_HLSL_INTRINSIC_FUNCTION(UDot, udot) GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane) - //===--===// // End of reserved area for HLSL intrinsic getters. //===--===// diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index 6cd6a2caf19994..d48b60bab16d51 100644 --- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -423,6 +423,26 @@ template _HLSL_INLINE uint asuint(T F) { return __detail::bit_cast(F); } +//===--===// +// asuint splitdouble builtins +//===--===// + +/// \fn void asuint(double D, out uint lowbits, out int highbits) +/// \brief Split and interprets the lowbits and highbits of double D into uints. +/// \param D The input double. +/// \param lowbits The output lowbits of D. +/// \param highbits The highbits lowbits D. +#if __is_target_arch(dxil) +_HLSL_BUILTIN_AL
[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/109169 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)
@@ -84,6 +84,29 @@ void test_macro_expansion4() { #undef MY_NULL } +template struct pear { + // If you say __null (or NULL), we assume that T will always be a pointer fmayer wrote: Thanks, otherwise this comment will only cause confusion. https://github.com/llvm/llvm-project/pull/109169 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)
@@ -84,6 +84,29 @@ void test_macro_expansion4() { #undef MY_NULL } +template struct pear { + // If you say __null (or NULL), we assume that T will always be a pointer tkoeppe wrote: Sure, done. https://github.com/llvm/llvm-project/pull/109169 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)
https://github.com/tkoeppe updated https://github.com/llvm/llvm-project/pull/109169 From 1149cbacb6b8376b6ed3d7651f0fa51360a67ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20K=C3=B6ppe?= Date: Wed, 18 Sep 2024 17:04:44 + Subject: [PATCH] [clang-tidy] Make modernize-use-nullptr matcher also match "NULL", but not "0", when it appears on a substituted type of a template specialization. Previously, any matches on a substituted type were excluded, but this meant that a situation like the following is not diagnosed: ```c++ template struct X { T val; X() { val = NULL; } // should diagnose }; ``` When the user says `NULL`, we expect that the destination type is always meant to be a pointer type, so this should be converted to `nullptr`. By contrast, we do not propose changing a literal `0` in that case, which appears as initializers of both pointer and integer specializations in reasonable real code. (If `NULL` is used erroneously in such a situation, it should be changed to `0` or `{}`.) --- .../clang-tidy/modernize/UseNullptrCheck.cpp | 4 ++- clang-tools-extra/docs/ReleaseNotes.rst | 4 +++ .../checkers/modernize/use-nullptr.cpp| 25 +++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp index 6a003a347badac..b2921690863b84 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp @@ -38,7 +38,9 @@ AST_MATCHER(Type, sugaredNullptrType) { StatementMatcher makeCastSequenceMatcher(llvm::ArrayRef NameList) { auto ImplicitCastToNull = implicitCastExpr( anyOf(hasCastKind(CK_NullToPointer), hasCastKind(CK_NullToMemberPointer)), - unless(hasImplicitDestinationType(qualType(substTemplateTypeParmType(, + anyOf(hasSourceExpression(gnuNullExpr()), +unless(hasImplicitDestinationType( +qualType(substTemplateTypeParmType(), unless(hasSourceExpression(hasType(sugaredNullptrType(, unless(hasImplicitDestinationType( qualType(matchers::matchesAnyListedTypeName(NameList); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index d032cef6b76164..b2bb7549f840cc 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -157,6 +157,10 @@ Changes in existing checks a false positive when only an implicit conversion happened inside an initializer list. +- Improved :doc:`modernize-use-nullptr + ` check to also recognize + ``NULL``/``__null`` (but not ``0``) when used with a templated type. + - Improved :doc:`modernize-use-std-print ` check to support replacing member function calls too. diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp index 7bc0925136aa86..2c36349da896cf 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp @@ -84,6 +84,31 @@ void test_macro_expansion4() { #undef MY_NULL } +template struct pear { + // If you say __null (or NULL), we assume that T will always be a pointer + // type, so we suggest replacing it with nullptr. (We only check __null here, + // because in this test NULL is defined as 0, but real library implementations + // it is often defined as __null and the check will catch it.) + void f() { x = __null; } + // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr [modernize-use-nullptr] + // CHECK-FIXES: x = nullptr; + + // But if you say 0, we allow the possibility that T can be used with integral + // and pointer types, and "0" is an acceptable initializer (even if "{}" might + // be even better). + void g() { y = 0; } + // CHECK-MESSAGES-NOT: :[[@LINE-1]] warning: use nullptr + + T x; + T y; +}; +void test_templated() { + pear p; + p.f(); + p.g(); + dummy(p.x); +} + #define IS_EQ(x, y) if (x != y) return; void test_macro_args() { int i = 0; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)
@@ -84,6 +84,29 @@ void test_macro_expansion4() { #undef MY_NULL } +template struct pear { + // If you say __null (or NULL), we assume that T will always be a pointer fmayer wrote: Sorry, the implication of my comment was: explain why in a comment, because future readers will not know that. https://github.com/llvm/llvm-project/pull/109169 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)
https://github.com/erichkeane approved this pull request. I'm happy once SOME level of solution for the index-starting-value is done (`NextStringLiteralVersion=rand()` 🤡). I think the avoided collisions is worth a touch of effort, but not much more. I think there is some concern from others about `opaque` that should probably be settled on, but I'm happy with whatever all of you come up with, even if it is `opaque`. https://github.com/llvm/llvm-project/pull/109208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)
@@ -84,6 +84,29 @@ void test_macro_expansion4() { #undef MY_NULL } +template struct pear { + // If you say __null (or NULL), we assume that T will always be a pointer tkoeppe wrote: That was the whole thing we were belaboring earlier -- this test defines `NULL` to `0` and thus isn't caught, but in production, it's defined as `__null`, where the new code catches it. We don't actually have code to detect "this was spelled as a macro", I'm afraid (right, @zygoloid?). https://github.com/llvm/llvm-project/pull/109169 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)
@@ -84,6 +84,29 @@ void test_macro_expansion4() { #undef MY_NULL } +template struct pear { + // If you say __null (or NULL), we assume that T will always be a pointer fmayer wrote: why are we only testing one of those? https://github.com/llvm/llvm-project/pull/109169 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)
@@ -324,6 +324,13 @@ class ASTContext : public RefCountedBase { /// This is lazily created. This is intentionally not serialized. mutable llvm::StringMap StringLiteralCache; + /// The next string literal "version" to allocate during constant evaluation. + /// This is used to distinguish between repeated evaluations of the same + /// string literal. + /// + /// TODO: Ensure version numbers don't collide when deserialized. erichkeane wrote: > Maybe we can think of a better way? (Initializing the counter to a hash is > sounding a bit better now, huh?) Thats probably at least as good as my line/column/file info suggestion, but based on the above/thinking further, I think anything besides "start at the same number for all" is perfectly acceptable. https://github.com/llvm/llvm-project/pull/109208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add toolchain for X86_64 UEFI target (PR #76838)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-ppc64le-linux-multistage` running on `ppc64le-clang-multistage-test` while building `clang` at step 5 "ninja check 1". Full details are available at: https://lab.llvm.org/buildbot/#/builders/76/builds/2986 Here is the relevant piece of the build log for the reference ``` Step 5 (ninja check 1) failure: stage 1 checked (failure) ... [77/85] Generating POWERPC64LELinuxConfig/Asan-powerpc64le-calls-Noinst-Test [78/85] Generating ASAN_NOINST_TEST_OBJECTS.gtest-all.cc.powerpc64le-inline.o [79/85] Generating POWERPC64LELinuxConfig/Asan-powerpc64le-inline-Noinst-Test [80/85] Generating ASAN_INST_TEST_OBJECTS.gtest-all.cc.powerpc64le-calls.o [81/85] Generating POWERPC64LELinuxDynamicConfig/Asan-powerpc64le-calls-Dynamic-Test [82/85] Generating POWERPC64LELinuxConfig/Asan-powerpc64le-calls-Test [83/85] Generating ASAN_INST_TEST_OBJECTS.gtest-all.cc.powerpc64le-inline.o [84/85] Generating POWERPC64LELinuxDynamicConfig/Asan-powerpc64le-inline-Dynamic-Test [85/85] Generating POWERPC64LELinuxConfig/Asan-powerpc64le-inline-Test [1159/1165] Linking CXX executable tools/clang/unittests/Driver/ClangDriverTests FAILED: tools/clang/unittests/Driver/ClangDriverTests : && /usr/lib64/ccache/c++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -Wno-misleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG -Wl,--gc-sections tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/DistroTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/DXCModeTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/GCCVersionTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/ToolChainTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/ModuleCacheTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/MultilibBuilderTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/MultilibTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/SanitizerArgsTest.cpp.o -o tools/clang/unittests/Driver/ClangDriverTests -Wl,-rpath,/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/lib lib/libLLVMAArch64CodeGen.so.20.0git lib/libLLVMAArch64AsmParser.so.20.0git lib/libLLVMAArch64Disassembler.so.20.0git lib/libLLVMAMDGPUCodeGen.so.20.0git lib/libLLVMAMDGPUAsmParser.so.20.0git lib/libLLVMAMDGPUDisassembler.so.20.0git lib/libLLVMARMCodeGen.so.20.0git lib/libLLVMARMAsmParser.so.20.0git lib/libLLVMARMDisassembler.so.20.0git lib/libLLVMAVRCodeGen.so.20.0git lib/libLLVMAVRAsmParser.so.20.0git lib/libLLVMAVRDesc.so.20.0git lib/libLLVMAVRDisassembler.so.20.0git lib/libLLVMAVRInfo.so.20.0git lib/libLLVMBPFCodeGen.so.20.0git lib/libLLVMBPFAsmParser.so.20.0git lib/libLLVMBPFDesc.so.20.0git lib/libLLVMBPFDisassembler.so.20.0git lib/libLLVMBPFInfo.so.20.0git lib/libLLVMHexagonCodeGen.so.20.0git lib/libLLVMHexagonAsmParser.so.20.0git lib/libLLVMHexagonDisassembler.so.20.0git lib/libLLVMLanaiCodeGen.so.20.0git lib/libLLVMLanaiAsmParser.so.20.0git lib/libLLVMLanaiDisassembler.so.20.0git lib/libLLVMLoongArchCodeGen.so.20.0git lib/libLLVMLoongArchAsmParser.so.20.0git lib/libLLVMLoongArchDisassembler.so.20.0git lib/libLLVMMipsCodeGen.so.20.0git lib/libLLVMMipsAsmParser.so.20.0git lib/libLLVMMipsDesc.so.20.0git lib/libLLVMMipsDisassembler.so.20.0git lib/libLLVMMipsInfo.so.20.0git lib/libLLVMMSP430CodeGen.so.20.0git lib/libLLVMMSP430AsmParser.so.20.0git lib/libLLVMMSP430Desc.so.20.0git lib/libLLVMMSP430Disassembler.so.20.0git lib/libLLVMMSP430Info.so.20.0git lib/libLLVMNVPTXCodeGen.so.20.0git lib/libLLVMNVPTXDesc.so.20.0git lib/libLLVMNVPTXInfo.so.20.0git lib/libLLVMPowerPCCodeGen.so.20.0git lib/libLLVMPowerPCAsmParser.so.20.0git lib/libLLVMPowerPCDesc.so.20.0git lib/libLLVMPowerPCDisassembler.so.20.0git lib/libLLVMPowerPCInfo.so.20.0git lib/libLLVMRISCVCodeGen.so.20.0git lib/libLLVMRISCVAsmParser.so.20.0git lib/libLLVMRISCVDisassembler.so.20.0git lib/libLLVMSparcCodeGen.so.20.0git lib/libLLVMSparcAsmParser.so.20.0git lib/libLLVMSparcDesc.so.20.0git lib/libLLVMSparcDisassembler.so.20.0git lib/libLLVMSparcInfo.so.20.0git lib/libLLVMSystemZCodeGen.so.20.0git lib/libLLVMSystemZAsmParser.so.20.0git lib/libLLVMSystemZDisassembler.so.20.0git lib/libLLVMVECodeGen.so.20.0git lib/libLLVMVEAsmParser.so.20.0git lib/libLLVMVEDesc.so.20.0git lib/libLLVMVEDisassembler.so.20.0git lib/libLLVMVEInfo.so.20.0git lib/libLLVMWebAssembly
[clang] [Driver] Add toolchain for X86_64 UEFI target (PR #76838)
bhandarkar-pranav wrote: Hi @Prabhuk, I am seeing this issue https://github.com/llvm/llvm-project/issues/109328 after this PR. Here is a proposed [fix](https://github.com/llvm/llvm-project/pull/109329). Could you please check? https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] - Add libclangSerialization to clang driver unittests (PR #109329)
https://github.com/bhandarkar-pranav edited https://github.com/llvm/llvm-project/pull/109329 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] - Add libclangSerialization to clang driver unittests (PR #109329)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: Pranav Bhandarkar (bhandarkar-pranav) Changes This PR is a fix for issue [#109328](https://github.com/llvm/llvm-project/issues/109328). libclangSerializaton.so is needed for building clang driver unittests after https://github.com/llvm/llvm-project/pull/76838 was merged. --- Full diff: https://github.com/llvm/llvm-project/pull/109329.diff 1 Files Affected: - (modified) clang/unittests/Driver/CMakeLists.txt (+1) ``diff diff --git a/clang/unittests/Driver/CMakeLists.txt b/clang/unittests/Driver/CMakeLists.txt index 752037f78fb147..efdd07ea238890 100644 --- a/clang/unittests/Driver/CMakeLists.txt +++ b/clang/unittests/Driver/CMakeLists.txt @@ -22,4 +22,5 @@ clang_target_link_libraries(ClangDriverTests clangDriver clangBasic clangFrontend # For TextDiagnosticPrinter. + clangSerialization ) `` https://github.com/llvm/llvm-project/pull/109329 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] - Add libclangSerialization to clang driver unittests (PR #109329)
https://github.com/bhandarkar-pranav created https://github.com/llvm/llvm-project/pull/109329 This PR is a fix for issue [#109328](https://github.com/llvm/llvm-project/issues/109328). libclangSerializaton.so is needed for building clang driver unittests after https://github.com/llvm/llvm-project/pull/76838 was merged. >From e81b6f5ad0ad987a8b6478d19335cc428f3fa635 Mon Sep 17 00:00:00 2001 From: Pranav Bhandarkar Date: Thu, 19 Sep 2024 15:16:18 -0500 Subject: [PATCH] [Clang] - Add libclangSerialization to clang driver unittests This PR is a fix for issue #109328. libclangSerializaton.so is needed for building clang driver unittests after https://github.com/llvm/llvm-project/pull/76838 was merged. --- clang/unittests/Driver/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/unittests/Driver/CMakeLists.txt b/clang/unittests/Driver/CMakeLists.txt index 752037f78fb147..efdd07ea238890 100644 --- a/clang/unittests/Driver/CMakeLists.txt +++ b/clang/unittests/Driver/CMakeLists.txt @@ -22,4 +22,5 @@ clang_target_link_libraries(ClangDriverTests clangDriver clangBasic clangFrontend # For TextDiagnosticPrinter. + clangSerialization ) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][OpenMP] Add codegen for scope directive (PR #109197)
https://github.com/ddpagan closed https://github.com/llvm/llvm-project/pull/109197 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevented assertion failure by handling integral to boolean conversions for boolean vectors (PR #108657)
@@ -51,6 +53,9 @@ static void test(void) { ivec4 -= ivec4; ivec4 |= ivec4; ivec4 += ptr; // expected-error {{cannot convert between vector and non-scalar values ('int4' (vector of 4 'int' values) and 'int *')}} + +bvec4 != 0; // expected-warning {{inequality comparison result unused}} \ a-tarasyuk wrote: @AaronBallman Thanks for the review, and I'm sorry for the confusion. There was a typo — the type should be `_Bool`. I've changed it to the appropriate type now. https://github.com/llvm/llvm-project/pull/108657 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] riscv: Support -mstack-protector-guard=tls (PR #108942)
@@ -3664,12 +3680,18 @@ static void RenderSSPOptions(const Driver &D, const ToolChain &TC, << A->getOption().getName() << Value; return; } +if (EffectiveTriple.isRISCV() && (Offset <= -2048 || Offset >= 2048)) { keith-packard wrote: Done, and new bits pushed. https://github.com/llvm/llvm-project/pull/108942 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] riscv: Support -mstack-protector-guard=tls (PR #108942)
@@ -3644,13 +3645,28 @@ static void RenderSSPOptions(const Driver &D, const ToolChain &TC, << A->getOption().getName() << Value << "sysreg global"; return; } +if (EffectiveTriple.isRISCV()) { + if (Value != "tls" && Value != "global") { +D.Diag(diag::err_drv_invalid_value_with_suggestion) +<< A->getOption().getName() << Value << "tls global"; +return; + } + if (Value == "tls") { keith-packard wrote: Could probably be, but I felt it would be easier to review if I didn't attempt to refactor the code at the same time new functionality was being added. https://github.com/llvm/llvm-project/pull/108942 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] riscv: Support -mstack-protector-guard=tls (PR #108942)
@@ -3644,13 +3645,28 @@ static void RenderSSPOptions(const Driver &D, const ToolChain &TC, << A->getOption().getName() << Value << "sysreg global"; return; } +if (EffectiveTriple.isRISCV()) { + if (Value != "tls" && Value != "global") { keith-packard wrote: Yeah, I went for the easiest-to-review mechanism that just created new RISC-V specific clauses instead of attempting to mix them into the existing ones. It's not exactly a performance-critical area of code. https://github.com/llvm/llvm-project/pull/108942 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] ac66469 - [clang] Tidy uses of raw_string_ostream (NFC)
Author: Youngsuk Kim Date: 2024-09-19T14:56:45-05:00 New Revision: ac664697c54cf2ffa9ebef0215f734bcca3b718f URL: https://github.com/llvm/llvm-project/commit/ac664697c54cf2ffa9ebef0215f734bcca3b718f DIFF: https://github.com/llvm/llvm-project/commit/ac664697c54cf2ffa9ebef0215f734bcca3b718f.diff LOG: [clang] Tidy uses of raw_string_ostream (NFC) As specified in the docs, 1) raw_string_ostream is always unbuffered and 2) the underlying buffer may be used directly ( 65b13610a5226b84889b923bae884ba395ad084d for further reference ) * Don't call raw_string_ostream::flush(), which is essentially a no-op. * Avoid unneeded calls to raw_string_ostream::str(), to avoid excess indirection. Added: Modified: clang/lib/ExtractAPI/DeclarationFragments.cpp clang/lib/Frontend/ChainedIncludesSource.cpp clang/lib/Frontend/CompilerInstance.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Frontend/Rewrite/RewriteObjC.cpp clang/lib/StaticAnalyzer/Checkers/OSObjectCStyleCast.cpp clang/lib/StaticAnalyzer/Checkers/ObjCSuperDeallocChecker.cpp clang/lib/StaticAnalyzer/Checkers/PointerIterationChecker.cpp clang/lib/StaticAnalyzer/Core/BugReporter.cpp clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp Removed: diff --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp b/clang/lib/ExtractAPI/DeclarationFragments.cpp index 06ce5ed6a64756..9cb45c8fbf9cbc 100644 --- a/clang/lib/ExtractAPI/DeclarationFragments.cpp +++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp @@ -1110,7 +1110,6 @@ DeclarationFragmentsBuilder::getFragmentsForTemplateArguments( Spelling.clear(); raw_string_ostream OutStream(Spelling); CTA.print(Context.getPrintingPolicy(), OutStream, false); - OutStream.flush(); } } diff --git a/clang/lib/Frontend/ChainedIncludesSource.cpp b/clang/lib/Frontend/ChainedIncludesSource.cpp index c1a9f25a8798c7..a7096e27796a0a 100644 --- a/clang/lib/Frontend/ChainedIncludesSource.cpp +++ b/clang/lib/Frontend/ChainedIncludesSource.cpp @@ -159,7 +159,7 @@ IntrusiveRefCntPtr clang::createChainedIncludesSource( std::string pchName = includes[i-1]; llvm::raw_string_ostream os(pchName); os << ".pch" << i-1; - serialBufNames.push_back(os.str()); + serialBufNames.push_back(pchName); IntrusiveRefCntPtr Reader; Reader = createASTReader( diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 5a273474f1d6b6..5f2a9637e3ea46 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1383,7 +1383,6 @@ static bool compileModule(CompilerInstance &ImportingInstance, std::string InferredModuleMapContent; llvm::raw_string_ostream OS(InferredModuleMapContent); Module->print(OS); -OS.flush(); Result = compileModuleImpl( ImportingInstance, ImportLoc, Module->getTopLevelModuleName(), diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 32628c5e84332d..de6776b3f9da1a 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -817,7 +817,6 @@ static bool RoundTrip(ParseFn Parse, GenerateFn Generate, llvm::sys::printArg(OS, Arg, /*Quote=*/true); OS << ' '; } -OS.flush(); return Buffer; }; @@ -1186,7 +1185,6 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args, os << " "; os << Args.getArgString(i); } - os.flush(); return Diags.getNumErrors() == NumErrorsBefore; } @@ -3735,7 +3733,7 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts, llvm::interleave( Opts.OMPTargetTriples, OS, [&OS](const llvm::Triple &T) { OS << T.str(); }, ","); -GenerateArg(Consumer, OPT_fopenmp_targets_EQ, OS.str()); +GenerateArg(Consumer, OPT_fopenmp_targets_EQ, Targets); } if (!Opts.OMPHostIRFile.empty()) diff --git a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp index fd5e8dc5298950..f3afb3e5e83acd 100644 --- a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp +++ b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp @@ -221,10 +221,9 @@ namespace { return; } // Get the new text. - std::string SStr; - llvm::raw_string_ostream S(SStr); + std::string Str; + llvm::raw_string_ostream S(Str); New->printPretty(S, nullptr, PrintingPolicy(LangOpts)); - const std::string &Str = S.str(); // If replacement succeeded or warning disabled return with no warning. if (!Rewrite.ReplaceText(SrcRange.getBegin(), Size, Str)) { @@ -1702,7 +1701,7 @@ Stmt *RewriteObjC::RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S) { llvm::raw_string_ostream syncExprBuf(syncExprBufS); assert(syncExp
[clang] [llvm] [X86][AVX10.2] Support AVX10.2 MOVZXC new Instructions. (PR #108537)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-s390x-linux-lnt` running on `systemz-1` while building `clang,llvm` at step 7 "ninja check 1". Full details are available at: https://lab.llvm.org/buildbot/#/builders/136/builds/960 Here is the relevant piece of the build log for the reference ``` Step 7 (ninja check 1) failure: stage 1 checked (failure) TEST 'libFuzzer-s390x-default-Linux :: fuzzer-timeout.test' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/TimeoutTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest + /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/TimeoutTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest RUN: at line 2: /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/TimeoutEmptyTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutEmptyTest + /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/TimeoutEmptyTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutEmptyTest RUN: at line 3: not /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 2>&1 | FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test --check-prefix=TimeoutTest + FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test --check-prefix=TimeoutTest + not /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 RUN: at line 12: not /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/hi.txt 2>&1 | FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test --check-prefix=SingleInputTimeoutTest + not /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/hi.txt + FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test --check-prefix=SingleInputTimeoutTest RUN: at line 16: /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 -timeout_exitcode=0 + /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 -timeout_exitcode=0 INFO: Running with entropic power schedule (0xFF, 100). INFO: Seed: 8157
[clang] [HLSL] Array by-value assignment (PR #109323)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Sarah Spall (spall) Changes Make Constant Arrays in HLSL assignable. Closes #109043 --- Full diff: https://github.com/llvm/llvm-project/pull/109323.diff 6 Files Affected: - (modified) clang/include/clang/AST/CanonicalType.h (+1) - (modified) clang/lib/AST/ExprClassification.cpp (+2-1) - (modified) clang/lib/Sema/SemaOverload.cpp (+8-3) - (added) clang/test/AST/HLSL/ArrayAssignable.hlsl (+80) - (added) clang/test/CodeGenHLSL/ArrayAssignable.hlsl (+50) - (added) clang/test/SemaHLSL/ArrayAssignable_errors.hlsl (+29) ``diff diff --git a/clang/include/clang/AST/CanonicalType.h b/clang/include/clang/AST/CanonicalType.h index dde08f0394c98d..6102eb01793530 100644 --- a/clang/include/clang/AST/CanonicalType.h +++ b/clang/include/clang/AST/CanonicalType.h @@ -299,6 +299,7 @@ class CanProxyBase { LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isDependentType) LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isOverloadableType) LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isArrayType) + LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isConstantArrayType) LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasPointerRepresentation) LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasObjCPointerRepresentation) LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasIntegerRepresentation) diff --git a/clang/lib/AST/ExprClassification.cpp b/clang/lib/AST/ExprClassification.cpp index 5dde923312698f..9d97633309ada2 100644 --- a/clang/lib/AST/ExprClassification.cpp +++ b/clang/lib/AST/ExprClassification.cpp @@ -704,7 +704,8 @@ static Cl::ModifiableType IsModifiable(ASTContext &Ctx, const Expr *E, return Cl::CM_ConstAddrSpace; // Arrays are not modifiable, only their elements are. - if (CT->isArrayType()) + if (CT->isArrayType() && + !(Ctx.getLangOpts().HLSL && CT->isConstantArrayType())) return Cl::CM_ArrayType; // Incomplete types are not modifiable. if (CT->isIncompleteType()) diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index d304f322aced64..ce503f9c69b411 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -2232,16 +2232,21 @@ static bool IsStandardConversion(Sema &S, Expr* From, QualType ToType, // just strip the qualifiers because they don't matter. FromType = FromType.getUnqualifiedType(); } else if (S.getLangOpts().HLSL && FromType->isConstantArrayType() && - ToType->isArrayParameterType()) { + ToType->isConstantArrayType()) { // HLSL constant array parameters do not decay, so if the argument is a // constant array and the parameter is an ArrayParameterType we have special // handling here. -FromType = S.Context.getArrayParameterType(FromType); +if (ToType->isArrayParameterType()) { + FromType = S.Context.getArrayParameterType(FromType); + SCS.First = ICK_HLSL_Array_RValue; +} else { + SCS.First = ICK_Identity; +} + if (S.Context.getCanonicalType(FromType) != S.Context.getCanonicalType(ToType)) return false; -SCS.First = ICK_HLSL_Array_RValue; SCS.setAllToTypes(ToType); return true; } else if (FromType->isArrayType()) { diff --git a/clang/test/AST/HLSL/ArrayAssignable.hlsl b/clang/test/AST/HLSL/ArrayAssignable.hlsl new file mode 100644 index 00..52c9918aa85334 --- /dev/null +++ b/clang/test/AST/HLSL/ArrayAssignable.hlsl @@ -0,0 +1,80 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump %s | FileCheck %s + +// CHECK-LABEL: arr_assign1 +// CHECK: CompoundStmt 0x{{[0-9a-f]+}} {{.*}} +// CHECK: DeclStmt 0x{{[0-9a-f]+}} {{.*}} +// CHECK: VarDecl [[A:0x[0-9a-f]+]] {{.*}} col:7 used Arr 'int[2]' cinit +// CHECK: InitListExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]' +// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 0 +// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 1 +// CHECK: DeclStmt 0x{{[0-9a-f]+}} {{.*}} +// CHECK: VarDecl [[B:0x[0-9a-f]+]] {{.*}} col:7 used Arr2 'int[2]' cinit +// CHECK: InitListExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]' +// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 0 +// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 0 +// CHECK: BinaryOperator 0x{{[0-9a-f]+}} {{.*}} 'int[2]' lvalue '=' +// CHECK: DeclRefExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]' lvalue Var [[A]] 'Arr' 'int[2]' +// CHECK: DeclRefExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]' lvalue Var [[B]] 'Arr2' 'int[2]' +void arr_assign1() { + int Arr[2] = {0, 1}; + int Arr2[2] = {0, 0}; + Arr = Arr2; +} + +// CHECK-LABEL: arr_assign2 +// CHECK: CompoundStmt 0x{{[0-9a-f]+}} {{.*}} +// CHECK: DeclStmt 0x{{[0-9a-f]+}} {{.*}} +// CHECK: VarDecl [[A:0x[0-9a-f]+]] {{.*}} col:7 used Arr 'int[2]' cinit +// CHECK: InitListExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]' +// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 0 +// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 1 +// CHECK: DeclStmt 0x{{[0-9a-f]+}} {{.*}} +// CHECK: VarDecl [[B:0x[0-9a-f]+
[clang] [HLSL] Array by-value assignment (PR #109323)
https://github.com/spall created https://github.com/llvm/llvm-project/pull/109323 Make Constant Arrays in HLSL assignable. Closes #109043 >From b24aed9771a415a4dc896c48cfc0481574a0773c Mon Sep 17 00:00:00 2001 From: Sarah Spall Date: Wed, 18 Sep 2024 22:19:07 + Subject: [PATCH 1/2] enable array by value assignment --- clang/include/clang/AST/CanonicalType.h | 1 + clang/lib/AST/ExprClassification.cpp| 3 ++- clang/lib/Sema/SemaOverload.cpp | 11 --- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/AST/CanonicalType.h b/clang/include/clang/AST/CanonicalType.h index dde08f0394c98d..6102eb01793530 100644 --- a/clang/include/clang/AST/CanonicalType.h +++ b/clang/include/clang/AST/CanonicalType.h @@ -299,6 +299,7 @@ class CanProxyBase { LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isDependentType) LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isOverloadableType) LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isArrayType) + LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isConstantArrayType) LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasPointerRepresentation) LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasObjCPointerRepresentation) LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, hasIntegerRepresentation) diff --git a/clang/lib/AST/ExprClassification.cpp b/clang/lib/AST/ExprClassification.cpp index 5dde923312698f..9d97633309ada2 100644 --- a/clang/lib/AST/ExprClassification.cpp +++ b/clang/lib/AST/ExprClassification.cpp @@ -704,7 +704,8 @@ static Cl::ModifiableType IsModifiable(ASTContext &Ctx, const Expr *E, return Cl::CM_ConstAddrSpace; // Arrays are not modifiable, only their elements are. - if (CT->isArrayType()) + if (CT->isArrayType() && + !(Ctx.getLangOpts().HLSL && CT->isConstantArrayType())) return Cl::CM_ArrayType; // Incomplete types are not modifiable. if (CT->isIncompleteType()) diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index d304f322aced64..ce503f9c69b411 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -2232,16 +2232,21 @@ static bool IsStandardConversion(Sema &S, Expr* From, QualType ToType, // just strip the qualifiers because they don't matter. FromType = FromType.getUnqualifiedType(); } else if (S.getLangOpts().HLSL && FromType->isConstantArrayType() && - ToType->isArrayParameterType()) { + ToType->isConstantArrayType()) { // HLSL constant array parameters do not decay, so if the argument is a // constant array and the parameter is an ArrayParameterType we have special // handling here. -FromType = S.Context.getArrayParameterType(FromType); +if (ToType->isArrayParameterType()) { + FromType = S.Context.getArrayParameterType(FromType); + SCS.First = ICK_HLSL_Array_RValue; +} else { + SCS.First = ICK_Identity; +} + if (S.Context.getCanonicalType(FromType) != S.Context.getCanonicalType(ToType)) return false; -SCS.First = ICK_HLSL_Array_RValue; SCS.setAllToTypes(ToType); return true; } else if (FromType->isArrayType()) { >From a81247d0992a3fb2376a9b3dc60e5fbfd782ffbf Mon Sep 17 00:00:00 2001 From: Sarah Spall Date: Thu, 19 Sep 2024 19:33:39 + Subject: [PATCH 2/2] test assignable arrays --- clang/test/AST/HLSL/ArrayAssignable.hlsl | 80 +++ clang/test/CodeGenHLSL/ArrayAssignable.hlsl | 50 .../test/SemaHLSL/ArrayAssignable_errors.hlsl | 29 +++ 3 files changed, 159 insertions(+) create mode 100644 clang/test/AST/HLSL/ArrayAssignable.hlsl create mode 100644 clang/test/CodeGenHLSL/ArrayAssignable.hlsl create mode 100644 clang/test/SemaHLSL/ArrayAssignable_errors.hlsl diff --git a/clang/test/AST/HLSL/ArrayAssignable.hlsl b/clang/test/AST/HLSL/ArrayAssignable.hlsl new file mode 100644 index 00..52c9918aa85334 --- /dev/null +++ b/clang/test/AST/HLSL/ArrayAssignable.hlsl @@ -0,0 +1,80 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump %s | FileCheck %s + +// CHECK-LABEL: arr_assign1 +// CHECK: CompoundStmt 0x{{[0-9a-f]+}} {{.*}} +// CHECK: DeclStmt 0x{{[0-9a-f]+}} {{.*}} +// CHECK: VarDecl [[A:0x[0-9a-f]+]] {{.*}} col:7 used Arr 'int[2]' cinit +// CHECK: InitListExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]' +// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 0 +// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 1 +// CHECK: DeclStmt 0x{{[0-9a-f]+}} {{.*}} +// CHECK: VarDecl [[B:0x[0-9a-f]+]] {{.*}} col:7 used Arr2 'int[2]' cinit +// CHECK: InitListExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]' +// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 0 +// CHECK: IntegerLiteral 0x{{[0-9a-f]+}} {{.*}} 'int' 0 +// CHECK: BinaryOperator 0x{{[0-9a-f]+}} {{.*}} 'int[2]' lvalue '=' +// CHECK: DeclRefExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]' lvalue Var [[A]] 'Arr' 'int[2]' +// CHECK: DeclRefExpr 0x{{[0-9a-f]+}} {{.*}} 'int[2]' lvalue Var [[B]] 'Arr2' '
[clang] [clang-tools-extra] [llvm] Remove clang-rename (PR #108988)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-ppc64-aix` running on `aix-ppc64` while building `clang-tools-extra,clang,llvm,utils` at step 3 "clean-build-dir". Full details are available at: https://lab.llvm.org/buildbot/#/builders/64/builds/1020 Here is the relevant piece of the build log for the reference ``` Step 3 (clean-build-dir) failure: Delete failed. (failure) (timed out) Step 6 (test-build-unified-tree-check-all) failure: test (failure) TEST 'Clang :: ClangScanDeps/verbose.test' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: rm -rf /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp + rm -rf /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp RUN: at line 2: split-file /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/ClangScanDeps/verbose.test /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp + split-file /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/ClangScanDeps/verbose.test /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp RUN: at line 3: sed -e "s|DIR|/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp|g" /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp/cdb.json.in > /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp/cdb.json + sed -e 's|DIR|/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp|g' /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp/cdb.json.in RUN: at line 5: /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/bin/clang-scan-deps -compilation-database /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp/cdb.json -v -o /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp/result.json 2>&1 | /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/bin/FileCheck /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/ClangScanDeps/verbose.test + /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/bin/clang-scan-deps -compilation-database /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp/cdb.json -v -o /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp/result.json + /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/bin/FileCheck /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/ClangScanDeps/verbose.test /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/ClangScanDeps/verbose.test:6:11: error: CHECK: expected string not found in input // CHECK: *** Virtual File System Stats: ^ :1:1: note: scanning from here PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. ^ :1:8: note: possible intended match here PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. ^ Input file: Check file: /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/ClangScanDeps/verbose.test -dump-input=help explains the following input dump. Input was: << 1: PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. check:6'0 X~~~ error: no match found check:6'1? possible intended match >> -- ``` https://github.com/llvm/llvm-project/pull/108988 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)
@@ -74,6 +74,22 @@ C++ Specific Potentially Breaking Changes template void f(); +- During constant evaluation, comparisons between different evaluations of the + same string literal are now correctly treated as non-constant, and comparisons + between string literals that cannot possibly overlap in memory are now treated + as constant. zygoloid wrote: Done. https://github.com/llvm/llvm-project/pull/109208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)
https://github.com/zygoloid updated https://github.com/llvm/llvm-project/pull/109208 >From 81193568c17a89f6cf42f43a82fb1fbf0f90184d Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 18 Sep 2024 21:59:56 + Subject: [PATCH 01/11] Implement current CWG direction for string literal comparisons. Track the identity of each string literal object produced by evaluation with a global version number. Accept comparisons between literals of the same version, and between literals of different versions that cannot possibly be placed in overlapping storage. Treat the remaining comparisons as non-constant. --- clang/include/clang/AST/ASTContext.h | 11 ++ .../include/clang/Basic/DiagnosticASTKinds.td | 2 + clang/lib/AST/ExprConstant.cpp| 119 +++--- clang/test/AST/ByteCode/builtin-functions.cpp | 3 +- clang/test/AST/ByteCode/cxx20.cpp | 20 ++- clang/test/SemaCXX/builtins.cpp | 2 +- .../SemaCXX/constant-expression-cxx11.cpp | 36 -- 7 files changed, 154 insertions(+), 39 deletions(-) diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index b65a1f7dff5bc1..6170bcd4f15ae3 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -324,6 +324,13 @@ class ASTContext : public RefCountedBase { /// This is lazily created. This is intentionally not serialized. mutable llvm::StringMap StringLiteralCache; + /// The next string literal "version" to allocate during constant evaluation. + /// This is used to distinguish between repeated evaluations of the same + /// string literal. + /// + /// TODO: Ensure version numbers don't collide when deserialized. + unsigned NextStringLiteralVersion = 0; + /// MD5 hash of CUID. It is calculated when first used and cached by this /// data member. mutable std::string CUIDHash; @@ -3278,6 +3285,10 @@ class ASTContext : public RefCountedBase { /// PredefinedExpr to cache evaluated results. StringLiteral *getPredefinedStringLiteralFromCache(StringRef Key) const; + /// Return the next version number to be used for a string literal evaluated + /// as part of constant evaluation. + unsigned getNextStringLiteralVersion() { return NextStringLiteralVersion++; } + /// Return a declaration for the global GUID object representing the given /// GUID value. MSGuidDecl *getMSGuidDecl(MSGuidDeclParts Parts) const; diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td b/clang/include/clang/Basic/DiagnosticASTKinds.td index 21a307d1e89878..76e693f6b4a6ca 100644 --- a/clang/include/clang/Basic/DiagnosticASTKinds.td +++ b/clang/include/clang/Basic/DiagnosticASTKinds.td @@ -96,6 +96,8 @@ def note_constexpr_pointer_constant_comparison : Note< "at runtime">; def note_constexpr_literal_comparison : Note< "comparison of addresses of literals has unspecified value">; +def note_constexpr_opaque_call_comparison : Note< + "comparison against opaque constant has unspecified value">; def note_constexpr_pointer_weak_comparison : Note< "comparison against address of weak declaration '%0' can only be performed " "at runtime">; diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 6387e375dda79c..d9384a7c125a82 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -54,8 +54,10 @@ #include "clang/Basic/DiagnosticSema.h" #include "clang/Basic/TargetInfo.h" #include "llvm/ADT/APFixedPoint.h" +#include "llvm/ADT/Sequence.h" #include "llvm/ADT/SmallBitVector.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Debug.h" #include "llvm/Support/SaveAndRestore.h" #include "llvm/Support/SipHash.h" @@ -2061,8 +2063,8 @@ static bool EvaluateIgnoredValue(EvalInfo &Info, const Expr *E) { return true; } -/// Should this call expression be treated as a no-op? -static bool IsNoOpCall(const CallExpr *E) { +/// Should this call expression be treated as forming an opaque constant? +static bool IsOpaqueConstantCall(const CallExpr *E) { unsigned Builtin = E->getBuiltinCallee(); return (Builtin == Builtin::BI__builtin___CFStringMakeConstantString || Builtin == Builtin::BI__builtin___NSStringMakeConstantString || @@ -2070,6 +2072,12 @@ static bool IsNoOpCall(const CallExpr *E) { Builtin == Builtin::BI__builtin_function_start); } +static bool IsOpaqueConstantCall(const LValue &LVal) { + auto *BaseExpr = + llvm::dyn_cast_or_null(LVal.Base.dyn_cast()); + return BaseExpr && IsOpaqueConstantCall(BaseExpr); +} + static bool IsGlobalLValue(APValue::LValueBase B) { // C++11 [expr.const]p3 An address constant expression is a prvalue core // constant expression of pointer type that evaluates to... @@ -2115,7 +2123,7 @@ static bool IsGlobalLValue(APValue::LValueBase B) { case Expr::ObjCBoxedExprClass: return cast(E)->isExpressibleAsConstantInitializer(); c
[clang-tools-extra] [clang-tools-extra] Fix add_clang_library usage (PR #109321)
https://github.com/fsfod updated https://github.com/llvm/llvm-project/pull/109321 >From 41cfaf1dff9b47c3bb6755290aa23bedb80c9ef2 Mon Sep 17 00:00:00 2001 From: Thomas Fransham Date: Thu, 19 Sep 2024 16:53:20 +0100 Subject: [PATCH] [clang-tools-extra] Fix add_clang_library usage If a add_clang_library call doesn't specify building as STATIC or SHARED library they are implicitly added to the list static libraries that is linked in to clang-cpp shared library. Because the clang-tools-extra libraries targets were declared after clang-cpp they by luck never got linked to clang-cpp. This change is required for clang symbol visibility macros on windows to work correctly for clang tools since we need to distinguish if a target being built will be importing or exporting clang symbols from the clang-cpp DLL. --- clang-tools-extra/clang-apply-replacements/CMakeLists.txt | 2 +- clang-tools-extra/clang-change-namespace/CMakeLists.txt | 2 +- clang-tools-extra/clang-doc/CMakeLists.txt| 2 +- clang-tools-extra/clang-include-fixer/CMakeLists.txt | 2 +- .../clang-include-fixer/find-all-symbols/CMakeLists.txt | 2 +- clang-tools-extra/clang-include-fixer/plugin/CMakeLists.txt | 2 +- clang-tools-extra/clang-move/CMakeLists.txt | 2 +- clang-tools-extra/clang-query/CMakeLists.txt | 2 +- clang-tools-extra/clang-reorder-fields/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/abseil/CMakeLists.txt| 2 +- clang-tools-extra/clang-tidy/altera/CMakeLists.txt| 2 +- clang-tools-extra/clang-tidy/android/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/boost/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/cert/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/darwin/CMakeLists.txt| 2 +- clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/google/CMakeLists.txt| 2 +- clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/linuxkernel/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/llvm/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/misc/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/modernize/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/mpi/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/objc/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/openmp/CMakeLists.txt| 2 +- clang-tools-extra/clang-tidy/performance/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/plugin/CMakeLists.txt| 2 +- clang-tools-extra/clang-tidy/portability/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/readability/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/tool/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/utils/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/zircon/CMakeLists.txt| 2 +- clang-tools-extra/clangd/CMakeLists.txt | 2 +- clang-tools-extra/clangd/index/remote/CMakeLists.txt | 2 +- .../clangd/index/remote/marshalling/CMakeLists.txt| 2 +- .../clangd/index/remote/unimplemented/CMakeLists.txt | 2 +- clang-tools-extra/clangd/support/CMakeLists.txt | 2 +- clang-tools-extra/clangd/tool/CMakeLists.txt | 2 +- clang-tools-extra/clangd/xpc/CMakeLists.txt | 4 ++-- clang-tools-extra/include-cleaner/lib/CMakeLists.txt | 2 +- 45 files changed, 46 insertions(+), 46 deletions(-) diff --git a/clang-tools-extra/clang-apply-replacements/CMakeLists.txt b/clang-tools-extra/clang-apply-replacements/CMakeLists.txt index 93198ccbfc406f..551ded903e88a6 100644 --- a/clang-tools-extra/clang-apply-replacements/CMakeLists.txt +++ b/clang-tools-extra/clang-apply-replacements/CMakeLists.txt @@ -2,7 +2,7 @@ set(LLVM_LINK_COMPONENTS Support ) -add_clang_library(clangApplyReplacements +add_clang_library(clangApplyReplacements STATIC lib/Tooling/ApplyReplacements.cpp DEPENDS diff --git a/clang-tools-extra/clang-change-namespace/CMakeLists.txt b/clang-tools-extra/clang-change-namespace/CMakeLists.txt index ded91edb8e34f0..62289ad031cfd6 100644 --- a/clang-tools-extra/clang-change-namespace/CMakeLists.txt +++ b/clang-tools-extra/clang-change-namespace/CMakeLists.txt @@ -3,7 +3,7 @@ set(LLVM_LINK_COMPONENTS Support ) -add_clang_library(clangChangeNamespace +add_clang_library(clangChangeNamespace STATIC ChangeNamespace.cpp
[clang-tools-extra] [clang-tools-extra] Fix add_clang_library usage (PR #109321)
llvmbot wrote: @llvm/pr-subscribers-clangd Author: Thomas Fransham (fsfod) Changes If a add_clang_library call doesn't specify building as static or shared library they are implicitly added to the list static libraries that is linked in to clang-cpp shared library here. https://github.com/llvm/llvm-project/blob/315ba7740663208f8bc45a7e4f145dc1df79500c/clang/cmake/modules/AddClang.cmake#L107 Because the clang-tools-extra libraries targets were declared after clang-cpp they by luck never got linked to clang-cpp. This change is required for clang symbol visibility macros on windows to work correctly for clang tools since we need to distinguish if a target being built will be importing or exporting clang symbols from the clang-cpp DLL. --- Patch is 24.51 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/109321.diff 49 Files Affected: - (modified) clang-tools-extra/clang-apply-replacements/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-change-namespace/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-doc/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-include-fixer/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-include-fixer/find-all-symbols/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-include-fixer/plugin/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-move/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-query/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-reorder-fields/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/abseil/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/altera/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/android/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/boost/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/cert/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/darwin/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/google/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/linuxkernel/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/llvm/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/misc/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/modernize/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/mpi/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/objc/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/openmp/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/performance/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/plugin/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/portability/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/readability/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/tool/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/utils/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clang-tidy/zircon/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clangd/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clangd/index/remote/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clangd/index/remote/marshalling/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clangd/index/remote/unimplemented/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clangd/support/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clangd/tool/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/clangd/xpc/CMakeLists.txt (+2-2) - (modified) clang-tools-extra/include-cleaner/lib/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/pseudo/lib/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/pseudo/lib/cli/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt (+1-1) - (modified) clang-tools-extra/pseudo/lib/grammar/CMakeLists.txt (+1-1) ``diff diff --git a/clang-tools-extra/clang-apply-replacements/CMakeLists.txt b/clang-tools-extra/clang-apply-replacements/CMakeLists.txt index 93198ccbfc406f..551ded903e88a6 100644 --- a/clang-tools-extra/clang-apply-replacements/CMakeLists.txt +++ b/clang-tools-extra/clang-apply-replacements/CMakeLists.txt @@ -2,7 +2,7 @@ set(LLVM_LINK_COMPONENTS Support ) -add_clang_library(clangApplyReplacements +add_clang_library(clangApplyReplacements STATIC lib/Tooling/ApplyReplacements.cpp DEPENDS di
[clang-tools-extra] [clang-tools-extra] Fix add_clang_library usage (PR #109321)
https://github.com/fsfod created https://github.com/llvm/llvm-project/pull/109321 If a add_clang_library call doesn't specify building as static or shared library they are implicitly added to the list static libraries that is linked in to clang-cpp shared library here. https://github.com/llvm/llvm-project/blob/315ba7740663208f8bc45a7e4f145dc1df79500c/clang/cmake/modules/AddClang.cmake#L107 Because the clang-tools-extra libraries targets were declared after clang-cpp they by luck never got linked to clang-cpp. This change is required for clang symbol visibility macros on windows to work correctly for clang tools since we need to distinguish if a target being built will be importing or exporting clang symbols from the clang-cpp DLL. >From 5b230bef622b76becace38d7035179314e63ea76 Mon Sep 17 00:00:00 2001 From: Thomas Fransham Date: Thu, 19 Sep 2024 16:53:20 +0100 Subject: [PATCH] [clang-tools-extra] Fix add_clang_library usage If a add_clang_library call doesn't specify building as STATIC or SHARED library they are implicitly added to the list static libraries that is linked in to clang-cpp shared library. Because the clang-tools-extra libraries targets were declared after clang-cpp they by luck never got linked to clang-cpp. This change is required for clang symbol visibility macros on windows work correctly for clang tools since we need to distinguish if a target being built will be importing or exporting clang symbols from the clang-cpp DLL. --- clang-tools-extra/clang-apply-replacements/CMakeLists.txt | 2 +- clang-tools-extra/clang-change-namespace/CMakeLists.txt | 2 +- clang-tools-extra/clang-doc/CMakeLists.txt| 2 +- clang-tools-extra/clang-include-fixer/CMakeLists.txt | 2 +- .../clang-include-fixer/find-all-symbols/CMakeLists.txt | 2 +- clang-tools-extra/clang-include-fixer/plugin/CMakeLists.txt | 2 +- clang-tools-extra/clang-move/CMakeLists.txt | 2 +- clang-tools-extra/clang-query/CMakeLists.txt | 2 +- clang-tools-extra/clang-reorder-fields/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/abseil/CMakeLists.txt| 2 +- clang-tools-extra/clang-tidy/altera/CMakeLists.txt| 2 +- clang-tools-extra/clang-tidy/android/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/boost/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/cert/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/darwin/CMakeLists.txt| 2 +- clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/google/CMakeLists.txt| 2 +- clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/linuxkernel/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/llvm/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/misc/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/modernize/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/mpi/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/objc/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/openmp/CMakeLists.txt| 2 +- clang-tools-extra/clang-tidy/performance/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/plugin/CMakeLists.txt| 2 +- clang-tools-extra/clang-tidy/portability/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/readability/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/tool/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/utils/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/zircon/CMakeLists.txt| 2 +- clang-tools-extra/clangd/CMakeLists.txt | 2 +- clang-tools-extra/clangd/index/remote/CMakeLists.txt | 2 +- .../clangd/index/remote/marshalling/CMakeLists.txt| 2 +- .../clangd/index/remote/unimplemented/CMakeLists.txt | 2 +- clang-tools-extra/clangd/support/CMakeLists.txt | 2 +- clang-tools-extra/clangd/tool/CMakeLists.txt | 2 +- clang-tools-extra/clangd/xpc/CMakeLists.txt | 4 ++-- clang-tools-extra/include-cleaner/lib/CMakeLists.txt | 2 +- clang-tools-extra/pseudo/lib/CMakeLists.txt | 2 +- clang-tools-extra/pseudo/lib/cli/CMakeLists.txt | 2 +- clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt | 2 +- clang-tools-extra/pseudo/lib/grammar/CMakeLists.txt | 2 +- 49 files changed, 50 insertions(+), 50 deletions(-) diff --git a/clang-tools-extr
[clang] [Driver] Add toolchain for X86_64 UEFI target (PR #76838)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `llvm-clang-aarch64-darwin` running on `doug-worker-4` while building `clang` at step 6 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/6103 Here is the relevant piece of the build log for the reference ``` Step 6 (test-build-unified-tree-check-all) failure: test (failure) TEST 'Clang :: Driver/uefi-constructed-args.c' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang --driver-mode=cl -### /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/uefi-constructed-args.c --target=x86_64-unknown-uefi --sysroot=/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/platform -fuse-ld=lld -g 2>&1 | /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefixes=CHECK /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/uefi-constructed-args.c + /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang --driver-mode=cl -### /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/uefi-constructed-args.c --target=x86_64-unknown-uefi --sysroot=/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/platform -fuse-ld=lld -g + /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefixes=CHECK /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/uefi-constructed-args.c [1m/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/uefi-constructed-args.c:4:11: [0m[0;1;31merror: [0m[1mCHECK: expected string not found in input [0m// CHECK: "-cc1" [0;1;32m ^ [0m[1m:1:1: [0m[0;1;30mnote: [0m[1mscanning from here [0mclang: warning: unknown argument ignored in clang-cl: '--sysroot=/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/platform' [-Wunknown-argument] [0;1;32m^ [0m[1m:1:49: [0m[0;1;30mnote: [0m[1mpossible intended match here [0mclang: warning: unknown argument ignored in clang-cl: '--sysroot=/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/platform' [-Wunknown-argument] [0;1;32m^ [0m Input file: Check file: /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/uefi-constructed-args.c -dump-input=help explains the following input dump. Input was: << [1m[0m[0;1;30m 1: [0m[1m[0;1;46mclang: warning: unknown argument ignored in clang-cl: '--sysroot=/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/platform' [-Wunknown-argument] [0m [0;1;31mcheck:4'0 X~~~ error: no match found [0m[0;1;35mcheck:4'1 ? possible intended match [0m[0;1;30m 2: [0m[1m[0;1;46mclang version 20.0.0git (https://github.com/llvm/llvm-project.git d1335fb86466221b0499db5fc8f158f1f64d9542) [0m [0;1;31mcheck:4'0 [0m[0;1;30m 3: [0m[1m[0;1;46mTarget: x86_64-unknown-uefi [0m [0;1;31mcheck:4'0 [0m[0;1;30m 4: [0m[1m[0;1;46mThread model: posix [0m [0;1;31mcheck:4'0 [0m[0;1;30m 5: [0m[1m[0;1;46mInstalledDir: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin [0m [0;1;31mcheck:4'0 ~ [0m[0;1;30m 6: [0m[1m[0;1;46mBuild config: +assertions [0m [0;1;31mcheck:4'0 ~~ [0m[0;1;30m 7: [0m[1m[0;1;46mclang: warning: '/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/uefi-constructed-args.c' treated as the '/U' option [-Wslash-u-filename] [0m [0;1;31mcheck:4'0 ~~ [0m[0;1;30m 8: [0m[1m[0;1;46mclang: note: use '--' to treat subsequent arguments as filenames [0m [0;1;31mcheck:4'0 ~ [0m[0;1;30m 9: [0m[1m[0;1;46mclang: warning: argument unused during compilation: '/U sers/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/uefi-constructed-args.c' [-Wunused-command-line
[clang] [Clang] prevented assertion failure by handling integral to boolean conversions for boolean vectors (PR #108657)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/108657 >From 70d1be2a2a0f2f44cdd70bfb4397e7a36f1c9f30 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 14 Sep 2024 01:46:28 +0300 Subject: [PATCH 1/3] [Clang] prevented assertion failure by handling integral to boolean conversions for boolean vectors --- clang/docs/ReleaseNotes.rst| 1 + clang/lib/Sema/SemaExpr.cpp| 7 ++- clang/test/Sema/ext_vector_casts.c | 5 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3929a9fb599259..e9d8d1b789506d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -386,6 +386,7 @@ Bug Fixes to C++ Support - Fixed a crash in the typo correction of an invalid CTAD guide. (#GH107887) - Fixed a crash when clang tries to subtitute parameter pack while retaining the parameter pack. #GH63819, #GH107560 +- Fixed an assertion failure by adjusting integral to boolean vector conversions (#GH108326) Bug Fixes to AST Handling diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 8f3e15cc9a9bb7..15b233212b770b 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -9868,7 +9868,12 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult *scalar, // if necessary. CastKind scalarCast = CK_NoOp; - if (vectorEltTy->isIntegralType(S.Context)) { + if (vectorEltTy->isBooleanType()) { +if (scalarTy->isIntegralType(S.Context)) + scalarCast = CK_IntegralToBoolean; +else if (!scalarTy->isBooleanType()) + return true; + } else if (vectorEltTy->isIntegralType(S.Context)) { if (S.getLangOpts().OpenCL && (scalarTy->isRealFloatingType() || (scalarTy->isIntegerType() && S.Context.getIntegerTypeOrder(vectorEltTy, scalarTy) < 0))) { diff --git a/clang/test/Sema/ext_vector_casts.c b/clang/test/Sema/ext_vector_casts.c index 48440735d88ea9..6338035a61aad6 100644 --- a/clang/test/Sema/ext_vector_casts.c +++ b/clang/test/Sema/ext_vector_casts.c @@ -11,6 +11,7 @@ typedef float t3 __attribute__ ((vector_size (16))); typedef __typeof__(sizeof(int)) size_t; typedef unsigned long ulong2 __attribute__ ((ext_vector_type(2))); typedef size_t stride4 __attribute__((ext_vector_type(4))); +typedef float bool4 __attribute__(( ext_vector_type(4) )); static void test(void) { float2 vec2; @@ -19,6 +20,7 @@ static void test(void) { int4 ivec4; short8 ish8; t3 vec4_3; +bool4 bvec4 = 0; int *ptr; int i; @@ -51,6 +53,9 @@ static void test(void) { ivec4 -= ivec4; ivec4 |= ivec4; ivec4 += ptr; // expected-error {{cannot convert between vector and non-scalar values ('int4' (vector of 4 'int' values) and 'int *')}} + +bvec4 != 0; // expected-warning {{inequality comparison result unused}} \ +// expected-note {{use '|=' to turn this inequality comparison into an or-assignment}} } typedef __attribute__(( ext_vector_type(2) )) float2 vecfloat2; // expected-error{{invalid vector element type 'float2' (vector of 2 'float' values)}} >From b7dc3966847429864fc56886370833afd40e38a5 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 17 Sep 2024 13:36:52 +0300 Subject: [PATCH 2/3] eliminate redundant logic that disallows non-boolean scalar casts --- clang/lib/Sema/SemaExpr.cpp | 7 ++- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 15b233212b770b..17dd3aeb6e3b6f 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -9868,11 +9868,8 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult *scalar, // if necessary. CastKind scalarCast = CK_NoOp; - if (vectorEltTy->isBooleanType()) { -if (scalarTy->isIntegralType(S.Context)) - scalarCast = CK_IntegralToBoolean; -else if (!scalarTy->isBooleanType()) - return true; + if (vectorEltTy->isBooleanType() && scalarTy->isIntegralType(S.Context)) { +scalarCast = CK_IntegralToBoolean; } else if (vectorEltTy->isIntegralType(S.Context)) { if (S.getLangOpts().OpenCL && (scalarTy->isRealFloatingType() || (scalarTy->isIntegerType() && >From d102f1a5db12e0066f70a3d30e467961baa6cf1f Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 19 Sep 2024 22:18:57 +0300 Subject: [PATCH 3/3] fix typo --- clang/test/Sema/ext_vector_casts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Sema/ext_vector_casts.c b/clang/test/Sema/ext_vector_casts.c index 6338035a61aad6..8bf2737e0bfab1 100644 --- a/clang/test/Sema/ext_vector_casts.c +++ b/clang/test/Sema/ext_vector_casts.c @@ -11,7 +11,7 @@ typedef float t3 __attribute__ ((vector_size (16))); typedef __typeof__(sizeof(int)) size_t; typedef unsigned long ulong2 __attribute__ ((ext_vector_type(2))); typedef size_t stride4 __attribute__((ext_vector_type(4))); -typedef
[clang] 3b3accb - [SystemZ][z/OS] Propagate IsText flag continuation
Author: Abhina Sreeskantharajan Date: 2024-09-19T15:16:08-04:00 New Revision: 3b3accb598ec87a6a30b0e18ded06071030bb78f URL: https://github.com/llvm/llvm-project/commit/3b3accb598ec87a6a30b0e18ded06071030bb78f DIFF: https://github.com/llvm/llvm-project/commit/3b3accb598ec87a6a30b0e18ded06071030bb78f.diff LOG: [SystemZ][z/OS] Propagate IsText flag continuation Added: Modified: clang/lib/Serialization/ASTReader.cpp llvm/lib/Support/FileCollector.cpp Removed: diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index ad0551ee117a97..a8d073dee0246e 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -5318,7 +5318,7 @@ std::string ASTReader::getOriginalSourceFile( // Open the AST file. auto Buffer = FileMgr.getBufferForFile(ASTFileName, /*IsVolatile=*/false, /*RequiresNullTerminator=*/false, - /*IsText=*/true); + /*IsText=*/false); if (!Buffer) { Diags.Report(diag::err_fe_unable_to_read_pch_file) << ASTFileName << Buffer.getError().message(); diff --git a/llvm/lib/Support/FileCollector.cpp b/llvm/lib/Support/FileCollector.cpp index fd4350da7f66a6..966c5ac90e9412 100644 --- a/llvm/lib/Support/FileCollector.cpp +++ b/llvm/lib/Support/FileCollector.cpp @@ -268,7 +268,7 @@ class FileCollectorFileSystem : public vfs::FileSystem { } llvm::ErrorOr> - openFileForRead(const Twine &Path, bool IsText) override { + openFileForRead(const Twine &Path, bool IsText = true) override { auto Result = FS->openFileForRead(Path, IsText); if (Result && *Result) Collector->addFile(Path); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Change Attribute plugin to link clang-cpp like other examples (PR #109319)
https://github.com/vgvassilev approved this pull request. This change looks reasonable to me. https://github.com/llvm/llvm-project/pull/109319 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)
@@ -2142,11 +2150,81 @@ static const ValueDecl *GetLValueBaseDecl(const LValue &LVal) { return LVal.Base.dyn_cast(); } -static bool IsLiteralLValue(const LValue &Value) { - if (Value.getLValueCallIndex()) +// Information about an LValueBase that is some kind of string. +struct LValueBaseString { + std::string ObjCEncodeStorage; + StringRef Bytes; + int CharWidth; +}; + +// Gets the lvalue base of LVal as a string. +static bool GetLValueBaseAsString(const EvalInfo &Info, const LValue &LVal, + LValueBaseString &AsString) { + const auto *BaseExpr = LVal.Base.dyn_cast(); + if (!BaseExpr) +return false; + + // For ObjCEncodeExpr, we need to compute and store the string. + if (const auto *EE = dyn_cast(BaseExpr)) { +Info.Ctx.getObjCEncodingForType(EE->getEncodedType(), +AsString.ObjCEncodeStorage); +AsString.Bytes = AsString.ObjCEncodeStorage; +AsString.CharWidth = 1; +return true; + } + + // Otherwise, we have a StringLiteral. + const auto *Lit = dyn_cast(BaseExpr); + if (const auto *PE = dyn_cast(BaseExpr)) +Lit = PE->getFunctionName(); + + if (!Lit) +return false; + + AsString.Bytes = Lit->getBytes(); + AsString.CharWidth = Lit->getCharByteWidth(); + return true; +} + +// Determine whether two string literals potentially overlap. This will be the +// case if they agree on the values of all the bytes on the overlapping region +// between them. +static bool ArePotentiallyOverlappingStringLiterals(const EvalInfo &Info, +const LValue &LHS, +const LValue &RHS) { + LValueBaseString LHSString, RHSString; + if (!GetLValueBaseAsString(Info, LHS, LHSString) || + !GetLValueBaseAsString(Info, RHS, RHSString)) return false; - const Expr *E = Value.Base.dyn_cast(); - return E && !isa(E); + + // This is the byte offset to the location of the first character of LHS + // within RHS. We don't need to look at the characters of one string that + // would appear before the start of the other string if they were merged. + CharUnits Offset = RHS.Offset - LHS.Offset; + if (Offset.isPositive()) { +RHSString.Bytes = RHSString.Bytes.drop_front(Offset.getQuantity()); + } else if (Offset.isNegative()) { erichkeane wrote: OH! I missed that re `LHSString` vs `RHSString`. Thanks, and definitely explains why you did it that way, thanks. https://github.com/llvm/llvm-project/pull/109208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] UEFI backend for x86_64 (PR #109320)
https://github.com/Prabhuk created https://github.com/llvm/llvm-project/pull/109320 Continuing the effort to support UEFI target as a first class citizen. The first backend I am trying to support here is x86_64. Original RFC: https://discourse.llvm.org/t/rfc-uefi-driver-support-uefi-target/73261 >From 8dec0e65bdf08bd9b1b1c63d601ae0d93584cb2d Mon Sep 17 00:00:00 2001 From: prabhukr Date: Tue, 3 Sep 2024 21:02:15 -0700 Subject: [PATCH] UEFI backend for x86_64 --- clang/lib/Basic/Targets/X86.h | 9 +++-- .../X86/MCTargetDesc/X86MCTargetDesc.cpp | 4 +- llvm/lib/Target/X86/X86CallingConv.td | 17 - llvm/lib/Target/X86/X86FrameLowering.cpp | 20 ++ llvm/lib/Target/X86/X86ISelLowering.cpp | 37 --- llvm/lib/Target/X86/X86RegisterInfo.cpp | 11 +++--- llvm/lib/Target/X86/X86RegisterInfo.h | 6 ++- llvm/lib/Target/X86/X86Subtarget.h| 15 ++-- llvm/lib/Target/X86/X86TargetMachine.cpp | 2 +- llvm/test/CodeGen/X86/mangle-question-mark.ll | 1 + llvm/test/CodeGen/X86/sse-regcall.ll | 1 + llvm/test/CodeGen/X86/win32-preemption.ll | 2 + 12 files changed, 93 insertions(+), 32 deletions(-) diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index a99ae62984c7d5..07c98d880ab778 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -826,10 +826,11 @@ class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo "i64:64-i128:128-f80:128-n8:16:32:64-S128"); } - void getTargetDefines(const LangOptions &Opts, -MacroBuilder &Builder) const override { -getOSDefines(Opts, X86TargetInfo::getTriple(), Builder); - } + // void getTargetDefines(const LangOptions &Opts, + // MacroBuilder &Builder) const override { + // getOSDefines(Opts, X86TargetInfo::getTriple(), Builder); + // Builder.defineMacro("__x86_64__"); + // } BuiltinVaListKind getBuiltinVaListKind() const override { return TargetInfo::CharPtrBuiltinVaList; diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp index fe3c42eeb6e8ec..c1baedda69c6b4 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp @@ -445,7 +445,7 @@ static MCAsmInfo *createX86MCAsmInfo(const MCRegisterInfo &MRI, // Force the use of an ELF container. MAI = new X86ELFMCAsmInfo(TheTriple); } else if (TheTriple.isWindowsMSVCEnvironment() || - TheTriple.isWindowsCoreCLREnvironment()) { + TheTriple.isWindowsCoreCLREnvironment() || TheTriple.isUEFI()) { if (Options.getAssemblyLanguage().equals_insensitive("masm")) MAI = new X86MCAsmInfoMicrosoftMASM(TheTriple); else @@ -453,8 +453,6 @@ static MCAsmInfo *createX86MCAsmInfo(const MCRegisterInfo &MRI, } else if (TheTriple.isOSCygMing() || TheTriple.isWindowsItaniumEnvironment()) { MAI = new X86MCAsmInfoGNUCOFF(TheTriple); - } else if (TheTriple.isUEFI()) { -MAI = new X86MCAsmInfoGNUCOFF(TheTriple); } else { // The default is ELF. MAI = new X86ELFMCAsmInfo(TheTriple); diff --git a/llvm/lib/Target/X86/X86CallingConv.td b/llvm/lib/Target/X86/X86CallingConv.td index 307aeb2ea4c6fd..93d84577801cd6 100644 --- a/llvm/lib/Target/X86/X86CallingConv.td +++ b/llvm/lib/Target/X86/X86CallingConv.td @@ -488,13 +488,24 @@ def RetCC_X86_64 : CallingConv<[ CCIfSubtarget<"isTargetWin64()", CCIfRegCallv4>>>, CCIfCC<"CallingConv::X86_RegCall", - CCIfSubtarget<"isTargetWin64()", +CCIfSubtarget<"isTargetUEFI64()", CCIfRegCallv4>>>, + + CCIfCC<"CallingConv::X86_RegCall", + CCIfSubtarget<"isTargetWin64()", CCDelegateTo>>, + + CCIfCC<"CallingConv::X86_RegCall", +CCIfSubtarget<"isTargetUEFI64()", + CCDelegateTo>>, + CCIfCC<"CallingConv::X86_RegCall", CCDelegateTo>, // Mingw64 and native Win64 use Win64 CC CCIfSubtarget<"isTargetWin64()", CCDelegateTo>, + // UEFI64 uses Win64 CC + CCIfSubtarget<"isTargetUEFI64()", CCDelegateTo>, + // Otherwise, drop to normal X86-64 CC CCDelegateTo ]>; @@ -1079,6 +1090,10 @@ def CC_X86_64 : CallingConv<[ CCIfSubtarget<"isTargetWin64()", CCIfRegCallv4>>>, CCIfCC<"CallingConv::X86_RegCall", CCIfSubtarget<"isTargetWin64()", CCDelegateTo>>, + CCIfCC<"CallingConv::X86_RegCall", +CCIfSubtarget<"isTargetUEFI64()", CCIfRegCallv4>>>, + CCIfCC<"CallingConv::X86_RegCall", +CCIfSubtarget<"isTargetUEFI64()", CCDelegateTo>>, CCIfCC<"CallingConv::X86_RegCall", CCDelegateTo>, CCIfCC<"CallingConv::PreserveNone", CCDelegateTo>, CCIfCC<"CallingConv::X86_INTR", CCCustom<"CC_X86_Intr">>, diff --git a/llvm/lib/Target/X86/X86FrameLowering.cpp b/llvm/lib/Target/X86/X86FrameLowering.cpp index 4f8
[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)
@@ -74,6 +74,22 @@ C++ Specific Potentially Breaking Changes template void f(); +- During constant evaluation, comparisons between different evaluations of the + same string literal are now correctly treated as non-constant, and comparisons + between string literals that cannot possibly overlap in memory are now treated + as constant. erichkeane wrote: Could you mention the CWG issue here as well? https://github.com/llvm/llvm-project/pull/109208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC] Re-sign a pointer to a noexcept member function when it is converted to a pointer to a member function without noexcept (PR #109056)
@@ -2419,8 +2419,13 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) { return Visit(const_cast(E)); case CK_NoOp: { -return CE->changesVolatileQualification() ? EmitLoadOfLValue(CE) - : Visit(const_cast(E)); +if (CE->changesVolatileQualification()) + return EmitLoadOfLValue(CE); +auto V = Visit(const_cast(E)); +if (CGF.CGM.getCodeGenOpts().PointerAuth.CXXMemberFunctionPointers && +CE->getType()->isMemberFunctionPointerType()) + V = CGF.CGM.getCXXABI().EmitMemberPointerConversion(CGF, CE, V); +return V; ahatanak wrote: I don't think there's a `CastKind` we can use in `clang/AST/OperationKinds.def`. We'll have to define a new one if we are going to stop using `NoOp`. https://github.com/llvm/llvm-project/pull/109056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits