[clang] 1bcec03 - [HIP][HIPSTDPAR][NFC] Re-order & adapt `hipstdpar` specific passes (#134753)

2025-04-14 Thread via cfe-commits

Author: Alex Voicu
Date: 2025-04-15T00:47:09+03:00
New Revision: 1bcec036e197f6ab7461722502e4393396b46ec3

URL: 
https://github.com/llvm/llvm-project/commit/1bcec036e197f6ab7461722502e4393396b46ec3
DIFF: 
https://github.com/llvm/llvm-project/commit/1bcec036e197f6ab7461722502e4393396b46ec3.diff

LOG: [HIP][HIPSTDPAR][NFC] Re-order & adapt `hipstdpar` specific passes 
(#134753)

The `hipstdpar` specific passes were not ordered ideally, especially for
`fgpu-rdc` compilations, which meant that we'd eagerly run accelerator
code selection and remove symbols that might end up used. This change
corrects that aspect by ensuring that accelerator code selection is only
done after linking (this will have to be revisited in the future once
the closed-world assumption no longer holds). Furthermore, we take the
opportunity to move allocation interposition so that it properly gets
printed when print-pipeline-passes is requested. NFC.

Added: 
clang/test/CodeGenHipStdPar/rdc-does-not-enable-hipstdpar.cpp
clang/test/CodeGenHipStdPar/select-accelerator-code-pass-ordering.cpp

Modified: 
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/HIPAMD.cpp
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7557cb8408921..f7eb853beb23c 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1115,6 +1115,10 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   if (CodeGenOpts.LinkBitcodePostopt)
 MPM.addPass(LinkInModulesPass(BC));
 
+  if (LangOpts.HIPStdPar && !LangOpts.CUDAIsDevice &&
+  LangOpts.HIPStdParInterposeAlloc)
+MPM.addPass(HipStdParAllocationInterpositionPass());
+
   // Add a verifier pass if requested. We don't have to do this if the action
   // requires code generation because there will already be a verifier pass in
   // the code-generation pipeline.
@@ -1178,10 +1182,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 return;
   }
 
-  if (LangOpts.HIPStdPar && !LangOpts.CUDAIsDevice &&
-  LangOpts.HIPStdParInterposeAlloc)
-MPM.addPass(HipStdParAllocationInterpositionPass());
-
   // Now that we have all of the passes ready, run them.
   {
 PrettyStackTraceString CrashInfo("Optimizer");

diff  --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index 4419339720b87..abda4eb453387 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -233,10 +233,11 @@ void HIPAMDToolChain::addClangTargetOptions(
   CC1Args.append({"-fcuda-is-device", "-fno-threadsafe-statics"});
 
   if (!DriverArgs.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
-  false))
+  false)) {
 CC1Args.append({"-mllvm", "-amdgpu-internalize-symbols"});
-  if (DriverArgs.hasArgNoClaim(options::OPT_hipstdpar))
-CC1Args.append({"-mllvm", "-amdgpu-enable-hipstdpar"});
+if (DriverArgs.hasArgNoClaim(options::OPT_hipstdpar))
+  CC1Args.append({"-mllvm", "-amdgpu-enable-hipstdpar"});
+  }
 
   StringRef MaxThreadsPerBlock =
   DriverArgs.getLastArgValue(options::OPT_gpu_max_threads_per_block_EQ);

diff  --git a/clang/test/CodeGenHipStdPar/rdc-does-not-enable-hipstdpar.cpp 
b/clang/test/CodeGenHipStdPar/rdc-does-not-enable-hipstdpar.cpp
new file mode 100644
index 0..f7438c374dd32
--- /dev/null
+++ b/clang/test/CodeGenHipStdPar/rdc-does-not-enable-hipstdpar.cpp
@@ -0,0 +1,17 @@
+// Check that if we are compiling with fgpu-rdc amdgpu-enable-hipstdpar is not
+// passed to CC1, to avoid eager, per TU, removal of potentially accessible
+// functions.
+
+// RUN: %clang -### --hipstdpar --offload-arch=gfx906 -nogpulib -nogpuinc %s \
+// RUN:--hipstdpar-path=%S/../Driver/Inputs/hipstdpar \
+// RUN:--hipstdpar-thrust-path=%S/../Driver/Inputs/hipstdpar/thrust \
+// RUN:--hipstdpar-prim-path=%S/../Driver/Inputs/hipstdpar/rocprim 2>&1 \
+// RUN:| FileCheck %s -check-prefix=NORDC
+// NORDC: {{.*}}"-mllvm" "-amdgpu-enable-hipstdpar"
+
+// RUN: %clang -### --hipstdpar --offload-arch=gfx906 -nogpulib -nogpuinc %s \
+// RUN:-fgpu-rdc --hipstdpar-path=%S/../Driver/Inputs/hipstdpar \
+// RUN:--hipstdpar-thrust-path=%S/../Driver/Inputs/hipstdpar/thrust \
+// RUN:--hipstdpar-prim-path=%S/../Driver/Inputs/hipstdpar/rocprim 2>&1 \
+// RUN:| FileCheck %s -check-prefix=RDC
+// RDC-NOT: {{.*}}"-mllvm" "-amdgpu-enable-hipstdpar"

diff  --git 
a/clang/test/CodeGenHipStdPar/select-accelerator-code-pass-ordering.cpp 
b/clang/test/CodeGenHipStdPar/select-accelerator-code-pass-ordering.cpp
new file mode 100644
index 0..c70b651397527
--- /dev/null
+++ b/clang/test/CodeGenHipStdPar/select-accelerator-code-pass-ordering.cpp
@@ -0,0 +1,24 @@
+// Test that the accelerator code selection pass only gets invoke

