[clang] [clang][CodeGen] `sret` args should always point to the `alloca` AS, so use that (PR #114062)

2024-12-04 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/114062

>From d2d2d3d5db3f639aab178f9ca9a20db2842d2b65 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Tue, 29 Oct 2024 14:20:44 +
Subject: [PATCH 01/11] `sret` args should always point to the `alloca` AS, so
 we can use that.

---
 clang/lib/CodeGen/CGCall.cpp   | 15 ---
 clang/test/CodeGen/partial-reinitialization2.c |  4 ++--
 clang/test/CodeGen/sret.c  | 11 +++
 3 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 8f4f5d3ed81601..56acfae7ae9e51 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1672,8 +1672,7 @@ CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI) {
 
   // Add type for sret argument.
   if (IRFunctionArgs.hasSRetArg()) {
-QualType Ret = FI.getReturnType();
-unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(Ret);
+unsigned AddressSpace = CGM.getDataLayout().getAllocaAddrSpace();
 ArgTypes[IRFunctionArgs.getSRetArgNo()] =
 llvm::PointerType::get(getLLVMContext(), AddressSpace);
   }
@@ -5145,7 +5144,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   // If the call returns a temporary with struct return, create a temporary
   // alloca to hold the result, unless one is given to us.
   Address SRetPtr = Address::invalid();
-  RawAddress SRetAlloca = RawAddress::invalid();
   llvm::Value *UnusedReturnSizePtr = nullptr;
   if (RetAI.isIndirect() || RetAI.isInAlloca() || RetAI.isCoerceAndExpand()) {
 // For virtual function pointer thunks and musttail calls, we must always
@@ -5159,16 +5157,19 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
 } else if (!ReturnValue.isNull()) {
   SRetPtr = ReturnValue.getAddress();
 } else {
-  SRetPtr = CreateMemTemp(RetTy, "tmp", &SRetAlloca);
+  SRetPtr = CreateMemTempWithoutCast(RetTy, "tmp");
   if (HaveInsertPoint() && ReturnValue.isUnused()) {
 llvm::TypeSize size =
 CGM.getDataLayout().getTypeAllocSize(ConvertTypeForMem(RetTy));
-UnusedReturnSizePtr = EmitLifetimeStart(size, SRetAlloca.getPointer());
+UnusedReturnSizePtr = EmitLifetimeStart(size, 
SRetPtr.getBasePointer());
   }
 }
 if (IRFunctionArgs.hasSRetArg()) {
+  // If the caller allocated the return slot, it is possible that the
+  // alloca was AS casted to the default as, so we ensure the cast is
+  // stripped before binding to the sret arg, which is in the allocaAS.
   IRCallArgs[IRFunctionArgs.getSRetArgNo()] =
-  getAsNaturalPointerTo(SRetPtr, RetTy);
+  getAsNaturalPointerTo(SRetPtr, RetTy)->stripPointerCasts();
 } else if (RetAI.isInAlloca()) {
   Address Addr =
   Builder.CreateStructGEP(ArgMemory, RetAI.getInAllocaFieldIndex());
@@ -5740,7 +5741,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   // pop this cleanup later on. Being eager about this is OK, since this
   // temporary is 'invisible' outside of the callee.
   if (UnusedReturnSizePtr)
-pushFullExprCleanup(NormalEHLifetimeMarker, SRetAlloca,
+pushFullExprCleanup(NormalEHLifetimeMarker, SRetPtr,
  UnusedReturnSizePtr);
 
   llvm::BasicBlock *InvokeDest = CannotThrow ? nullptr : getInvokeDest();
diff --git a/clang/test/CodeGen/partial-reinitialization2.c 
b/clang/test/CodeGen/partial-reinitialization2.c
index e709c1d4ad1ee1..7949a69555031e 100644
--- a/clang/test/CodeGen/partial-reinitialization2.c
+++ b/clang/test/CodeGen/partial-reinitialization2.c
@@ -91,8 +91,8 @@ void test5(void)
 // CHECK-LABEL: test6
 void test6(void)
 {
-  // CHECK: [[LP:%[a-z0-9]+]] = getelementptr{{.*}}%struct.LLP2P2, ptr{{.*}}, 
i32 0, i32 0
-  // CHECK: call {{.*}}get456789(ptr {{.*}}[[LP]])
+  // CHECK: [[VAR:%[a-z0-9]+]] = alloca
+  // CHECK: call {{.*}}get456789(ptr {{.*}}sret{{.*}} [[VAR]])
 
   // CHECK: [[CALL:%[a-z0-9]+]] = call {{.*}}@get235()
   // CHECK: store{{.*}}[[CALL]], {{.*}}[[TMP0:%[a-z0-9.]+]]
diff --git a/clang/test/CodeGen/sret.c b/clang/test/CodeGen/sret.c
index 6d905e89b2c6fd..3b4914f29d2bfe 100644
--- a/clang/test/CodeGen/sret.c
+++ b/clang/test/CodeGen/sret.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -Wno-strict-prototypes -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -Wno-strict-prototypes -triple amdgcn-amd-amdhsa 
-emit-llvm -o - | FileCheck --check-prefix=NONZEROALLOCAAS %s
 
 struct abc {
  long a;
@@ -6,18 +7,28 @@ struct abc {
  long c;
  long d;
  long e;
+ long f;
+ long g;
+ long h;
+ long i;
+ long j;
 };
 
 struct abc foo1(void);
 // CHECK-DAG: declare {{.*}} @foo1(ptr dead_on_unwind writable 
sret(%struct.abc)
+// NONZEROALLOCAAS-DAG: declare {{.*}} @foo1(ptr addrspace(5) dead_on_unwind 
writable sret(%struct.abc)
 struct abc foo2();
 // CHECK-DAG: declare {{.*}} @foo2(ptr dead_on_unwind wri

[clang] Pack relocations for Android API >= 28 (PR #117624)

2024-12-04 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

breaks this bot https://lab.llvm.org/buildbot/#/builders/186/builds/4581

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


[clang] Add an off-by-default warning to complain about MSVC bitfield padding (PR #117428)

2024-12-04 Thread Oliver Hunt via cfe-commits

ojhunt wrote:

> > > So I take it we decided not to enable it by default in 
> > > `-fms-compatibility` mode then?
> > 
> > 
> > I don't believe it is appropriate to do so. The intent of this warning is 
> > to indicate MSVC compatibility issues when building in non-ms-compatibility 
> > modes. The existing padding warnings already trigger for these layouts in 
> > the relevant ms compatibility modes
> 
> We don't typically add new off-by-default warnings though; users don't enable 
> them often enough to be worth the costs. My thought process is: if we enable 
> this diagnostic by default in `-fms-compatibility` mode as telling the user 
> their bit-fields aren't packing, then it's on by default for some 
> configurations so it meets our bar for inclusion, and it helps us directly 
> because we have Windows precommit (and post-commit) CI coverage for building 
> Clang and LLVM. Users on other platforms can opt-in to the diagnostic if they 
> want the diagnostics for compatibility reasons.

My concerns with attaching it to `-fms-compatibility` is that projects using 
that and that care about padding already have the padding/packing warnings 
enabled. For every other user we will be warning them that the padding matches 
the abi they're targeting. The problem I'm wanting to address is not "I am 
targeting the ms abi" it is "I am not targeting ms abi but want to be told 
about packing/padding that would be different on ms platforms".

The intention would be to then enable the warning (maybe with a `-Werror=...` 
once the build is clean :D ) for all llvm projects, not just the windows 
targets - maybe with some evangelism so larger projects that have similar 
issues can be made aware of the flag. Then we can start migrating away from 
unending unsigned bit-fields and adopt enum bit-fields

> 
> If we want to leave it off by default, then I wonder if we want to roll the 
> functionality into `-Wpadded-bitfield` which already exists and is off by 
> default.

The problem with this is that that people who do not care about windows/ms abi 
will then be getting what to them are spurious warnings.

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


[clang] [compiler-rt] [llvm] [SystemZ] Add support for half (fp16) (PR #109164)

2024-12-04 Thread Jonas Paulsson via cfe-commits

JonPsson1 wrote:

Spill f16 using float instructions into 4-byte stack slots:

- Seems to work to use a RegInfoByHwMode to reset the SpillSize for FP16 to 32 
bits. By using two HwMode:s, the spill size can still be 16 bits with vector 
support.

- Using new LE16/STE16 opcodes seems easier than extracting/inserting subregs 
in storeRegToStackSlot() / loadRegFromStackSlot() via FP32 regs, although that 
could also work.


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


[clang] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)

2024-12-04 Thread Zhengxing li via cfe-commits


@@ -2,15 +2,18 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-mesh -hlsl-entry CSMain -x 
hlsl -finclude-default-header  -verify -o - %s
 
 [numthreads(8,8,1)]
-// expected-error@+3 {{attribute 'SV_GroupIndex' is unsupported in 'mesh' 
shaders, requires compute}}
-// expected-error@+2 {{attribute 'SV_DispatchThreadID' is unsupported in 
'mesh' shaders, requires compute}}
-// expected-error@+1 {{attribute 'SV_GroupID' is unsupported in 'mesh' 
shaders, requires compute}}
-void CSMain(int GI : SV_GroupIndex, uint ID : SV_DispatchThreadID, uint GID : 
SV_GroupID) {
-// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> line:[[@LINE-1]]:6 CSMain 
'void (int, uint, uint)'
+// expected-error@+4 {{attribute 'SV_GroupIndex' is unsupported in 'mesh' 
shaders, requires compute}}
+// expected-error@+3 {{attribute 'SV_DispatchThreadID' is unsupported in 
'mesh' shaders, requires compute}}
+// expected-error@+2 {{attribute 'SV_GroupID' is unsupported in 'mesh' 
shaders, requires compute}}
+// expected-error@+1 {{attribute 'SV_GroupThreadID' is unsupported in 'mesh' 
shaders, requires compute}}
+void CSMain(int GI : SV_GroupIndex, uint ID : SV_DispatchThreadID, uint GID : 
SV_GroupID, uint GThreadID : SV_GroupThreadID) {

lizhengxing wrote:

@tex3d It makes sense to me. I'll try to move the non-CS checks into 
`invalid_entry_parameter.hlsl`

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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-04 Thread Chandler Carruth via cfe-commits

chandlerc wrote:

Discussion thread about the MSVC version change: 
https://discourse.llvm.org/t/rfc-raising-minimum-msvc-version-by-one-patch-release/83490

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


[clang] Revert "Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585, #111173)" (#111852)" (PR #115159)

2024-12-04 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

@sdkrystian Friendly ping. Any chance for you to reapply this patch recently? 
thanks

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


[clang] 32b821c - [AST] Fix a warning

2024-12-04 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2024-12-04T16:03:14-08:00
New Revision: 32b821cab3064ae9a77a0f1d9916a286c7543735

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

LOG: [AST] Fix a warning

This patch fixes:

  clang/lib/AST/MicrosoftMangle.cpp:1006:11: error: enumeration value
  'S_PPCDoubleDoubleLegacy' not handled in switch [-Werror,-Wswitch]

Added: 


Modified: 
clang/lib/AST/MicrosoftMangle.cpp

Removed: 




diff  --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index 7642ff7ca606cd..edeeaeaa9ae17c 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -1014,6 +1014,7 @@ void MicrosoftCXXNameMangler::mangleFloat(llvm::APFloat 
Number) {
   case APFloat::S_x87DoubleExtended: Out << 'X'; break;
   case APFloat::S_IEEEquad: Out << 'Y'; break;
   case APFloat::S_PPCDoubleDouble: Out << 'Z'; break;
+  case APFloat::S_PPCDoubleDoubleLegacy:
   case APFloat::S_Float8E5M2:
   case APFloat::S_Float8E4M3:
   case APFloat::S_Float8E4M3FN:



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


[clang] [llvm] [AMDGPU] Infer amdgpu-no-flat-scratch-init attribute in AMDGPUAttributor (PR #94647)

2024-12-04 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lld-x86_64-ubuntu-fast` 
running on `as-builder-4` while building `clang,llvm` at step 6 
"test-build-unified-tree-check-all".

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


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

```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'LLVM :: 
CodeGen/AMDGPU/attributor-flatscratchinit-globalisel.ll' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 2: 
/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/opt -S -O2 
-mtriple=amdgcn-amd-amdhsa -mcpu=gfx1010 
/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/llvm/test/CodeGen/AMDGPU/attributor-flatscratchinit-globalisel.ll
 | /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/llc 
-mtriple=amdgcn-amd-amdhsa -mcpu=gfx1010 -global-isel -stop-after=irtranslator 
| /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/FileCheck 
-check-prefixes=GFX10 
/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/llvm/test/CodeGen/AMDGPU/attributor-flatscratchinit-globalisel.ll
+ /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/opt -S -O2 
-mtriple=amdgcn-amd-amdhsa -mcpu=gfx1010 
/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/llvm/test/CodeGen/AMDGPU/attributor-flatscratchinit-globalisel.ll
+ /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/llc 
-mtriple=amdgcn-amd-amdhsa -mcpu=gfx1010 -global-isel -stop-after=irtranslator
+ /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/FileCheck 
-check-prefixes=GFX10 
/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/llvm/test/CodeGen/AMDGPU/attributor-flatscratchinit-globalisel.ll
/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/llvm/test/CodeGen/AMDGPU/attributor-flatscratchinit-globalisel.ll:521:15:
 error: GFX10-NEXT: expected string not found in input
; GFX10-NEXT: kernargSegmentPtr: { reg: '$sgpr6_sgpr7' }
  ^
:4864:38: note: scanning from here
 dispatchPtr: { reg: '$sgpr4_sgpr5' }
 ^
:4866:2: note: possible intended match here
 kernargSegmentPtr: { reg: '$sgpr8_sgpr9' }
 ^

Input file: 
Check file: 
/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/llvm/test/CodeGen/AMDGPU/attributor-flatscratchinit-globalisel.ll

-dump-input=help explains the following input dump.

Input was:
<<
.
.
.
 4859:  stackPtrOffsetReg: '$sp_reg' 
 4860:  bytesInStackArgArea: 0 
 4861:  returnsVoid: true 
 4862:  argumentInfo: 
 4863:  privateSegmentBuffer: { reg: '$sgpr0_sgpr1_sgpr2_sgpr3' } 
 4864:  dispatchPtr: { reg: '$sgpr4_sgpr5' } 
next:521'0  X error: no match found
 4865:  queuePtr: { reg: '$sgpr6_sgpr7' } 
next:521'0 ~~~
 4866:  kernargSegmentPtr: { reg: '$sgpr8_sgpr9' } 
next:521'0 
next:521'1  ?   possible intended 
match
 4867:  dispatchID: { reg: '$sgpr10_sgpr11' } 
next:521'0 ~~~
 4868:  flatScratchInit: { reg: '$sgpr12_sgpr13' } 
next:521'0 
 4869:  workGroupIDX: { reg: '$sgpr14' } 
next:521'0 ~~
 4870:  workGroupIDY: { reg: '$sgpr15' } 
next:521'0 ~~
 4871:  workGroupIDZ: { reg: '$sgpr16' } 
...

```



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


[clang] [HLSL] Add ByteAddressBuffer, RWByteAddressBuffer and RasterizerOrderedByteAddressBuffer definitions to HLSLExternalSemaSource #113477 (PR #116699)

2024-12-04 Thread Helena Kotas via cfe-commits


@@ -540,10 +555,10 @@ struct BuiltinTypeMethodBuilder {
 
 // create method decl
 auto *TSInfo = AST.getTrivialTypeSourceInfo(MethodTy, SourceLocation());
-Method =
-CXXMethodDecl::Create(AST, DeclBuilder.Record, SourceLocation(),
-  NameInfo, MethodTy, TSInfo, SC_None, false, 
false,
-  ConstexprSpecKind::Unspecified, 
SourceLocation());
+Method = CXXMethodDecl::Create(
+AST, DeclBuilder.finalizeForwardDeclaration(), SourceLocation(),

hekota wrote:

This change is not necessary - methods are added when the type is getting 
completed on its first use, which is long after the forward declaration was 
created.

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


[clang] [llvm] [AArch64] Add intrinsics for SME FP8 FDOT LANE instructions (PR #118492)

2024-12-04 Thread Jonathan Thackray via cfe-commits


@@ -740,6 +740,11 @@ let SMETargetGuard = "sme2" in {
   def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>;
 }
 
+// FDOT

jthackray wrote:

Sure, will do.

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-12-04 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,785 @@
+//===-- Mustache.cpp 
--===//
+//
+// 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/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+using namespace llvm::mustache;
+
+namespace {
+
+static bool isFalsey(const Value &V) {
+  return V.getAsNull() || (V.getAsBoolean() && !V.getAsBoolean().value()) ||
+ (V.getAsArray() && V.getAsArray()->empty()) ||
+ (V.getAsObject() && V.getAsObject()->empty());
+}
+
+static Accessor splitMustacheString(StringRef Str) {
+  // We split the mustache string into an accessor.
+  // For example:
+  //"a.b.c" would be split into {"a", "b", "c"}
+  // We make an exception for a single dot which
+  // refers to the current context.
+  Accessor Tokens;
+  if (Str == ".") {
+Tokens.emplace_back(Str);
+return Tokens;
+  }
+  while (!Str.empty()) {
+StringRef Part;
+std::tie(Part, Str) = Str.split(".");
+Tokens.emplace_back(Part.trim());
+  }
+  return Tokens;
+}
+
+} // namespace
+
+namespace llvm {
+namespace mustache {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized.
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed.
+  std::string TokenBody;
+  Accessor Accessor;
+  size_t Indentation;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode(llvm::BumpPtrAllocator &Alloc, llvm::StringMap &Partials,
+  llvm::StringMap &Lambdas,
+  llvm::StringMap &SectionLambdas,
+  llvm::DenseMap &Escapes)
+  : Allocator(Alloc), Partials(Partials), Lambdas(Lambdas),
+SectionLambdas(SectionLambdas), Escapes(Escapes), T(Type::Root),
+ParentContext(nullptr) {};
+
+  ASTNode(llvm::StringRef Body, ASTNode *Parent, llvm::BumpPtrAllocator &Alloc,
+  llvm::StringMap &Partials,
+  llvm::StringMap &Lambdas,
+  llvm::StringMap &SectionLambdas,
+  llvm::DenseMap &Escapes)
+  : Allocator(Alloc), Partials(Partials), Lambdas(Lambdas),
+SectionLambdas(SectionLambdas), Escapes(Escapes), T(Type::Text),
+Body(Body.str()), Parent(Parent), ParentContext(nullptr) {}
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable Nodes
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent,
+  llvm::BumpPtrAllocator &Alloc, llvm::StringMap &Partials,
+  llvm::StringMap &Lambdas,
+  llvm::StringMap &SectionLambdas,
+  llvm::DenseMap &Escapes)
+  : Allocator(Alloc), Partials(Partials), Lambdas(Lambdas),
+SectionLambdas(SectionLambdas), Escapes(Escapes), T(T),
+Accessor(Accessor), Parent(Parent), ParentContext(nullptr) {}
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setRawBody(std::string NewBody) { RawBody = std::move(NewBody); };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator &Allocator;
+  StringMap &Partials;
+  StringMap &Lambdas;
+  StringMap &SectionLambdas;
+  DenseMap &Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-12-04 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,785 @@
+//===-- Mustache.cpp 
--===//
+//
+// 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/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+using namespace llvm::mustache;
+
+namespace {
+
+static bool isFalsey(const Value &V) {
+  return V.getAsNull() || (V.getAsBoolean() && !V.getAsBoolean().value()) ||
+ (V.getAsArray() && V.getAsArray()->empty()) ||
+ (V.getAsObject() && V.getAsObject()->empty());
+}
+
+static Accessor splitMustacheString(StringRef Str) {
+  // We split the mustache string into an accessor.
+  // For example:
+  //"a.b.c" would be split into {"a", "b", "c"}
+  // We make an exception for a single dot which
+  // refers to the current context.
+  Accessor Tokens;
+  if (Str == ".") {
+Tokens.emplace_back(Str);
+return Tokens;
+  }
+  while (!Str.empty()) {
+StringRef Part;
+std::tie(Part, Str) = Str.split(".");
+Tokens.emplace_back(Part.trim());
+  }
+  return Tokens;
+}
+
+} // namespace
+
+namespace llvm {
+namespace mustache {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized.
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed.
+  std::string TokenBody;
+  Accessor Accessor;
+  size_t Indentation;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode(llvm::BumpPtrAllocator &Alloc, llvm::StringMap &Partials,
+  llvm::StringMap &Lambdas,
+  llvm::StringMap &SectionLambdas,
+  llvm::DenseMap &Escapes)
+  : Allocator(Alloc), Partials(Partials), Lambdas(Lambdas),
+SectionLambdas(SectionLambdas), Escapes(Escapes), T(Type::Root),
+ParentContext(nullptr) {};
+
+  ASTNode(llvm::StringRef Body, ASTNode *Parent, llvm::BumpPtrAllocator &Alloc,
+  llvm::StringMap &Partials,
+  llvm::StringMap &Lambdas,
+  llvm::StringMap &SectionLambdas,
+  llvm::DenseMap &Escapes)
+  : Allocator(Alloc), Partials(Partials), Lambdas(Lambdas),
+SectionLambdas(SectionLambdas), Escapes(Escapes), T(Type::Text),
+Body(Body.str()), Parent(Parent), ParentContext(nullptr) {}
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable Nodes
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent,
+  llvm::BumpPtrAllocator &Alloc, llvm::StringMap &Partials,
+  llvm::StringMap &Lambdas,
+  llvm::StringMap &SectionLambdas,
+  llvm::DenseMap &Escapes)
+  : Allocator(Alloc), Partials(Partials), Lambdas(Lambdas),
+SectionLambdas(SectionLambdas), Escapes(Escapes), T(T),
+Accessor(Accessor), Parent(Parent), ParentContext(nullptr) {}
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setRawBody(std::string NewBody) { RawBody = std::move(NewBody); };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator &Allocator;
+  StringMap &Partials;
+  StringMap &Lambdas;
+  StringMap &SectionLambdas;
+  DenseMap &Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-12-04 Thread Paul Kirth via cfe-commits

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

Modulo a few small things, I think this is in pretty decent shape now.

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-12-04 Thread Paul Kirth via cfe-commits

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


[clang] [clang-cl][flang][dxc] Fix opts exposed to clang-cl/dxc by mistake (PR #118640)

2024-12-04 Thread Haohai Wen via cfe-commits


@@ -1055,11 +1055,11 @@ def z : Separate<["-"], "z">, Flags<[LinkerInput]>,
 def offload_link : Flag<["--"], "offload-link">, Group,
   HelpText<"Use the new offloading linker to perform the link job.">;
 def Xlinker : Separate<["-"], "Xlinker">, Flags<[LinkerInput, RenderAsInput]>,
-  Visibility<[ClangOption, CLOption, FlangOption, DXCOption]>,
+  Visibility<[ClangOption, FlangOption]>,

HaohaiWen wrote:

For clang-cl, /link would pass all args after it to linker and that would cause 
some trouble when using cmake.
e.g. cmake may use clang-cl as "linker" and append some args after flags 
specified by CMAKE_EXE_LINKER_FLAGS.
In that case, -Xlinker is better choice.


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


[clang] [AArch64][SME] Fix bug on SMELd1St1 (PR #118109)

2024-12-04 Thread via cfe-commits

wwwatermiao wrote:

> > I thought that this fix will automatically pull from main to other branch 
> > at some tiime
> 
> main is the basis for all future release branches (20.x and later), but we 
> don't automatically pull fixes into release branches that are already created 
> (19.x).
> 
> See 
> https://llvm.org/docs/GitHub.html#backporting-fixes-to-the-release-branches 
> for backporting instructions.

Thank you for your reply, i'll cherry-pick to these branch after this patch 
merging.

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


[clang] [clang-cl][flang][dxc] Fix opts exposed to clang-cl/dxc by mistake (PR #118640)

2024-12-04 Thread Haohai Wen via cfe-commits

HaohaiWen wrote:

Better to double check with author who specified those CL flags.

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


[clang] [clang-cl][flang][dxc] Fix opts exposed to clang-cl/dxc by mistake (PR #118640)

2024-12-04 Thread Haohai Wen via cfe-commits

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


[clang] [Darwin][Driver][clang] Prioritise command line args over `DEFAULT_SYSROOT` (PR #115993)

2024-12-04 Thread Carlo Cabrera via cfe-commits

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


[clang] [Darwin][Driver][clang] Prioritise `-isysroot` over `--sysroot` consistently (PR #115993)

2024-12-04 Thread Carlo Cabrera via cfe-commits

https://github.com/carlocab updated 
https://github.com/llvm/llvm-project/pull/115993

>From e257a7924d15e3f19fe483ea81d792feb4644874 Mon Sep 17 00:00:00 2001
From: Carlo Cabrera 
Date: Wed, 13 Nov 2024 13:09:59 +0800
Subject: [PATCH] [Darwin][Driver][clang] Prioritise command line flags over
 `DEFAULT_SYSROOT`

If a toolchain is configured with `DEFAULT_SYSROOT`, then this could
result in an unintended value for `-syslibroot` being passed to the
linker if the user manually sets `-isysroot` or `SDKROOT`.

Let's fix this by prioritising command line flags when determining
`-syslibroot` before checking `getSysRoot`.

Downstream bug report: https://github.com/Homebrew/homebrew-core/issues/197277

Co-authored-by: Bo Anderson 
---
 clang/lib/Driver/ToolChains/Darwin.cpp | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 87380869f6fdab..cdb6d21a0148b6 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -430,13 +430,17 @@ void darwin::Linker::AddLinkArgs(Compilation &C, const 
ArgList &Args,
 
   // Give --sysroot= preference, over the Apple specific behavior to also use
   // --isysroot as the syslibroot.
-  StringRef sysroot = C.getSysRoot();
-  if (sysroot != "") {
+  // We check `OPT__sysroot_EQ` directly instead of `getSysRoot` to make sure 
we
+  // prioritise command line arguments over configuration of `DEFAULT_SYSROOT`.
+  if (const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ)) {
 CmdArgs.push_back("-syslibroot");
-CmdArgs.push_back(C.getArgs().MakeArgString(sysroot));
+CmdArgs.push_back(A->getValue());
   } else if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
 CmdArgs.push_back("-syslibroot");
 CmdArgs.push_back(A->getValue());
+  } else if (StringRef sysroot = C.getSysRoot(); sysroot != "") {
+CmdArgs.push_back("-syslibroot");
+CmdArgs.push_back(C.getArgs().MakeArgString(sysroot));
   }
 
   Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace);

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


[clang] [llvm] [clang-format] Add cmake target clang-format-style-options for updating ClangFormatStyleOptions.rst (PR #111513)

2024-12-04 Thread Owen Pan via cfe-commits

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


[clang] [llvm] Support for dispatch construct (Sema & Codegen) support. (PR #117904)

2024-12-04 Thread via cfe-commits

SunilKuravinakop wrote:

I have addressed all the previous comments. Can you please take a look?

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


[clang] [clang-tools-extra] [clang] Avoid re-evaluating field bitwidth (PR #117732)

2024-12-04 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/117732

>From 90929a23af50f7b209e68055abf4deb903a490cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 27 Nov 2024 08:54:51 +0100
Subject: [PATCH 1/3] Save FieldDecl BitWidth as a ConstantExpr

---
 .../bugprone/TooSmallLoopVariableCheck.cpp|  2 +-
 .../NarrowingConversionsCheck.cpp |  2 +-
 .../hicpp/MultiwayPathsCoveredCheck.cpp   |  2 +-
 clang-tools-extra/clangd/Hover.cpp|  2 +-
 clang/include/clang/AST/Decl.h|  4 ++--
 clang/include/clang/ASTMatchers/ASTMatchers.h |  3 +--
 clang/lib/AST/ASTContext.cpp  | 10 -
 clang/lib/AST/ByteCode/Interp.h   | 10 -
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp |  2 +-
 clang/lib/AST/Decl.cpp| 13 +++-
 clang/lib/AST/DeclCXX.cpp |  2 +-
 clang/lib/AST/Expr.cpp|  3 +--
 clang/lib/AST/ExprConstant.cpp|  2 +-
 clang/lib/AST/Randstruct.cpp  |  2 +-
 clang/lib/AST/RecordLayoutBuilder.cpp |  6 +++---
 clang/lib/CodeGen/ABIInfo.cpp |  2 +-
 clang/lib/CodeGen/ABIInfoImpl.cpp |  2 +-
 clang/lib/CodeGen/CGCall.cpp  |  6 +++---
 clang/lib/CodeGen/CGClass.cpp |  2 +-
 clang/lib/CodeGen/CGDebugInfo.cpp |  8 +++
 clang/lib/CodeGen/CGNonTrivialStruct.cpp  |  6 +++---
 clang/lib/CodeGen/CGObjCMac.cpp   |  3 +--
 clang/lib/CodeGen/CGObjCRuntime.cpp   |  2 +-
 clang/lib/CodeGen/CGRecordLayoutBuilder.cpp   | 20 +-
 clang/lib/CodeGen/SwiftCallingConv.cpp|  2 +-
 clang/lib/CodeGen/Targets/LoongArch.cpp   |  2 +-
 clang/lib/CodeGen/Targets/RISCV.cpp   |  2 +-
 clang/lib/CodeGen/Targets/X86.cpp |  2 +-
 clang/lib/CodeGen/Targets/XCore.cpp   |  2 +-
 .../Frontend/Rewrite/RewriteModernObjC.cpp|  3 ++-
 clang/lib/Sema/SemaChecking.cpp   | 10 -
 clang/lib/Sema/SemaDecl.cpp   | 21 ++-
 clang/lib/Sema/SemaDeclCXX.cpp|  6 +++---
 clang/lib/Sema/SemaDeclObjC.cpp   |  3 +--
 clang/lib/Sema/SemaOverload.cpp   |  2 +-
 clang/lib/StaticAnalyzer/Core/RegionStore.cpp |  2 +-
 clang/tools/libclang/CXType.cpp   |  2 +-
 clang/unittests/AST/ASTImporterTest.cpp   |  4 ++--
 38 files changed, 88 insertions(+), 91 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
index a73d46f01d9b2d..4ceeefb78ee824 100644
--- a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
@@ -124,7 +124,7 @@ static MagnitudeBits calcMagnitudeBits(const ASTContext 
&Context,
   unsigned SignedBits = IntExprType->isUnsignedIntegerType() ? 0U : 1U;
 
   if (const auto *BitField = IntExpr->getSourceBitField()) {
-unsigned BitFieldWidth = BitField->getBitWidthValue(Context);
+unsigned BitFieldWidth = BitField->getBitWidthValue();
 return {BitFieldWidth - SignedBits, BitFieldWidth};
   }
 
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
index 45fef9471d5211..25931d57943de1 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
@@ -38,7 +38,7 @@ AST_MATCHER(FieldDecl, hasIntBitwidth) {
   assert(Node.isBitField());
   const ASTContext &Ctx = Node.getASTContext();
   unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
-  unsigned CurrentBitWidth = Node.getBitWidthValue(Ctx);
+  unsigned CurrentBitWidth = Node.getBitWidthValue();
   return IntBitWidth == CurrentBitWidth;
 }
 
diff --git a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp 
b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
index 47dafca2d03ff0..7028c3958f103e 100644
--- a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
@@ -160,7 +160,7 @@ void MultiwayPathsCoveredCheck::handleSwitchWithoutDefault(
 }
 if (const auto *BitfieldDecl =
 Result.Nodes.getNodeAs("bitfield")) {
-  return twoPow(BitfieldDecl->getBitWidthValue(*Result.Context));
+  return twoPow(BitfieldDecl->getBitWidthValue());
 }
 
 return static_cast(0);
diff --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 298fa79e3fd0ba..5e136d0e76ece7 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -1

[clang] [clang][bytecode] Pass __builtin_memcpy size along (PR #118649)

2024-12-04 Thread Timm Baeder via cfe-commits

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


[clang] abc2703 - [clang][bytecode] Pass __builtin_memcpy size along (#118649)

2024-12-04 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-12-05T06:55:18+01:00
New Revision: abc27039be63ce31afe42fc10510921b559db4fe

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

LOG: [clang][bytecode] Pass __builtin_memcpy size along (#118649)

To DoBitCastPtr, so we know how many bytes we want to read.

Added: 


Modified: 
clang/lib/AST/ByteCode/InterpBuiltin.cpp
clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
clang/lib/AST/ByteCode/InterpBuiltinBitCast.h
clang/test/AST/ByteCode/builtin-functions.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 85cffb0c4332df..24b630d0455e14 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1831,7 +1831,7 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
   if (DestPtr.isDummy() || SrcPtr.isDummy())
 return false;
 
-  if (!DoBitCastPtr(S, OpPC, SrcPtr, DestPtr))
+  if (!DoBitCastPtr(S, OpPC, SrcPtr, DestPtr, Size.getZExtValue()))
 return false;
 
   S.Stk.push(DestPtr);

diff  --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
index 8f7edaa18c74b4..03c556cd70bb7a 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
@@ -315,9 +315,17 @@ bool clang::interp::DoBitCast(InterpState &S, CodePtr 
OpPC, const Pointer &Ptr,
 
   return Success;
 }
-
 bool clang::interp::DoBitCastPtr(InterpState &S, CodePtr OpPC,
  const Pointer &FromPtr, Pointer &ToPtr) {
+  const ASTContext &ASTCtx = S.getASTContext();
+  CharUnits ObjectReprChars = ASTCtx.getTypeSizeInChars(ToPtr.getType());
+
+  return DoBitCastPtr(S, OpPC, FromPtr, ToPtr, ObjectReprChars.getQuantity());
+}
+
+bool clang::interp::DoBitCastPtr(InterpState &S, CodePtr OpPC,
+ const Pointer &FromPtr, Pointer &ToPtr,
+ size_t Size) {
   assert(FromPtr.isLive());
   assert(FromPtr.isBlockPointer());
   assert(ToPtr.isBlockPointer());
@@ -331,9 +339,7 @@ bool clang::interp::DoBitCastPtr(InterpState &S, CodePtr 
OpPC,
 return false;
 
   const ASTContext &ASTCtx = S.getASTContext();
-
-  CharUnits ObjectReprChars = ASTCtx.getTypeSizeInChars(ToType);
-  BitcastBuffer Buffer(Bits(ASTCtx.toBits(ObjectReprChars)));
+  BitcastBuffer Buffer(Bytes(Size).toBits());
   readPointerToBuffer(S.getContext(), FromPtr, Buffer,
   /*ReturnOnUninit=*/false);
 

diff  --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.h 
b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.h
index 494c0880a9c453..8142e0bf28fcf2 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.h
+++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.h
@@ -21,6 +21,8 @@ bool DoBitCast(InterpState &S, CodePtr OpPC, const Pointer 
&Ptr,
std::byte *Buff, size_t BuffSize, bool &HasIndeterminateBits);
 bool DoBitCastPtr(InterpState &S, CodePtr OpPC, const Pointer &FromPtr,
   Pointer &ToPtr);
+bool DoBitCastPtr(InterpState &S, CodePtr OpPC, const Pointer &FromPtr,
+  Pointer &ToPtr, size_t Size);
 
 } // namespace interp
 } // namespace clang

diff  --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index f70b77fe74636b..e2121a54e15768 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1151,6 +1151,13 @@ namespace BuiltinMemcpy {
   }
   static_assert(simple() == 12);
 
+  constexpr bool arrayMemcpy() {
+char src[] = "abc";
+char dst[4] = {};
+__builtin_memcpy(dst, src, 4);
+return dst[0] == 'a' && dst[1] == 'b' && dst[2] == 'c' && dst[3] == '\0';
+  }
+  static_assert(arrayMemcpy());
 
   extern struct Incomplete incomplete;
   constexpr struct Incomplete *null_incomplete = 0;



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


[clang] [flang] [clang][driver] Special care for linker flags in config files (PR #117573)

2024-12-04 Thread Fangrui Song via cfe-commits

MaskRay wrote:

It's worth spending more time discussing the metacharacter.

`^` can be interpreted as `^` in regex, which means the beginning. `$`, on the 
other side, suggests the end.

In CCC_OVERRIDE_OPTIONS (clang/lib/Driver/Driver.cpp), `^` is to add an option 
at the beginning, but there is no `$`. There is `+`, whose meaning is slightly 
different.

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


[clang] [clang-format] Fix an assertion failure in RemoveSemicolon (PR #117472)

2024-12-04 Thread Owen Pan via cfe-commits

owenca wrote:

Ping @mydeveloperday @HazardyKnusperkeks

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


[clang] [clang][ExprConst] Add diagnostics for invalid binary arithmetic (PR #118475)

2024-12-04 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/118475

>From ce52d3d0c04fc53b814debdcd2c5019f488eddc0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 3 Dec 2024 11:54:07 +0100
Subject: [PATCH 1/3] [clang][ExprConst] Add diagnostics for invalid binary
 arithmetic

... between unrelated declarations or literals.
---
 clang/include/clang/Basic/DiagnosticASTKinds.td |  4 
 clang/lib/AST/ExprConstant.cpp  | 17 +++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index f630698757c5fb..4d078fc9ca6bb7 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -91,11 +91,15 @@ def note_constexpr_pointer_subtraction_zero_size : Note<
   "subtraction of pointers to type %0 of zero size">;
 def note_constexpr_pointer_comparison_unspecified : Note<
   "comparison between '%0' and '%1' has unspecified value">;
+def note_constexpr_pointer_arith_unspecified : Note<
+  "arithmetic involving '%0' and '%1' has unspecified value">;
 def note_constexpr_pointer_constant_comparison : Note<
   "comparison of numeric address '%0' with pointer '%1' can only be performed "
   "at runtime">;
 def note_constexpr_literal_comparison : Note<
   "comparison of addresses of literals has unspecified value">;
+def note_constexpr_literal_arith : Note<
+  "arithmetic on addresses of literals has unspecified value">;
 def note_constexpr_opaque_call_comparison : Note<
   "comparison against opaque constant address '%0' can only be performed at "
   "runtime">;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6b5b95aee35522..2aefcd870ebaf8 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14548,8 +14548,21 @@ bool IntExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
 return Error(E);
   const Expr *LHSExpr = LHSValue.Base.dyn_cast();
   const Expr *RHSExpr = RHSValue.Base.dyn_cast();
-  if (!LHSExpr || !RHSExpr)
-return Error(E);
+  if (!LHSExpr || !RHSExpr) {
+std::string LHS = LHSValue.toString(Info.Ctx, E->getLHS()->getType());
+std::string RHS = RHSValue.toString(Info.Ctx, E->getRHS()->getType());
+Info.FFDiag(E, diag::note_constexpr_pointer_arith_unspecified)
+<< LHS << RHS;
+return false;
+  }
+
+  if (ArePotentiallyOverlappingStringLiterals(Info, LHSValue, RHSValue)) {
+std::string LHS = LHSValue.toString(Info.Ctx, E->getLHS()->getType());
+std::string RHS = RHSValue.toString(Info.Ctx, E->getRHS()->getType());
+Info.FFDiag(E, diag::note_constexpr_literal_arith) << LHS << RHS;
+return false;
+  }
+
   const AddrLabelExpr *LHSAddrExpr = dyn_cast(LHSExpr);
   const AddrLabelExpr *RHSAddrExpr = dyn_cast(RHSExpr);
   if (!LHSAddrExpr || !RHSAddrExpr)

>From e59b74fe979a17898096e0039dd4572241124bc9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 4 Dec 2024 16:04:25 +0100
Subject: [PATCH 2/3] Address review comments

---
 .../include/clang/Basic/DiagnosticASTKinds.td | 10 ---
 clang/lib/AST/ExprConstant.cpp| 27 ++-
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 4d078fc9ca6bb7..ab432606edbc4c 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -90,16 +90,18 @@ def note_constexpr_pointer_subtraction_not_same_array : 
Note<
 def note_constexpr_pointer_subtraction_zero_size : Note<
   "subtraction of pointers to type %0 of zero size">;
 def note_constexpr_pointer_comparison_unspecified : Note<
-  "comparison between '%0' and '%1' has unspecified value">;
+  "comparison between pointers to unrelated objects '%0' and '%1' has 
unspecified value">;
 def note_constexpr_pointer_arith_unspecified : Note<
-  "arithmetic involving '%0' and '%1' has unspecified value">;
+  "arithmetic involving unrelated objects '%0' and '%1' has unspecified 
value">;
 def note_constexpr_pointer_constant_comparison : Note<
   "comparison of numeric address '%0' with pointer '%1' can only be performed "
   "at runtime">;
 def note_constexpr_literal_comparison : Note<
-  "comparison of addresses of literals has unspecified value">;
+  "comparison of addresses of potentially overlapping literals has unspecified 
value">;
 def note_constexpr_literal_arith : Note<
-  "arithmetic on addresses of literals has unspecified value">;
+  "arithmetic on addresses of potentially overlapping literals has unspecified 
value">;
+def note_constexpr_repeated_literal_eval : Note<
+  "repeated evaluation 

[clang] [CIR] Integral types; simple global variables (PR #118743)

2024-12-04 Thread David Olsen via cfe-commits

https://github.com/dkolsen-pgi created 
https://github.com/llvm/llvm-project/pull/118743

Add integral types to ClangIR.  These are the first ClangIR types, so the 
change includes some infrastructure for managing ClangIR types.

So that the integral types can be used somewhere, generate ClangIR for global 
variables using the new `cir.global` op.  As with the current support for 
functions, global variables are just a stub at the moment. The only properties 
that global variables have are a name and a type.

Add a new ClangIR code gen test global-var-simple.cpp, which defines global 
variables with most of the integral types.

(Part of upstreaming the ClangIR incubator project into LLVM.)

>From 3f911a452599d6b92218db2e12059ee8613a12bc Mon Sep 17 00:00:00 2001
From: David Olsen 
Date: Wed, 4 Dec 2024 21:32:52 -0800
Subject: [PATCH] [CIR] Integral types; simple global variables

Add integral types to ClangIR.  These are the first ClangIR types, so
the change includes some infrastructure for managing ClangIR types.

So that the integral types can be used somewhere, generate ClangIR for
global variables using the new cir.global op.  As with the current
support for functions, global variables are just a stub at the moment.
The only properties that global variables have are a name and a type.

Add a new ClangIR code gen test global-var-simple.cpp, which defines
global variables with most of the integral types.

(Part of upstreaming the ClangIR incubator project into LLVM.)
---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  29 +++-
 clang/include/clang/CIR/Dialect/IR/CIRTypes.h |  27 
 .../include/clang/CIR/Dialect/IR/CIRTypes.td  | 130 ++
 clang/lib/CIR/CodeGen/CIRGenModule.cpp|  42 +++---
 clang/lib/CIR/CodeGen/CIRGenModule.h  |  33 -
 clang/lib/CIR/CodeGen/CIRGenTypes.cpp |  97 +
 clang/lib/CIR/CodeGen/CIRGenTypes.h   |  47 +++
 clang/lib/CIR/CodeGen/CMakeLists.txt  |   1 +
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   |  18 +++
 clang/lib/CIR/Dialect/IR/CIRTypes.cpp | 120 +++-
 clang/lib/CIR/Dialect/IR/CMakeLists.txt   |   4 +
 clang/test/CIR/global-var-simple.cpp  |  53 +++
 12 files changed, 567 insertions(+), 34 deletions(-)
 create mode 100644 clang/include/clang/CIR/Dialect/IR/CIRTypes.h
 create mode 100644 clang/include/clang/CIR/Dialect/IR/CIRTypes.td
 create mode 100644 clang/lib/CIR/CodeGen/CIRGenTypes.cpp
 create mode 100644 clang/lib/CIR/CodeGen/CIRGenTypes.h
 create mode 100644 clang/test/CIR/global-var-simple.cpp

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 4462eb6fc00bae..04b3e77dcf6f38 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_CIR_DIALECT_IR_CIROPS
 
 include "clang/CIR/Dialect/IR/CIRDialect.td"
+include "clang/CIR/Dialect/IR/CIRTypes.td"
 
 include "mlir/IR/BuiltinAttributeInterfaces.td"
 include "mlir/IR/EnumAttr.td"
@@ -74,6 +75,32 @@ class LLVMLoweringInfo {
 class CIR_Op traits = []> :
 Op, LLVMLoweringInfo;
 
+//===--===//
+// GlobalOp
+//===--===//
+
+// TODO(CIR): For starters, cir.global has only name and type.  The other
+// properties of a global variable will be added over time as more of ClangIR
+// is upstreamed.
+
+def GlobalOp : CIR_Op<"global"> {
+  let summary = "Declare or define a global variable";
+  let description = [{
+... lots of text to be added later ...
+  }];
+
+  let arguments = (ins SymbolNameAttr:$sym_name, TypeAttr:$sym_type);
+
+  let assemblyFormat = [{ $sym_name `:` $sym_type attr-dict }];
+
+  let skipDefaultBuilders = 1;
+
+  let builders = [OpBuilder<(ins "llvm::StringRef":$sym_name,
+"mlir::Type":$sym_type)>];
+
+  let hasVerifier = 1;
+}
+
 
//===--===//
 // FuncOp
 
//===--===//
@@ -92,7 +119,7 @@ def FuncOp : CIR_Op<"func"> {
 
   let skipDefaultBuilders = 1;
 
-  let builders = [OpBuilder<(ins "llvm::StringRef":$name)>];
+  let builders = [OpBuilder<(ins "llvm::StringRef":$sym_name)>];
 
   let hasCustomAssemblyFormat = 1;
   let hasVerifier = 1;
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
new file mode 100644
index 00..89fb355ed2a051
--- /dev/null
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
@@ -0,0 +1,27 @@
+//===- CIRTypes.h - MLIR CIR Types --*- 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-Identifi

[clang] [CIR] Integral types; simple global variables (PR #118743)

2024-12-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: David Olsen (dkolsen-pgi)


Changes

Add integral types to ClangIR.  These are the first ClangIR types, so the 
change includes some infrastructure for managing ClangIR types.

So that the integral types can be used somewhere, generate ClangIR for global 
variables using the new `cir.global` op.  As with the current support for 
functions, global variables are just a stub at the moment. The only properties 
that global variables have are a name and a type.

Add a new ClangIR code gen test global-var-simple.cpp, which defines global 
variables with most of the integral types.

(Part of upstreaming the ClangIR incubator project into LLVM.)

---

Patch is 27.19 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/118743.diff


12 Files Affected:

- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+28-1) 
- (added) clang/include/clang/CIR/Dialect/IR/CIRTypes.h (+27) 
- (added) clang/include/clang/CIR/Dialect/IR/CIRTypes.td (+130) 
- (modified) clang/lib/CIR/CodeGen/CIRGenModule.cpp (+20-22) 
- (modified) clang/lib/CIR/CodeGen/CIRGenModule.h (+26-7) 
- (added) clang/lib/CIR/CodeGen/CIRGenTypes.cpp (+97) 
- (added) clang/lib/CIR/CodeGen/CIRGenTypes.h (+47) 
- (modified) clang/lib/CIR/CodeGen/CMakeLists.txt (+1) 
- (modified) clang/lib/CIR/Dialect/IR/CIRDialect.cpp (+18) 
- (modified) clang/lib/CIR/Dialect/IR/CIRTypes.cpp (+116-4) 
- (modified) clang/lib/CIR/Dialect/IR/CMakeLists.txt (+4) 
- (added) clang/test/CIR/global-var-simple.cpp (+53) 


``diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 4462eb6fc00bae..04b3e77dcf6f38 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_CIR_DIALECT_IR_CIROPS
 
 include "clang/CIR/Dialect/IR/CIRDialect.td"
+include "clang/CIR/Dialect/IR/CIRTypes.td"
 
 include "mlir/IR/BuiltinAttributeInterfaces.td"
 include "mlir/IR/EnumAttr.td"
@@ -74,6 +75,32 @@ class LLVMLoweringInfo {
 class CIR_Op traits = []> :
 Op, LLVMLoweringInfo;
 
+//===--===//
+// GlobalOp
+//===--===//
+
+// TODO(CIR): For starters, cir.global has only name and type.  The other
+// properties of a global variable will be added over time as more of ClangIR
+// is upstreamed.
+
+def GlobalOp : CIR_Op<"global"> {
+  let summary = "Declare or define a global variable";
+  let description = [{
+... lots of text to be added later ...
+  }];
+
+  let arguments = (ins SymbolNameAttr:$sym_name, TypeAttr:$sym_type);
+
+  let assemblyFormat = [{ $sym_name `:` $sym_type attr-dict }];
+
+  let skipDefaultBuilders = 1;
+
+  let builders = [OpBuilder<(ins "llvm::StringRef":$sym_name,
+"mlir::Type":$sym_type)>];
+
+  let hasVerifier = 1;
+}
+
 
//===--===//
 // FuncOp
 
//===--===//
@@ -92,7 +119,7 @@ def FuncOp : CIR_Op<"func"> {
 
   let skipDefaultBuilders = 1;
 
-  let builders = [OpBuilder<(ins "llvm::StringRef":$name)>];
+  let builders = [OpBuilder<(ins "llvm::StringRef":$sym_name)>];
 
   let hasCustomAssemblyFormat = 1;
   let hasVerifier = 1;
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
new file mode 100644
index 00..89fb355ed2a051
--- /dev/null
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
@@ -0,0 +1,27 @@
+//===- CIRTypes.h - MLIR CIR Types --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file declares the types in the CIR dialect.
+//
+//===--===//
+
+#ifndef MLIR_DIALECT_CIR_IR_CIRTYPES_H_
+#define MLIR_DIALECT_CIR_IR_CIRTYPES_H_
+
+#include "mlir/IR/BuiltinAttributes.h"
+#include "mlir/IR/Types.h"
+#include "mlir/Interfaces/DataLayoutInterfaces.h"
+
+//===--===//
+// CIR Dialect Tablegen'd Types
+//===--===//
+
+#define GET_TYPEDEF_CLASSES
+#include "clang/CIR/Dialect/IR/CIROpsTypes.h.inc"
+
+#endif // MLIR_DIALECT_CIR_IR_CIRTYPES_H_
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
new file mode 100644
index 00..92a561d6d2fd3f
--- /dev/null
+++ b/clang/include/clang/CIR/Dial

[clang] [CIR] Integral types; simple global variables (PR #118743)

2024-12-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: David Olsen (dkolsen-pgi)


Changes

Add integral types to ClangIR.  These are the first ClangIR types, so the 
change includes some infrastructure for managing ClangIR types.

So that the integral types can be used somewhere, generate ClangIR for global 
variables using the new `cir.global` op.  As with the current support for 
functions, global variables are just a stub at the moment. The only properties 
that global variables have are a name and a type.

Add a new ClangIR code gen test global-var-simple.cpp, which defines global 
variables with most of the integral types.

(Part of upstreaming the ClangIR incubator project into LLVM.)

---

Patch is 27.19 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/118743.diff


12 Files Affected:

- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+28-1) 
- (added) clang/include/clang/CIR/Dialect/IR/CIRTypes.h (+27) 
- (added) clang/include/clang/CIR/Dialect/IR/CIRTypes.td (+130) 
- (modified) clang/lib/CIR/CodeGen/CIRGenModule.cpp (+20-22) 
- (modified) clang/lib/CIR/CodeGen/CIRGenModule.h (+26-7) 
- (added) clang/lib/CIR/CodeGen/CIRGenTypes.cpp (+97) 
- (added) clang/lib/CIR/CodeGen/CIRGenTypes.h (+47) 
- (modified) clang/lib/CIR/CodeGen/CMakeLists.txt (+1) 
- (modified) clang/lib/CIR/Dialect/IR/CIRDialect.cpp (+18) 
- (modified) clang/lib/CIR/Dialect/IR/CIRTypes.cpp (+116-4) 
- (modified) clang/lib/CIR/Dialect/IR/CMakeLists.txt (+4) 
- (added) clang/test/CIR/global-var-simple.cpp (+53) 


``diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 4462eb6fc00bae..04b3e77dcf6f38 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_CIR_DIALECT_IR_CIROPS
 
 include "clang/CIR/Dialect/IR/CIRDialect.td"
+include "clang/CIR/Dialect/IR/CIRTypes.td"
 
 include "mlir/IR/BuiltinAttributeInterfaces.td"
 include "mlir/IR/EnumAttr.td"
@@ -74,6 +75,32 @@ class LLVMLoweringInfo {
 class CIR_Op traits = []> :
 Op, LLVMLoweringInfo;
 
+//===--===//
+// GlobalOp
+//===--===//
+
+// TODO(CIR): For starters, cir.global has only name and type.  The other
+// properties of a global variable will be added over time as more of ClangIR
+// is upstreamed.
+
+def GlobalOp : CIR_Op<"global"> {
+  let summary = "Declare or define a global variable";
+  let description = [{
+... lots of text to be added later ...
+  }];
+
+  let arguments = (ins SymbolNameAttr:$sym_name, TypeAttr:$sym_type);
+
+  let assemblyFormat = [{ $sym_name `:` $sym_type attr-dict }];
+
+  let skipDefaultBuilders = 1;
+
+  let builders = [OpBuilder<(ins "llvm::StringRef":$sym_name,
+"mlir::Type":$sym_type)>];
+
+  let hasVerifier = 1;
+}
+
 
//===--===//
 // FuncOp
 
//===--===//
@@ -92,7 +119,7 @@ def FuncOp : CIR_Op<"func"> {
 
   let skipDefaultBuilders = 1;
 
-  let builders = [OpBuilder<(ins "llvm::StringRef":$name)>];
+  let builders = [OpBuilder<(ins "llvm::StringRef":$sym_name)>];
 
   let hasCustomAssemblyFormat = 1;
   let hasVerifier = 1;
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
new file mode 100644
index 00..89fb355ed2a051
--- /dev/null
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
@@ -0,0 +1,27 @@
+//===- CIRTypes.h - MLIR CIR Types --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file declares the types in the CIR dialect.
+//
+//===--===//
+
+#ifndef MLIR_DIALECT_CIR_IR_CIRTYPES_H_
+#define MLIR_DIALECT_CIR_IR_CIRTYPES_H_
+
+#include "mlir/IR/BuiltinAttributes.h"
+#include "mlir/IR/Types.h"
+#include "mlir/Interfaces/DataLayoutInterfaces.h"
+
+//===--===//
+// CIR Dialect Tablegen'd Types
+//===--===//
+
+#define GET_TYPEDEF_CLASSES
+#include "clang/CIR/Dialect/IR/CIROpsTypes.h.inc"
+
+#endif // MLIR_DIALECT_CIR_IR_CIRTYPES_H_
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
new file mode 100644
index 00..92a561d6d2fd3f
--- /dev/null
+++ b/clang/include/clang/CIR/Di

[clang] [clang][ExprConst] Add diagnostics for invalid binary arithmetic (PR #118475)

2024-12-04 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/118475

>From ce52d3d0c04fc53b814debdcd2c5019f488eddc0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 3 Dec 2024 11:54:07 +0100
Subject: [PATCH 1/3] [clang][ExprConst] Add diagnostics for invalid binary
 arithmetic

... between unrelated declarations or literals.
---
 clang/include/clang/Basic/DiagnosticASTKinds.td |  4 
 clang/lib/AST/ExprConstant.cpp  | 17 +++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index f630698757c5fb..4d078fc9ca6bb7 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -91,11 +91,15 @@ def note_constexpr_pointer_subtraction_zero_size : Note<
   "subtraction of pointers to type %0 of zero size">;
 def note_constexpr_pointer_comparison_unspecified : Note<
   "comparison between '%0' and '%1' has unspecified value">;
+def note_constexpr_pointer_arith_unspecified : Note<
+  "arithmetic involving '%0' and '%1' has unspecified value">;
 def note_constexpr_pointer_constant_comparison : Note<
   "comparison of numeric address '%0' with pointer '%1' can only be performed "
   "at runtime">;
 def note_constexpr_literal_comparison : Note<
   "comparison of addresses of literals has unspecified value">;
+def note_constexpr_literal_arith : Note<
+  "arithmetic on addresses of literals has unspecified value">;
 def note_constexpr_opaque_call_comparison : Note<
   "comparison against opaque constant address '%0' can only be performed at "
   "runtime">;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6b5b95aee35522..2aefcd870ebaf8 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14548,8 +14548,21 @@ bool IntExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
 return Error(E);
   const Expr *LHSExpr = LHSValue.Base.dyn_cast();
   const Expr *RHSExpr = RHSValue.Base.dyn_cast();
-  if (!LHSExpr || !RHSExpr)
-return Error(E);
+  if (!LHSExpr || !RHSExpr) {
+std::string LHS = LHSValue.toString(Info.Ctx, E->getLHS()->getType());
+std::string RHS = RHSValue.toString(Info.Ctx, E->getRHS()->getType());
+Info.FFDiag(E, diag::note_constexpr_pointer_arith_unspecified)
+<< LHS << RHS;
+return false;
+  }
+
+  if (ArePotentiallyOverlappingStringLiterals(Info, LHSValue, RHSValue)) {
+std::string LHS = LHSValue.toString(Info.Ctx, E->getLHS()->getType());
+std::string RHS = RHSValue.toString(Info.Ctx, E->getRHS()->getType());
+Info.FFDiag(E, diag::note_constexpr_literal_arith) << LHS << RHS;
+return false;
+  }
+
   const AddrLabelExpr *LHSAddrExpr = dyn_cast(LHSExpr);
   const AddrLabelExpr *RHSAddrExpr = dyn_cast(RHSExpr);
   if (!LHSAddrExpr || !RHSAddrExpr)

>From e59b74fe979a17898096e0039dd4572241124bc9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 4 Dec 2024 16:04:25 +0100
Subject: [PATCH 2/3] Address review comments

---
 .../include/clang/Basic/DiagnosticASTKinds.td | 10 ---
 clang/lib/AST/ExprConstant.cpp| 27 ++-
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 4d078fc9ca6bb7..ab432606edbc4c 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -90,16 +90,18 @@ def note_constexpr_pointer_subtraction_not_same_array : 
Note<
 def note_constexpr_pointer_subtraction_zero_size : Note<
   "subtraction of pointers to type %0 of zero size">;
 def note_constexpr_pointer_comparison_unspecified : Note<
-  "comparison between '%0' and '%1' has unspecified value">;
+  "comparison between pointers to unrelated objects '%0' and '%1' has 
unspecified value">;
 def note_constexpr_pointer_arith_unspecified : Note<
-  "arithmetic involving '%0' and '%1' has unspecified value">;
+  "arithmetic involving unrelated objects '%0' and '%1' has unspecified 
value">;
 def note_constexpr_pointer_constant_comparison : Note<
   "comparison of numeric address '%0' with pointer '%1' can only be performed "
   "at runtime">;
 def note_constexpr_literal_comparison : Note<
-  "comparison of addresses of literals has unspecified value">;
+  "comparison of addresses of potentially overlapping literals has unspecified 
value">;
 def note_constexpr_literal_arith : Note<
-  "arithmetic on addresses of literals has unspecified value">;
+  "arithmetic on addresses of potentially overlapping literals has unspecified 
value">;
+def note_constexpr_repeated_literal_eval : Note<
+  "repeated evaluation 

[clang] [flang] [clang][driver] Special care for linker flags in config files (PR #117573)

2024-12-04 Thread Fangrui Song via cfe-commits


@@ -297,6 +297,9 @@ class Driver {
   /// Object that stores strings read from configuration file.
   llvm::StringSaver Saver;
 
+  /// Linker inputs originated from configuration file.
+  std::unique_ptr CfgLinkerInputs;

MaskRay wrote:

`CfgLinkerInputs` is not a good name as the implementation is generic, not 
coupled with linker options.

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


[clang] f98c9a9 - [mutation analyzer][NFC] combine `ConditionalOperator` `BinaryConditionalOperator` (#118602)

2024-12-04 Thread via cfe-commits

Author: Congcong Cai
Date: 2024-12-05T11:17:45+08:00
New Revision: f98c9a9b3665c75a6bf01577734f16185710009d

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

LOG: [mutation analyzer][NFC] combine `ConditionalOperator` 
`BinaryConditionalOperator` (#118602)

Added: 


Modified: 
clang/lib/Analysis/ExprMutationAnalyzer.cpp

Removed: 




diff  --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp 
b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index be0e8aa5743dd9..53b838e9ede4d7 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -55,25 +55,13 @@ static bool canExprResolveTo(const Expr *Source, const Expr 
*Target) {
   // This is matched by `IgnoreDerivedToBase(canResolveToExpr(InnerMatcher))`
   // below.
   const auto ConditionalOperatorM = [Target](const Expr *E) {
-if (const auto *OP = dyn_cast(E)) {
-  if (const auto *TE = OP->getTrueExpr()->IgnoreParens())
-if (canExprResolveTo(TE, Target))
-  return true;
-  if (const auto *FE = OP->getFalseExpr()->IgnoreParens())
-if (canExprResolveTo(FE, Target))
-  return true;
-}
-return false;
-  };
-
-  const auto ElvisOperator = [Target](const Expr *E) {
-if (const auto *OP = dyn_cast(E)) {
-  if (const auto *TE = OP->getTrueExpr()->IgnoreParens())
-if (canExprResolveTo(TE, Target))
-  return true;
-  if (const auto *FE = OP->getFalseExpr()->IgnoreParens())
-if (canExprResolveTo(FE, Target))
-  return true;
+if (const auto *CO = dyn_cast(E)) {
+  const auto *TE = CO->getTrueExpr()->IgnoreParens();
+  if (TE && canExprResolveTo(TE, Target))
+return true;
+  const auto *FE = CO->getFalseExpr()->IgnoreParens();
+  if (FE && canExprResolveTo(FE, Target))
+return true;
 }
 return false;
   };
@@ -81,8 +69,7 @@ static bool canExprResolveTo(const Expr *Source, const Expr 
*Target) {
   const Expr *SourceExprP = Source->IgnoreParens();
   return IgnoreDerivedToBase(SourceExprP,
  [&](const Expr *E) {
-   return E == Target || ConditionalOperatorM(E) ||
-  ElvisOperator(E);
+   return E == Target || ConditionalOperatorM(E);
  }) ||
  EvalCommaExpr(SourceExprP, [&](const Expr *E) {
return IgnoreDerivedToBase(



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


[clang] [mutation analyzer][NFC] combine `ConditionalOperator` `BinaryConditionalOperator` (PR #118602)

2024-12-04 Thread Congcong Cai via cfe-commits

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


[clang] Make the `CHECK` lines here resistent to `chandlerc` (PR #118736)

2024-12-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Chandler Carruth (chandlerc)


Changes

Specifically, usernames containing `handle`, such as `chandlerc`, often end up 
in paths, including the path of this test file which contains the word 
`overflow`. Combined, they create a match for `handle.*overflow` in the 
filename on my system (but likely not many others), leading this test to 
mysteriously fail for unfortunate usernames like mine. =D

No discussion of the amount of time I spent debugging this please. =[

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


1 Files Affected:

- (modified) clang/test/CodeGen/ignore-overflow-pattern.c (+3) 


``diff
diff --git a/clang/test/CodeGen/ignore-overflow-pattern.c 
b/clang/test/CodeGen/ignore-overflow-pattern.c
index c4a9d07b07aaac..4e5ed82d7967ec 100644
--- a/clang/test/CodeGen/ignore-overflow-pattern.c
+++ b/clang/test/CodeGen/ignore-overflow-pattern.c
@@ -21,7 +21,10 @@
 // unsigned negation, for example:
 // unsigned long A = -1UL;
 
+// Skip over parts of the IR containing this file's name.
+// CHECK: source_filename = {{.*}}
 
+// Ensure we don't see anything about handling overflow before the tests below.
 // CHECK-NOT: handle{{.*}}overflow
 
 extern unsigned a, b, c;

``




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


[clang] [CMake] Allow parametrizing of the static libraries in Cross ARM CMake cache. NFC. (PR #118737)

2024-12-04 Thread Vladimir Vereschaka via cfe-commits

https://github.com/vvereschaka created 
https://github.com/llvm/llvm-project/pull/118737

In order to support the cross-arm remote tests for LLDB project

(see 'lldb-remote-linux-*' public builders for details).

>From d8264b55cb84b5a7c9f1534f7c7f81e3f5c6738c Mon Sep 17 00:00:00 2001
From: Vladimir Vereschaka 
Date: Wed, 4 Dec 2024 19:24:34 -0800
Subject: [PATCH] [CMake] Allow parametrizing of the static libraries in Cross
 ARM CMake cache.

In order to support the cross-arm remote tests for LLDB project
(see lldb-remote-linux builders for details).
---
 clang/cmake/caches/CrossWinToARMLinux.cmake | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/clang/cmake/caches/CrossWinToARMLinux.cmake 
b/clang/cmake/caches/CrossWinToARMLinux.cmake
index 853217c6db61a3..c47c4ac3bb73ec 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -96,7 +96,11 @@ endif()
 if (NOT DEFINED TOOLCHAIN_SHARED_LIBS)
   set(TOOLCHAIN_SHARED_LIBS OFF)
 endif()
- 
+# Enable usage of the static libunwind and libc++abi libraries.
+if (NOT DEFINED TOOLCHAIN_USE_STATIC_LIBS)
+  set(TOOLCHAIN_USE_STATIC_LIBS ON)
+endif()
+
 if (NOT DEFINED LLVM_TARGETS_TO_BUILD)
   if ("${TOOLCHAIN_TARGET_TRIPLE}" MATCHES "^(armv|arm32)+")
 set(LLVM_TARGETS_TO_BUILD "ARM" CACHE STRING "")
@@ -206,7 +210,7 @@ 
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_USE_COMPILER_RT
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_ENABLE_SHARED
   ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
 
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_LLVM_UNWINDER
   ON CACHE BOOL "")
-set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_STATIC_UNWINDER   
   ON CACHE BOOL "")
+set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_STATIC_UNWINDER   
   ${TOOLCHAIN_USE_STATIC_LIBS} CACHE BOOL "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_COMPILER_RT  
   ON CACHE BOOL "")
 
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS 
  OFF CACHE BOOL "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_SHARED
   ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
@@ -217,7 +221,7 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ABI_VERSION
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_CXX_ABI 
   "libcxxabi" CACHE STRING "")#!!!
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS   
   ON CACHE BOOL "")
 # Merge libc++ and libc++abi libraries into the single libc++ library file.
-set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY   
   ON CACHE BOOL "")
+set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY   
   ${TOOLCHAIN_USE_STATIC_LIBS} CACHE BOOL "")
 # Forcely disable the libc++ benchmarks on Windows build hosts
 # (current benchmark test configuration does not support the cross builds 
there).
 if (WIN32)

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


[clang] [CMake] Allow parametrizing of the static libraries in Cross ARM CMake cache. NFC. (PR #118737)

2024-12-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vladimir Vereschaka (vvereschaka)


Changes

In order to support the cross-arm remote tests for LLDB project

(see 'lldb-remote-linux-*' public builders for details).

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


1 Files Affected:

- (modified) clang/cmake/caches/CrossWinToARMLinux.cmake (+7-3) 


``diff
diff --git a/clang/cmake/caches/CrossWinToARMLinux.cmake 
b/clang/cmake/caches/CrossWinToARMLinux.cmake
index 853217c6db61a3..c47c4ac3bb73ec 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -96,7 +96,11 @@ endif()
 if (NOT DEFINED TOOLCHAIN_SHARED_LIBS)
   set(TOOLCHAIN_SHARED_LIBS OFF)
 endif()
- 
+# Enable usage of the static libunwind and libc++abi libraries.
+if (NOT DEFINED TOOLCHAIN_USE_STATIC_LIBS)
+  set(TOOLCHAIN_USE_STATIC_LIBS ON)
+endif()
+
 if (NOT DEFINED LLVM_TARGETS_TO_BUILD)
   if ("${TOOLCHAIN_TARGET_TRIPLE}" MATCHES "^(armv|arm32)+")
 set(LLVM_TARGETS_TO_BUILD "ARM" CACHE STRING "")
@@ -206,7 +210,7 @@ 
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_USE_COMPILER_RT
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_ENABLE_SHARED
   ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
 
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_LLVM_UNWINDER
   ON CACHE BOOL "")
-set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_STATIC_UNWINDER   
   ON CACHE BOOL "")
+set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_STATIC_UNWINDER   
   ${TOOLCHAIN_USE_STATIC_LIBS} CACHE BOOL "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_COMPILER_RT  
   ON CACHE BOOL "")
 
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS 
  OFF CACHE BOOL "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_SHARED
   ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
@@ -217,7 +221,7 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ABI_VERSION
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_CXX_ABI 
   "libcxxabi" CACHE STRING "")#!!!
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS   
   ON CACHE BOOL "")
 # Merge libc++ and libc++abi libraries into the single libc++ library file.
-set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY   
   ON CACHE BOOL "")
+set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY   
   ${TOOLCHAIN_USE_STATIC_LIBS} CACHE BOOL "")
 # Forcely disable the libc++ benchmarks on Windows build hosts
 # (current benchmark test configuration does not support the cross builds 
there).
 if (WIN32)

``




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


[clang] Make the `CHECK` lines here resistent to `chandlerc` (PR #118736)

2024-12-04 Thread Chandler Carruth via cfe-commits

https://github.com/chandlerc created 
https://github.com/llvm/llvm-project/pull/118736

Specifically, usernames containing `handle`, such as `chandlerc`, often end up 
in paths, including the path of this test file which contains the word 
`overflow`. Combined, they create a match for `handle.*overflow` in the 
filename on my system (but likely not many others), leading this test to 
mysteriously fail for unfortunate usernames like mine. =D

No discussion of the amount of time I spent debugging this please. =[

>From 46633593ab1c6a7c997832b45872250f09dbc06a Mon Sep 17 00:00:00 2001
From: Chandler Carruth 
Date: Thu, 5 Dec 2024 03:11:42 +
Subject: [PATCH] Make the `CHECK` lines here resistent to `chandlerc`

Specifically, usernames containing `handle`, such as `chandlerc`, often
end up in paths, including the path of this test file which contains the
word `overflow`. Combined, they create a match for `handle.*overflow` in
the filename on my system (but likely not many others), leading this
test to mysteriously fail for unfortunate usernames like mine. =D

No discussion of the amount of time I spent debugging this please. =[
---
 clang/test/CodeGen/ignore-overflow-pattern.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/test/CodeGen/ignore-overflow-pattern.c 
b/clang/test/CodeGen/ignore-overflow-pattern.c
index c4a9d07b07aaac..4e5ed82d7967ec 100644
--- a/clang/test/CodeGen/ignore-overflow-pattern.c
+++ b/clang/test/CodeGen/ignore-overflow-pattern.c
@@ -21,7 +21,10 @@
 // unsigned negation, for example:
 // unsigned long A = -1UL;
 
+// Skip over parts of the IR containing this file's name.
+// CHECK: source_filename = {{.*}}
 
+// Ensure we don't see anything about handling overflow before the tests below.
 // CHECK-NOT: handle{{.*}}overflow
 
 extern unsigned a, b, c;

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


[clang-tools-extra] Re-add path normalization that was removed in 315561c86778 (PR #118718)

2024-12-04 Thread Mike Hommey via cfe-commits

glandium wrote:

The change in 315561c86778 causes problems on Windows, and I thought that's 
what it was, but it turns out it's not. Sorry for the noise. I'm still digging 
as to what exactly is going wrong on our setup.

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


[clang-tools-extra] Re-add path normalization that was removed in 315561c86778 (PR #118718)

2024-12-04 Thread Mike Hommey via cfe-commits

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


[clang] [Darwin][Driver][clang] Prioritise command line args over `DEFAULT_SYSROOT` (PR #115993)

2024-12-04 Thread Carlo Cabrera via cfe-commits

carlocab wrote:

> Maybe instead, the logic in the patch should be setting `-syslibroot` for 
> linker in following order:
> 
> * `--sysroot`
> * `-isysroot`
> * `C.getSysRoot()`, which is basically DEFAULT_SYSROOT as other cases is 
> handled in `--sysroot`

Thanks, pushed a change that I think should implement this. Haven't gotten 
around to testing it yet, I will this afternoon.

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


[clang] [llvm] [clang-format] Add new cmake target, `clang-format-style-options`, for updating ClangFormatStyleOptions.rst. (PR #111513)

2024-12-04 Thread Owen Pan via cfe-commits


@@ -53,3 +53,13 @@ foreach (file IN LISTS files)
 endforeach ()
 
 add_custom_target(clang-format-check-format DEPENDS ${check_format_depends})
+
+set(style_options_depends ${CLANG_SOURCE_DIR}/docs/ClangFormatStyleOptions.rst)
+add_custom_command(OUTPUT ${style_options_depends}

owenca wrote:

```suggestion
set(docs_tools_dir ${CLANG_SOURCE_DIR}/docs/tools)
add_custom_command(OUTPUT ${style_options_depends}
```

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


[clang] f7560ee - [clang-format] Add cmake target clang-format-style-options for updating ClangFormatStyleOptions.rst (#111513)

2024-12-04 Thread via cfe-commits

Author: Iuri Chaer
Date: 2024-12-04T22:50:01-08:00
New Revision: f7560ee97b7441eb3f5b2d0744aad857fafa5855

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

LOG: [clang-format] Add cmake target clang-format-style-options for updating 
ClangFormatStyleOptions.rst (#111513)

* Create a new `clang-format-style-options` build target which
re-generates ClangFormatStyleOptions.rst from its source header files.

As discussed in
https://github.com/llvm/llvm-project/pull/96804#discussion_r1718407404

-

Co-authored-by: Owen Pan 

Added: 


Modified: 
clang/lib/Format/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Format/CMakeLists.txt b/clang/lib/Format/CMakeLists.txt
index ff987cc608fb88..a633a15df3d9aa 100644
--- a/clang/lib/Format/CMakeLists.txt
+++ b/clang/lib/Format/CMakeLists.txt
@@ -53,3 +53,13 @@ foreach (file IN LISTS files)
 endforeach ()
 
 add_custom_target(clang-format-check-format DEPENDS ${check_format_depends})
+
+set(style_options_depends ${CLANG_SOURCE_DIR}/docs/ClangFormatStyleOptions.rst)
+add_custom_command(OUTPUT ${style_options_depends}
+  COMMAND ${Python3_EXECUTABLE} dump_format_style.py
+  WORKING_DIRECTORY ${CLANG_SOURCE_DIR}/docs/tools
+  DEPENDS ${CLANG_SOURCE_DIR}/include/clang/Format/Format.h
+  ${CLANG_SOURCE_DIR}/include/clang/Tooling/Inclusions/IncludeStyle.h
+  )
+add_custom_target(clang-format-style-options DEPENDS ${style_options_depends})
+add_dependencies(clangFormat clang-format-style-options)



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


[clang] [llvm] [clang-format] Add cmake target clang-format-style-options for updating ClangFormatStyleOptions.rst (PR #111513)

2024-12-04 Thread Owen Pan via cfe-commits

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


[clang] [llvm] [clang-format] Add cmake target clang-format-style-options for updating ClangFormatStyleOptions.rst (PR #111513)

2024-12-04 Thread Owen Pan via cfe-commits

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


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


[clang] [clang-format] Add test to ensure formatting options docs are updated (PR #118154)

2024-12-04 Thread Aiden Grossman via cfe-commits

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


[clang] [clang-format][CMake] Generate formatting options docs during build (PR #113739)

2024-12-04 Thread Aiden Grossman via cfe-commits

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


[clang] [clang-format][CMake] Generate formatting options docs during build (PR #113739)

2024-12-04 Thread Aiden Grossman via cfe-commits

boomanaiden154 wrote:

Closing in favor of #111513 / #118154.

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


[clang] [clang-format] Add test to ensure formatting options docs are updated (PR #118154)

2024-12-04 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-format

@llvm/pr-subscribers-clang

Author: Aiden Grossman (boomanaiden154)


Changes

This patch adds a lit test to clang format to ensure that the 
ClangFormatStyleOptions doc page has been updated appropriately. The test just 
runs the automatic update script and diffs the outputs to ensure they are the 
same.

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


3 Files Affected:

- (modified) clang/docs/tools/dump_format_style.py (+2-1) 
- (added) clang/test/Format/docs_updated.test (+2) 
- (modified) clang/test/Format/lit.local.cfg (+1) 


``diff
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index af0e658fcdc55d..c82b4479f299d9 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -487,5 +487,6 @@ class State:
 
 contents = substitute(contents, "FORMAT_STYLE_OPTIONS", options_text)
 
-with open(DOC_FILE, "wb") as output:
+output_file_path = sys.argv[1] if len(sys.argv) == 2 else DOC_FILE
+with open(output_file_path, "wb") as output:
 output.write(contents.encode())
diff --git a/clang/test/Format/docs_updated.test 
b/clang/test/Format/docs_updated.test
new file mode 100644
index 00..fe2e4f1bd13a1b
--- /dev/null
+++ b/clang/test/Format/docs_updated.test
@@ -0,0 +1,2 @@
+// RUN: %python %S/../../docs/tools/dump_format_style.py %t
+// RUN: diff %t %S/../../docs/ClangFormatStyleOptions.rst
diff --git a/clang/test/Format/lit.local.cfg b/clang/test/Format/lit.local.cfg
index 3eb0f54ceaa6f9..8acf02725d701b 100644
--- a/clang/test/Format/lit.local.cfg
+++ b/clang/test/Format/lit.local.cfg
@@ -17,4 +17,5 @@ config.suffixes = [
 ".textpb",
 ".asciipb",
 ".td",
+".test"
 ]

``




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


[clang] [clang-format] Add test to ensure formatting options docs are updated (PR #118154)

2024-12-04 Thread Owen Pan via cfe-commits

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


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


[clang] a9a4a83 - [clang-format] Add test to ensure formatting options docs are updated (#118154)

2024-12-04 Thread via cfe-commits

Author: Aiden Grossman
Date: 2024-12-04T23:41:12-08:00
New Revision: a9a4a83b6132f076fd14ac31268deaa4bf1381d5

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

LOG: [clang-format] Add test to ensure formatting options docs are updated 
(#118154)

This patch adds a lit test to clang format to ensure that the
ClangFormatStyleOptions doc page has been updated appropriately. The
test just runs the automatic update script and diffs the outputs to
ensure they are the same.

Added: 
clang/test/Format/docs_updated.test

Modified: 
clang/docs/tools/dump_format_style.py
clang/test/Format/lit.local.cfg

Removed: 




diff  --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index af0e658fcdc55d..c82b4479f299d9 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -487,5 +487,6 @@ class State:
 
 contents = substitute(contents, "FORMAT_STYLE_OPTIONS", options_text)
 
-with open(DOC_FILE, "wb") as output:
+output_file_path = sys.argv[1] if len(sys.argv) == 2 else DOC_FILE
+with open(output_file_path, "wb") as output:
 output.write(contents.encode())

diff  --git a/clang/test/Format/docs_updated.test 
b/clang/test/Format/docs_updated.test
new file mode 100644
index 00..fe2e4f1bd13a1b
--- /dev/null
+++ b/clang/test/Format/docs_updated.test
@@ -0,0 +1,2 @@
+// RUN: %python %S/../../docs/tools/dump_format_style.py %t
+// RUN: 
diff  %t %S/../../docs/ClangFormatStyleOptions.rst

diff  --git a/clang/test/Format/lit.local.cfg b/clang/test/Format/lit.local.cfg
index 3eb0f54ceaa6f9..8acf02725d701b 100644
--- a/clang/test/Format/lit.local.cfg
+++ b/clang/test/Format/lit.local.cfg
@@ -17,4 +17,5 @@ config.suffixes = [
 ".textpb",
 ".asciipb",
 ".td",
+".test"
 ]



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


[clang] [llvm] [clang-format] Add new cmake target, `clang-format-style-options`, for updating ClangFormatStyleOptions.rst. (PR #111513)

2024-12-04 Thread Owen Pan via cfe-commits


@@ -53,3 +53,13 @@ foreach (file IN LISTS files)
 endforeach ()
 
 add_custom_target(clang-format-check-format DEPENDS ${check_format_depends})
+
+set(style_options_depends ${CLANG_SOURCE_DIR}/docs/ClangFormatStyleOptions.rst)
+add_custom_command(OUTPUT ${style_options_depends}
+  COMMAND ${Python3_EXECUTABLE} dump_format_style.py
+  WORKING_DIRECTORY ${CLANG_SOURCE_DIR}/docs/tools

owenca wrote:

```suggestion
  WORKING_DIRECTORY ${docs_tools_dir}
```

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


[clang] [llvm] [clang-format] Add new cmake target, `clang-format-style-options`, for updating ClangFormatStyleOptions.rst. (PR #111513)

2024-12-04 Thread Owen Pan via cfe-commits


@@ -53,3 +53,13 @@ foreach (file IN LISTS files)
 endforeach ()
 
 add_custom_target(clang-format-check-format DEPENDS ${check_format_depends})
+
+set(style_options_depends ${CLANG_SOURCE_DIR}/docs/ClangFormatStyleOptions.rst)
+add_custom_command(OUTPUT ${style_options_depends}
+  COMMAND ${Python3_EXECUTABLE} dump_format_style.py
+  WORKING_DIRECTORY ${CLANG_SOURCE_DIR}/docs/tools
+  DEPENDS ${CLANG_SOURCE_DIR}/include/clang/Format/Format.h
+  ${CLANG_SOURCE_DIR}/include/clang/Tooling/Inclusions/IncludeStyle.h
+  )

owenca wrote:

```suggestion
  ${docs_tools_dir}/plurals.txt
  ${docs_tools_dir}/dump_format_style.py
  )
```

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


[clang] [CodeGen] Migrate away from PointerUnion::{is, get} (NFC) (PR #118600)

2024-12-04 Thread Nikita Popov via cfe-commits


@@ -37,8 +37,8 @@ void ConstantInitFuture::abandon() {
 
 void ConstantInitFuture::installInGlobal(llvm::GlobalVariable *GV) {
   assert(Data && "installing null future");
-  if (Data.is()) {
-GV->setInitializer(Data.get());
+  if (auto *C = dyn_cast(Data)) {
+GV->setInitializer(C);
   } else {
 auto &builder = *Data.get();

nikic wrote:

Leftover get here?

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


[clang] Add support for referencable labels for attribute documentation (PR #118428)

2024-12-04 Thread Oliver Hunt via cfe-commits

ojhunt wrote:

> LGTM after fixing one more thing.
> 
> I personally think this is a reasonable addition now, but please wait for 
> Aaron or Erich to approve this too before merging.

Righto, I've committed the change, is `const StringRef` a style violation (I 
recognize StringRef is a constant type)? (Pondering adding support for style 
rule enforcement for things like "this is a constant type so doesn't need to be 
const")

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


[clang] [libc] [llvm] [AMDGPU] Use COV6 by default (PR #118515)

2024-12-04 Thread Pierre van Houtryve via cfe-commits

Pierre-vh wrote:

@shiltian Please also remove `warn_drv_amdgpu_cov6` - it's a warning I added 
while v6 was being worked on.
Now that it's supported by the stack we can remove it.

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


[clang] [Clang] [Sema] Support matrix types in pseudo-destructor expressions (PR #117483)

2024-12-04 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/117483

>From 4eff78b4f8404217cecf254227bc79dcc11d2f36 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sun, 24 Nov 2024 13:43:02 +0100
Subject: [PATCH 1/2] [Clang] [Sema] Support matrix types in pseudo-destructor
 expressions

---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Sema/SemaExprCXX.cpp|  2 +-
 .../matrix-types-pseudo-destructor.cpp| 19 +++
 3 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/matrix-types-pseudo-destructor.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8bd06fadfdc984..ad3c0d3e67f031 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -371,6 +371,9 @@ Non-comprehensive list of changes in this release
 - ``__builtin_reduce_and`` function can now be used in constant expressions.
 - ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be 
used in constant expressions.
 
+- Matrix types (a Clang extension) can now be used in pseudo-destructor 
expressions,
+  which allows them to be stored in STL containers.
+
 New Compiler Flags
 --
 
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d85819b21c8265..d440755ee70665 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -8189,7 +8189,7 @@ ExprResult Sema::BuildPseudoDestructorExpr(Expr *Base,
 return ExprError();
 
   if (!ObjectType->isDependentType() && !ObjectType->isScalarType() &&
-  !ObjectType->isVectorType()) {
+  !ObjectType->isVectorType() && !ObjectType->isMatrixType()) {
 if (getLangOpts().MSVCCompat && ObjectType->isVoidType())
   Diag(OpLoc, diag::ext_pseudo_dtor_on_void) << Base->getSourceRange();
 else {
diff --git a/clang/test/SemaCXX/matrix-types-pseudo-destructor.cpp 
b/clang/test/SemaCXX/matrix-types-pseudo-destructor.cpp
new file mode 100644
index 00..f0ee953ad2557c
--- /dev/null
+++ b/clang/test/SemaCXX/matrix-types-pseudo-destructor.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -fenable-matrix -std=c++11 -verify %s
+// expected-no-diagnostics
+
+template 
+void f() {
+  T().~T();
+}
+
+using mat4 = float __attribute__((matrix_type(4, 4)));
+using mat4i = int __attribute__((matrix_type(4, 4)));
+
+template 
+using mat4_t = T __attribute__((matrix_type(4, 4)));
+
+void g() {
+  f();
+  f();
+  f>();
+}

>From 748f28ec638d5344c7e83dd42cc7945fa58d2341 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 4 Dec 2024 09:44:28 +0100
Subject: [PATCH 2/2] Add some codegen tests

---
 clang/test/CodeGenCXX/matrix-type.cpp | 33 +++
 1 file changed, 33 insertions(+)

diff --git a/clang/test/CodeGenCXX/matrix-type.cpp 
b/clang/test/CodeGenCXX/matrix-type.cpp
index 1a5e5dba2978c8..c3a299e7feee82 100644
--- a/clang/test/CodeGenCXX/matrix-type.cpp
+++ b/clang/test/CodeGenCXX/matrix-type.cpp
@@ -368,3 +368,36 @@ void test_use_matrix_2() {
 
   selector<2> r5 = use_matrix_3(m1);
 }
+
+// CHECK-LABEL: define void @_Z22test_pseudo_destructorv()
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %a = alloca [25 x double], align 8
+// CHECK-NEXT:   %b = alloca [12 x float], align 4
+// CHECK-NEXT:   %0 = load <25 x double>, ptr %a, align 8
+// CHECK-NEXT:   call void 
@_Z17pseudo_destructorIu11matrix_typeILm5ELm5EdEEvT_(<25 x double> %0)
+// CHECK-NEXT:   %1 = load <12 x float>, ptr %b, align 4
+// CHECK-NEXT:   call void 
@_Z17pseudo_destructorIu11matrix_typeILm3ELm4EfEEvT_(<12 x float> %1)
+// CHECK-NEXT:   ret void
+
+// CHECK-LABEL: define linkonce_odr void 
@_Z17pseudo_destructorIu11matrix_typeILm5ELm5EdEEvT_(<25 x double> %t)
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %t.addr = alloca [25 x double], align 8
+// CHECK-NEXT:   store <25 x double> %t, ptr %t.addr, align 8
+// CHECK-NEXT:   ret void
+
+// CHECK-LABEL: define linkonce_odr void 
@_Z17pseudo_destructorIu11matrix_typeILm3ELm4EfEEvT_(<12 x float> %t)
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %t.addr = alloca [12 x float], align 4
+// CHECK-NEXT:   store <12 x float> %t, ptr %t.addr, align 4
+// CHECK-NEXT:   ret void
+template 
+void pseudo_destructor(T t) {
+  t.~T();
+}
+
+void test_pseudo_destructor() {
+  dx5x5_t a;
+  fx3x4_t b;
+  pseudo_destructor(a);
+  pseudo_destructor(b);
+}

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


[clang] [Clang] [Sema] Support matrix types in pseudo-destructor expressions (PR #117483)

2024-12-04 Thread via cfe-commits

Sirraide wrote:

> I definitely agree with a need to test this/validate codegen to make sure the 
> destruciton 'looks' reasonable.

Done.

(And while adding the tests, I also discovered an unrelated bug: #118604)

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


[libclc] [libcxx] [llvm] [openmp] [polly] [llvm] Move sub-project lead maintainers into their own Maintainers.md files (PR #118309)

2024-12-04 Thread David Spickett via cfe-commits

DavidSpickett wrote:

It already landed, I'll rebase this PR.

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


[clang] [Clang] [Sema] Support matrix types in pseudo-destructor expressions (PR #117483)

2024-12-04 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/117483

>From 4eff78b4f8404217cecf254227bc79dcc11d2f36 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sun, 24 Nov 2024 13:43:02 +0100
Subject: [PATCH 1/3] [Clang] [Sema] Support matrix types in pseudo-destructor
 expressions

---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Sema/SemaExprCXX.cpp|  2 +-
 .../matrix-types-pseudo-destructor.cpp| 19 +++
 3 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/matrix-types-pseudo-destructor.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8bd06fadfdc984..ad3c0d3e67f031 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -371,6 +371,9 @@ Non-comprehensive list of changes in this release
 - ``__builtin_reduce_and`` function can now be used in constant expressions.
 - ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be 
used in constant expressions.
 
+- Matrix types (a Clang extension) can now be used in pseudo-destructor 
expressions,
+  which allows them to be stored in STL containers.
+
 New Compiler Flags
 --
 
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d85819b21c8265..d440755ee70665 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -8189,7 +8189,7 @@ ExprResult Sema::BuildPseudoDestructorExpr(Expr *Base,
 return ExprError();
 
   if (!ObjectType->isDependentType() && !ObjectType->isScalarType() &&
-  !ObjectType->isVectorType()) {
+  !ObjectType->isVectorType() && !ObjectType->isMatrixType()) {
 if (getLangOpts().MSVCCompat && ObjectType->isVoidType())
   Diag(OpLoc, diag::ext_pseudo_dtor_on_void) << Base->getSourceRange();
 else {
diff --git a/clang/test/SemaCXX/matrix-types-pseudo-destructor.cpp 
b/clang/test/SemaCXX/matrix-types-pseudo-destructor.cpp
new file mode 100644
index 00..f0ee953ad2557c
--- /dev/null
+++ b/clang/test/SemaCXX/matrix-types-pseudo-destructor.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -fenable-matrix -std=c++11 -verify %s
+// expected-no-diagnostics
+
+template 
+void f() {
+  T().~T();
+}
+
+using mat4 = float __attribute__((matrix_type(4, 4)));
+using mat4i = int __attribute__((matrix_type(4, 4)));
+
+template 
+using mat4_t = T __attribute__((matrix_type(4, 4)));
+
+void g() {
+  f();
+  f();
+  f>();
+}

>From 748f28ec638d5344c7e83dd42cc7945fa58d2341 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 4 Dec 2024 09:44:28 +0100
Subject: [PATCH 2/3] Add some codegen tests

---
 clang/test/CodeGenCXX/matrix-type.cpp | 33 +++
 1 file changed, 33 insertions(+)

diff --git a/clang/test/CodeGenCXX/matrix-type.cpp 
b/clang/test/CodeGenCXX/matrix-type.cpp
index 1a5e5dba2978c8..c3a299e7feee82 100644
--- a/clang/test/CodeGenCXX/matrix-type.cpp
+++ b/clang/test/CodeGenCXX/matrix-type.cpp
@@ -368,3 +368,36 @@ void test_use_matrix_2() {
 
   selector<2> r5 = use_matrix_3(m1);
 }
+
+// CHECK-LABEL: define void @_Z22test_pseudo_destructorv()
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %a = alloca [25 x double], align 8
+// CHECK-NEXT:   %b = alloca [12 x float], align 4
+// CHECK-NEXT:   %0 = load <25 x double>, ptr %a, align 8
+// CHECK-NEXT:   call void 
@_Z17pseudo_destructorIu11matrix_typeILm5ELm5EdEEvT_(<25 x double> %0)
+// CHECK-NEXT:   %1 = load <12 x float>, ptr %b, align 4
+// CHECK-NEXT:   call void 
@_Z17pseudo_destructorIu11matrix_typeILm3ELm4EfEEvT_(<12 x float> %1)
+// CHECK-NEXT:   ret void
+
+// CHECK-LABEL: define linkonce_odr void 
@_Z17pseudo_destructorIu11matrix_typeILm5ELm5EdEEvT_(<25 x double> %t)
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %t.addr = alloca [25 x double], align 8
+// CHECK-NEXT:   store <25 x double> %t, ptr %t.addr, align 8
+// CHECK-NEXT:   ret void
+
+// CHECK-LABEL: define linkonce_odr void 
@_Z17pseudo_destructorIu11matrix_typeILm3ELm4EfEEvT_(<12 x float> %t)
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %t.addr = alloca [12 x float], align 4
+// CHECK-NEXT:   store <12 x float> %t, ptr %t.addr, align 4
+// CHECK-NEXT:   ret void
+template 
+void pseudo_destructor(T t) {
+  t.~T();
+}
+
+void test_pseudo_destructor() {
+  dx5x5_t a;
+  fx3x4_t b;
+  pseudo_destructor(a);
+  pseudo_destructor(b);
+}

>From 91c768d80f9b4736360656f45c7beb6653d90e9a Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 4 Dec 2024 09:51:06 +0100
Subject: [PATCH 3/3] Add more sema tests

---
 .../test/SemaCXX/matrix-types-pseudo-destructor.cpp  | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/test/SemaCXX/matrix-types-pseudo-destructor.cpp 
b/clang/test/SemaCXX/matrix-types-pseudo-destructor.cpp
index f0ee953ad2557c..86fef1338955e1 100644
--- a/clang/test/SemaCXX/matrix-types-pseudo-destructor.cpp
+++ b/clang/test/SemaCXX/matrix-types-pseudo-destructor.cpp
@@ -6,6 +6,12 @@ void f() {
   T().~T();
 }
 
+tem

[clang] [Clang] [Sema] Support matrix types in pseudo-destructor expressions (PR #117483)

2024-12-04 Thread via cfe-commits


@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -fenable-matrix -std=c++11 -verify %s
+// expected-no-diagnostics
+
+template 
+void f() {
+  T().~T();
+}

Sirraide wrote:

Added a test for this too

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


[clang] [clang-repl][CMake][MSVC] Use LINKER: instead of `-Wl` (PR #118518)

2024-12-04 Thread Mészáros Gergely via cfe-commits

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


[clang] 3b0cb89 - [clang-repl][CMake][MSVC] Use LINKER: instead of `-Wl` (#118518)

2024-12-04 Thread via cfe-commits

Author: Mészáros Gergely
Date: 2024-12-04T09:54:21+01:00
New Revision: 3b0cb8979624bc052587712650bfd52f77eb69d3

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

LOG: [clang-repl][CMake][MSVC] Use LINKER: instead of `-Wl` (#118518)

This should be more portable, and avoids passing the option to
`clang-cl` when linking, because `clang-cl` accepts any `-W` flags
(normally warning flags) during linking (#118516).

Added: 


Modified: 
clang/tools/clang-repl/CMakeLists.txt

Removed: 




diff  --git a/clang/tools/clang-repl/CMakeLists.txt 
b/clang/tools/clang-repl/CMakeLists.txt
index 7aebbe7a19436a..f9a911b0ae8e24 100644
--- a/clang/tools/clang-repl/CMakeLists.txt
+++ b/clang/tools/clang-repl/CMakeLists.txt
@@ -66,7 +66,7 @@ clang_target_link_libraries(clang-repl PRIVATE
 # start to exceed this limit, e.g. when linking for arm-linux-gnueabihf with
 # gold. This flag tells the linker to build a PLT for the full address range.
 # Linkers without this flag are assumed to support proper PLTs by default.
-set(flag_long_plt "-Wl,--long-plt")
+set(flag_long_plt "LINKER:--long-plt")
 check_linker_flag(CXX ${flag_long_plt} HAVE_LINKER_FLAG_LONG_PLT)
 if(HAVE_LINKER_FLAG_LONG_PLT)
   target_link_options(clang-repl PRIVATE ${flag_long_plt})



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


[clang] [clang-repl][CMake][MSVC] Use LINKER: instead of `-Wl` (PR #118518)

2024-12-04 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`libc-x86_64-debian-fullbuild-dbg-asan` running on 
`libc-x86_64-debian-fullbuild` while building `clang` at step 4 "annotate".

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


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

```
Step 4 (annotate) failure: 'python 
../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[==] Running 1 test from 1 test suite.
[ RUN  ] LlvmLibcSelectTest.SelectInvalidFD
[   OK ] LlvmLibcSelectTest.SelectInvalidFD (27 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[947/1099] Running unit test libc.test.src.sys.sendfile.sendfile_test
[==] Running 1 test from 1 test suite.
[ RUN  ] LlvmLibcSendfileTest.CreateAndTransfer
[   OK ] LlvmLibcSendfileTest.CreateAndTransfer (374 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[948/1099] Running unit test libc.test.src.sys.mman.linux.process_mrelease_test
FAILED: 
projects/libc/test/src/sys/mman/linux/CMakeFiles/libc.test.src.sys.mman.linux.process_mrelease_test
 
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/build/projects/libc/test/src/sys/mman/linux/CMakeFiles/libc.test.src.sys.mman.linux.process_mrelease_test
 
cd 
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/build/projects/libc/test/src/sys/mman/linux
 && 
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/build/projects/libc/test/src/sys/mman/linux/libc.test.src.sys.mman.linux.process_mrelease_test.__build__
[==] Running 3 tests from 1 test suite.
[ RUN  ] LlvmLibcProcessMReleaseTest.NoError
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/src/sys/mman/linux/process_mrelease_test.cpp:44:
 FAILURE
Failed to match LIBC_NAMESPACE::process_mrelease(pidfd, 0) against Succeeds().
Expected return value to be equal to 0 but got -1.
Expected errno to be equal to "Success" but got "No such process".
[  FAILED  ] LlvmLibcProcessMReleaseTest.NoError
[ RUN  ] LlvmLibcProcessMReleaseTest.ErrorNotKilled
[   OK ] LlvmLibcProcessMReleaseTest.ErrorNotKilled (783 us)
[ RUN  ] LlvmLibcProcessMReleaseTest.ErrorNonExistingPidfd
[   OK ] LlvmLibcProcessMReleaseTest.ErrorNonExistingPidfd (9 us)
Ran 3 tests.  PASS: 2  FAIL: 1
[949/1099] Running unit test libc.test.src.sys.resource.getrlimit_setrlimit_test
[==] Running 1 test from 1 test suite.
[ RUN  ] LlvmLibcResourceLimitsTest.SetNoFileLimit
[   OK ] LlvmLibcResourceLimitsTest.SetNoFileLimit (309 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[950/1099] Running unit test libc.test.src.sys.socket.linux.socket_test
[==] Running 1 test from 1 test suite.
[ RUN  ] LlvmLibcSocketTest.LocalSocket
[   OK ] LlvmLibcSocketTest.LocalSocket (70 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[951/1099] Running unit test libc.test.src.sys.socket.linux.socketpair_test
[==] Running 2 tests from 1 test suite.
[ RUN  ] LlvmLibcSocketPairTest.LocalSocket
[   OK ] LlvmLibcSocketPairTest.LocalSocket (125 us)
[ RUN  ] LlvmLibcSocketPairTest.SocketFails
[   OK ] LlvmLibcSocketPairTest.SocketFails (3 us)
Ran 2 tests.  PASS: 2  FAIL: 0
[952/1099] Running unit test libc.test.src.sys.socket.linux.send_recv_test
[==] Running 3 tests from 1 test suite.
[ RUN  ] LlvmLibcSendRecvTest.SucceedsWithSocketPair
[   OK ] LlvmLibcSendRecvTest.SucceedsWithSocketPair (181 us)
[ RUN  ] LlvmLibcSendRecvTest.SendFails
[   OK ] LlvmLibcSendRecvTest.SendFails (3 us)
[ RUN  ] LlvmLibcSendRecvTest.RecvFails
[   OK ] LlvmLibcSendRecvTest.RecvFails (3 us)
Step 8 (libc-unit-tests) failure: libc-unit-tests (failure)
...
[==] Running 1 test from 1 test suite.
[ RUN  ] LlvmLibcSelectTest.SelectInvalidFD
[   OK ] LlvmLibcSelectTest.SelectInvalidFD (27 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[947/1099] Running unit test libc.test.src.sys.sendfile.sendfile_test
[==] Running 1 test from 1 test suite.
[ RUN  ] LlvmLibcSendfileTest.CreateAndTransfer
[   OK ] LlvmLibcSendfileTest.CreateAndTransfer (374 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[948/1099] Running unit test libc.test.src.sys.mman.linux.process_mrelease_test
FAILED: 
projects/libc/test/src/sys/mman/linux/CMakeFiles/libc.test.src.sys.mman.linux.process_mrelease_test
 
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/build/projects/libc/test/src/sys/mman/linux/CMakeFiles/libc.test.src.sys.mman.linux.process_mrelease_test
 
cd 
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/build/projects/libc/test/src/sys/mman/linux
 && 
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debia

[clang] [clang-repl][CMake][MSVC] Use LINKER: instead of `-Wl` (PR #118518)

2024-12-04 Thread Mészáros Gergely via cfe-commits

Maetveis wrote:

> LGTM!

Thanks!

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


[clang] [mutation analyzer] support mutation analysis for pointee (PR #118593)

2024-12-04 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/118593

>From 01657045893c3fca226f0682523f999cabffc1ca Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Wed, 4 Dec 2024 15:38:06 +0800
Subject: [PATCH 1/2] [analysis] support mutation analysis for pointee wip

---
 .../Analysis/Analyses/ExprMutationAnalyzer.h  |   4 +
 clang/lib/Analysis/ExprMutationAnalyzer.cpp   | 142 +++-
 .../Analysis/ExprMutationAnalyzerTest.cpp | 333 ++
 3 files changed, 476 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h 
b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
index 7442f4aad531b7..3344959072c221 100644
--- a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
+++ b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
@@ -71,6 +71,10 @@ class ExprMutationAnalyzer {
 const Stmt *findReferenceMutation(const Expr *Exp);
 const Stmt *findFunctionArgMutation(const Expr *Exp);
 
+const Stmt *findPointeeValueMutation(const Expr *Exp);
+const Stmt *findPointeeMemberMutation(const Expr *Exp);
+const Stmt *findPointeeToNonConst(const Expr *Exp);
+
 const Stmt &Stm;
 ASTContext &Context;
 Memoized &Memorized;
diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp 
b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index be0e8aa5743dd9..a1b26d0e063d55 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -8,9 +8,12 @@
 #include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/OperationKinds.h"
+#include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Casting.h"
 
 namespace clang {
 using namespace ast_matchers;
@@ -22,7 +25,6 @@ using namespace ast_matchers;
 //  - ConditionalOperator
 //  - BinaryConditionalOperator
 static bool canExprResolveTo(const Expr *Source, const Expr *Target) {
-
   const auto IgnoreDerivedToBase = [](const Expr *E, auto Matcher) {
 if (Matcher(E))
   return true;
@@ -92,6 +94,8 @@ static bool canExprResolveTo(const Expr *Source, const Expr 
*Target) {
 
 namespace {
 
+AST_MATCHER(Type, isDependentType) { return Node.isDependentType(); }
+
 AST_MATCHER_P(LambdaExpr, hasCaptureInit, const Expr *, E) {
   return llvm::is_contained(Node.capture_inits(), E);
 }
@@ -112,6 +116,53 @@ AST_MATCHER_P(Stmt, canResolveToExpr, const Stmt *, Inner) 
{
   return canExprResolveTo(Exp, Target);
 }
 
+class ExprPointeeResolve {
+  const Expr *T;
+
+  bool resolveExpr(const Expr *E) {
+if (E == T)
+  return true;
+
+if (const auto *BO = dyn_cast(E)) {
+  if (BO->isAdditiveOp())
+return (resolveExpr(BO->getLHS()) || resolveExpr(BO->getRHS()));
+  if (BO->isCommaOp())
+return resolveExpr(BO->getRHS());
+  return false;
+}
+
+if (const auto *PE = dyn_cast(E))
+  return resolveExpr(PE->getSubExpr());
+
+if (const auto *ICE = dyn_cast(E)) {
+  const CastKind kind = ICE->getCastKind();
+  if (kind == CK_LValueToRValue || kind == CK_DerivedToBase ||
+  kind == CK_UncheckedDerivedToBase)
+return resolveExpr(ICE->getSubExpr());
+  return false;
+}
+
+if (const auto *ACE = dyn_cast(E))
+  return resolve(ACE->getTrueExpr()) || resolve(ACE->getFalseExpr());
+
+return false;
+  }
+
+public:
+  ExprPointeeResolve(const Expr *T) : T(T) {}
+  bool resolve(const Expr *S) { return resolveExpr(S); }
+};
+
+AST_MATCHER_P(Stmt, canResolveToExprPointee, const Stmt *, T) {
+  auto *Exp = dyn_cast(&Node);
+  if (!Exp)
+return true;
+  auto *Target = dyn_cast(T);
+  if (!Target)
+return false;
+  return ExprPointeeResolve{Target}.resolve(Exp);
+}
+
 // Similar to 'hasAnyArgument', but does not work because 'InitListExpr' does
 // not have the 'arguments()' method.
 AST_MATCHER_P(InitListExpr, hasAnyInit, ast_matchers::internal::Matcher,
@@ -219,7 +270,14 @@ const Stmt 
*ExprMutationAnalyzer::Analyzer::findMutation(const Decl *Dec) {
 
 const Stmt *
 ExprMutationAnalyzer::Analyzer::findPointeeMutation(const Expr *Exp) {
-  return findMutationMemoized(Exp, {/*TODO*/}, Memorized.PointeeResults);
+  return findMutationMemoized(
+  Exp,
+  {
+  &ExprMutationAnalyzer::Analyzer::findPointeeValueMutation,
+  &ExprMutationAnalyzer::Analyzer::findPointeeMemberMutation,
+  &ExprMutationAnalyzer::Analyzer::findPointeeToNonConst,
+  },
+  Memorized.PointeeResults);
 }
 
 const Stmt *
@@ -388,7 +446,8 @@ ExprMutationAnalyzer::Analyzer::findDirectMutation(const 
Expr *Exp) {
   // references.
   const auto NonConstRefParam = forEachArgumentWithParamType(
   anyOf(canResolveToExpr(Exp),
-memberExpr(hasObjectExpression(canResolveToExpr(Exp,
+ 

[clang] [clang] Catch missing format attributes (PR #105479)

2024-12-04 Thread Budimir Aranđelović via cfe-commits

https://github.com/budimirarandjelovichtec updated 
https://github.com/llvm/llvm-project/pull/105479

From 26b6997e758eba43fbf6b94ae6213ca9b3894445 Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Fri, 5 Apr 2024 15:20:37 +0200
Subject: [PATCH] [clang] Catch missing format attributes

---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/Basic/DiagnosticGroups.td |   1 -
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/include/clang/Sema/Attr.h   |   7 +
 clang/include/clang/Sema/Sema.h   |   5 +
 clang/lib/Sema/SemaChecking.cpp   |   4 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 179 +++-
 clang/test/Sema/attr-format-missing.c | 259 ++
 clang/test/Sema/attr-format-missing.cpp   | 189 +
 10 files changed, 648 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/Sema/attr-format-missing.c
 create mode 100644 clang/test/Sema/attr-format-missing.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 755418e9550cf4..f0d03aa9a48973 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -632,6 +632,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses dangling references for C++20's parenthesized aggregate 
initialization (#101957).
 
+- Clang now diagnoses missing format attributes for non-template functions and 
class/struct/union members. (#GH60718)
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 3ac490d30371b1..0a97b7a1d92e01 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -536,7 +536,6 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
 def MissingIncludeDirs : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8020be6c57bcfb..6e67a627c9df76 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1055,6 +1055,10 @@ def err_opencl_invalid_param : Error<
   "declaring function parameter of type %0 is not allowed%select{; did you 
forget * ?|}1">;
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup>, DefaultIgnore;
+def note_format_function : Note<"%0 format function">;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Attr.h b/clang/include/clang/Sema/Attr.h
index 3f0b10212789a4..37c124ca7b454a 100644
--- a/clang/include/clang/Sema/Attr.h
+++ b/clang/include/clang/Sema/Attr.h
@@ -123,6 +123,13 @@ inline bool isInstanceMethod(const Decl *D) {
   return false;
 }
 
+inline bool checkIfMethodHasImplicitObjectParameter(const Decl *D) {
+  if (const auto *MethodDecl = dyn_cast(D))
+return MethodDecl->isInstance() &&
+   !MethodDecl->hasCXXExplicitFunctionObjectParameter();
+  return false;
+}
+
 /// Diagnose mutually exclusive attributes when present on a given
 /// declaration. Returns true if diagnosed.
 template 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b8684d11460eda..3f7713f994666a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4603,6 +4603,11 @@ class Sema final : public SemaBase {
 
   enum class RetainOwnershipKind { NS, CF, OS };
 
+  void DetectMissingFormatAttributes(const FunctionDecl *Callee,
+ ArrayRef Args,
+ SourceLocation Loc);
+  void EmitMissingFormatAttributesDiagnostic(const FunctionDecl *Caller);
+
   UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI,
   StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index a248a6b53b0d06..44ca093ec4b16c 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3452,8 +3452,10 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 }
   }
 
-  if (FD)
+  if (FD) {
 diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
+DetectMissin

[libclc] [libcxx] [llvm] [polly] [llvm] Move sub-project lead maintainers into their own Maintainers.md files (PR #118309)

2024-12-04 Thread David Spickett via cfe-commits

https://github.com/DavidSpickett updated 
https://github.com/llvm/llvm-project/pull/118309

>From fe59fcd2c14f7ff84857ad75bc3564cbe6752c9d Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Mon, 2 Dec 2024 15:22:50 +
Subject: [PATCH] [llvm] Move sub-project lead maintainers into their own files

This adds Maintainers.md files to the sub-projects mentioned
here, so that someone going directly to that sub-project will
find them more easily.

Recently I needed to find a libclc maintainer and I had no
idea there was one listed here instead of in libclc/.
---
 libclc/Maintainers.md | 10 ++
 libcxx/Maintainers.md | 10 ++
 llvm/Maintainers.md   | 20 +---
 polly/Maintainers.md  | 10 ++
 4 files changed, 35 insertions(+), 15 deletions(-)
 create mode 100644 libclc/Maintainers.md
 create mode 100644 libcxx/Maintainers.md
 create mode 100644 polly/Maintainers.md

diff --git a/libclc/Maintainers.md b/libclc/Maintainers.md
new file mode 100644
index 00..314b139b81aaff
--- /dev/null
+++ b/libclc/Maintainers.md
@@ -0,0 +1,10 @@
+# libclc Maintainers
+
+This file is a list of the
+[maintainers](https://llvm.org/docs/DeveloperPolicy.html#maintainers) for
+libclc.
+
+# Lead maintainer
+
+Tom Stellard \
+tstel...@redhat.com (email), [tstellar](https://github.com/tstellar) (GitHub)
\ No newline at end of file
diff --git a/libcxx/Maintainers.md b/libcxx/Maintainers.md
new file mode 100644
index 00..2630ed9001119b
--- /dev/null
+++ b/libcxx/Maintainers.md
@@ -0,0 +1,10 @@
+# libc++ Maintainers
+
+This file is a list of the
+[maintainers](https://llvm.org/docs/DeveloperPolicy.html#maintainers) for
+libc++.
+
+# Lead maintainer
+
+Louis Dionne \
+ldionn...@gmail.com (email), [ldionne](https://github.com/ldionne) (GitHub)
\ No newline at end of file
diff --git a/llvm/Maintainers.md b/llvm/Maintainers.md
index 63bdfd42528db4..27b69ef98da1f6 100644
--- a/llvm/Maintainers.md
+++ b/llvm/Maintainers.md
@@ -422,7 +422,6 @@ gkistan...@gmail.com (email), 
[gkistanova](https://github.com/gkistanova) (GitHu
 ### Other subprojects
 
 Some subprojects maintain their own list of per-component maintainers.
-Others only have a lead maintainer listed here.
 
 [Bolt 
maintainers](https://github.com/llvm/llvm-project/blob/main/bolt/Maintainers.txt)
 
@@ -434,26 +433,17 @@ Others only have a lead maintainer listed here.
 
 [Flang 
maintainers](https://github.com/llvm/llvm-project/blob/main/flang/Maintainers.txt)
 
+[libc++ 
maintainers](https://github.com/llvm/llvm-project/blob/main/libcxx/Maintainers.md)
+
+[libclc 
maintainers](https://github.com/llvm/llvm-project/blob/main/libclc/Maintainers.md)
+
 [LLD 
maintainers](https://github.com/llvm/llvm-project/blob/main/lld/Maintainers.md)
 
 [LLDB 
maintainers](https://github.com/llvm/llvm-project/blob/main/lldb/Maintainers.rst)
 
 [LLVM OpenMP Library 
maintainers](https://github.com/llvm/llvm-project/blob/main/openmp/Maintainers.md)
 
- libc++
-
-Louis Dionne \
-ldionn...@gmail.com (email), [ldionne](https://github.com/ldionne) (GitHub)
-
- libclc
-
-Tom Stellard \
-tstel...@redhat.com (email), [tstellar](https://github.com/tstellar) (GitHub)
-
- Polly
-
-Tobias Grosser \
-tob...@grosser.es (email), [tobiasgrosser](https://github.com/tobiasgrosser) 
(GitHub)
+[Polly 
maintainers](https://github.com/llvm/llvm-project/blob/main/polly/Maintainers.md)
 
 ## Inactive Maintainers
 
diff --git a/polly/Maintainers.md b/polly/Maintainers.md
new file mode 100644
index 00..6c0ecef0f281a9
--- /dev/null
+++ b/polly/Maintainers.md
@@ -0,0 +1,10 @@
+# Polly Maintainers
+
+This file is a list of the
+[maintainers](https://llvm.org/docs/DeveloperPolicy.html#maintainers) for
+Polly.
+
+# Lead maintainer
+
+Tobias Grosser \
+tob...@grosser.es (email), [tobiasgrosser](https://github.com/tobiasgrosser) 
(GitHub)
\ No newline at end of file

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


[clang] Add support for referencable labels for attribute documentation (PR #118428)

2024-12-04 Thread via cfe-commits

Sirraide wrote:

> is `const StringRef` a style violation

Yeah, we generally don’t use top-level `const` for variables that are value 
types.

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


[clang] [mutation analyzer] support mutation analysis for pointee (PR #118593)

2024-12-04 Thread Congcong Cai via cfe-commits

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


[clang] [flang] [flang][Driver] Support -nostdlib and -nodefaultlibs (PR #108868)

2024-12-04 Thread Mészáros Gergely via cfe-commits


@@ -5572,7 +5572,8 @@ def : Flag<["-"], "nocudalib">, Alias;
 def gpulibc : Flag<["-"], "gpulibc">, Visibility<[ClangOption, CC1Option, 
FlangOption, FC1Option]>,
   HelpText<"Link the LLVM C Library for GPUs">;
 def nogpulibc : Flag<["-"], "nogpulibc">, Visibility<[ClangOption, CC1Option, 
FlangOption, FC1Option]>;
-def nodefaultlibs : Flag<["-"], "nodefaultlibs">;
+def nodefaultlibs : Flag<["-"], "nodefaultlibs">,
+  Visibility<[ClangOption, FlangOption, CLOption, DXCOption]>;

Maetveis wrote:

With this change in Options.td:

```diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index cb96b5daed9d3a2..842e6c2e6233adb 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5644,4 +5644,3 @@ def gpulibc : Flag<["-"], "gpulibc">, 
Visibility<[ClangOption, CC1Option, FlangO
 def nogpulibc : Flag<["-"], "nogpulibc">, Visibility<[ClangOption, CC1Option, 
FlangOption, FC1Option]>;
-def nodefaultlibs : Flag<["-"], "nodefaultlibs">,
-  Visibility<[ClangOption, FlangOption, CLOption, DXCOption]>;
+def nodefaultlibs : Flag<["-"], "nodefaultlibs">;
 def nodriverkitlib : Flag<["-"], "nodriverkitlib">;
 ```
 
I'm getting:
 
```console
> build\bin\clang-cl.exe -nodefaultlibs asd.o
clang-cl: warning: unknown argument ignored in clang-cl: '-nodefaultlibs' 
[-Wunknown-argument]
```

without it I don't get a warning.

The comment at Options.td:74 also seems to suggest the default is only the gcc 
compatible driver. 
https://github.com/llvm/llvm-project/blob/c3536b263f253a69fb336fb0617ee33a01a5c5dd/clang/include/clang/Driver/Options.td#L74-L77

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


[clang] [clang-format] extend clang-format directive with options to prevent formatting for one line (PR #118566)

2024-12-04 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/118566

>From 0badd09a2c77c94446b3ba352e48a54ff8fbc0b7 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 4 Dec 2024 02:24:12 +0200
Subject: [PATCH] [clang-format] extend clang-format directive with options to
 prevent formatting for one line

---
 clang/include/clang/Format/Format.h   | 11 +++-
 clang/lib/Format/DefinitionBlockSeparator.cpp |  3 +-
 clang/lib/Format/Format.cpp   | 57 +--
 clang/lib/Format/FormatTokenLexer.cpp | 39 ++---
 clang/lib/Format/FormatTokenLexer.h   |  8 ++-
 .../Format/IntegerLiteralSeparatorFixer.cpp   |  4 +-
 clang/lib/Format/SortJavaScriptImports.cpp| 10 +++-
 clang/lib/Format/TokenAnnotator.cpp   |  4 +-
 clang/unittests/Format/FormatTest.cpp | 53 +
 9 files changed, 154 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 6383934afa2c40..b25d190178247d 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5620,8 +5620,15 @@ inline StringRef 
getLanguageName(FormatStyle::LanguageKind Language) {
   }
 }
 
-bool isClangFormatOn(StringRef Comment);
-bool isClangFormatOff(StringRef Comment);
+enum class ClangFormatDirective {
+  None,
+  Off,
+  On,
+  OffLine,
+  OffNextLine,
+};
+
+ClangFormatDirective parseClangFormatDirective(StringRef Comment);
 
 } // end namespace format
 } // end namespace clang
diff --git a/clang/lib/Format/DefinitionBlockSeparator.cpp 
b/clang/lib/Format/DefinitionBlockSeparator.cpp
index 319236d3bd618c..709ad5e776cc5a 100644
--- a/clang/lib/Format/DefinitionBlockSeparator.cpp
+++ b/clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -144,7 +144,8 @@ void DefinitionBlockSeparator::separateBlocks(
 return false;
 
   if (const auto *Tok = OperateLine->First;
-  Tok->is(tok::comment) && !isClangFormatOn(Tok->TokenText)) {
+  Tok->is(tok::comment) && parseClangFormatDirective(Tok->TokenText) ==
+   ClangFormatDirective::None) {
 return true;
   }
 
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index dcaac4b0d42cc5..5b7659306696c5 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3267,9 +3267,9 @@ tooling::Replacements sortCppIncludes(const FormatStyle 
&Style, StringRef Code,
 
 bool IsBlockComment = false;
 
-if (isClangFormatOff(Trimmed)) {
+if (parseClangFormatDirective(Trimmed) == ClangFormatDirective::Off) {
   FormattingOff = true;
-} else if (isClangFormatOn(Trimmed)) {
+} else if (parseClangFormatDirective(Trimmed) == ClangFormatDirective::On) 
{
   FormattingOff = false;
 } else if (Trimmed.starts_with("/*")) {
   IsBlockComment = true;
@@ -3452,9 +3452,9 @@ tooling::Replacements sortJavaImports(const FormatStyle 
&Style, StringRef Code,
 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
 
 StringRef Trimmed = Line.trim();
-if (isClangFormatOff(Trimmed))
+if (parseClangFormatDirective(Trimmed) == ClangFormatDirective::Off)
   FormattingOff = true;
-else if (isClangFormatOn(Trimmed))
+else if (parseClangFormatDirective(Trimmed) == ClangFormatDirective::On)
   FormattingOff = false;
 
 if (ImportRegex.match(Line, &Matches)) {
@@ -4190,24 +4190,45 @@ Expected getStyle(StringRef StyleName, 
StringRef FileName,
   return FallbackStyle;
 }
 
-static bool isClangFormatOnOff(StringRef Comment, bool On) {
-  if (Comment == (On ? "/* clang-format on */" : "/* clang-format off */"))
-return true;
+static unsigned skipWhitespace(unsigned Pos, StringRef Str, unsigned Length) {
+  while (Pos < Length && isspace(Str[Pos]))
+++Pos;
+  return Pos;
+}
 
-  static const char ClangFormatOn[] = "// clang-format on";
-  static const char ClangFormatOff[] = "// clang-format off";
-  const unsigned Size = (On ? sizeof ClangFormatOn : sizeof ClangFormatOff) - 
1;
+ClangFormatDirective parseClangFormatDirective(StringRef Comment) {
+  size_t Pos = std::min(Comment.find("/*"), Comment.find("//"));
+  unsigned Length = Comment.size();
+  if (Pos == StringRef::npos)
+return ClangFormatDirective::None;
 
-  return Comment.starts_with(On ? ClangFormatOn : ClangFormatOff) &&
- (Comment.size() == Size || Comment[Size] == ':');
-}
+  Pos = skipWhitespace(Pos + 2, Comment, Length);
+  StringRef ClangFormatDirectiveName = "clang-format";
 
-bool isClangFormatOn(StringRef Comment) {
-  return isClangFormatOnOff(Comment, /*On=*/true);
-}
+  if (Comment.substr(Pos, ClangFormatDirectiveName.size()) ==
+  ClangFormatDirectiveName) {
+Pos =
+skipWhitespace(Pos + ClangFormatDirectiveName.size(), Comment, Length);
+
+unsigned EndDirectiveValuePos = Pos;
+while (EndDirectiveValuePos < Length) {
+  char Char = Comment[EndDirect

[clang] [X86] Do not apply fast-math to the logic intriniscs (PR #118603)

2024-12-04 Thread Phoebe Wang via cfe-commits

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


[clang] [clang][bytecode] Handle bitcasts involving bitfields (PR #116843)

2024-12-04 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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


[clang] [clang][bytecode] Handle bitcasts involving bitfields (PR #116843)

2024-12-04 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/116843

>From 1eafc000e5f788a98ec9e4387057d62e509115f5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 8 Nov 2024 14:37:56 +0100
Subject: [PATCH 1/3] [clang][bytecode] Handle bitcasts involving bitfields

---
 clang/lib/AST/ByteCode/BitcastBuffer.cpp  |  88 
 clang/lib/AST/ByteCode/BitcastBuffer.h|  67 +++
 clang/lib/AST/ByteCode/Boolean.h  |   4 +-
 clang/lib/AST/ByteCode/Integral.h |   1 +
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp | 250 --
 clang/lib/AST/CMakeLists.txt  |   1 +
 .../ByteCode/builtin-bit-cast-bitfields.cpp   | 437 ++
 clang/test/AST/ByteCode/builtin-bit-cast.cpp  | 104 +
 .../unittests/AST/ByteCode/BitcastBuffer.cpp  |  83 
 clang/unittests/AST/ByteCode/CMakeLists.txt   |   1 +
 10 files changed, 790 insertions(+), 246 deletions(-)
 create mode 100644 clang/lib/AST/ByteCode/BitcastBuffer.cpp
 create mode 100644 clang/lib/AST/ByteCode/BitcastBuffer.h
 create mode 100644 clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 create mode 100644 clang/unittests/AST/ByteCode/BitcastBuffer.cpp

diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.cpp 
b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
new file mode 100644
index 00..093f2b2c224093
--- /dev/null
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
@@ -0,0 +1,88 @@
+//=== Bitcastbuffer.cpp -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "BitcastBuffer.h"
+
+using namespace clang;
+using namespace clang::interp;
+
+void BitcastBuffer::pushData(const std::byte *In, size_t BitOffset,
+ size_t BitWidth, Endian TargetEndianness) {
+  for (unsigned It = 0; It != BitWidth; ++It) {
+bool BitValue = bitof(In, It);
+if (!BitValue)
+  continue;
+
+unsigned DstBit;
+if (TargetEndianness == Endian::Little)
+  DstBit = BitOffset + It;
+else
+  DstBit = size() - BitOffset - BitWidth + It;
+
+unsigned DstByte = (DstBit / 8);
+Data[DstByte] |= std::byte{1} << (DstBit % 8);
+  }
+}
+
+std::unique_ptr
+BitcastBuffer::copyBits(unsigned BitOffset, unsigned BitWidth,
+unsigned FullBitWidth, Endian TargetEndianness) const {
+  assert(BitWidth <= FullBitWidth);
+  assert(fullByte(FullBitWidth));
+  auto Out = std::make_unique(FullBitWidth / 8);
+
+  for (unsigned It = 0; It != BitWidth; ++It) {
+unsigned BitIndex;
+if (TargetEndianness == Endian::Little)
+  BitIndex = BitOffset + It;
+else
+  BitIndex = size() - BitWidth - BitOffset + It;
+
+bool BitValue = bitof(Data.get(), BitIndex);
+if (!BitValue)
+  continue;
+unsigned DstBit = It;
+unsigned DstByte = (DstBit / 8);
+Out[DstByte] |= std::byte{1} << (DstBit % 8);
+  }
+
+  return Out;
+}
+
+#if 0
+  template
+  static std::string hex(T t) {
+std::stringstream stream;
+stream << std::hex << (int)t;
+return std::string(stream.str());
+  }
+
+
+  void BitcastBuffer::dump(bool AsHex = true) const {
+llvm::errs() << "LSB\n  ";
+unsigned LineLength = 0;
+for (unsigned I = 0; I != (FinalBitSize / 8); ++I) {
+  std::byte B = Data[I];
+  if (AsHex) {
+std::stringstream stream;
+stream << std::hex << (int)B;
+llvm::errs() << stream.str();
+LineLength += stream.str().size() + 1;
+  } else {
+llvm::errs() << std::bitset<8>((int)B).to_string();
+LineLength += 8 + 1;
+// llvm::errs() << (int)B;
+  }
+  llvm::errs() << ' ';
+}
+llvm::errs() << '\n';
+
+for (unsigned I = 0; I != LineLength; ++I)
+  llvm::errs() << ' ';
+llvm::errs() << "MSB\n";
+  }
+#endif
diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
new file mode 100644
index 00..0cc7d5909c47e4
--- /dev/null
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -0,0 +1,67 @@
+//===- BitcastBuffer.h --*- 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
+//
+//===--===//
+#ifndef LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+#define LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace interp {
+
+enum class Endian { Little, Big };
+
+/// Returns the value of the bit

[clang] 4b5e7fa - [clang][bytecode] Handle bitcasts involving bitfields (#116843)

2024-12-04 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-12-04T11:25:04+01:00
New Revision: 4b5e7fa4de54e00df007ae5e2675393fd046aa59

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

LOG: [clang][bytecode] Handle bitcasts involving bitfields (#116843)

Copy the data one bit at a time, leaving optimizations for future work.
Adds a BitcastBuffer that takes care of pushing the bits in the right
order.

Added: 
clang/lib/AST/ByteCode/BitcastBuffer.cpp
clang/lib/AST/ByteCode/BitcastBuffer.h
clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
clang/unittests/AST/ByteCode/BitcastBuffer.cpp

Modified: 
clang/lib/AST/ByteCode/Boolean.h
clang/lib/AST/ByteCode/Integral.h
clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
clang/lib/AST/CMakeLists.txt
clang/test/AST/ByteCode/builtin-bit-cast.cpp
clang/unittests/AST/ByteCode/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/AST/ByteCode/BitcastBuffer.cpp 
b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
new file mode 100644
index 00..0cc97b0b6bf190
--- /dev/null
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
@@ -0,0 +1,95 @@
+//=== Bitcastbuffer.cpp -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "BitcastBuffer.h"
+
+using namespace clang;
+using namespace clang::interp;
+
+/// Returns the value of the bit in the given sequence of bytes.
+static inline bool bitof(const std::byte *B, Bits BitIndex) {
+  return (B[BitIndex.roundToBytes()] &
+  (std::byte{1} << BitIndex.getOffsetInByte())) != std::byte{0};
+}
+
+void BitcastBuffer::pushData(const std::byte *In, Bits BitOffset, Bits 
BitWidth,
+ Endian TargetEndianness) {
+  for (unsigned It = 0; It != BitWidth.getQuantity(); ++It) {
+bool BitValue = bitof(In, Bits(It));
+if (!BitValue)
+  continue;
+
+Bits DstBit;
+if (TargetEndianness == Endian::Little)
+  DstBit = BitOffset + Bits(It);
+else
+  DstBit = size() - BitOffset - BitWidth + Bits(It);
+
+size_t DstByte = DstBit.roundToBytes();
+Data[DstByte] |= std::byte{1} << DstBit.getOffsetInByte();
+  }
+}
+
+std::unique_ptr
+BitcastBuffer::copyBits(Bits BitOffset, Bits BitWidth, Bits FullBitWidth,
+Endian TargetEndianness) const {
+  assert(BitWidth.getQuantity() <= FullBitWidth.getQuantity());
+  assert(FullBitWidth.isFullByte());
+  auto Out = std::make_unique(FullBitWidth.roundToBytes());
+
+  for (unsigned It = 0; It != BitWidth.getQuantity(); ++It) {
+Bits BitIndex;
+if (TargetEndianness == Endian::Little)
+  BitIndex = BitOffset + Bits(It);
+else
+  BitIndex = size() - BitWidth - BitOffset + Bits(It);
+
+bool BitValue = bitof(Data.get(), BitIndex);
+if (!BitValue)
+  continue;
+
+Bits DstBit = Bits(It);
+size_t DstByte = DstBit.roundToBytes();
+Out[DstByte] |= std::byte{1} << DstBit.getOffsetInByte();
+  }
+
+  return Out;
+}
+
+#if 0
+  template
+  static std::string hex(T t) {
+std::stringstream stream;
+stream << std::hex << (int)t;
+return std::string(stream.str());
+  }
+
+
+  void BitcastBuffer::dump(bool AsHex = true) const {
+llvm::errs() << "LSB\n  ";
+unsigned LineLength = 0;
+for (unsigned I = 0; I != (FinalBitSize / 8); ++I) {
+  std::byte B = Data[I];
+  if (AsHex) {
+std::stringstream stream;
+stream << std::hex << (int)B;
+llvm::errs() << stream.str();
+LineLength += stream.str().size() + 1;
+  } else {
+llvm::errs() << std::bitset<8>((int)B).to_string();
+LineLength += 8 + 1;
+// llvm::errs() << (int)B;
+  }
+  llvm::errs() << ' ';
+}
+llvm::errs() << '\n';
+
+for (unsigned I = 0; I != LineLength; ++I)
+  llvm::errs() << ' ';
+llvm::errs() << "MSB\n";
+  }
+#endif

diff  --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
new file mode 100644
index 00..8442df5c60cf56
--- /dev/null
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -0,0 +1,88 @@
+//===- BitcastBuffer.h --*- 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
+//
+//===--===//
+#ifndef LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+#define LLVM_CLANG_AST_INTERP_B

[clang] [clang][bytecode] Handle bitcasts involving bitfields (PR #116843)

2024-12-04 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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


[clang] [Clang][OpenCL][AMDGPU] Allow a kernel to call another kernel (PR #115821)

2024-12-04 Thread Aniket Lal via cfe-commits


@@ -1085,8 +1085,10 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const 
CGBlockInfo &blockInfo) {
   blockAddr.getPointer(), 
ConvertType(blockInfo.getBlockExpr()->getType()));
 
   if (IsOpenCL) {
-CGM.getOpenCLRuntime().recordBlockInfo(blockInfo.BlockExpression, InvokeFn,
-   result, blockInfo.StructureType);
+CGM.getOpenCLRuntime().recordBlockInfo(
+blockInfo.BlockExpression, InvokeFn, result, blockInfo.StructureType,
+CurGD && CurGD.isDeclOpenCLKernel() &&
+(CurGD.getKernelReferenceKind() == KernelReferenceKind::Kernel));

lalaniket8 wrote:

> a kernel to kernel function call is replaced by a kernel to stub to kernel 
> call 

Calls to kernel (from device and kernel functions) is not supported during 
backend IselLowering : 
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp#L1127
So, we can't have a stub calling a kernel go into the backend.
In-lining the callee kernel body into the stub function might not be helpful in 
cases where callee kernel is just a function declaration.

> kernel is emitted first and then directly cloning the kernel body into the 
> stub

> emit kernels by emitting the stub and then directly cloning the function body 
> into the kernel

Some doubts on these points: Wouldn't this also result in having two copies of 
the kernel body ? Would this avoid the problems we see during double emission ?

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


[clang] [AArch64][Clang] Define __ARM_NEON_SVE_BRIDGE unconditionally (PR #118272)

2024-12-04 Thread Jonathan Thackray via cfe-commits

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

LGTM

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


[clang] [clang] Apply internal buffering to clang diagnostics printing (PR #113440)

2024-12-04 Thread Mariya Podchishchaeva via cfe-commits


@@ -656,15 +656,19 @@ static bool printWordWrapped(raw_ostream &OS, StringRef 
Str, unsigned Columns,
 TextDiagnostic::TextDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
DiagnosticOptions *DiagOpts,
const Preprocessor *PP)
-: DiagnosticRenderer(LangOpts, DiagOpts), OS(OS), PP(PP) {}
+: DiagnosticRenderer(LangOpts, DiagOpts), Out(OS), PP(PP),
+  OS(InternalBuffer) {
+  this->OS.buffer().clear();
+  this->OS.enable_colors(true);

Fznamznon wrote:

Good point. I think we do have tests checking colors. We probably don't have 
the tests that check there is no colors.

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


[clang] [llvm] [AArch64] Implement intrinsics for FP8 FCVT/FCVTN/BFCVT (PR #118025)

2024-12-04 Thread Jonathan Thackray via cfe-commits

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

LGTM

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


[clang] [llvm] [AArch64] Implement intrinsics for SME FP8 F1CVT/F2CVT and BF1CVT/BF2CVT (PR #118027)

2024-12-04 Thread Jonathan Thackray via cfe-commits

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

LGTM

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


[clang-tools-extra] [clang-tidy] Sync ContainerSizeEmptyCheck with container-size-empty doc (PR #118459)

2024-12-04 Thread Niels Dekker via cfe-commits


@@ -18,10 +18,11 @@ namespace clang::tidy::readability {
 /// a call to `empty()`.
 ///
 /// The emptiness of a container should be checked using the `empty()` method
-/// instead of the `size()` method. It shows clearer intent to use `empty()`.
-/// Furthermore some containers may implement the `empty()` method but not
-/// implement the `size()` method. Using `empty()` whenever possible makes it
-/// easier to switch to another container in the future.
+/// instead of the `size()`/`length()` method. It shows clearer intent to use
+/// `empty()`. Furthermore some containers may implement the `empty()` method
+/// but not implement the `size()` or `length()` method. Using `empty()`
+/// whenever possible makes it easier to switch to another container in the
+/// future.

N-Dekker wrote:

Thank you both for your approval, @HerrCai0907 and @carlosgalvezp. I'm 
considering to propose mentioning `std::forward_list` here, as it is _the_ one 
STL container that does not implement `size()`. But maybe first wait for this 
one (#118459) to get merged... 

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


[clang] [Serialization] Downgrade error to warning for inconsistent language flags (PR #117840)

2024-12-04 Thread Boris Kolpackov via cfe-commits

boris-kolpackov wrote:

> Maybe then we could adapt the Fortran/ASM convention where an uppercase 
> extension means "I need preprocessing" and lowercase doesn't. (tongue lightly 
> in cheek…)

>From https://build2.org/build2/doc/build2-build-system-manual.xhtml :

> The `preprocessed` property indicates the degree of preprocessing the module 
> unit requires and is used to optimize module compilation. Valid values are 
> `none` (not preprocessed), `includes` (no #include directives in the source), 
> `modules` (as above plus no module declarations depend on the preprocessor, 
> for example, `#ifdef`, etc.), and `all` (the source is fully preprocessed). 
> Note that for `all` the source may still contain comments and line 
> continuations.

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


[libclc] [libcxx] [llvm] [openmp] [polly] [llvm] Move sub-project lead maintainers into their own Maintainers.md files (PR #118309)

2024-12-04 Thread David Spickett via cfe-commits

DavidSpickett wrote:

OpenMP part pushed directly: 
https://github.com/llvm/llvm-project/commit/2137ded301adb430e0616cd835da9838e4fd79ce

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


[clang] [llvm] [AArch64] Implements FP8 SVE intrinsics for dot-product (PR #118125)

2024-12-04 Thread Jonathan Thackray via cfe-commits

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

LGTM

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


[clang] [llvm] [AArch64] Implement FP8 SVE intrinsics for fused multiply-add (PR #118126)

2024-12-04 Thread Jonathan Thackray via cfe-commits

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

LGTM

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


[clang] [FMV][AArch64][clang] Emit fmv-features metadata in LLVM IR. (PR #118544)

2024-12-04 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

> A motivating example might be target_version("simd+dotprod") and 
> target_version("sve"): when sve is available we should pick that version, but 
> the current rule prioritizes the number of attribute-specified features over 
> their overall weight.

I agree about this. As I said we will adress the priorities and selection 
algorithm separately. However in the example I am mentioning the problem arises 
once we mix target-features from the cmdline with fmv-features. So we need 
separate metadata. I was thinking whether it makes sense to expand the fmv 
dependecies before we store them in metadata but I think it's not necessary. We 
can perform this step later.

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


[clang] [clang][bytecode] Handle bitcasts involving bitfields (PR #116843)

2024-12-04 Thread LLVM Continuous Integration via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-armv8-quick` running 
on `linaro-clang-armv8-quick` while building `clang` at step 5 "ninja check 1".

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


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

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'Clang :: 
AST/ByteCode/builtin-bit-cast-bitfields.cpp' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang 
-cc1 -internal-isystem 
/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/20/include 
-nostdsysteminc -verify=expected,both -std=c++2a -fsyntax-only 
-fexperimental-new-constant-interpreter 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
+ /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang -cc1 
-internal-isystem 
/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/20/include 
-nostdsysteminc -verify=expected,both -std=c++2a -fsyntax-only 
-fexperimental-new-constant-interpreter 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
error: 'both-error' diagnostics seen but not expected: 
  File 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 Line 304: unknown type name '__int128_t'
  File 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 Line 25: static assertion failed due to requirement 'sizeof(bool 
__attribute__((ext_vector_type(128 == sizeof(unsigned long long)'
  File 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 Line 26: size of '__builtin_bit_cast' source type 'const unsigned long long' 
does not match destination type 'bool __attribute__((ext_vector_type(128)))' 
(vector of 128 'bool' values) (8 vs 16 bytes)
  File 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 Line 25: static assertion failed due to requirement 'sizeof(unsigned long 
long) == sizeof(bool __attribute__((ext_vector_type(128'
  File 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 Line 26: size of '__builtin_bit_cast' source type 'bool const 
__attribute__((ext_vector_type(128)))' (vector of 128 'bool' values) does not 
match destination type 'unsigned long long' (16 vs 8 bytes)
  File 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 Line 304: static assertion expression is not an integral constant expression
error: 'both-note' diagnostics seen but not expected: 
  File 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 Line 31: in instantiation of function template specialization 'bit_cast' requested here
  File 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 Line 304: in instantiation of function template specialization 
'check_round_trip' requested here
  File 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 Line 25: expression evaluates to '16 == 8'
  File 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 Line 31: in instantiation of function template specialization 
'bit_cast' 
requested here
  File 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 Line 304: in instantiation of function template specialization 
'check_round_trip' requested here
  File 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
 Line 25: expression evaluates to '8 == 16'
12 errors generated.

--




```



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


[clang] 54db162 - Revert "[clang][bytecode] Handle bitcasts involving bitfields (#116843)"

2024-12-04 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-12-04T11:43:43+01:00
New Revision: 54db16221c92eb52efbea90ad5b5d2a1d00cda3e

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

LOG: Revert "[clang][bytecode] Handle bitcasts involving bitfields (#116843)"

This reverts commit 4b5e7fa4de54e00df007ae5e2675393fd046aa59.

This breaks builders:
https://lab.llvm.org/buildbot/#/builders/154/builds/8464

I guess some more testing on 32 bit hosts is needed.

Added: 


Modified: 
clang/lib/AST/ByteCode/Boolean.h
clang/lib/AST/ByteCode/Integral.h
clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
clang/lib/AST/CMakeLists.txt
clang/test/AST/ByteCode/builtin-bit-cast.cpp
clang/unittests/AST/ByteCode/CMakeLists.txt

Removed: 
clang/lib/AST/ByteCode/BitcastBuffer.cpp
clang/lib/AST/ByteCode/BitcastBuffer.h
clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
clang/unittests/AST/ByteCode/BitcastBuffer.cpp



diff  --git a/clang/lib/AST/ByteCode/BitcastBuffer.cpp 
b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
deleted file mode 100644
index 0cc97b0b6bf190..00
--- a/clang/lib/AST/ByteCode/BitcastBuffer.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-//=== Bitcastbuffer.cpp -*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-#include "BitcastBuffer.h"
-
-using namespace clang;
-using namespace clang::interp;
-
-/// Returns the value of the bit in the given sequence of bytes.
-static inline bool bitof(const std::byte *B, Bits BitIndex) {
-  return (B[BitIndex.roundToBytes()] &
-  (std::byte{1} << BitIndex.getOffsetInByte())) != std::byte{0};
-}
-
-void BitcastBuffer::pushData(const std::byte *In, Bits BitOffset, Bits 
BitWidth,
- Endian TargetEndianness) {
-  for (unsigned It = 0; It != BitWidth.getQuantity(); ++It) {
-bool BitValue = bitof(In, Bits(It));
-if (!BitValue)
-  continue;
-
-Bits DstBit;
-if (TargetEndianness == Endian::Little)
-  DstBit = BitOffset + Bits(It);
-else
-  DstBit = size() - BitOffset - BitWidth + Bits(It);
-
-size_t DstByte = DstBit.roundToBytes();
-Data[DstByte] |= std::byte{1} << DstBit.getOffsetInByte();
-  }
-}
-
-std::unique_ptr
-BitcastBuffer::copyBits(Bits BitOffset, Bits BitWidth, Bits FullBitWidth,
-Endian TargetEndianness) const {
-  assert(BitWidth.getQuantity() <= FullBitWidth.getQuantity());
-  assert(FullBitWidth.isFullByte());
-  auto Out = std::make_unique(FullBitWidth.roundToBytes());
-
-  for (unsigned It = 0; It != BitWidth.getQuantity(); ++It) {
-Bits BitIndex;
-if (TargetEndianness == Endian::Little)
-  BitIndex = BitOffset + Bits(It);
-else
-  BitIndex = size() - BitWidth - BitOffset + Bits(It);
-
-bool BitValue = bitof(Data.get(), BitIndex);
-if (!BitValue)
-  continue;
-
-Bits DstBit = Bits(It);
-size_t DstByte = DstBit.roundToBytes();
-Out[DstByte] |= std::byte{1} << DstBit.getOffsetInByte();
-  }
-
-  return Out;
-}
-
-#if 0
-  template
-  static std::string hex(T t) {
-std::stringstream stream;
-stream << std::hex << (int)t;
-return std::string(stream.str());
-  }
-
-
-  void BitcastBuffer::dump(bool AsHex = true) const {
-llvm::errs() << "LSB\n  ";
-unsigned LineLength = 0;
-for (unsigned I = 0; I != (FinalBitSize / 8); ++I) {
-  std::byte B = Data[I];
-  if (AsHex) {
-std::stringstream stream;
-stream << std::hex << (int)B;
-llvm::errs() << stream.str();
-LineLength += stream.str().size() + 1;
-  } else {
-llvm::errs() << std::bitset<8>((int)B).to_string();
-LineLength += 8 + 1;
-// llvm::errs() << (int)B;
-  }
-  llvm::errs() << ' ';
-}
-llvm::errs() << '\n';
-
-for (unsigned I = 0; I != LineLength; ++I)
-  llvm::errs() << ' ';
-llvm::errs() << "MSB\n";
-  }
-#endif

diff  --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
deleted file mode 100644
index 8442df5c60cf56..00
--- a/clang/lib/AST/ByteCode/BitcastBuffer.h
+++ /dev/null
@@ -1,88 +0,0 @@
-//===- BitcastBuffer.h --*- 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
-//
-//===--===//
-#ifndef LLVM_CLA

[clang] [llvm] [IR] Allow fast math flags on fptrunc and fpext (PR #115894)

2024-12-04 Thread John Brawn via cfe-commits

https://github.com/john-brawn-arm closed 
https://github.com/llvm/llvm-project/pull/115894
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 12ca72b - Reapply "[clang][bytecode] Handle bitcasts involving bitfields (#116843)"

2024-12-04 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-12-04T11:53:37+01:00
New Revision: 12ca72ba7f11fb880794a37cffdea5f47e3062f4

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

LOG: Reapply "[clang][bytecode] Handle bitcasts involving bitfields (#116843)"

This reverts commit 54db16221c92eb52efbea90ad5b5d2a1d00cda3e.

Check for existence of __SIZOEF_INT128__ so we don't run those
tests on targets that don't have int128.

Added: 
clang/lib/AST/ByteCode/BitcastBuffer.cpp
clang/lib/AST/ByteCode/BitcastBuffer.h
clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp
clang/unittests/AST/ByteCode/BitcastBuffer.cpp

Modified: 
clang/lib/AST/ByteCode/Boolean.h
clang/lib/AST/ByteCode/Integral.h
clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
clang/lib/AST/CMakeLists.txt
clang/test/AST/ByteCode/builtin-bit-cast.cpp
clang/unittests/AST/ByteCode/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/AST/ByteCode/BitcastBuffer.cpp 
b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
new file mode 100644
index 00..0cc97b0b6bf190
--- /dev/null
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
@@ -0,0 +1,95 @@
+//=== Bitcastbuffer.cpp -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "BitcastBuffer.h"
+
+using namespace clang;
+using namespace clang::interp;
+
+/// Returns the value of the bit in the given sequence of bytes.
+static inline bool bitof(const std::byte *B, Bits BitIndex) {
+  return (B[BitIndex.roundToBytes()] &
+  (std::byte{1} << BitIndex.getOffsetInByte())) != std::byte{0};
+}
+
+void BitcastBuffer::pushData(const std::byte *In, Bits BitOffset, Bits 
BitWidth,
+ Endian TargetEndianness) {
+  for (unsigned It = 0; It != BitWidth.getQuantity(); ++It) {
+bool BitValue = bitof(In, Bits(It));
+if (!BitValue)
+  continue;
+
+Bits DstBit;
+if (TargetEndianness == Endian::Little)
+  DstBit = BitOffset + Bits(It);
+else
+  DstBit = size() - BitOffset - BitWidth + Bits(It);
+
+size_t DstByte = DstBit.roundToBytes();
+Data[DstByte] |= std::byte{1} << DstBit.getOffsetInByte();
+  }
+}
+
+std::unique_ptr
+BitcastBuffer::copyBits(Bits BitOffset, Bits BitWidth, Bits FullBitWidth,
+Endian TargetEndianness) const {
+  assert(BitWidth.getQuantity() <= FullBitWidth.getQuantity());
+  assert(FullBitWidth.isFullByte());
+  auto Out = std::make_unique(FullBitWidth.roundToBytes());
+
+  for (unsigned It = 0; It != BitWidth.getQuantity(); ++It) {
+Bits BitIndex;
+if (TargetEndianness == Endian::Little)
+  BitIndex = BitOffset + Bits(It);
+else
+  BitIndex = size() - BitWidth - BitOffset + Bits(It);
+
+bool BitValue = bitof(Data.get(), BitIndex);
+if (!BitValue)
+  continue;
+
+Bits DstBit = Bits(It);
+size_t DstByte = DstBit.roundToBytes();
+Out[DstByte] |= std::byte{1} << DstBit.getOffsetInByte();
+  }
+
+  return Out;
+}
+
+#if 0
+  template
+  static std::string hex(T t) {
+std::stringstream stream;
+stream << std::hex << (int)t;
+return std::string(stream.str());
+  }
+
+
+  void BitcastBuffer::dump(bool AsHex = true) const {
+llvm::errs() << "LSB\n  ";
+unsigned LineLength = 0;
+for (unsigned I = 0; I != (FinalBitSize / 8); ++I) {
+  std::byte B = Data[I];
+  if (AsHex) {
+std::stringstream stream;
+stream << std::hex << (int)B;
+llvm::errs() << stream.str();
+LineLength += stream.str().size() + 1;
+  } else {
+llvm::errs() << std::bitset<8>((int)B).to_string();
+LineLength += 8 + 1;
+// llvm::errs() << (int)B;
+  }
+  llvm::errs() << ' ';
+}
+llvm::errs() << '\n';
+
+for (unsigned I = 0; I != LineLength; ++I)
+  llvm::errs() << ' ';
+llvm::errs() << "MSB\n";
+  }
+#endif

diff  --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
new file mode 100644
index 00..8442df5c60cf56
--- /dev/null
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -0,0 +1,88 @@
+//===- BitcastBuffer.h --*- 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
+//
+//===--===//
+#ifndef LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
+#def

[clang] ecbe4d1 - [IR] Allow fast math flags on fptrunc and fpext (#115894)

2024-12-04 Thread via cfe-commits

Author: John Brawn
Date: 2024-12-04T10:53:04Z
New Revision: ecbe4d1e360e25c0634a3a62fbd01e8df5bb0c1b

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

LOG: [IR] Allow fast math flags on fptrunc and fpext (#115894)

This consists of:
 * Make these instructions part of FPMathOperator.
* Adjust bitcode/ir readers/writers to expect fast math flags on these
instructions.
 * Make IRBuilder set the fast math flags on these instructions.
 * Update langref and release notes.
* Update a bunch of tests. Some of these are due to InstCombineCasts
incorrectly adding fast math flags to fptrunc, which will be fixed in a
later patch.

Added: 


Modified: 
clang/test/CodeGen/X86/cx-complex-range.c
clang/test/CodeGen/cx-complex-range.c
clang/test/CodeGen/matrix-type-operators-fast-math.c
clang/test/CodeGen/nofpclass.c
clang/test/CodeGenCUDA/amdgpu-atomic-ops.cu
clang/test/CodeGenHIP/printf_nonhostcall.cpp
clang/test/Headers/__clang_hip_math_ocml_rounded_ops.hip
llvm/docs/LangRef.rst
llvm/docs/ReleaseNotes.md
llvm/include/llvm/IR/IRBuilder.h
llvm/include/llvm/IR/Operator.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/test/Assembler/fast-math-flags.ll
llvm/test/Bitcode/compatibility.ll
llvm/test/Transforms/InstCombine/fpcast.ll

Removed: 




diff  --git a/clang/test/CodeGen/X86/cx-complex-range.c 
b/clang/test/CodeGen/X86/cx-complex-range.c
index a0e6dc219b36f7..f87091427df713 100644
--- a/clang/test/CodeGen/X86/cx-complex-range.c
+++ b/clang/test/CodeGen/X86/cx-complex-range.c
@@ -266,14 +266,14 @@
 // BASIC_FAST-NEXT:[[A_REAL:%.*]] = load half, ptr [[A_REALP]], align 2
 // BASIC_FAST-NEXT:[[A_IMAGP:%.*]] = getelementptr inbounds nuw { half, 
half }, ptr [[A]], i32 0, i32 1
 // BASIC_FAST-NEXT:[[A_IMAG:%.*]] = load half, ptr [[A_IMAGP]], align 2
-// BASIC_FAST-NEXT:[[EXT:%.*]] = fpext half [[A_REAL]] to float
-// BASIC_FAST-NEXT:[[EXT1:%.*]] = fpext half [[A_IMAG]] to float
+// BASIC_FAST-NEXT:[[EXT:%.*]] = fpext reassoc nnan ninf nsz arcp afn half 
[[A_REAL]] to float
+// BASIC_FAST-NEXT:[[EXT1:%.*]] = fpext reassoc nnan ninf nsz arcp afn 
half [[A_IMAG]] to float
 // BASIC_FAST-NEXT:[[B_REALP:%.*]] = getelementptr inbounds nuw { half, 
half }, ptr [[B]], i32 0, i32 0
 // BASIC_FAST-NEXT:[[B_REAL:%.*]] = load half, ptr [[B_REALP]], align 2
 // BASIC_FAST-NEXT:[[B_IMAGP:%.*]] = getelementptr inbounds nuw { half, 
half }, ptr [[B]], i32 0, i32 1
 // BASIC_FAST-NEXT:[[B_IMAG:%.*]] = load half, ptr [[B_IMAGP]], align 2
-// BASIC_FAST-NEXT:[[EXT2:%.*]] = fpext half [[B_REAL]] to float
-// BASIC_FAST-NEXT:[[EXT3:%.*]] = fpext half [[B_IMAG]] to float
+// BASIC_FAST-NEXT:[[EXT2:%.*]] = fpext reassoc nnan ninf nsz arcp afn 
half [[B_REAL]] to float
+// BASIC_FAST-NEXT:[[EXT3:%.*]] = fpext reassoc nnan ninf nsz arcp afn 
half [[B_IMAG]] to float
 // BASIC_FAST-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn 
float [[EXT]], [[EXT2]]
 // BASIC_FAST-NEXT:[[TMP1:%.*]] = fmul reassoc nnan ninf nsz arcp afn 
float [[EXT1]], [[EXT3]]
 // BASIC_FAST-NEXT:[[TMP2:%.*]] = fadd reassoc nnan ninf nsz arcp afn 
float [[TMP0]], [[TMP1]]
@@ -285,8 +285,8 @@
 // BASIC_FAST-NEXT:[[TMP8:%.*]] = fsub reassoc nnan ninf nsz arcp afn 
float [[TMP6]], [[TMP7]]
 // BASIC_FAST-NEXT:[[TMP9:%.*]] = fdiv reassoc nnan ninf nsz arcp afn 
float [[TMP2]], [[TMP5]]
 // BASIC_FAST-NEXT:[[TMP10:%.*]] = fdiv reassoc nnan ninf nsz arcp afn 
float [[TMP8]], [[TMP5]]
-// BASIC_FAST-NEXT:[[UNPROMOTION:%.*]] = fptrunc float [[TMP9]] to half
-// BASIC_FAST-NEXT:[[UNPROMOTION4:%.*]] = fptrunc float [[TMP10]] to half
+// BASIC_FAST-NEXT:[[UNPROMOTION:%.*]] = fptrunc reassoc nnan ninf nsz 
arcp afn float [[TMP9]] to half
+// BASIC_FAST-NEXT:[[UNPROMOTION4:%.*]] = fptrunc reassoc nnan ninf nsz 
arcp afn float [[TMP10]] to half
 // BASIC_FAST-NEXT:[[RETVAL_REALP:%.*]] = getelementptr inbounds nuw { 
half, half }, ptr [[RETVAL]], i32 0, i32 0
 // BASIC_FAST-NEXT:[[RETVAL_IMAGP:%.*]] = getelementptr inbounds nuw { 
half, half }, ptr [[RETVAL]], i32 0, i32 1
 // BASIC_FAST-NEXT:store half [[UNPROMOTION]], ptr [[RETVAL_REALP]], align 
2
@@ -307,22 +307,22 @@
 // FULL_FAST-NEXT:[[A_REAL:%.*]] = load half, ptr [[A_REALP]], align 2
 // FULL_FAST-NEXT:[[A_IMAGP:%.*]] = getelementptr inbounds nuw { half, 
half }, ptr [[A]], i32 0, i32 1
 // FULL_FAST-NEXT:[[A_IMAG:%.*]] = load half, ptr [[A_IMAGP]], align 2
-// FULL_FAST-NEXT:[[EXT:%.*]] = fpext half [[A_REAL]] to float
-// FULL_FAST-NEXT:[[EXT1:%.*]] = fpext half [[A_IMAG]] to float
+// FULL_FAST-NEXT:[[EXT:%.*]] = fpext reassoc nnan ninf nsz arcp afn half 
[[A_REAL]] to floa

[clang] [FMV][AArch64][clang] Emit fmv-features metadata in LLVM IR. (PR #118544)

2024-12-04 Thread Alexandros Lamprineas via cfe-commits

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


[clang] [clang] Apply internal buffering to clang diagnostics printing (PR #113440)

2024-12-04 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> I'm also a bit worried we're updating TextDiagnostic but not SARIFDiagnostic; 
> does emitting to SARIF also have interleaving issues?

It seems it does
https://github.com/user-attachments/assets/2837334a-891f-4e1b-8fd0-2f456745ada0";>

I'll try to see what happens in raw_ostream.

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


[libclc] [libclc] Move several integer functions to CLC library (PR #116786)

2024-12-04 Thread Fraser Cormack via cfe-commits


@@ -0,0 +1,44 @@
+#include 
+#include 
+#include 
+
+_CLC_OVERLOAD _CLC_DEF char __clc_clz(char x) {
+  return __clc_clz((ushort)(uchar)x) - 8;
+}
+
+_CLC_OVERLOAD _CLC_DEF uchar __clc_clz(uchar x) {
+  return __clc_clz((ushort)x) - 8;
+}
+
+_CLC_OVERLOAD _CLC_DEF short __clc_clz(short x) {
+  return x ? __builtin_clzs(x) : 16;
+}
+
+_CLC_OVERLOAD _CLC_DEF ushort __clc_clz(ushort x) {
+  return x ? __builtin_clzs(x) : 16;
+}
+
+_CLC_OVERLOAD _CLC_DEF int __clc_clz(int x) {
+  return x ? __builtin_clz(x) : 32;
+}
+
+_CLC_OVERLOAD _CLC_DEF uint __clc_clz(uint x) {
+  return x ? __builtin_clz(x) : 32;
+}
+
+_CLC_OVERLOAD _CLC_DEF long __clc_clz(long x) {
+  return x ? __builtin_clzl(x) : 64;
+}
+
+_CLC_OVERLOAD _CLC_DEF ulong __clc_clz(ulong x) {
+  return x ? __builtin_clzl(x) : 64;
+}
+
+_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, char, __clc_clz, char)

frasercrmck wrote:

That might be better and less ambiguous as a new `__builtin_elementwise_clz` 
builtin, come to think of it.

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


[clang] [clang] Apply internal buffering to clang diagnostics printing (PR #113440)

2024-12-04 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/113440

>From 10439ffa9e61240402190538f7a1e1665ca215c8 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 23 Oct 2024 02:50:50 -0700
Subject: [PATCH] [clang] Apply internal buffering to clang diagnostics
 printing

To stabilize output of clang when clang is run in multiple build threads
the whole diagnostic message is written first to internal buffer and then
the whole message is put to the output stream which usually points to
stderr to avoid printing to stderr with small chunks and interleaving of
multiple diagnostic messages.
---
 clang/include/clang/Frontend/TextDiagnostic.h | 12 +++-
 clang/lib/Frontend/TextDiagnostic.cpp | 16 +---
 clang/lib/Frontend/TextDiagnosticPrinter.cpp  | 10 +++---
 3 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Frontend/TextDiagnostic.h 
b/clang/include/clang/Frontend/TextDiagnostic.h
index a2fe8ae995423b..e47a111c1dcdc2 100644
--- a/clang/include/clang/Frontend/TextDiagnostic.h
+++ b/clang/include/clang/Frontend/TextDiagnostic.h
@@ -16,6 +16,7 @@
 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 
 #include "clang/Frontend/DiagnosticRenderer.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
@@ -33,8 +34,15 @@ namespace clang {
 /// DiagnosticClient is implemented through this class as is diagnostic
 /// printing coming out of libclang.
 class TextDiagnostic : public DiagnosticRenderer {
-  raw_ostream &OS;
+  raw_ostream &Out;
   const Preprocessor *PP;
+  // To stabilize output of clang when clang is run in multiple build threads
+  // the whole diagnostic message is written first to internal buffer and then
+  // the whole message is put to the output stream Out which usually points to
+  // stderr to avoid printing to stderr with small chunks and interleaving of
+  // multiple diagnostic messages.
+  SmallString<1024> InternalBuffer;
+  llvm::raw_svector_ostream OS;
 
 public:
   TextDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
@@ -104,6 +112,8 @@ class TextDiagnostic : public DiagnosticRenderer {
 
   void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc,
   StringRef ModuleName) override;
+  void endDiagnostic(DiagOrStoredDiag D,
+ DiagnosticsEngine::Level Level) override;
 
 private:
   void emitFilename(StringRef Filename, const SourceManager &SM);
diff --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index 4119ce6048d45d..fddb846745aa83 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -656,7 +656,11 @@ static bool printWordWrapped(raw_ostream &OS, StringRef 
Str, unsigned Columns,
 TextDiagnostic::TextDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
DiagnosticOptions *DiagOpts,
const Preprocessor *PP)
-: DiagnosticRenderer(LangOpts, DiagOpts), OS(OS), PP(PP) {}
+: DiagnosticRenderer(LangOpts, DiagOpts), Out(OS), PP(PP),
+  OS(InternalBuffer) {
+  this->OS.buffer().clear();
+  this->OS.enable_colors(true);
+}
 
 TextDiagnostic::~TextDiagnostic() {}
 
@@ -664,7 +668,7 @@ void TextDiagnostic::emitDiagnosticMessage(
 FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level,
 StringRef Message, ArrayRef Ranges,
 DiagOrStoredDiag D) {
-  uint64_t StartOfLocationInfo = OS.tell();
+  uint64_t StartOfLocationInfo = Out.tell();
 
   // Emit the location of this particular diagnostic.
   if (Loc.isValid())
@@ -677,7 +681,7 @@ void TextDiagnostic::emitDiagnosticMessage(
 printDiagnosticLevel(OS, Level, DiagOpts->ShowColors);
   printDiagnosticMessage(OS,
  /*IsSupplemental*/ Level == DiagnosticsEngine::Note,
- Message, OS.tell() - StartOfLocationInfo,
+ Message, Out.tell() - StartOfLocationInfo,
  DiagOpts->MessageLength, DiagOpts->ShowColors);
 }
 
@@ -1545,3 +1549,9 @@ void 
TextDiagnostic::emitParseableFixits(ArrayRef Hints,
 OS << "\"\n";
   }
 }
+
+void TextDiagnostic::endDiagnostic(DiagOrStoredDiag D,
+   DiagnosticsEngine::Level Level) {
+  Out << OS.str();
+  OS.buffer().clear();
+}
diff --git a/clang/lib/Frontend/TextDiagnosticPrinter.cpp 
b/clang/lib/Frontend/TextDiagnosticPrinter.cpp
index dac5c44fe92566..6e24a19a1ad501 100644
--- a/clang/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/clang/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -133,12 +133,16 @@ void 
TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level,
   // diagnostics in a context that lacks language options, a source manager, or
   // other infrastructure necessary when emitting more rich diagnostics.
   if (!Info.getLocation().isValid()) {
-TextDiagnostic::printDiagnosticLevel(OS,

[clang] [AArch64][Clang] Define __ARM_NEON_SVE_BRIDGE unconditionally (PR #118272)

2024-12-04 Thread Paul Walker via cfe-commits

https://github.com/paulwalker-arm approved this pull request.


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


  1   2   3   4   5   >