[clang] 67cb040 - [clang] Remove dead incremental Parser code (#102450)

2024-08-09 Thread via cfe-commits

Author: Jonas Hahnfeld
Date: 2024-08-09T09:00:23+02:00
New Revision: 67cb04035fe831a3b5df98dabc44b53ba5ff7126

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

LOG: [clang] Remove dead incremental Parser code (#102450)

When incremental processing is enabled, the Parser will never report
tok::eof but tok::annot_repl_input_end. However, that case is already
taken care of in IncrementalParser::ParseOrWrapTopLevelDecl() so this
check was never executing.

Added: 


Modified: 
clang/lib/Parse/Parser.cpp

Removed: 




diff  --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 5ebe71e496a2e8..04c2f1d380bc48 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -629,11 +629,6 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result,
Sema::ModuleImportState &ImportState) {
   DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*this);
 
-  // Skip over the EOF token, flagging end of previous input for incremental
-  // processing
-  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
-ConsumeToken();
-
   Result = nullptr;
   switch (Tok.getKind()) {
   case tok::annot_pragma_unused:



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


[clang] [clang] Remove dead incremental Parser code (PR #102450)

2024-08-09 Thread Jonas Hahnfeld via cfe-commits

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


[clang] [Clang][Interp] Fix display of syntactically-invalid note for member function calls (PR #102170)

2024-08-09 Thread Timm Baeder via cfe-commits

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


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


[clang] [RFC] Add clang atomic control options and pragmas (PR #102569)

2024-08-09 Thread Matt Arsenault via cfe-commits


@@ -1034,6 +1038,169 @@ inline void FPOptions::applyChanges(FPOptionsOverride 
FPO) {
   *this = FPO.applyOverrides(*this);
 }
 
+/// Atomic control options
+class AtomicOptionsOverride;
+class AtomicOptions {
+public:
+  using storage_type = uint16_t;
+
+  static constexpr unsigned StorageBitSize = 8 * sizeof(storage_type);
+
+  static constexpr storage_type FirstShift = 0, FirstWidth = 0;
+#define OPTION(NAME, TYPE, WIDTH, PREVIOUS)
\
+  static constexpr storage_type NAME##Shift =  
\
+  PREVIOUS##Shift + PREVIOUS##Width;   
\
+  static constexpr storage_type NAME##Width = WIDTH;   
\
+  static constexpr storage_type NAME##Mask = ((1 << NAME##Width) - 1)  
\
+ << NAME##Shift;
+#include "clang/Basic/AtomicOptions.def"
+
+  static constexpr storage_type TotalWidth = 0
+#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) +WIDTH
+#include "clang/Basic/AtomicOptions.def"
+  ;
+  static_assert(TotalWidth <= StorageBitSize,
+"Too short type for AtomicOptions");
+
+private:
+  storage_type Value;
+
+  AtomicOptionsOverride getChangesSlow(const AtomicOptions &Base) const;
+
+public:
+  AtomicOptions() : Value(0) {
+setNoRemoteMemory(false);
+setNoFineGrainedMemory(false);
+setIgnoreDenormalMode(false);
+  }
+  explicit AtomicOptions(const LangOptions &LO) {
+Value = 0;
+#if 0

arsenm wrote:

Disabled code 

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


[clang] [RFC] Add clang atomic control options and pragmas (PR #102569)

2024-08-09 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,19 @@
+//===--- AtomicOptions.def - Atomic Options database -*- 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 defines the Atomic language options. Users of this file
+// must define the OPTION macro to make use of this information.
+#ifndef OPTION
+#  error Define the OPTION macro to handle atomic language options
+#endif
+
+// OPTION(name, type, width, previousName)
+OPTION(NoRemoteMemory, bool, 1, First)
+OPTION(NoFineGrainedMemory, bool, 1, NoRemoteMemory)
+OPTION(IgnoreDenormalMode, bool, 1, NoFineGrainedMemory)
+
+#undef OPTION

arsenm wrote:

End of file missing line error 

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


[clang] [RFC] Add clang atomic control options and pragmas (PR #102569)

2024-08-09 Thread Matt Arsenault via cfe-commits


@@ -238,3 +238,55 @@ LLVM_DUMP_METHOD void FPOptionsOverride::dump() {
 #include "clang/Basic/FPOptions.def"
   llvm::errs() << "\n";
 }
+
+AtomicOptions
+AtomicOptions::defaultWithoutTrailingStorage(const LangOptions &LO) {
+  AtomicOptions result(LO);
+  return result;
+}
+
+AtomicOptionsOverride
+AtomicOptions::getChangesSlow(const AtomicOptions &Base) const {
+  AtomicOptions::storage_type OverrideMask = 0;
+#define OPTION(NAME, TYPE, WIDTH, PREVIOUS)
\
+  if (get##NAME() != Base.get##NAME()) 
\
+OverrideMask |= NAME##Mask;
+#include "clang/Basic/AtomicOptions.def"
+  return AtomicOptionsOverride(*this, OverrideMask);
+}
+
+LLVM_DUMP_METHOD void AtomicOptions::dump() {
+#define OPTION(NAME, TYPE, WIDTH, PREVIOUS)
\
+  llvm::errs() << "\n " #NAME " " << get##NAME();
+#include "clang/Basic/AtomicOptions.def"
+  llvm::errs() << "\n";
+}
+
+LLVM_DUMP_METHOD void AtomicOptionsOverride::dump() {
+#define OPTION(NAME, TYPE, WIDTH, PREVIOUS)
\
+  if (has##NAME##Override())   
\
+llvm::errs() << "\n " #NAME " Override is " << get##NAME##Override();
+#include "clang/Basic/AtomicOptions.def"
+  llvm::errs() << "\n";
+}
+
+AtomicOptionsOverride::AtomicOptionsOverride(const LangOptions &LO) {
+  for (const auto &Setting : LO.AtomicOptionsAsWritten) {
+SmallVector KeyValue;
+StringRef(Setting).split(KeyValue, ":");
+// Assuming option string has been checked elsewhere and is valid.
+assert(KeyValue.size() == 2 && "Invalid atomic option format");
+StringRef Key = KeyValue[0];
+StringRef Val = KeyValue[1];
+bool IsEnabled = (Val == "on");
+
+if (Key == "no_fine_grained_memory")
+  setNoFineGrainedMemoryOverride(IsEnabled);
+else if (Key == "no_remote_memory")
+  setNoRemoteMemoryOverride(IsEnabled);
+else if (Key == "ignore_denormal_mode")
+  setIgnoreDenormalModeOverride(IsEnabled);
+else
+  assert(false && "Unknown atomic option key");

arsenm wrote:

llvm_unreachable 

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


[clang] [RFC] Add clang atomic control options and pragmas (PR #102569)

2024-08-09 Thread Matt Arsenault via cfe-commits


@@ -1,50 +1,48 @@
 // RUN: %clang_cc1 -x hip %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx906 -fnative-half-type \
-// RUN:   -fnative-half-arguments-and-returns | FileCheck 
-check-prefixes=CHECK,SAFEIR %s
+// RUN:   -fnative-half-arguments-and-returns | FileCheck 
-check-prefixes=FUN,CHECK,SAFEIR %s
 
 // RUN: %clang_cc1 -x hip %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx906 -fnative-half-type \
-// RUN:   -fnative-half-arguments-and-returns -munsafe-fp-atomics | FileCheck 
-check-prefixes=CHECK,UNSAFEIR %s
+// RUN:   -fnative-half-arguments-and-returns -munsafe-fp-atomics | FileCheck 
-check-prefixes=FUN,CHECK,UNSAFEIR %s
 
 // RUN: %clang_cc1 -x hip %s -O3 -S -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx1100 -fnative-half-type \
-// RUN:   -fnative-half-arguments-and-returns | FileCheck -check-prefix=SAFE %s
+// RUN:   -fnative-half-arguments-and-returns | FileCheck 
-check-prefixes=FUN,SAFE %s
 
 // RUN: %clang_cc1 -x hip %s -O3 -S -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx940 -fnative-half-type \
 // RUN:   -fnative-half-arguments-and-returns -munsafe-fp-atomics \
-// RUN:   | FileCheck -check-prefix=UNSAFE %s
+// RUN:   | FileCheck -check-prefixes=FUN,UNSAFE %s
 
 // REQUIRES: amdgpu-registered-target
 
 #include "Inputs/cuda.h"
 #include 
 
 __global__ void ffp1(float *p) {
-  // CHECK-LABEL: @_Z4ffp1Pf
-  // SAFEIR: atomicrmw fadd ptr {{.*}} monotonic, align 4{{$}}
-  // SAFEIR: atomicrmw fsub ptr {{.*}} monotonic, align 4{{$}}
-  // SAFEIR: atomicrmw fmax ptr {{.*}} monotonic, align 4{{$}}
-  // SAFEIR: atomicrmw fmin ptr {{.*}} monotonic, align 4{{$}}
-  // SAFEIR: atomicrmw fmax ptr {{.*}} syncscope("agent-one-as") monotonic, 
align 4{{$}}
-  // SAFEIR: atomicrmw fmin ptr {{.*}} syncscope("workgroup-one-as") 
monotonic, align 4{{$}}
-
-  // UNSAFEIR: atomicrmw fadd ptr {{.*}} monotonic, align 4, 
!amdgpu.no.fine.grained.memory !{{[0-9]+}}, !amdgpu.ignore.denormal.mode 
!{{[0-9]+$}}
-  // UNSAFEIR: atomicrmw fsub ptr {{.*}} monotonic, align 4, 
!amdgpu.no.fine.grained.memory !{{[0-9]+$}}
-  // UNSAFEIR: atomicrmw fmax ptr {{.*}} monotonic, align 4, 
!amdgpu.no.fine.grained.memory !{{[0-9]+$}}
-  // UNSAFEIR: atomicrmw fmin ptr {{.*}} monotonic, align 4, 
!amdgpu.no.fine.grained.memory !{{[0-9]+$}}
-  // UNSAFEIR: atomicrmw fmax ptr {{.*}} syncscope("agent-one-as") monotonic, 
align 4, !amdgpu.no.fine.grained.memory !{{[0-9]+$}}
-  // UNSAFEIR: atomicrmw fmin ptr {{.*}} syncscope("workgroup-one-as") 
monotonic, align 4, !amdgpu.no.fine.grained.memory !{{[0-9]+$}}
-
-  // SAFE: _Z4ffp1Pf
-  // SAFE: global_atomic_cmpswap
-  // SAFE: global_atomic_cmpswap
-  // SAFE: global_atomic_cmpswap
-  // SAFE: global_atomic_cmpswap
-  // SAFE: global_atomic_cmpswap
+  // FUN-LABEL: @_Z4ffp1Pf
+  // SAFEIR: atomicrmw fadd ptr {{.*}} monotonic, align 4, 
[[DEFMD:!amdgpu.no.fine.grained.memory ![0-9]+, !amdgpu.no.remote.memory 
![0-9]+$]]
+  // SAFEIR: atomicrmw fsub ptr {{.*}} monotonic, align 4, [[DEFMD]]

arsenm wrote:

This is losing the checks for end of line 

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


[clang] [RFC] Add clang atomic control options and pragmas (PR #102569)

2024-08-09 Thread Matt Arsenault via cfe-commits


@@ -2,315 +2,195 @@
 // RUN: %clang_cc1 -fnative-half-arguments-and-returns -triple 
amdgcn-amd-amdhsa-gnu -target-cpu gfx900 -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK,SAFE %s
 // RUN: %clang_cc1 -fnative-half-arguments-and-returns -triple 
amdgcn-amd-amdhsa-gnu -target-cpu gfx900 -emit-llvm -munsafe-fp-atomics -o - %s 
| FileCheck -check-prefixes=CHECK,UNSAFE %s
 
-// SAFE-LABEL: define dso_local float @test_float_post_inc(
-// SAFE-SAME: ) #[[ATTR0:[0-9]+]] {
-// SAFE-NEXT:  [[ENTRY:.*:]]
-// SAFE-NEXT:[[RETVAL:%.*]] = alloca float, align 4, addrspace(5)
-// SAFE-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[RETVAL]] to ptr
-// SAFE-NEXT:[[TMP0:%.*]] = atomicrmw fadd ptr addrspacecast (ptr 
addrspace(1) @test_float_post_inc.n to ptr), float 1.00e+00 seq_cst, align 4
-// SAFE-NEXT:ret float [[TMP0]]
-//
-// UNSAFE-LABEL: define dso_local float @test_float_post_inc(
-// UNSAFE-SAME: ) #[[ATTR0:[0-9]+]] {
-// UNSAFE-NEXT:  [[ENTRY:.*:]]
-// UNSAFE-NEXT:[[RETVAL:%.*]] = alloca float, align 4, addrspace(5)
-// UNSAFE-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[RETVAL]] to ptr
-// UNSAFE-NEXT:[[TMP0:%.*]] = atomicrmw fadd ptr addrspacecast (ptr 
addrspace(1) @test_float_post_inc.n to ptr), float 1.00e+00 seq_cst, align 
4, !amdgpu.no.fine.grained.memory [[META3:![0-9]+]], 
!amdgpu.ignore.denormal.mode [[META3]]
-// UNSAFE-NEXT:ret float [[TMP0]]
+// CHECK-LABEL: define dso_local float @test_float_post_inc(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[RETVAL:%.*]] = alloca float, align 4, addrspace(5)
+// CHECK-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[RETVAL]] to ptr
+// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fadd ptr addrspacecast (ptr 
addrspace(1) @test_float_post_inc.n to ptr), float 1.00e+00 seq_cst, align 4

arsenm wrote:

This lost the effect of -munsafe-fp-atomics

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


[clang] [RFC] Add clang atomic control options and pragmas (PR #102569)

2024-08-09 Thread Matt Arsenault via cfe-commits


@@ -61,30 +59,28 @@ __global__ void ffp1(float *p) {
 }
 
 __global__ void ffp2(double *p) {
-  // CHECK-LABEL: @_Z4ffp2Pd
-  // SAFEIR: atomicrmw fadd ptr {{.*}} monotonic, align 8{{$}}
-  // SAFEIR: atomicrmw fsub ptr {{.*}} monotonic, align 8{{$}}
-  // SAFEIR: atomicrmw fmax ptr {{.*}} monotonic, align 8{{$}}
-  // SAFEIR: atomicrmw fmin ptr {{.*}} monotonic, align 8{{$}}
-  // SAFEIR: atomicrmw fmax ptr {{.*}} syncscope("agent-one-as") monotonic, 
align 8{{$}}
-  // SAFEIR: atomicrmw fmin ptr {{.*}} syncscope("workgroup-one-as") 
monotonic, align 8{{$}}
-
-  // UNSAFEIR: atomicrmw fadd ptr {{.*}} monotonic, align 8, 
!amdgpu.no.fine.grained.memory !{{[0-9]+$}}
-  // UNSAFEIR: atomicrmw fsub ptr {{.*}} monotonic, align 8, 
!amdgpu.no.fine.grained.memory !{{[0-9]+$}}
-  // UNSAFEIR: atomicrmw fmax ptr {{.*}} monotonic, align 8, 
!amdgpu.no.fine.grained.memory !{{[0-9]+$}}
-  // UNSAFEIR: atomicrmw fmin ptr {{.*}} monotonic, align 8, 
!amdgpu.no.fine.grained.memory !{{[0-9]+$}}
-  // UNSAFEIR: atomicrmw fmax ptr {{.*}} syncscope("agent-one-as") monotonic, 
align 8, !amdgpu.no.fine.grained.memory !{{[0-9]+$}}
-  // UNSAFEIR: atomicrmw fmin ptr {{.*}} syncscope("workgroup-one-as") 
monotonic, align 8, !amdgpu.no.fine.grained.memory !{{[0-9]+$}}
-
-  // SAFE-LABEL: @_Z4ffp2Pd
+  // FUN-LABEL: @_Z4ffp2Pd
+  // SAFEIR: atomicrmw fadd ptr {{.*}} monotonic, align 8, [[DEFMD]]

arsenm wrote:

Losing the end of line checks 

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


[clang] [RFC] Add clang atomic control options and pragmas (PR #102569)

2024-08-09 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -ast-dump %s | FileCheck %s
+// RUN: %clang_cc1 -ast-dump -fcuda-is-device %s | FileCheck %s
+// RUN: %clang_cc1 -ast-dump -fcuda-is-device %s \
+// RUN:   
-fatomic=no_fine_grained_memory:off,no_remote_memory:on,ignore_denormal_mode:on 
\
+// RUN:   | FileCheck %s
+
+#include "Inputs/cuda.h"
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_default
+// CHECK: | |-CompoundStmt
+// CHECK-NOT: AtomicNoRemoteMemory
+// CHECK-NOT: AtomicNoFineGrainedMemory
+// CHECK-NOT: AtomicIgnoreDenormalMode
+__device__ __host__ void test_default(float *a) {
+  __scoped_atomic_fetch_add(a, 1, __ATOMIC_RELAXED, __MEMORY_SCOPE_SYSTEM);
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_one
+// CHECK: | |-CompoundStmt {{.*}} AtomicNoRemoteMemory=1
+// CHECK-NOT: AtomicNoFineGrainedMemory

arsenm wrote:

can you use positive checks for this 

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


[clang] [RFC] Add clang atomic control options and pragmas (PR #102569)

2024-08-09 Thread Matt Arsenault via cfe-commits


@@ -5881,6 +5881,32 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 
   RenderFloatingPointOptions(TC, D, OFastEnabled, Args, CmdArgs, JA);
 
+  if (Arg *AtomicArg = Args.getLastArg(options::OPT_fatomic_EQ)) {
+if (!AtomicArg->getNumValues()) {
+  D.Diag(clang::diag::warn_drv_empty_joined_argument)
+  << AtomicArg->getAsString(Args);
+} else {
+  bool Valid = true;
+  std::set Keys;

arsenm wrote:

Don't use std::set 

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


[clang] [RFC] Add clang atomic control options and pragmas (PR #102569)

2024-08-09 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fcuda-is-device %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fcuda-is-device %s \
+// RUN:   
-fatomic=no_fine_grained_memory:off,no_remote_memory:on,ignore_denormal_mode:on
+
+#include "Inputs/cuda.h"
+
+#pragma clang atomic no_remote_memory(off) // expected-error {{'#pragma clang 
atomic' can only appear at the start of a compound statement}}
+
+__device__ __host__ void test_location(float *a) {
+  __scoped_atomic_fetch_add(a, 1, __ATOMIC_RELAXED, __MEMORY_SCOPE_SYSTEM);
+  #pragma clang atomic no_remote_memory(off) // expected-error {{'#pragma 
clang atomic' can only appear at the start of a compound statement}}
+}
+
+__device__ __host__ void test_invalid_option(float *a) {
+  #pragma clang atomic fast(on) // expected-error {{invalid option 'fast'; 
expected 'no_remote_memory', 'no_fine_grained_memory', or 
'ignore_denormal_mode'}}
+  __scoped_atomic_fetch_add(a, 1, __ATOMIC_RELAXED, __MEMORY_SCOPE_SYSTEM);
+}
+
+__device__ __host__ void test_invalid_value(float *a) {
+  #pragma clang atomic no_remote_memory(default)  // expected-error 
{{unexpected argument 'default' to '#pragma clang atomic no_remote_memory'; 
expected 'on' or 'off'}}
+  __scoped_atomic_fetch_add(a, 1, __ATOMIC_RELAXED, __MEMORY_SCOPE_SYSTEM);
+}
+
+__device__ __host__ void test_extra_token(float *a) {
+  #pragma clang atomic no_remote_memory(on) * // expected-warning {{extra 
tokens at end of '#pragma clang atomic' - ignored}}
+  __scoped_atomic_fetch_add(a, 1, __ATOMIC_RELAXED, __MEMORY_SCOPE_SYSTEM);
+}

arsenm wrote:

Test empty and unbalanced parentheses? 

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


[clang] [RFC] Add clang atomic control options and pragmas (PR #102569)

2024-08-09 Thread Matt Arsenault via cfe-commits


@@ -238,3 +238,55 @@ LLVM_DUMP_METHOD void FPOptionsOverride::dump() {
 #include "clang/Basic/FPOptions.def"
   llvm::errs() << "\n";
 }
+
+AtomicOptions
+AtomicOptions::defaultWithoutTrailingStorage(const LangOptions &LO) {
+  AtomicOptions result(LO);
+  return result;
+}
+
+AtomicOptionsOverride
+AtomicOptions::getChangesSlow(const AtomicOptions &Base) const {
+  AtomicOptions::storage_type OverrideMask = 0;
+#define OPTION(NAME, TYPE, WIDTH, PREVIOUS)
\
+  if (get##NAME() != Base.get##NAME()) 
\
+OverrideMask |= NAME##Mask;
+#include "clang/Basic/AtomicOptions.def"
+  return AtomicOptionsOverride(*this, OverrideMask);
+}
+
+LLVM_DUMP_METHOD void AtomicOptions::dump() {
+#define OPTION(NAME, TYPE, WIDTH, PREVIOUS)
\
+  llvm::errs() << "\n " #NAME " " << get##NAME();
+#include "clang/Basic/AtomicOptions.def"
+  llvm::errs() << "\n";
+}
+
+LLVM_DUMP_METHOD void AtomicOptionsOverride::dump() {
+#define OPTION(NAME, TYPE, WIDTH, PREVIOUS)
\
+  if (has##NAME##Override())   
\
+llvm::errs() << "\n " #NAME " Override is " << get##NAME##Override();
+#include "clang/Basic/AtomicOptions.def"
+  llvm::errs() << "\n";
+}
+
+AtomicOptionsOverride::AtomicOptionsOverride(const LangOptions &LO) {
+  for (const auto &Setting : LO.AtomicOptionsAsWritten) {
+SmallVector KeyValue;
+StringRef(Setting).split(KeyValue, ":");
+// Assuming option string has been checked elsewhere and is valid.
+assert(KeyValue.size() == 2 && "Invalid atomic option format");

arsenm wrote:

If you just do the split without the SmallVector, the second name would just 
fail to parse the same way?

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


[clang] [llvm] [RISCV][FMV] Support target_clones (PR #85786)

2024-08-09 Thread Piyou Chen via cfe-commits


@@ -119,6 +119,51 @@ void getFeaturesForCPU(StringRef CPU,
 else
   EnabledFeatures.push_back(F.substr(1));
 }
+
+namespace RISCVExtensionBitmaskTable {
+#define GET_RISCVExtensionBitmaskTable_IMPL
+#include "llvm/TargetParser/RISCVTargetParserDef.inc"
+
+} // namespace RISCVExtensionBitmaskTable
+
+namespace {
+struct LessExtName {
+  bool operator()(const RISCVExtensionBitmaskTable::RISCVExtensionBitmask &LHS,
+  StringRef RHS) {
+return StringRef(LHS.Name) < RHS;
+  }
+  bool
+  operator()(StringRef LHS,
+ const RISCVExtensionBitmaskTable::RISCVExtensionBitmask &RHS) {
+return LHS < StringRef(RHS.Name);
+  }
+};
+} // namespace
+
+static Expected
+getExtensionBitmask(StringRef ExtName) {
+  ArrayRef ExtBitmasks =
+  RISCVExtensionBitmaskTable::ExtensionBitmask;
+  auto *I = llvm::lower_bound(ExtBitmasks, ExtName, LessExtName());
+
+  if (I != ExtBitmasks.end())
+return *I;
+
+  return createStringError("Unsupport extension");
+}
+
+llvm::SmallVector getRequireFeatureBitMask(ArrayRef Exts) 
{
+  llvm::SmallVector BitMasks(RISCV::RISCVFeatureBitSize);
+
+  for (auto Ext : Exts) {
+Expected ExtBitmask =
+getExtensionBitmask(Ext);
+assert(ExtBitmask && "This extension doesn't has bitmask.");

BeMg wrote:

Sema check now also verifies whether the extension has already allocated the 
bit in the bitmask.

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


[clang] [llvm] [RISCV][FMV] Support target_clones (PR #85786)

2024-08-09 Thread Piyou Chen via cfe-commits


@@ -63,9 +63,32 @@ class RISCVABIInfo : public DefaultABIInfo {
CharUnits Field2Off) const;
 
   ABIArgInfo coerceVLSVector(QualType Ty) const;
+
+  using ABIInfo::appendAttributeMangling;
+  void appendAttributeMangling(TargetClonesAttr *Attr, unsigned Index,
+   raw_ostream &Out) const override;
+  void appendAttributeMangling(StringRef AttrStr,
+   raw_ostream &Out) const override;
 };
 } // end anonymous namespace
 
+void RISCVABIInfo::appendAttributeMangling(TargetClonesAttr *Attr,
+   unsigned Index,
+   raw_ostream &Out) const {
+  appendAttributeMangling(Attr->getFeatureStr(Index), Out);
+}
+
+void RISCVABIInfo::appendAttributeMangling(StringRef AttrStr,
+   raw_ostream &Out) const {
+  if (AttrStr == "default") {
+Out << ".default";
+return;
+  }
+
+  Out << '.';

BeMg wrote:

The format will be the function name appended with the sorted feature string, 
joined by an underscore.

 ```
.__...
```

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


[clang] [llvm] [RISCV][FMV] Support target_clones (PR #85786)

2024-08-09 Thread Piyou Chen via cfe-commits


@@ -2854,10 +2854,121 @@ void CodeGenFunction::EmitMultiVersionResolver(
   case llvm::Triple::aarch64:
 EmitAArch64MultiVersionResolver(Resolver, Options);
 return;
+  case llvm::Triple::riscv32:
+  case llvm::Triple::riscv64:
+EmitRISCVMultiVersionResolver(Resolver, Options);
+return;
 
   default:
-assert(false && "Only implemented for x86 and AArch64 targets");
+assert(false && "Only implemented for x86, AArch64 and RISC-V targets");
+  }
+}
+
+void CodeGenFunction::EmitRISCVMultiVersionResolver(
+llvm::Function *Resolver, ArrayRef Options) {
+
+  if (getContext().getTargetInfo().getTriple().getOS() !=
+  llvm::Triple::OSType::Linux) {
+CGM.getDiags().Report(diag::err_os_unsupport_riscv_target_clones);
+return;
+  }
+
+  llvm::BasicBlock *CurBlock = createBasicBlock("resolver_entry", Resolver);
+  Builder.SetInsertPoint(CurBlock);
+  EmitRISCVCpuInit();
+
+  bool SupportsIFunc = getContext().getTargetInfo().supportsIFunc();
+  bool HasDefault = false;
+  unsigned DefaultIndex = 0;
+  // Check the each candidate function.
+  for (unsigned Index = 0; Index < Options.size(); Index++) {
+
+if (Options[Index].Conditions.Features[0].starts_with("default")) {
+  HasDefault = true;
+  DefaultIndex = Index;
+  continue;
+}
+
+Builder.SetInsertPoint(CurBlock);
+
+std::vector TargetAttrFeats =
+getContext()
+.getTargetInfo()
+.parseTargetAttr(Options[Index].Conditions.Features[0])
+.Features;
+
+if (TargetAttrFeats.empty())
+  continue;
+
+// Two conditions need to be checked for the current version:

BeMg wrote:

Drop the length check and reuse the approach using the `__builtin_support_cpus`.

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


[clang] [llvm] [RISCV][FMV] Support target_clones (PR #85786)

2024-08-09 Thread Piyou Chen via cfe-commits


@@ -14266,6 +14277,71 @@ 
CodeGenFunction::EmitAArch64CpuSupports(ArrayRef FeaturesStrs) {
   return Result;
 }
 
+Value *CodeGenFunction::EmitRISCVCpuSupports(ArrayRef FeaturesStrs,
+ unsigned &MaxGroupIDUsed) {
+
+  const unsigned FeatureBitSize = llvm::RISCV::RISCVFeatureBitSize;
+  llvm::ArrayType *ArrayOfInt64Ty =
+  llvm::ArrayType::get(Int64Ty, FeatureBitSize);
+  llvm::Type *StructTy = llvm::StructType::get(Int32Ty, ArrayOfInt64Ty);
+  llvm::Constant *RISCVFeaturesBits =
+  CGM.CreateRuntimeVariable(StructTy, "__riscv_feature_bits");
+  cast(RISCVFeaturesBits)->setDSOLocal(true);
+
+  auto LoadFeatureBit = [&](unsigned Index) {
+// Create GEP then load.
+Value *IndexVal = llvm::ConstantInt::get(Int32Ty, Index);
+llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(1),
+ IndexVal};
+Value *Ptr =
+Builder.CreateInBoundsGEP(StructTy, RISCVFeaturesBits, GEPIndices);
+Value *FeaturesBit =
+Builder.CreateAlignedLoad(Int64Ty, Ptr, CharUnits::fromQuantity(8));
+return FeaturesBit;
+  };
+
+  SmallVector RequireFeatureBits =
+  llvm::RISCV::getRequireFeatureBitMask(FeaturesStrs);
+  Value *Result = Builder.getTrue();
+  for (unsigned i = 0; i < RequireFeatureBits.size(); i++) {
+if (!RequireFeatureBits[i])
+  continue;
+MaxGroupIDUsed = i;
+Value *Mask = Builder.getInt64(RequireFeatureBits[i]);
+Value *Bitset = Builder.CreateAnd(LoadFeatureBit(i), Mask);
+Value *Cmp = Builder.CreateICmpEQ(Bitset, Mask);
+Result = Builder.CreateAnd(Result, Cmp);
+  }
+
+  return Result;
+}
+
+Value *CodeGenFunction::EmitRISCVFeatureBitsLength(unsigned MaxGroupIDUsed) {

BeMg wrote:

Droped

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


[clang] [llvm] [RISCV][FMV] Support target_clones (PR #85786)

2024-08-09 Thread Piyou Chen via cfe-commits


@@ -14266,6 +14277,71 @@ 
CodeGenFunction::EmitAArch64CpuSupports(ArrayRef FeaturesStrs) {
   return Result;
 }
 
+Value *CodeGenFunction::EmitRISCVCpuSupports(ArrayRef FeaturesStrs,
+ unsigned &MaxGroupIDUsed) {
+
+  const unsigned FeatureBitSize = llvm::RISCV::RISCVFeatureBitSize;
+  llvm::ArrayType *ArrayOfInt64Ty =
+  llvm::ArrayType::get(Int64Ty, FeatureBitSize);
+  llvm::Type *StructTy = llvm::StructType::get(Int32Ty, ArrayOfInt64Ty);
+  llvm::Constant *RISCVFeaturesBits =
+  CGM.CreateRuntimeVariable(StructTy, "__riscv_feature_bits");
+  cast(RISCVFeaturesBits)->setDSOLocal(true);
+
+  auto LoadFeatureBit = [&](unsigned Index) {
+// Create GEP then load.
+Value *IndexVal = llvm::ConstantInt::get(Int32Ty, Index);
+llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(1),
+ IndexVal};
+Value *Ptr =
+Builder.CreateInBoundsGEP(StructTy, RISCVFeaturesBits, GEPIndices);
+Value *FeaturesBit =
+Builder.CreateAlignedLoad(Int64Ty, Ptr, CharUnits::fromQuantity(8));
+return FeaturesBit;
+  };
+
+  SmallVector RequireFeatureBits =

BeMg wrote:

Now it query the bitpos for only one extension each time.

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


[clang] [llvm] [RISCV][FMV] Support target_clones (PR #85786)

2024-08-09 Thread Piyou Chen via cfe-commits


@@ -14266,6 +14277,71 @@ 
CodeGenFunction::EmitAArch64CpuSupports(ArrayRef FeaturesStrs) {
   return Result;
 }
 
+Value *CodeGenFunction::EmitRISCVCpuSupports(ArrayRef FeaturesStrs,
+ unsigned &MaxGroupIDUsed) {
+
+  const unsigned FeatureBitSize = llvm::RISCV::RISCVFeatureBitSize;

BeMg wrote:

> This block of repeating code should be factored out as a static helper.

It is standalone help function now.


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


[clang] [llvm] [IR] Add method to GlobalVariable to change type of initializer. (PR #102553)

2024-08-09 Thread Nikita Popov via cfe-commits

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

LGTM

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


[clang] [clang] Support -Wa, options -mmsa and -mno-msa (PR #99615)

2024-08-09 Thread via cfe-commits

https://github.com/yingopq updated 
https://github.com/llvm/llvm-project/pull/99615

>From c25fb0f2e869a958405fd97f95e363bb603ce5ef Mon Sep 17 00:00:00 2001
From: Ying Huang 
Date: Fri, 19 Jul 2024 04:19:09 -0400
Subject: [PATCH] [clang] Support -Wa, options -mmsa and -mno-msa

---
 clang/include/clang/Basic/CodeGenOptions.def |  1 +
 clang/include/clang/Driver/Options.td|  4 ++-
 clang/lib/Driver/ToolChains/Clang.cpp| 17 
 clang/test/Driver/mips-msa.c | 27 
 4 files changed, 48 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Driver/mips-msa.c

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index f671b780bcbeb1..898fbcd8e47fde 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -178,6 +178,7 @@ CODEGENOPT(MergeAllConstants , 1, 1) ///< Merge identical 
constants.
 CODEGENOPT(MergeFunctions, 1, 0) ///< Set when -fmerge-functions is 
enabled.
 CODEGENOPT(NoCommon  , 1, 0) ///< Set when -fno-common or C++ is 
enabled.
 CODEGENOPT(NoExecStack   , 1, 0) ///< Set when -Wa,--noexecstack is 
enabled.
+CODEGENOPT(MipsMsa   , 1, 0) ///< Set when -Wa,-mmsa is enabled.
 CODEGENOPT(FatalWarnings , 1, 0) ///< Set when -Wa,--fatal-warnings is
  ///< enabled.
 CODEGENOPT(NoWarn, 1, 0) ///< Set when -Wa,--no-warn is enabled.
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 12b20fe04675bf..c96338264dc82e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5337,7 +5337,9 @@ def mmadd4 : Flag<["-"], "mmadd4">, 
Group,
 def mno_madd4 : Flag<["-"], "mno-madd4">, Group,
   HelpText<"Disable the generation of 4-operand madd.s, madd.d and related 
instructions.">;
 def mmsa : Flag<["-"], "mmsa">, Group,
-  HelpText<"Enable MSA ASE (MIPS only)">;
+  Visibility<[ClangOption, CC1Option, CC1AsOption]>,
+  HelpText<"Enable MSA ASE (MIPS only)">,
+  MarshallingInfoFlag>;
 def mno_msa : Flag<["-"], "mno-msa">, Group,
   HelpText<"Disable MSA ASE (MIPS only)">;
 def mmt : Flag<["-"], "mmt">, Group,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 1fd6fba2100426..ebefd83c471edf 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2507,6 +2507,8 @@ static void CollectArgsForIntegratedAssembler(Compilation 
&C,
   bool Crel = false, ExperimentalCrel = false;
   bool UseRelaxRelocations = C.getDefaultToolChain().useRelaxRelocations();
   bool UseNoExecStack = false;
+  bool Msa = false;
+  bool NoMsa = false;
   const char *MipsTargetFeature = nullptr;
   StringRef ImplicitIt;
   for (const Arg *A :
@@ -2630,6 +2632,10 @@ static void 
CollectArgsForIntegratedAssembler(Compilation &C,
 CmdArgs.push_back("-massembler-no-warn");
   } else if (Value == "--noexecstack") {
 UseNoExecStack = true;
+  } else if (Value == "-mmsa") {
+Msa = true;
+  } else if (Value == "-mno-msa") {
+NoMsa = true;
   } else if (Value.starts_with("-compress-debug-sections") ||
  Value.starts_with("--compress-debug-sections") ||
  Value == "-nocompress-debug-sections" ||
@@ -2716,6 +2722,17 @@ static void 
CollectArgsForIntegratedAssembler(Compilation &C,
   << "-Wa,--crel" << D.getTargetTriple();
 }
   }
+  if (Msa) {
+if (Triple.isMIPS())
+  CmdArgs.push_back("-mmsa");
+else {
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << "-Wa,-mmsa" << D.getTargetTriple();
+}
+  }
+  if (NoMsa && !Triple.isMIPS())
+D.Diag(diag::err_drv_unsupported_opt_for_target)
+<< "-Wa,-mno-msa" << D.getTargetTriple();
   if (!UseRelaxRelocations)
 CmdArgs.push_back("-mrelax-relocations=no");
   if (UseNoExecStack)
diff --git a/clang/test/Driver/mips-msa.c b/clang/test/Driver/mips-msa.c
new file mode 100644
index 00..4b4e27c7af99da
--- /dev/null
+++ b/clang/test/Driver/mips-msa.c
@@ -0,0 +1,27 @@
+// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
+// RUN: -Wa,-mmsa %s -Werror 2>&1 | FileCheck %s --check-prefix=CHECK-MMSA
+// CHECK-MMSA: "-cc1" {{.*}}"-mmsa"
+
+// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
+// RUN: -Wa,-mno-msa,-mmsa %s -Werror 2>&1 | FileCheck %s 
--check-prefix=CHECK-MMSA
+
+// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
+// RUN: -Wa,-mmsa,-mno-msa %s -Werror 2>&1 | FileCheck %s 
--check-prefix=CHECK-NOMMSA
+// CHECK-NOMMSA: "-cc1"
+
+// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
+// RUN:-fno-integrated-as -Wa,-mmsa %s -Werror 2>&1 | FileCheck %s 
--check-prefix=MIPS-MSA
+// MIPS-MSA: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64" "-EL" "-KPIC" 
"-mmsa"
+
+// RUN: %clang -### -c 

[clang] [clang][analyzer] Remove array bounds check from PointerSubChecker (PR #102580)

2024-08-09 Thread Balázs Kéri via cfe-commits

https://github.com/balazske created 
https://github.com/llvm/llvm-project/pull/102580

At pointer subtraction only pointers are allowed that point into an array (or 
one after the end), this fact was checker by the checker. This check is now 
removed because it is a special case of array indexing error that is handled by 
a different checker (ArrayBoundsV2). At least theoretically the array bounds 
checker (when finalized) should find the same cases that were detected by the 
PointerSubChecker.

From 08367f06167d8b12ee4de06a37915decd1e754e5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Fri, 9 Aug 2024 09:31:55 +0200
Subject: [PATCH] [clang][analyzer] Remove array bounds check from
 PointerSubChecker

At pointer subtraction only pointers are allowed that point into
an array (or one after the end), this fact was checker by the checker.
This check is now removed because it is a special case of array
indexing error that is handled by a different checker (ArrayBoundsV2).
At least theoretically the array bounds checker (when finalized)
should find the same cases that were detected by the PointerSubChecker.
---
 clang/docs/analyzer/checkers.rst  | 17 ++--
 .../Checkers/PointerSubChecker.cpp| 93 +--
 clang/test/Analysis/pointer-sub.c |  9 --
 3 files changed, 12 insertions(+), 107 deletions(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index 55832d20bd27a1..df3a013ce269c7 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2501,7 +2501,14 @@ alpha.core.PointerSub (C)
 Check for pointer subtractions on two pointers pointing to different memory
 chunks. According to the C standard §6.5.6 only subtraction of pointers that
 point into (or one past the end) the same array object is valid (for this
-purpose non-array variables are like arrays of size 1).
+purpose non-array variables are like arrays of size 1). This checker only
+searches for different memory objects at subtraction, but does not check if the
+array index is correct (
+:ref:`alpha.security.ArrayBoundsV2 ` checks the
+index to some extent).
+
+Furthermore, only cases are reported where stack-allocated objects are involved
+(no warnings on pointers to memory allocated by `malloc`).
 
 .. code-block:: c
 
@@ -2511,11 +2518,6 @@ purpose non-array variables are like arrays of size 1).
x = &d[4] - &c[1]; // warn: 'c' and 'd' are different arrays
x = (&a + 1) - &a;
x = &b - &a; // warn: 'a' and 'b' are different variables
-   x = (&a + 2) - &a; // warn: for a variable it is only valid to have a 
pointer
-  // to one past the address of it
-   x = &c[10] - &c[0];
-   x = &c[11] - &c[0]; // warn: index larger than one past the end
-   x = &c[-1] - &c[0]; // warn: negative index
  }
 
  struct S {
@@ -2538,9 +2540,6 @@ offsets of members in a structure, using pointer 
subtractions. This is still
 undefined behavior according to the standard and code like this can be replaced
 with the `offsetof` macro.
 
-The checker only reports cases where stack-allocated objects are involved (no
-warnings on pointers to memory allocated by `malloc`).
-
 .. _alpha-core-StackAddressAsyncEscape:
 
 alpha.core.StackAddressAsyncEscape (C)
diff --git a/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
index b856b0edc61514..f0dc5efd75f7d6 100644
--- a/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
@@ -31,99 +31,12 @@ class PointerSubChecker
   const llvm::StringLiteral Msg_MemRegionDifferent =
   "Subtraction of two pointers that do not point into the same array "
   "is undefined behavior.";
-  const llvm::StringLiteral Msg_LargeArrayIndex =
-  "Using an array index greater than the array size at pointer subtraction 
"
-  "is undefined behavior.";
-  const llvm::StringLiteral Msg_NegativeArrayIndex =
-  "Using a negative array index at pointer subtraction "
-  "is undefined behavior.";
-  const llvm::StringLiteral Msg_BadVarIndex =
-  "Indexing the address of a variable with other than 1 at this place "
-  "is undefined behavior.";
-
-  /// Check that an array is indexed in the allowed range that is 0 to "one
-  /// after the end". The "array" can be address of a non-array variable.
-  /// @param E Expression of the pointer subtraction.
-  /// @param ElemReg An indexed region in the subtraction expression.
-  /// @param Reg Region of the other side of the expression.
-  bool checkArrayBounds(CheckerContext &C, const Expr *E,
-const ElementRegion *ElemReg,
-const MemRegion *Reg) const;
 
 public:
   void checkPreStmt(const BinaryOperator *B, CheckerContext &C) const;
 };
 }
 
-static bool isArrayVar(const MemRegion *R) {
-  while (R) {
-if (isa(R))
-  return true;
-if (const a

[clang] [RISCV][RFC] BareMetal multilibs YAML usage (PR #75191)

2024-08-09 Thread Emil J via cfe-commits

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


[clang] [RISCV][RFC] BareMetal multilibs YAML usage (PR #75191)

2024-08-09 Thread Emil J via cfe-commits

widlarizer wrote:

Closing this as superseded by #75191 since I've no longer been involved in 
related changes

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


[clang] [clang][analyzer] Remove array bounds check from PointerSubChecker (PR #102580)

2024-08-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Balázs Kéri (balazske)


Changes

At pointer subtraction only pointers are allowed that point into an array (or 
one after the end), this fact was checker by the checker. This check is now 
removed because it is a special case of array indexing error that is handled by 
a different checker (ArrayBoundsV2). At least theoretically the array bounds 
checker (when finalized) should find the same cases that were detected by the 
PointerSubChecker.

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


3 Files Affected:

- (modified) clang/docs/analyzer/checkers.rst (+8-9) 
- (modified) clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp (+4-89) 
- (modified) clang/test/Analysis/pointer-sub.c (-9) 


``diff
diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index 55832d20bd27a..df3a013ce269c 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2501,7 +2501,14 @@ alpha.core.PointerSub (C)
 Check for pointer subtractions on two pointers pointing to different memory
 chunks. According to the C standard §6.5.6 only subtraction of pointers that
 point into (or one past the end) the same array object is valid (for this
-purpose non-array variables are like arrays of size 1).
+purpose non-array variables are like arrays of size 1). This checker only
+searches for different memory objects at subtraction, but does not check if the
+array index is correct (
+:ref:`alpha.security.ArrayBoundsV2 ` checks the
+index to some extent).
+
+Furthermore, only cases are reported where stack-allocated objects are involved
+(no warnings on pointers to memory allocated by `malloc`).
 
 .. code-block:: c
 
@@ -2511,11 +2518,6 @@ purpose non-array variables are like arrays of size 1).
x = &d[4] - &c[1]; // warn: 'c' and 'd' are different arrays
x = (&a + 1) - &a;
x = &b - &a; // warn: 'a' and 'b' are different variables
-   x = (&a + 2) - &a; // warn: for a variable it is only valid to have a 
pointer
-  // to one past the address of it
-   x = &c[10] - &c[0];
-   x = &c[11] - &c[0]; // warn: index larger than one past the end
-   x = &c[-1] - &c[0]; // warn: negative index
  }
 
  struct S {
@@ -2538,9 +2540,6 @@ offsets of members in a structure, using pointer 
subtractions. This is still
 undefined behavior according to the standard and code like this can be replaced
 with the `offsetof` macro.
 
-The checker only reports cases where stack-allocated objects are involved (no
-warnings on pointers to memory allocated by `malloc`).
-
 .. _alpha-core-StackAddressAsyncEscape:
 
 alpha.core.StackAddressAsyncEscape (C)
diff --git a/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
index b856b0edc6151..f0dc5efd75f7d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
@@ -31,99 +31,12 @@ class PointerSubChecker
   const llvm::StringLiteral Msg_MemRegionDifferent =
   "Subtraction of two pointers that do not point into the same array "
   "is undefined behavior.";
-  const llvm::StringLiteral Msg_LargeArrayIndex =
-  "Using an array index greater than the array size at pointer subtraction 
"
-  "is undefined behavior.";
-  const llvm::StringLiteral Msg_NegativeArrayIndex =
-  "Using a negative array index at pointer subtraction "
-  "is undefined behavior.";
-  const llvm::StringLiteral Msg_BadVarIndex =
-  "Indexing the address of a variable with other than 1 at this place "
-  "is undefined behavior.";
-
-  /// Check that an array is indexed in the allowed range that is 0 to "one
-  /// after the end". The "array" can be address of a non-array variable.
-  /// @param E Expression of the pointer subtraction.
-  /// @param ElemReg An indexed region in the subtraction expression.
-  /// @param Reg Region of the other side of the expression.
-  bool checkArrayBounds(CheckerContext &C, const Expr *E,
-const ElementRegion *ElemReg,
-const MemRegion *Reg) const;
 
 public:
   void checkPreStmt(const BinaryOperator *B, CheckerContext &C) const;
 };
 }
 
-static bool isArrayVar(const MemRegion *R) {
-  while (R) {
-if (isa(R))
-  return true;
-if (const auto *ER = dyn_cast(R))
-  R = ER->getSuperRegion();
-else
-  return false;
-  }
-  return false;
-}
-
-bool PointerSubChecker::checkArrayBounds(CheckerContext &C, const Expr *E,
- const ElementRegion *ElemReg,
- const MemRegion *Reg) const {
-  if (!ElemReg)
-return true;
-
-  const MemRegion *SuperReg = ElemReg->getSuperRegion();
-  if (!isArrayVar(SuperReg))
-return true;
-
-  auto ReportBug = [&](const llvm::StringLiteral &Msg) {
-if (ExplodedNode *N = C.generateNonFa

[clang] [clang] Support -Wa, options -mmsa and -mno-msa (PR #99615)

2024-08-09 Thread via cfe-commits


@@ -0,0 +1,28 @@
+// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
+// RUN: -Wa,-mmsa %s -Werror 2>&1 | FileCheck %s --check-prefix=CHECK-MMSA
+// CHECK-MMSA: "-cc1" {{.*}}"-mmsa"
+//
+//
+// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
+// RUN: -Wa,-mno-msa,-mmsa %s -Werror 2>&1 | FileCheck %s 
--check-prefix=CHECK-MMSA
+//
+//
+// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
+// RUN: -Wa,-mmsa,-mno-msa %s -Werror 2>&1 | FileCheck %s 
--check-prefix=CHECK-NOMMSA
+// CHECK-NOMMSA: "-cc1"
+//
+//
+// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
+// RUN:-fno-integrated-as -Wa,-mmsa %s -Werror 2>&1 | FileCheck %s 
--check-prefix=MIPS-MSA
+// MIPS-MSA: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64" "-EL" "-KPIC" 
"-mmsa"
+//
+//
+// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
+// RUN:-fno-integrated-as -Wa,-mno-msa %s -Werror 2>&1 | FileCheck %s 
--check-prefix=MIPS-NOMSA
+// MIPS-NOMSA: as{{(.exe)?}}"

yingopq wrote:

OK, I have added it.

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


[clang] [clang] Support -Wa, options -mmsa and -mno-msa (PR #99615)

2024-08-09 Thread via cfe-commits


@@ -0,0 +1,28 @@
+// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
+// RUN: -Wa,-mmsa %s -Werror 2>&1 | FileCheck %s --check-prefix=CHECK-MMSA
+// CHECK-MMSA: "-cc1" {{.*}}"-mmsa"
+//

yingopq wrote:

OK, dropped them.

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


[clang] [clang][analyzer] Add more notes to PointerSubChecker (PR #102432)

2024-08-09 Thread Balázs Kéri via cfe-commits

balazske wrote:

I uploaded now #102580 that removes the entire array bounds checking.

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


[clang] [clang] Support -Wa, options -mmsa and -mno-msa (PR #99615)

2024-08-09 Thread via cfe-commits


@@ -2507,6 +2507,7 @@ static void CollectArgsForIntegratedAssembler(Compilation 
&C,
   bool Crel = false, ExperimentalCrel = false;
   bool UseRelaxRelocations = C.getDefaultToolChain().useRelaxRelocations();
   bool UseNoExecStack = false;
+  bool Msa = false;

yingopq wrote:

I added bool NoMsa and lead to "unsupported" error when it is on non-mips, were 
I understanding correctly?

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


[clang] [clang][ASTMatcher] Add `matchesString` for `StringLiteral` which matches literals on given `RegExp` (PR #102152)

2024-08-09 Thread via cfe-commits

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


[clang] [Clang] Support non-reference structured bindings with braced array as initializer (PR #102581)

2024-08-09 Thread Yanzuo Liu via cfe-commits

https://github.com/zwuis created 
https://github.com/llvm/llvm-project/pull/102581

When initializing non-reference structured bindings from braced array, array 
copy will be performed, which is a special case not following 
list-initialization.

This PR adds support for this case.

Fixes #31813.

>From 9d5d8d99db6f7fa0b6973fe55582de9d34740b19 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu 
Date: Fri, 9 Aug 2024 15:45:40 +0800
Subject: [PATCH] Support non-reference structured bindings with braced array
 as initializer

---
 clang/docs/ReleaseNotes.rst|  2 +
 clang/include/clang/Sema/Initialization.h  |  4 ++
 clang/lib/Sema/SemaInit.cpp| 82 +-
 clang/test/SemaCXX/cxx1z-decomposition.cpp | 31 +++-
 4 files changed, 99 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7beef7be0e6a53..4e725ce4770e99 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -211,6 +211,8 @@ Bug Fixes to C++ Support
 - Clang now preserves the unexpanded flag in a lambda transform used for pack 
expansion. (#GH56852), (#GH85667),
   (#GH99877).
 - Fixed a bug when diagnosing ambiguous explicit specializations of 
constrained member functions.
+- Clang now correctly handle non-reference structured bindings with braced
+  array as initializer. (#GH31813)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Initialization.h 
b/clang/include/clang/Sema/Initialization.h
index 4b876db436b48c..dfe3d5ff0a252c 100644
--- a/clang/include/clang/Sema/Initialization.h
+++ b/clang/include/clang/Sema/Initialization.h
@@ -1384,6 +1384,10 @@ class InitializationSequence {
 
   void AddParenthesizedListInitStep(QualType T);
 
+  /// Only used when initializing non-reference structured bindings from braced
+  /// array. Unwrap the initializer list to get the array for array copy.
+  void AddUnwrapInitListAtFirst(InitListExpr *Syntactic);
+
   /// Add steps to unwrap a initializer list for a reference around a
   /// single element and rewrap it at the end.
   void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 2666e60c0dd67c..5884955838006e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4091,6 +4091,15 @@ void 
InitializationSequence::AddParenthesizedListInitStep(QualType T) {
   Steps.push_back(S);
 }
 
+void InitializationSequence::AddUnwrapInitListAtFirst(InitListExpr *Syntactic) 
{
+  assert(Syntactic->getNumInits() == 1 &&
+ "Can only unwrap trivial init lists.");
+  Step S;
+  S.Kind = SK_UnwrapInitList;
+  S.Type = Syntactic->getInit(0)->getType();
+  Steps.insert(Steps.begin(), S);
+}
+
 void InitializationSequence::RewrapReferenceInitList(QualType T,
  InitListExpr *Syntactic) {
   assert(Syntactic->getNumInits() == 1 &&
@@ -4167,6 +4176,33 @@ static void MaybeProduceObjCObject(Sema &S,
   }
 }
 
+/// Initialize an array from another array
+static void TryArrayCopy(Sema &S, const InitializationKind &Kind,
+ const InitializedEntity &Entity, Expr *Initializer,
+ QualType DestType, InitializationSequence &Sequence,
+ bool TreatUnavailableAsInvalid) {
+  // If source is a prvalue, use it directly.
+  if (Initializer->isPRValue()) {
+Sequence.AddArrayInitStep(DestType, /*IsGNUExtension*/ false);
+return;
+  }
+
+  // Emit element-at-a-time copy loop.
+  InitializedEntity Element =
+  InitializedEntity::InitializeElement(S.Context, 0, Entity);
+  QualType InitEltT =
+  S.Context.getAsArrayType(Initializer->getType())->getElementType();
+  OpaqueValueExpr OVE(Initializer->getExprLoc(), InitEltT,
+  Initializer->getValueKind(),
+  Initializer->getObjectKind());
+  Expr *OVEAsExpr = &OVE;
+  Sequence.InitializeFrom(S, Element, Kind, OVEAsExpr,
+  /*TopLevelOfInitList*/ false,
+  TreatUnavailableAsInvalid);
+  if (Sequence)
+Sequence.AddArrayInitLoopStep(Entity.getType(), InitEltT);
+}
+
 static void TryListInitialization(Sema &S,
   const InitializedEntity &Entity,
   const InitializationKind &Kind,
@@ -4775,6 +4811,31 @@ static void TryListInitialization(Sema &S,
 }
 if (const ArrayType *DestAT = S.Context.getAsArrayType(DestType)) {
   Expr *SubInit[1] = {InitList->getInit(0)};
+
+  // C++17 [dcl.struct.bind]p1:
+  // ... If the assignment-expression in the initializer has array type A
+  // and no ref-qualifier is present, e has type cv A and each element is
+  // copy-initialized or direct-initialized from the corresponding element
+  // of the assignment-expression as specified by the form of the
+  // initializer.
+  

[clang] [Clang] Support non-reference structured bindings with braced array as initializer (PR #102581)

2024-08-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Yanzuo Liu (zwuis)


Changes

When initializing non-reference structured bindings from braced array, array 
copy will be performed, which is a special case not following 
list-initialization.

This PR adds support for this case.

Fixes #31813.

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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Sema/Initialization.h (+4) 
- (modified) clang/lib/Sema/SemaInit.cpp (+63-19) 
- (modified) clang/test/SemaCXX/cxx1z-decomposition.cpp (+30-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7beef7be0e6a53..4e725ce4770e99 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -211,6 +211,8 @@ Bug Fixes to C++ Support
 - Clang now preserves the unexpanded flag in a lambda transform used for pack 
expansion. (#GH56852), (#GH85667),
   (#GH99877).
 - Fixed a bug when diagnosing ambiguous explicit specializations of 
constrained member functions.
+- Clang now correctly handle non-reference structured bindings with braced
+  array as initializer. (#GH31813)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Initialization.h 
b/clang/include/clang/Sema/Initialization.h
index 4b876db436b48c..dfe3d5ff0a252c 100644
--- a/clang/include/clang/Sema/Initialization.h
+++ b/clang/include/clang/Sema/Initialization.h
@@ -1384,6 +1384,10 @@ class InitializationSequence {
 
   void AddParenthesizedListInitStep(QualType T);
 
+  /// Only used when initializing non-reference structured bindings from braced
+  /// array. Unwrap the initializer list to get the array for array copy.
+  void AddUnwrapInitListAtFirst(InitListExpr *Syntactic);
+
   /// Add steps to unwrap a initializer list for a reference around a
   /// single element and rewrap it at the end.
   void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 2666e60c0dd67c..5884955838006e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4091,6 +4091,15 @@ void 
InitializationSequence::AddParenthesizedListInitStep(QualType T) {
   Steps.push_back(S);
 }
 
+void InitializationSequence::AddUnwrapInitListAtFirst(InitListExpr *Syntactic) 
{
+  assert(Syntactic->getNumInits() == 1 &&
+ "Can only unwrap trivial init lists.");
+  Step S;
+  S.Kind = SK_UnwrapInitList;
+  S.Type = Syntactic->getInit(0)->getType();
+  Steps.insert(Steps.begin(), S);
+}
+
 void InitializationSequence::RewrapReferenceInitList(QualType T,
  InitListExpr *Syntactic) {
   assert(Syntactic->getNumInits() == 1 &&
@@ -4167,6 +4176,33 @@ static void MaybeProduceObjCObject(Sema &S,
   }
 }
 
+/// Initialize an array from another array
+static void TryArrayCopy(Sema &S, const InitializationKind &Kind,
+ const InitializedEntity &Entity, Expr *Initializer,
+ QualType DestType, InitializationSequence &Sequence,
+ bool TreatUnavailableAsInvalid) {
+  // If source is a prvalue, use it directly.
+  if (Initializer->isPRValue()) {
+Sequence.AddArrayInitStep(DestType, /*IsGNUExtension*/ false);
+return;
+  }
+
+  // Emit element-at-a-time copy loop.
+  InitializedEntity Element =
+  InitializedEntity::InitializeElement(S.Context, 0, Entity);
+  QualType InitEltT =
+  S.Context.getAsArrayType(Initializer->getType())->getElementType();
+  OpaqueValueExpr OVE(Initializer->getExprLoc(), InitEltT,
+  Initializer->getValueKind(),
+  Initializer->getObjectKind());
+  Expr *OVEAsExpr = &OVE;
+  Sequence.InitializeFrom(S, Element, Kind, OVEAsExpr,
+  /*TopLevelOfInitList*/ false,
+  TreatUnavailableAsInvalid);
+  if (Sequence)
+Sequence.AddArrayInitLoopStep(Entity.getType(), InitEltT);
+}
+
 static void TryListInitialization(Sema &S,
   const InitializedEntity &Entity,
   const InitializationKind &Kind,
@@ -4775,6 +4811,31 @@ static void TryListInitialization(Sema &S,
 }
 if (const ArrayType *DestAT = S.Context.getAsArrayType(DestType)) {
   Expr *SubInit[1] = {InitList->getInit(0)};
+
+  // C++17 [dcl.struct.bind]p1:
+  // ... If the assignment-expression in the initializer has array type A
+  // and no ref-qualifier is present, e has type cv A and each element is
+  // copy-initialized or direct-initialized from the corresponding element
+  // of the assignment-expression as specified by the form of the
+  // initializer.
+  //
+  // This is a special case not following list-initialization.
+  if (isa(DestAT) &&
+  Entity.getKind() == InitializedEntity::EK_Variable &&
+  is

[clang] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-09 Thread via cfe-commits


@@ -76,7 +76,7 @@ let ArchGuard = "defined(__aarch64__) || 
defined(__arm64ec__)", TargetGuard = "f
   def SCALAR_FCVTPUH  : SInst<"vcvtp_u16", "(1U)1", "Sh">;
   def SCALAR_FCVTPUH1 : SInst<"vcvtp_u32", "(1U>)1", "Sh">;
   def SCALAR_FCVTPUH2 : SInst<"vcvtp_u64", "(1U>>)1", "Sh">;
-  let isVCVT_N = 1 in {
+  let isVCVT_N = 1, ImmChecks = [ImmCheck<1, ImmCheck1_16>] in {

SpencerAbson wrote:

Thank you!

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


[clang] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-09 Thread via cfe-commits


@@ -401,27 +405,45 @@ def VQRSHL : SInst<"vqrshl", "..S", 
"csilUcUsUiUlQcQsQiQlQUcQUsQUiQUl">;
 

 // E.3.12 Shifts by constant
 let isShift = 1 in {
-def VSHR_N : SInst<"vshr_n", "..I", "csilUcUsUiUlQcQsQiQlQUcQUsQUiQUl">;
-def VSHL_N : IInst<"vshl_n", "..I", "csilUcUsUiUlQcQsQiQlQUcQUsQUiQUl">;
-def VRSHR_N: SInst<"vrshr_n", "..I", "csilUcUsUiUlQcQsQiQlQUcQUsQUiQUl">;
-def VSRA_N : SInst<"vsra_n", "...I", "csilUcUsUiUlQcQsQiQlQUcQUsQUiQUl">;
-def VRSRA_N: SInst<"vrsra_n", "...I", "csilUcUsUiUlQcQsQiQlQUcQUsQUiQUl">;
-def VQSHL_N: SInst<"vqshl_n", "..I", "csilUcUsUiUlQcQsQiQlQUcQUsQUiQUl">;
-def VQSHLU_N   : SInst<"vqshlu_n", "U.I", "csilQcQsQiQl">;
-def VSHRN_N: IInst<"vshrn_n", ";
-def VQSHRUN_N  : SInst<"vqshrun_n", "(;
-def VQRSHRUN_N : SInst<"vqrshrun_n", "(;
-def VQSHRN_N   : SInst<"vqshrn_n", ";
-def VRSHRN_N   : IInst<"vrshrn_n", ";
-def VQRSHRN_N  : SInst<"vqrshrn_n", ";
-def VSHLL_N: SInst<"vshll_n", "(>Q).I", "csiUcUsUi">;
+
+
+def VSHR_N : SInst<"vshr_n", "..I", "csilUcUsUiUlQcQsQiQlQUcQUsQUiQUl", 
+  [ImmCheck<1, ImmCheckShiftRight>]>;
+def VSHL_N : IInst<"vshl_n", "..I", "csilUcUsUiUlQcQsQiQlQUcQUsQUiQUl", 
+  [ImmCheck<1, ImmCheckShiftLeft>]>;
+def VRSHR_N: SInst<"vrshr_n", "..I", "csilUcUsUiUlQcQsQiQlQUcQUsQUiQUl", 
+  [ImmCheck<1, ImmCheckShiftRight>]>;
+def VSRA_N : SInst<"vsra_n", "...I", "csilUcUsUiUlQcQsQiQlQUcQUsQUiQUl", 
+  [ImmCheck<2, ImmCheckShiftRight>]>;
+def VRSRA_N: SInst<"vrsra_n", "...I", "csilUcUsUiUlQcQsQiQlQUcQUsQUiQUl", 
+  [ImmCheck<2, ImmCheckShiftRight>]>;
+def VQSHL_N: SInst<"vqshl_n", "..I", "csilUcUsUiUlQcQsQiQlQUcQUsQUiQUl", 
+  [ImmCheck<1, ImmCheckShiftLeft>]>;
+def VQSHLU_N   : SInst<"vqshlu_n", "U.I", "csilQcQsQiQl", 
+  [ImmCheck<1, ImmCheckShiftLeft>]>;
+def VSHRN_N: IInst<"vshrn_n", "]>;
+def VQSHRUN_N  : SInst<"vqshrun_n", "(]>;
+def VQRSHRUN_N : SInst<"vqrshrun_n", "(]>;
+def VQSHRN_N   : SInst<"vqshrn_n", "]>;
+def VRSHRN_N   : IInst<"vrshrn_n", "]>;
+def VQRSHRN_N  : SInst<"vqrshrn_n", "https://github.com/llvm/llvm-project/pull/100278
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-09 Thread via cfe-commits


@@ -447,19 +470,23 @@ def VST1_X3   : WInst<"vst1_x3", "v*(3!)",
 def VST1_X4   : WInst<"vst1_x4", "v*(4!)",
   "cfilsUcUiUlUsQcQfQiQlQsQUcQUiQUlQUsPcPsQPcQPs">;
 def VST1_LANE : WInst<"vst1_lane", "v*(.!)I",
-  "QUcQUsQUiQUlQcQsQiQlQfQPcQPsUcUsUiUlcsilfPcPs">;
+  "QUcQUsQUiQUlQcQsQiQlQfQPcQPsUcUsUiUlcsilfPcPs", 
+  [ImmCheck<2, ImmCheckLaneIndex, 1>]>;
+
 let ArchGuard = "(__ARM_FP & 2)" in {
 def VLD1_F16  : WInst<"vld1", ".(c*!)", "hQh">;
 def VLD1_X2_F16   : WInst<"vld1_x2", "2(c*!)", "hQh">;
 def VLD1_X3_F16   : WInst<"vld1_x3", "3(c*!)", "hQh">;
 def VLD1_X4_F16   : WInst<"vld1_x4", "4(c*!)", "hQh">;
-def VLD1_LANE_F16 : WInst<"vld1_lane", ".(c*!).I", "hQh">;
+def VLD1_LANE_F16 : WInst<"vld1_lane", ".(c*!).I", "hQh", 
+  [ImmCheck<2, ImmCheck0_3, 1>]>;

SpencerAbson wrote:

Thank you!

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


[clang] [clang][analyzer] Remove array bounds check from PointerSubChecker (PR #102580)

2024-08-09 Thread Donát Nagy via cfe-commits

https://github.com/NagyDonat commented:

In the PR/commit message you write that

> At least theoretically the array bounds checker (when finalized) should find 
> the same cases that were detected by the PointerSubChecker.

but I'm pretty sure that the array bound checker already does find all these 
cases (and much more complex cases as well). (The only remaining reason why 
ArrayBoundV2 is in alpha is that it emits too many false positives, because 
engine issues like the inaccurate modeling of loops feed it with incorrect 
information.)

Instead of deleting the array bound testcases, you could also enable 
ArrayBoundV2 in the pointer-sub test files and validate that it does find those 
reports.

Also note that the array bounds checker is named `ArrayBoundV2` with no "s" in 
the name.

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


[clang] [clang][analyzer] Remove array bounds check from PointerSubChecker (PR #102580)

2024-08-09 Thread Donát Nagy via cfe-commits

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


[clang] [clang][analyzer] Remove array bounds check from PointerSubChecker (PR #102580)

2024-08-09 Thread Donát Nagy via cfe-commits


@@ -2501,7 +2501,14 @@ alpha.core.PointerSub (C)
 Check for pointer subtractions on two pointers pointing to different memory
 chunks. According to the C standard §6.5.6 only subtraction of pointers that
 point into (or one past the end) the same array object is valid (for this
-purpose non-array variables are like arrays of size 1).
+purpose non-array variables are like arrays of size 1). This checker only
+searches for different memory objects at subtraction, but does not check if the
+array index is correct (
+:ref:`alpha.security.ArrayBoundsV2 ` checks the
+index to some extent).

NagyDonat wrote:

```suggestion
reports subtraction between different memory objects and does not check whether
the index (or more generally, memory offset) is within bounds. Bounds checking
is done by :ref:`alpha.security.ArrayBoundV2 `.
```

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


[clang] [clang][analyzer] Remove array bounds check from PointerSubChecker (PR #102580)

2024-08-09 Thread Donát Nagy via cfe-commits

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


[clang] [clang][analyzer] Remove array bounds check from PointerSubChecker (PR #102580)

2024-08-09 Thread Donát Nagy via cfe-commits

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


[clang] [clang][analyzer] Add more notes to PointerSubChecker (PR #102432)

2024-08-09 Thread Donát Nagy via cfe-commits

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

Thanks!

We should close this when that other PR is accepted and merged. Until then I'm 
putting a "Request changes" mark on this to prevent an accidental merge.

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


[clang] 310a9f3 - [clang][DebugInfo] Don't mark structured bindings as artificial (#100355)

2024-08-09 Thread via cfe-commits

Author: Michael Buch
Date: 2024-08-09T09:41:09+01:00
New Revision: 310a9f3f257f1f7a41958b792b27e69a0237218f

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

LOG: [clang][DebugInfo] Don't mark structured bindings as artificial (#100355)

This patch is motivated by the debug-info issue in
https://github.com/llvm/llvm-project/issues/48909. Clang is currently
emitting the `DW_AT_artificial` attribute on debug-info entries for
structured bindings whereas GCC does not. GCC's interpretation of the
DWARF spec is more user-friendly in this regard, so we would like to do
the same in Clang. [`CGDebugInfo` uses `isImplicit` to decide which
variables to mark
artificial](https://github.com/llvm/llvm-project/blob/0c4023ae3b64c54ff51947e9776aee0e963c5635/clang/lib/CodeGen/CGDebugInfo.cpp#L4783-L4784)
(e.g., `ImplicitParamDecls`, compiler-generated variables, etc.). But
for the purposes of debug-info, when we say "artificial", what we really
mean in many cases is: "not explicitly spelled out in source".
`VarDecl`s that back tuple-like bindings are [technically
compiler-generated](https://github.com/llvm/llvm-project/issues/48909#issuecomment-2238976579),
but that is a confusing notion for debug-info, since these bindings
*are* spelled out in source. The [documentation for
`isImplicit`](https://github.com/llvm/llvm-project/blob/68a0d0c76223736351fd7c452bca3ba9d80ca342/clang/include/clang/AST/DeclBase.h#L596-L600)
does to some extent imply that implicit variables aren't written in
source.

This patch adds another condition to deciding whether a `VarDecl` should
be marked artificial. Specifically, don't treat structured bindings as
artificial.

**Main alternatives considered**
1. Don't use `isImplicit` in `CGDebugInfo` when determining whether to
add `DW_AT_artificial`. Instead use some other property of the AST that
would tell us whether a node was explicitly spelled out in source or not
* Considered using `SourceRange` or `SourceLocation` to tell us this,
but didn't find a good way to, e.g., correctly identify that the
implicit `this` parameter wasn't spelled out in source (as opposed to an
unnamed parameter in a function declaration)
2. We could've also added a bit to `VarDeclBitFields` that indicates
that a `VarDecl` is a holding var, but the use-case didn't feel like
good enough justification for this
3. Don't set the `VarDecl` introduced as part of a tuple-like
decomposition as implicit.
* This may affect AST matching/traversal and this specific use-case
wasn't enough to justify such a change

Fixes https://github.com/llvm/llvm-project/issues/48909

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-structured-binding.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 8d57c87e97e393..7ad3088f0ab756 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -21,6 +21,7 @@
 #include "TargetInfo.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclFriend.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
@@ -79,6 +80,35 @@ static uint32_t getDeclAlignIfRequired(const Decl *D, const 
ASTContext &Ctx) {
   return D->hasAttr() ? D->getMaxAlignment() : 0;
 }
 
+/// Returns true if \ref VD is a a holding variable (aka a
+/// VarDecl retrieved using \ref BindingDecl::getHoldingVar).
+static bool IsDecomposedVarDecl(VarDecl const *VD) {
+  auto const *Init = VD->getInit();
+  if (!Init)
+return false;
+
+  auto const *RefExpr =
+  llvm::dyn_cast_or_null(Init->IgnoreUnlessSpelledInSource());
+  if (!RefExpr)
+return false;
+
+  return llvm::dyn_cast_or_null(RefExpr->getDecl());
+}
+
+/// Returns true if \ref VD is a compiler-generated variable
+/// and should be treated as artificial for the purposes
+/// of debug-info generation.
+static bool IsArtificial(VarDecl const *VD) {
+  // Tuple-like bindings are marked as implicit despite
+  // being spelled out in source. Don't treat them as artificial
+  // variables.
+  if (IsDecomposedVarDecl(VD))
+return false;
+
+  return VD->isImplicit() || (isa(VD->getDeclContext()) &&
+  cast(VD->getDeclContext())->isImplicit());
+}
+
 CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
   DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
@@ -4766,11 +4796,10 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const 
VarDecl *VD,
   if (VD->hasAttr())
 return nullptr;
 
-  bool Unwritten =
-  VD->isImplicit() || (isa(VD->getDeclContext()) &&
-   cast(VD->getDeclContext())->isImplicit());
+  const bool Va

[clang] [clang][DebugInfo] Don't mark structured bindings as artificial (PR #100355)

2024-08-09 Thread Michael Buch via cfe-commits

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


[clang] [llvm] [LV] Mask off possibly aliasing vector lanes (PR #100579)

2024-08-09 Thread Sam Tebbs via cfe-commits


@@ -9838,16 +9902,33 @@ bool LoopVectorizePass::processLoop(Loop *L) {
   ElementCount UserVF = Hints.getWidth();
   unsigned UserIC = Hints.getInterleave();
 
+  bool AddBranchWeights =
+  hasBranchWeightMD(*L->getLoopLatch()->getTerminator());
+  GeneratedRTChecks Checks(*PSE.getSE(), DT, LI, TTI, F->getDataLayout(),
+   AddBranchWeights);
+
+  // VPlan needs the aliasing pointers as Values and not SCEVs, so expand them

SamTebbs33 wrote:

Done.

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


[clang] [Clang][Concepts] Fix a constraint comparison regression for out-of-line ClassTemplateDecls (PR #102587)

2024-08-09 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/102587

Since 98191d7c, we have been comparing constraints on out-of-line class 
template declarations by recovering surrounding template arguments from the 
DeclContext if neither the new declaration nor its template arguments are 
available.

However, there is a problem in that the out-of-line class template is 
introduced from its lexical context rather than the semantic context.

This results in a discrepancy: out-of-line constraint expressions are not 
substituted while their corresponding inline expressions are transformed, hence 
the bogus error.

This patch fixes that by introspecting these template arguments from the 
semantic context, regardless of it being a friend declaration - we have handled 
friends in `getTemplateInstantiationArgs()`.

Fixes #102320

>From 62218a472c88764472ffba69ceca1825686fe1b9 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 9 Aug 2024 16:32:30 +0800
Subject: [PATCH] [Clang][Concepts] Fix a constraint comparison regression for
 out-of-line ClassTemplateDecls

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Sema/SemaConcept.cpp| 11 ++
 .../SemaTemplate/concepts-out-of-line-def.cpp | 21 +++
 3 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0f1a4c1851911d..cb92ba25d1633f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -186,6 +186,8 @@ Bug Fixes to C++ Support
   substitutions in concepts, so it doesn't incorrectly complain of missing
   module imports in those situations. (#GH60336)
 - Fix init-capture packs having a size of one before being instantiated. 
(#GH63677)
+- Clang now properly compares constraints on an out of line class template
+  declaration definition. (#GH102320)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index d4c9d044985e34..2871f78868aea7 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -948,7 +948,7 @@ static const Expr 
*SubstituteConstraintExpressionWithoutSatisfaction(
 Sema &S, const Sema::TemplateCompareNewDeclInfo &DeclInfo,
 const Expr *ConstrExpr) {
   MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs(
-  DeclInfo.getDecl(), DeclInfo.getLexicalDeclContext(), /*Final=*/false,
+  DeclInfo.getDecl(), DeclInfo.getDeclContext(), /*Final=*/false,
   /*Innermost=*/std::nullopt,
   /*RelativeToPrimary=*/true,
   /*Pattern=*/nullptr, /*ForConstraintInstantiation=*/true,
@@ -971,9 +971,12 @@ static const Expr 
*SubstituteConstraintExpressionWithoutSatisfaction(
   // this may happen while we're comparing two templates' constraint
   // equivalence.
   LocalInstantiationScope ScopeForParameters(S);
-  if (auto *FD = DeclInfo.getDecl()->getAsFunction())
-for (auto *PVD : FD->parameters())
-  ScopeForParameters.InstantiatedLocal(PVD, PVD);
+  if (const NamedDecl *D = DeclInfo.getDecl()) {
+const FunctionDecl *FD = D->getAsFunction();
+if (FD)
+  for (auto *PVD : FD->parameters())
+ScopeForParameters.InstantiatedLocal(PVD, PVD);
+  }
 
   std::optional ThisScope;
 
diff --git a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp 
b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
index 0142efcdc3ee86..5ea1ff79e572bc 100644
--- a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -599,3 +599,24 @@ template 
 unsigned long DerivedCollection::index() {}
 
 } // namespace GH72557
+
+namespace GH102320 {
+
+template 
+concept Constrained = true;
+
+template  class C {
+  template > class D;
+  template 
+requires Constrained
+  class E;
+};
+
+template  template > class C::D {};
+
+template 
+template 
+  requires Constrained
+class C::E {};
+
+} // namespace GH102320

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


[clang] [Clang][Concepts] Fix a constraint comparison regression for out-of-line ClassTemplateDecls (PR #102587)

2024-08-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

Since 98191d7c, we have been comparing constraints on out-of-line class 
template declarations by recovering surrounding template arguments from the 
DeclContext if neither the new declaration nor its template arguments are 
available.

However, there is a problem in that the out-of-line class template is 
introduced from its lexical context rather than the semantic context.

This results in a discrepancy: out-of-line constraint expressions are not 
substituted while their corresponding inline expressions are transformed, hence 
the bogus error.

This patch fixes that by introspecting these template arguments from the 
semantic context, regardless of it being a friend declaration - we have handled 
friends in `getTemplateInstantiationArgs()`.

Fixes #102320

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Sema/SemaConcept.cpp (+7-4) 
- (modified) clang/test/SemaTemplate/concepts-out-of-line-def.cpp (+21) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0f1a4c1851911d..cb92ba25d1633f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -186,6 +186,8 @@ Bug Fixes to C++ Support
   substitutions in concepts, so it doesn't incorrectly complain of missing
   module imports in those situations. (#GH60336)
 - Fix init-capture packs having a size of one before being instantiated. 
(#GH63677)
+- Clang now properly compares constraints on an out of line class template
+  declaration definition. (#GH102320)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index d4c9d044985e34..2871f78868aea7 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -948,7 +948,7 @@ static const Expr 
*SubstituteConstraintExpressionWithoutSatisfaction(
 Sema &S, const Sema::TemplateCompareNewDeclInfo &DeclInfo,
 const Expr *ConstrExpr) {
   MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs(
-  DeclInfo.getDecl(), DeclInfo.getLexicalDeclContext(), /*Final=*/false,
+  DeclInfo.getDecl(), DeclInfo.getDeclContext(), /*Final=*/false,
   /*Innermost=*/std::nullopt,
   /*RelativeToPrimary=*/true,
   /*Pattern=*/nullptr, /*ForConstraintInstantiation=*/true,
@@ -971,9 +971,12 @@ static const Expr 
*SubstituteConstraintExpressionWithoutSatisfaction(
   // this may happen while we're comparing two templates' constraint
   // equivalence.
   LocalInstantiationScope ScopeForParameters(S);
-  if (auto *FD = DeclInfo.getDecl()->getAsFunction())
-for (auto *PVD : FD->parameters())
-  ScopeForParameters.InstantiatedLocal(PVD, PVD);
+  if (const NamedDecl *D = DeclInfo.getDecl()) {
+const FunctionDecl *FD = D->getAsFunction();
+if (FD)
+  for (auto *PVD : FD->parameters())
+ScopeForParameters.InstantiatedLocal(PVD, PVD);
+  }
 
   std::optional ThisScope;
 
diff --git a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp 
b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
index 0142efcdc3ee86..5ea1ff79e572bc 100644
--- a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -599,3 +599,24 @@ template 
 unsigned long DerivedCollection::index() {}
 
 } // namespace GH72557
+
+namespace GH102320 {
+
+template 
+concept Constrained = true;
+
+template  class C {
+  template > class D;
+  template 
+requires Constrained
+  class E;
+};
+
+template  template > class C::D {};
+
+template 
+template 
+  requires Constrained
+class C::E {};
+
+} // namespace GH102320

``




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


[clang] [Clang][Concepts] Fix a constraint comparison regression for out-of-line ClassTemplateDecls (PR #102587)

2024-08-09 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

Note that @jcsxky has a similar patch 
https://github.com/llvm/llvm-project/pull/102554 that fixes the same thing. I 
don't intend to contend against him, and admittedly, that patch works.

But I don't think that approach is so reasonable because it is hacky in that 
`ForConstraintInstantiation` is disabled in the presence of 
`ClassTemplateDecl`s, which seemingly does a superfluous job that 
`getTemplateInstantiationArgs()` should do and blurs the meaning of the flag.

That would also leave us a concern about whether we should change all the other 
lines where `ForConstraintInstantiation` was true to the same pattern in 
`SubstituteConstraintExpressionWithoutSatisfaction`.

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


[clang] [Clang][Concepts] Fix a constraint comparison regression for out-of-line ClassTemplateDecls (PR #102587)

2024-08-09 Thread Younan Zhang via cfe-commits

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


[clang] [DebugInfo][RemoveDIs] Use iterator-inserters in clang (PR #102006)

2024-08-09 Thread Jeremy Morse via cfe-commits

jmorse wrote:

(I can't replicate the buildkite windows failure locally, will commit and see 
what actually goes wrong)

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


[clang] 92aec51 - [DebugInfo][RemoveDIs] Use iterator-inserters in clang (#102006)

2024-08-09 Thread via cfe-commits

Author: Jeremy Morse
Date: 2024-08-09T10:17:48+01:00
New Revision: 92aec5192ce752c984837a93227200b54faa8679

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

LOG: [DebugInfo][RemoveDIs] Use iterator-inserters in clang (#102006)

As part of the LLVM effort to eliminate debug-info intrinsics, we're
moving to a world where only iterators should be used to insert
instructions. This isn't a problem in clang when instructions get
generated before any debug-info is inserted, however we're planning on
deprecating and removing the instruction-pointer insertion routines.

Scatter some calls to getIterator in a few places, remove a
deref-then-addrof on another iterator, and add an overload for the
createLoadInstBefore utility. Some callers passes a null insertion
point, which we need to handle explicitly now.

Added: 


Modified: 
clang/lib/CodeGen/CGCUDANV.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGCleanup.cpp
clang/lib/CodeGen/CGCoroutine.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGObjC.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 43dfbbb90dd522..1f5fb630a47038 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -505,9 +505,9 @@ static void replaceManagedVar(llvm::GlobalVariable *Var,
 }
 if (auto *I = dyn_cast(U)) {
   llvm::Value *OldV = Var;
-  llvm::Instruction *NewV =
-  new llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,
- llvm::Align(Var->getAlignment()), I);
+  llvm::Instruction *NewV = new llvm::LoadInst(
+  Var->getType(), ManagedVar, "ld.managed", false,
+  llvm::Align(Var->getAlignment()), I->getIterator());
   WorkItem.pop_back();
   // Replace constant expressions directly or indirectly using the managed
   // variable with instructions.

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index f333b20d86ad7f..070001a180ab88 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5064,8 +5064,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
 llvm::AllocaInst *AI;
 if (IP) {
   IP = IP->getNextNode();
-  AI = new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(),
-"argmem", IP);
+  AI = new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(), "argmem",
+IP->getIterator());
 } else {
   AI = CreateTempAlloca(ArgStruct, "argmem");
 }

diff  --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index 4e210a9e3c95ff..b1af4a0a97884b 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -293,20 +293,26 @@ void 
CodeGenFunction::initFullExprCleanupWithFlag(RawAddress ActiveFlag) {
 void EHScopeStack::Cleanup::anchor() {}
 
 static void createStoreInstBefore(llvm::Value *value, Address addr,
-  llvm::Instruction *beforeInst,
+  llvm::BasicBlock::iterator beforeInst,
   CodeGenFunction &CGF) {
   auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF), 
beforeInst);
   store->setAlignment(addr.getAlignment().getAsAlign());
 }
 
 static llvm::LoadInst *createLoadInstBefore(Address addr, const Twine &name,
-llvm::Instruction *beforeInst,
+llvm::BasicBlock::iterator 
beforeInst,
 CodeGenFunction &CGF) {
   return new llvm::LoadInst(addr.getElementType(), addr.emitRawPointer(CGF),
 name, false, addr.getAlignment().getAsAlign(),
 beforeInst);
 }
 
+static llvm::LoadInst *createLoadInstBefore(Address addr, const Twine &name,
+CodeGenFunction &CGF) {
+  return new llvm::LoadInst(addr.getElementType(), addr.emitRawPointer(CGF),
+name, false, addr.getAlignment().getAsAlign());
+}
+
 /// All the branch fixups on the EH stack have propagated out past the
 /// outermost normal cleanup; resolve them all by adding cases to the
 /// given switch instruction.
@@ -330,8 +336,8 @@ static void ResolveAllBranchFixups(CodeGenFunction &CGF,
 // entry which we're currently popping.
 if (Fixup.OptimisticBranchBlock == nullptr) {
   createStoreInstBefore(CGF.Builder.getInt32(Fixup.DestinationIndex),
-CGF.getNormalCleanupDestSlot(), 
Fixup.InitialBranch,
-

[clang] [DebugInfo][RemoveDIs] Use iterator-inserters in clang (PR #102006)

2024-08-09 Thread Jeremy Morse via cfe-commits

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


[clang] [clang][analyzer] Remove array bounds check from PointerSubChecker (PR #102580)

2024-08-09 Thread Balázs Kéri via cfe-commits

balazske wrote:

The `ArrayBoundV2` checker needs some update to find all cases. For example 
`(&x - 1) - &x` is not found, because the checker does only check 
`ArraySubscriptExpr` (and others), not a `BinaryOperator` with pointer and 
integer.

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


[clang] [clang-tools-extra] [clang-tidy] bugprone-implicit-widening ignores unsigned consts (PR #101073)

2024-08-09 Thread Nathan James via cfe-commits


@@ -569,7 +573,8 @@ class Expr : public ValueStmt {
   /// Note: This does not perform the implicit conversions required by C++11
   /// [expr.const]p5.
   bool isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result = nullptr,
-   SourceLocation *Loc = nullptr) const;
+   SourceLocation *Loc = nullptr,
+   bool CheckUnsignedOverflow = false) const;

njames93 wrote:

Given that unsigned overflow is well defined and allowed in constexpr, having 
an argument to disallow it seems a little off. From what I can tell the 
implementation here can just hard code the value internally to `false` and the 
public API for this function remains unchanged

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


[clang] [clang-tools-extra] [clang-tidy] bugprone-implicit-widening ignores unsigned consts (PR #101073)

2024-08-09 Thread Nathan James via cfe-commits

njames93 wrote:

> Thats a good question. @njames93 What do you thing, current tests are 
> sufficient ?

There should definitely be a test in the clang side of things to ensure correct 
handling of the `Expr::getIntegerConstantExpr` method with this new parameter

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


[clang-tools-extra] [clang-tidy] Add new check bugprone-tagged-union-member-count (PR #89925)

2024-08-09 Thread via cfe-commits
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= ,
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= ,
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= ,
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= ,
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= ,
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= ,
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= ,
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= 
Message-ID:
In-Reply-To: 



@@ -16,39 +16,74 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::bugprone {
 
-const char StrictModeOptionName[] = "StrictMode";
-const char EnableCountingEnumHeuristicOptionName[] =
+static constexpr llvm::StringLiteral StrictModeOptionName = "StrictMode";
+static constexpr llvm::StringLiteral EnableCountingEnumHeuristicOptionName =
 "EnableCountingEnumHeuristic";
-const char CountingEnumPrefixesOptionName[] = "CountingEnumPrefixes";
-const char CountingEnumSuffixesOptionName[] = "CountingEnumSuffixes";
+static constexpr llvm::StringLiteral CountingEnumPrefixesOptionName =
+"CountingEnumPrefixes";
+static constexpr llvm::StringLiteral CountingEnumSuffixesOptionName =
+"CountingEnumSuffixes";
+
+static constexpr bool StrictModeOptionDefaultValue = false;
+static constexpr bool EnableCountingEnumHeuristicOptionDefaultValue = true;
+static constexpr llvm::StringLiteral CountingEnumPrefixesOptionDefaultValue =
+"";
+static constexpr llvm::StringLiteral CountingEnumSuffixesOptionDefaultValue =
+"count";
+
+static constexpr llvm::StringLiteral RootMatchBindName = "root";
+static constexpr llvm::StringLiteral UnionMatchBindName = "union";
+static constexpr llvm::StringLiteral TagMatchBindName = "tags";
+
+namespace {
+AST_MATCHER(FieldDecl, isUnion) {
+  const Type *T = Node.getType().getCanonicalType().getTypePtr();
+  assert(T);
+  return T->isUnionType();
+}
+
+AST_MATCHER(FieldDecl, isEnum) {
+  const Type *T = Node.getType().getCanonicalType().getTypePtr();
+  assert(T);
+  return T->isEnumeralType();
+}

whisperity wrote:

@tigbr How about these matchers? https://godbolt.org/z/Mh3nEo8YY

```cpp
match fieldDecl(
hasType(qualType(hasCanonicalType(
recordType(hasDeclaration(
recordDecl(isUnion()).bind("union-decl")

)
).bind("union-field")

match fieldDecl(
hasType(qualType(hasCanonicalType(
enumType(hasDeclaration(
enumDecl().bind("enum-decl")
)
)))
)
).bind("enum-field")
```

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


[clang-tools-extra] [clang-tidy] Add new check bugprone-tagged-union-member-count (PR #89925)

2024-08-09 Thread via cfe-commits
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= ,
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= ,
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= ,
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= ,
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= ,
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= ,
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= ,
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= 
Message-ID:
In-Reply-To: 


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


[clang] [clang][analyzer] Remove array bounds check from PointerSubChecker (PR #102580)

2024-08-09 Thread Donát Nagy via cfe-commits

NagyDonat wrote:

Oh, you're right, invalid pointer arithmetic like `(&x - 1)` is not handled by 
ArrayBoundV2, because right now that's the responsibility of a THIRD checker, 
`alpha.core.PointerArithm`.

However, directly after bringing `ArrayBoundV2` out of alpha, I'll continue 
with working on this `PointerArithm` and either I'll completely merge it with 
`ArrayBoundV2` or I'll keep it as a separate "frontend" which also calls the 
bounds-checking logic that's behind `ArrayBoundV2`.

Based on this I'd suggest that you should
- delete the bounds checking logic from `PointerSubChecker`,
- delete the testcases that were testing it (because it would be too 
complicated to bring in *two* other checkers + AFAIK `PointerArithm` is in a 
bad shape currently),
- refer to both ArrayBoundV2 and PointerArithm in the documentation.

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


[clang] [Arm][AArch64][Clang] Respect function's branch protection attributes. (PR #101978)

2024-08-09 Thread Ties Stuij via cfe-commits


@@ -209,9 +209,28 @@ llvm::Value *TargetCodeGenInfo::createEnqueuedBlockKernel(
 
 void TargetCodeGenInfo::setBranchProtectionFnAttributes(
 const TargetInfo::BranchProtectionInfo &BPI, llvm::Function &F) {
-  llvm::AttrBuilder FuncAttrs(F.getContext());
-  setBranchProtectionFnAttributes(BPI, FuncAttrs);
-  F.addFnAttrs(FuncAttrs);
+  if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
+F.addFnAttr("sign-return-address", BPI.getSignReturnAddrStr());
+F.addFnAttr("sign-return-address-key", BPI.getSignKeyStr());
+  } else {
+if (F.hasFnAttribute("sign-return-address"))
+  F.removeFnAttr("sign-return-address");
+if (F.hasFnAttribute("sign-return-address-key"))
+  F.removeFnAttr("sign-return-address-key");
+  }
+
+  auto AddRemoveAttributeAsSet = [&](bool Set, const StringRef &ModAttr) {
+if (Set)
+  F.addFnAttr(ModAttr);
+else if (F.hasFnAttribute(ModAttr))
+  F.removeFnAttr(ModAttr);
+  };
+
+  AddRemoveAttributeAsSet(BPI.BranchTargetEnforcement,
+  "branch-target-enforcement");
+  AddRemoveAttributeAsSet(BPI.BranchProtectionPAuthLR,
+  "branch-protection-pauth-lr");
+  AddRemoveAttributeAsSet(BPI.GuardedControlStack, "guarded-control-stack");
 }
 
 void TargetCodeGenInfo::setBranchProtectionFnAttributes(

stuij wrote:

I can see that this AttrBuilder version of the fn is still used in 
`getTrivialDefaultFunctionAttributes` in `CGCall.cpp`. I guess in practice the 
outcome would still be the same for this use case between old and new 
implementation, but even if I didn't miss something it does feel a bit icky to 
do so.

Perhaps add a comment to explain the code duplication?

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


[clang] badfb4b - [Clang][Interp] Fix display of syntactically-invalid note for member function calls (#102170)

2024-08-09 Thread via cfe-commits

Author: yronglin
Date: 2024-08-09T17:49:00+08:00
New Revision: badfb4bd33c27f7bb6351ad3d7250a9b8782b43f

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

LOG: [Clang][Interp] Fix display of syntactically-invalid note for member 
function calls (#102170)

This PR fix display of syntactically-invalid note for member function
calls to follow the behavior of current interpreter.

-

Signed-off-by: yronglin 

Added: 
clang/test/AST/Interp/constexpr-frame-describe.cpp

Modified: 
clang/lib/AST/Interp/InterpFrame.cpp
clang/lib/AST/Interp/Source.cpp
clang/test/AST/Interp/constexpr-nqueens.cpp
clang/test/AST/Interp/lambda.cpp
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index 83784db91f4f3e..27108f957305f3 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -18,6 +18,7 @@
 #include "Program.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/ExprCXX.h"
 
 using namespace clang;
 using namespace clang::interp;
@@ -169,11 +170,32 @@ void InterpFrame::describe(llvm::raw_ostream &OS) const {
   F && (F->isBuiltin() || F->isLambdaStaticInvoker()))
 return;
 
+  const Expr *CallExpr = Caller->getExpr(getRetPC());
   const FunctionDecl *F = getCallee();
-  if (const auto *M = dyn_cast(F);
-  M && M->isInstance() && !isa(F)) {
-print(OS, This, S.getCtx(), S.getCtx().getRecordType(M->getParent()));
-OS << "->";
+  bool IsMemberCall = isa(F) && !isa(F) &&
+  cast(F)->isImplicitObjectMemberFunction();
+  if (Func->hasThisPointer() && IsMemberCall) {
+if (const auto *MCE = dyn_cast_if_present(CallExpr)) {
+  const Expr *Object = MCE->getImplicitObjectArgument();
+  Object->printPretty(OS, /*Helper=*/nullptr,
+  S.getCtx().getPrintingPolicy(),
+  /*Indentation=*/0);
+  if (Object->getType()->isPointerType())
+OS << "->";
+  else
+OS << ".";
+} else if (const auto *OCE =
+   dyn_cast_if_present(CallExpr)) {
+  OCE->getArg(0)->printPretty(OS, /*Helper=*/nullptr,
+  S.getCtx().getPrintingPolicy(),
+  /*Indentation=*/0);
+  OS << ".";
+} else if (const auto *M = dyn_cast(F)) {
+  print(OS, This, S.getCtx(),
+S.getCtx().getLValueReferenceType(
+S.getCtx().getRecordType(M->getParent(;
+  OS << ".";
+}
   }
 
   F->getNameForDiagnostic(OS, S.getCtx().getPrintingPolicy(),

diff  --git a/clang/lib/AST/Interp/Source.cpp b/clang/lib/AST/Interp/Source.cpp
index 45cd0ad4fd4273..77796b00ca52cb 100644
--- a/clang/lib/AST/Interp/Source.cpp
+++ b/clang/lib/AST/Interp/Source.cpp
@@ -41,7 +41,7 @@ const Expr *SourceInfo::asExpr() const {
 const Expr *SourceMapper::getExpr(const Function *F, CodePtr PC) const {
   if (const Expr *E = getSource(F, PC).asExpr())
 return E;
-  llvm::report_fatal_error("missing source expression");
+  return nullptr;
 }
 
 SourceLocation SourceMapper::getLocation(const Function *F, CodePtr PC) const {

diff  --git a/clang/test/AST/Interp/constexpr-frame-describe.cpp 
b/clang/test/AST/Interp/constexpr-frame-describe.cpp
new file mode 100644
index 00..e039fd61ae9812
--- /dev/null
+++ b/clang/test/AST/Interp/constexpr-frame-describe.cpp
@@ -0,0 +1,83 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=ref,both %s
+// RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter 
-fsyntax-only -verify=expected,both %s
+
+
+struct Foo {
+constexpr void zomg() const { (void)(1 / 0); } // both-error {{constant 
expression}} \
+  both-warning {{division 
by zero}} \
+  both-note 2{{division by 
zero}}
+};
+
+struct S {
+constexpr S() {}
+constexpr bool operator==(const S&) const { // both-error {{never produces 
a constant expression}}
+  return 1 / 0; // both-warning {{division by zero}} \
+   both-note 3{{division by zero}}
+}
+
+constexpr bool heh() const {
+auto F = new Foo();
+F->zomg(); // both-note {{in call to 'F->zomg()'}}
+delete F;
+return false;
+}
+};
+
+constexpr S s;
+
+static_assert(s.heh()); // both-error {{constant expression}} \
+   both-note {{in call to 's.heh()'}}
+
+constexpr S s2;
+constexpr const S *sptr = &s;
+constexpr const S *sptr2 = &s2;
+static_assert(s == s2); // both-error {{constant expression}} \
+   both-note {{in call to 's.operator==(s2)'}}
+static_as

[clang] [Clang][Interp] Fix display of syntactically-invalid note for member function calls (PR #102170)

2024-08-09 Thread via cfe-commits

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


[clang] [DebugInfo][RemoveDIs] Use iterator-inserters in clang (PR #102006)

2024-08-09 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-libc-amdgpu-runtime` running on `omp-vega20-1` while building 
`clang` at step 10 "Add check check-offload".

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

Here is the relevant piece of the build log for the reference:
```
Step 10 (Add check check-offload) failure: 1200 seconds without output running 
[b'ninja', b'-j 32', b'check-offload'], attempting to kill
...
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/test_libc.cpp (827 
of 837)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/bug53727.cpp (828 
of 837)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/bug50022.cpp (829 
of 837)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/wtime.c (830 of 837)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/bug47654.cpp (831 
of 837)
PASS: libomptarget :: x86_64-pc-linux-gnu :: 
offloading/std_complex_arithmetic.cpp (832 of 837)
PASS: libomptarget :: x86_64-pc-linux-gnu :: offloading/bug49021.cpp (833 of 
837)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: 
offloading/complex_reduction.cpp (834 of 837)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: 
offloading/std_complex_arithmetic.cpp (835 of 837)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/bug49021.cpp (836 
of 837)
command timed out: 1200 seconds without output running [b'ninja', b'-j 32', 
b'check-offload'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1230.437460

```

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


[clang] [llvm] [X86][AVX10.2] Support saturated converts (PR #102592)

2024-08-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Malay Sanghi (MalaySanghi)


Changes

Ref.: https://cdrdv2.intel.com/v1/dl/getContent/828965

---

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


31 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsX86.def (+30) 
- (modified) clang/include/clang/Basic/BuiltinsX86_64.def (+6) 
- (modified) clang/lib/Headers/CMakeLists.txt (+2) 
- (added) clang/lib/Headers/avx10_2_512satcvtdsintrin.h (+302) 
- (added) clang/lib/Headers/avx10_2satcvtdsintrin.h (+453) 
- (modified) clang/lib/Headers/immintrin.h (+8) 
- (modified) clang/lib/Sema/SemaX86.cpp (+26) 
- (added) clang/test/CodeGen/X86/avx10_2_512satcvtds-builtins-errors.c (+52) 
- (added) clang/test/CodeGen/X86/avx10_2_512satcvtds-builtins-x64-error.c (+76) 
- (added) clang/test/CodeGen/X86/avx10_2_512satcvtds-builtins-x64.c (+184) 
- (added) clang/test/CodeGen/X86/avx10_2_512satcvtds-builtins.c (+183) 
- (added) clang/test/CodeGen/X86/avx10_2satcvtds-builtins-errors.c (+57) 
- (added) clang/test/CodeGen/X86/avx10_2satcvtds-builtins-x64.c (+223) 
- (added) clang/test/CodeGen/X86/avx10_2satcvtds-builtins.c (+220) 
- (modified) llvm/include/llvm/IR/IntrinsicsX86.td (+100) 
- (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+21-2) 
- (modified) llvm/lib/Target/X86/X86ISelLowering.h (+18) 
- (modified) llvm/lib/Target/X86/X86InstrAVX10.td (+311) 
- (modified) llvm/lib/Target/X86/X86InstrFragmentsSIMD.td (+12) 
- (modified) llvm/lib/Target/X86/X86IntrinsicsInfo.h (+65-1) 
- (added) llvm/test/CodeGen/X86/avx10_2_512satcvtds-intrinsics.ll (+548) 
- (added) llvm/test/CodeGen/X86/avx10_2fptosi_satcvtds.ll (+115) 
- (added) llvm/test/CodeGen/X86/avx10_2satcvtds-intrinsics.ll (+1098) 
- (added) llvm/test/CodeGen/X86/avx10_2satcvtds-x64-intrinsics.ll (+58) 
- (added) llvm/test/MC/Disassembler/X86/avx10.2-satcvtds-32.txt (+1043) 
- (added) llvm/test/MC/Disassembler/X86/avx10.2-satcvtds-64.txt (+1171) 
- (added) llvm/test/MC/X86/avx10_2satcvtds-32-att.s (+1042) 
- (added) llvm/test/MC/X86/avx10_2satcvtds-32-intel.s (+1042) 
- (added) llvm/test/MC/X86/avx10_2satcvtds-64-att.s (+1170) 
- (added) llvm/test/MC/X86/avx10_2satcvtds-64-intel.s (+1170) 
- (modified) llvm/test/TableGen/x86-fold-tables.inc (+160) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsX86.def 
b/clang/include/clang/Basic/BuiltinsX86.def
index a696cf117908e2..a8639c341d0a43 100644
--- a/clang/include/clang/Basic/BuiltinsX86.def
+++ b/clang/include/clang/Basic/BuiltinsX86.def
@@ -2122,6 +2122,36 @@ TARGET_BUILTIN(__builtin_ia32_vpdpwuud256, 
"V8iV8iV8iV8i", "nV:256:", "avxvnniin
 TARGET_BUILTIN(__builtin_ia32_vpdpwuuds128, "V4iV4iV4iV4i", "nV:128:", 
"avxvnniint16|avx10.2-256")
 TARGET_BUILTIN(__builtin_ia32_vpdpwuuds256, "V8iV8iV8iV8i", "nV:256:", 
"avxvnniint16|avx10.2-256")
 
+// AVX10.2 SATCVT-DS
+TARGET_BUILTIN(__builtin_ia32_vcvttssd2si32, "iV2dIi", "ncV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttssd2usi32, "UiV2dIi", "ncV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttsss2si32, "iV4fIi", "ncV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttsss2usi32, "UiV4fIi", "ncV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2dqs128_mask, "V4iV2dV4iUc", "nV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2dqs256_round_mask, "V4iV4dV4iUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2dqs512_round_mask, "V8iV8dV8iUcIi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2udqs128_mask, "V4iV2dV4iUc", "nV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2udqs256_round_mask, "V4iV4dV4iUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2udqs512_round_mask, "V8iV8dV8iUcIi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2qqs128_mask,  "V2OiV2dV2OiUc", 
"nV:128:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2qqs256_round_mask, "V4OiV4dV4OiUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2qqs512_round_mask, "V8OiV8dV8OiUcIi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2uqqs128_mask, "V2OiV2dV2OiUc", 
"nV:128:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2uqqs256_round_mask, "V4OiV4dV4OiUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2uqqs512_round_mask, "V8OiV8dV8OiUcIi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvttps2dqs128_mask, "V4iV4fV4iUc", "nV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttps2dqs256_round_mask, "V8iV8fV8iUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttps2dqs512_round_mask, "V16iV16fV16iUsIi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvttps2udqs128_mask, "V4iV4fV4iUc", "nV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttps2udqs256_round_mask, "V8iV8fV8iUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttps2udqs

[clang] [llvm] [X86][AVX10.2] Support saturated converts (PR #102592)

2024-08-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Malay Sanghi (MalaySanghi)


Changes

Ref.: https://cdrdv2.intel.com/v1/dl/getContent/828965

---

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


31 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsX86.def (+30) 
- (modified) clang/include/clang/Basic/BuiltinsX86_64.def (+6) 
- (modified) clang/lib/Headers/CMakeLists.txt (+2) 
- (added) clang/lib/Headers/avx10_2_512satcvtdsintrin.h (+302) 
- (added) clang/lib/Headers/avx10_2satcvtdsintrin.h (+453) 
- (modified) clang/lib/Headers/immintrin.h (+8) 
- (modified) clang/lib/Sema/SemaX86.cpp (+26) 
- (added) clang/test/CodeGen/X86/avx10_2_512satcvtds-builtins-errors.c (+52) 
- (added) clang/test/CodeGen/X86/avx10_2_512satcvtds-builtins-x64-error.c (+76) 
- (added) clang/test/CodeGen/X86/avx10_2_512satcvtds-builtins-x64.c (+184) 
- (added) clang/test/CodeGen/X86/avx10_2_512satcvtds-builtins.c (+183) 
- (added) clang/test/CodeGen/X86/avx10_2satcvtds-builtins-errors.c (+57) 
- (added) clang/test/CodeGen/X86/avx10_2satcvtds-builtins-x64.c (+223) 
- (added) clang/test/CodeGen/X86/avx10_2satcvtds-builtins.c (+220) 
- (modified) llvm/include/llvm/IR/IntrinsicsX86.td (+100) 
- (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+21-2) 
- (modified) llvm/lib/Target/X86/X86ISelLowering.h (+18) 
- (modified) llvm/lib/Target/X86/X86InstrAVX10.td (+311) 
- (modified) llvm/lib/Target/X86/X86InstrFragmentsSIMD.td (+12) 
- (modified) llvm/lib/Target/X86/X86IntrinsicsInfo.h (+65-1) 
- (added) llvm/test/CodeGen/X86/avx10_2_512satcvtds-intrinsics.ll (+548) 
- (added) llvm/test/CodeGen/X86/avx10_2fptosi_satcvtds.ll (+115) 
- (added) llvm/test/CodeGen/X86/avx10_2satcvtds-intrinsics.ll (+1098) 
- (added) llvm/test/CodeGen/X86/avx10_2satcvtds-x64-intrinsics.ll (+58) 
- (added) llvm/test/MC/Disassembler/X86/avx10.2-satcvtds-32.txt (+1043) 
- (added) llvm/test/MC/Disassembler/X86/avx10.2-satcvtds-64.txt (+1171) 
- (added) llvm/test/MC/X86/avx10_2satcvtds-32-att.s (+1042) 
- (added) llvm/test/MC/X86/avx10_2satcvtds-32-intel.s (+1042) 
- (added) llvm/test/MC/X86/avx10_2satcvtds-64-att.s (+1170) 
- (added) llvm/test/MC/X86/avx10_2satcvtds-64-intel.s (+1170) 
- (modified) llvm/test/TableGen/x86-fold-tables.inc (+160) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsX86.def 
b/clang/include/clang/Basic/BuiltinsX86.def
index a696cf117908e2..a8639c341d0a43 100644
--- a/clang/include/clang/Basic/BuiltinsX86.def
+++ b/clang/include/clang/Basic/BuiltinsX86.def
@@ -2122,6 +2122,36 @@ TARGET_BUILTIN(__builtin_ia32_vpdpwuud256, 
"V8iV8iV8iV8i", "nV:256:", "avxvnniin
 TARGET_BUILTIN(__builtin_ia32_vpdpwuuds128, "V4iV4iV4iV4i", "nV:128:", 
"avxvnniint16|avx10.2-256")
 TARGET_BUILTIN(__builtin_ia32_vpdpwuuds256, "V8iV8iV8iV8i", "nV:256:", 
"avxvnniint16|avx10.2-256")
 
+// AVX10.2 SATCVT-DS
+TARGET_BUILTIN(__builtin_ia32_vcvttssd2si32, "iV2dIi", "ncV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttssd2usi32, "UiV2dIi", "ncV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttsss2si32, "iV4fIi", "ncV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttsss2usi32, "UiV4fIi", "ncV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2dqs128_mask, "V4iV2dV4iUc", "nV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2dqs256_round_mask, "V4iV4dV4iUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2dqs512_round_mask, "V8iV8dV8iUcIi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2udqs128_mask, "V4iV2dV4iUc", "nV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2udqs256_round_mask, "V4iV4dV4iUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2udqs512_round_mask, "V8iV8dV8iUcIi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2qqs128_mask,  "V2OiV2dV2OiUc", 
"nV:128:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2qqs256_round_mask, "V4OiV4dV4OiUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2qqs512_round_mask, "V8OiV8dV8OiUcIi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2uqqs128_mask, "V2OiV2dV2OiUc", 
"nV:128:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2uqqs256_round_mask, "V4OiV4dV4OiUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2uqqs512_round_mask, "V8OiV8dV8OiUcIi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvttps2dqs128_mask, "V4iV4fV4iUc", "nV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttps2dqs256_round_mask, "V8iV8fV8iUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttps2dqs512_round_mask, "V16iV16fV16iUsIi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvttps2udqs128_mask, "V4iV4fV4iUc", "nV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttps2udqs256_round_mask, "V8iV8fV8iUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttp

[clang] [llvm] [X86][AVX10.2] Support saturated converts (PR #102592)

2024-08-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-mc

Author: Malay Sanghi (MalaySanghi)


Changes

Ref.: https://cdrdv2.intel.com/v1/dl/getContent/828965

---

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


31 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsX86.def (+30) 
- (modified) clang/include/clang/Basic/BuiltinsX86_64.def (+6) 
- (modified) clang/lib/Headers/CMakeLists.txt (+2) 
- (added) clang/lib/Headers/avx10_2_512satcvtdsintrin.h (+302) 
- (added) clang/lib/Headers/avx10_2satcvtdsintrin.h (+453) 
- (modified) clang/lib/Headers/immintrin.h (+8) 
- (modified) clang/lib/Sema/SemaX86.cpp (+26) 
- (added) clang/test/CodeGen/X86/avx10_2_512satcvtds-builtins-errors.c (+52) 
- (added) clang/test/CodeGen/X86/avx10_2_512satcvtds-builtins-x64-error.c (+76) 
- (added) clang/test/CodeGen/X86/avx10_2_512satcvtds-builtins-x64.c (+184) 
- (added) clang/test/CodeGen/X86/avx10_2_512satcvtds-builtins.c (+183) 
- (added) clang/test/CodeGen/X86/avx10_2satcvtds-builtins-errors.c (+57) 
- (added) clang/test/CodeGen/X86/avx10_2satcvtds-builtins-x64.c (+223) 
- (added) clang/test/CodeGen/X86/avx10_2satcvtds-builtins.c (+220) 
- (modified) llvm/include/llvm/IR/IntrinsicsX86.td (+100) 
- (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+21-2) 
- (modified) llvm/lib/Target/X86/X86ISelLowering.h (+18) 
- (modified) llvm/lib/Target/X86/X86InstrAVX10.td (+311) 
- (modified) llvm/lib/Target/X86/X86InstrFragmentsSIMD.td (+12) 
- (modified) llvm/lib/Target/X86/X86IntrinsicsInfo.h (+65-1) 
- (added) llvm/test/CodeGen/X86/avx10_2_512satcvtds-intrinsics.ll (+548) 
- (added) llvm/test/CodeGen/X86/avx10_2fptosi_satcvtds.ll (+115) 
- (added) llvm/test/CodeGen/X86/avx10_2satcvtds-intrinsics.ll (+1098) 
- (added) llvm/test/CodeGen/X86/avx10_2satcvtds-x64-intrinsics.ll (+58) 
- (added) llvm/test/MC/Disassembler/X86/avx10.2-satcvtds-32.txt (+1043) 
- (added) llvm/test/MC/Disassembler/X86/avx10.2-satcvtds-64.txt (+1171) 
- (added) llvm/test/MC/X86/avx10_2satcvtds-32-att.s (+1042) 
- (added) llvm/test/MC/X86/avx10_2satcvtds-32-intel.s (+1042) 
- (added) llvm/test/MC/X86/avx10_2satcvtds-64-att.s (+1170) 
- (added) llvm/test/MC/X86/avx10_2satcvtds-64-intel.s (+1170) 
- (modified) llvm/test/TableGen/x86-fold-tables.inc (+160) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsX86.def 
b/clang/include/clang/Basic/BuiltinsX86.def
index a696cf117908e2..a8639c341d0a43 100644
--- a/clang/include/clang/Basic/BuiltinsX86.def
+++ b/clang/include/clang/Basic/BuiltinsX86.def
@@ -2122,6 +2122,36 @@ TARGET_BUILTIN(__builtin_ia32_vpdpwuud256, 
"V8iV8iV8iV8i", "nV:256:", "avxvnniin
 TARGET_BUILTIN(__builtin_ia32_vpdpwuuds128, "V4iV4iV4iV4i", "nV:128:", 
"avxvnniint16|avx10.2-256")
 TARGET_BUILTIN(__builtin_ia32_vpdpwuuds256, "V8iV8iV8iV8i", "nV:256:", 
"avxvnniint16|avx10.2-256")
 
+// AVX10.2 SATCVT-DS
+TARGET_BUILTIN(__builtin_ia32_vcvttssd2si32, "iV2dIi", "ncV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttssd2usi32, "UiV2dIi", "ncV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttsss2si32, "iV4fIi", "ncV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttsss2usi32, "UiV4fIi", "ncV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2dqs128_mask, "V4iV2dV4iUc", "nV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2dqs256_round_mask, "V4iV4dV4iUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2dqs512_round_mask, "V8iV8dV8iUcIi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2udqs128_mask, "V4iV2dV4iUc", "nV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2udqs256_round_mask, "V4iV4dV4iUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2udqs512_round_mask, "V8iV8dV8iUcIi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2qqs128_mask,  "V2OiV2dV2OiUc", 
"nV:128:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2qqs256_round_mask, "V4OiV4dV4OiUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2qqs512_round_mask, "V8OiV8dV8OiUcIi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2uqqs128_mask, "V2OiV2dV2OiUc", 
"nV:128:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2uqqs256_round_mask, "V4OiV4dV4OiUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttpd2uqqs512_round_mask, "V8OiV8dV8OiUcIi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvttps2dqs128_mask, "V4iV4fV4iUc", "nV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttps2dqs256_round_mask, "V8iV8fV8iUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttps2dqs512_round_mask, "V16iV16fV16iUsIi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvttps2udqs128_mask, "V4iV4fV4iUc", "nV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttps2udqs256_round_mask, "V8iV8fV8iUcIi", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvttps2udqs512

[clang] [llvm] [X86][AVX10.2] Support saturated converts (PR #102592)

2024-08-09 Thread Malay Sanghi via cfe-commits

MalaySanghi wrote:

@phoebewang @KanRobert please review

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


[clang] 08e0e29 - [RISCV][clang] Add missing `zvfbfmin` to `vget_v` intrinsic (#102149)

2024-08-09 Thread via cfe-commits

Author: Brandon Wu
Date: 2024-08-09T17:57:24+08:00
New Revision: 08e0e29572ac0a324ac36831a843ac99f41f42a4

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

LOG: [RISCV][clang] Add missing `zvfbfmin` to `vget_v` intrinsic (#102149)

It's missing in the patch supporting `zvfbfmin` intrinsics.

Added: 


Modified: 
clang/include/clang/Basic/riscv_vector.td

Removed: 




diff  --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index dda2dcb9f4ff6..69ac87297149c 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -2547,12 +2547,16 @@ let HasMasked = false, HasVL = false, IRName = "" in {
   }
   }] in {
 foreach dst_lmul = ["(SFixedLog2LMUL:0)", "(SFixedLog2LMUL:1)", 
"(SFixedLog2LMUL:2)"] in {
-  def : RVVBuiltin<"v" # dst_lmul # "v", dst_lmul # "vvKz", "csilxfdy", 
dst_lmul # "v">;
+  def : RVVBuiltin<"v" # dst_lmul # "v", dst_lmul # "vvKz", "csilxfd", 
dst_lmul # "v">;
+  let RequiredFeatures = ["Zvfbfmin"] in
+def : RVVBuiltin<"v" # dst_lmul # "v", dst_lmul # "vvKz", "y", 
dst_lmul # "v">;
   def : RVVBuiltin<"Uv" # dst_lmul # "Uv", dst_lmul # "UvUvKz", "csil", 
dst_lmul # "Uv">;
 }
 foreach nf = NFList in {
   defvar T = "(Tuple:" # nf # ")";
-  def : RVVBuiltin;
+  def : RVVBuiltin;
+  let RequiredFeatures = ["Zvfbfmin"] in
+def : RVVBuiltin;
   def : RVVBuiltin;
 }
   }



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


[clang] [RISCV][clang] Add missing `zvfbfmin` to `vget_v` intrinsic (PR #102149)

2024-08-09 Thread Brandon Wu via cfe-commits

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


[clang] 1b80ed4 - [RISCV][clang] Remove bfloat base type in non-zvfbfmin vcreate (#102146)

2024-08-09 Thread via cfe-commits

Author: Brandon Wu
Date: 2024-08-09T17:57:45+08:00
New Revision: 1b80ed457d2dfd278541b7c20e7d2b6192ecbf13

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

LOG: [RISCV][clang] Remove bfloat base type in non-zvfbfmin vcreate (#102146)

Added: 


Modified: 
clang/include/clang/Basic/riscv_vector.td

Removed: 




diff  --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index 69ac87297149c..80e0f6ec65390 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -2637,7 +2637,7 @@ let HasMasked = false, HasVL = false, IRName = "" in {
 defvar T = "(Tuple:" # nf # ")";
 defvar V = VString.S;
 defvar UV = VString.S;
-def : RVVBuiltin;
+def : RVVBuiltin;
 let RequiredFeatures = ["Zvfbfmin"] in
   def : RVVBuiltin;
 def : RVVBuiltin;



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


[clang] [RISCV][clang] Remove bfloat base type in non-zvfbfmin vcreate (PR #102146)

2024-08-09 Thread Brandon Wu via cfe-commits

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


[clang] [Fuchsia][CMake] Remove new/delete from baremetal libc++ (PR #102415)

2024-08-09 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-aarch64-lld-2stage` 
running on `linaro-clang-aarch64-lld-2stage` while building `clang` at step 13 
"ninja check 2".

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

Here is the relevant piece of the build log for the reference:
```
Step 13 (ninja check 2) failure: stage 2 checked (failure)
 TEST 'AddressSanitizer-aarch64-linux-dynamic :: 
TestCases/Posix/halt_on_error-signals.c' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 3: 
/home/tcwg-buildbot/worker/clang-aarch64-lld-2stage/stage2/./bin/clang  
-fsanitize=address -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer 
-fno-optimize-sibling-calls -gline-tables-only   -Wthread-safety 
-Wthread-safety-reference -Wthread-safety-beta   -shared-libasan 
-fsanitize-recover=address -pthread 
/home/tcwg-buildbot/worker/clang-aarch64-lld-2stage/llvm/compiler-rt/test/asan/TestCases/Posix/halt_on_error-signals.c
 -o 
/home/tcwg-buildbot/worker/clang-aarch64-lld-2stage/stage2/runtimes/runtimes-bins/compiler-rt/test/asan/AARCH64LinuxDynamicConfig/TestCases/Posix/Output/halt_on_error-signals.c.tmp
+ /home/tcwg-buildbot/worker/clang-aarch64-lld-2stage/stage2/./bin/clang 
-fsanitize=address -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer 
-fno-optimize-sibling-calls -gline-tables-only -Wthread-safety 
-Wthread-safety-reference -Wthread-safety-beta -shared-libasan 
-fsanitize-recover=address -pthread 
/home/tcwg-buildbot/worker/clang-aarch64-lld-2stage/llvm/compiler-rt/test/asan/TestCases/Posix/halt_on_error-signals.c
 -o 
/home/tcwg-buildbot/worker/clang-aarch64-lld-2stage/stage2/runtimes/runtimes-bins/compiler-rt/test/asan/AARCH64LinuxDynamicConfig/TestCases/Posix/Output/halt_on_error-signals.c.tmp
In file included from 
/home/tcwg-buildbot/worker/clang-aarch64-lld-2stage/llvm/compiler-rt/test/asan/TestCases/Posix/halt_on_error-signals.c:11:
In file included from /usr/include/stdio.h:27:
In file included from 
/usr/include/aarch64-linux-gnu/bits/libc-header-start.h:33:
/usr/include/features.h:187:3: warning: "_BSD_SOURCE and _SVID_SOURCE are 
deprecated, use _DEFAULT_SOURCE" [-W#warnings]
  187 | # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use 
_DEFAULT_SOURCE"
  |   ^
1 warning generated.
RUN: at line 5: env ASAN_OPTIONS=halt_on_error=false:suppress_equal_pcs=false  
/home/tcwg-buildbot/worker/clang-aarch64-lld-2stage/stage2/runtimes/runtimes-bins/compiler-rt/test/asan/AARCH64LinuxDynamicConfig/TestCases/Posix/Output/halt_on_error-signals.c.tmp
 100 
>/home/tcwg-buildbot/worker/clang-aarch64-lld-2stage/stage2/runtimes/runtimes-bins/compiler-rt/test/asan/AARCH64LinuxDynamicConfig/TestCases/Posix/Output/halt_on_error-signals.c.tmp.log
 2>&1 || true
+ env ASAN_OPTIONS=halt_on_error=false:suppress_equal_pcs=false 
/home/tcwg-buildbot/worker/clang-aarch64-lld-2stage/stage2/runtimes/runtimes-bins/compiler-rt/test/asan/AARCH64LinuxDynamicConfig/TestCases/Posix/Output/halt_on_error-signals.c.tmp
 100
+ true
RUN: at line 7: FileCheck --check-prefix=CHECK-COLLISION 
/home/tcwg-buildbot/worker/clang-aarch64-lld-2stage/llvm/compiler-rt/test/asan/TestCases/Posix/halt_on_error-signals.c
 
:1:1: note: scanning from here
=
^
:54:141: note: possible intended match here
/home/tcwg-buildbot/worker/clang-aarch64-lld-2stage/stage2/./bin/llvm-symbolizer:
 error: 'linux-vdso.so.1': AddressSanitizerNo such file or directory: nested 
bug in the same thread, aborting.

^

Input file: 
Check file: 
/home/tcwg-buildbot/worker/clang-aarch64-lld-2stage/llvm/compiler-rt/test/asan/TestCases/Posix/halt_on_error-signals.c

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

Input was:
<<
1: 
= 
check:29'0 
X~ error: no 
match found
2: ==1360716==ERROR: AddressSanitizer: use-after-poison on address 
0xab10b160 at pc 0xab0f8c64 bp 0xa7dfe7a0 sp 0xa7dfe798 
check:29'0 

3: WRITE of size 1 at 0xab10b160 thread T1 
check:29'0 
4:  #0 0xab0f8c60 in error 
/home/tcwg-buildbot/worker/clang-aarch64-lld-2stage/llvm/compiler-rt/test/asan/TestCases/Posix/halt_on_error-signals.c:32:12
 
check:29'0 
~
5:  #1 0xab0f9010 in receiver 
/home/tcwg-buildbot/worker/clang

[clang] [RFC] Add clang atomic control options and pragmas (PR #102569)

2024-08-09 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

Thank you for the patch, but RFCs for Clang should be published in 
https://discourse.llvm.org/c/clang/6. PRs doesn't have the visibility we want 
RFCs to have.

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


[clang] [lldb] [llvm] Extending LLDB to work on AIX (PR #102601)

2024-08-09 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [lldb] [llvm] Extending LLDB to work on AIX (PR #102601)

2024-08-09 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-binary-utilities

@llvm/pr-subscribers-clang-codegen

Author: None (Dhruv-Srivastava-IBM)


Changes

We have Implemented the necessary code changes required to run LLDB on AIX. 
This PR is for discussion as asked in #101657
With this PR, we request your inputs and feedback about our code changes. 


---

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


128 Files Affected:

- (modified) clang/lib/CodeGen/CGObjCMac.cpp (+5-1) 
- (modified) lldb/CMakeLists.txt (+4) 
- (added) lldb/NOTICE.TXT (+7) 
- (modified) lldb/cmake/modules/LLDBConfig.cmake (+1-1) 
- (modified) lldb/include/lldb/Core/Module.h (+3) 
- (modified) lldb/include/lldb/Core/ModuleSpec.h (+21-2) 
- (modified) lldb/include/lldb/Host/HostGetOpt.h (+1-1) 
- (modified) lldb/include/lldb/Host/HostInfo.h (+3) 
- (modified) lldb/include/lldb/Host/HostInfoBase.h (+1-1) 
- (modified) lldb/include/lldb/Host/XML.h (+5) 
- (added) lldb/include/lldb/Host/aix/AbstractSocket.h (+25) 
- (added) lldb/include/lldb/Host/aix/Host.h (+22) 
- (added) lldb/include/lldb/Host/aix/HostInfoAIX.h (+42) 
- (added) lldb/include/lldb/Host/aix/Ptrace.h (+62) 
- (added) lldb/include/lldb/Host/aix/Support.h (+29) 
- (added) lldb/include/lldb/Host/aix/Uio.h (+23) 
- (modified) lldb/include/lldb/Host/common/GetOptInc.h (+3-3) 
- (modified) lldb/include/lldb/Symbol/ObjectFile.h (+5) 
- (modified) lldb/include/lldb/Target/ABI.h (+6) 
- (modified) lldb/include/lldb/Target/DynamicLoader.h (+6) 
- (modified) lldb/include/lldb/Target/Process.h (+14) 
- (modified) lldb/include/lldb/Target/RegisterContextUnwind.h (+4) 
- (modified) lldb/include/lldb/Target/ThreadPlanCallFunction.h (+6) 
- (modified) lldb/include/lldb/Utility/StringExtractorGDBRemote.h (+1) 
- (modified) lldb/include/lldb/lldb-private-enumerations.h (+1) 
- (modified) lldb/source/API/CMakeLists.txt (+108) 
- (modified) lldb/source/API/SBBreakpoint.cpp (+3-3) 
- (modified) lldb/source/API/SBBreakpointLocation.cpp (+3-3) 
- (modified) lldb/source/API/SBBreakpointName.cpp (+2-2) 
- (modified) lldb/source/Core/DynamicLoader.cpp (+10) 
- (modified) lldb/source/Core/Mangled.cpp (+2) 
- (modified) lldb/source/Core/Module.cpp (+12) 
- (modified) lldb/source/Core/Section.cpp (+4) 
- (modified) lldb/source/Expression/DWARFExpression.cpp (+5-5) 
- (modified) lldb/source/Host/CMakeLists.txt (+13) 
- (added) lldb/source/Host/aix/AbstractSocket.cpp (+21) 
- (added) lldb/source/Host/aix/Host.cpp (+304) 
- (added) lldb/source/Host/aix/HostInfoAIX.cpp (+215) 
- (added) lldb/source/Host/aix/Support.cpp (+44) 
- (modified) lldb/source/Host/common/GetOptInc.cpp (+1-1) 
- (modified) lldb/source/Host/common/Host.cpp (+174-6) 
- (added) lldb/source/Host/common/LICENSE.aix-netbsd.txt (+125) 
- (modified) lldb/source/Host/common/XML.cpp (+3) 
- (modified) lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp (+2) 
- (modified) lldb/source/Host/posix/FileSystemPosix.cpp (+2) 
- (modified) lldb/source/Host/posix/MainLoopPosix.cpp (+17) 
- (modified) lldb/source/Host/posix/ProcessLauncherPosixFork.cpp (+5) 
- (modified) lldb/source/Initialization/CMakeLists.txt (+1-1) 
- (modified) lldb/source/Initialization/SystemInitializerCommon.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp (+130-1) 
- (modified) lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.h (+6) 
- (added) lldb/source/Plugins/DynamicLoader/AIX-DYLD/CMakeLists.txt (+11) 
- (added) lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.cpp 
(+272) 
- (added) lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.h 
(+55) 
- (modified) lldb/source/Plugins/DynamicLoader/CMakeLists.txt (+1) 
- (modified) 
lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp 
(+2-2) 
- (modified) 
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp (+1-1) 
- (modified) lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.cpp 
(+193-3) 
- (modified) lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.h 
(+14) 
- (modified) 
lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/InstrumentationRuntimeMainThreadChecker.cpp
 (+1-1) 
- (modified) 
lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp 
(+7-7) 
- (modified) 
lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp
 (+1-1) 
- (modified) lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp (+4) 
- (modified) lldb/source/Plugins/Language/ObjC/Cocoa.cpp (+2) 
- (modified) lldb/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp 
(+1-1) 
- (modified) 
lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp 
(+1-1) 
- (added) lldb/source/Plugins/ObjectContainer/Big-Archive/CMakeLists.txt (+10) 
- (added) 
lldb/source/Plugins/ObjectContainer/Big-Archive/ObjectContainerBigArchive.cpp 
(+522) 
- (added) 
lldb/source/Plugins/ObjectContainer/Big-Archive/ObjectConta

[clang] [lldb] [llvm] Extending LLDB to work on AIX (PR #102601)

2024-08-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Dhruv-Srivastava-IBM)


Changes

We have Implemented the necessary code changes required to run LLDB on AIX. 
This PR is for discussion as asked in #101657
With this PR, we request your inputs and feedback about our code changes. 


---

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


128 Files Affected:

- (modified) clang/lib/CodeGen/CGObjCMac.cpp (+5-1) 
- (modified) lldb/CMakeLists.txt (+4) 
- (added) lldb/NOTICE.TXT (+7) 
- (modified) lldb/cmake/modules/LLDBConfig.cmake (+1-1) 
- (modified) lldb/include/lldb/Core/Module.h (+3) 
- (modified) lldb/include/lldb/Core/ModuleSpec.h (+21-2) 
- (modified) lldb/include/lldb/Host/HostGetOpt.h (+1-1) 
- (modified) lldb/include/lldb/Host/HostInfo.h (+3) 
- (modified) lldb/include/lldb/Host/HostInfoBase.h (+1-1) 
- (modified) lldb/include/lldb/Host/XML.h (+5) 
- (added) lldb/include/lldb/Host/aix/AbstractSocket.h (+25) 
- (added) lldb/include/lldb/Host/aix/Host.h (+22) 
- (added) lldb/include/lldb/Host/aix/HostInfoAIX.h (+42) 
- (added) lldb/include/lldb/Host/aix/Ptrace.h (+62) 
- (added) lldb/include/lldb/Host/aix/Support.h (+29) 
- (added) lldb/include/lldb/Host/aix/Uio.h (+23) 
- (modified) lldb/include/lldb/Host/common/GetOptInc.h (+3-3) 
- (modified) lldb/include/lldb/Symbol/ObjectFile.h (+5) 
- (modified) lldb/include/lldb/Target/ABI.h (+6) 
- (modified) lldb/include/lldb/Target/DynamicLoader.h (+6) 
- (modified) lldb/include/lldb/Target/Process.h (+14) 
- (modified) lldb/include/lldb/Target/RegisterContextUnwind.h (+4) 
- (modified) lldb/include/lldb/Target/ThreadPlanCallFunction.h (+6) 
- (modified) lldb/include/lldb/Utility/StringExtractorGDBRemote.h (+1) 
- (modified) lldb/include/lldb/lldb-private-enumerations.h (+1) 
- (modified) lldb/source/API/CMakeLists.txt (+108) 
- (modified) lldb/source/API/SBBreakpoint.cpp (+3-3) 
- (modified) lldb/source/API/SBBreakpointLocation.cpp (+3-3) 
- (modified) lldb/source/API/SBBreakpointName.cpp (+2-2) 
- (modified) lldb/source/Core/DynamicLoader.cpp (+10) 
- (modified) lldb/source/Core/Mangled.cpp (+2) 
- (modified) lldb/source/Core/Module.cpp (+12) 
- (modified) lldb/source/Core/Section.cpp (+4) 
- (modified) lldb/source/Expression/DWARFExpression.cpp (+5-5) 
- (modified) lldb/source/Host/CMakeLists.txt (+13) 
- (added) lldb/source/Host/aix/AbstractSocket.cpp (+21) 
- (added) lldb/source/Host/aix/Host.cpp (+304) 
- (added) lldb/source/Host/aix/HostInfoAIX.cpp (+215) 
- (added) lldb/source/Host/aix/Support.cpp (+44) 
- (modified) lldb/source/Host/common/GetOptInc.cpp (+1-1) 
- (modified) lldb/source/Host/common/Host.cpp (+174-6) 
- (added) lldb/source/Host/common/LICENSE.aix-netbsd.txt (+125) 
- (modified) lldb/source/Host/common/XML.cpp (+3) 
- (modified) lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp (+2) 
- (modified) lldb/source/Host/posix/FileSystemPosix.cpp (+2) 
- (modified) lldb/source/Host/posix/MainLoopPosix.cpp (+17) 
- (modified) lldb/source/Host/posix/ProcessLauncherPosixFork.cpp (+5) 
- (modified) lldb/source/Initialization/CMakeLists.txt (+1-1) 
- (modified) lldb/source/Initialization/SystemInitializerCommon.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp (+130-1) 
- (modified) lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.h (+6) 
- (added) lldb/source/Plugins/DynamicLoader/AIX-DYLD/CMakeLists.txt (+11) 
- (added) lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.cpp 
(+272) 
- (added) lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.h 
(+55) 
- (modified) lldb/source/Plugins/DynamicLoader/CMakeLists.txt (+1) 
- (modified) 
lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp 
(+2-2) 
- (modified) 
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp (+1-1) 
- (modified) lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.cpp 
(+193-3) 
- (modified) lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.h 
(+14) 
- (modified) 
lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/InstrumentationRuntimeMainThreadChecker.cpp
 (+1-1) 
- (modified) 
lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp 
(+7-7) 
- (modified) 
lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp
 (+1-1) 
- (modified) lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp (+4) 
- (modified) lldb/source/Plugins/Language/ObjC/Cocoa.cpp (+2) 
- (modified) lldb/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp 
(+1-1) 
- (modified) 
lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp 
(+1-1) 
- (added) lldb/source/Plugins/ObjectContainer/Big-Archive/CMakeLists.txt (+10) 
- (added) 
lldb/source/Plugins/ObjectContainer/Big-Archive/ObjectContainerBigArchive.cpp 
(+522) 
- (added) 
lldb/source/Plugins/ObjectContainer/Big-Archive/ObjectContainerBigArchive.h 
(+177) 
- (modified) lldb/source/

[clang] [clang] Implement CWG2627 Bit-fields and narrowing conversions (PR #78112)

2024-08-09 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

DR test part looks good.

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


[clang] [lldb] [llvm] Extending LLDB to work on AIX (PR #102601)

2024-08-09 Thread via cfe-commits

https://github.com/Dhruv-Srivastava-IBM edited 
https://github.com/llvm/llvm-project/pull/102601
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] clang/csa: add initial support for builtin overflow (PR #102602)

2024-08-09 Thread Pavel Skripkin via cfe-commits

https://github.com/pskrgag created 
https://github.com/llvm/llvm-project/pull/102602

Add basic support for `builtin_*_overflow`  primitives.
 
These helps a lot for checking custom calloc-like functions with inlinable 
body. Without such support code like

```c
#include 
#include 

static void *myMalloc(size_t a1, size_t a2)
{
size_t res;

if (__builtin_smul_overflow(a1, a2, &res))
return NULL;
return malloc(res);
}

void test(void)
{
char *ptr = myMalloc(10, 1);
ptr[20] = 10;
}


does not trigger any warnings.

>From 3e0fcffa8fbea5f89ab927fd897c451bcafd8e5e Mon Sep 17 00:00:00 2001
From: Pavel Skripkin 
Date: Fri, 9 Aug 2024 14:37:47 +0300
Subject: [PATCH] clang/csa: add initial support for builtin overflow

---
 .../Checkers/BuiltinFunctionChecker.cpp   | 124 +-
 clang/test/Analysis/builtin_overflow.c|  65 +
 .../test/Analysis/out-of-bounds-diagnostics.c |  17 +++
 3 files changed, 204 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Analysis/builtin_overflow.c

diff --git a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
index b198b1c2ff4d11..0c8b9fa3d947b0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -21,16 +21,67 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 
 using namespace clang;
 using namespace ento;
 
 namespace {
 
+QualType getOverflowBuiltinResultType(const CallEvent &Call) {
+  assert(Call.getNumArgs() == 3);
+
+  return Call.getArgExpr(2)->getType()->getPointeeType();
+}
+
+QualType getOverflowBuiltinResultType(const CallEvent &Call, CheckerContext &C,
+  unsigned BI) {
+  assert(Call.getNumArgs() == 3);
+
+  ASTContext &Ast = C.getASTContext();
+
+  switch (BI) {
+  case Builtin::BI__builtin_smul_overflow:
+  case Builtin::BI__builtin_ssub_overflow:
+  case Builtin::BI__builtin_sadd_overflow:
+return Ast.IntTy;
+  case Builtin::BI__builtin_smull_overflow:
+  case Builtin::BI__builtin_ssubl_overflow:
+  case Builtin::BI__builtin_saddl_overflow:
+return Ast.LongTy;
+  case Builtin::BI__builtin_smulll_overflow:
+  case Builtin::BI__builtin_ssubll_overflow:
+  case Builtin::BI__builtin_saddll_overflow:
+return Ast.LongLongTy;
+  case Builtin::BI__builtin_umul_overflow:
+  case Builtin::BI__builtin_usub_overflow:
+  case Builtin::BI__builtin_uadd_overflow:
+return Ast.UnsignedIntTy;
+  case Builtin::BI__builtin_umull_overflow:
+  case Builtin::BI__builtin_usubl_overflow:
+  case Builtin::BI__builtin_uaddl_overflow:
+return Ast.UnsignedLongTy;
+  case Builtin::BI__builtin_umulll_overflow:
+  case Builtin::BI__builtin_usubll_overflow:
+  case Builtin::BI__builtin_uaddll_overflow:
+return Ast.UnsignedLongLongTy;
+  case Builtin::BI__builtin_mul_overflow:
+  case Builtin::BI__builtin_sub_overflow:
+  case Builtin::BI__builtin_add_overflow:
+return getOverflowBuiltinResultType(Call);
+  default:
+assert(false && "Unknown overflow builtin");
+  }
+}
+
 class BuiltinFunctionChecker : public Checker {
 public:
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
+  void HandleOverflowBuiltin(const CallEvent &Call, CheckerContext &C,
+ BinaryOperator::Opcode Op,
+ QualType ResultType) const;
 
 private:
   // From: clang/include/clang/Basic/Builtins.def
@@ -50,6 +101,44 @@ class BuiltinFunctionChecker : public Checker {
 
 } // namespace
 
+void BuiltinFunctionChecker::HandleOverflowBuiltin(const CallEvent &Call,
+   CheckerContext &C,
+   BinaryOperator::Opcode Op,
+   QualType ResultType) const {
+  // All __builtin_*_overflow functions take 3 argumets.
+  assert(Call.getNumArgs() == 3);
+
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  const Expr *CE = Call.getOriginExpr();
+
+  SVal Arg1 = Call.getArgSVal(0);
+  SVal Arg2 = Call.getArgSVal(1);
+
+  SVal RetVal = SVB.evalBinOp(State, Op, Arg1, Arg2, ResultType);
+
+  // TODO: Handle overflows with values that known to overflow. Like INT_MAX + 
1
+  // should not produce state for non-overflow case and threat it as
+  // unreachable.
+
+  // Handle non-overflow case.
+  {
+ProgramStateRef StateSuccess =
+State->BindExpr(CE, C.getLocationContext(), SVB.makeTruthVal(false));
+
+if (auto L = Call.getArgSVal(2).getAs())
+ 

[clang] [clang] [Static analyzer]: add initial support for builtin overflow (PR #102602)

2024-08-09 Thread Pavel Skripkin via cfe-commits

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


[clang] [clang] [Static analyzer]: add initial support for builtin overflow (PR #102602)

2024-08-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Pavel Skripkin (pskrgag)


Changes

Add basic support for `builtin_*_overflow`  primitives.
 
These helps a lot for checking custom calloc-like functions with inlinable 
body. Without such support code like

```c
#include 
#include 

static void *myMalloc(size_t a1, size_t a2)
{
size_t res;

if (__builtin_smul_overflow(a1, a2, &res))
return NULL;
return malloc(res);
}

void test(void)
{
char *ptr = myMalloc(10, 1);
ptr[20] = 10;
}


does not trigger any warnings.

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


3 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp 
(+122-2) 
- (added) clang/test/Analysis/builtin_overflow.c (+65) 
- (modified) clang/test/Analysis/out-of-bounds-diagnostics.c (+17) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
index b198b1c2ff4d11..0c8b9fa3d947b0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -21,16 +21,67 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 
 using namespace clang;
 using namespace ento;
 
 namespace {
 
+QualType getOverflowBuiltinResultType(const CallEvent &Call) {
+  assert(Call.getNumArgs() == 3);
+
+  return Call.getArgExpr(2)->getType()->getPointeeType();
+}
+
+QualType getOverflowBuiltinResultType(const CallEvent &Call, CheckerContext &C,
+  unsigned BI) {
+  assert(Call.getNumArgs() == 3);
+
+  ASTContext &Ast = C.getASTContext();
+
+  switch (BI) {
+  case Builtin::BI__builtin_smul_overflow:
+  case Builtin::BI__builtin_ssub_overflow:
+  case Builtin::BI__builtin_sadd_overflow:
+return Ast.IntTy;
+  case Builtin::BI__builtin_smull_overflow:
+  case Builtin::BI__builtin_ssubl_overflow:
+  case Builtin::BI__builtin_saddl_overflow:
+return Ast.LongTy;
+  case Builtin::BI__builtin_smulll_overflow:
+  case Builtin::BI__builtin_ssubll_overflow:
+  case Builtin::BI__builtin_saddll_overflow:
+return Ast.LongLongTy;
+  case Builtin::BI__builtin_umul_overflow:
+  case Builtin::BI__builtin_usub_overflow:
+  case Builtin::BI__builtin_uadd_overflow:
+return Ast.UnsignedIntTy;
+  case Builtin::BI__builtin_umull_overflow:
+  case Builtin::BI__builtin_usubl_overflow:
+  case Builtin::BI__builtin_uaddl_overflow:
+return Ast.UnsignedLongTy;
+  case Builtin::BI__builtin_umulll_overflow:
+  case Builtin::BI__builtin_usubll_overflow:
+  case Builtin::BI__builtin_uaddll_overflow:
+return Ast.UnsignedLongLongTy;
+  case Builtin::BI__builtin_mul_overflow:
+  case Builtin::BI__builtin_sub_overflow:
+  case Builtin::BI__builtin_add_overflow:
+return getOverflowBuiltinResultType(Call);
+  default:
+assert(false && "Unknown overflow builtin");
+  }
+}
+
 class BuiltinFunctionChecker : public Checker {
 public:
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
+  void HandleOverflowBuiltin(const CallEvent &Call, CheckerContext &C,
+ BinaryOperator::Opcode Op,
+ QualType ResultType) const;
 
 private:
   // From: clang/include/clang/Basic/Builtins.def
@@ -50,6 +101,44 @@ class BuiltinFunctionChecker : public Checker {
 
 } // namespace
 
+void BuiltinFunctionChecker::HandleOverflowBuiltin(const CallEvent &Call,
+   CheckerContext &C,
+   BinaryOperator::Opcode Op,
+   QualType ResultType) const {
+  // All __builtin_*_overflow functions take 3 argumets.
+  assert(Call.getNumArgs() == 3);
+
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  const Expr *CE = Call.getOriginExpr();
+
+  SVal Arg1 = Call.getArgSVal(0);
+  SVal Arg2 = Call.getArgSVal(1);
+
+  SVal RetVal = SVB.evalBinOp(State, Op, Arg1, Arg2, ResultType);
+
+  // TODO: Handle overflows with values that known to overflow. Like INT_MAX + 
1
+  // should not produce state for non-overflow case and threat it as
+  // unreachable.
+
+  // Handle non-overflow case.
+  {
+ProgramStateRef StateSuccess =
+State->BindExpr(CE, C.getLocationContext(), SVB.makeTruthVal(false));
+
+if (auto L = Call.getArgSVal(2).getAs())
+  StateSuccess = StateSuccess->bindLoc(*L, RetVal, C.getLocationContext());
+
+C.addTransition(StateSuccess);
+  }
+
+  // Handle overflow case

[clang] [clang] [Static analyzer]: add initial support for builtin overflow (PR #102602)

2024-08-09 Thread Pavel Skripkin via cfe-commits


@@ -50,6 +101,44 @@ class BuiltinFunctionChecker : public Checker {
 
 } // namespace
 
+void BuiltinFunctionChecker::HandleOverflowBuiltin(const CallEvent &Call,
+   CheckerContext &C,
+   BinaryOperator::Opcode Op,
+   QualType ResultType) const {
+  // All __builtin_*_overflow functions take 3 argumets.
+  assert(Call.getNumArgs() == 3);
+
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  const Expr *CE = Call.getOriginExpr();
+
+  SVal Arg1 = Call.getArgSVal(0);
+  SVal Arg2 = Call.getArgSVal(1);
+
+  SVal RetVal = SVB.evalBinOp(State, Op, Arg1, Arg2, ResultType);
+
+  // TODO: Handle overflows with values that known to overflow. Like INT_MAX + 
1
+  // should not produce state for non-overflow case and threat it as

pskrgag wrote:

I didn't find a way to check this. We could do old-style thing like `res < 0 ? 
lhs > rhs : lhs < rhs` , but I guess, `SVB` should take care of it?

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


[clang] [clang] [Static analyzer]: add initial support for builtin overflow (PR #102602)

2024-08-09 Thread Pavel Skripkin via cfe-commits

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


[clang-tools-extra] [clangd] support the zig c++ compiler wrapper (PR #100759)

2024-08-09 Thread Duncan Ogilvie via cfe-commits

mrexodia wrote:

@kazutakahirata @kadircet @sam-mccall it looks like you were recently touching 
this file, any chance for a review?

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


[clang] [lld] [llvm] Embed the command line arguments during LTO (PR #79390)

2024-08-09 Thread Duncan Ogilvie via cfe-commits

https://github.com/mrexodia updated 
https://github.com/llvm/llvm-project/pull/79390

>From e6737b6e65669160868a85b8a870fe6fd70b94b0 Mon Sep 17 00:00:00 2001
From: Duncan Ogilvie 
Date: Thu, 25 Jan 2024 00:08:49 +0100
Subject: [PATCH] Embed the command line arguments during LTO

---
 clang/lib/CodeGen/BackendUtil.cpp|  3 +-
 lld/COFF/Driver.cpp  |  1 +
 lld/COFF/LTO.cpp |  3 +-
 lld/Common/CommonLinkerContext.cpp   |  9 ++
 lld/ELF/Driver.cpp   |  1 +
 lld/ELF/LTO.cpp  |  3 +-
 lld/MachO/Driver.cpp |  1 +
 lld/MachO/LTO.cpp|  3 +-
 lld/MinGW/Driver.cpp |  1 +
 lld/include/lld/Common/CommonLinkerContext.h |  3 ++
 lld/wasm/Driver.cpp  |  1 +
 lld/wasm/LTO.cpp |  2 ++
 llvm/include/llvm/LTO/Config.h   |  2 +-
 llvm/include/llvm/LTO/LTOBackend.h   |  6 ++--
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp| 14 ++
 llvm/lib/LTO/LTO.cpp |  3 +-
 llvm/lib/LTO/LTOBackend.cpp  | 29 ++--
 llvm/lib/LTO/LTOCodeGenerator.cpp|  3 +-
 18 files changed, 52 insertions(+), 36 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index e765bbf637a661..e4f597798b06c8 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1222,6 +1222,7 @@ static void runThinLTOBackend(
   Conf.CPU = TOpts.CPU;
   Conf.CodeModel = getCodeModel(CGOpts);
   Conf.MAttrs = TOpts.Features;
+  Conf.EmbedCmdArgs = CGOpts.CmdArgs;
   Conf.RelocModel = CGOpts.RelocationModel;
   std::optional OptLevelOrNone =
   CodeGenOpt::getLevel(CGOpts.OptimizationLevel);
@@ -1283,7 +1284,7 @@ static void runThinLTOBackend(
   if (Error E =
   thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
   ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
-  /* ModuleMap */ nullptr, CGOpts.CmdArgs)) {
+  /* ModuleMap */ nullptr)) {
 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
   errs() << "Error running ThinLTO backend: " << EIB.message() << '\n';
 });
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 9e28b1c50be504..cc656f5188fea8 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1439,6 +1439,7 @@ void LinkerDriver::linkerMain(ArrayRef 
argsArr) {
   // Parse command line options.
   ArgParser parser(ctx);
   opt::InputArgList args = parser.parse(argsArr);
+  ctx.storeCmdArgs(args);
 
   // Initialize time trace profiler.
   config->timeTraceEnabled = args.hasArg(OPT_time_trace_eq);
diff --git a/lld/COFF/LTO.cpp b/lld/COFF/LTO.cpp
index 5c881bc01c663d..a0b1af33eb8f00 100644
--- a/lld/COFF/LTO.cpp
+++ b/lld/COFF/LTO.cpp
@@ -52,8 +52,7 @@ lto::Config BitcodeCompiler::createConfig() {
   lto::Config c;
   c.Options = initTargetOptionsFromCodeGenFlags();
   c.Options.EmitAddrsig = true;
-  for (StringRef C : ctx.config.mllvmOpts)
-c.MllvmArgs.emplace_back(C.str());
+  c.EmbedCmdArgs = context().cmdArgs;
 
   // Always emit a section per function/datum with LTO. LLVM LTO should get 
most
   // of the benefit of linker GC, but there are still opportunities for ICF.
diff --git a/lld/Common/CommonLinkerContext.cpp 
b/lld/Common/CommonLinkerContext.cpp
index 12f56bc10ec963..57aae8fd0a703d 100644
--- a/lld/Common/CommonLinkerContext.cpp
+++ b/lld/Common/CommonLinkerContext.cpp
@@ -37,6 +37,15 @@ CommonLinkerContext::~CommonLinkerContext() {
   lctx = nullptr;
 }
 
+void CommonLinkerContext::storeCmdArgs(const llvm::opt::ArgList &args) {
+  cmdArgs.clear();
+  for (const llvm::opt::Arg *arg : args) {
+StringRef str(args.getArgString(arg->getIndex()));
+cmdArgs.insert(cmdArgs.end(), str.begin(), str.end());
+cmdArgs.push_back('\0');
+  }
+}
+
 CommonLinkerContext &lld::commonContext() {
   assert(lctx);
   return *lctx;
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 8aa2380ba3a177..9623a35549537e 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -613,6 +613,7 @@ constexpr const char *saveTempsValues[] = {
 void LinkerDriver::linkerMain(ArrayRef argsArr) {
   ELFOptTable parser;
   opt::InputArgList args = parser.parse(argsArr.slice(1));
+  context().storeCmdArgs(args);
 
   // Interpret these flags early because error()/warn() depend on them.
   errorHandler().errorLimit = args::getInteger(args, OPT_error_limit, 20);
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index 935d0a9eab9ee0..7d453cd187b9b4 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -54,8 +54,7 @@ static lto::Config createConfig() {
   // LLD supports the new relocations and address-significance tables.
   c.Options = initTargetOptionsFromCodeGenFlags();
   c.Options.EmitAddrsig = true;
-  for (StringRef C : config->mllv

[clang] [clang] Avoid triggering vtable instantiation for C++23 constexpr dtor (PR #102605)

2024-08-09 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/102605

In C++23 anything can be constexpr, including a dtor of a class whose members 
and bases don't have constexpr dtors. Avoid early triggering of vtable 
instantiation int this case.

Fixes https://github.com/llvm/llvm-project/issues/102293

>From eb97afb9cade7b496ec55acdd4f02a915c4a4955 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Fri, 9 Aug 2024 05:20:37 -0700
Subject: [PATCH] [clang] Avoid triggering vtable instantiation for C++23
 constexpr dtor

In C++23 anything can be constexpr, including a dtor of a class whose
members and bases don't have constexpr dtors. Avoid early triggering of
vtable instantiation int this case.

Fixes https://github.com/llvm/llvm-project/issues/102293
---
 clang/lib/Sema/SemaDeclCXX.cpp  | 28 +++-
 clang/test/SemaCXX/gh102293.cpp | 22 ++
 2 files changed, 49 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/gh102293.cpp

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index b07e555afcaccf..63d2131acdd650 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7042,12 +7042,38 @@ void Sema::CheckCompletedCXXClass(Scope *S, 
CXXRecordDecl *Record) {
   }
 }
 
+bool EffectivelyConstexprDestructor = true;
+// Avoid triggering vtable instantiation due to a dtor that is not
+// "effectively constexpr" for better compatibility.
+if (isa(M)) {
+  auto Check = [](QualType T, auto &&Check) -> bool {
+const CXXRecordDecl *RD =
+T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();
+if (!RD || !RD->isCompleteDefinition())
+  return true;
+
+if (!RD->hasConstexprDestructor())
+  return false;
+
+for (const CXXBaseSpecifier &B : RD->bases())
+  if (!Check(B.getType(), Check))
+return false;
+for (const FieldDecl *FD : RD->fields())
+  if (!Check(FD->getType(), Check))
+return false;
+return true;
+  };
+  EffectivelyConstexprDestructor =
+  Check(QualType(Record->getTypeForDecl(), 0), Check);
+}
+
 // Define defaulted constexpr virtual functions that override a base class
 // function right away.
 // FIXME: We can defer doing this until the vtable is marked as used.
 if (CSM != CXXSpecialMemberKind::Invalid && !M->isDeleted() &&
 M->isDefaulted() && M->isConstexpr() && M->size_overridden_methods())
-  DefineDefaultedFunction(*this, M, M->getLocation());
+  if (EffectivelyConstexprDestructor)
+DefineDefaultedFunction(*this, M, M->getLocation());
 
 if (!Incomplete)
   CheckCompletedMemberFunction(M);
diff --git a/clang/test/SemaCXX/gh102293.cpp b/clang/test/SemaCXX/gh102293.cpp
new file mode 100644
index 00..30629fc03bf6a9
--- /dev/null
+++ b/clang/test/SemaCXX/gh102293.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template  static void destroy() {
+T t;
+++t;
+}
+
+struct Incomplete;
+
+template  struct HasD {
+  ~HasD() { destroy(); }
+};
+
+struct HasVT {
+  virtual ~HasVT();
+};
+
+struct S : HasVT {
+  HasD<> v;
+};
+

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


[clang] [clang] Avoid triggering vtable instantiation for C++23 constexpr dtor (PR #102605)

2024-08-09 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

I'm really in doubts that this is actually correct and useful...

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


[clang] [clang] Avoid triggering vtable instantiation for C++23 constexpr dtor (PR #102605)

2024-08-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mariya Podchishchaeva (Fznamznon)


Changes

In C++23 anything can be constexpr, including a dtor of a class whose members 
and bases don't have constexpr dtors. Avoid early triggering of vtable 
instantiation int this case.

Fixes https://github.com/llvm/llvm-project/issues/102293

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+27-1) 
- (added) clang/test/SemaCXX/gh102293.cpp (+22) 


``diff
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index b07e555afcaccf..63d2131acdd650 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7042,12 +7042,38 @@ void Sema::CheckCompletedCXXClass(Scope *S, 
CXXRecordDecl *Record) {
   }
 }
 
+bool EffectivelyConstexprDestructor = true;
+// Avoid triggering vtable instantiation due to a dtor that is not
+// "effectively constexpr" for better compatibility.
+if (isa(M)) {
+  auto Check = [](QualType T, auto &&Check) -> bool {
+const CXXRecordDecl *RD =
+T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();
+if (!RD || !RD->isCompleteDefinition())
+  return true;
+
+if (!RD->hasConstexprDestructor())
+  return false;
+
+for (const CXXBaseSpecifier &B : RD->bases())
+  if (!Check(B.getType(), Check))
+return false;
+for (const FieldDecl *FD : RD->fields())
+  if (!Check(FD->getType(), Check))
+return false;
+return true;
+  };
+  EffectivelyConstexprDestructor =
+  Check(QualType(Record->getTypeForDecl(), 0), Check);
+}
+
 // Define defaulted constexpr virtual functions that override a base class
 // function right away.
 // FIXME: We can defer doing this until the vtable is marked as used.
 if (CSM != CXXSpecialMemberKind::Invalid && !M->isDeleted() &&
 M->isDefaulted() && M->isConstexpr() && M->size_overridden_methods())
-  DefineDefaultedFunction(*this, M, M->getLocation());
+  if (EffectivelyConstexprDestructor)
+DefineDefaultedFunction(*this, M, M->getLocation());
 
 if (!Incomplete)
   CheckCompletedMemberFunction(M);
diff --git a/clang/test/SemaCXX/gh102293.cpp b/clang/test/SemaCXX/gh102293.cpp
new file mode 100644
index 00..30629fc03bf6a9
--- /dev/null
+++ b/clang/test/SemaCXX/gh102293.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template  static void destroy() {
+T t;
+++t;
+}
+
+struct Incomplete;
+
+template  struct HasD {
+  ~HasD() { destroy(); }
+};
+
+struct HasVT {
+  virtual ~HasVT();
+};
+
+struct S : HasVT {
+  HasD<> v;
+};
+

``




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


[clang] [llvm] [mlir] [polly] [clang] Generate nuw GEPs for struct member accesses (PR #99538)

2024-08-09 Thread Hari Limaye via cfe-commits

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


[clang] [clang] Support --sysroot= for ${arch}-windows-msvc targets (PR #96417)

2024-08-09 Thread Godvin Ouseph via cfe-commits

godvino wrote:

This could close #54868 that I had opened a while back to support cross 
compiling using clang with [xwin](https://github.com/Jake-Shadle/xwin/).

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


[clang] [Arm][AArch64][Clang] Respect function's branch protection attributes. (PR #101978)

2024-08-09 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/101978

>From 4afadb9122c982c63f2b067661548a2c063590a5 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Mon, 5 Aug 2024 13:01:06 +0200
Subject: [PATCH 1/2] [Arm][AArch64][Clang] Respect function's branch
 protection attributes.

Default attributes assigned to all functions according to the command line
parameters. Some functions might have their own attributes and we need to set
or remove attributes accordingly.
---
 clang/lib/CodeGen/TargetInfo.cpp  | 25 ---
 clang/lib/CodeGen/TargetInfo.h|  3 +++
 .../CodeGen/aarch64-branch-protection-attr.c  | 13 +-
 .../CodeGen/arm-branch-protection-attr-1.c|  6 +
 4 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp
index 38faa50cf19cf2..ec05db0ecfac58 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -209,9 +209,28 @@ llvm::Value *TargetCodeGenInfo::createEnqueuedBlockKernel(
 
 void TargetCodeGenInfo::setBranchProtectionFnAttributes(
 const TargetInfo::BranchProtectionInfo &BPI, llvm::Function &F) {
-  llvm::AttrBuilder FuncAttrs(F.getContext());
-  setBranchProtectionFnAttributes(BPI, FuncAttrs);
-  F.addFnAttrs(FuncAttrs);
+  if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
+F.addFnAttr("sign-return-address", BPI.getSignReturnAddrStr());
+F.addFnAttr("sign-return-address-key", BPI.getSignKeyStr());
+  } else {
+if (F.hasFnAttribute("sign-return-address"))
+  F.removeFnAttr("sign-return-address");
+if (F.hasFnAttribute("sign-return-address-key"))
+  F.removeFnAttr("sign-return-address-key");
+  }
+
+  auto AddRemoveAttributeAsSet = [&](bool Set, const StringRef &ModAttr) {
+if (Set)
+  F.addFnAttr(ModAttr);
+else if (F.hasFnAttribute(ModAttr))
+  F.removeFnAttr(ModAttr);
+  };
+
+  AddRemoveAttributeAsSet(BPI.BranchTargetEnforcement,
+  "branch-target-enforcement");
+  AddRemoveAttributeAsSet(BPI.BranchProtectionPAuthLR,
+  "branch-protection-pauth-lr");
+  AddRemoveAttributeAsSet(BPI.GuardedControlStack, "guarded-control-stack");
 }
 
 void TargetCodeGenInfo::setBranchProtectionFnAttributes(
diff --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h
index 8f17c053f4783f..639717bd9580d0 100644
--- a/clang/lib/CodeGen/TargetInfo.h
+++ b/clang/lib/CodeGen/TargetInfo.h
@@ -418,10 +418,13 @@ class TargetCodeGenInfo {
 return nullptr;
   }
 
+  // Set the Branch Protection Attributes of the Function accordingly to the
+  // BPI. Might remove attributes if contradicts with the pass request.
   static void
   setBranchProtectionFnAttributes(const TargetInfo::BranchProtectionInfo &BPI,
   llvm::Function &F);
 
+  // Add the Branch Protection Attributes of the FuncAttrs.
   static void
   setBranchProtectionFnAttributes(const TargetInfo::BranchProtectionInfo &BPI,
   llvm::AttrBuilder &FuncAttrs);
diff --git a/clang/test/CodeGen/aarch64-branch-protection-attr.c 
b/clang/test/CodeGen/aarch64-branch-protection-attr.c
index e7ae7fb1570c95..c66bce1bee6d36 100644
--- a/clang/test/CodeGen/aarch64-branch-protection-attr.c
+++ b/clang/test/CodeGen/aarch64-branch-protection-attr.c
@@ -1,6 +1,18 @@
 // REQUIRES: aarch64-registered-target
 // RUN: %clang_cc1 -triple aarch64 -emit-llvm  -target-cpu generic 
-target-feature +v8.5a %s -o - \
 // RUN:   | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple aarch64 -emit-llvm  -target-cpu generic 
-target-feature +v8.5a -mbranch-target-enforce %s -o - \
+// RUN:   | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple aarch64 -emit-llvm  -target-cpu generic 
-target-feature +v8.5a -mguarded-control-stack %s -o - \
+// RUN:   | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple aarch64 -emit-llvm  -target-cpu generic 
-target-feature +v8.5a -msign-return-address=non-leaf 
-msign-return-address-key=a_key %s -o - \
+// RUN:   | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple aarch64 -emit-llvm  -target-cpu generic 
-target-feature +v8.5a -msign-return-address=all 
-msign-return-address-key=b_key %s -o - \
+// RUN:   | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple aarch64 -emit-llvm  -target-cpu generic 
-target-feature +v8.5a -mbranch-protection-pauth-lr -msign-return-address=all 
-msign-return-address-key=a_key %s -o - \
+// RUN:   | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple aarch64 -emit-llvm  -target-cpu generic 
-target-feature +v8.5a -mguarded-control-stack -mbranch-target-enforce 
-mbranch-protection-pauth-lr -msign-return-address=

[clang] [RFC] Add clang atomic control options and pragmas (PR #102569)

2024-08-09 Thread Yaxun Liu via cfe-commits

yxsamliu wrote:

> Thank you for the patch, but RFCs for Clang should be published in 
> https://discourse.llvm.org/c/clang/6. PRs doesn't have the visibility we want 
> RFCs to have.

Discourse topic created: 
https://discourse.llvm.org/t/rfc-add-clang-atomic-control-options-and-pragmas/80641.
 Thanks.

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


[clang] [RFC] Add clang atomic control options and pragmas (PR #102569)

2024-08-09 Thread Yaxun Liu via cfe-commits

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


[clang] [Arm][AArch64][Clang] Respect function's branch protection attributes. (PR #101978)

2024-08-09 Thread Daniel Kiss via cfe-commits


@@ -209,9 +209,28 @@ llvm::Value *TargetCodeGenInfo::createEnqueuedBlockKernel(
 
 void TargetCodeGenInfo::setBranchProtectionFnAttributes(
 const TargetInfo::BranchProtectionInfo &BPI, llvm::Function &F) {
-  llvm::AttrBuilder FuncAttrs(F.getContext());
-  setBranchProtectionFnAttributes(BPI, FuncAttrs);
-  F.addFnAttrs(FuncAttrs);
+  if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
+F.addFnAttr("sign-return-address", BPI.getSignReturnAddrStr());
+F.addFnAttr("sign-return-address-key", BPI.getSignKeyStr());
+  } else {
+if (F.hasFnAttribute("sign-return-address"))
+  F.removeFnAttr("sign-return-address");
+if (F.hasFnAttribute("sign-return-address-key"))
+  F.removeFnAttr("sign-return-address-key");
+  }
+
+  auto AddRemoveAttributeAsSet = [&](bool Set, const StringRef &ModAttr) {
+if (Set)
+  F.addFnAttr(ModAttr);
+else if (F.hasFnAttribute(ModAttr))
+  F.removeFnAttr(ModAttr);
+  };
+
+  AddRemoveAttributeAsSet(BPI.BranchTargetEnforcement,
+  "branch-target-enforcement");
+  AddRemoveAttributeAsSet(BPI.BranchProtectionPAuthLR,
+  "branch-protection-pauth-lr");
+  AddRemoveAttributeAsSet(BPI.GuardedControlStack, "guarded-control-stack");
 }
 
 void TargetCodeGenInfo::setBranchProtectionFnAttributes(

DanielKristofKiss wrote:

Thanks for the concern. I added more comments and renamed the AttrBuilder 
version to make it more distinct.

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


[clang] [clang] Implement CWG2627 Bit-fields and narrowing conversions (PR #78112)

2024-08-09 Thread via cfe-commits

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


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


[clang] 574e958 - [clang] Implement CWG2627 Bit-fields and narrowing conversions (#78112)

2024-08-09 Thread via cfe-commits

Author: Mital Ashok
Date: 2024-08-09T14:46:28+02:00
New Revision: 574e9584494cd408fb3595df9b9d52bb3e03921a

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

LOG: [clang] Implement CWG2627 Bit-fields and narrowing conversions (#78112)

https://cplusplus.github.io/CWG/issues/2627.html

It is no longer a narrowing conversion when converting a bit-field to a
type smaller than the field's declared type if the bit-field has a width
small enough to fit in the target type. This includes integral
promotions (`long long i : 8` promoted to `int` is no longer narrowing,
allowing `c.i <=> c.i`) and list-initialization (`int n{ c.i };`)

Also applies back to C++11 as this is a defect report.

Added: 
clang/test/SemaCXX/bitint-narrowing.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaOverload.cpp
clang/test/CXX/drs/cwg26xx.cpp
clang/test/Sema/constexpr.c
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7beef7be0e6a53..7a05ccf3184111 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -111,6 +111,11 @@ Resolutions to C++ Defect Reports
   Otherwise, if there is no initializer list constructor, the copy will be 
elided as if it was ``T(e)``.
   (`CWG2311: Missed case for guaranteed copy elision 
`)
 
+- Casts from a bit-field to an integral type is now not considered narrowing 
if the
+  width of the bit-field means that all potential values are in the range
+  of the target type, even if the type of the bit-field is larger.
+  (`CWG2627: Bit-fields and narrowing conversions 
`_)
+
 C Language Changes
 --
 

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 0f196ddf812fdf..52f640eb96b73b 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -489,7 +489,12 @@ NarrowingKind StandardConversionSequence::getNarrowingKind(
 
   // -- from an integer type or unscoped enumeration type to an integer type
   //that cannot represent all the values of the original type, except where
-  //the source is a constant expression and the actual value after
+  //(CWG2627) -- the source is a bit-field whose width w is less than that
+  //of its type (or, for an enumeration type, its underlying type) and the
+  //target type can represent all the values of a hypothetical extended
+  //integer type with width w and with the same signedness as the original
+  //type or
+  //-- the source is a constant expression and the actual value after
   //conversion will fit into the target type and will produce the original
   //value when converted back to the original type.
   case ICK_Integral_Conversion:
@@ -497,53 +502,80 @@ NarrowingKind 
StandardConversionSequence::getNarrowingKind(
 assert(FromType->isIntegralOrUnscopedEnumerationType());
 assert(ToType->isIntegralOrUnscopedEnumerationType());
 const bool FromSigned = FromType->isSignedIntegerOrEnumerationType();
-const unsigned FromWidth = Ctx.getIntWidth(FromType);
+unsigned FromWidth = Ctx.getIntWidth(FromType);
 const bool ToSigned = ToType->isSignedIntegerOrEnumerationType();
 const unsigned ToWidth = Ctx.getIntWidth(ToType);
 
-if (FromWidth > ToWidth ||
-(FromWidth == ToWidth && FromSigned != ToSigned) ||
-(FromSigned && !ToSigned)) {
-  // Not all values of FromType can be represented in ToType.
-  const Expr *Initializer = IgnoreNarrowingConversion(Ctx, Converted);
+constexpr auto CanRepresentAll = [](bool FromSigned, unsigned FromWidth,
+bool ToSigned, unsigned ToWidth) {
+  return (FromWidth < ToWidth + (FromSigned == ToSigned)) &&
+ (FromSigned <= ToSigned);
+};
 
-  // If it's value-dependent, we can't tell whether it's narrowing.
-  if (Initializer->isValueDependent())
-return NK_Dependent_Narrowing;
+if (CanRepresentAll(FromSigned, FromWidth, ToSigned, ToWidth))
+  return NK_Not_Narrowing;
 
-  std::optional OptInitializerValue;
-  if (!(OptInitializerValue = Initializer->getIntegerConstantExpr(Ctx))) {
-// Such conversions on variables are always narrowing.
-return NK_Variable_Narrowing;
-  }
-  llvm::APSInt &InitializerValue = *OptInitializerValue;
-  bool Narrowing = false;
-  if (FromWidth < ToWidth) {
-// Negative -> unsigned is narrowing. Otherwise, more bits is never
-// narrowing.
-if (InitializerValue.isSigned() && InitializerValue.isNegative())
-  Narrowing = true;
-  } else {
- 

[clang] [clang] Implement CWG2627 Bit-fields and narrowing conversions (PR #78112)

2024-08-09 Thread via cfe-commits

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


[clang] [clang] [Static analyzer]: add initial support for builtin overflow (PR #102602)

2024-08-09 Thread Donát Nagy via cfe-commits

https://github.com/NagyDonat commented:

Thanks for adding support for these functions! The code LGTM overall, except 
for one mostly theoretical issue (about the use of `assert`) which I described 
in an inline comment.

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


[clang] [clang] [Static analyzer]: add initial support for builtin overflow (PR #102602)

2024-08-09 Thread Donát Nagy via cfe-commits

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


[clang] [clang] [Static analyzer]: add initial support for builtin overflow (PR #102602)

2024-08-09 Thread Donát Nagy via cfe-commits


@@ -21,16 +21,67 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 
 using namespace clang;
 using namespace ento;
 
 namespace {
 
+QualType getOverflowBuiltinResultType(const CallEvent &Call) {
+  assert(Call.getNumArgs() == 3);
+
+  return Call.getArgExpr(2)->getType()->getPointeeType();
+}
+
+QualType getOverflowBuiltinResultType(const CallEvent &Call, CheckerContext &C,
+  unsigned BI) {
+  assert(Call.getNumArgs() == 3);
+
+  ASTContext &Ast = C.getASTContext();

NagyDonat wrote:

``
Checker code usually uses the name `ACtx` for 'the' `ASTContext` object, so 
consider using that here. However, `Ast` is also a completely correct name, so 
if you prefer it, feel free to keep it.
``

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


[clang] [clang] [Static analyzer]: add initial support for builtin overflow (PR #102602)

2024-08-09 Thread Donát Nagy via cfe-commits


@@ -50,6 +101,44 @@ class BuiltinFunctionChecker : public Checker {
 
 } // namespace
 
+void BuiltinFunctionChecker::HandleOverflowBuiltin(const CallEvent &Call,
+   CheckerContext &C,
+   BinaryOperator::Opcode Op,
+   QualType ResultType) const {
+  // All __builtin_*_overflow functions take 3 argumets.
+  assert(Call.getNumArgs() == 3);

NagyDonat wrote:

The use of `assert()` should be limited to situations where we realize that the 
_analyzer code_ is buggy (we reached an "impossible" situation). If the 
_analyzed code_ contains an invalid call like `__builtin_add_overflow(10, 20, 
&res, "spam")`, then the analyzer _may_ report an error, but must not crash 
with an assertion failure.

Unfortunately, this particular checker is a so-called "modeling" checker, so it 
is hidden from the user (as an undocumented implementation detail), and 
therefore it cannot create bug reports.

This means that if we encounter an invalid `__builtin_*_overflow` call, then we 
should probably just ignore it, because we should not assert and we cannot 
create a bug report. I'd assume that this is an extremely rare situation (if 
someone uses these builtin function, they're unlikely to mess up the argument 
count), so a more complex solution (e.g. introducing a new non-modeling checker 
which creates bug reports) is probably not worth the effort.

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


[clang] [clang] Avoid triggering vtable instantiation for C++23 constexpr dtor (PR #102605)

2024-08-09 Thread via cfe-commits


@@ -7042,12 +7042,38 @@ void Sema::CheckCompletedCXXClass(Scope *S, 
CXXRecordDecl *Record) {
   }
 }
 
+bool EffectivelyConstexprDestructor = true;
+// Avoid triggering vtable instantiation due to a dtor that is not
+// "effectively constexpr" for better compatibility.
+if (isa(M)) {
+  auto Check = [](QualType T, auto &&Check) -> bool {
+const CXXRecordDecl *RD =
+T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();
+if (!RD || !RD->isCompleteDefinition())
+  return true;
+
+if (!RD->hasConstexprDestructor())
+  return false;
+
+for (const CXXBaseSpecifier &B : RD->bases())
+  if (!Check(B.getType(), Check))
+return false;
+for (const FieldDecl *FD : RD->fields())
+  if (!Check(FD->getType(), Check))
+return false;
+return true;
+  };
+  EffectivelyConstexprDestructor =
+  Check(QualType(Record->getTypeForDecl(), 0), Check);
+}
+
 // Define defaulted constexpr virtual functions that override a base class
 // function right away.
 // FIXME: We can defer doing this until the vtable is marked as used.
 if (CSM != CXXSpecialMemberKind::Invalid && !M->isDeleted() &&
 M->isDefaulted() && M->isConstexpr() && M->size_overridden_methods())
-  DefineDefaultedFunction(*this, M, M->getLocation());
+  if (EffectivelyConstexprDestructor)
+DefineDefaultedFunction(*this, M, M->getLocation());

cor3ntin wrote:

you can merge the two if statements

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


  1   2   3   4   5   >