[clang] [clang-format]: Add `Custom` to `ShortFunctionStyle`; add new AllowShortFunctionsOnASingleLineOptions for granular setup (PR #134337)

2025-04-14 Thread Owen Pan via cfe-commits


@@ -293,15 +293,14 @@ class LineJoiner {
 
 auto ShouldMergeShortFunctions = [this, &I, &NextLine, PreviousLine,
   TheLine]() {
-  if (Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_All)
+  if (Style.AllowShortFunctionsOnASingleLine.Other)
 return true;
-  if (Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty &&
+  if (Style.AllowShortFunctionsOnASingleLine.Empty &&
   NextLine.First->is(tok::r_brace)) {
 return true;
   }
 
-  if (Style.AllowShortFunctionsOnASingleLine &
-  FormatStyle::SFS_InlineOnly) {
+  if (Style.AllowShortFunctionsOnASingleLine.Inline) {

owenca wrote:

See https://github.com/llvm/llvm-project/pull/134337#discussion_r2029943820.

https://github.com/llvm/llvm-project/pull/134337
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format]: Add `Custom` to `ShortFunctionStyle`; add new AllowShortFunctionsOnASingleLineOptions for granular setup (PR #134337)

2025-04-14 Thread Owen Pan via cfe-commits


@@ -5687,11 +5687,11 @@ bool TokenAnnotator::mustBreakBefore(const 
AnnotatedLine &Line,
 if (Right.is(tok::r_brace) && Left.is(tok::l_brace) &&
 !Left.Children.empty()) {
   // Support AllowShortFunctionsOnASingleLine for JavaScript.
-  return Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_None ||
- Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Empty 
||
+  return (!Style.AllowShortFunctionsOnASingleLine.Inline &&
+  !Style.AllowShortFunctionsOnASingleLine.Other) ||
  (Left.NestingLevel == 0 && Line.Level == 0 &&
-  Style.AllowShortFunctionsOnASingleLine &
-  FormatStyle::SFS_InlineOnly);
+  Style.AllowShortFunctionsOnASingleLine.Inline &&
+  !Style.AllowShortFunctionsOnASingleLine.Other);

owenca wrote:

> Since the options are now independent, this part should probably become 
> something like this.
> 
> ```c++
> !(Left.NestingLevel == 0 && Line.Level == 0 ? 
> Style.AllowShortFunctionsOnASingleLine.Other : 
> Style.AllowShortFunctionsOnASingleLine.Inline)
> ```

That seems wrong. See 
https://github.com/llvm/llvm-project/pull/134337#discussion_r2043562759.

https://github.com/llvm/llvm-project/pull/134337
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [llvm][clang] Allocate a new stack instead of spawning a new thread to get more stack space (PR #133173)

2025-04-14 Thread Reid Kleckner via cfe-commits


@@ -0,0 +1,115 @@
+//===--- RunOnNewStack.cpp - Crash Recovery 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/ProgramStack.h"
+#include "llvm/Config/config.h"
+#include "llvm/Support/Compiler.h"
+
+#ifdef HAVE_SYS_RESOURCE_H
+# include 
+#endif
+
+#ifdef _MSC_VER
+# include   // for _AddressOfReturnAddress
+#endif
+
+// Currently only Apple AArch64 is known to support split stacks in the 
debugger
+// and other tooling.
+#if defined(__APPLE__) && defined(__aarch64__) &&  
\
+LLVM_HAS_CPP_ATTRIBUTE(gnu::naked) && __has_extension(gnu_asm)
+# define LLVM_HAS_SPLIT_STACKS
+# define LLVM_HAS_SPLIT_STACKS_AARCH64
+#include 
+#endif
+
+#ifndef LLVM_HAS_SPLIT_STACKS
+# include "llvm/Support/thread.h"
+#endif
+
+using namespace llvm;
+
+uintptr_t llvm::getStackPointer() {
+#if __GNUC__ || __has_builtin(__builtin_frame_address)
+  return (uintptr_t)__builtin_frame_address(0);
+#elif defined(_MSC_VER)
+  return (uintptr_t)_AddressOfReturnAddress();
+#else
+  char CharOnStack = 0;
+  // The volatile store here is intended to escape the local variable, to
+  // prevent the compiler from optimizing CharOnStack into anything other
+  // than a char on the stack.
+  //
+  // Tested on: MSVC 2015 - 2019, GCC 4.9 - 9, Clang 3.2 - 9, ICC 13 - 19.
+  char *volatile Ptr = &CharOnStack;
+  return (uintptr_t)Ptr;
+#endif
+}
+
+unsigned llvm::getDefaultStackSize() {
+#ifdef HAVE_SYS_RESOURCE_H
+  rlimit RL;
+  getrlimit(RLIMIT_STACK, &RL);

rnk wrote:

I guess "no change" is reasonable.

https://github.com/llvm/llvm-project/pull/133173
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Disable -fdollars-in-identifiers by default (PR #135407)

2025-04-14 Thread Owen Pan via cfe-commits


@@ -4036,6 +4036,7 @@ LangOptions getFormattingLangOpts(const FormatStyle 
&Style) {
   LangOpts.MicrosoftExt = 1;// To get kw___try, kw___finally.
   LangOpts.DeclSpecKeyword = 1; // To get __declspec.
   LangOpts.C99 = 1; // To get kw_restrict for non-underscore-prefixed restrict.
+  LangOpts.DollarIdents = 1; // For $identifier$ testing.

owenca wrote:

Should the comment be something like `To allow $ in identifiers.`?

https://github.com/llvm/llvm-project/pull/135407
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-14 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/135649

>From 6f0a3ba5852134d8bd04679438866e6f373f494a Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 15 Apr 2025 12:12:19 +0800
Subject: [PATCH 1/3] [Clang] Add support for GCC bound member functions
 extension

---
 clang/include/clang/AST/OperationKinds.def|  4 ++
 clang/include/clang/Basic/DiagnosticGroups.td | 32 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  1 +
 clang/lib/AST/Expr.cpp|  5 ++
 clang/lib/AST/ExprConstant.cpp|  2 +
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExprAgg.cpp   |  2 +
 clang/lib/CodeGen/CGExprComplex.cpp   |  1 +
 clang/lib/CodeGen/CGExprConstant.cpp  |  1 +
 clang/lib/CodeGen/CGExprScalar.cpp|  1 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 24 ++-
 clang/lib/Edit/RewriteObjCFoundationAPI.cpp   |  1 +
 clang/lib/Sema/SemaCast.cpp   | 63 +++
 .../StaticAnalyzer/Core/BasicValueFactory.cpp |  3 +-
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |  3 +-
 17 files changed, 129 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/AST/OperationKinds.def 
b/clang/include/clang/AST/OperationKinds.def
index 790dd572a7c99..489d89a697dc3 100644
--- a/clang/include/clang/AST/OperationKinds.def
+++ b/clang/include/clang/AST/OperationKinds.def
@@ -152,6 +152,10 @@ CAST_OPERATION(MemberPointerToBoolean)
 /// many ABIs do not guarantee this on all possible intermediate types).
 CAST_OPERATION(ReinterpretMemberPointer)
 
+/// CK_BoundPointerToMemberFunctionToFunctionPointer - Convert a bound
+/// member function pointer to a function pointer.  This is a GNU extension.
+CAST_OPERATION(BoundMemberFunctionToFunctionPointer)
+
 /// CK_UserDefinedConversion - Conversion using a user defined type
 /// conversion function.
 ///struct A { operator int(); }; int i = int(A());
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d97bbfee2e4d5..8e5a4cba87c95 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -795,6 +795,7 @@ def DuplicateDeclSpecifier : 
DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
 def GNUUnionCast : DiagGroup<"gnu-union-cast">;
 def GNUVariableSizedTypeNotAtEnd : 
DiagGroup<"gnu-variable-sized-type-not-at-end">;
+def GNUPMFCast : DiagGroup<"pmf-conversions">;
 def Varargs : DiagGroup<"varargs">;
 def XorUsedAsPow : DiagGroup<"xor-used-as-pow">;
 
@@ -1294,22 +1295,21 @@ def C2y : DiagGroup<"c2y-extensions">;
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
-GNUAutoType, GNUBinaryLiteral, GNUCaseRange,
-GNUComplexInteger, GNUCompoundLiteralInitializer,
-GNUConditionalOmittedOperand, GNUDesignator,
-GNUEmptyStruct,
-VLAExtension, GNUFlexibleArrayInitializer,
-GNUFlexibleArrayUnionMember, GNUFoldingConstant,
-GNUImaginaryConstant, GNUIncludeNext,
-GNULabelsAsValue, GNULineMarker, 
GNUNullPointerArithmetic,
-GNUOffsetofExtensions, GNUPointerArith,
-RedeclaredClassMember, GNURedeclaredEnum,
-GNUStatementExpression, GNUStaticFloatInit,
-GNUStringLiteralOperatorTemplate, GNUUnionCast,
-GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
-GNUZeroLineDirective,
-GNUZeroVariadicMacroArguments]>;
+def GNU
+: DiagGroup<
+  "gnu", [GNUAlignofExpression, GNUAnonymousStruct, GNUAutoType,
+  GNUBinaryLiteral, GNUCaseRange, GNUComplexInteger,
+  GNUCompoundLiteralInitializer, GNUConditionalOmittedOperand,
+  GNUDesignator, GNUEmptyStruct, VLAExtension,
+  GNUFlexibleArrayInitializer, GNUFlexibleArrayUnionMember,
+  GNUFoldingConstant, GNUImaginaryConstant, GNUIncludeNext,
+  GNULabelsAsValue, GNULineMarker, GNUNullPointerArithmetic,
+  GNUOffsetofExtensions, GNUPointerArith, 
RedeclaredClassMember,
+  GNURedeclaredEnum, GNUStatementExpression, 
GNUStaticFloatInit,
+  GNUStringLiteralOperatorTemplate, GNUUnionCast,
+  GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
+  GNUZeroLineDirective, GNUZeroVariadicMacr

[clang] ff687af - [clang][CodeGen] Add range metadata for atomic load of boolean type. #131476 (#133546)

2025-04-14 Thread via cfe-commits

Author: Jan Górski
Date: 2025-04-14T14:26:10-07:00
New Revision: ff687af04f5b0e85305250587b524cb0b3849aa0

URL: 
https://github.com/llvm/llvm-project/commit/ff687af04f5b0e85305250587b524cb0b3849aa0
DIFF: 
https://github.com/llvm/llvm-project/commit/ff687af04f5b0e85305250587b524cb0b3849aa0.diff

LOG: [clang][CodeGen] Add range metadata for atomic load of boolean type. 
#131476 (#133546)

Fixes #131476.

For `x86_64` it folds
```
movzbl  t1(%rip), %eax
andb$1, %al
```
into
```
movzbl  t1(%rip), %eax
```
when run: `clang -S atomic-ops-load.c -o atomic-ops-load.s -O1
--target=x86_64`.

But for riscv replaces:
```
lb  a0, %lo(t1)(a0)
andia0, a0, 1
```
with
```
lb  a0, %lo(t1)(a0)
zext.b  a0, a0
``` 
when run: `clang -S atomic-ops-load.c -o atomic-ops-load.s -O1
--target=riscv64`.

Added: 
clang/test/CodeGen/atomic-ops-load.c

Modified: 
clang/lib/CodeGen/CGAtomic.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CodeGenFunction.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 672e82f8dcc3e..0af3cd07b13a0 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -590,6 +590,7 @@ static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr 
*E, Address Dest,
 llvm::LoadInst *Load = CGF.Builder.CreateLoad(Ptr);
 Load->setAtomic(Order, Scope);
 Load->setVolatile(E->isVolatile());
+CGF.maybeAttachRangeForLoad(Load, E->getValueType(), E->getExprLoc());
 CGF.Builder.CreateStore(Load, Dest);
 return;
   }

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 5f028f6d8c6ac..3da21cebd9d68 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -1919,6 +1919,20 @@ llvm::MDNode 
*CodeGenFunction::getRangeForLoadFromType(QualType Ty) {
   return MDHelper.createRange(Min, End);
 }
 
+void CodeGenFunction::maybeAttachRangeForLoad(llvm::LoadInst *Load, QualType 
Ty,
+  SourceLocation Loc) {
+  if (EmitScalarRangeCheck(Load, Ty, Loc)) {
+// In order to prevent the optimizer from throwing away the check, don't
+// attach range metadata to the load.
+  } else if (CGM.getCodeGenOpts().OptimizationLevel > 0) {
+if (llvm::MDNode *RangeInfo = getRangeForLoadFromType(Ty)) {
+  Load->setMetadata(llvm::LLVMContext::MD_range, RangeInfo);
+  Load->setMetadata(llvm::LLVMContext::MD_noundef,
+llvm::MDNode::get(CGM.getLLVMContext(), {}));
+}
+  }
+}
+
 bool CodeGenFunction::EmitScalarRangeCheck(llvm::Value *Value, QualType Ty,
SourceLocation Loc) {
   bool HasBoolCheck = SanOpts.has(SanitizerKind::Bool);
@@ -2037,15 +2051,7 @@ llvm::Value *CodeGenFunction::EmitLoadOfScalar(Address 
Addr, bool Volatile,
 
   CGM.DecorateInstructionWithTBAA(Load, TBAAInfo);
 
-  if (EmitScalarRangeCheck(Load, Ty, Loc)) {
-// In order to prevent the optimizer from throwing away the check, don't
-// attach range metadata to the load.
-  } else if (CGM.getCodeGenOpts().OptimizationLevel > 0)
-if (llvm::MDNode *RangeInfo = getRangeForLoadFromType(Ty)) {
-  Load->setMetadata(llvm::LLVMContext::MD_range, RangeInfo);
-  Load->setMetadata(llvm::LLVMContext::MD_noundef,
-llvm::MDNode::get(getLLVMContext(), {}));
-}
+  maybeAttachRangeForLoad(Load, Ty, Loc);
 
   return EmitFromMemory(Load, Ty);
 }

diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index cdddc69effb86..aa07e5d6c8099 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -5309,6 +5309,9 @@ class CodeGenFunction : public CodeGenTypeCache {
  unsigned NumElementsDst,
  const llvm::Twine &Name = "");
 
+  void maybeAttachRangeForLoad(llvm::LoadInst *Load, QualType Ty,
+   SourceLocation Loc);
+
 private:
   // Emits a convergence_loop instruction for the given |BB|, with 
|ParentToken|
   // as it's parent convergence instr.

diff  --git a/clang/test/CodeGen/atomic-ops-load.c 
b/clang/test/CodeGen/atomic-ops-load.c
new file mode 100644
index 0..778a7ebdc2618
--- /dev/null
+++ b/clang/test/CodeGen/atomic-ops-load.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple riscv64 -O1 -emit-llvm %s -o - | FileCheck %s
+#include 
+
+extern bool t1;
+bool test1(void) {
+// CHECK-LABEL: define{{.*}} i1 @test1
+// CHECK: load atomic i8, ptr @t1 monotonic, align 1, !range 
![[$WS_RANGE:[0-9]*]], !noundef !{{[0-9]+}}
+// CHECK-NEXT: trunc nuw i8 %{{.*}} to i1
+// CHECK-NEXT: ret i1 %{{.*}}
+  return __atomic_load_n(&t1, __ATOMIC_RELAXED);
+}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/

[clang] [clang] [Driver] Fix respecting libdir when locating flang runtime (PR #127345)

2025-04-14 Thread Michał Górny via cfe-commits

https://github.com/mgorny closed 
https://github.com/llvm/llvm-project/pull/127345
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format]: Add `Custom` to `ShortFunctionStyle`; add new AllowShortFunctionsOnASingleLineOptions for granular setup (PR #134337)

2025-04-14 Thread Owen Pan via cfe-commits


@@ -293,15 +293,14 @@ class LineJoiner {
 
 auto ShouldMergeShortFunctions = [this, &I, &NextLine, PreviousLine,
   TheLine]() {
-  if (Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_All)
+  if (Style.AllowShortFunctionsOnASingleLine.Other)

owenca wrote:

Isn't `SFS_All` equivalent to `Empty && Inline && Other`?

https://github.com/llvm/llvm-project/pull/134337
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format]: Add `Custom` to `ShortFunctionStyle`; add new AllowShortFunctionsOnASingleLineOptions for granular setup (PR #134337)

2025-04-14 Thread Owen Pan via cfe-commits


@@ -5687,11 +5687,11 @@ bool TokenAnnotator::mustBreakBefore(const 
AnnotatedLine &Line,
 if (Right.is(tok::r_brace) && Left.is(tok::l_brace) &&
 !Left.Children.empty()) {
   // Support AllowShortFunctionsOnASingleLine for JavaScript.
-  return Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_None ||
- Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Empty 
||
+  return (!Style.AllowShortFunctionsOnASingleLine.Inline &&
+  !Style.AllowShortFunctionsOnASingleLine.Other) ||
  (Left.NestingLevel == 0 && Line.Level == 0 &&
-  Style.AllowShortFunctionsOnASingleLine &
-  FormatStyle::SFS_InlineOnly);
+  Style.AllowShortFunctionsOnASingleLine.Inline &&
+  !Style.AllowShortFunctionsOnASingleLine.Other);

owenca wrote:

> It looks like you should not add inline here. The old check uses `&`. That is 
> same as comparing against `SFS_All`.

See https://github.com/llvm/llvm-project/pull/134337#discussion_r2029943820.

https://github.com/llvm/llvm-project/pull/134337
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format]: Add `Custom` to `ShortFunctionStyle`; add new AllowShortFunctionsOnASingleLineOptions for granular setup (PR #134337)

2025-04-14 Thread Owen Pan via cfe-commits


@@ -5687,11 +5687,9 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
&Line,
 if (Right.is(tok::r_brace) && Left.is(tok::l_brace) &&
 !Left.Children.empty()) {
   // Support AllowShortFunctionsOnASingleLine for JavaScript.
-  return Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_None ||
- Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Empty 
||
- (Left.NestingLevel == 0 && Line.Level == 0 &&
-  Style.AllowShortFunctionsOnASingleLine &
-  FormatStyle::SFS_InlineOnly);
+  return !(Left.NestingLevel == 0 && Line.Level == 0
+   ? Style.AllowShortFunctionsOnASingleLine.Other
+   : Style.AllowShortFunctionsOnASingleLine.Inline);

owenca wrote:

It would return `false` for `SFS_All` before but returns `true` for `Other` now?

https://github.com/llvm/llvm-project/pull/134337
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][MicrosoftMangle] Implement mangling for ConstantMatrixType (PR #134930)

2025-04-14 Thread via cfe-commits

Losy001 wrote:

Ping

https://github.com/llvm/llvm-project/pull/134930
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-14 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/135649

>From 6f0a3ba5852134d8bd04679438866e6f373f494a Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 15 Apr 2025 12:12:19 +0800
Subject: [PATCH 1/2] [Clang] Add support for GCC bound member functions
 extension

---
 clang/include/clang/AST/OperationKinds.def|  4 ++
 clang/include/clang/Basic/DiagnosticGroups.td | 32 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  1 +
 clang/lib/AST/Expr.cpp|  5 ++
 clang/lib/AST/ExprConstant.cpp|  2 +
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExprAgg.cpp   |  2 +
 clang/lib/CodeGen/CGExprComplex.cpp   |  1 +
 clang/lib/CodeGen/CGExprConstant.cpp  |  1 +
 clang/lib/CodeGen/CGExprScalar.cpp|  1 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 24 ++-
 clang/lib/Edit/RewriteObjCFoundationAPI.cpp   |  1 +
 clang/lib/Sema/SemaCast.cpp   | 63 +++
 .../StaticAnalyzer/Core/BasicValueFactory.cpp |  3 +-
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |  3 +-
 17 files changed, 129 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/AST/OperationKinds.def 
b/clang/include/clang/AST/OperationKinds.def
index 790dd572a7c99..489d89a697dc3 100644
--- a/clang/include/clang/AST/OperationKinds.def
+++ b/clang/include/clang/AST/OperationKinds.def
@@ -152,6 +152,10 @@ CAST_OPERATION(MemberPointerToBoolean)
 /// many ABIs do not guarantee this on all possible intermediate types).
 CAST_OPERATION(ReinterpretMemberPointer)
 
+/// CK_BoundPointerToMemberFunctionToFunctionPointer - Convert a bound
+/// member function pointer to a function pointer.  This is a GNU extension.
+CAST_OPERATION(BoundMemberFunctionToFunctionPointer)
+
 /// CK_UserDefinedConversion - Conversion using a user defined type
 /// conversion function.
 ///struct A { operator int(); }; int i = int(A());
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d97bbfee2e4d5..8e5a4cba87c95 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -795,6 +795,7 @@ def DuplicateDeclSpecifier : 
DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
 def GNUUnionCast : DiagGroup<"gnu-union-cast">;
 def GNUVariableSizedTypeNotAtEnd : 
DiagGroup<"gnu-variable-sized-type-not-at-end">;
+def GNUPMFCast : DiagGroup<"pmf-conversions">;
 def Varargs : DiagGroup<"varargs">;
 def XorUsedAsPow : DiagGroup<"xor-used-as-pow">;
 
@@ -1294,22 +1295,21 @@ def C2y : DiagGroup<"c2y-extensions">;
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
-GNUAutoType, GNUBinaryLiteral, GNUCaseRange,
-GNUComplexInteger, GNUCompoundLiteralInitializer,
-GNUConditionalOmittedOperand, GNUDesignator,
-GNUEmptyStruct,
-VLAExtension, GNUFlexibleArrayInitializer,
-GNUFlexibleArrayUnionMember, GNUFoldingConstant,
-GNUImaginaryConstant, GNUIncludeNext,
-GNULabelsAsValue, GNULineMarker, 
GNUNullPointerArithmetic,
-GNUOffsetofExtensions, GNUPointerArith,
-RedeclaredClassMember, GNURedeclaredEnum,
-GNUStatementExpression, GNUStaticFloatInit,
-GNUStringLiteralOperatorTemplate, GNUUnionCast,
-GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
-GNUZeroLineDirective,
-GNUZeroVariadicMacroArguments]>;
+def GNU
+: DiagGroup<
+  "gnu", [GNUAlignofExpression, GNUAnonymousStruct, GNUAutoType,
+  GNUBinaryLiteral, GNUCaseRange, GNUComplexInteger,
+  GNUCompoundLiteralInitializer, GNUConditionalOmittedOperand,
+  GNUDesignator, GNUEmptyStruct, VLAExtension,
+  GNUFlexibleArrayInitializer, GNUFlexibleArrayUnionMember,
+  GNUFoldingConstant, GNUImaginaryConstant, GNUIncludeNext,
+  GNULabelsAsValue, GNULineMarker, GNUNullPointerArithmetic,
+  GNUOffsetofExtensions, GNUPointerArith, 
RedeclaredClassMember,
+  GNURedeclaredEnum, GNUStatementExpression, 
GNUStaticFloatInit,
+  GNUStringLiteralOperatorTemplate, GNUUnionCast,
+  GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
+  GNUZeroLineDirective, GNUZeroVariadicMacr

[clang] [llvm] [ARM] Adding diagnostics for mcmodel=tiny when used in invalid targets (PR #125643)

2025-04-14 Thread via cfe-commits

https://github.com/ShashwathiNavada updated 
https://github.com/llvm/llvm-project/pull/125643

>From 0aebcd7119fbcd51154c5d9706752e8ff3f041bc Mon Sep 17 00:00:00 2001
From: ShashwathiNavada 
Date: Tue, 4 Feb 2025 00:16:09 -0600
Subject: [PATCH 1/7] Adding diagnostics for unsupported option

---
 clang/lib/Frontend/CompilerInvocation.cpp | 9 +
 1 file changed, 9 insertions(+)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 11fd6ab7f52a7..ac8d8be572012 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1897,6 +1897,15 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions 
&Opts, ArgList &Args,
 Opts.setInlining(CodeGenOptions::NormalInlining);
   }
 
+// -mcmodel option.
+if (const llvm::opt::Arg *A = 
Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)) 
+{
+llvm::StringRef modelName = A->getValue();
+if(modelName=="tiny" && !T.isARM())
+  Diags.Report(diag::err_drv_unsupported_option_argument_for_target) 
+  << A->getSpelling() getValue();
 if(modelName=="tiny" && !T.isARM())
-  Diags.Report(diag::err_drv_unsupported_option_argument_for_target) 
-  << A->getSpelling() From 689dc3a3472ff8270ee9631b235e776f5fa1a27f Mon Sep 17 00:00:00 2001
From: ShashwathiNavada 
Date: Tue, 4 Feb 2025 00:49:37 -0600
Subject: [PATCH 3/7] minor changes

---
 clang/lib/Frontend/CompilerInvocation.cpp | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 1242073ea6746..15d382620d279 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1896,13 +1896,15 @@ bool 
CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
   } else {
 Opts.setInlining(CodeGenOptions::NormalInlining);
   }
-
- // -mcmodel option.
-  if (const llvm::opt::Arg *A = 
Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)){
+ 
+  // -mcmodel option.
+  if (const llvm::opt::Arg *A =
+  Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)) {
 llvm::StringRef modelName = A->getValue();
-if(modelName=="tiny" && !T.isARM())
+if (modelName == "tiny" && !T.isARM()) {
   Diags.Report(diag::err_drv_unsupported_option_argument_for_target)
-  << A->getSpelling() << modelName << T.getTriple();  
+  << A->getSpelling() << modelName << T.getTriple();
+}
   }
 
   // PIC defaults to -fno-direct-access-external-data while non-PIC defaults to

>From 28fcb0ee20645cd1d30dd15bfd7f6eff402ba2b9 Mon Sep 17 00:00:00 2001
From: ShashwathiNavada 
Date: Tue, 4 Feb 2025 01:01:00 -0600
Subject: [PATCH 4/7] minor changes

---
 clang/lib/Frontend/CompilerInvocation.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 15d382620d279..f858ec2234cb5 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1896,7 +1896,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions 
&Opts, ArgList &Args,
   } else {
 Opts.setInlining(CodeGenOptions::NormalInlining);
   }
- 
+
   // -mcmodel option.
   if (const llvm::opt::Arg *A =
   Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)) {

>From 843d4ccf4c41a78397e14eb5d9459a4921325741 Mon Sep 17 00:00:00 2001
From: ShashwathiNavada 
Date: Tue, 4 Feb 2025 21:39:44 +0530
Subject: [PATCH 5/7] Addressed build fail

---
 clang/lib/Frontend/CompilerInvocation.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index f858ec2234cb5..48f66931af06c 10064

[clang] [llvm] [llvm][clang] Allocate a new stack instead of spawning a new thread to get more stack space (PR #133173)

2025-04-14 Thread Reid Kleckner via cfe-commits

https://github.com/rnk approved this pull request.

Thanks, looks good.

https://github.com/llvm/llvm-project/pull/133173
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] [Driver] Fix respecting libdir when locating flang runtime (PR #127345)

2025-04-14 Thread Michał Górny via cfe-commits

mgorny wrote:

Closed in favor of #134362.

https://github.com/llvm/llvm-project/pull/127345
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] consistently quote expressions in diagnostics (PR #134769)

2025-04-14 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/134769

>From 7fe930def5714c196d003e94bafdb4639cea3a43 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Mon, 7 Apr 2025 22:44:20 -0300
Subject: [PATCH] [clang] consistently quote expressions in diagnostics

This changes the expression diagnostic printer to always add quotes,
and removes hardcoded quotes from the diagnostic format strings.

In some cases, a placeholder could be filled by either an expression
or as a string. In order to quote this consistently, a new modifier
was added, which can be used to quote strings.

One diagnostic was relying on unquoted expressions in order to
generate code suggestions. This diagnostic is converted to use fixit
hints instead.
---
 clang/docs/InternalsManual.rst| 11 +++
 clang/docs/ReleaseNotes.rst   |  1 +
 .../include/clang/Basic/DiagnosticASTKinds.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  2 +-
 .../clang/Basic/DiagnosticSemaKinds.td| 70 ++-
 clang/lib/AST/ASTDiagnostic.cpp   |  2 -
 clang/lib/Basic/Diagnostic.cpp| 29 
 clang/lib/Sema/SemaChecking.cpp   |  5 +-
 clang/test/AST/ByteCode/literals.cpp  |  2 +-
 clang/test/C/C11/n1285.c  | 16 ++---
 clang/test/CodeGenCXX/sections.cpp|  6 +-
 clang/test/FixIt/fixit-bool.cpp   |  7 ++
 clang/test/Modules/odr_hash.cpp   |  4 +-
 clang/test/OpenMP/declare_variant_messages.c  | 12 ++--
 .../test/OpenMP/declare_variant_messages.cpp  | 18 ++---
 ...bute_parallel_for_simd_linear_messages.cpp |  4 +-
 .../distribute_simd_linear_messages.cpp   |  2 +-
 clang/test/OpenMP/for_linear_messages.cpp |  2 +-
 .../test/OpenMP/for_simd_linear_messages.cpp  |  6 +-
 clang/test/OpenMP/for_simd_misc_messages.c|  2 +-
 .../masked_taskloop_simd_linear_messages.cpp  |  6 +-
 .../master_taskloop_simd_linear_messages.cpp  |  6 +-
 .../OpenMP/parallel_for_linear_messages.cpp   |  2 +-
 .../parallel_for_simd_linear_messages.cpp |  2 +-
 .../OpenMP/parallel_for_simd_misc_messages.c  |  2 +-
 ...l_masked_taskloop_simd_linear_messages.cpp |  8 +--
 ...l_master_taskloop_simd_linear_messages.cpp |  6 +-
 clang/test/OpenMP/simd_linear_messages.cpp|  6 +-
 clang/test/OpenMP/simd_misc_messages.c|  2 +-
 .../target_parallel_for_linear_messages.cpp   |  4 +-
 ...rget_parallel_for_simd_linear_messages.cpp |  4 +-
 .../OpenMP/target_simd_linear_messages.cpp|  4 +-
 ...bute_parallel_for_simd_linear_messages.cpp |  2 +-
 ..._teams_distribute_simd_linear_messages.cpp |  2 +-
 clang/test/OpenMP/task_affinity_messages.cpp  |  2 +-
 clang/test/OpenMP/task_depend_messages.cpp|  2 +-
 .../OpenMP/taskloop_simd_linear_messages.cpp  |  6 +-
 ...bute_parallel_for_simd_linear_messages.cpp |  2 +-
 .../teams_distribute_simd_linear_messages.cpp |  2 +-
 clang/test/Sema/code_align.c  |  4 +-
 clang/test/Sema/warn-int-in-bool-context.c| 24 +++
 .../Sema/warn-lifetime-analysis-nocfg.cpp | 26 +++
 .../test/SemaCXX/attr-lifetime-capture-by.cpp | 10 +--
 clang/test/SemaCXX/attr-lifetimebound.cpp | 14 ++--
 clang/test/SemaCXX/cxx2c-pack-indexing.cpp| 14 ++--
 clang/test/SemaCXX/warn-dangling-local.cpp|  6 +-
 .../test/SemaHLSL/BuiltIns/asuint-errors.hlsl |  8 +--
 .../test/SemaHLSL/BuiltIns/select-errors.hlsl |  2 +-
 .../SemaHLSL/BuiltIns/splitdouble-errors.hlsl | 24 +++
 .../SemaHLSL/Language/OutputParameters.hlsl   |  8 +--
 clang/test/SemaHLSL/parameter_modifiers.hlsl  |  4 +-
 clang/test/SemaOpenCL/to_addr_builtin.cl  |  6 +-
 .../TableGen/ClangDiagnosticsEmitter.cpp  |  5 ++
 53 files changed, 233 insertions(+), 197 deletions(-)
 create mode 100644 clang/test/FixIt/fixit-bool.cpp

diff --git a/clang/docs/InternalsManual.rst b/clang/docs/InternalsManual.rst
index a2b551b6f333e..353a5f094cb1c 100644
--- a/clang/docs/InternalsManual.rst
+++ b/clang/docs/InternalsManual.rst
@@ -416,6 +416,17 @@ Description:
   and the modifier indexes in the substitution are re-numbered accordingly. The
   substituted text must itself be a valid format string before substitution.
 
+**"quoted" format**
+
+Example:
+  ``"expression %quoted0 evaluates to 0"``
+Class:
+  ``String``
+Description:
+  This is a simple formatter which adds quotes around the given string.
+  This is useful when the argument could be a string in some cases, but
+  another class in other cases, and it needs to be quoted consistently.
+
 .. _internals-producing-diag:
 
 Producing the Diagnostic
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ca04d9ebd44c..d3130ab088674 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -314,6 +314,7 @@ Improvements to Clang's diagnostics
 - Clang now respects the current language mode when printing expressions in
   diagnostics. This fixes a bunch of `bool` being printed as `_B

[clang] [clang] consistently quote expressions in diagnostics (PR #134769)

2025-04-14 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/134769

>From e2c40042553845125914e544e696d7e21b553e7d Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Mon, 7 Apr 2025 22:44:20 -0300
Subject: [PATCH] [clang] consistently quote expressions in diagnostics

This changes the expression diagnostic printer to always add quotes,
and removes hardcoded quotes from the diagnostic format strings.

In some cases, a placeholder could be filled by either an expression
or as a string. In order to quote this consistently, a new modifier
was added, which can be used to quote strings.

One diagnostic was relying on unquoted expressions in order to
generate code suggestions. This diagnostic is converted to use fixit
hints instead.
---
 clang/docs/InternalsManual.rst| 11 +++
 clang/docs/ReleaseNotes.rst   |  1 +
 .../include/clang/Basic/DiagnosticASTKinds.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  2 +-
 .../clang/Basic/DiagnosticSemaKinds.td| 70 ++-
 clang/lib/AST/ASTDiagnostic.cpp   |  2 -
 clang/lib/Basic/Diagnostic.cpp| 29 
 clang/lib/Sema/SemaChecking.cpp   |  5 +-
 clang/test/AST/ByteCode/literals.cpp  |  2 +-
 clang/test/C/C11/n1285.c  | 20 +++---
 clang/test/CodeGenCXX/sections.cpp|  6 +-
 clang/test/FixIt/fixit-bool.cpp   |  7 ++
 clang/test/Modules/odr_hash.cpp   |  4 +-
 clang/test/OpenMP/declare_variant_messages.c  | 12 ++--
 .../test/OpenMP/declare_variant_messages.cpp  | 18 ++---
 ...bute_parallel_for_simd_linear_messages.cpp |  4 +-
 .../distribute_simd_linear_messages.cpp   |  2 +-
 clang/test/OpenMP/for_linear_messages.cpp |  2 +-
 .../test/OpenMP/for_simd_linear_messages.cpp  |  6 +-
 clang/test/OpenMP/for_simd_misc_messages.c|  2 +-
 .../masked_taskloop_simd_linear_messages.cpp  |  6 +-
 .../master_taskloop_simd_linear_messages.cpp  |  6 +-
 .../OpenMP/parallel_for_linear_messages.cpp   |  2 +-
 .../parallel_for_simd_linear_messages.cpp |  2 +-
 .../OpenMP/parallel_for_simd_misc_messages.c  |  2 +-
 ...l_masked_taskloop_simd_linear_messages.cpp |  8 +--
 ...l_master_taskloop_simd_linear_messages.cpp |  6 +-
 clang/test/OpenMP/simd_linear_messages.cpp|  6 +-
 clang/test/OpenMP/simd_misc_messages.c|  2 +-
 .../target_parallel_for_linear_messages.cpp   |  4 +-
 ...rget_parallel_for_simd_linear_messages.cpp |  4 +-
 .../OpenMP/target_simd_linear_messages.cpp|  4 +-
 ...bute_parallel_for_simd_linear_messages.cpp |  2 +-
 ..._teams_distribute_simd_linear_messages.cpp |  2 +-
 clang/test/OpenMP/task_affinity_messages.cpp  |  2 +-
 clang/test/OpenMP/task_depend_messages.cpp|  2 +-
 .../OpenMP/taskloop_simd_linear_messages.cpp  |  6 +-
 ...bute_parallel_for_simd_linear_messages.cpp |  2 +-
 .../teams_distribute_simd_linear_messages.cpp |  2 +-
 clang/test/Sema/code_align.c  |  4 +-
 clang/test/Sema/warn-int-in-bool-context.c| 24 +++
 .../Sema/warn-lifetime-analysis-nocfg.cpp | 26 +++
 .../test/SemaCXX/attr-lifetime-capture-by.cpp | 10 +--
 clang/test/SemaCXX/attr-lifetimebound.cpp | 14 ++--
 clang/test/SemaCXX/cxx2c-pack-indexing.cpp| 14 ++--
 clang/test/SemaCXX/warn-dangling-local.cpp|  6 +-
 .../test/SemaHLSL/BuiltIns/asuint-errors.hlsl |  8 +--
 .../test/SemaHLSL/BuiltIns/select-errors.hlsl |  2 +-
 .../SemaHLSL/BuiltIns/splitdouble-errors.hlsl | 24 +++
 .../SemaHLSL/Language/OutputParameters.hlsl   |  8 +--
 clang/test/SemaHLSL/parameter_modifiers.hlsl  |  4 +-
 clang/test/SemaOpenCL/to_addr_builtin.cl  |  6 +-
 .../TableGen/ClangDiagnosticsEmitter.cpp  |  5 ++
 53 files changed, 235 insertions(+), 199 deletions(-)
 create mode 100644 clang/test/FixIt/fixit-bool.cpp

diff --git a/clang/docs/InternalsManual.rst b/clang/docs/InternalsManual.rst
index a2b551b6f333e..353a5f094cb1c 100644
--- a/clang/docs/InternalsManual.rst
+++ b/clang/docs/InternalsManual.rst
@@ -416,6 +416,17 @@ Description:
   and the modifier indexes in the substitution are re-numbered accordingly. The
   substituted text must itself be a valid format string before substitution.
 
+**"quoted" format**
+
+Example:
+  ``"expression %quoted0 evaluates to 0"``
+Class:
+  ``String``
+Description:
+  This is a simple formatter which adds quotes around the given string.
+  This is useful when the argument could be a string in some cases, but
+  another class in other cases, and it needs to be quoted consistently.
+
 .. _internals-producing-diag:
 
 Producing the Diagnostic
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ca04d9ebd44c..d3130ab088674 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -314,6 +314,7 @@ Improvements to Clang's diagnostics
 - Clang now respects the current language mode when printing expressions in
   diagnostics. This fixes a bunch of `bool` being printed as `_

[clang] [clang] Mark some language options as benign. (PR #131569)

2025-04-14 Thread via cfe-commits

matts1 wrote:

> The issue is that if we allow the preprocessor's state to differ across 
> modules, then the resulting compiled units can be arbitrary (and subtly 
> incompatible).
> 
> I wonder if a possible solution is to record which macros are used (ie, are 
> expanded or appear in `#ifdef` / `defined`) And ONLY serialize the set of 
> macros that are used. That way, if your program never uses `__SSP__`, for 
> example, then your module would not be incompatible just because **SPP** has 
> been defined.

IIUC, you're saying that codegen options that create macros are benign when 
they are never read. This statement seems correct and would probably be a good 
optimization, however it won't solve all use cases.

In our use case, for example, we want our code built without exceptions to 
depend upon libc++ built with exceptions. As libc++ reads `__cpp_exceptions`, 
this won't work. I think that the correct thing to do would be to, similarly to 
[https://github.com/llvm/llvm-project/blob/1cf9f764ac41fb3492e10c78640dd50e616388db/clang/include/clang/Basic/LangOptions.def#L209](other
 options) which only affect a single macro, turn it into a compatible langopt, 
with a future potential optimization that if the macro is never read it can  be 
turned into a benign langopt.


https://github.com/llvm/llvm-project/pull/131569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][RFC] Bypass TAD during overload resolution if a perfect match exists (PR #133426)

2025-04-14 Thread via cfe-commits


@@ -1117,16 +1205,27 @@ class Sema;
 SmallVector Candidates;
 llvm::SmallPtrSet Functions;
 
-// Allocator for ConversionSequenceLists. We store the first few of these
+DeferredTemplateOverloadCandidate *FirstDeferredCandidate;
+unsigned DeferredCandidatesCount : 8 * sizeof(unsigned) - 2;

cor3ntin wrote:

The 32 on line 1227 is super arbitrary and not tied to the size of `unsigned`.
It did felt worth making bigger as we are now storing more than conversion 
sequences in the overload set. 

https://github.com/llvm/llvm-project/pull/133426
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Fix -Whigher-precision-for-complex-division (PR #131477)

2025-04-14 Thread Mészáros Gergely via cfe-commits

https://github.com/Maetveis updated 
https://github.com/llvm/llvm-project/pull/131477

From d3da72bf61ae8268a25e5331acefe895c783905a Mon Sep 17 00:00:00 2001
From: Gergely Meszaros 
Date: Sat, 15 Mar 2025 22:37:07 +0100
Subject: [PATCH 1/2] [Clang][Sema] Fix -Whigher-precision-for-complex-division

- Fix false positive when divisor is a real number
- Fix false negative when divident is real, but divisor is complex
- Fix false negative when due to promotion the division is performed
  in higher precision than the divident.
- Fix false negative in divide and assign (`a /= b`)

Fixes: #131127
---
 clang/docs/ReleaseNotes.rst   | 11 +++
 clang/lib/Sema/SemaExpr.cpp   | 78 
 .../complex-div-warn-higher-precision.cpp | 93 +++
 3 files changed, 144 insertions(+), 38 deletions(-)
 create mode 100644 clang/test/Sema/complex-div-warn-higher-precision.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 46d2debec3621..ae04ff52cdfdc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -349,6 +349,17 @@ Improvements to Clang's diagnostics
 - Now correctly diagnose a tentative definition of an array with static
   storage duration in pedantic mode in C. (#GH50661)
 
+- ``-Whigher-precisision-for-complex-divison`` no longer incorrectly warns 
when the divisor is real
+  in complex division. (#GH131127)
+
+- ``-Whigher-precisision-for-complex-divison`` now correctly warns when:
+
+  - The dividend is real, but the divisor is complex.
+  - When the complex division happens in a higher precision type than the 
dividend due to arithmetic promotion.
+  - When using the divide and assign operator (``/=``)
+  
+  Fixes #GH131127
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index c25daaa022f49..1ac84d7e95323 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10591,6 +10591,45 @@ static void checkArithmeticNull(Sema &S, ExprResult 
&LHS, ExprResult &RHS,
   << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
 }
 
+static void DetectPrecisionLossInComplexDivision(Sema &S, QualType DivisorTy,
+ SourceLocation OpLoc) {
+  // If the divisor is real, then this is real/real or complex/real division.
+  // Either way there can be no precision loss.
+  auto *CT = DivisorTy->getAs();
+  if (!CT)
+return;
+
+  QualType ElementType = CT->getElementType();
+  bool IsComplexRangePromoted = S.getLangOpts().getComplexRange() ==
+LangOptions::ComplexRangeKind::CX_Promoted;
+  if (!ElementType->isFloatingType() || !IsComplexRangePromoted)
+return;
+
+  ASTContext &Ctx = S.getASTContext();
+  QualType HigherElementType = Ctx.GetHigherPrecisionFPType(ElementType);
+  const llvm::fltSemantics &ElementTypeSemantics =
+  Ctx.getFloatTypeSemantics(ElementType);
+  const llvm::fltSemantics &HigherElementTypeSemantics =
+  Ctx.getFloatTypeSemantics(HigherElementType);
+
+  if ((llvm::APFloat::semanticsMaxExponent(ElementTypeSemantics) * 2 + 1 >
+   llvm::APFloat::semanticsMaxExponent(HigherElementTypeSemantics)) ||
+  (HigherElementType == Ctx.LongDoubleTy &&
+   !Ctx.getTargetInfo().hasLongDoubleType())) {
+// Retain the location of the first use of higher precision type.
+if (!S.LocationOfExcessPrecisionNotSatisfied.isValid())
+  S.LocationOfExcessPrecisionNotSatisfied = OpLoc;
+for (auto &[Type, Num] : S.ExcessPrecisionNotSatisfied) {
+  if (Type == HigherElementType) {
+Num++;
+return;
+  }
+}
+S.ExcessPrecisionNotSatisfied.push_back(std::make_pair(
+HigherElementType, S.ExcessPrecisionNotSatisfied.size()));
+  }
+}
+
 static void DiagnoseDivisionSizeofPointerOrArray(Sema &S, Expr *LHS, Expr *RHS,
   SourceLocation Loc) {
   const auto *LUE = dyn_cast(LHS);
@@ -10685,6 +10724,7 @@ QualType Sema::CheckMultiplyDivideOperands(ExprResult 
&LHS, ExprResult &RHS,
   if (compType.isNull() || !compType->isArithmeticType())
 return InvalidOperands(Loc, LHS, RHS);
   if (IsDiv) {
+DetectPrecisionLossInComplexDivision(*this, RHS.get()->getType(), Loc);
 DiagnoseBadDivideOrRemainderValues(*this, LHS, RHS, Loc, IsDiv);
 DiagnoseDivisionSizeofPointerOrArray(*this, LHS.get(), RHS.get(), Loc);
   }
@@ -15336,39 +15376,6 @@ static void DiagnoseBinOpPrecedence(Sema &Self, 
BinaryOperatorKind Opc,
 DiagnoseShiftCompare(Self, OpLoc, LHSExpr, RHSExpr);
 }
 
-static void DetectPrecisionLossInComplexDivision(Sema &S, SourceLocation OpLoc,
- Expr *Operand) {
-  if (auto *CT = Operand->getType()->getAs()) {
-QualType ElementType = CT->getElementType();
-bool IsComplexRangePromoted = S.getLangOpts().getComplexRange() ==
- 

[clang] [Clang][Sema] Fix -Whigher-precision-for-complex-division (PR #131477)

2025-04-14 Thread Mészáros Gergely via cfe-commits


@@ -349,6 +349,17 @@ Improvements to Clang's diagnostics
 - Now correctly diagnose a tentative definition of an array with static
   storage duration in pedantic mode in C. (#GH50661)
 
+- ``-Whigher-precisision-for-complex-divison`` no longer incorrectly warns 
when the divisor is real

Maetveis wrote:

Thanks, applied!

https://github.com/llvm/llvm-project/pull/131477
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][CodeGen][OpenCL] Add `-fno-delete-null-pointer-checks` to avoid UB. NFC. (PR #135602)

2025-04-14 Thread Eli Friedman via cfe-commits


@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" 
-fno-delete-null-pointer-checks -emit-llvm -o - | FileCheck %s

efriedma-quic wrote:

I don't see any optimization flags here... is this somehow running the 
optimizer by default?

If it is, this change is fine, I guess.

https://github.com/llvm/llvm-project/pull/135602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Merge similar Clang Thread Safety attributes (PR #135561)

2025-04-14 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

LGTM, thank you for the cleanup! The behavioral changes all seem defensible to 
me. Should those have a release note?

https://github.com/llvm/llvm-project/pull/135561
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-04-14 Thread via cfe-commits

cor3ntin wrote:

@Sterling-Augustine Oliver is looking into it. Given it's a relatively large 
patch, I'd rather wait a day until reverting to avoid churn. Will that work for 
you?

https://github.com/llvm/llvm-project/pull/113510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AArch64] Change the coercion type of structs with pointer members. (PR #135064)

2025-04-14 Thread Eli Friedman via cfe-commits


@@ -485,6 +485,39 @@ ABIArgInfo AArch64ABIInfo::classifyArgumentType(QualType 
Ty, bool IsVariadicFn,
 }
 Size = llvm::alignTo(Size, Alignment);
 
+// If the Aggregate is made up of pointers, use an array of pointers for 
the
+// coerced type. This prevents having to convert ptr2int->int2ptr through
+// the call, allowing alias analysis to produce better code.
+std::function ContainsOnlyPointers = [&](QualType Ty) {
+  if (isEmptyRecord(getContext(), Ty, true))
+return false;
+  const RecordType *RT = Ty->getAs();
+  if (!RT)
+return false;
+  const RecordDecl *RD = RT->getDecl();
+  if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) {
+for (const auto &I : CXXRD->bases())
+  if (!ContainsOnlyPointers(I.getType()))
+return false;
+  }
+  return all_of(RD->fields(), [&](FieldDecl *FD) {
+QualType FDTy = FD->getType();
+if (FDTy->isArrayType())
+  FDTy = QualType(FDTy->getBaseElementTypeUnsafe(), 0);

efriedma-quic wrote:

The "unsafe" bit actually matters here because address spaces are qualifiers.  
Please use the ASTContext method.

https://github.com/llvm/llvm-project/pull/135064
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SYCL] Basic code generation for SYCL kernel caller offload entry point functions. (PR #133030)

2025-04-14 Thread Erich Keane via cfe-commits


@@ -14794,9 +14803,36 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   }
 }
 
-static SYCLKernelInfo BuildSYCLKernelInfo(CanQualType KernelNameType,
+static SYCLKernelInfo BuildSYCLKernelInfo(ASTContext &Context,
+  CanQualType KernelNameType,
   const FunctionDecl *FD) {
-  return {KernelNameType, FD};
+  // Host and device compilation may use different ABIs and different ABIs
+  // may allocate name mangling discriminators differently. A discriminator
+  // override is used to ensure consistent discriminator allocation across
+  // host and device compilation.
+  auto DeviceDiscriminatorOverrider =
+  [](ASTContext &Ctx, const NamedDecl *ND) -> std::optional {
+if (const auto *RD = dyn_cast(ND))
+  if (RD->isLambda())

erichkeane wrote:

My concern here is: What happens if a `genericLambda` gets here, which I 
believe will have an unset 'mangling-id'.   I'd VERY much like to not let this 
get pushed to the next one, in part since the ways forward aren't a 
particularly sizable amount of work.

I see a few ways forward:
1- Create an example that shows the mangler properly handling the 
generic-lambda.  Note you might have to do some work to get here, as getting 
generic-lambdas mangled often requires some surprising things to make happen.
2- Prove in some-way that generic-lambda cannot get here (which, would actually 
take quite a bit of convincing, dependent types find their way to sneak into 
the mangler all the time unfortunately, particularly with SFINAE and 
`diagnose_if`/etc).
2- 'assert(!isGenericLambda() && "dont' know how to handle generic lambdas 
yet");`



https://github.com/llvm/llvm-project/pull/133030
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Modules] Fix an identifier hiding a function-like macro definition. (PR #135471)

2025-04-14 Thread Volodymyr Sapsai via cfe-commits




vsapsai wrote:

By the way, looked at the other tests in Modules directory and think that the 
test should start with "macro-" for consistency. Probably something like 
"macro-identifier-hiding.c" as we have "macro-hiding.cpp" already.

https://github.com/llvm/llvm-project/pull/135471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Modules] Fix an identifier hiding a function-like macro definition. (PR #135471)

2025-04-14 Thread Jan Svoboda via cfe-commits


@@ -3871,7 +3874,8 @@ class ASTIdentifierTableTrait {
 if (isInterestingIdentifier(II, MacroOffset)) {
   DataLen += 2; // 2 bytes for builtin ID
   DataLen += 2; // 2 bytes for flags
-  if (MacroOffset)
+  if (MacroOffset || (II->hasMacroDefinition() &&
+  II->hasFETokenInfoChangedSinceDeserialization()))

jansvoboda11 wrote:

Ah, I see that `ASTReader` does this for each `ModuleFile`:
```c++
for (auto Offset : F.PreloadIdentifierOffsets) {
  // ...
  IdentifierInfo *II;
  if (!PP.getLangOpts().CPlusPlus) {
// Identifiers present in both the module file and the importing
// instance are marked out-of-date so that they can be deserialized
// on next use via ASTReader::updateOutOfDateIdentifier().
// Identifiers present in the module file but not in the importing
// instance are ignored for now, preventing growth of the identifier
// table. They will be deserialized on first use via ASTReader::get().
auto It = PP.getIdentifierTable().find(Key);
if (It == PP.getIdentifierTable().end())
  continue;
II = It->second;
  } else {
// With C++ modules, not many identifiers are considered interesting.
// All identifiers in the module file can be placed into the identifier
// table of the importing instance and marked as out-of-date. This makes
// ASTReader::get() a no-op, and deserialization will take place on
// first/next use via ASTReader::updateOutOfDateIdentifier().
II = &PP.getIdentifierTable().getOwn(Key);
  }
  // ...
  markIdentifierFromAST(*this, *II, /*IsModule=*/true);
  //...
}
```
and "__Q" already is in the table, so that works out. Makes sense, thanks for 
walking me through it.

https://github.com/llvm/llvm-project/pull/135471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang]Ensure correct handling of cleanup access control (#135668) (PR #135686)

2025-04-14 Thread via cfe-commits

Sterling-Augustine wrote:

Thanks from this side too. Appreciate the speed.

https://github.com/llvm/llvm-project/pull/135686
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Merge similar Clang Thread Safety attributes (PR #135561)

2025-04-14 Thread Aaron Puchert via cfe-commits

aaronpuchert wrote:

I think it's obscure enough to not need to be mentioned. Since I went with the 
less intrusive variant of downgrading an error to warning, it should not break 
anyone's code.

I'd be open to add `ErrorDiag` on all thread safety attributes, but I'd do so 
in a separate change in case we break some user code and it has to be reverted.

https://github.com/llvm/llvm-project/pull/135561
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Modules] Fix an identifier hiding a function-like macro definition. (PR #135471)

2025-04-14 Thread Jan Svoboda via cfe-commits


@@ -2419,6 +2422,9 @@ namespace {
   // declarations it needs.
   ++NumIdentifierLookupHits;
   Found = *Pos;
+  if (Trait.hasMoreInformationInDependencies())
+// Look for the identifier in extra modules as they contain more info.
+return false;

jansvoboda11 wrote:

Nit: I'd wrap this in braces since it spans two lines.

https://github.com/llvm/llvm-project/pull/135471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] Use SmartMutex when visiting the AST (PR #135514)

2025-04-14 Thread Daniel Thornburgh via cfe-commits

https://github.com/mysterymath approved this pull request.


https://github.com/llvm/llvm-project/pull/135514
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang]Ensure correct handling of cleanup access control (#135668) (PR #135686)

2025-04-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oliver Hunt (ojhunt)


Changes

The P2719 implementation refactored diagnostics for cleanup delete, and as part 
of that I attempted to fix handling of inaccessible cleanup operator delete. 
Alas the new branch was incorrect as it was performing an implicit bool 
conversion, which resulted in friend accessible cleanup operators incorrectly 
being considered erroneous and the allocation path errored out. This error 
however did not get diagnosed, so the result was and so we did not actually 
error out before codegen.

Added both Sema and CodeGen tests to cover this.

---
Full diff: https://github.com/llvm/llvm-project/pull/135686.diff


3 Files Affected:

- (modified) clang/lib/Sema/SemaExprCXX.cpp (+3-2) 
- (added) clang/test/CodeGenCXX/bug135668.cpp (+38) 
- (added) clang/test/SemaCXX/bug135668.cpp (+25) 


``diff
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 16a39f8b5a4dd..dfb5824a1c3d7 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1929,8 +1929,9 @@ static bool CheckDeleteOperator(Sema &S, SourceLocation 
StartLoc,
 }
 return true;
   }
-
-  return S.CheckAllocationAccess(StartLoc, Range, NamingClass, Decl, Diagnose);
+  Sema::AccessResult Accessible =
+  S.CheckAllocationAccess(StartLoc, Range, NamingClass, Decl, Diagnose);
+  return Accessible == Sema::AR_inaccessible;
 }
 
 /// Select the correct "usual" deallocation function to use from a selection of
diff --git a/clang/test/CodeGenCXX/bug135668.cpp 
b/clang/test/CodeGenCXX/bug135668.cpp
new file mode 100644
index 0..08743bd36bf5b
--- /dev/null
+++ b/clang/test/CodeGenCXX/bug135668.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 %s -triple arm64-apple-macosx -emit-llvm -fcxx-exceptions 
-fexceptions -std=c++23 -o - | FileCheck  %s
+
+class TestClass {
+  public:
+   TestClass();
+   int field = 0;
+   friend class Foo;
+   static void * operator new(unsigned long size);
+  private:
+   static void operator delete(void *p);
+ };
+
+class Foo {
+public:
+  int test_method();
+};
+
+int Foo::test_method() {
+  TestClass *obj = new TestClass() ;
+  return obj->field;
+}
+
+// CHECK-LABEL: define noundef i32 @_ZN3Foo11test_methodEv
+// CHECK: [[THIS_ADDR:%.*]] = alloca ptr, align 8
+// CHECK: [[OBJ:%.*]] = alloca ptr, align 8
+// CHECK: store ptr %this, ptr [[THIS_ADDR]], align 8
+// CHECK: [[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
+// CHECK: [[ALLOCATION:%.*]] = call noundef ptr @_ZN9TestClassnwEm(i64 noundef 
4)
+// CHECK: [[INITIALIZEDOBJ:%.*]] = invoke noundef ptr @_ZN9TestClassC1Ev(ptr 
noundef nonnull align 4 dereferenceable(4) [[ALLOCATION]])
+// CHECK-NEXT:  to label %[[INVOKE_CONT:.*]] unwind label %[[LPAD:.*]]
+// CHECK: [[INVOKE_CONT]]:
+// CHECK: store ptr [[ALLOCATION]], ptr [[OBJ]], align 8
+// CHECK: [[OBJPTR:%.*]] = load ptr, ptr [[OBJ]], align 8
+// CHECK: [[FIELDPTR:%.*]] = getelementptr inbounds nuw %class.TestClass, ptr 
[[OBJPTR]], i32 0, i32 0
+// CHECK: [[FIELD:%.*]] = load i32, ptr [[FIELDPTR]], align 4
+// CHECK: ret i32 [[FIELD]]
+// CHECK: [[LPAD]]:
+// CHECK: call void @_ZN9TestClassdlEPv(ptr noundef [[ALLOCATION]]) #3
diff --git a/clang/test/SemaCXX/bug135668.cpp b/clang/test/SemaCXX/bug135668.cpp
new file mode 100644
index 0..96d3d4abfd3ef
--- /dev/null
+++ b/clang/test/SemaCXX/bug135668.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple arm64-apple-macosx -Wall -fsyntax-only -verify %s 
-std=c++26 -fexceptions -fcxx-exceptions
+// expected-no-diagnostics
+
+// This test makes sure that we don't erroneously consider an accessible 
operator
+// delete to be inaccessible, and then discard the entire new expression.
+
+class TestClass {
+public:
+  TestClass();
+  int field = 0;
+  friend class Foo;
+  static void * operator new(unsigned long size);
+private:
+  static void operator delete(void *p);
+};
+
+class Foo {
+public:
+  int test_method();
+};
+
+int Foo::test_method() {
+  TestClass *obj = new TestClass() ;
+  return obj->field;
+}

``




https://github.com/llvm/llvm-project/pull/135686
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [NFC] Fix xmipscmov extension name (PR #135647)

2025-04-14 Thread Craig Topper via cfe-commits

https://github.com/topperc approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/135647
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][DirectX] Always use Diagnostic Printer (PR #135655)

2025-04-14 Thread Eli Friedman via cfe-commits


@@ -2,7 +2,6 @@
 // RUN: not %clang_cc1 %s -o - -S -triple=amdgcn-amd-amdhsa 2>&1 | FileCheck %s
 
 void test_amdgcn_fence_failure() {
-
-  // CHECK: error: Unsupported atomic synchronization scope
+  // CHECK: error: :0:0: in function _Z25test_amdgcn_fence_failurev 
void (): Unsupported atomic synchronization scope

efriedma-quic wrote:

Current diagnostic without debug info:

```
:1:6: error: Unsupported atomic synchronization scope
1 | void test_amdgcn_fence_failure() {
  |  ^
```

Current diagnostic with debug info:

```
:3:3: error: Unsupported atomic synchronization scope
3 |   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "foobar");
  |   ^
```

The one without debug info could maybe be improved a bit, but throwing away the 
location info doesn't seem like the right approach.

https://github.com/llvm/llvm-project/pull/135655
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Forward two linker options to `lld` when ThinLTO is enabled for AMDGPU (PR #135690)

2025-04-14 Thread Shilei Tian via cfe-commits

https://github.com/shiltian created 
https://github.com/llvm/llvm-project/pull/135690

None

>From c1fd5f3f3493b4e5b553438f023fde77d721199b Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Mon, 14 Apr 2025 18:46:45 -0400
Subject: [PATCH] [Clang] Forward two linker options to `lld` when ThinLTO is
 enabled for AMDGPU

---
 clang/lib/Driver/ToolChains/Clang.cpp  | 11 ++-
 clang/test/Driver/openmp-offload-gpu.c | 15 +++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index a330972045550..65910e7fdaaa6 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -9270,9 +9270,18 @@ void LinkerWrapper::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (C.getDriver().getOffloadLTOMode() == LTOK_Full)
 CmdArgs.push_back(Args.MakeArgString(
 "--device-compiler=" + TC->getTripleString() + "=-flto=full"));
-  else if (C.getDriver().getOffloadLTOMode() == LTOK_Thin)
+  else if (C.getDriver().getOffloadLTOMode() == LTOK_Thin) {
 CmdArgs.push_back(Args.MakeArgString(
 "--device-compiler=" + TC->getTripleString() + "=-flto=thin"));
+if (TC->getTriple().isAMDGPU()) {
+  CmdArgs.push_back(
+  Args.MakeArgString("--device-linker=" + TC->getTripleString() +
+ "=-plugin-opt=-force-import-all"));
+  CmdArgs.push_back(
+  Args.MakeArgString("--device-linker=" + TC->getTripleString() +
+ "=-plugin-opt=-avail-extern-to-local"));
+}
+  }
 }
   }
 
diff --git a/clang/test/Driver/openmp-offload-gpu.c 
b/clang/test/Driver/openmp-offload-gpu.c
index 1f7e2996068c4..8a7edaef7cc45 100644
--- a/clang/test/Driver/openmp-offload-gpu.c
+++ b/clang/test/Driver/openmp-offload-gpu.c
@@ -378,3 +378,18 @@
 // RUN:  --offload-arch=sm_52 -nogpulibc -nogpuinc %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=LIBC-GPU %s
 // LIBC-GPU-NOT: clang-linker-wrapper{{.*}}"--device-linker"
+
+//
+// Check that ThinLTO works for OpenMP offloading.
+//
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp \
+// RUN: --offload-arch=gfx906 -foffload-lto=thin -nogpulib -nogpuinc %s 
2>&1 \
+// RUN:   | FileCheck --check-prefix=THINLTO-GFX906 %s
+// THINLTO-GFX906: --device-compiler=amdgcn-amd-amdhsa=-flto=thin
+// THINLTO-GFX906-SAME: 
--device-linker=amdgcn-amd-amdhsa=-plugin-opt=-force-import-all
+// THINLTO-GFX906-SAME: 
--device-linker=amdgcn-amd-amdhsa=-plugin-opt=-avail-extern-to-local
+//
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp \
+// RUN: --offload-arch=sm_52 -foffload-lto=thin -nogpulib -nogpuinc %s 
2>&1 \
+// RUN:   | FileCheck --check-prefix=THINLTO-SM52 %s
+// THINLTO-SM52: --device-compiler=nvptx64-nvidia-cuda=-flto=thin

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Forward two linker options to `lld` when ThinLTO is enabled for AMDGPU (PR #135690)

2025-04-14 Thread Shilei Tian via cfe-commits

https://github.com/shiltian edited 
https://github.com/llvm/llvm-project/pull/135690
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Forward two linker options to `lld` when ThinLTO is enabled for AMDGPU (PR #135690)

2025-04-14 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Shilei Tian (shiltian)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/135690.diff


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+10-1) 
- (modified) clang/test/Driver/openmp-offload-gpu.c (+15) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index a330972045550..65910e7fdaaa6 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -9270,9 +9270,18 @@ void LinkerWrapper::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (C.getDriver().getOffloadLTOMode() == LTOK_Full)
 CmdArgs.push_back(Args.MakeArgString(
 "--device-compiler=" + TC->getTripleString() + "=-flto=full"));
-  else if (C.getDriver().getOffloadLTOMode() == LTOK_Thin)
+  else if (C.getDriver().getOffloadLTOMode() == LTOK_Thin) {
 CmdArgs.push_back(Args.MakeArgString(
 "--device-compiler=" + TC->getTripleString() + "=-flto=thin"));
+if (TC->getTriple().isAMDGPU()) {
+  CmdArgs.push_back(
+  Args.MakeArgString("--device-linker=" + TC->getTripleString() +
+ "=-plugin-opt=-force-import-all"));
+  CmdArgs.push_back(
+  Args.MakeArgString("--device-linker=" + TC->getTripleString() +
+ "=-plugin-opt=-avail-extern-to-local"));
+}
+  }
 }
   }
 
diff --git a/clang/test/Driver/openmp-offload-gpu.c 
b/clang/test/Driver/openmp-offload-gpu.c
index 1f7e2996068c4..8a7edaef7cc45 100644
--- a/clang/test/Driver/openmp-offload-gpu.c
+++ b/clang/test/Driver/openmp-offload-gpu.c
@@ -378,3 +378,18 @@
 // RUN:  --offload-arch=sm_52 -nogpulibc -nogpuinc %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=LIBC-GPU %s
 // LIBC-GPU-NOT: clang-linker-wrapper{{.*}}"--device-linker"
+
+//
+// Check that ThinLTO works for OpenMP offloading.
+//
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp \
+// RUN: --offload-arch=gfx906 -foffload-lto=thin -nogpulib -nogpuinc %s 
2>&1 \
+// RUN:   | FileCheck --check-prefix=THINLTO-GFX906 %s
+// THINLTO-GFX906: --device-compiler=amdgcn-amd-amdhsa=-flto=thin
+// THINLTO-GFX906-SAME: 
--device-linker=amdgcn-amd-amdhsa=-plugin-opt=-force-import-all
+// THINLTO-GFX906-SAME: 
--device-linker=amdgcn-amd-amdhsa=-plugin-opt=-avail-extern-to-local
+//
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp \
+// RUN: --offload-arch=sm_52 -foffload-lto=thin -nogpulib -nogpuinc %s 
2>&1 \
+// RUN:   | FileCheck --check-prefix=THINLTO-SM52 %s
+// THINLTO-SM52: --device-compiler=nvptx64-nvidia-cuda=-flto=thin

``




https://github.com/llvm/llvm-project/pull/135690
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang]Ensure correct handling of cleanup access control (#135668) (PR #135686)

2025-04-14 Thread via cfe-commits

https://github.com/Sterling-Augustine approved this pull request.


https://github.com/llvm/llvm-project/pull/135686
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)

2025-04-14 Thread via cfe-commits

https://github.com/jeremyd2019 updated 
https://github.com/llvm/llvm-project/pull/135691

>From 7bb8bc392d2ea0a0deabb69117da3305ac3137af Mon Sep 17 00:00:00 2001
From: Jeremy Drake 
Date: Mon, 14 Apr 2025 10:37:59 -0700
Subject: [PATCH] [Clang] [Driver] add a Cygwin ToolChain

Add a new Cygwin toolchain that just goes through the motions to
initialize the Generic_GCC base properly.  This allows removing some
old, almost certainly wrong hard-coded paths from
Lex/InitHeaderSearch.cpp

Signed-off-by: Jeremy Drake 
---
 clang/lib/Driver/CMakeLists.txt|   1 +
 clang/lib/Driver/Driver.cpp|   4 +
 clang/lib/Driver/ToolChains/Cygwin.cpp | 102 +
 clang/lib/Driver/ToolChains/Cygwin.h   |  33 
 clang/lib/Driver/ToolChains/Gnu.cpp|  21 +
 clang/lib/Lex/InitHeaderSearch.cpp |  86 +
 6 files changed, 164 insertions(+), 83 deletions(-)
 create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp
 create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h

diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 5bdb6614389cf..e72525e99d517 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -51,6 +51,7 @@ add_clang_library(clangDriver
   ToolChains/CrossWindows.cpp
   ToolChains/CSKYToolChain.cpp
   ToolChains/Cuda.cpp
+  ToolChains/Cygwin.cpp
   ToolChains/Darwin.cpp
   ToolChains/DragonFly.cpp
   ToolChains/Flang.cpp
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 90d8e823d1d02..9b2264bbc9eaa 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -17,6 +17,7 @@
 #include "ToolChains/Clang.h"
 #include "ToolChains/CrossWindows.h"
 #include "ToolChains/Cuda.h"
+#include "ToolChains/Cygwin.h"
 #include "ToolChains/Darwin.h"
 #include "ToolChains/DragonFly.h"
 #include "ToolChains/FreeBSD.h"
@@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
   case llvm::Triple::GNU:
 TC = std::make_unique(*this, Target, Args);
 break;
+  case llvm::Triple::Cygnus:
+TC = std::make_unique(*this, Target, Args);
+break;
   case llvm::Triple::Itanium:
 TC = std::make_unique(*this, Target,
   Args);
diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp 
b/clang/lib/Driver/ToolChains/Cygwin.cpp
new file mode 100644
index 0..62ac12923a9b9
--- /dev/null
+++ b/clang/lib/Driver/ToolChains/Cygwin.cpp
@@ -0,0 +1,102 @@
+//===--- Cygwin.cpp - Cygwin ToolChain Implementations *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Cygwin.h"
+#include "CommonArgs.h"
+#include "clang/Config/config.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/Options.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/VirtualFileSystem.h"
+
+using namespace clang::driver;
+using namespace clang::driver::toolchains;
+using namespace clang;
+using namespace llvm::opt;
+
+using tools::addPathIfExists;
+
+Cygwin::Cygwin(const Driver &D, const llvm::Triple &Triple, const ArgList 
&Args)
+: Generic_GCC(D, Triple, Args) {
+  GCCInstallation.init(Triple, Args);
+  std::string SysRoot = computeSysRoot();
+  ToolChain::path_list &PPaths = getProgramPaths();
+
+  Generic_GCC::PushPPaths(PPaths);
+
+  path_list &Paths = getFilePaths();
+
+  Generic_GCC::AddMultiarchPaths(D, SysRoot, "lib", Paths);
+
+  // Similar to the logic for GCC above, if we are currently running Clang
+  // inside of the requested system root, add its parent library path to those
+  // searched.
+  // FIXME: It's not clear whether we should use the driver's installed
+  // directory ('Dir' below) or the ResourceDir.
+  if (StringRef(D.Dir).starts_with(SysRoot))
+addPathIfExists(D, D.Dir + "/../lib", Paths);
+
+  addPathIfExists(D, SysRoot + "/lib", Paths);
+  addPathIfExists(D, SysRoot + "/usr/lib", Paths);
+  addPathIfExists(D, SysRoot + "/usr/lib/w32api", Paths);
+}
+
+void Cygwin::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
+   ArgStringList &CC1Args) const {
+  const Driver &D = getDriver();
+  std::string SysRoot = computeSysRoot();
+
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
+return;
+
+  if (!DriverArgs.hasArg(options::OPT_nostdlibinc))
+addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include");
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> P(D.ResourceDir);
+llvm::sys::path::append(P, "include");
+addSystemInclude(DriverArgs, CC1Args, P);
+  }
+
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  // Check for confi

[clang] [llvm] [NFC] Fix bot breakage introduced by #134753 (PR #135697)

2025-04-14 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx created 
https://github.com/llvm/llvm-project/pull/135697

This test needs the amdgpu target, and its absence wreaked havoc with some of 
the bots, therefore we now require it.

>From a988ecf63dc79d226c2f7aa1430f65d08256888b Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Tue, 8 Apr 2025 00:20:27 +0100
Subject: [PATCH 1/9] Re-order & adapt `hipstdpar` specific passes.

---
 clang/lib/CodeGen/BackendUtil.cpp |  8 
 clang/lib/Driver/ToolChains/HIPAMD.cpp|  7 ---
 .../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | 20 ---
 3 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7557cb8408921..fa5e12d4033a5 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1115,6 +1115,10 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   if (CodeGenOpts.LinkBitcodePostopt)
 MPM.addPass(LinkInModulesPass(BC));
 
+  if (LangOpts.HIPStdPar && !LangOpts.CUDAIsDevice &&
+  LangOpts.HIPStdParInterposeAlloc)
+  MPM.addPass(HipStdParAllocationInterpositionPass());
+
   // Add a verifier pass if requested. We don't have to do this if the action
   // requires code generation because there will already be a verifier pass in
   // the code-generation pipeline.
@@ -1178,10 +1182,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 return;
   }
 
-  if (LangOpts.HIPStdPar && !LangOpts.CUDAIsDevice &&
-  LangOpts.HIPStdParInterposeAlloc)
-MPM.addPass(HipStdParAllocationInterpositionPass());
-
   // Now that we have all of the passes ready, run them.
   {
 PrettyStackTraceString CrashInfo("Optimizer");
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index abb83701759ce..52e35a01be58d 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -231,10 +231,11 @@ void HIPAMDToolChain::addClangTargetOptions(
   CC1Args.append({"-fcuda-is-device", "-fno-threadsafe-statics"});
 
   if (!DriverArgs.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
-  false))
+  false)) {
 CC1Args.append({"-mllvm", "-amdgpu-internalize-symbols"});
-  if (DriverArgs.hasArgNoClaim(options::OPT_hipstdpar))
-CC1Args.append({"-mllvm", "-amdgpu-enable-hipstdpar"});
+if (DriverArgs.hasArgNoClaim(options::OPT_hipstdpar))
+  CC1Args.append({"-mllvm", "-amdgpu-enable-hipstdpar"});
+  }
 
   StringRef MaxThreadsPerBlock =
   DriverArgs.getLastArgValue(options::OPT_gpu_max_threads_per_block_EQ);
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 4b5c70f09155f..03b1693244879 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -802,17 +802,17 @@ void 
AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
 #define GET_PASS_REGISTRY "AMDGPUPassRegistry.def"
 #include "llvm/Passes/TargetPassRegistry.inc"
 
-  PB.registerPipelineStartEPCallback(
-  [](ModulePassManager &PM, OptimizationLevel Level) {
-if (EnableHipStdPar)
-  PM.addPass(HipStdParAcceleratorCodeSelectionPass());
-  });
-
   PB.registerPipelineEarlySimplificationEPCallback(
   [](ModulePassManager &PM, OptimizationLevel Level,
  ThinOrFullLTOPhase Phase) {
-if (!isLTOPreLink(Phase))
+if (!isLTOPreLink(Phase)) {
+  // When we are not using -fgpu-rdc, we can run accelerator code
+  // selection relatively early, but still after linking to prevent
+  // eager removal of potentially reachable symbols.
+  if (EnableHipStdPar)
+PM.addPass(HipStdParAcceleratorCodeSelectionPass());
   PM.addPass(AMDGPUPrintfRuntimeBindingPass());
+}
 
 if (Level == OptimizationLevel::O0)
   return;
@@ -883,6 +883,12 @@ void 
AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
 
   PB.registerFullLinkTimeOptimizationLastEPCallback(
   [this](ModulePassManager &PM, OptimizationLevel Level) {
+// When we are using -fgpu-rdc, we can onky run accelerator code
+// selection after linking to prevent, otherwise we end up removing
+// potentially reachable symbols that were exported as external in 
other
+// modules.
+if (EnableHipStdPar)
+  PM.addPass(HipStdParAcceleratorCodeSelectionPass());
 // We want to support the -lto-partitions=N option as "best effort".
 // For that, we need to lower LDS earlier in the pipeline before the
 // module is partitioned for codegen.

>From 5cd1abb217d7fb2dd1f33c94a4f285b9aacd8dde Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Tue, 8 Apr 2025 00:27:18 +0100
Subject: [PATCH 2/9] Fix formatting.

---
 clang/lib/CodeGen/BackendUtil.cpp | 2 +-
 1 file changed, 1 insertion(+)

[clang] [CIR] Upstream ArraySubscriptExpr from function parameter with pointer base (PR #135493)

2025-04-14 Thread Bruno Cardoso Lopes via cfe-commits


@@ -350,20 +350,87 @@ void func7() {
 // OGCG: %[[ARR:.*]] = alloca [1 x ptr], align 8
 // OGCG: call void @llvm.memset.p0.i64(ptr align 8 %[[ARR]], i8 0, i64 8, i1 
false)
 
-void func8(int p[10]) {}
-// CIR: cir.func @func8(%arg0: !cir.ptr
-// CIR: cir.alloca !cir.ptr, !cir.ptr>, ["p", init]
-
-// LLVM: define void @func8(ptr {{%.*}})
-// LLVM-NEXT: alloca ptr, i64 1, align 8
-
-// OGCG: alloca ptr, align 8
+void func8(int arr[10]) {
+  int e = arr[0];
+  int e2 = arr[1];
+}
 
-void func9(int pp[10][5]) {}
-// CIR: cir.func @func9(%arg0: !cir.ptr>
-// CIR: cir.alloca !cir.ptr>, 
!cir.ptr>>
+// CIR: cir.func @func8(%[[ARG:.*]]: !cir.ptr
+// CIR:  %[[ARR:.*]] = cir.alloca !cir.ptr, !cir.ptr>, 
["arr", init]
+// CIR:  %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr, ["e", init]
+// CIR:  %[[INIT_2:.*]] = cir.alloca !s32i, !cir.ptr, ["e2", init]
+// CIR:  cir.store %[[ARG]], %[[ARR]] : !cir.ptr, 
!cir.ptr>
+// CIR:  %[[IDX:.*]] = cir.const #cir.int<0> : !s32i
+// CIR:  %[[TMP_1:.*]] = cir.load %[[ARR]] : !cir.ptr>, 
!cir.ptr
+// CIR:  %[[ELE_0:.*]] = cir.ptr_stride(%[[TMP_1]] : !cir.ptr, %[[IDX]] 
: !s32i), !cir.ptr
+// CIR:  %[[TMP_2:.*]] = cir.load %[[ELE_0]] : !cir.ptr, !s32i
+// CIR:  cir.store %[[TMP_2]], %[[INIT]] : !s32i, !cir.ptr
+// CIR:  %[[IDX_1:.*]] = cir.const #cir.int<1> : !s32i
+// CIR:  %[[TMP_3:.*]] = cir.load %[[ARR]] : !cir.ptr>, 
!cir.ptr
+// CIR:  %[[ELE_1:.*]] = cir.ptr_stride(%[[TMP_3]] : !cir.ptr, 
%[[IDX_1]] : !s32i), !cir.ptr
+// CIR:  %[[TMP_4:.*]] = cir.load %[[ELE_1]] : !cir.ptr, !s32i
+// CIR:  cir.store %[[TMP_4]], %[[INIT_2]] : !s32i, !cir.ptr
+
+// LLVM: define void @func8(ptr %[[ARG:.*]])
+// LLVM:  %[[ARR:.*]] = alloca ptr, i64 1, align 8
+// LLVM:  %[[INIT:.*]] = alloca i32, i64 1, align 4
+// LLVM:  %[[INIT_2:.*]] = alloca i32, i64 1, align 4
+// LLVM:  store ptr %[[ARG]], ptr %[[ARR]], align 8
+// LLVM:  %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8
+// LLVM:  %[[ELE_0:.*]] = getelementptr i32, ptr %[[TMP_1]], i64 0
+// LLVM:  %[[TMP_2:.*]] = load i32, ptr %[[ELE_0]], align 4
+// LLVM:  store i32 %[[TMP_2]], ptr %[[INIT]], align 4
+// LLVM:  %[[TMP_3:.*]] = load ptr, ptr %[[ARR]], align 8
+// LLVM:  %[[ELE_1:.*]] = getelementptr i32, ptr %[[TMP_3]], i64 1
+// LLVM:  %[[TMP_4:.*]] = load i32, ptr %[[ELE_1]], align 4
+// LLVM:  store i32 %[[TMP_4]], ptr %[[INIT_2]], align 4
+
+// OGCG: %[[ARR:.*]] = alloca ptr, align 8
+// OGCG: %[[INIT:.*]] = alloca i32, align 4
+// OGCG: %[[INIT_2:.*]] = alloca i32, align 4
+// OGCG: store ptr {{%.*}}, ptr %[[ARR]], align 8
+// OGCG: %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8
+// OGCG: %[[ELE_0:.*]] = getelementptr inbounds i32, ptr %[[TMP_1]], i64 0
+// OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ELE_0]], align 4
+// OGCG: store i32 %[[TMP_2]], ptr %[[INIT]], align 4
+// OGCG: %[[TMP_3:.*]] = load ptr, ptr %[[ARR]], align 8
+// OGCG: %[[ELE_1:.*]] = getelementptr inbounds i32, ptr %[[TMP_3]], i64 1
+// OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ELE_1]], align 4
+// OGCG: store i32 %[[TMP_2]], ptr %[[INIT_2]], align 4
 
-// LLVM: define void @func9(ptr {{%.*}})
-// LLVM-NEXT: alloca ptr, i64 1, align 8
+void func9(int arr[10][5]) {
+  int e = arr[1][2];
+}
 
-// OGCG: alloca ptr, align 8
+// CIR: cir.func @func9(%[[ARG:.*]]: !cir.ptr>
+// CIR:  %[[ARR:.*]] = cir.alloca !cir.ptr>, 
!cir.ptr>>, ["arr", init]
+// CIR:  %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr, ["e", init]
+// CIR:  cir.store %[[ARG]], %[[ARR]] : !cir.ptr>, 
!cir.ptr>>
+// CIR:  %[[IDX:.*]] = cir.const #cir.int<2> : !s32i
+// CIR:  %[[IDX_1:.*]] = cir.const #cir.int<1> : !s32i
+// CIR:  %[[TMP_1:.*]] = cir.load %[[ARR]] : 
!cir.ptr>>, !cir.ptr>
+// CIR:  %[[ARR_1:.*]] = cir.ptr_stride(%[[TMP_1]] : !cir.ptr>, %[[IDX_1]] : !s32i), !cir.ptr>
+// CIR:  %[[ARR_1_PTR:.*]] = cir.cast(array_to_ptrdecay, %[[ARR_1]] : 
!cir.ptr>), !cir.ptr
+// CIR:  %[[ARR_1_2:.*]] = cir.ptr_stride(%[[ARR_1_PTR]] : !cir.ptr, 
%[[IDX]] : !s32i), !cir.ptr
+// CIR:  %[[TMP_2:.*]] = cir.load %[[ARR_1_2]] : !cir.ptr, !s32i
+// CIR:  cir.store %[[TMP_2]], %[[INIT]] : !s32i, !cir.ptr
+
+// LLVM: define void @func9(ptr %[[ARG:.*]])
+// LLVM:  %[[ARR:.*]] = alloca ptr, i64 1, align 8
+// LLVM:  %[[INIT:.*]] = alloca i32, i64 1, align 4
+// LLVM:  store ptr %[[ARG]], ptr %[[ARR]], align 8
+// LLVM:  %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8
+// LLVM:  %[[ARR_1:.*]] = getelementptr [5 x i32], ptr %[[TMP_1]], i64 1
+// LLVM:  %[[ARR_1_PTR:.*]] = getelementptr i32, ptr %[[ARR_1]], i32 0

bcardosolopes wrote:

You might need to change similar in the incubator

https://github.com/llvm/llvm-project/pull/135493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 984ec70 - Minor documentation update.

2025-04-14 Thread Peter Collingbourne via cfe-commits

Author: Peter Collingbourne
Date: 2025-04-14T19:50:37-07:00
New Revision: 984ec70b61cb57b00e622a21b259aaf11775c5f0

URL: 
https://github.com/llvm/llvm-project/commit/984ec70b61cb57b00e622a21b259aaf11775c5f0
DIFF: 
https://github.com/llvm/llvm-project/commit/984ec70b61cb57b00e622a21b259aaf11775c5f0.diff

LOG: Minor documentation update.

Added: 


Modified: 
clang/docs/ControlFlowIntegrity.rst

Removed: 




diff  --git a/clang/docs/ControlFlowIntegrity.rst 
b/clang/docs/ControlFlowIntegrity.rst
index a88271faf6b42..2f2f8ccf4481b 100644
--- a/clang/docs/ControlFlowIntegrity.rst
+++ b/clang/docs/ControlFlowIntegrity.rst
@@ -19,11 +19,12 @@ of undefined behavior that can potentially allow attackers 
to subvert the
 program's control flow. These schemes have been optimized for performance,
 allowing developers to enable them in release builds.
 
-To enable Clang's available CFI schemes, use the flag ``-fsanitize=cfi``.
-You can also enable a subset of available :ref:`schemes `.
-As currently implemented, all schemes rely on link-time optimization (LTO);
-so it is required to specify ``-flto``, and the linker used must support LTO,
-for example via the `gold plugin`_.
+To enable Clang's available CFI schemes, use the flag
+``-fsanitize=cfi``. You can also enable a subset of available
+:ref:`schemes `. As currently implemented, all schemes
+except for ``kcfi`` rely on link-time optimization (LTO); so it is
+required to specify ``-flto`` or ``-flto=thin``, and the linker used
+must support LTO, for example via the `gold plugin`_.
 
 To allow the checks to be implemented efficiently, the program must
 be structured such that certain object files are compiled with CFI



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][CodeGen][OpenCL] Add `-fno-delete-null-pointer-checks` to avoid UB. NFC. (PR #135602)

2025-04-14 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.


https://github.com/llvm/llvm-project/pull/135602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] SiFive CLIC Support (PR #132481)

2025-04-14 Thread Kito Cheng via cfe-commits

https://github.com/kito-cheng approved this pull request.

LGTM :)

https://github.com/llvm/llvm-project/pull/132481
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][tests] Add missing FileCheck check, NFC (PR #135687)

2025-04-14 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida created 
https://github.com/llvm/llvm-project/pull/135687

None

>From d105489358661b0cd38b447592ff3e69a5641a7c Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Mon, 14 Apr 2025 15:01:45 -0700
Subject: [PATCH] [clang][tests] Add missing FileCheck check, NFC

---
 clang/test/ClangScanDeps/prebuilt-modules-in-stable-dirs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/test/ClangScanDeps/prebuilt-modules-in-stable-dirs.c 
b/clang/test/ClangScanDeps/prebuilt-modules-in-stable-dirs.c
index bf9d178686abc..acacda1466b59 100644
--- a/clang/test/ClangScanDeps/prebuilt-modules-in-stable-dirs.c
+++ b/clang/test/ClangScanDeps/prebuilt-modules-in-stable-dirs.c
@@ -26,6 +26,8 @@
 // PCH_DEP: "is-in-stable-directories": true
 // PCH_DEP: "name": "A"
 
+// PCH_DEP-NOT: "is-in-stable-directories": true
+
 // Verify is-in-stable-directories is only assigned to the module that only 
depends on A.
 // CLIENT-NOT: "is-in-stable-directories": true
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Mips] Fix clang compile error when -march=p5600 with -mmsa (PR #132679)

2025-04-14 Thread via cfe-commits

yingopq wrote:

Ping.

https://github.com/llvm/llvm-project/pull/132679
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang]Ensure correct handling of cleanup access control (#135668) (PR #135686)

2025-04-14 Thread Oliver Hunt via cfe-commits

https://github.com/ojhunt created 
https://github.com/llvm/llvm-project/pull/135686

The P2719 implementation refactored diagnostics for cleanup delete, and as part 
of that I attempted to fix handling of inaccessible cleanup operator delete. 
Alas the new branch was incorrect as it was performing an implicit bool 
conversion, which resulted in friend accessible cleanup operators incorrectly 
being considered erroneous and the allocation path errored out. This error 
however did not get diagnosed, so the result was and so we did not actually 
error out before codegen.

Added both Sema and CodeGen tests to cover this.

>From c0549c4bca817342f5d65bbecf86053cb4182553 Mon Sep 17 00:00:00 2001
From: Oliver Hunt 
Date: Mon, 14 Apr 2025 15:02:46 -0700
Subject: [PATCH] [Clang]Ensure correct handling of access control in P2719
 diagnostics (#135668)

The P2719 implementation refactored diagnostics for cleanup delete, and as
part of that I attempted to fix handling of inaccessible cleanup operator
delete. Alas the new branch was incorrect as it was performing an implicit
bool conversion, which resulted in friend accessible cleanup operators
incorrectly being considered erroneous and the allocation path errored out.
This error however did not get diagnosed, so the result was and so we did
not actually error out before codegen.

Added both Sema and CodeGen tests to cover this.
---
 clang/lib/Sema/SemaExprCXX.cpp  |  5 ++--
 clang/test/CodeGenCXX/bug135668.cpp | 38 +
 clang/test/SemaCXX/bug135668.cpp| 25 +++
 3 files changed, 66 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/bug135668.cpp
 create mode 100644 clang/test/SemaCXX/bug135668.cpp

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 16a39f8b5a4dd..712c33e152877 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1929,8 +1929,9 @@ static bool CheckDeleteOperator(Sema &S, SourceLocation 
StartLoc,
 }
 return true;
   }
-
-  return S.CheckAllocationAccess(StartLoc, Range, NamingClass, Decl, Diagnose);
+  Sema::AccessResult Accessible =
+S.CheckAllocationAccess(StartLoc, Range, NamingClass, Decl, Diagnose);
+  return Accessible == Sema::AR_inaccessible;
 }
 
 /// Select the correct "usual" deallocation function to use from a selection of
diff --git a/clang/test/CodeGenCXX/bug135668.cpp 
b/clang/test/CodeGenCXX/bug135668.cpp
new file mode 100644
index 0..08743bd36bf5b
--- /dev/null
+++ b/clang/test/CodeGenCXX/bug135668.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 %s -triple arm64-apple-macosx -emit-llvm -fcxx-exceptions 
-fexceptions -std=c++23 -o - | FileCheck  %s
+
+class TestClass {
+  public:
+   TestClass();
+   int field = 0;
+   friend class Foo;
+   static void * operator new(unsigned long size);
+  private:
+   static void operator delete(void *p);
+ };
+
+class Foo {
+public:
+  int test_method();
+};
+
+int Foo::test_method() {
+  TestClass *obj = new TestClass() ;
+  return obj->field;
+}
+
+// CHECK-LABEL: define noundef i32 @_ZN3Foo11test_methodEv
+// CHECK: [[THIS_ADDR:%.*]] = alloca ptr, align 8
+// CHECK: [[OBJ:%.*]] = alloca ptr, align 8
+// CHECK: store ptr %this, ptr [[THIS_ADDR]], align 8
+// CHECK: [[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
+// CHECK: [[ALLOCATION:%.*]] = call noundef ptr @_ZN9TestClassnwEm(i64 noundef 
4)
+// CHECK: [[INITIALIZEDOBJ:%.*]] = invoke noundef ptr @_ZN9TestClassC1Ev(ptr 
noundef nonnull align 4 dereferenceable(4) [[ALLOCATION]])
+// CHECK-NEXT:  to label %[[INVOKE_CONT:.*]] unwind label %[[LPAD:.*]]
+// CHECK: [[INVOKE_CONT]]:
+// CHECK: store ptr [[ALLOCATION]], ptr [[OBJ]], align 8
+// CHECK: [[OBJPTR:%.*]] = load ptr, ptr [[OBJ]], align 8
+// CHECK: [[FIELDPTR:%.*]] = getelementptr inbounds nuw %class.TestClass, ptr 
[[OBJPTR]], i32 0, i32 0
+// CHECK: [[FIELD:%.*]] = load i32, ptr [[FIELDPTR]], align 4
+// CHECK: ret i32 [[FIELD]]
+// CHECK: [[LPAD]]:
+// CHECK: call void @_ZN9TestClassdlEPv(ptr noundef [[ALLOCATION]]) #3
diff --git a/clang/test/SemaCXX/bug135668.cpp b/clang/test/SemaCXX/bug135668.cpp
new file mode 100644
index 0..96d3d4abfd3ef
--- /dev/null
+++ b/clang/test/SemaCXX/bug135668.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple arm64-apple-macosx -Wall -fsyntax-only -verify %s 
-std=c++26 -fexceptions -fcxx-exceptions
+// expected-no-diagnostics
+
+// This test makes sure that we don't erroneously consider an accessible 
operator
+// delete to be inaccessible, and then discard the entire new expression.
+
+class TestClass {
+public:
+  TestClass();
+  int field = 0;
+  friend class Foo;
+  static void * operator new(unsigned long size);
+private:
+  static void operator delete(void *p);
+};
+
+class Foo {
+public:
+  int test_method();
+};
+
+int Foo::test_method() {
+  TestClass *obj = new TestClass() ;
+  return obj->field;
+}

___
cfe-commits mailing list
cfe-commits@li

[clang] [clang] [CodeGen] fix crash when Ty isDependentType in CodeGenFunction::EmitAutoVarAlloca (PR #135643)

2025-04-14 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

I'm not really sure how to go about reducing a testcase in that case; it's not 
something I've ever run into myself.  Please post on Discourse 
(https://discourse.llvm.org/); maybe someone else has some ideas.

https://github.com/llvm/llvm-project/pull/135643
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][frontend] Make `CompilerInstance::FailedModules` thread-safe (PR #135473)

2025-04-14 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 closed 
https://github.com/llvm/llvm-project/pull/135473
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][frontend] Make `CompilerInstance::FailedModules` thread-safe (PR #135473)

2025-04-14 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `flang-x86_64-windows` 
running on `minipc-ryzen-win` while building `clang` at step 6 
"build-unified-tree".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/166/builds/994


Here is the relevant piece of the build log for the reference

```
Step 6 (build-unified-tree) failure: build (failure)
...
74.093 [138/11/74] Linking CXX executable bin\llvm-rtdyld.exe
74.094 [138/10/75] Linking CXX executable bin\llvm-strings.exe
74.096 [138/9/76] Linking CXX executable bin\llvm-sim.exe
75.197 [138/8/77] Copying llvm-locstats into 
C:/buildbot/flang-x86_64-windows/build/./bin
75.330 [138/7/78] Linking CXX executable bin\llvm-tli-checker.exe
75.909 [138/6/79] Linking CXX executable bin\yaml2obj.exe
75.910 [138/5/80] Linking CXX executable bin\verify-uselistorder.exe
76.199 [138/4/81] Building CXX object 
tools\clang\lib\Frontend\CMakeFiles\obj.clangFrontend.dir\PrecompiledPreamble.cpp.obj
77.716 [137/4/82] Building CXX object 
tools\clang\lib\Frontend\CMakeFiles\obj.clangFrontend.dir\CompilerInvocation.cpp.obj
83.859 [136/4/83] Building CXX object 
tools\clang\lib\Frontend\CMakeFiles\obj.clangFrontend.dir\InterfaceStubFunctionsConsumer.cpp.obj
FAILED: 
tools/clang/lib/Frontend/CMakeFiles/obj.clangFrontend.dir/InterfaceStubFunctionsConsumer.cpp.obj
 
C:\buildbot\bin\cl.exe  /nologo /TP -DCLANG_BUILD_STATIC -DGTEST_HAS_RTTI=0 
-DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS 
-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS 
-D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS 
-D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D__STDC_LIMIT_MACROS 
-IC:\buildbot\flang-x86_64-windows\build\tools\clang\lib\Frontend 
-IC:\buildbot\flang-x86_64-windows\llvm-project\clang\lib\Frontend 
-IC:\buildbot\flang-x86_64-windows\llvm-project\clang\include 
-IC:\buildbot\flang-x86_64-windows\build\tools\clang\include 
-IC:\buildbot\flang-x86_64-windows\build\include 
-IC:\buildbot\flang-x86_64-windows\llvm-project\llvm\include /DWIN32 /D_WINDOWS 
  /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 
-wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 
-wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 
-wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 
-wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 -wd4275 -w14062 -we4238 
/Gw /O2 /Ob2  -std:c++17 -MD  /EHs-c- /GR- -UNDEBUG /showIncludes 
/Fotools\clang\lib\Frontend\CMakeFiles\obj.clangFrontend.dir\InterfaceStubFunctionsConsumer.cpp.obj
 /Fdtools\clang\lib\Frontend\CMakeFiles\obj.clangFrontend.dir\ /FS -c 
C:\buildbot\flang-x86_64-windows\llvm-project\clang\lib\Frontend\InterfaceStubFunctionsConsumer.cpp
C:\buildbot\flang-x86_64-windows\llvm-project\clang\lib\Frontend\InterfaceStubFunctionsConsumer.cpp(342):
 fatal error C1001: Internal compiler error.
(compiler file 'msc1.cpp', line 1533)
 To work around this problem, try simplifying or changing the program near the 
locations listed above.
If possible please provide a repro here: 
https://developercommunity.visualstudio.com 
Please choose the Technical Support command on the Visual C++ 
 Help menu, or open the Technical Support help file for more information
INTERNAL COMPILER ERROR in 'C:\Program Files\Microsoft Visual 
Studio\2022\Community\VC\Tools\MSVC\14.43.34808\bin\Hostx64\x64\cl.exe'
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
91.803 [136/3/84] Building CXX object 
lib\CodeGen\AsmPrinter\CMakeFiles\LLVMAsmPrinter.dir\AsmPrinter.cpp.obj
92.453 [136/2/85] Building CXX object 
tools\clang\lib\Index\CMakeFiles\obj.clangIndex.dir\IndexingAction.cpp.obj
96.155 [136/1/86] Building CXX object lib\LTO\CMakeFiles\LLVMLTO.dir\LTO.cpp.obj
ninja: build stopped: subcommand failed.

```



https://github.com/llvm/llvm-project/pull/135473
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Enable making `CompilerInstance` VFS thread-safe (PR #135737)

2025-04-14 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 created 
https://github.com/llvm/llvm-project/pull/135737

The `llvm::vfs::FileSystem` interface makes no promises around thread-safety. 
To enable making `CompilerInstance` thread-safe, this PR allows passing an 
explicit VFS to `cloneForModuleCompile()`. This will be used from the 
dependency scanner.

>From 388447be4ef30fdf0470cf21db1a9675519d894d Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Fri, 11 Apr 2025 10:13:49 -0700
Subject: [PATCH] [clang] Enable making `CompilerInstance` VFS thread-safe

The `llvm::vfs::FileSystem` interface makes no promises around thread-safety. 
To enable making `CompilerInstance` thread-safe, this PR allows passing an 
explicit VFS to `cloneForModuleCompile()`. This will be used from the 
dependency scanner.
---
 .../include/clang/Frontend/CompilerInstance.h | 15 +++---
 clang/lib/Frontend/CompilerInstance.cpp   | 28 +++
 2 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 41dc7f1fef461..d70f5c45b3d38 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -845,18 +845,25 @@ class CompilerInstance : public ModuleLoader {
   /// Creates a \c CompilerInstance for compiling a module.
   ///
   /// This expects a properly initialized \c FrontendInputFile.
+  ///
+  /// Explicitly-specified \c VFS takes precedence over the VFS of this 
instance
+  /// when creating the clone and also prevents \c FileManager sharing.
   std::unique_ptr cloneForModuleCompileImpl(
   SourceLocation ImportLoc, StringRef ModuleName, FrontendInputFile Input,
-  StringRef OriginalModuleMapFile, StringRef ModuleFileName);
+  StringRef OriginalModuleMapFile, StringRef ModuleFileName,
+  IntrusiveRefCntPtr VFS = nullptr);
 
 public:
   /// Creates a new \c CompilerInstance for compiling a module.
   ///
   /// This takes care of creating appropriate \c FrontendInputFile for
   /// public/private frameworks, inferred modules and such.
-  std::unique_ptr
-  cloneForModuleCompile(SourceLocation ImportLoc, Module *Module,
-StringRef ModuleFileName);
+  ///
+  /// Explicitly-specified \c VFS takes precedence over the VFS of this 
instance
+  /// when creating the clone and also prevents \c FileManager sharing.
+  std::unique_ptr cloneForModuleCompile(
+  SourceLocation ImportLoc, Module *Module, StringRef ModuleFileName,
+  IntrusiveRefCntPtr VFS = nullptr);
 
   /// Compile a module file for the given module, using the options
   /// provided by the importing compiler instance. Returns true if the module
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 243e0a3c15b05..fa6b137338f26 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1152,7 +1152,8 @@ static Language getLanguageFromOptions(const LangOptions 
&LangOpts) {
 
 std::unique_ptr CompilerInstance::cloneForModuleCompileImpl(
 SourceLocation ImportLoc, StringRef ModuleName, FrontendInputFile Input,
-StringRef OriginalModuleMapFile, StringRef ModuleFileName) {
+StringRef OriginalModuleMapFile, StringRef ModuleFileName,
+IntrusiveRefCntPtr VFS) {
   // Construct a compiler invocation for creating this module.
   auto Invocation = std::make_shared(getInvocation());
 
@@ -1212,19 +1213,21 @@ std::unique_ptr 
CompilerInstance::cloneForModuleCompileImpl(
   auto &Inv = *Invocation;
   Instance.setInvocation(std::move(Invocation));
 
+  if (VFS) {
+Instance.createFileManager(std::move(VFS));
+  } else if (FrontendOpts.ModulesShareFileManager) {
+Instance.setFileManager(&getFileManager());
+  } else {
+Instance.createFileManager(&getVirtualFileSystem());
+  }
+
   Instance.createDiagnostics(
-  getVirtualFileSystem(),
+  Instance.getVirtualFileSystem(),
   new ForwardingDiagnosticConsumer(getDiagnosticClient()),
   /*ShouldOwnClient=*/true);
-
   if (llvm::is_contained(DiagOpts.SystemHeaderWarningsModules, ModuleName))
 Instance.getDiagnostics().setSuppressSystemWarnings(false);
 
-  if (FrontendOpts.ModulesShareFileManager) {
-Instance.setFileManager(&getFileManager());
-  } else {
-Instance.createFileManager(&getVirtualFileSystem());
-  }
   Instance.createSourceManager(Instance.getFileManager());
   SourceManager &SourceMgr = Instance.getSourceManager();
 
@@ -1318,7 +1321,8 @@ static OptionalFileEntryRef 
getPublicModuleMap(FileEntryRef File,
 }
 
 std::unique_ptr CompilerInstance::cloneForModuleCompile(
-SourceLocation ImportLoc, Module *Module, StringRef ModuleFileName) {
+SourceLocation ImportLoc, Module *Module, StringRef ModuleFileName,
+IntrusiveRefCntPtr VFS) {
   StringRef ModuleName = Module->getTopLevelModuleName();
 
   InputKind IK(getLanguageFromOptions(getLangOpts()), InputKind::ModuleMap);

[clang] [clang] Enable making `CompilerInstance` VFS thread-safe (PR #135737)

2025-04-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jan Svoboda (jansvoboda11)


Changes

The `llvm::vfs::FileSystem` interface makes no promises around thread-safety. 
To enable making `CompilerInstance` thread-safe, this PR allows passing an 
explicit VFS to `cloneForModuleCompile()`. This will be used from the 
dependency scanner.

---
Full diff: https://github.com/llvm/llvm-project/pull/135737.diff


2 Files Affected:

- (modified) clang/include/clang/Frontend/CompilerInstance.h (+11-4) 
- (modified) clang/lib/Frontend/CompilerInstance.cpp (+17-11) 


``diff
diff --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 41dc7f1fef461..d70f5c45b3d38 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -845,18 +845,25 @@ class CompilerInstance : public ModuleLoader {
   /// Creates a \c CompilerInstance for compiling a module.
   ///
   /// This expects a properly initialized \c FrontendInputFile.
+  ///
+  /// Explicitly-specified \c VFS takes precedence over the VFS of this 
instance
+  /// when creating the clone and also prevents \c FileManager sharing.
   std::unique_ptr cloneForModuleCompileImpl(
   SourceLocation ImportLoc, StringRef ModuleName, FrontendInputFile Input,
-  StringRef OriginalModuleMapFile, StringRef ModuleFileName);
+  StringRef OriginalModuleMapFile, StringRef ModuleFileName,
+  IntrusiveRefCntPtr VFS = nullptr);
 
 public:
   /// Creates a new \c CompilerInstance for compiling a module.
   ///
   /// This takes care of creating appropriate \c FrontendInputFile for
   /// public/private frameworks, inferred modules and such.
-  std::unique_ptr
-  cloneForModuleCompile(SourceLocation ImportLoc, Module *Module,
-StringRef ModuleFileName);
+  ///
+  /// Explicitly-specified \c VFS takes precedence over the VFS of this 
instance
+  /// when creating the clone and also prevents \c FileManager sharing.
+  std::unique_ptr cloneForModuleCompile(
+  SourceLocation ImportLoc, Module *Module, StringRef ModuleFileName,
+  IntrusiveRefCntPtr VFS = nullptr);
 
   /// Compile a module file for the given module, using the options
   /// provided by the importing compiler instance. Returns true if the module
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 243e0a3c15b05..fa6b137338f26 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1152,7 +1152,8 @@ static Language getLanguageFromOptions(const LangOptions 
&LangOpts) {
 
 std::unique_ptr CompilerInstance::cloneForModuleCompileImpl(
 SourceLocation ImportLoc, StringRef ModuleName, FrontendInputFile Input,
-StringRef OriginalModuleMapFile, StringRef ModuleFileName) {
+StringRef OriginalModuleMapFile, StringRef ModuleFileName,
+IntrusiveRefCntPtr VFS) {
   // Construct a compiler invocation for creating this module.
   auto Invocation = std::make_shared(getInvocation());
 
@@ -1212,19 +1213,21 @@ std::unique_ptr 
CompilerInstance::cloneForModuleCompileImpl(
   auto &Inv = *Invocation;
   Instance.setInvocation(std::move(Invocation));
 
+  if (VFS) {
+Instance.createFileManager(std::move(VFS));
+  } else if (FrontendOpts.ModulesShareFileManager) {
+Instance.setFileManager(&getFileManager());
+  } else {
+Instance.createFileManager(&getVirtualFileSystem());
+  }
+
   Instance.createDiagnostics(
-  getVirtualFileSystem(),
+  Instance.getVirtualFileSystem(),
   new ForwardingDiagnosticConsumer(getDiagnosticClient()),
   /*ShouldOwnClient=*/true);
-
   if (llvm::is_contained(DiagOpts.SystemHeaderWarningsModules, ModuleName))
 Instance.getDiagnostics().setSuppressSystemWarnings(false);
 
-  if (FrontendOpts.ModulesShareFileManager) {
-Instance.setFileManager(&getFileManager());
-  } else {
-Instance.createFileManager(&getVirtualFileSystem());
-  }
   Instance.createSourceManager(Instance.getFileManager());
   SourceManager &SourceMgr = Instance.getSourceManager();
 
@@ -1318,7 +1321,8 @@ static OptionalFileEntryRef 
getPublicModuleMap(FileEntryRef File,
 }
 
 std::unique_ptr CompilerInstance::cloneForModuleCompile(
-SourceLocation ImportLoc, Module *Module, StringRef ModuleFileName) {
+SourceLocation ImportLoc, Module *Module, StringRef ModuleFileName,
+IntrusiveRefCntPtr VFS) {
   StringRef ModuleName = Module->getTopLevelModuleName();
 
   InputKind IK(getLanguageFromOptions(getLangOpts()), InputKind::ModuleMap);
@@ -1363,7 +1367,8 @@ std::unique_ptr 
CompilerInstance::cloneForModuleCompile(
 return cloneForModuleCompileImpl(
 ImportLoc, ModuleName,
 FrontendInputFile(ModuleMapFilePath, IK, IsSystem),
-ModMap.getModuleMapFileForUniquing(Module)->getName(), ModuleFileName);
+ModMap.getModuleMapFileForUniquing(Module)->getName(), ModuleFileName,
+std::move(VFS));

[clang] [clang] [CodeGen] fix crash when Ty isDependentType in CodeGenFunction::EmitAutoVarAlloca (PR #135643)

2025-04-14 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

Also, if you're okay with publicly posting your code, it's fine to file a bug 
with an unreduced testcase.

https://github.com/llvm/llvm-project/pull/135643
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][driver] Suppress gnu-line-marker when saving temps (PR #134621)

2025-04-14 Thread via cfe-commits

macurtis-amd wrote:

> I don't, but I wonder what's the GCC behavior. It seems to suppress the 
> diagnostic when processing a .i file.

Diagnostic seems to be suppressed by 
[-fpreprocessed](https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html#index-fpreprocessed),
 which is implicit if you pass a `.i` file to `gcc` and passed explicitly to 
`cc1` when using `-save-temps`.

I guess the analogous clang option is `-x`?

https://github.com/llvm/llvm-project/pull/134621
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] [Sema] Fix a crash when a `friend` function is redefined as deleted (PR #135679)

2025-04-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Sirraide)


Changes

NB: This only fixes the crash introduced in Clang 19; we still accept this code 
even though we shouldn’t:
```c++
struct S {
friend int f() { return 3; }
friend int f() = delete;
};
```
I tried figuring out a way to diagnose this redeclaration, but it seems tricky 
because I kept running into issues around defaulted comparison operators. From 
my testing, however, this fix here would still be required even once we do 
start diagnosing this.

Fixes #135506.

---
Full diff: https://github.com/llvm/llvm-project/pull/135679.diff


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1-1) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+5-10) 
- (modified) clang/test/SemaCXX/cxx2c-delete-with-message.cpp (+30) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 11f62bc881b03..037f9f6fe79e0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -389,7 +389,7 @@ Bug Fixes in This Version
 
 #if 1 ? 1 : 9
 #endif
-
+- Fixed a crash when a ``friend`` function is redefined as deleted. (#GH135506)
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e9805c345b6af..8fd857d347895 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16178,16 +16178,11 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
 // This is meant to pop the context added in ActOnStartOfFunctionDef().
 ExitFunctionBodyRAII ExitRAII(*this, isLambdaCallOperator(FD));
 if (FD) {
-  // If this is called by Parser::ParseFunctionDefinition() after marking
-  // the declaration as deleted, and if the deleted-function-body contains
-  // a message (C++26), then a DefaultedOrDeletedInfo will have already 
been
-  // added to store that message; do not overwrite it in that case.
-  //
-  // Since this would always set the body to 'nullptr' in that case anyway,
-  // which is already done when the function decl is initially created,
-  // always skipping this irrespective of whether there is a delete message
-  // should not be a problem.
-  if (!FD->isDeletedAsWritten())
+  // The function body and the DefaultedOrDeletedInfo, if present, use
+  // the same storage; don't overwrite the latter if the former is null
+  // (the body is initialised to null anyway, so even if the latter isn't
+  // present, this would still be a no-op).
+  if (Body)
 FD->setBody(Body);
   FD->setWillHaveBody(false);
 
diff --git a/clang/test/SemaCXX/cxx2c-delete-with-message.cpp 
b/clang/test/SemaCXX/cxx2c-delete-with-message.cpp
index 22e65d902ecd4..5609da18c05aa 100644
--- a/clang/test/SemaCXX/cxx2c-delete-with-message.cpp
+++ b/clang/test/SemaCXX/cxx2c-delete-with-message.cpp
@@ -271,3 +271,33 @@ void operators() {
   if (to_int_int) {} // expected-error {{attempt to use a deleted function: 
deleted (TO, operator bool)}}
   static_cast(to_int_int); // expected-error {{static_cast from 'TO' to 'bool' uses deleted function: deleted (TO, operator bool)}}
 };
+
+namespace gh135506 {
+struct a {
+  // FIXME: We currently don't diagnose these invalid redeclarations if the
+  // second declaration is defaulted or deleted. This probably needs to be
+  // handled in ParseCXXInlineMethodDef() after parsing the defaulted/deleted
+  // body.
+  friend consteval int f() { return 3; }
+  friend consteval int f() = delete("foo");
+
+  friend consteval int g() { return 3; }
+  friend consteval int g() = delete;
+
+  friend int h() { return 3; }
+  friend int h() = delete;
+
+  friend consteval int i() = delete; // expected-note {{previous definition is 
here}}
+  friend consteval int i() { return 3; } // expected-error {{redefinition of 
'i'}}
+};
+
+struct b {
+  friend consteval bool operator==(b, b) { return true; } // expected-note 
{{previous declaration is here}}
+  friend consteval bool operator==(b, b) = default; // expected-error 
{{defaulting this equality comparison operator is not allowed because it was 
already declared outside the class}}
+};
+
+struct c {
+  friend consteval bool operator==(c, c) = default; // expected-note 
{{previous definition is here}}
+  friend consteval bool operator==(c, c) { return true; } // expected-error 
{{redefinition of 'operator=='}}
+};
+}

``




https://github.com/llvm/llvm-project/pull/135679
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Reland][Clang][CodeGen][UBSan] Add more precise attributes to recoverable ubsan handlers (PR #135135)

2025-04-14 Thread Eli Friedman via cfe-commits


@@ -3615,6 +3618,23 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
 .addAttribute(llvm::Attribute::NoUnwind);
   }
   B.addUWTableAttr(llvm::UWTableKind::Default);
+  // Add more precise attributes to recoverable ubsan handlers for better
+  // optimizations.
+  if (CGF.CGM.getCodeGenOpts().OptimizationLevel > 0 && MayReturn) {
+// __ubsan_handle_dynamic_type_cache_miss reads the vtable, which is also
+// accessible by the current module.
+if (CheckHandler != SanitizerHandler::DynamicTypeCacheMiss) {
+  llvm::MemoryEffects ME =
+  llvm::MemoryEffects::argMemOnly(llvm::ModRefInfo::Ref) |
+  llvm::MemoryEffects::inaccessibleMemOnly();
+  if (MayReadFromPtrToInt)
+ME |= llvm::MemoryEffects::readOnly();
+  B.addMemoryAttr(ME);
+}
+// If the handler does not return, it must interact with the environment in
+// an observable way.
+B.addAttribute(llvm::Attribute::MustProgress);

efriedma-quic wrote:

I know this isn't new... but I don't think this "mustprogress" marking actually 
does anything useful.  "mustprogress" is more a characteristic of function 
definitions, not calls.

https://github.com/llvm/llvm-project/pull/135135
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SYCL] Basic code generation for SYCL kernel caller offload entry point functions. (PR #133030)

2025-04-14 Thread Tom Honermann via cfe-commits


@@ -14794,9 +14803,36 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   }
 }
 
-static SYCLKernelInfo BuildSYCLKernelInfo(CanQualType KernelNameType,
+static SYCLKernelInfo BuildSYCLKernelInfo(ASTContext &Context,
+  CanQualType KernelNameType,
   const FunctionDecl *FD) {
-  return {KernelNameType, FD};
+  // Host and device compilation may use different ABIs and different ABIs
+  // may allocate name mangling discriminators differently. A discriminator
+  // override is used to ensure consistent discriminator allocation across
+  // host and device compilation.
+  auto DeviceDiscriminatorOverrider =
+  [](ASTContext &Ctx, const NamedDecl *ND) -> std::optional {
+if (const auto *RD = dyn_cast(ND))
+  if (RD->isLambda())

tahonermann wrote:

Sorry, but I need a more concrete description of the concern to know what I'm 
looking for. I audited uses of `isGenericLambda()` that I thought might be 
relevant and I didn't find anything that suggested relevance for device 
mangling context. Can we postpone this until the upcoming PR that revises the 
name mangling approach? That PR will come with tests and I can ensure that 
generic lambdas are exercised.

https://github.com/llvm/llvm-project/pull/133030
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] add option --offload-jobs=N (PR #135229)

2025-04-14 Thread Yaxun Liu via cfe-commits


@@ -57,6 +57,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
+#include "llvm/Support/ThreadPool.h"

yxsamliu wrote:

will remove

https://github.com/llvm/llvm-project/pull/135229
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][analyzer] Document configuration options (PR #135169)

2025-04-14 Thread Balazs Benics via cfe-commits


@@ -143,6 +143,32 @@ if (LLVM_ENABLE_SPHINX)
 gen_rst_file_from_td(DiagnosticsReference.rst -gen-diag-docs 
../include/clang/Basic/Diagnostic.td "${docs_targets}")
 gen_rst_file_from_td(ClangCommandLineReference.rst -gen-opt-docs 
../include/clang/Driver/ClangOptionDocs.td "${docs_targets}")
 
+# Another generated file from a different source
+set(docs_tools_dir ${CMAKE_CURRENT_SOURCE_DIR}/tools)
+set(aopts_rst_rel_path analyzer/user-docs/Options.rst)
+set(aopts_rst "${CMAKE_CURRENT_BINARY_DIR}/${aopts_rst_rel_path}")
+set(analyzeroptions_def 
"${CMAKE_CURRENT_SOURCE_DIR}/../include/clang/StaticAnalyzer/Core/AnalyzerOptions.def")
+set(aopts_rst_in "${CMAKE_CURRENT_SOURCE_DIR}/${aopts_rst_rel_path}.in")
+set(generate_aopts_docs generate_analyzer_options_docs.py)
+add_custom_command(
+  OUTPUT ${aopts_rst}
+  COMMAND ${Python3_EXECUTABLE} ${generate_aopts_docs} -i 
${analyzeroptions_def} -t ${aopts_rst_in} -o ${aopts_rst}
+  WORKING_DIRECTORY ${docs_tools_dir}
+  VERBATIM
+  COMMENT "Generating ${aopts_rst}"
+  DEPENDS ${docs_tools_dir}/${generate_aopts_docs}
+  ${aopts_rst_in}
+  copy-clang-rst-docs
+  )
+add_custom_target(generate-analyzer-options-rst DEPENDS ${aopts_rst})
+foreach(target ${docs_targets})
+  add_dependencies(${target} generate-analyzer-options-rst)
+endforeach()

steakhal wrote:

Should really all the doc targets depend on this new dep?

https://github.com/llvm/llvm-project/pull/135169
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][DirectX] Always use Diagnostic Printer (PR #135655)

2025-04-14 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl closed 
https://github.com/llvm/llvm-project/pull/135655
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Forward two linker options to `lld` when ThinLTO is enabled for AMDGPU (PR #135690)

2025-04-14 Thread Shilei Tian via cfe-commits

shiltian wrote:

* **#135690** https://app.graphite.dev/github/pr/llvm/llvm-project/135690?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/135690?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/135690
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Fix dependent local class instantiation bugs (PR #134038)

2025-04-14 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov approved this pull request.

LGTM as well.

https://github.com/llvm/llvm-project/pull/134038
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [liblc] only check filename part of the source for avoiding duplication (PR #135710)

2025-04-14 Thread Wenju He via cfe-commits

https://github.com/wenju-he created 
https://github.com/llvm/llvm-project/pull/135710

llvm-diff shows this PR has no changes to amdgcn--amdhsa.bc.

Motivation is that in our downstream the same category of target built-ins, 
e.g. math, are organized in several different folders. For example, in target 
SOURCES we have math-common/cos.cl, while in generic SOURCES it is math/cos.cl. 
Based on current check rule that compares both folder name and base filename, 
target math-common/cos.cl won't override math/cos.cl when collecting source 
files from SOURCES files in cmake function libclc_configure_lib_source.

With this PR, we allow folder name to be different in the process.

A notable change of this PR is that two entries in SOURCES with the same base 
filename must not implements the same built-in.

>From 1a05195eb897f93c84f6c6bc22f211ad7457fc27 Mon Sep 17 00:00:00 2001
From: Wenju He 
Date: Mon, 14 Apr 2025 17:17:15 -0700
Subject: [PATCH] [liblc] only check filename part of the source for avoiding
 duplication

llvm-diff shows this PR has no changes to amdgcn--amdhsa.bc.

Motivation is that in our downstream the same category of target
built-ins, e.g. math, are organized in several different folders.
For example, in target SOURCES we have math-common/cos.cl, while in
generic SOURCES it is math/cos.cl. Based on current check rule that
compares both folder name and base filename, target math-common/cos.cl
won't override math/cos.cl when collecting source files from SOURCES
files in cmake function libclc_configure_lib_source.

With this PR, we allow folder name to be different in the process.

A notable change of this PR is that two entries in SOURCES with the same
base filename must not implements the same built-in.
---
 libclc/cmake/modules/AddLibclc.cmake | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/libclc/cmake/modules/AddLibclc.cmake 
b/libclc/cmake/modules/AddLibclc.cmake
index 154f4ea8f6cf5..3be2bf231eb30 100644
--- a/libclc/cmake/modules/AddLibclc.cmake
+++ b/libclc/cmake/modules/AddLibclc.cmake
@@ -466,16 +466,22 @@ function(libclc_configure_lib_source LIB_FILE_LIST)
   ## Add the generated convert files here to prevent adding the ones listed in
   ## SOURCES
   set( rel_files ${${LIB_FILE_LIST}} ) # Source directory input files, 
relative to the root dir
-  set( objects ${${LIB_FILE_LIST}} )   # A "set" of already-added input files
+  # A "set" of already-added input files
+  set( objects )
+  foreach( f ${${LIB_FILE_LIST}} )
+get_filename_component( name ${f} NAME )
+list( APPEND objects ${name} )
+  endforeach()
 
   foreach( l ${source_list} )
 file( READ ${l} file_list )
 string( REPLACE "\n" ";" file_list ${file_list} )
 get_filename_component( dir ${l} DIRECTORY )
 foreach( f ${file_list} )
+  get_filename_component( name ${f} NAME )
   # Only add each file once, so that targets can 'specialize' builtins
-  if( NOT ${f} IN_LIST objects )
-list( APPEND objects ${f} )
+  if( NOT ${name} IN_LIST objects )
+list( APPEND objects ${name} )
 list( APPEND rel_files ${dir}/${f} )
   endif()
 endforeach()

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Upstream ArraySubscriptExpr from function parameter with pointer base (PR #135493)

2025-04-14 Thread Andy Kaylor via cfe-commits

https://github.com/andykaylor approved this pull request.

lgtm

https://github.com/llvm/llvm-project/pull/135493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f4ff209 - [Clang] Forward two linker options to `lld` when ThinLTO is enabled for AMDGPU (#135690)

2025-04-14 Thread via cfe-commits

Author: Shilei Tian
Date: 2025-04-14T20:57:20-04:00
New Revision: f4ff209e4384d8073f36fb7da9916b33f1140edf

URL: 
https://github.com/llvm/llvm-project/commit/f4ff209e4384d8073f36fb7da9916b33f1140edf
DIFF: 
https://github.com/llvm/llvm-project/commit/f4ff209e4384d8073f36fb7da9916b33f1140edf.diff

LOG: [Clang] Forward two linker options to `lld` when ThinLTO is enabled for 
AMDGPU (#135690)

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/openmp-offload-gpu.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index a330972045550..65910e7fdaaa6 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -9270,9 +9270,18 @@ void LinkerWrapper::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (C.getDriver().getOffloadLTOMode() == LTOK_Full)
 CmdArgs.push_back(Args.MakeArgString(
 "--device-compiler=" + TC->getTripleString() + "=-flto=full"));
-  else if (C.getDriver().getOffloadLTOMode() == LTOK_Thin)
+  else if (C.getDriver().getOffloadLTOMode() == LTOK_Thin) {
 CmdArgs.push_back(Args.MakeArgString(
 "--device-compiler=" + TC->getTripleString() + "=-flto=thin"));
+if (TC->getTriple().isAMDGPU()) {
+  CmdArgs.push_back(
+  Args.MakeArgString("--device-linker=" + TC->getTripleString() +
+ "=-plugin-opt=-force-import-all"));
+  CmdArgs.push_back(
+  Args.MakeArgString("--device-linker=" + TC->getTripleString() +
+ "=-plugin-opt=-avail-extern-to-local"));
+}
+  }
 }
   }
 

diff  --git a/clang/test/Driver/openmp-offload-gpu.c 
b/clang/test/Driver/openmp-offload-gpu.c
index 1f7e2996068c4..8a7edaef7cc45 100644
--- a/clang/test/Driver/openmp-offload-gpu.c
+++ b/clang/test/Driver/openmp-offload-gpu.c
@@ -378,3 +378,18 @@
 // RUN:  --offload-arch=sm_52 -nogpulibc -nogpuinc %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=LIBC-GPU %s
 // LIBC-GPU-NOT: clang-linker-wrapper{{.*}}"--device-linker"
+
+//
+// Check that ThinLTO works for OpenMP offloading.
+//
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp \
+// RUN: --offload-arch=gfx906 -foffload-lto=thin -nogpulib -nogpuinc %s 
2>&1 \
+// RUN:   | FileCheck --check-prefix=THINLTO-GFX906 %s
+// THINLTO-GFX906: --device-compiler=amdgcn-amd-amdhsa=-flto=thin
+// THINLTO-GFX906-SAME: 
--device-linker=amdgcn-amd-amdhsa=-plugin-opt=-force-import-all
+// THINLTO-GFX906-SAME: 
--device-linker=amdgcn-amd-amdhsa=-plugin-opt=-avail-extern-to-local
+//
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp \
+// RUN: --offload-arch=sm_52 -foffload-lto=thin -nogpulib -nogpuinc %s 
2>&1 \
+// RUN:   | FileCheck --check-prefix=THINLTO-SM52 %s
+// THINLTO-SM52: --device-compiler=nvptx64-nvidia-cuda=-flto=thin



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] consistently quote expressions in diagnostics (PR #134769)

2025-04-14 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/134769

>From 7a777961125a31a8e721f2f78354a3b21c0a06b2 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Mon, 7 Apr 2025 22:44:20 -0300
Subject: [PATCH] [clang] consistently quote expressions in diagnostics

This changes the expression diagnostic printer to always add quotes,
and removes hardcoded quotes from the diagnostic format strings.

In some cases, a placeholder could be filled by either an expression
or as a string. In order to quote this consistently, a new modifier
was added, which can be used to quote strings.

One diagnostic was relying on unquoted expressions in order to
generate code suggestions. This diagnostic is converted to use fixit
hints instead.
---
 clang/docs/InternalsManual.rst| 11 +++
 clang/docs/ReleaseNotes.rst   |  1 +
 .../include/clang/Basic/DiagnosticASTKinds.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  2 +-
 .../clang/Basic/DiagnosticSemaKinds.td| 70 ++-
 clang/lib/AST/ASTDiagnostic.cpp   |  2 -
 clang/lib/Basic/Diagnostic.cpp| 29 
 clang/lib/Sema/SemaChecking.cpp   |  5 +-
 clang/test/AST/ByteCode/literals.cpp  |  2 +-
 clang/test/CodeGenCXX/sections.cpp|  6 +-
 clang/test/FixIt/fixit-bool.cpp   |  7 ++
 clang/test/Modules/odr_hash.cpp   |  4 +-
 clang/test/OpenMP/declare_variant_messages.c  | 12 ++--
 .../test/OpenMP/declare_variant_messages.cpp  | 18 ++---
 ...bute_parallel_for_simd_linear_messages.cpp |  4 +-
 .../distribute_simd_linear_messages.cpp   |  2 +-
 clang/test/OpenMP/for_linear_messages.cpp |  2 +-
 .../test/OpenMP/for_simd_linear_messages.cpp  |  6 +-
 clang/test/OpenMP/for_simd_misc_messages.c|  2 +-
 .../masked_taskloop_simd_linear_messages.cpp  |  6 +-
 .../master_taskloop_simd_linear_messages.cpp  |  6 +-
 .../OpenMP/parallel_for_linear_messages.cpp   |  2 +-
 .../parallel_for_simd_linear_messages.cpp |  2 +-
 .../OpenMP/parallel_for_simd_misc_messages.c  |  2 +-
 ...l_masked_taskloop_simd_linear_messages.cpp |  8 +--
 ...l_master_taskloop_simd_linear_messages.cpp |  6 +-
 clang/test/OpenMP/simd_linear_messages.cpp|  6 +-
 clang/test/OpenMP/simd_misc_messages.c|  2 +-
 .../target_parallel_for_linear_messages.cpp   |  4 +-
 ...rget_parallel_for_simd_linear_messages.cpp |  4 +-
 .../OpenMP/target_simd_linear_messages.cpp|  4 +-
 ...bute_parallel_for_simd_linear_messages.cpp |  2 +-
 ..._teams_distribute_simd_linear_messages.cpp |  2 +-
 clang/test/OpenMP/task_affinity_messages.cpp  |  2 +-
 clang/test/OpenMP/task_depend_messages.cpp|  2 +-
 .../OpenMP/taskloop_simd_linear_messages.cpp  |  6 +-
 ...bute_parallel_for_simd_linear_messages.cpp |  2 +-
 .../teams_distribute_simd_linear_messages.cpp |  2 +-
 clang/test/Sema/code_align.c  |  4 +-
 clang/test/Sema/warn-int-in-bool-context.c| 24 +++
 .../Sema/warn-lifetime-analysis-nocfg.cpp | 26 +++
 .../test/SemaCXX/attr-lifetime-capture-by.cpp | 10 +--
 clang/test/SemaCXX/attr-lifetimebound.cpp | 14 ++--
 clang/test/SemaCXX/cxx2c-pack-indexing.cpp| 14 ++--
 clang/test/SemaCXX/warn-dangling-local.cpp|  6 +-
 .../test/SemaHLSL/BuiltIns/asuint-errors.hlsl |  8 +--
 .../test/SemaHLSL/BuiltIns/select-errors.hlsl |  2 +-
 .../SemaHLSL/BuiltIns/splitdouble-errors.hlsl | 24 +++
 .../SemaHLSL/Language/OutputParameters.hlsl   |  8 +--
 clang/test/SemaHLSL/parameter_modifiers.hlsl  |  4 +-
 clang/test/SemaOpenCL/to_addr_builtin.cl  |  6 +-
 .../TableGen/ClangDiagnosticsEmitter.cpp  |  5 ++
 52 files changed, 225 insertions(+), 189 deletions(-)
 create mode 100644 clang/test/FixIt/fixit-bool.cpp

diff --git a/clang/docs/InternalsManual.rst b/clang/docs/InternalsManual.rst
index a2b551b6f333e..353a5f094cb1c 100644
--- a/clang/docs/InternalsManual.rst
+++ b/clang/docs/InternalsManual.rst
@@ -416,6 +416,17 @@ Description:
   and the modifier indexes in the substitution are re-numbered accordingly. The
   substituted text must itself be a valid format string before substitution.
 
+**"quoted" format**
+
+Example:
+  ``"expression %quoted0 evaluates to 0"``
+Class:
+  ``String``
+Description:
+  This is a simple formatter which adds quotes around the given string.
+  This is useful when the argument could be a string in some cases, but
+  another class in other cases, and it needs to be quoted consistently.
+
 .. _internals-producing-diag:
 
 Producing the Diagnostic
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ca04d9ebd44c..d3130ab088674 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -314,6 +314,7 @@ Improvements to Clang's diagnostics
 - Clang now respects the current language mode when printing expressions in
   diagnostics. This fixes a bunch of `bool` being printed as `_Bool`, and also
   a bunch of HLSL types being printed as t

[clang] Fixed issue #128882: don't warn if 1st argument to 'getcwd' is NULL (PR #135720)

2025-04-14 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

https://github.com/llvm/llvm-project/pull/135720
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-14 Thread via cfe-commits

Sirraide wrote:

> Sorry about that. This PR had become so stale that there merge conflicts and 
> the easiest way to fix it was to squash because the conflicts were with 
> things I later removed.

I see, yeah, it happens; that’s unfortunate...


https://github.com/llvm/llvm-project/pull/106321
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fixed issue #128882: don't warn if 1st argument to 'getcwd' is NULL (PR #135720)

2025-04-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Sean McBride (seanm)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/135720.diff


1 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
(-1) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 9c0b79ab58618..34bab80307a04 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2663,7 +2663,6 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .Case({ArgumentCondition(1, WithinRange, Range(1, SizeMax)),
IsNull(Ret)},
   ErrnoNEZeroIrrelevant, GenericFailureMsg)
-.ArgConstraint(NotNull(ArgNo(0)))
 .ArgConstraint(
 BufferSize(/*Buffer*/ ArgNo(0), /*BufSize*/ ArgNo(1)))
 .ArgConstraint(

``




https://github.com/llvm/llvm-project/pull/135720
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 83344da - [Clang] Fix dependent local class instantiation bugs (#134038)

2025-04-14 Thread via cfe-commits

Author: Younan Zhang
Date: 2025-04-15T09:16:55+08:00
New Revision: 83344da69145a648aad3e0cd88eab4aaf60b2142

URL: 
https://github.com/llvm/llvm-project/commit/83344da69145a648aad3e0cd88eab4aaf60b2142
DIFF: 
https://github.com/llvm/llvm-project/commit/83344da69145a648aad3e0cd88eab4aaf60b2142.diff

LOG: [Clang] Fix dependent local class instantiation bugs (#134038)

This patch fixes two long-standing bugs that prevent Clang from
instantiating local class members inside a dependent context. These bugs
were introduced in commits 21eb1af469c3 and 919df9d75a.

21eb1af469c3 introduced a concept called eligible methods such that it
did an attempt to skip past ineligible method instantiation when
instantiating class members. Unfortunately, this broke the instantiation
chain for local classes - getTemplateInstantiationPattern() would fail
to find the correct definition pattern if the class was defined within a
partially transformed dependent context.

919df9d75a introduced a separate issue by incorrectly copying the
DeclarationNameInfo during function definition instantiation from the
template pattern, even though that DNI might contain a transformed
TypeSourceInfo. Since that TSI was already updated when the declaration
was instantiated, this led to inconsistencies. As a result, the final
instantiated function could lose track of the transformed declarations,
hence we crash: https://compiler-explorer.com/z/vjvoG76Tf.

This PR corrects them by

1. Removing the bypass logic for method instantiation. The eligible flag
is independent of instantiation and can be updated properly afterward,
so skipping instantiation is unnecessary.

2. Carefully handling TypeSourceInfo by creating a new instance that
preserves the pattern's source location while using the already
transformed type.

Fixes https://github.com/llvm/llvm-project/issues/59734
Fixes https://github.com/llvm/llvm-project/issues/132208

Added: 
clang/test/CodeGenCXX/local-class-instantiation.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ca04d9ebd44c..d551de0d4aabd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -434,6 +434,7 @@ Bug Fixes to C++ Support
   by template argument deduction.
 - Clang is now better at instantiating the function definition after its use 
inside
   of a constexpr lambda. (#GH125747)
+- Fixed a local class member function instantiation bug inside dependent 
lambdas. (#GH59734), (#GH132208)
 - Clang no longer crashes when trying to unify the types of arrays with
   certain 
diff erences in qualifiers (this could happen during template argument
   deduction or when building a ternary operator). (#GH97005)

diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index d2408a94ad0ab..0e81804f8c1e7 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -4126,9 +4126,6 @@ Sema::InstantiateClassMembers(SourceLocation 
PointOfInstantiation,
   if (FunctionDecl *Pattern =
   Function->getInstantiatedFromMemberFunction()) {
 
-if (Function->isIneligibleOrNotSelected())
-  continue;
-
 if (Function->getTrailingRequiresClause()) {
   ConstraintSatisfaction Satisfaction;
   if (CheckFunctionConstraints(Function, Satisfaction) ||

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 5c80077f294c6..bf5a882ba4f12 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5597,7 +5597,61 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
   Function->setLocation(PatternDecl->getLocation());
   Function->setInnerLocStart(PatternDecl->getInnerLocStart());
   Function->setRangeEnd(PatternDecl->getEndLoc());
-  Function->setDeclarationNameLoc(PatternDecl->getNameInfo().getInfo());
+  // Let the instantiation use the Pattern's DeclarationNameLoc, due to the
+  // following awkwardness:
+  //
+  //   1. There are out-of-tree users of getNameInfo().getSourceRange(), who
+  //   expect the source range of the instantiated declaration to be set to
+  //   point to the definition.
+  //
+  //   2. That getNameInfo().getSourceRange() might return the TypeLocInfo's
+  //   location it tracked.
+  //
+  //   3. Function might come from an (implicit) declaration, while the pattern
+  //   comes from a definition. In these cases, we need the PatternDecl's 
source
+  //   location.
+  //
+  // To that end, we need to more or less tweak the DeclarationNameLoc. 
However,
+  // we can't blindly copy the DeclarationNameLoc from the PatternDecl to the
+  // function,

[clang] [Clang] Fix dependent local class instantiation bugs (PR #134038)

2025-04-14 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 closed 
https://github.com/llvm/llvm-project/pull/134038
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] add option --offload-jobs=N (PR #135229)

2025-04-14 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/135229

>From 5c2283b01ac6a58e41df4260aecc01bcf463a0a9 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Thu, 10 Apr 2025 14:14:47 -0400
Subject: [PATCH] [Clang] add option --offload-jobs=N

for specifying number of threads for clang-linker-wrapper.
---
 clang/include/clang/Driver/Options.td |  4 
 clang/lib/Driver/ToolChains/Clang.cpp | 13 +
 clang/test/Driver/hip-options.hip | 17 +++--
 3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a9f3912e0773a..c9d2bc5e81976 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1234,6 +1234,10 @@ def offload_compression_level_EQ : Joined<["--"], 
"offload-compression-level=">,
   Flags<[HelpHidden]>,
   HelpText<"Compression level for offload device binaries (HIP only)">;
 
+def offload_jobs_EQ : Joined<["--"], "offload-jobs=">,
+  HelpText<"Specify the number of threads to use for device offloading tasks"
+   " during compilation.">;
+
 defm offload_via_llvm : BoolFOption<"offload-via-llvm",
   LangOpts<"OffloadViaLLVM">, DefaultFalse,
   PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 1de83baacff93..a330972045550 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1031,6 +1031,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const 
JobAction &JA,
 if (JA.isOffloading(Action::OFK_HIP)) {
   Args.ClaimAllArgs(options::OPT_offload_compress);
   Args.ClaimAllArgs(options::OPT_no_offload_compress);
+  Args.ClaimAllArgs(options::OPT_offload_jobs_EQ);
 }
 
 bool HasTarget = false;
@@ -9361,6 +9362,18 @@ void LinkerWrapper::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back(LinkArg);
 
   addOffloadCompressArgs(Args, CmdArgs);
+
+  if (Arg *A = Args.getLastArg(options::OPT_offload_jobs_EQ)) {
+int NumThreads;
+if (StringRef(A->getValue()).getAsInteger(10, NumThreads) ||
+NumThreads <= 0)
+  C.getDriver().Diag(diag::err_drv_invalid_int_value)
+  << A->getAsString(Args) << A->getValue();
+else
+  CmdArgs.push_back(
+  Args.MakeArgString("--wrapper-jobs=" + Twine(NumThreads)));
+  }
+
   const char *Exec =
   
Args.MakeArgString(getToolChain().GetProgramPath("clang-linker-wrapper"));
 
diff --git a/clang/test/Driver/hip-options.hip 
b/clang/test/Driver/hip-options.hip
index 29d23c1b6c8d9..a07dca3638565 100644
--- a/clang/test/Driver/hip-options.hip
+++ b/clang/test/Driver/hip-options.hip
@@ -243,6 +243,19 @@
 // NO-WARN-ATOMIC-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} 
"-Werror=atomic-alignment"
 // NO-WARN-ATOMIC-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} 
"-Wno-error=atomic-alignment"
 
-// Check --offload-compress does not cause warning.
+// Check --offload-compress --offload-jobs=N does not cause warning.
 // RUN: %clang -### -Werror --target=x86_64-unknown-linux-gnu -nogpuinc 
-nogpulib \
-// RUN:   --offload-arch=gfx1100 --offload-compress --offload-host-only -M %s
+// RUN:   --offload-arch=gfx1100 --offload-compress --offload-host-only -M %s \
+// RUN:   --offload-jobs=4
+
+// Check --offload-jobs=N option.
+
+// RUN: %clang -### -Werror --target=x86_64-unknown-linux-gnu -nogpuinc 
-nogpulib \
+// RUN:   --offload-arch=gfx1100 --offload-new-driver --offload-jobs=4 %s 2>&1 
| \
+// RUN:   FileCheck -check-prefix=JOBS %s
+// JOBS: clang-linker-wrapper{{.*}} "--wrapper-jobs=4"
+
+// RUN: not %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
+// RUN:   --offload-arch=gfx1100 --offload-new-driver --offload-jobs=0x4 %s 
2>&1 | \
+// RUN:   FileCheck -check-prefix=INVJOBS %s
+// INVJOBS: clang: error: invalid integral value '0x4' in '--offload-jobs=0x4'

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][CodeGen][OpenCL] Add `-fno-delete-null-pointer-checks` to avoid UB. NFC. (PR #135602)

2025-04-14 Thread Yingwei Zheng via cfe-commits


@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" 
-fno-delete-null-pointer-checks -emit-llvm -o - | FileCheck %s

dtcxzyw wrote:

The default optimization level for opencl frontend is O2 :)
https://github.com/llvm/llvm-project/blob/83344da69145a648aad3e0cd88eab4aaf60b2142/clang/lib/Frontend/CompilerInvocation.cpp#L717-L723

https://github.com/llvm/llvm-project/pull/135602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-04-14 Thread Oliver Hunt via cfe-commits

ojhunt wrote:

@Sterling-Augustine thank you!

https://github.com/llvm/llvm-project/pull/113510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM, AArch64] Fix passing of structures with aligned base classes (PR #135564)

2025-04-14 Thread John McCall via cfe-commits

https://github.com/rjmccall requested changes to this pull request.

Flagging as changes requested to at least verify that this doesn't change ABI 
for Darwin.

https://github.com/llvm/llvm-project/pull/135564
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 41892fc - [CLANG-CL] ignores Wpadded (#134426)

2025-04-14 Thread via cfe-commits

Author: Theo de Magalhaes
Date: 2025-04-14T14:17:49-07:00
New Revision: 41892fc4353d2dd705666783d799e79748467ed8

URL: 
https://github.com/llvm/llvm-project/commit/41892fc4353d2dd705666783d799e79748467ed8
DIFF: 
https://github.com/llvm/llvm-project/commit/41892fc4353d2dd705666783d799e79748467ed8.diff

LOG: [CLANG-CL] ignores Wpadded (#134426)

[clang] add support for -Wpadded on Windows

Implements the -Wpadded warning for --target=x86_64-windows-msvc etc.

Fixes #61702 .

Added: 
clang/test/SemaCXX/windows-Wpadded-bitfield.cpp
clang/test/SemaCXX/windows-Wpadded.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/RecordLayoutBuilder.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f9ba1bcf542ef..7ca04d9ebd44c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,6 +217,8 @@ Modified Compiler Flags
 
 - The compiler flag `-fbracket-depth` default value is increased from 256 to 
2048. (#GH94728)
 
+- `-Wpadded` option implemented for the `x86_64-windows-msvc` target. Fixes 
#61702
+
 Removed Compiler Flags
 -
 

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 3e756ab9b9bfe..ea353f88a8aec 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2274,9 +2274,9 @@ static unsigned getPaddingDiagFromTagKind(TagTypeKind 
Tag) {
   }
 }
 
-void ItaniumRecordLayoutBuilder::CheckFieldPadding(
-uint64_t Offset, uint64_t UnpaddedOffset, uint64_t UnpackedOffset,
-unsigned UnpackedAlign, bool isPacked, const FieldDecl *D) {
+static void CheckFieldPadding(const ASTContext &Context, bool IsUnion,
+  uint64_t Offset, uint64_t UnpaddedOffset,
+  const FieldDecl *D) {
   // We let objc ivars without warning, objc interfaces generally are not used
   // for padding tricks.
   if (isa(D))
@@ -2300,7 +2300,8 @@ void ItaniumRecordLayoutBuilder::CheckFieldPadding(
 if (D->getIdentifier()) {
   auto Diagnostic = D->isBitField() ? diag::warn_padded_struct_bitfield
 : diag::warn_padded_struct_field;
-  Diag(D->getLocation(), Diagnostic)
+  Context.getDiagnostics().Report(D->getLocation(),
+  Diagnostic)
   << getPaddingDiagFromTagKind(D->getParent()->getTagKind())
   << Context.getTypeDeclType(D->getParent()) << PadSize
   << (InBits ? 1 : 0) // (byte|bit)
@@ -2308,15 +2309,22 @@ void ItaniumRecordLayoutBuilder::CheckFieldPadding(
 } else {
   auto Diagnostic = D->isBitField() ? 
diag::warn_padded_struct_anon_bitfield
 : diag::warn_padded_struct_anon_field;
-  Diag(D->getLocation(), Diagnostic)
+  Context.getDiagnostics().Report(D->getLocation(),
+  Diagnostic)
   << getPaddingDiagFromTagKind(D->getParent()->getTagKind())
   << Context.getTypeDeclType(D->getParent()) << PadSize
   << (InBits ? 1 : 0); // (byte|bit)
 }
- }
- if (isPacked && Offset != UnpackedOffset) {
-   HasPackedField = true;
- }
+  }
+}
+
+void ItaniumRecordLayoutBuilder::CheckFieldPadding(
+uint64_t Offset, uint64_t UnpaddedOffset, uint64_t UnpackedOffset,
+unsigned UnpackedAlign, bool isPacked, const FieldDecl *D) {
+  ::CheckFieldPadding(Context, IsUnion, Offset, UnpaddedOffset, D);
+  if (isPacked && Offset != UnpackedOffset) {
+HasPackedField = true;
+  }
 }
 
 static const CXXMethodDecl *computeKeyFunction(ASTContext &Context,
@@ -2555,7 +2563,8 @@ struct MicrosoftRecordLayoutBuilder {
   typedef llvm::DenseMap BaseOffsetsMapTy;
   MicrosoftRecordLayoutBuilder(const ASTContext &Context,
EmptySubobjectMap *EmptySubobjects)
-  : Context(Context), EmptySubobjects(EmptySubobjects) {}
+  : Context(Context), EmptySubobjects(EmptySubobjects),
+RemainingBitsInField(0) {}
 
 private:
   MicrosoftRecordLayoutBuilder(const MicrosoftRecordLayoutBuilder &) = delete;
@@ -2642,8 +2651,6 @@ struct MicrosoftRecordLayoutBuilder {
   /// virtual base classes and their offsets in the record.
   ASTRecordLayout::VBaseOffsetsMapTy VBases;
   /// The number of remaining bits in our last bitfield allocation.
-  /// This value isn't meaningful unless LastFieldIsNonZeroWidthBitfield is
-  /// true.
   unsigned RemainingBitsInField;
   bool IsUnion : 1;
   /// True if the last field laid out was a bitfield and was not 0
@@ -3004,6 +3011,15 @@ void MicrosoftRecordLayoutBuilder::layoutField(const 
FieldDecl *FD) {
   } else {
 FieldOffset = Size.alignTo(Info.Alignment);
   }
+
+  uint64_t UnpaddedFielddOffsetInBits =
+  Context.toBits(DataSize) - RemainingBitsInField;
+
+  ::CheckFieldPadding(Context, IsUnion, Context.toBits(FieldO

[clang] [CLANG-CL] ignores Wpadded (PR #134426)

2025-04-14 Thread Eli Friedman via cfe-commits
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,Theo de
 Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes 
Message-ID:
In-Reply-To: 


https://github.com/efriedma-quic closed 
https://github.com/llvm/llvm-project/pull/134426
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AArch64] Change the coercion type of structs with pointer members. (PR #135064)

2025-04-14 Thread Eli Friedman via cfe-commits


@@ -485,6 +485,39 @@ ABIArgInfo AArch64ABIInfo::classifyArgumentType(QualType 
Ty, bool IsVariadicFn,
 }
 Size = llvm::alignTo(Size, Alignment);
 
+// If the Aggregate is made up of pointers, use an array of pointers for 
the
+// coerced type. This prevents having to convert ptr2int->int2ptr through
+// the call, allowing alias analysis to produce better code.
+std::function ContainsOnlyPointers = [&](QualType Ty) {
+  if (isEmptyRecord(getContext(), Ty, true))
+return false;
+  const RecordType *RT = Ty->getAs();
+  if (!RT)
+return false;
+  const RecordDecl *RD = RT->getDecl();
+  if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) {
+for (const auto &I : CXXRD->bases())
+  if (!ContainsOnlyPointers(I.getType()))
+return false;
+  }
+  return all_of(RD->fields(), [&](FieldDecl *FD) {
+QualType FDTy = FD->getType();
+if (FDTy->isArrayType())
+  FDTy = QualType(FDTy->getBaseElementTypeUnsafe(), 0);
+return (FDTy->isPointerOrReferenceType() &&
+getContext().getTypeSize(FDTy) == 64) ||
+   ContainsOnlyPointers(FDTy);
+  });
+};
+if (ContainsOnlyPointers(Ty)) {
+  assert((Size == 64 || Size == 128) &&
+ "Expected a 64 or 128bit struct containing pointers");
+  llvm::Type *PtrTy = llvm::PointerType::getUnqual(getVMContext());
+  if (Size == 128)
+PtrTy = llvm::ArrayType::get(PtrTy, 2);

efriedma-quic wrote:

`llvm::ArrayType::get(PtrTy, 2);` is unfortunately not correct if the alignment 
of the struct is 16 bytes.  (Usually a struct containing only pointers should 
be 8-byte-aligned, but you can override it with attributes.)

https://github.com/llvm/llvm-project/pull/135064
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Add range metadata for atomic load of boolean type. #131476 (PR #133546)

2025-04-14 Thread Jan Górski via cfe-commits

janagor wrote:

Oh, I see, I changed it.

https://github.com/llvm/llvm-project/pull/133546
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-04-14 Thread via cfe-commits

Sterling-Augustine wrote:

Yes it does. Here is a reduced repro:

```
augustine:~/crdc $ cat repro.ii
extern void* GetMem();

class MyFileMod {
 public:
  MyFileMod(int x, int y) {}
  void SetNext() {}
  friend class Foo;
 private:
  static void * operator new(unsigned long size) { return GetMem(); }
  static void * operator new[](unsigned long size) { return GetMem() ; }
  static void * operator new(unsigned long, void *p) { return p ; }
  static void * operator new[](unsigned long, void *p) { return p ; }
  static void operator delete(void *p) {  }
  static void operator delete[](void *p) {  }
  static void operator delete(void*, void*) {}
  static void operator delete[](void*, void*) {}
};

MyFileMod* f;

class Foo {
 public:
void Bar() {
MyFileMod *new_section = new MyFileMod(0, 0) ;
new_section->SetNext() ;
}
};
augustine:~/crdc $ ~/llvm/build/bin/clang++ repro.ii -std=gnu++20 
-Wuninitialized -Werror -c
repro.ii:25:13: error: variable 'new_section' is uninitialized when used here 
[-Werror,-Wuninitialized]
   25 | new_section->SetNext() ;
  | ^~~
repro.ii:24:35: note: initialize the variable 'new_section' to silence this 
warning
   24 | MyFileMod *new_section = new MyFileMod(0, 0) ;
  |   ^
  |= nullptr
1 error generated.
augustine:~/crdc $ 
```

https://github.com/llvm/llvm-project/pull/113510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][DirectX] Always use Diagnostic Printer (PR #135655)

2025-04-14 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl updated 
https://github.com/llvm/llvm-project/pull/135655

>From 7ec850f4a31cdd4554d813f759f519cb688652f9 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Mon, 14 Apr 2025 14:07:30 -0400
Subject: [PATCH 1/2] [Clang][DirectX] Always use Diagnostic Printer fixes
 #135654

In #128613 we added safe guards to prevent the lowering of just any
intrinsic in the backend. We used `DiagnosticInfoUnsupported` to do
this.

What we found was when using `opt` the diagnostic printer was called
but when using clang the diagnostic message was called.

Printing message in the clang version means we miss valuable debugging
information like function name and function type when LLVMContext was
only needed to call `getBestLocationFromDebugLoc`.
---
 clang/lib/CodeGen/CodeGenAction.cpp  | 10 --
 clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl |  7 +++
 2 files changed, 11 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 1f5eb427b566f..fbf7700d80a93 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -605,13 +605,11 @@ void BackendConsumer::UnsupportedDiagHandler(
 
   // Context will be nullptr for IR input files, we will construct the diag
   // message from llvm::DiagnosticInfoUnsupported.
-  if (Context != nullptr) {
+  if (Context != nullptr)
 Loc = getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
-MsgStream << D.getMessage();
-  } else {
-DiagnosticPrinterRawOStream DP(MsgStream);
-D.print(DP);
-  }
+
+  DiagnosticPrinterRawOStream DP(MsgStream);
+  D.print(DP);
 
   auto DiagType = D.getSeverity() == llvm::DS_Error
   ? diag::err_fe_backend_unsupported
diff --git a/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl 
b/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl
new file mode 100644
index 0..e2f8907c14d6d
--- /dev/null
+++ b/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl
@@ -0,0 +1,7 @@
+// RUN: not %clang_dxc -T lib_6_3 %s 2>&1 | FileCheck %s
+
+// CHECK: error: :0:0: in function llvm.vector.reduce.mul.v4i32 i32 
(<4 x i32>): Unsupported intrinsic for DXIL lowering
+
+export int vecReduceMulTest(int4 vec) {
+return __builtin_reduce_mul(vec);
+}

>From 4b9619c17f20b2ac541ef04cf1d1d044edca2907 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Mon, 14 Apr 2025 16:01:03 -0400
Subject: [PATCH 2/2] update test cases to new error format and restrict to
 correct target

---
 clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl | 2 +-
 clang/test/Sema/builtin-amdgcn-fence-failure.cpp | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl 
b/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl
index e2f8907c14d6d..a309132aa0595 100644
--- a/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl
+++ b/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl
@@ -1,4 +1,4 @@
-// RUN: not %clang_dxc -T lib_6_3 %s 2>&1 | FileCheck %s
+// RUN: %if clang-dxc %{not %clang_dxc -T lib_6_3 %s 2>&1 | FileCheck %s %}
 
 // CHECK: error: :0:0: in function llvm.vector.reduce.mul.v4i32 i32 
(<4 x i32>): Unsupported intrinsic for DXIL lowering
 
diff --git a/clang/test/Sema/builtin-amdgcn-fence-failure.cpp 
b/clang/test/Sema/builtin-amdgcn-fence-failure.cpp
index 651700cbb63ac..9630ea069a423 100644
--- a/clang/test/Sema/builtin-amdgcn-fence-failure.cpp
+++ b/clang/test/Sema/builtin-amdgcn-fence-failure.cpp
@@ -2,7 +2,6 @@
 // RUN: not %clang_cc1 %s -o - -S -triple=amdgcn-amd-amdhsa 2>&1 | FileCheck %s
 
 void test_amdgcn_fence_failure() {
-
-  // CHECK: error: Unsupported atomic synchronization scope
+  // CHECK: error: :0:0: in function _Z25test_amdgcn_fence_failurev 
void (): Unsupported atomic synchronization scope
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "foobar");
 }

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM, AArch64] Fix passing of structures with aligned base classes (PR #135564)

2025-04-14 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic edited 
https://github.com/llvm/llvm-project/pull/135564
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM, AArch64] Fix passing of structures with aligned base classes (PR #135564)

2025-04-14 Thread Eli Friedman via cfe-commits


@@ -1302,6 +1302,7 @@ ItaniumRecordLayoutBuilder::LayoutBase(const 
BaseSubobjectInfo *Base) {
 setSize(std::max(getSize(), Offset + Layout.getSize()));
 
   // Remember max struct/class alignment.
+  UnadjustedAlignment = std::max(UnadjustedAlignment, PreferredBaseAlign);

efriedma-quic wrote:

If other compilers agree, maybe it's not high-priority to update the spec... 
but it would be nice to have an explicit statement somewhere.



I was remembering that other targets have preferred alignment, but I guess on 
non-AIX targets that's only a thing outside of record layout.  But for clarity, 
please do fix it so it doesn't interact with preferred alignment stuff.

https://github.com/llvm/llvm-project/pull/135564
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] add option --offload-jobs=N (PR #135229)

2025-04-14 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/135229

>From 6aae774e5729779b1e9fd8fee792c06cbc00f29a Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Thu, 10 Apr 2025 14:14:47 -0400
Subject: [PATCH] [Clang] add option --offload-jobs=N

for specifying number of threads for clang-linker-wrapper.
---
 clang/include/clang/Driver/Options.td |  4 
 clang/lib/Driver/ToolChains/Clang.cpp | 14 ++
 clang/test/Driver/hip-options.hip | 17 +++--
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a9f3912e0773a..c9d2bc5e81976 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1234,6 +1234,10 @@ def offload_compression_level_EQ : Joined<["--"], 
"offload-compression-level=">,
   Flags<[HelpHidden]>,
   HelpText<"Compression level for offload device binaries (HIP only)">;
 
+def offload_jobs_EQ : Joined<["--"], "offload-jobs=">,
+  HelpText<"Specify the number of threads to use for device offloading tasks"
+   " during compilation.">;
+
 defm offload_via_llvm : BoolFOption<"offload-via-llvm",
   LangOpts<"OffloadViaLLVM">, DefaultFalse,
   PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 1de83baacff93..5155a7b089a9a 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -57,6 +57,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
+#include "llvm/Support/ThreadPool.h"
 #include "llvm/Support/YAMLParser.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/TargetParser/ARMTargetParserCommon.h"
@@ -1031,6 +1032,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const 
JobAction &JA,
 if (JA.isOffloading(Action::OFK_HIP)) {
   Args.ClaimAllArgs(options::OPT_offload_compress);
   Args.ClaimAllArgs(options::OPT_no_offload_compress);
+  Args.ClaimAllArgs(options::OPT_offload_jobs_EQ);
 }
 
 bool HasTarget = false;
@@ -9361,6 +9363,18 @@ void LinkerWrapper::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back(LinkArg);
 
   addOffloadCompressArgs(Args, CmdArgs);
+
+  if (Arg *A = Args.getLastArg(options::OPT_offload_jobs_EQ)) {
+int NumThreads;
+if (StringRef(A->getValue()).getAsInteger(10, NumThreads) ||
+NumThreads <= 0)
+  C.getDriver().Diag(diag::err_drv_invalid_int_value)
+  << A->getAsString(Args) << A->getValue();
+else
+  CmdArgs.push_back(
+  Args.MakeArgString("--wrapper-jobs=" + Twine(NumThreads)));
+  }
+
   const char *Exec =
   
Args.MakeArgString(getToolChain().GetProgramPath("clang-linker-wrapper"));
 
diff --git a/clang/test/Driver/hip-options.hip 
b/clang/test/Driver/hip-options.hip
index 29d23c1b6c8d9..a07dca3638565 100644
--- a/clang/test/Driver/hip-options.hip
+++ b/clang/test/Driver/hip-options.hip
@@ -243,6 +243,19 @@
 // NO-WARN-ATOMIC-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} 
"-Werror=atomic-alignment"
 // NO-WARN-ATOMIC-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} 
"-Wno-error=atomic-alignment"
 
-// Check --offload-compress does not cause warning.
+// Check --offload-compress --offload-jobs=N does not cause warning.
 // RUN: %clang -### -Werror --target=x86_64-unknown-linux-gnu -nogpuinc 
-nogpulib \
-// RUN:   --offload-arch=gfx1100 --offload-compress --offload-host-only -M %s
+// RUN:   --offload-arch=gfx1100 --offload-compress --offload-host-only -M %s \
+// RUN:   --offload-jobs=4
+
+// Check --offload-jobs=N option.
+
+// RUN: %clang -### -Werror --target=x86_64-unknown-linux-gnu -nogpuinc 
-nogpulib \
+// RUN:   --offload-arch=gfx1100 --offload-new-driver --offload-jobs=4 %s 2>&1 
| \
+// RUN:   FileCheck -check-prefix=JOBS %s
+// JOBS: clang-linker-wrapper{{.*}} "--wrapper-jobs=4"
+
+// RUN: not %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
+// RUN:   --offload-arch=gfx1100 --offload-new-driver --offload-jobs=0x4 %s 
2>&1 | \
+// RUN:   FileCheck -check-prefix=INVJOBS %s
+// INVJOBS: clang: error: invalid integral value '0x4' in '--offload-jobs=0x4'

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] add option --offload-jobs=N (PR #135229)

2025-04-14 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 approved this pull request.

LG, one nit.

https://github.com/llvm/llvm-project/pull/135229
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM, AArch64] Fix passing of structures with aligned base classes (PR #135564)

2025-04-14 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.

LGTM with the PreferredBaseAlign thing fixed.

https://github.com/llvm/llvm-project/pull/135564
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang]Ensure correct handling of cleanup access control (#135668) (PR #135686)

2025-04-14 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

Thanks for the quick fix

https://github.com/llvm/llvm-project/pull/135686
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang]Ensure correct handling of cleanup access control (#135668) (PR #135686)

2025-04-14 Thread Oliver Hunt via cfe-commits

https://github.com/ojhunt updated 
https://github.com/llvm/llvm-project/pull/135686

>From 62be33b3aa475a33d1c11679ed069eb2af981754 Mon Sep 17 00:00:00 2001
From: Oliver Hunt 
Date: Mon, 14 Apr 2025 15:02:46 -0700
Subject: [PATCH] [Clang]Ensure correct handling of access control in P2719
 diagnostics (#135668)

The P2719 implementation refactored diagnostics for cleanup delete, and as
part of that I attempted to fix handling of inaccessible cleanup operator
delete. Alas the new branch was incorrect as it was performing an implicit
bool conversion, which resulted in friend accessible cleanup operators
incorrectly being considered erroneous and the allocation path errored out.
This error however did not get diagnosed, so the result was and so we did
not actually error out before codegen.

Added both Sema and CodeGen tests to cover this.
---
 clang/lib/Sema/SemaExprCXX.cpp  |  5 ++--
 clang/test/CodeGenCXX/bug135668.cpp | 38 +
 clang/test/SemaCXX/bug135668.cpp| 25 +++
 3 files changed, 66 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/bug135668.cpp
 create mode 100644 clang/test/SemaCXX/bug135668.cpp

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 16a39f8b5a4dd..dfb5824a1c3d7 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1929,8 +1929,9 @@ static bool CheckDeleteOperator(Sema &S, SourceLocation 
StartLoc,
 }
 return true;
   }
-
-  return S.CheckAllocationAccess(StartLoc, Range, NamingClass, Decl, Diagnose);
+  Sema::AccessResult Accessible =
+  S.CheckAllocationAccess(StartLoc, Range, NamingClass, Decl, Diagnose);
+  return Accessible == Sema::AR_inaccessible;
 }
 
 /// Select the correct "usual" deallocation function to use from a selection of
diff --git a/clang/test/CodeGenCXX/bug135668.cpp 
b/clang/test/CodeGenCXX/bug135668.cpp
new file mode 100644
index 0..08743bd36bf5b
--- /dev/null
+++ b/clang/test/CodeGenCXX/bug135668.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 %s -triple arm64-apple-macosx -emit-llvm -fcxx-exceptions 
-fexceptions -std=c++23 -o - | FileCheck  %s
+
+class TestClass {
+  public:
+   TestClass();
+   int field = 0;
+   friend class Foo;
+   static void * operator new(unsigned long size);
+  private:
+   static void operator delete(void *p);
+ };
+
+class Foo {
+public:
+  int test_method();
+};
+
+int Foo::test_method() {
+  TestClass *obj = new TestClass() ;
+  return obj->field;
+}
+
+// CHECK-LABEL: define noundef i32 @_ZN3Foo11test_methodEv
+// CHECK: [[THIS_ADDR:%.*]] = alloca ptr, align 8
+// CHECK: [[OBJ:%.*]] = alloca ptr, align 8
+// CHECK: store ptr %this, ptr [[THIS_ADDR]], align 8
+// CHECK: [[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
+// CHECK: [[ALLOCATION:%.*]] = call noundef ptr @_ZN9TestClassnwEm(i64 noundef 
4)
+// CHECK: [[INITIALIZEDOBJ:%.*]] = invoke noundef ptr @_ZN9TestClassC1Ev(ptr 
noundef nonnull align 4 dereferenceable(4) [[ALLOCATION]])
+// CHECK-NEXT:  to label %[[INVOKE_CONT:.*]] unwind label %[[LPAD:.*]]
+// CHECK: [[INVOKE_CONT]]:
+// CHECK: store ptr [[ALLOCATION]], ptr [[OBJ]], align 8
+// CHECK: [[OBJPTR:%.*]] = load ptr, ptr [[OBJ]], align 8
+// CHECK: [[FIELDPTR:%.*]] = getelementptr inbounds nuw %class.TestClass, ptr 
[[OBJPTR]], i32 0, i32 0
+// CHECK: [[FIELD:%.*]] = load i32, ptr [[FIELDPTR]], align 4
+// CHECK: ret i32 [[FIELD]]
+// CHECK: [[LPAD]]:
+// CHECK: call void @_ZN9TestClassdlEPv(ptr noundef [[ALLOCATION]]) #3
diff --git a/clang/test/SemaCXX/bug135668.cpp b/clang/test/SemaCXX/bug135668.cpp
new file mode 100644
index 0..96d3d4abfd3ef
--- /dev/null
+++ b/clang/test/SemaCXX/bug135668.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple arm64-apple-macosx -Wall -fsyntax-only -verify %s 
-std=c++26 -fexceptions -fcxx-exceptions
+// expected-no-diagnostics
+
+// This test makes sure that we don't erroneously consider an accessible 
operator
+// delete to be inaccessible, and then discard the entire new expression.
+
+class TestClass {
+public:
+  TestClass();
+  int field = 0;
+  friend class Foo;
+  static void * operator new(unsigned long size);
+private:
+  static void operator delete(void *p);
+};
+
+class Foo {
+public:
+  int test_method();
+};
+
+int Foo::test_method() {
+  TestClass *obj = new TestClass() ;
+  return obj->field;
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang]Ensure correct handling of cleanup access control (#135668) (PR #135686)

2025-04-14 Thread Oliver Hunt via cfe-commits

ojhunt wrote:

> Thanks for the quick fix

it's so very very stupid :O

https://github.com/llvm/llvm-project/pull/135686
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] cir.call with scalar return type (PR #135552)

2025-04-14 Thread Andy Kaylor via cfe-commits


@@ -0,0 +1,89 @@
+//==-- ABIArgInfo.h - Abstract info regarding ABI-specific arguments 
---==//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Defines ABIArgInfo and associated types used by CIR to track information
+// regarding ABI-coerced types for function arguments and return values. This
+// was moved to the common library as it might be used by both CIRGen and
+// passes.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_CIR_ABIARGINFO_H

andykaylor wrote:

```suggestion
#ifndef CLANG_CIR_ABIARGINFO_H
```
We've done a terrible job of being consistent about this during upstreaming, 
but this should correspond to the path that appears in the include statement.

https://github.com/llvm/llvm-project/pull/135552
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM, AArch64] Fix passing of structures with aligned base classes (PR #135564)

2025-04-14 Thread Harald van Dijk via cfe-commits

https://github.com/hvdijk edited 
https://github.com/llvm/llvm-project/pull/135564
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Improve ``-Wtautological-overlap-compare`` diagnostics flag (PR #133653)

2025-04-14 Thread via cfe-commits


@@ -1170,82 +1171,117 @@ class CFGBuilder {
 if (!areExprTypesCompatible(NumExpr1, NumExpr2))
   return {};
 
+// Check that the two expressions are of the same type.
 Expr::EvalResult L1Result, L2Result;
-if (!NumExpr1->EvaluateAsInt(L1Result, *Context) ||
-!NumExpr2->EvaluateAsInt(L2Result, *Context))
-  return {};
-
-llvm::APSInt L1 = L1Result.Val.getInt();
-llvm::APSInt L2 = L2Result.Val.getInt();
-
-// Can't compare signed with unsigned or with different bit width.
-if (L1.isSigned() != L2.isSigned() || L1.getBitWidth() != L2.getBitWidth())
+if (!NumExpr1->EvaluateAsRValue(L1Result, *Context) ||
+!NumExpr2->EvaluateAsRValue(L2Result, *Context))
   return {};
 
-// Values that will be used to determine if result of logical
-// operator is always true/false
-const llvm::APSInt Values[] = {
-  // Value less than both Value1 and Value2
-  llvm::APSInt::getMinValue(L1.getBitWidth(), L1.isUnsigned()),
-  // L1
-  L1,
-  // Value between Value1 and Value2
-  ((L1 < L2) ? L1 : L2) + llvm::APSInt(llvm::APInt(L1.getBitWidth(), 1),
-  L1.isUnsigned()),
-  // L2
-  L2,
-  // Value greater than both Value1 and Value2
-  llvm::APSInt::getMaxValue(L1.getBitWidth(), L1.isUnsigned()),
-};
-
-// Check whether expression is always true/false by evaluating the 
following
+// Check whether expression is always true/false by evaluating the
+// following
 // * variable x is less than the smallest literal.
 // * variable x is equal to the smallest literal.
 // * Variable x is between smallest and largest literal.
 // * Variable x is equal to the largest literal.
 // * Variable x is greater than largest literal.
-bool AlwaysTrue = true, AlwaysFalse = true;
-// Track value of both subexpressions.  If either side is always
-// true/false, another warning should have already been emitted.
-bool LHSAlwaysTrue = true, LHSAlwaysFalse = true;
-bool RHSAlwaysTrue = true, RHSAlwaysFalse = true;
-for (const llvm::APSInt &Value : Values) {
-  TryResult Res1, Res2;
-  Res1 = analyzeLogicOperatorCondition(BO1, Value, L1);
-  Res2 = analyzeLogicOperatorCondition(BO2, Value, L2);
-
-  if (!Res1.isKnown() || !Res2.isKnown())
-return {};
+auto analyzeConditions = [&](const auto &Values,
+ const BinaryOperatorKind *BO1,
+ const BinaryOperatorKind *BO2) -> TryResult {
+  bool AlwaysTrue = true, AlwaysFalse = true;
+  // Track value of both subexpressions.  If either side is always
+  // true/false, another warning should have already been emitted.
+  bool LHSAlwaysTrue = true, LHSAlwaysFalse = true;
+  bool RHSAlwaysTrue = true, RHSAlwaysFalse = true;
+
+  for (const auto &Value : Values) {
+TryResult Res1 =
+analyzeLogicOperatorCondition(*BO1, Value, Values[1] /* L1 */);
+TryResult Res2 =
+analyzeLogicOperatorCondition(*BO2, Value, Values[3] /* L2 */);
+
+if (!Res1.isKnown() || !Res2.isKnown())
+  return {};
+
+const bool isAnd = B->getOpcode() == BO_LAnd;
+const bool combine = isAnd ? (Res1.isTrue() && Res2.isTrue())
+   : (Res1.isTrue() || Res2.isTrue());
+
+AlwaysTrue &= combine;
+AlwaysFalse &= !combine;
+
+LHSAlwaysTrue &= Res1.isTrue();
+LHSAlwaysFalse &= Res1.isFalse();
+RHSAlwaysTrue &= Res2.isTrue();
+RHSAlwaysFalse &= Res2.isFalse();
+  }
 
-  if (B->getOpcode() == BO_LAnd) {
-AlwaysTrue &= (Res1.isTrue() && Res2.isTrue());
-AlwaysFalse &= !(Res1.isTrue() && Res2.isTrue());
-  } else {
-AlwaysTrue &= (Res1.isTrue() || Res2.isTrue());
-AlwaysFalse &= !(Res1.isTrue() || Res2.isTrue());
+  if (AlwaysTrue || AlwaysFalse) {
+if (!LHSAlwaysTrue && !LHSAlwaysFalse && !RHSAlwaysTrue &&
+!RHSAlwaysFalse && BuildOpts.Observer) {
+  BuildOpts.Observer->compareAlwaysTrue(B, AlwaysTrue);
+}
+return TryResult(AlwaysTrue);
   }
+  return {};
+};
 
-  LHSAlwaysTrue &= Res1.isTrue();
-  LHSAlwaysFalse &= Res1.isFalse();
-  RHSAlwaysTrue &= Res2.isTrue();
-  RHSAlwaysFalse &= Res2.isFalse();
+// Handle integer comparison
+if (L1Result.Val.getKind() == APValue::Int &&
+L2Result.Val.getKind() == APValue::Int) {
+  llvm::APSInt L1 = L1Result.Val.getInt();
+  llvm::APSInt L2 = L2Result.Val.getInt();
+
+  // Can't compare signed with unsigned or with different bit width.
+  if (L1.isSigned() != L2.isSigned() ||
+  L1.getBitWidth() != L2.getBitWidth())
+return {};
+
+  // Values that will be used to determine if result of logical
+  // operator is always true/false
+  const llvm::APSInt Values[] = {

[clang] [Clang] [Sema] Fix a crash when a `friend` function is redefined as deleted (PR #135679)

2025-04-14 Thread via cfe-commits

https://github.com/Sirraide created 
https://github.com/llvm/llvm-project/pull/135679

NB: This only fixes the crash introduced in Clang 19; we still accept this code 
even though we shouldn’t:
```c++
struct S {
friend int f() { return 3; }
friend int f() = delete;
};
```
I tried figuring out a way to diagnose this redeclaration, but it seems tricky 
because I kept running into issues around defaulted comparison operators. From 
my testing, however, this fix here would still be required even once we do 
start diagnosing this.

Fixes #135506.

>From daa795d3807ecdceedb764582a01396c3b7f2e2f Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Mon, 14 Apr 2025 22:54:11 +0200
Subject: [PATCH] [Clang] [Sema] Fix a crash when a `friend` function is
 redefined as deleted

---
 clang/docs/ReleaseNotes.rst   |  2 +-
 clang/lib/Sema/SemaDecl.cpp   | 15 --
 .../SemaCXX/cxx2c-delete-with-message.cpp | 30 +++
 3 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 11f62bc881b03..037f9f6fe79e0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -389,7 +389,7 @@ Bug Fixes in This Version
 
 #if 1 ? 1 : 9
 #endif
-
+- Fixed a crash when a ``friend`` function is redefined as deleted. (#GH135506)
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e9805c345b6af..8fd857d347895 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16178,16 +16178,11 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
 // This is meant to pop the context added in ActOnStartOfFunctionDef().
 ExitFunctionBodyRAII ExitRAII(*this, isLambdaCallOperator(FD));
 if (FD) {
-  // If this is called by Parser::ParseFunctionDefinition() after marking
-  // the declaration as deleted, and if the deleted-function-body contains
-  // a message (C++26), then a DefaultedOrDeletedInfo will have already 
been
-  // added to store that message; do not overwrite it in that case.
-  //
-  // Since this would always set the body to 'nullptr' in that case anyway,
-  // which is already done when the function decl is initially created,
-  // always skipping this irrespective of whether there is a delete message
-  // should not be a problem.
-  if (!FD->isDeletedAsWritten())
+  // The function body and the DefaultedOrDeletedInfo, if present, use
+  // the same storage; don't overwrite the latter if the former is null
+  // (the body is initialised to null anyway, so even if the latter isn't
+  // present, this would still be a no-op).
+  if (Body)
 FD->setBody(Body);
   FD->setWillHaveBody(false);
 
diff --git a/clang/test/SemaCXX/cxx2c-delete-with-message.cpp 
b/clang/test/SemaCXX/cxx2c-delete-with-message.cpp
index 22e65d902ecd4..5609da18c05aa 100644
--- a/clang/test/SemaCXX/cxx2c-delete-with-message.cpp
+++ b/clang/test/SemaCXX/cxx2c-delete-with-message.cpp
@@ -271,3 +271,33 @@ void operators() {
   if (to_int_int) {} // expected-error {{attempt to use a deleted function: 
deleted (TO, operator bool)}}
   static_cast(to_int_int); // expected-error {{static_cast from 'TO' to 'bool' uses deleted function: deleted (TO, operator bool)}}
 };
+
+namespace gh135506 {
+struct a {
+  // FIXME: We currently don't diagnose these invalid redeclarations if the
+  // second declaration is defaulted or deleted. This probably needs to be
+  // handled in ParseCXXInlineMethodDef() after parsing the defaulted/deleted
+  // body.
+  friend consteval int f() { return 3; }
+  friend consteval int f() = delete("foo");
+
+  friend consteval int g() { return 3; }
+  friend consteval int g() = delete;
+
+  friend int h() { return 3; }
+  friend int h() = delete;
+
+  friend consteval int i() = delete; // expected-note {{previous definition is 
here}}
+  friend consteval int i() { return 3; } // expected-error {{redefinition of 
'i'}}
+};
+
+struct b {
+  friend consteval bool operator==(b, b) { return true; } // expected-note 
{{previous declaration is here}}
+  friend consteval bool operator==(b, b) = default; // expected-error 
{{defaulting this equality comparison operator is not allowed because it was 
already declared outside the class}}
+};
+
+struct c {
+  friend consteval bool operator==(c, c) = default; // expected-note 
{{previous definition is here}}
+  friend consteval bool operator==(c, c) { return true; } // expected-error 
{{redefinition of 'operator=='}}
+};
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][DirectX] Always use Diagnostic Printer (PR #135655)

2025-04-14 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl created 
https://github.com/llvm/llvm-project/pull/135655

fixes #135654

In #128613 we added safe guards to prevent the lowering of just any intrinsic 
in the backend. We used `DiagnosticInfoUnsupported` to do this.

What we found was when using `opt` the diagnostic printer was called but when 
using clang the diagnostic message was called.

Printing message in the clang version means we miss valuable debugging 
information like function name and function type when LLVMContext was only 
needed to call `getBestLocationFromDebugLoc`.

>From 4dc14760870fcc88da3d9162ba817aae6a01d759 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Mon, 14 Apr 2025 14:07:30 -0400
Subject: [PATCH] [Clang][DirectX] Always use Diagnostic Printer fixes #135654

In #128613 we added safe guards to prevent the lowering of just any
intrinsic in the backend. We used `DiagnosticInfoUnsupported` to do
this.

What we found was when using `opt` the diagnostic printer was called
but when using clang the diagnostic message was called.

Printing message in the clang version means we miss valuable debugging
information like function name and function type when LLVMContext was
only needed to call `getBestLocationFromDebugLoc`.
---
 clang/lib/CodeGen/CodeGenAction.cpp  | 11 +--
 clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl | 10 ++
 2 files changed, 15 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 1f5eb427b566f..9d7a8b92f6616 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -605,13 +605,12 @@ void BackendConsumer::UnsupportedDiagHandler(
 
   // Context will be nullptr for IR input files, we will construct the diag
   // message from llvm::DiagnosticInfoUnsupported.
-  if (Context != nullptr) {
+  if (Context != nullptr)
 Loc = getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
-MsgStream << D.getMessage();
-  } else {
-DiagnosticPrinterRawOStream DP(MsgStream);
-D.print(DP);
-  }
+
+  DiagnosticPrinterRawOStream DP(MsgStream);
+  D.print(DP);
+
 
   auto DiagType = D.getSeverity() == llvm::DS_Error
   ? diag::err_fe_backend_unsupported
diff --git a/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl 
b/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl
new file mode 100644
index 0..3d0462679f152
--- /dev/null
+++ b/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl
@@ -0,0 +1,10 @@
+// RUN: not %clang_dxc -T lib_6_3 %s 2>&1 | FileCheck %s
+
+// Define a vector of 4 ints (Clang/LLVM extension)
+typedef int int4 __attribute__((ext_vector_type(4)));
+
+// CHECK: error: :0:0: in function llvm.vector.reduce.mul.v4i32 i32 
(<4 x i32>): Unsupported intrinsic for DXIL lowering
+
+export int vecReduceMulTest(int4 vec) {
+return __builtin_reduce_mul(vec);
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] add option --offload-jobs=N (PR #135229)

2025-04-14 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu edited 
https://github.com/llvm/llvm-project/pull/135229
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema]:Fix musttail attribute on a function with not_tail_called attribute has no warning/error (PR #134465)

2025-04-14 Thread Erich Keane via cfe-commits


@@ -717,6 +717,13 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr 
&MTA) {
 return false;
   }
 
+  if (const FunctionDecl *CalleeDecl = CE->getDirectCallee();
+  CalleeDecl && CalleeDecl->hasAttr()) {
+Diag(St->getBeginLoc(), diag::err_musttail_mismatch) << 
/*show-function-callee=*/true << CalleeDecl;
+Diag(CalleeDecl->getLocation(), 
diag::note_musttail_disabled_by_not_tail_called) << CalleeDecl;

erichkeane wrote:

```suggestion
Diag(CalleeDecl->getLocation(), 
diag::note_musttail_disabled_by_not_tail_called);
```

You don't need the `<< CalleeDecl` since that is how we fill in the `%0` type 
things in the diagnostic kinds message.  Since the added one doesn't have one, 

Aaron suggested instead of this diagnostic to reuse an existing one in a 
previous comment which I'm OK with (though I'm also ok with this one).  I'll 
let Aaron decide if he feels strongly enough to revert to the other one.

https://github.com/llvm/llvm-project/pull/134465
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Upstream minimal support for structure types (PR #135105)

2025-04-14 Thread Erich Keane via cfe-commits

https://github.com/erichkeane approved this pull request.


https://github.com/llvm/llvm-project/pull/135105
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM, AArch64] Fix passing of structures with aligned base classes (PR #135564)

2025-04-14 Thread John McCall via cfe-commits


@@ -1302,6 +1302,7 @@ ItaniumRecordLayoutBuilder::LayoutBase(const 
BaseSubobjectInfo *Base) {
 setSize(std::max(getSize(), Offset + Layout.getSize()));
 
   // Remember max struct/class alignment.
+  UnadjustedAlignment = std::max(UnadjustedAlignment, PreferredBaseAlign);

rjmccall wrote:

There should at least be a test case for it.

https://github.com/llvm/llvm-project/pull/135564
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   5   >