[clang] [clang] Substitute alias templates from correct context (PR #75069)

2023-12-12 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] dbf67ea - [clang] Substitute alias templates from correct context (#75069)

2023-12-12 Thread via cfe-commits

Author: Mariya Podchishchaeva
Date: 2023-12-13T08:50:43+01:00
New Revision: dbf67ea1d334d2114fe49701a8f4b8afd536e39f

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

LOG: [clang] Substitute alias templates from correct context (#75069)

Current context set to where alias was met, not where it is declared
caused incorrect access check in case alias referenced private members
of the parent class.
This is a recommit of 6b1aa31 with a slight modification in order to fix
reported regression.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaCXXScopeSpec.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/CXX/temp/temp.decls/temp.alias/p3.cpp
clang/test/SemaCXX/alias-template.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 066e4ac5b9e54b..05d59d0da264f3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -685,6 +685,9 @@ Bug Fixes in This Version
   (`#62157 `_) and
   (`#64885 `_) and
   (`#65568 `_)
+- Fixed false positive error emitted when templated alias inside a class
+  used private members of the same class.
+  Fixes (`#41693 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1d7b4c729ce84e..7e89e74733a090 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8737,7 +8737,7 @@ class Sema final {
  SourceLocation IILoc,
  bool DeducedTSTContext = true);
 
-
+  bool RebuildingTypesInCurrentInstantiation = false;
   TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
 SourceLocation Loc,
 DeclarationName Name);

diff  --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp 
b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index 44a40215b90dfb..b3b19b7ed7 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -30,6 +30,20 @@ static CXXRecordDecl *getCurrentInstantiationOf(QualType T,
 return nullptr;
 
   const Type *Ty = T->getCanonicalTypeInternal().getTypePtr();
+  if (isa(Ty)) {
+if (auto *Record = dyn_cast(CurContext)) {
+  if (isa(Record) ||
+  Record->getDescribedClassTemplate()) {
+const Type *ICNT = Record->getTypeForDecl();
+QualType Injected =
+cast(ICNT)->getInjectedSpecializationType();
+
+if (Ty == Injected->getCanonicalTypeInternal().getTypePtr())
+  return Record;
+  }
+}
+  }
+
   if (const RecordType *RecordTy = dyn_cast(Ty)) {
 CXXRecordDecl *Record = cast(RecordTy->getDecl());
 if (!Record->isDependentContext() ||
@@ -37,10 +51,12 @@ static CXXRecordDecl *getCurrentInstantiationOf(QualType T,
   return Record;
 
 return nullptr;
-  } else if (isa(Ty))
-return cast(Ty)->getDecl();
-  else
-return nullptr;
+  }
+
+  if (auto *ICNT = dyn_cast(Ty))
+return ICNT->getDecl();
+
+  return nullptr;
 }
 
 /// Compute the DeclContext that is associated with the given type.

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index f10abeaba0d451..cca7d613061564 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -39,6 +39,7 @@
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/SaveAndRestore.h"
 
 #include 
 #include 
@@ -3990,9 +3991,14 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
 if (Inst.isInvalid())
   return QualType();
 
-CanonType = SubstType(Pattern->getUnderlyingType(),
-  TemplateArgLists, AliasTemplate->getLocation(),
-  AliasTemplate->getDeclName());
+{
+  Sema::ContextRAII SavedContext(*this, Pattern->getDeclContext());
+  if (RebuildingTypesInCurrentInstantiation)
+SavedContext.pop();
+  CanonType =
+  SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
+AliasTemplate->getLocation(), 
AliasTemplate->getDeclName());
+}
 if (CanonType.isNull()) {
   // If this was enable_if and we failed to find the nested type
   // within enable_if in a SFINAE context, dig out the specific
@@ -11392,6 +11398,8 @@ TypeSourceInfo 
*Sema::RebuildTypeInCurrentInstantiat

[clang-tools-extra] [llvm] [clang] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-12-12 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] a01307a - [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (#70829)

2023-12-12 Thread via cfe-commits

Author: Mariya Podchishchaeva
Date: 2023-12-13T08:48:32+01:00
New Revision: a01307a6ee788fc6ac2e09e58f0f52e5666def86

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

LOG: [clang] Fix false positive -Wmissing-field-initializer for anonymous 
unions (#70829)

Normally warning is not reported when a field has default initializer.
Do so for anonymous unions with default initializers as well. No release
note since it is a regression in clang 18.

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

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp
clang/test/Sema/missing-field-initializers.c
clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 5ca6b232df66a5..4028b2d642b212 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -465,7 +465,8 @@ class InitListChecker {
   void FillInEmptyInitForField(unsigned Init, FieldDecl *Field,
const InitializedEntity &ParentEntity,
InitListExpr *ILE, bool &RequiresSecondPass,
-   bool FillWithNoInit = false);
+   bool FillWithNoInit = false,
+   bool WarnIfMissing = false);
   void FillInEmptyInitializations(const InitializedEntity &Entity,
   InitListExpr *ILE, bool &RequiresSecondPass,
   InitListExpr *OuterILE, unsigned OuterIndex,
@@ -654,11 +655,16 @@ void InitListChecker::FillInEmptyInitForBase(
   }
 }
 
-void InitListChecker::FillInEmptyInitForField(unsigned Init, FieldDecl *Field,
-const InitializedEntity &ParentEntity,
-  InitListExpr *ILE,
-  bool &RequiresSecondPass,
-  bool FillWithNoInit) {
+static bool hasAnyDesignatedInits(const InitListExpr *IL) {
+  return llvm::any_of(*IL, [=](const Stmt *Init) {
+return isa_and_nonnull(Init);
+  });
+}
+
+void InitListChecker::FillInEmptyInitForField(
+unsigned Init, FieldDecl *Field, const InitializedEntity &ParentEntity,
+InitListExpr *ILE, bool &RequiresSecondPass, bool FillWithNoInit,
+bool WarnIfMissing) {
   SourceLocation Loc = ILE->getEndLoc();
   unsigned NumInits = ILE->getNumInits();
   InitializedEntity MemberEntity
@@ -726,15 +732,52 @@ void InitListChecker::FillInEmptyInitForField(unsigned 
Init, FieldDecl *Field,
 
 if (hadError || VerifyOnly) {
   // Do nothing
-} else if (Init < NumInits) {
-  ILE->setInit(Init, MemberInit.getAs());
-} else if (!isa(MemberInit.get())) {
-  // Empty initialization requires a constructor call, so
-  // extend the initializer list to include the constructor
-  // call and make a note that we'll need to take another pass
-  // through the initializer list.
-  ILE->updateInit(SemaRef.Context, Init, MemberInit.getAs());
-  RequiresSecondPass = true;
+} else {
+  if (WarnIfMissing) {
+auto CheckAnonMember = [&](const FieldDecl *FD,
+   auto &&CheckAnonMember) -> FieldDecl * {
+  FieldDecl *Uninitialized = nullptr;
+  RecordDecl *RD = FD->getType()->getAsRecordDecl();
+  assert(RD && "Not anonymous member checked?");
+  for (auto *F : RD->fields()) {
+FieldDecl *UninitializedFieldInF = nullptr;
+if (F->isAnonymousStructOrUnion())
+  UninitializedFieldInF = CheckAnonMember(F, CheckAnonMember);
+else if (!F->isUnnamedBitfield() &&
+ !F->getType()->isIncompleteArrayType() &&
+ !F->hasInClassInitializer())
+  UninitializedFieldInF = F;
+
+if (RD->isUnion() && !UninitializedFieldInF)
+  return nullptr;
+if (!Uninitialized)
+  Uninitialized = UninitializedFieldInF;
+  }
+  return Uninitialized;
+};
+
+FieldDecl *FieldToDiagnose = nullptr;
+if (Field->isAnonymousStructOrUnion())
+  FieldToDiagnose = CheckAnonMember(Field, CheckAnonMember);
+else if (!Field->isUnnamedBitfield() &&
+ !Field->getType()->isIncompleteArrayType())
+  FieldToDiagnose = Field;
+
+if (FieldToDiagnose)
+  SemaRef.Diag(Loc, diag::warn_missing_field_initializers)
+  << FieldToDiagnose;
+  }
+
+  if (Init < NumInits) {
+ILE->setInit(Init, MemberInit.getAs());
+  } else if (!isa(MemberInit.get())) {
+// Empty initialization requires a constructor call, so
+// ex

[clang] [clang] Add per-global code model attribute (PR #72078)

2023-12-12 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Add @erichkeane for the attribute change.

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


[clang] [clang] Add per-global code model attribute (PR #72078)

2023-12-12 Thread Fangrui Song via cfe-commits


@@ -3408,6 +3408,8 @@ def warn_objc_redundant_literal_use : Warning<
 def err_attr_tlsmodel_arg : Error<"tls_model must be \"global-dynamic\", "
   "\"local-dynamic\", \"initial-exec\" or \"local-exec\"">;
 
+def err_attr_codemodel_arg : Error<"code_model '%0' is not yet supported on 
this target">;

MaskRay wrote:

We should remove `yet`, because a target may decide not to support the 
attribute.

The AIX err below is for progress tracking.

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


[clang-tools-extra] [clangd] Allow specifying what headers are always included via "" or <> (PR #67749)

2023-12-12 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

What is the relationship between this patch, and clangd 17's ["missing include" 
warning](https://clangd.llvm.org/guides/include-cleaner#missing-include-warning)?
 Does the quick-fix for the "missing include" warning also respect these config 
options?

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


[mlir] [llvm] [clang] [AMDGPU] - Add address space for strided buffers (PR #74471)

2023-12-12 Thread Jessica Del via cfe-commits

https://github.com/OutOfCache updated 
https://github.com/llvm/llvm-project/pull/74471

>From a6e0f1170cc0a9a3c6541d16edd12f2fafbe0da0 Mon Sep 17 00:00:00 2001
From: Jessica Del 
Date: Tue, 5 Dec 2023 13:45:58 +0100
Subject: [PATCH 1/8] [AMDGPU] - Add address space for strided buffers

This is an experimental address space for strided buffers.
These buffers can have structs as elements and
a stride > 1.
These pointers allow the indexed access in units of stride,
i.e., they point at `buffer[index * stride]`.
Thus, we can use the `idxen` modifier for buffer loads.

We assign address space 9 to 192-bit buffer pointers which
contain a 128-bit descriptor, a 32-bit offset and a 32-bit
index. Essentially, they are fat buffer pointers with
an additional 32-bit index.
---
 llvm/docs/AMDGPUUsage.rst | 48 -
 llvm/include/llvm/Support/AMDGPUAddrSpace.h   |  3 +
 llvm/lib/Target/AMDGPU/AMDGPU.h   | 27 +++
 .../lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp |  7 +-
 .../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp |  2 +-
 .../AMDGPU/AMDGPUTargetTransformInfo.cpp  |  3 +-
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 13 +++-
 .../CodeGen/AMDGPU/amdgpu-alias-analysis.ll   | 70 +++
 .../AMDGPU/vectorize-buffer-fat-pointer.ll| 19 -
 9 files changed, 153 insertions(+), 39 deletions(-)

diff --git a/llvm/docs/AMDGPUUsage.rst b/llvm/docs/AMDGPUUsage.rst
index 7fb3d70bbeffe..ff45efac7e848 100644
--- a/llvm/docs/AMDGPUUsage.rst
+++ b/llvm/docs/AMDGPUUsage.rst
@@ -703,23 +703,24 @@ supported for the ``amdgcn`` target.
   .. table:: AMDGPU Address Spaces
  :name: amdgpu-address-spaces-table
 
- = === === 
 === 
- ..
 64-Bit Process Address Space
- - --- --- 
 
- Address Space NameLLVM IR Address HSA Segment Hardware
 Address NULL Value
-   Space NumberNameName
 Size
- = === === 
 === 
- Generic   0   flatflat
 64  0x
- Global1   global  global  
 64  0x
- Region2   N/A GDS 
 32  *not implemented for AMDHSA*
- Local 3   group   LDS 
 32  0x
- Constant  4   constant*same as 
global* 64  0x
- Private   5   private scratch 
 32  0x
- Constant 32-bit   6   *TODO*  
 0x
- Buffer Fat Pointer (experimental) 7   *TODO*
- Buffer Resource (experimental)8   *TODO*
- Streamout Registers   128 N/A GS_REGS
- = === === 
 === 
+ = === === 
 === 
+ ..
 64-Bit Process Address Space
+ - --- --- 
 
+ Address Space NameLLVM IR Address HSA Segment 
Hardware Address NULL Value
+   Space NumberNameName
 Size
+ = === === 
 === 
+ Generic   0   flatflat
 64  0x
+ Global1   global  global  
 64  0x
+ Region2   N/A GDS 
 32  *not implemented for AMDHSA*
+ Local 3   group   LDS 
 32  0x
+ Constant  4   constant*same 
as global* 64  0x
+ Private   5   private scratch 
 32  0x
+ Constant 32-bit   6   *TODO*  
 0x
+ Buffer Fat Poi

[clang] [clang] Add size filter for stack auto init (PR #74777)

2023-12-12 Thread Vitaly Buka via cfe-commits


@@ -1759,20 +1759,29 @@ void 
CodeGenFunction::emitZeroOrPatternForAutoVarInit(QualType type,
   const VarDecl &D,
   Address Loc) {
   auto trivialAutoVarInit = getContext().getLangOpts().getTrivialAutoVarInit();
+  auto trivialAutoVarInitSizeBound =
+  getContext().getLangOpts().TrivialAutoVarInitSizeBound;
   CharUnits Size = getContext().getTypeSizeInChars(type);
   bool isVolatile = type.isVolatileQualified();
   if (!Size.isZero()) {
+auto allocSize = 
CGM.getDataLayout().getTypeAllocSize(Loc.getElementType());

vitalybuka wrote:

I'd expect that it's kind of `bail out` measure which should not be consider as 
a contract by a end-user. So confusing should not be a concern.

Also how 
```
struct S {
  long a;
  long b;
  char c;
} var;
```

is better  then:
```
long a;
long b;
char c;
```

My impression was that your concern is buffers of hundreds of bytes, then maybe 
better to target just them?
If it 's `24 vs 16` maybe it should not use auto init at all?

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


[clang] [clang] Add size filter for stack auto init (PR #74777)

2023-12-12 Thread Haopeng Liu via cfe-commits


@@ -1759,20 +1759,29 @@ void 
CodeGenFunction::emitZeroOrPatternForAutoVarInit(QualType type,
   const VarDecl &D,
   Address Loc) {
   auto trivialAutoVarInit = getContext().getLangOpts().getTrivialAutoVarInit();
+  auto trivialAutoVarInitSizeBound =
+  getContext().getLangOpts().TrivialAutoVarInitSizeBound;
   CharUnits Size = getContext().getTypeSizeInChars(type);
   bool isVolatile = type.isVolatileQualified();
   if (!Size.isZero()) {
+auto allocSize = 
CGM.getDataLayout().getTypeAllocSize(Loc.getElementType());

haopliu wrote:

`struct S {
  long a;
  long b;
  char c;
}; S var;` The `var` size is 24 bytes. `emitStoresForConstant` splits the 
constant store and emits several stores instead. Assume we set the max-size 
flag to 16. If filter the size in `emitStoresForConstant`, this var will be 
auto-initialized (each split store is less than 16) even though its size > 16. 
Would it be confusing? 

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


[mlir] [clang-tools-extra] [lld] [lldb] [libcxx] [llvm] [compiler-rt] [clang] [hwasan] Add `__hwasan_get_tag_from_pointer` (PR #75267)

2023-12-12 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/75267

>From 7fa7ea4786d3c8244aff575d3147d421c761e02a Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Tue, 12 Dec 2023 17:01:54 -0800
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 .../TestCases/Posix/fork_threaded.cpp | 86 +++
 .../sanitizer_common/sanitizer_specific.h | 16 
 2 files changed, 102 insertions(+)
 create mode 100644 
compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp

diff --git 
a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp 
b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp
new file mode 100644
index 0..72a2f78a5a3e7
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp
@@ -0,0 +1,86 @@
+// RUN: %clangxx -O0 %s -o %t && %env_tool_opts=die_after_fork=0 %run %t
+
+// UNSUPPORTED: asan, lsan, hwasan
+
+// Forking in multithread environment is unsupported. However we already have
+// some workarounds, and will add more, so this is the test.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "sanitizer_common/sanitizer_specific.h"
+
+static const size_t kBufferSize = 1 << 20;
+
+static void *background(void *arg) { return nullptr; }
+
+pthread_barrier_t bar;
+
+void CanDeadLock() {
+  // Don't bother with leaks, we try to trigger allocator or lsan deadlock.
+  __lsan::ScopedDisabler disable;
+  char *volatile p = new char[10];
+  __lsan_do_recoverable_leak_check();
+  delete[] p;
+}
+
+// Prevent stack buffer cleanup by instrumentation.
+#define NOSAN __attribute__((no_sanitize("address", "hwaddress", "memory")))
+
+NOSAN static void *inparent(void *arg) {
+  fprintf(stderr, "inparent %d\n", gettid());
+
+  char t[kBufferSize];
+  make_mem_bad(t, sizeof(t));
+
+  pthread_barrier_wait(&bar);
+
+  for (;;)
+CanDeadLock();
+
+  return 0;
+}
+
+NOSAN static void *inchild(void *arg) {
+  char t[kBufferSize];
+  check_mem_is_good(t, sizeof(t));
+  CanDeadLock();
+  return 0;
+}
+
+int main(void) {
+  pid_t pid;
+
+  pthread_barrier_init(&bar, nullptr, 2);
+  pthread_t thread_id;
+  while (pthread_create(&thread_id, 0, &inparent, 0) != 0) {
+  }
+  pthread_barrier_wait(&bar);
+
+  pid = fork();
+  switch (pid) {
+  case -1:
+perror("fork");
+return -1;
+  case 0:
+while (pthread_create(&thread_id, 0, &inchild, 0) != 0) {
+}
+break;
+  default: {
+fprintf(stderr, "fork %d\n", pid);
+int status;
+while (waitpid(-1, &status, __WALL) != pid) {
+}
+assert(WIFEXITED(status) && WEXITSTATUS(status) == 0);
+break;
+  }
+  }
+
+  return 0;
+}
diff --git a/compiler-rt/test/sanitizer_common/sanitizer_specific.h 
b/compiler-rt/test/sanitizer_common/sanitizer_specific.h
index 1a802020cfd66..963d91cb305f6 100644
--- a/compiler-rt/test/sanitizer_common/sanitizer_specific.h
+++ b/compiler-rt/test/sanitizer_common/sanitizer_specific.h
@@ -1,6 +1,12 @@
 #ifndef __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__
 #define __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__
 
+#include 
+
+__attribute__((weak)) int __lsan_do_recoverable_leak_check() { return 0; }
+__attribute__((weak)) void __lsan_disable(void) {}
+__attribute__((weak)) void __lsan_enable(void) {}
+
 #ifndef __has_feature
 #  define __has_feature(x) 0
 #endif
@@ -10,6 +16,8 @@
 static void check_mem_is_good(void *p, size_t s) {
   __msan_check_mem_is_initialized(p, s);
 }
+static void make_mem_good(void *p, size_t s) { __msan_unpoison(p, s); }
+static void make_mem_bad(void *p, size_t s) { __msan_poison(p, s); }
 #elif __has_feature(address_sanitizer)
 #  include 
 #  include 
@@ -17,8 +25,16 @@ static void check_mem_is_good(void *p, size_t s) {
   if (__asan_region_is_poisoned(p, s))
 abort();
 }
+static void make_mem_good(void *p, size_t s) {
+  __asan_unpoison_memory_region(p, s);
+}
+static void make_mem_bad(void *p, size_t s) {
+  __asan_poison_memory_region(p, s);
+}
 #else
 static void check_mem_is_good(void *p, size_t s) {}
+static void make_mem_good(void *p, size_t s) {}
+static void make_mem_bad(void *p, size_t s) {}
 #endif
 
 #endif // __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__
\ No newline at end of file

>From 6ed9198c136ead9c6726e5bfd83978e891522f5b Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Tue, 12 Dec 2023 17:09:19 -0800
Subject: [PATCH 2/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20introduced=20through=20rebase?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 compiler-rt/test/sanitizer_common/sanitizer_specific.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/test

[clang] [clang] Parse attribute [[gnu::no_stack_protector]] (PR #75289)

2023-12-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Sirui Mu (Lancern)


Changes

This commit adds relative TableGen definitions to parse the 
`[[gnu::no_stack_protector]]` attribute.

This PR addresses issue #75235.

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


1 Files Affected:

- (modified) clang/include/clang/Basic/Attr.td (+2-1) 


``diff
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 0d94ea2851c9ab..0344fa23e15369 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2212,7 +2212,8 @@ def NotTailCalled : InheritableAttr {
 def : MutualExclusions<[AlwaysInline, NotTailCalled]>;
 
 def NoStackProtector : InheritableAttr {
-  let Spellings = [Clang<"no_stack_protector">, Declspec<"safebuffers">];
+  let Spellings = [Clang<"no_stack_protector">, CXX11<"gnu", 
"no_stack_protector">,
+   C23<"gnu", "no_stack_protector">, Declspec<"safebuffers">];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [NoStackProtectorDocs];
   let SimpleHandler = 1;

``




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


[clang] [clang] Parse attribute [[gnu::no_stack_protector]] (PR #75289)

2023-12-12 Thread Sirui Mu via cfe-commits

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


[clang] [clang] Parse attribute [[gnu::no_stack_protector]] (PR #75289)

2023-12-12 Thread Sirui Mu via cfe-commits

https://github.com/Lancern created 
https://github.com/llvm/llvm-project/pull/75289

This commit adds relative TableGen definitions to parse the 
[[gnu::no_stack_protector]] attribute.

This PR addresses issue #75235.

>From d8de529580101ba68dc1c981aec8711aa0c58da4 Mon Sep 17 00:00:00 2001
From: Sirui Mu 
Date: Wed, 13 Dec 2023 06:51:09 +
Subject: [PATCH] [clang] Parse attribute [[gnu::no_stack_protector]]

This commit adds relative TableGen definitions to parse the
[[gnu::no_stack_protector]] attribute.
---
 clang/include/clang/Basic/Attr.td | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 0d94ea2851c9ab..0344fa23e15369 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2212,7 +2212,8 @@ def NotTailCalled : InheritableAttr {
 def : MutualExclusions<[AlwaysInline, NotTailCalled]>;
 
 def NoStackProtector : InheritableAttr {
-  let Spellings = [Clang<"no_stack_protector">, Declspec<"safebuffers">];
+  let Spellings = [Clang<"no_stack_protector">, CXX11<"gnu", 
"no_stack_protector">,
+   C23<"gnu", "no_stack_protector">, Declspec<"safebuffers">];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [NoStackProtectorDocs];
   let SimpleHandler = 1;

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


[llvm] [clang] [RISCV] Bump zicfilp to 0.4 (PR #75134)

2023-12-12 Thread Yeting Kuo via cfe-commits

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


[clang] 6095e21 - [RISCV] Bump zicfilp to 0.4 (#75134)

2023-12-12 Thread via cfe-commits

Author: Yeting Kuo
Date: 2023-12-13T14:50:24+08:00
New Revision: 6095e211303d1c9b8bc2eb184c919d0b56bfe7e0

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

LOG: [RISCV] Bump zicfilp to 0.4 (#75134)

Bump to https://github.com/riscv/riscv-cfi/releases/tag/v0.4.0. Actually
there is no functional change here.

Added: 


Modified: 
clang/test/Preprocessor/riscv-target-features.c
llvm/docs/RISCVUsage.rst
llvm/lib/Support/RISCVISAInfo.cpp
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/MC/RISCV/attribute-arch.s
llvm/unittests/Support/RISCVISAInfoTest.cpp

Removed: 




diff  --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 6fc921a8c6ee15..35208b2eae8fbd 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -1056,12 +1056,12 @@
 // CHECK-ZFBFMIN-EXT: __riscv_zfbfmin 8000{{$}}
 
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
-// RUN: -march=rv32i_zicfilp0p2 -x c -E -dM %s \
+// RUN: -march=rv32i_zicfilp0p4 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZICFILP-EXT %s
 // RUN: %clang --target=riscv64 -menable-experimental-extensions \
-// RUN: -march=rv64i_zicfilp0p2 -x c -E -dM %s \
+// RUN: -march=rv64i_zicfilp0p4 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZICFILP-EXT %s
-// CHECK-ZICFILP-EXT: __riscv_zicfilp 2000{{$}}
+// CHECK-ZICFILP-EXT: __riscv_zicfilp 4000{{$}}
 
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN: -march=rv32i_zicond1p0 -x c -E -dM %s \

diff  --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 65dd0d83448ed1..842ebf45305952 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -197,7 +197,7 @@ The primary goal of experimental support is to assist in 
the process of ratifica
   LLVM implements assembler support for the `0.8.0 draft specification 
`_.
 
 ``experimental-zicfilp``
-  LLVM implements the `0.2 draft specification 
`__.
+  LLVM implements the `0.4 draft specification 
`__.
 
 ``experimental-zicond``
   LLVM implements the `1.0-rc1 draft specification 
`__.

diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 6322748430063c..85c34dd6206307 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -174,7 +174,7 @@ static const RISCVSupportedExtension 
SupportedExperimentalExtensions[] = {
 
 {"zfbfmin", RISCVExtensionVersion{0, 8}},
 
-{"zicfilp", RISCVExtensionVersion{0, 2}},
+{"zicfilp", RISCVExtensionVersion{0, 4}},
 {"zicond", RISCVExtensionVersion{1, 0}},
 
 {"ztso", RISCVExtensionVersion{0, 1}},

diff  --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index 030ae06af6d282..b34ccb3ff0f937 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -271,7 +271,7 @@
 ; RV32ZVFBFMIN: .attribute 5, 
"rv32i2p1_f2p2_zicsr2p0_zfbfmin0p8_zve32f1p0_zve32x1p0_zvfbfmin0p8_zvl32b1p0"
 ; RV32ZVFBFWMA: .attribute 5, 
"rv32i2p1_f2p2_zicsr2p0_zfbfmin0p8_zve32f1p0_zve32x1p0_zvfbfmin0p8_zvfbfwma0p8_zvl32b1p0"
 ; RV32ZACAS: .attribute 5, "rv32i2p1_a2p1_zacas1p0"
-; RV32ZICFILP: .attribute 5, "rv32i2p1_zicfilp0p2"
+; RV32ZICFILP: .attribute 5, "rv32i2p1_zicfilp0p4"
 
 ; RV64M: .attribute 5, "rv64i2p1_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p1_zmmul1p0"
@@ -360,7 +360,7 @@
 ; RV64ZVFBFMIN: .attribute 5, 
"rv64i2p1_f2p2_zicsr2p0_zfbfmin0p8_zve32f1p0_zve32x1p0_zvfbfmin0p8_zvl32b1p0"
 ; RV64ZVFBFWMA: .attribute 5, 
"rv64i2p1_f2p2_zicsr2p0_zfbfmin0p8_zve32f1p0_zve32x1p0_zvfbfmin0p8_zvfbfwma0p8_zvl32b1p0"
 ; RV64ZACAS: .attribute 5, "rv64i2p1_a2p1_zacas1p0"
-; RV64ZICFILP: .attribute 5, "rv64i2p1_zicfilp0p2"
+; RV64ZICFILP: .attribute 5, "rv64i2p1_zicfilp0p4"
 
 define i32 @addi(i32 %a) {
   %1 = add i32 %a, 1

diff  --git a/llvm/test/MC/RISCV/attribute-arch.s 
b/llvm/test/MC/RISCV/attribute-arch.s
index aa919f266592f4..3ed48401e43fc8 100644
--- a/llvm/test/MC/RISCV/attribute-arch.s
+++ b/llvm/test/MC/RISCV/attribute-arch.s
@@ -309,5 +309,5 @@
 .attribute arch, "rv32i_xcvbi"
 # CHECK: attribute  5, "rv32i2p1_xcvbi1p0"
 
-.attribute arch, "rv32i_zicfilp0p2"
-# CHECK: attribute  5, "rv32i2p1_zicfilp0p2"
+.attribute arch, "rv32i_zicfilp0p4"
+# CHECK: attribute  5, "rv32i2p1_zicfilp0p4"

diff  --git a/llvm/unittests/Support/RISCVISAInfoTest.cpp 
b/llvm/unittests/Support/RISCVISAInfoTest.cpp
index 549964eed55518.

[llvm] [clang] [RISCV] Bump zicfilp to 0.4 (PR #75134)

2023-12-12 Thread Craig Topper via cfe-commits

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

LGTM

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


[llvm] [clang] [RISCV] Bump zicfilp to 0.4 (PR #75134)

2023-12-12 Thread Craig Topper via cfe-commits


@@ -736,7 +736,7 @@ R"(All available -march extensions for RISC-V
 xventanacondops 1.0
 
 Experimental extensions
-zicfilp 0.2   This is a long dummy description
+zicfilp 0.4   This is a long dummy description

topperc wrote:

Ok thanks

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


[clang] [llvm] [RISCV] Bump zicfilp to 0.4 (PR #75134)

2023-12-12 Thread Yeting Kuo via cfe-commits


@@ -736,7 +736,7 @@ R"(All available -march extensions for RISC-V
 xventanacondops 1.0
 
 Experimental extensions
-zicfilp 0.2   This is a long dummy description
+zicfilp 0.4   This is a long dummy description

yetingk wrote:

It's added by #66715. I guess it is means that we don't check the description.

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


[clang] [llvm] [RISCV] Remove experimental from Vector Crypto extensions (PR #74213)

2023-12-12 Thread Eric Biggers via cfe-commits


@@ -143,6 +143,22 @@ on support follow.
  ``Zve64f``   Supported
  ``Zve64d``   Supported
  ``Zvfh`` Supported
+ ``Zvbb`` Assembly Support

ebiggers wrote:

Done

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


[clang] [clang-format] Fix parsing of `operator<() {}` (PR #75144)

2023-12-12 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Fix parsing of `operator<() {}` (PR #75144)

2023-12-12 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Fix parsing of `operator<() {}` (PR #75144)

2023-12-12 Thread Owen Pan via cfe-commits


@@ -298,6 +298,17 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
   ASSERT_EQ(Tokens.size(), 12u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::identifier, TT_TypeName);
   EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
+
+  Tokens = annotate("class Foo {\n"
+"void operator<(Foo&) {}\n"
+"Foo& f;\n"

owenca wrote:

Use LLVM style:
```suggestion
"  void operator<(Foo &) {}\n"
"  Foo &f;\n"
```

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


[clang] [clang-format] Fix parsing of `operator<() {}` (PR #75144)

2023-12-12 Thread Owen Pan via cfe-commits


@@ -11727,6 +11727,13 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
"  void func(type &a) { a & member; }\n"
"  anotherType &member;\n"
"}");
+
+  Style.ReferenceAlignment = FormatStyle::RAS_Left;
+  verifyFormat("class Foo {\n"
+   "  void operator<(Foo&) {}\n"
+   "  Foo& f;\n"
+   "};",
+   Style);

owenca wrote:

Consider remove this test. The one in `UnderstandsUsesOfStarAndAmp` of 
`UnderstandsUsesOfStarAndAmp` is enough.

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


[clang] [clang-format] Fix parsing of `operator<() {}` (PR #75144)

2023-12-12 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Fix parsing of `operator<() {}` (PR #75144)

2023-12-12 Thread Owen Pan via cfe-commits

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


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


[clang] [clang][sema] forbid '+f' on output register (PR #75208)

2023-12-12 Thread Phoebe Wang via cfe-commits


@@ -717,8 +717,15 @@ bool TargetInfo::validateOutputConstraint(ConstraintInfo 
&Info) const {
   if (*Name != '=' && *Name != '+')
 return false;
 
-  if (*Name == '+')
+  if (*Name == '+') {
 Info.setIsReadWrite();
+// To align with GCC asm: "=f" is not allowed, the
+// operand constraints must select a class with a single reg.
+auto Flag = Name + 1;
+if (Flag && *Flag == 'f') {
+  return false;
+}
+  }

phoebewang wrote:

Need to change from here: 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/X86.cpp#L1436

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


[llvm] [clang] [RISCV] Remove experimental from Vector Crypto extensions (PR #74213)

2023-12-12 Thread Craig Topper via cfe-commits


@@ -143,6 +143,22 @@ on support follow.
  ``Zve64f``   Supported
  ``Zve64d``   Supported
  ``Zvfh`` Supported
+ ``Zvbb`` Assembly Support

topperc wrote:

Please alphabetize this list correctly.

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


[llvm] [clang] Disable PGO instrumentation on naked function (PR #75224)

2023-12-12 Thread via cfe-commits

serge-sans-paille wrote:

Thanks @MaskRay & @teresajohnson for the quick review o/

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


[llvm] [clang] Disable PGO instrumentation on naked function (PR #75224)

2023-12-12 Thread via cfe-commits

https://github.com/serge-sans-paille closed 
https://github.com/llvm/llvm-project/pull/75224
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] [libunwind][WebAssembly] Omit unused parts of libunwind.cpp for Wasm (PR #73196)

2023-12-12 Thread Heejin Ahn via cfe-commits

aheejin wrote:

@trcrsired When we use it in Emscripten, we build it with 
`-D__USING_WASM_EXCEPTIONS__`. Does that work? I'm not sure which toolchain and 
libraries you are using though. (It looks you are using WASI, but does WASI 
have the EH support? Does it allow usage with llvm libunwind?)

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


[clang] [RISCV] Implement multi-lib reuse rule for RISC-V bare-metal toolchain (PR #73765)

2023-12-12 Thread Craig Topper via cfe-commits

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

LGTM

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


[libunwind] [libunwind][WebAssembly] Omit unused parts of libunwind.cpp for Wasm (PR #73196)

2023-12-12 Thread via cfe-commits

trcrsired wrote:

![image](https://github.com/llvm/llvm-project/assets/100043421/fef1a590-37cd-4fc0-803d-01ff18890439)
Not working

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


[clang] [RISCV] Implement multi-lib reuse rule for RISC-V bare-metal toolchain (PR #73765)

2023-12-12 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat updated 
https://github.com/llvm/llvm-project/pull/73765

>From 320061a69ed129947eab1097d6308af434134a35 Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Wed, 29 Nov 2023 00:27:25 -0800
Subject: [PATCH 1/3] [RISCV] Implement multi-lib reuse rule for RISC-V
 bare-metal toolchain

Extend the multi-lib re-use selection mechanism for RISC-V.
This function will try to re-use multi-lib if they are compatible.
Definition of compatible:
  - ABI must be the same.
  - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
is a subset of march=rv32imc.
  - march that contains atomic extension can't reuse multi-lib that
doesn't have atomic, vice versa. e.g. multi-lib=march=rv32im and
march=rv32ima are not compatible, because software and hardware
atomic operation can't work together correctly.
---
 clang/lib/Driver/ToolChains/Gnu.cpp   | 127 +-
 .../riscv-toolchain-gcc-multilib-reuse.c  |  86 
 2 files changed, 212 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Driver/riscv-toolchain-gcc-multilib-reuse.c

diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index b875991844..c373a194ee4064 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -30,6 +30,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/TargetParser.h"
 #include 
@@ -1715,6 +1716,129 @@ static void findCSKYMultilibs(const Driver &D, const 
llvm::Triple &TargetTriple,
 Result.Multilibs = CSKYMultilibs;
 }
 
+/// Extend the multi-lib re-use selection mechanism for RISC-V.
+/// This funciton will try to re-use multi-lib if they are compatible.
+/// Definition of compatible:
+///   - ABI must be the same.
+///   - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
+/// is a subset of march=rv32imc.
+///   - march that contains atomic extension can't reuse multi-lib that
+/// doesn't has atomic, vice versa. e.g. multi-lib=march=rv32im and
+/// march=rv32ima are not compatible, because software and hardware
+/// atomic operation can't work together correctly.
+static bool
+RISCVMultilibSelect(const MultilibSet &RISCVMultilibSet, StringRef Arch,
+const Multilib::flags_list &Flags,
+llvm::SmallVector &SelectedMultilibs) {
+  // Try to find the perfect matching multi-lib first.
+  if (RISCVMultilibSet.select(Flags, SelectedMultilibs))
+return true;
+
+  llvm::StringMap FlagSet;
+  Multilib::flags_list NewFlags;
+  std::vector NewMultilibs;
+
+  auto ParseResult = llvm::RISCVISAInfo::parseArchString(
+  Arch, /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!ParseResult) {
+// Ignore any error here, we assume it will handled in another place.
+consumeError(ParseResult.takeError());
+return false;
+  }
+  auto &ISAInfo = *ParseResult;
+
+  auto CurrentExts = ISAInfo->getExtensions();
+
+  addMultilibFlag(ISAInfo->getXLen() == 32, "-m32", NewFlags);
+  addMultilibFlag(ISAInfo->getXLen() == 64, "-m64", NewFlags);
+
+  // Collect all flags except march=*
+  for (StringRef Flag : Flags) {
+if (Flag.startswith("!march=") || Flag.startswith("-march="))
+  continue;
+
+NewFlags.push_back(Flag.str());
+  }
+
+  llvm::StringSet<> AllArchExts;
+  // Reconstruct multi-lib list, and break march option into seperated
+  // extension. e.g. march=rv32im -> +i +m
+  for (auto M : RISCVMultilibSet) {
+bool Skip = false;
+
+MultilibBuilder NewMultilib =
+MultilibBuilder(M.gccSuffix(), M.osSuffix(), M.includeSuffix());
+for (StringRef Flag : M.flags()) {
+  // Add back the all option except -march.
+  if (!Flag.startswith("-march=")) {
+NewMultilib.flag(Flag);
+continue;
+  }
+
+  // Break down -march into individual extension.
+  auto MLConfigParseResult = llvm::RISCVISAInfo::parseArchString(
+  Flag.drop_front(7), /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!MLConfigParseResult) {
+// Ignore any error here, we assume it will handled in another place.
+llvm::consumeError(MLConfigParseResult.takeError());
+
+// We might got parsing error if rv32e in the list, we could just skip
+// that and process the rest of multi-lib configs.
+Skip = true;
+continue;
+  }
+  auto &MLConfigISAInfo = *MLConfigParseResult;
+
+  auto MLConfigArchExts = MLConfigISAInfo->getExtensions();
+  for (auto MLConfigArchExt : MLConfigArchExts) {
+auto ExtName = MLConfigArchExt.first;
+NewMultilib.flag(Twine("-", ExtName).str());
+
+if (!AllArchExts.contains(ExtName)) {
+  AllArchExts.ins

[clang] [clang][Driver] Support -fms-volatile as equivalent to /volatile:ms (PR #74790)

2023-12-12 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic updated 
https://github.com/llvm/llvm-project/pull/74790

>From 476402a90cc24a5697efbef0b3bcb1276a4bc6f5 Mon Sep 17 00:00:00 2001
From: Eli Friedman 
Date: Thu, 7 Dec 2023 16:21:53 -0800
Subject: [PATCH] [clang][Driver] Support -fms-volatile as equivalent to
 /volatile:ms

The flag "-fms-volatile" has existed as a -cc1 flag for a while.  It
also technically existed as a driver flag, but didn't do anything
because it wasn't wired up to anything in the driver.

This patch adds -fno-ms-volatile, and makes both -fms-volatile and
-fno-ms-volatile work the same way as the cl-mode flags. The defaults
are unchanged (default on for x86 in cl mode, default off otherwise).
---
 clang/include/clang/Driver/Options.td | 12 +++-
 clang/lib/Driver/ToolChains/Clang.cpp | 16 
 clang/test/Driver/cl-options.c|  6 --
 clang/test/Driver/clang_f_opts.c  |  6 ++
 4 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0eec2b35263762..6274ff76950d98 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2869,9 +2869,11 @@ defm asm_blocks : BoolFOption<"asm-blocks",
   LangOpts<"AsmBlocks">, Default,
   PosFlag,
   NegFlag>;
-def fms_volatile : Flag<["-"], "fms-volatile">, Group,
-  Visibility<[ClangOption, CC1Option]>,
-  MarshallingInfoFlag>;
+defm ms_volatile : BoolFOption<"ms-volatile",
+  LangOpts<"MSVolatile">, DefaultFalse,
+  PosFlag,
+  NegFlag>;
 def fmsc_version : Joined<["-"], "fmsc-version=">, Group,
   Visibility<[ClangOption, CLOption]>,
   HelpText<"Microsoft compiler version number to report in _MSC_VER (0 = don't 
define it (default))">;
@@ -8184,7 +8186,7 @@ def _SLASH_winsysroot : CLJoinedOrSeparate<"winsysroot">,
   HelpText<"Same as \"/diasdkdir /DIA SDK\" /vctoolsdir 
/VC/Tools/MSVC/ \"/winsdkdir /Windows Kits/10\"">,
   MetaVarName<"">;
 def _SLASH_volatile_iso : Option<["/", "-"], "volatile:iso", KIND_FLAG>,
-  Group<_SLASH_volatile_Group>, Flags<[NoXarchOption]>, Visibility<[CLOption]>,
+  Visibility<[CLOption]>, Alias,
   HelpText<"Volatile loads and stores have standard semantics">;
 def _SLASH_vmb : CLFlag<"vmb">,
   HelpText<"Use a best-case representation method for member pointers">;
@@ -8199,7 +8201,7 @@ def _SLASH_vmv : CLFlag<"vmv">,
   HelpText<"Set the default most-general representation to "
"virtual inheritance">;
 def _SLASH_volatile_ms  : Option<["/", "-"], "volatile:ms", KIND_FLAG>,
-  Group<_SLASH_volatile_Group>, Flags<[NoXarchOption]>, Visibility<[CLOption]>,
+  Visibility<[CLOption]>, Alias,
   HelpText<"Volatile loads and stores have acquire and release semantics">;
 def _SLASH_clang : CLJoined<"clang:">,
   HelpText<"Pass  to the clang driver">, MetaVarName<"">;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index f02f7c841b91f0..c6be0750e1c338 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5545,6 +5545,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
options::OPT_fno_auto_import);
   }
 
+  if (Args.hasFlag(options::OPT_fms_volatile, options::OPT_fno_ms_volatile,
+   Triple.isX86() && D.IsCLMode()))
+CmdArgs.push_back("-fms-volatile");
+
   // Non-PIC code defaults to -fdirect-access-external-data while PIC code
   // defaults to -fno-direct-access-external-data. Pass the option if different
   // from the default.
@@ -7877,18 +7881,6 @@ void Clang::AddClangCLArgs(const ArgList &Args, 
types::ID InputType,
 CmdArgs.push_back("-P");
   }
 
-  unsigned VolatileOptionID;
-  if (getToolChain().getTriple().isX86())
-VolatileOptionID = options::OPT__SLASH_volatile_ms;
-  else
-VolatileOptionID = options::OPT__SLASH_volatile_iso;
-
-  if (Arg *A = Args.getLastArg(options::OPT__SLASH_volatile_Group))
-VolatileOptionID = A->getOption().getID();
-
-  if (VolatileOptionID == options::OPT__SLASH_volatile_ms)
-CmdArgs.push_back("-fms-volatile");
-
  if (Args.hasFlag(options::OPT__SLASH_Zc_dllexportInlines_,
   options::OPT__SLASH_Zc_dllexportInlines,
   false)) {
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 6d929b19e7e2ef..6bc315b09477a9 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -272,10 +272,12 @@
 // RUN: not %clang_cl /vmg /vmm /vms -### -- %s 2>&1 | FileCheck 
-check-prefix=VMX %s
 // VMX: '/vms' not allowed with '/vmm'
 
-// RUN: %clang_cl /volatile:iso -### -- %s 2>&1 | FileCheck 
-check-prefix=VOLATILE-ISO %s
+// RUN: %clang_cl --target=i686-pc-win32 /volatile:iso -### -- %s 2>&1 | 
FileCheck -check-prefix=VOLATILE-ISO %s
+// RUN: %clang_cl --target=aarch64-pc-win32 -### -- %s 2>&1 | FileCheck 
-check-prefix=VOLATILE-ISO %s
 // VOLATILE-ISO-NOT: "-fms-volatile"
 
-// RUN: %clang_

[clang] [RISCV] Implement multi-lib reuse rule for RISC-V bare-metal toolchain (PR #73765)

2023-12-12 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat updated 
https://github.com/llvm/llvm-project/pull/73765

>From 320061a69ed129947eab1097d6308af434134a35 Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Wed, 29 Nov 2023 00:27:25 -0800
Subject: [PATCH 1/3] [RISCV] Implement multi-lib reuse rule for RISC-V
 bare-metal toolchain

Extend the multi-lib re-use selection mechanism for RISC-V.
This function will try to re-use multi-lib if they are compatible.
Definition of compatible:
  - ABI must be the same.
  - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
is a subset of march=rv32imc.
  - march that contains atomic extension can't reuse multi-lib that
doesn't have atomic, vice versa. e.g. multi-lib=march=rv32im and
march=rv32ima are not compatible, because software and hardware
atomic operation can't work together correctly.
---
 clang/lib/Driver/ToolChains/Gnu.cpp   | 127 +-
 .../riscv-toolchain-gcc-multilib-reuse.c  |  86 
 2 files changed, 212 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Driver/riscv-toolchain-gcc-multilib-reuse.c

diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index b875991844..c373a194ee4064 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -30,6 +30,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/TargetParser.h"
 #include 
@@ -1715,6 +1716,129 @@ static void findCSKYMultilibs(const Driver &D, const 
llvm::Triple &TargetTriple,
 Result.Multilibs = CSKYMultilibs;
 }
 
+/// Extend the multi-lib re-use selection mechanism for RISC-V.
+/// This funciton will try to re-use multi-lib if they are compatible.
+/// Definition of compatible:
+///   - ABI must be the same.
+///   - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
+/// is a subset of march=rv32imc.
+///   - march that contains atomic extension can't reuse multi-lib that
+/// doesn't has atomic, vice versa. e.g. multi-lib=march=rv32im and
+/// march=rv32ima are not compatible, because software and hardware
+/// atomic operation can't work together correctly.
+static bool
+RISCVMultilibSelect(const MultilibSet &RISCVMultilibSet, StringRef Arch,
+const Multilib::flags_list &Flags,
+llvm::SmallVector &SelectedMultilibs) {
+  // Try to find the perfect matching multi-lib first.
+  if (RISCVMultilibSet.select(Flags, SelectedMultilibs))
+return true;
+
+  llvm::StringMap FlagSet;
+  Multilib::flags_list NewFlags;
+  std::vector NewMultilibs;
+
+  auto ParseResult = llvm::RISCVISAInfo::parseArchString(
+  Arch, /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!ParseResult) {
+// Ignore any error here, we assume it will handled in another place.
+consumeError(ParseResult.takeError());
+return false;
+  }
+  auto &ISAInfo = *ParseResult;
+
+  auto CurrentExts = ISAInfo->getExtensions();
+
+  addMultilibFlag(ISAInfo->getXLen() == 32, "-m32", NewFlags);
+  addMultilibFlag(ISAInfo->getXLen() == 64, "-m64", NewFlags);
+
+  // Collect all flags except march=*
+  for (StringRef Flag : Flags) {
+if (Flag.startswith("!march=") || Flag.startswith("-march="))
+  continue;
+
+NewFlags.push_back(Flag.str());
+  }
+
+  llvm::StringSet<> AllArchExts;
+  // Reconstruct multi-lib list, and break march option into seperated
+  // extension. e.g. march=rv32im -> +i +m
+  for (auto M : RISCVMultilibSet) {
+bool Skip = false;
+
+MultilibBuilder NewMultilib =
+MultilibBuilder(M.gccSuffix(), M.osSuffix(), M.includeSuffix());
+for (StringRef Flag : M.flags()) {
+  // Add back the all option except -march.
+  if (!Flag.startswith("-march=")) {
+NewMultilib.flag(Flag);
+continue;
+  }
+
+  // Break down -march into individual extension.
+  auto MLConfigParseResult = llvm::RISCVISAInfo::parseArchString(
+  Flag.drop_front(7), /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!MLConfigParseResult) {
+// Ignore any error here, we assume it will handled in another place.
+llvm::consumeError(MLConfigParseResult.takeError());
+
+// We might got parsing error if rv32e in the list, we could just skip
+// that and process the rest of multi-lib configs.
+Skip = true;
+continue;
+  }
+  auto &MLConfigISAInfo = *MLConfigParseResult;
+
+  auto MLConfigArchExts = MLConfigISAInfo->getExtensions();
+  for (auto MLConfigArchExt : MLConfigArchExts) {
+auto ExtName = MLConfigArchExt.first;
+NewMultilib.flag(Twine("-", ExtName).str());
+
+if (!AllArchExts.contains(ExtName)) {
+  AllArchExts.ins

[mlir] [compiler-rt] [lldb] [clang-tools-extra] [clang] [llvm] [hwasan] Add `__hwasan_get_tag_from_pointer` (PR #75267)

2023-12-12 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/75267

>From 7fa7ea4786d3c8244aff575d3147d421c761e02a Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Tue, 12 Dec 2023 17:01:54 -0800
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 .../TestCases/Posix/fork_threaded.cpp | 86 +++
 .../sanitizer_common/sanitizer_specific.h | 16 
 2 files changed, 102 insertions(+)
 create mode 100644 
compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp

diff --git 
a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp 
b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp
new file mode 100644
index 00..72a2f78a5a3e77
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp
@@ -0,0 +1,86 @@
+// RUN: %clangxx -O0 %s -o %t && %env_tool_opts=die_after_fork=0 %run %t
+
+// UNSUPPORTED: asan, lsan, hwasan
+
+// Forking in multithread environment is unsupported. However we already have
+// some workarounds, and will add more, so this is the test.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "sanitizer_common/sanitizer_specific.h"
+
+static const size_t kBufferSize = 1 << 20;
+
+static void *background(void *arg) { return nullptr; }
+
+pthread_barrier_t bar;
+
+void CanDeadLock() {
+  // Don't bother with leaks, we try to trigger allocator or lsan deadlock.
+  __lsan::ScopedDisabler disable;
+  char *volatile p = new char[10];
+  __lsan_do_recoverable_leak_check();
+  delete[] p;
+}
+
+// Prevent stack buffer cleanup by instrumentation.
+#define NOSAN __attribute__((no_sanitize("address", "hwaddress", "memory")))
+
+NOSAN static void *inparent(void *arg) {
+  fprintf(stderr, "inparent %d\n", gettid());
+
+  char t[kBufferSize];
+  make_mem_bad(t, sizeof(t));
+
+  pthread_barrier_wait(&bar);
+
+  for (;;)
+CanDeadLock();
+
+  return 0;
+}
+
+NOSAN static void *inchild(void *arg) {
+  char t[kBufferSize];
+  check_mem_is_good(t, sizeof(t));
+  CanDeadLock();
+  return 0;
+}
+
+int main(void) {
+  pid_t pid;
+
+  pthread_barrier_init(&bar, nullptr, 2);
+  pthread_t thread_id;
+  while (pthread_create(&thread_id, 0, &inparent, 0) != 0) {
+  }
+  pthread_barrier_wait(&bar);
+
+  pid = fork();
+  switch (pid) {
+  case -1:
+perror("fork");
+return -1;
+  case 0:
+while (pthread_create(&thread_id, 0, &inchild, 0) != 0) {
+}
+break;
+  default: {
+fprintf(stderr, "fork %d\n", pid);
+int status;
+while (waitpid(-1, &status, __WALL) != pid) {
+}
+assert(WIFEXITED(status) && WEXITSTATUS(status) == 0);
+break;
+  }
+  }
+
+  return 0;
+}
diff --git a/compiler-rt/test/sanitizer_common/sanitizer_specific.h 
b/compiler-rt/test/sanitizer_common/sanitizer_specific.h
index 1a802020cfd668..963d91cb305f60 100644
--- a/compiler-rt/test/sanitizer_common/sanitizer_specific.h
+++ b/compiler-rt/test/sanitizer_common/sanitizer_specific.h
@@ -1,6 +1,12 @@
 #ifndef __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__
 #define __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__
 
+#include 
+
+__attribute__((weak)) int __lsan_do_recoverable_leak_check() { return 0; }
+__attribute__((weak)) void __lsan_disable(void) {}
+__attribute__((weak)) void __lsan_enable(void) {}
+
 #ifndef __has_feature
 #  define __has_feature(x) 0
 #endif
@@ -10,6 +16,8 @@
 static void check_mem_is_good(void *p, size_t s) {
   __msan_check_mem_is_initialized(p, s);
 }
+static void make_mem_good(void *p, size_t s) { __msan_unpoison(p, s); }
+static void make_mem_bad(void *p, size_t s) { __msan_poison(p, s); }
 #elif __has_feature(address_sanitizer)
 #  include 
 #  include 
@@ -17,8 +25,16 @@ static void check_mem_is_good(void *p, size_t s) {
   if (__asan_region_is_poisoned(p, s))
 abort();
 }
+static void make_mem_good(void *p, size_t s) {
+  __asan_unpoison_memory_region(p, s);
+}
+static void make_mem_bad(void *p, size_t s) {
+  __asan_poison_memory_region(p, s);
+}
 #else
 static void check_mem_is_good(void *p, size_t s) {}
+static void make_mem_good(void *p, size_t s) {}
+static void make_mem_bad(void *p, size_t s) {}
 #endif
 
 #endif // __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__
\ No newline at end of file

>From 6ed9198c136ead9c6726e5bfd83978e891522f5b Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Tue, 12 Dec 2023 17:09:19 -0800
Subject: [PATCH 2/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20introduced=20through=20rebase?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 compiler-rt/test/sanitizer_common/sanitizer_specific.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/

[clang-tools-extra] [clangd] check for synthesized symbols when tracking include locations (PR #75128)

2023-12-12 Thread Matheus Izvekov via cfe-commits

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

>From 6f4cc2d6a9af855a12feb03bd81cbc6f7cbf9caf Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 13 Dec 2023 01:44:16 -0300
Subject: [PATCH] [clangd] check for synthesized symbols when tracking include
 locations

This fixes https://github.com/llvm/llvm-project/issues/75115

In C mode with MSVC compatibility, when the `assert` macro is defined,
as a workaround, `static_assert` is implicitly defined as well,
if not already so, in order to work around a broken `assert.h`
implementation.
This workaround was implemented in 
https://github.com/llvm/llvm-project/commit/8da090381d567d0ec555840f6b2a651d2997e4b3

A synthesized symbol does not occur in source code, and therefore
should not have valid source location, but this was not checked when
inserting this into a `symbol -> include file` map.

The invalid FileID value is used for empty key representation in
the include file hash table, so it's not valid to insert it.
---
 clang-tools-extra/clangd/index/SymbolCollector.cpp |  8 
 clang-tools-extra/clangd/test/GH75115.test | 11 +++
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index aac6676a995fe..5d995cdae6d66 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -821,7 +821,8 @@ void SymbolCollector::setIncludeLocation(const Symbol &S, 
SourceLocation DefLoc,
 
   // Use the expansion location to get the #include header since this is
   // where the symbol is exposed.
-  IncludeFiles[S.ID] = SM.getDecomposedExpansionLoc(DefLoc).first;
+  if (FileID FID = SM.getDecomposedExpansionLoc(DefLoc).first; FID.isValid())
+IncludeFiles[S.ID] = FID;
 
   // We update providers for a symbol with each occurence, as SymbolCollector
   // might run while parsing, rather than at the end of a translation unit.
@@ -893,16 +894,15 @@ void SymbolCollector::finish() {
 const Symbol *S = Symbols.find(SID);
 if (!S)
   continue;
-assert(IncludeFiles.contains(SID));
 
-const auto FID = IncludeFiles.at(SID);
+FileID FID = IncludeFiles.lookup(SID);
 // Determine if the FID is #include'd or #import'ed.
 Symbol::IncludeDirective Directives = Symbol::Invalid;
 auto CollectDirectives = shouldCollectIncludePath(S->SymInfo.Kind);
 if ((CollectDirectives & Symbol::Include) != 0)
   Directives |= Symbol::Include;
 // Only allow #import for symbols from ObjC-like files.
-if ((CollectDirectives & Symbol::Import) != 0) {
+if ((CollectDirectives & Symbol::Import) != 0 && FID.isValid()) {
   auto [It, Inserted] = FileToContainsImportsOrObjC.try_emplace(FID);
   if (Inserted)
 It->second = FilesWithObjCConstructs.contains(FID) ||
diff --git a/clang-tools-extra/clangd/test/GH75115.test 
b/clang-tools-extra/clangd/test/GH75115.test
index 030392f1d69b3..dc86f5b9a6cee 100644
--- a/clang-tools-extra/clangd/test/GH75115.test
+++ b/clang-tools-extra/clangd/test/GH75115.test
@@ -1,12 +1,15 @@
 // RUN: rm -rf %t.dir && mkdir -p %t.dir
 // RUN: echo '[{"directory": "%/t.dir", "command": "clang 
--target=x86_64-pc-windows-msvc -x c GH75115.test", "file": "GH75115.test"}]' > 
%t.dir/compile_commands.json
-// RUN: not --crash clangd -enable-config=0 --compile-commands-dir=%t.dir 
-check=%s 2>&1 | FileCheck -strict-whitespace %s
-
-// FIXME: Crashes
+// RUN: clangd -enable-config=0 --compile-commands-dir=%t.dir -check=%s 2>&1 | 
FileCheck -strict-whitespace %s
 
 // CHECK: Building preamble...
 // CHECK-NEXT: Built preamble
 // CHECK-NEXT: Indexing headers...
-// CHECK-NEXT: !KeyInfoT::isEqual(Val, EmptyKey) && !KeyInfoT::isEqual(Val, 
TombstoneKey) && "Empty/Tombstone value shouldn't be inserted into map!"
+// CHECK-NEXT: Building AST...
+// CHECK-NEXT: Indexing AST...
+// CHECK-NEXT: Building inlay hints
+// CHECK-NEXT: semantic highlighting
+// CHECK-NEXT: Testing features at each token
+// CHECK-NEXT: All checks completed, 0 errors
 
 #define assert

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


[clang-tools-extra] [clangd] check for synthesized symbols when tracking include locations (PR #75128)

2023-12-12 Thread Matheus Izvekov via cfe-commits

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


[clang-tools-extra] [clangd] Add test for GH75115 (PR #75116)

2023-12-12 Thread Matheus Izvekov via cfe-commits

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


[clang-tools-extra] 04580ed - [clangd] Add test for GH75115 (#75116)

2023-12-12 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2023-12-13T05:50:05+01:00
New Revision: 04580edd8a394dc2ccee7363c8a41ee05b1a6b98

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

LOG: [clangd] Add test for GH75115 (#75116)

Add test for https://github.com/llvm/llvm-project/issues/75115

Added: 
clang-tools-extra/clangd/test/GH75115.test

Modified: 


Removed: 




diff  --git a/clang-tools-extra/clangd/test/GH75115.test 
b/clang-tools-extra/clangd/test/GH75115.test
new file mode 100644
index 00..030392f1d69b30
--- /dev/null
+++ b/clang-tools-extra/clangd/test/GH75115.test
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t.dir && mkdir -p %t.dir
+// RUN: echo '[{"directory": "%/t.dir", "command": "clang 
--target=x86_64-pc-windows-msvc -x c GH75115.test", "file": "GH75115.test"}]' > 
%t.dir/compile_commands.json
+// RUN: not --crash clangd -enable-config=0 --compile-commands-dir=%t.dir 
-check=%s 2>&1 | FileCheck -strict-whitespace %s
+
+// FIXME: Crashes
+
+// CHECK: Building preamble...
+// CHECK-NEXT: Built preamble
+// CHECK-NEXT: Indexing headers...
+// CHECK-NEXT: !KeyInfoT::isEqual(Val, EmptyKey) && !KeyInfoT::isEqual(Val, 
TombstoneKey) && "Empty/Tombstone value shouldn't be inserted into map!"
+
+#define assert



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


[clang-tools-extra] [clangd] Add test for GH75115 (PR #75116)

2023-12-12 Thread Matheus Izvekov via cfe-commits

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

>From 1c9690d87f3a3bbe8389cb9a852d00fe2d3cf478 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Mon, 11 Dec 2023 17:36:44 -0300
Subject: [PATCH] [clangd] Add test for GH75115

Add test for https://github.com/llvm/llvm-project/issues/75115
---
 clang-tools-extra/clangd/test/GH75115.test | 12 
 1 file changed, 12 insertions(+)
 create mode 100644 clang-tools-extra/clangd/test/GH75115.test

diff --git a/clang-tools-extra/clangd/test/GH75115.test 
b/clang-tools-extra/clangd/test/GH75115.test
new file mode 100644
index 00..030392f1d69b30
--- /dev/null
+++ b/clang-tools-extra/clangd/test/GH75115.test
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t.dir && mkdir -p %t.dir
+// RUN: echo '[{"directory": "%/t.dir", "command": "clang 
--target=x86_64-pc-windows-msvc -x c GH75115.test", "file": "GH75115.test"}]' > 
%t.dir/compile_commands.json
+// RUN: not --crash clangd -enable-config=0 --compile-commands-dir=%t.dir 
-check=%s 2>&1 | FileCheck -strict-whitespace %s
+
+// FIXME: Crashes
+
+// CHECK: Building preamble...
+// CHECK-NEXT: Built preamble
+// CHECK-NEXT: Indexing headers...
+// CHECK-NEXT: !KeyInfoT::isEqual(Val, EmptyKey) && !KeyInfoT::isEqual(Val, 
TombstoneKey) && "Empty/Tombstone value shouldn't be inserted into map!"
+
+#define assert

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


[llvm] [clang] [RISCV] Remove experimental from Vector Crypto extensions (PR #74213)

2023-12-12 Thread Eric Biggers via cfe-commits

ebiggers wrote:

Rebased onto latest upstream because the `clang-format` warning is fixed there. 
 No changes

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


[lldb] [mlir] [compiler-rt] [clang] [llvm] [hwasan] Add `__hwasan_get_tag_from_pointer` (PR #75267)

2023-12-12 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/75267

>From 7fa7ea4786d3c8244aff575d3147d421c761e02a Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Tue, 12 Dec 2023 17:01:54 -0800
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 .../TestCases/Posix/fork_threaded.cpp | 86 +++
 .../sanitizer_common/sanitizer_specific.h | 16 
 2 files changed, 102 insertions(+)
 create mode 100644 
compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp

diff --git 
a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp 
b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp
new file mode 100644
index 0..72a2f78a5a3e7
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp
@@ -0,0 +1,86 @@
+// RUN: %clangxx -O0 %s -o %t && %env_tool_opts=die_after_fork=0 %run %t
+
+// UNSUPPORTED: asan, lsan, hwasan
+
+// Forking in multithread environment is unsupported. However we already have
+// some workarounds, and will add more, so this is the test.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "sanitizer_common/sanitizer_specific.h"
+
+static const size_t kBufferSize = 1 << 20;
+
+static void *background(void *arg) { return nullptr; }
+
+pthread_barrier_t bar;
+
+void CanDeadLock() {
+  // Don't bother with leaks, we try to trigger allocator or lsan deadlock.
+  __lsan::ScopedDisabler disable;
+  char *volatile p = new char[10];
+  __lsan_do_recoverable_leak_check();
+  delete[] p;
+}
+
+// Prevent stack buffer cleanup by instrumentation.
+#define NOSAN __attribute__((no_sanitize("address", "hwaddress", "memory")))
+
+NOSAN static void *inparent(void *arg) {
+  fprintf(stderr, "inparent %d\n", gettid());
+
+  char t[kBufferSize];
+  make_mem_bad(t, sizeof(t));
+
+  pthread_barrier_wait(&bar);
+
+  for (;;)
+CanDeadLock();
+
+  return 0;
+}
+
+NOSAN static void *inchild(void *arg) {
+  char t[kBufferSize];
+  check_mem_is_good(t, sizeof(t));
+  CanDeadLock();
+  return 0;
+}
+
+int main(void) {
+  pid_t pid;
+
+  pthread_barrier_init(&bar, nullptr, 2);
+  pthread_t thread_id;
+  while (pthread_create(&thread_id, 0, &inparent, 0) != 0) {
+  }
+  pthread_barrier_wait(&bar);
+
+  pid = fork();
+  switch (pid) {
+  case -1:
+perror("fork");
+return -1;
+  case 0:
+while (pthread_create(&thread_id, 0, &inchild, 0) != 0) {
+}
+break;
+  default: {
+fprintf(stderr, "fork %d\n", pid);
+int status;
+while (waitpid(-1, &status, __WALL) != pid) {
+}
+assert(WIFEXITED(status) && WEXITSTATUS(status) == 0);
+break;
+  }
+  }
+
+  return 0;
+}
diff --git a/compiler-rt/test/sanitizer_common/sanitizer_specific.h 
b/compiler-rt/test/sanitizer_common/sanitizer_specific.h
index 1a802020cfd66..963d91cb305f6 100644
--- a/compiler-rt/test/sanitizer_common/sanitizer_specific.h
+++ b/compiler-rt/test/sanitizer_common/sanitizer_specific.h
@@ -1,6 +1,12 @@
 #ifndef __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__
 #define __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__
 
+#include 
+
+__attribute__((weak)) int __lsan_do_recoverable_leak_check() { return 0; }
+__attribute__((weak)) void __lsan_disable(void) {}
+__attribute__((weak)) void __lsan_enable(void) {}
+
 #ifndef __has_feature
 #  define __has_feature(x) 0
 #endif
@@ -10,6 +16,8 @@
 static void check_mem_is_good(void *p, size_t s) {
   __msan_check_mem_is_initialized(p, s);
 }
+static void make_mem_good(void *p, size_t s) { __msan_unpoison(p, s); }
+static void make_mem_bad(void *p, size_t s) { __msan_poison(p, s); }
 #elif __has_feature(address_sanitizer)
 #  include 
 #  include 
@@ -17,8 +25,16 @@ static void check_mem_is_good(void *p, size_t s) {
   if (__asan_region_is_poisoned(p, s))
 abort();
 }
+static void make_mem_good(void *p, size_t s) {
+  __asan_unpoison_memory_region(p, s);
+}
+static void make_mem_bad(void *p, size_t s) {
+  __asan_poison_memory_region(p, s);
+}
 #else
 static void check_mem_is_good(void *p, size_t s) {}
+static void make_mem_good(void *p, size_t s) {}
+static void make_mem_bad(void *p, size_t s) {}
 #endif
 
 #endif // __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__
\ No newline at end of file

>From 6ed9198c136ead9c6726e5bfd83978e891522f5b Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Tue, 12 Dec 2023 17:09:19 -0800
Subject: [PATCH 2/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20introduced=20through=20rebase?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 compiler-rt/test/sanitizer_common/sanitizer_specific.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/test

[lldb] [mlir] [compiler-rt] [clang] [llvm] [hwasan] Add `__hwasan_get_tag_from_pointer` (PR #75267)

2023-12-12 Thread Vitaly Buka via cfe-commits

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


[lldb] [mlir] [compiler-rt] [clang] [llvm] [test][sanitizer] Allow fork_threaded test on Msan, Tsan, Ubsan (PR #75260)

2023-12-12 Thread Vitaly Buka via cfe-commits

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


[lldb] [mlir] [compiler-rt] [clang] [llvm] [test][sanitizer] Allow fork_threaded test on Msan, Tsan, Ubsan (PR #75260)

2023-12-12 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/75260

>From 2dad66c39ce65a06df39cd761362624b355951e3 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Tue, 12 Dec 2023 16:20:07 -0800
Subject: [PATCH 1/4] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 .../TestCases/Posix/fork_threaded.cpp | 86 +++
 .../sanitizer_common/sanitizer_specific.h | 16 
 2 files changed, 102 insertions(+)
 create mode 100644 
compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp

diff --git 
a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp 
b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp
new file mode 100644
index 00..2264c558166388
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp
@@ -0,0 +1,86 @@
+// RUN: %clangxx -O0 %s -o %t && %env_tool_opts=die_after_fork=0 %run %t
+
+// UNSUPPORTED: *
+
+// Forking in multithread environment is unsupported. However we already have
+// some workarounds, and will add more, so this is the test.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "sanitizer_common/sanitizer_specific.h"
+
+static const size_t kBufferSize = 1 << 20;
+
+static void *background(void *arg) { return nullptr; }
+
+pthread_barrier_t bar;
+
+void CanDeadLock() {
+  // Don't bother with leaks, we try to trigger allocator or lsan deadlock.
+  __lsan::ScopedDisabler disable;
+  char *volatile p = new char[10];
+  __lsan_do_recoverable_leak_check();
+  delete[] p;
+}
+
+// Prevent stack buffer cleanup by instrumentation.
+#define NOSAN __attribute__((no_sanitize("address", "hwaddress", "memory")))
+
+NOSAN static void *inparent(void *arg) {
+  fprintf(stderr, "inparent %d\n", gettid());
+
+  char t[kBufferSize];
+  make_mem_bad(t, sizeof(t));
+
+  pthread_barrier_wait(&bar);
+
+  for (;;)
+CanDeadLock();
+
+  return 0;
+}
+
+NOSAN static void *inchild(void *arg) {
+  char t[kBufferSize];
+  check_mem_is_good(t, sizeof(t));
+  CanDeadLock();
+  return 0;
+}
+
+int main(void) {
+  pid_t pid;
+
+  pthread_barrier_init(&bar, nullptr, 2);
+  pthread_t thread_id;
+  while (pthread_create(&thread_id, 0, &inparent, 0) != 0) {
+  }
+  pthread_barrier_wait(&bar);
+
+  pid = fork();
+  switch (pid) {
+  case -1:
+perror("fork");
+return -1;
+  case 0:
+while (pthread_create(&thread_id, 0, &inchild, 0) != 0) {
+}
+break;
+  default: {
+fprintf(stderr, "fork %d\n", pid);
+int status;
+while (waitpid(-1, &status, __WALL) != pid) {
+}
+assert(WIFEXITED(status) && WEXITSTATUS(status) == 0);
+break;
+  }
+  }
+
+  return 0;
+}
diff --git a/compiler-rt/test/sanitizer_common/sanitizer_specific.h 
b/compiler-rt/test/sanitizer_common/sanitizer_specific.h
index 1a802020cfd668..963d91cb305f60 100644
--- a/compiler-rt/test/sanitizer_common/sanitizer_specific.h
+++ b/compiler-rt/test/sanitizer_common/sanitizer_specific.h
@@ -1,6 +1,12 @@
 #ifndef __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__
 #define __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__
 
+#include 
+
+__attribute__((weak)) int __lsan_do_recoverable_leak_check() { return 0; }
+__attribute__((weak)) void __lsan_disable(void) {}
+__attribute__((weak)) void __lsan_enable(void) {}
+
 #ifndef __has_feature
 #  define __has_feature(x) 0
 #endif
@@ -10,6 +16,8 @@
 static void check_mem_is_good(void *p, size_t s) {
   __msan_check_mem_is_initialized(p, s);
 }
+static void make_mem_good(void *p, size_t s) { __msan_unpoison(p, s); }
+static void make_mem_bad(void *p, size_t s) { __msan_poison(p, s); }
 #elif __has_feature(address_sanitizer)
 #  include 
 #  include 
@@ -17,8 +25,16 @@ static void check_mem_is_good(void *p, size_t s) {
   if (__asan_region_is_poisoned(p, s))
 abort();
 }
+static void make_mem_good(void *p, size_t s) {
+  __asan_unpoison_memory_region(p, s);
+}
+static void make_mem_bad(void *p, size_t s) {
+  __asan_poison_memory_region(p, s);
+}
 #else
 static void check_mem_is_good(void *p, size_t s) {}
+static void make_mem_good(void *p, size_t s) {}
+static void make_mem_bad(void *p, size_t s) {}
 #endif
 
 #endif // __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__
\ No newline at end of file

>From 5c4317f5610316cfe5550f1366e1323116529799 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Tue, 12 Dec 2023 17:09:13 -0800
Subject: [PATCH 2/4] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20introduced=20through=20rebase?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 compiler-rt/test/sanitizer_common/sanitizer_specific.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/test/sanitizer_co

[clang] [Sema] atomic_compare_exchange: check failure memory order (PR #74959)

2023-12-12 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> Did this change anything for the `scoped_atomic_compare_exchange_n` variant I 
> added recently?

I am not familiar with the scoped atomic xchg stuff, but this patch needs to 
update one `__hip_atomic_compare_exchange_weak` test:
```
  flag = __hip_atomic_compare_exchange_weak(ptr, &val, desired, 
__ATOMIC_RELAXED, __ATOMIC_ACQ_REL, __HIP_MEMORY_SCOPE_SINGLETHREAD); // 
expected-warning {{failure memory order argument to atomic operation is 
invalid}}
```

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


[mlir] [clang] [lldb] [compiler-rt] [llvm] [test][sanitizer] Allow fork_threaded test on Msan, Tsan, Ubsan (PR #75260)

2023-12-12 Thread Vitaly Buka via cfe-commits

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


[mlir] [clang] [lldb] [compiler-rt] [llvm] [test][sanitizer] Allow fork_threaded test on Msan, Tsan (PR #75260)

2023-12-12 Thread Vitaly Buka via cfe-commits

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


[mlir] [clang] [lldb] [compiler-rt] [llvm] [sanitizer] Pre-commit disabled test for fork (PR #75257)

2023-12-12 Thread Vitaly Buka via cfe-commits

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


[mlir] [clang] [lldb] [compiler-rt] [llvm] [sanitizer] Pre-commit disabled test for fork (PR #75257)

2023-12-12 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/75257

>From db7b2abf12add7fcbac65c7f7fad5f60be58de2f Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Tue, 12 Dec 2023 16:08:56 -0800
Subject: [PATCH 1/5] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 .../TestCases/Posix/fork_threaded.cpp | 86 +++
 .../sanitizer_common/sanitizer_specific.h | 16 
 2 files changed, 102 insertions(+)
 create mode 100644 
compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp

diff --git 
a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp 
b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp
new file mode 100644
index 0..d5c60bbb7c943
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp
@@ -0,0 +1,86 @@
+// RUN: %clangxx -O0 %s -o %t && %env_tool_opts=die_after_fork=0 %run %t
+
+// UNSUPPORTED: *
+
+// Forking in multithread environment is unsupported. However we already have
+// some workarounds, and will add more, so this is the test.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "sanitizer_common/sanitizer_specific.h"
+
+static const size_t kBufferSize = 1 << 20;
+
+static void *background(void *arg) { return nullptr; }
+
+pthread_barrier_t bar;
+
+void CanDeadLock() {
+  // Don't bother with leaks, we try to trigger allocator or lsan deadlock.
+  __lsan::ScopedDisabler disable;
+  char *volatile p = new char[10];
+  __lsan_do_recoverable_leak_check();
+  delete[] p;
+}
+
+// Prevent stack buffer cleanup by instrumentation.
+#define NOSAN __attribute__((no_sanitize("address", "hwaddress", "memory")))
+
+NOSAN static void *inparent(void *arg) {
+  fprintf(stderr, "inparent %d\n", gettid());
+
+  char t[kBufferSize];
+  make_mem_bad(t, sizeof(t));
+
+  pthread_barrier_wait(&bar);
+
+  for (;;)
+CanDeadLock();
+
+  return 0;
+}
+
+NOSAN static void *inchild(void *arg) {
+  char t[kBufferSize];
+  check_mem_is_good(t, sizeof(t));
+  CanDeadLock();
+  return 0;
+}
+
+int main(void) {
+  pid_t pid;
+
+  pthread_barrier_init(&bar, nullptr, 2);
+  pthread_t thread_id;
+  while (pthread_create(&thread_id, 0, &inparent, 0) != 0) {
+  }
+  pthread_barrier_wait(&bar);
+
+  pid = fork();
+  switch (pid) {
+  case -1:
+perror("fork");
+return -1;
+  case 0:
+while (pthread_create(&thread_id, 0, &inchild, 0) != 0) {
+}
+break;
+  default: {
+fprintf(stderr, "fork %d\n", pid);
+int status;
+while (waitpid(-1, &status, __WALL) != pid) {
+}
+assert(WIFEXITED(status) && WEXITSTATUS(status) == 0);
+break;
+  }
+  }
+
+  return 0;
+}
\ No newline at end of file
diff --git a/compiler-rt/test/sanitizer_common/sanitizer_specific.h 
b/compiler-rt/test/sanitizer_common/sanitizer_specific.h
index 1a802020cfd66..963d91cb305f6 100644
--- a/compiler-rt/test/sanitizer_common/sanitizer_specific.h
+++ b/compiler-rt/test/sanitizer_common/sanitizer_specific.h
@@ -1,6 +1,12 @@
 #ifndef __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__
 #define __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__
 
+#include 
+
+__attribute__((weak)) int __lsan_do_recoverable_leak_check() { return 0; }
+__attribute__((weak)) void __lsan_disable(void) {}
+__attribute__((weak)) void __lsan_enable(void) {}
+
 #ifndef __has_feature
 #  define __has_feature(x) 0
 #endif
@@ -10,6 +16,8 @@
 static void check_mem_is_good(void *p, size_t s) {
   __msan_check_mem_is_initialized(p, s);
 }
+static void make_mem_good(void *p, size_t s) { __msan_unpoison(p, s); }
+static void make_mem_bad(void *p, size_t s) { __msan_poison(p, s); }
 #elif __has_feature(address_sanitizer)
 #  include 
 #  include 
@@ -17,8 +25,16 @@ static void check_mem_is_good(void *p, size_t s) {
   if (__asan_region_is_poisoned(p, s))
 abort();
 }
+static void make_mem_good(void *p, size_t s) {
+  __asan_unpoison_memory_region(p, s);
+}
+static void make_mem_bad(void *p, size_t s) {
+  __asan_poison_memory_region(p, s);
+}
 #else
 static void check_mem_is_good(void *p, size_t s) {}
+static void make_mem_good(void *p, size_t s) {}
+static void make_mem_bad(void *p, size_t s) {}
 #endif
 
 #endif // __SANITIZER_COMMON_SANITIZER_SPECIFIC_H__
\ No newline at end of file

>From 3ceddfbc5d928a8297e41923cfb3ac63d0af2a03 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Tue, 12 Dec 2023 16:11:58 -0800
Subject: [PATCH 2/5] newline

Created using spr 1.3.4
---
 .../test/sanitizer_common/TestCases/Posix/fork_threaded.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp 
b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp
index d5c60bbb7c943..2264c55816638 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_

[clang-tools-extra] [NFC][clang] add a clang tool for mlir refactor (PR #75279)

2023-12-12 Thread via cfe-commits

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


[clang-tools-extra] [NFC][clang] add a clang tool for mlir refactor (PR #75279)

2023-12-12 Thread via cfe-commits

https://github.com/lipracer created 
https://github.com/llvm/llvm-project/pull/75279

None

>From bd1182b28ac62bddabe7b31e1913295ba169 Mon Sep 17 00:00:00 2001
From: lipracer 
Date: Wed, 13 Dec 2023 11:37:12 +0800
Subject: [PATCH] [NFC][clang] add a clang tool for mlir refactor

---
 clang-tools-extra/CMakeLists.txt  |   1 +
 .../mlir-cast-refactor/CMakeLists.txt |  18 ++
 .../mlir-cast-refactor/MlirCastRefactor.cpp   | 178 ++
 3 files changed, 197 insertions(+)
 create mode 100644 clang-tools-extra/mlir-cast-refactor/CMakeLists.txt
 create mode 100644 clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp

diff --git a/clang-tools-extra/CMakeLists.txt b/clang-tools-extra/CMakeLists.txt
index 6a3f741721ee6..44e4f02dca332 100644
--- a/clang-tools-extra/CMakeLists.txt
+++ b/clang-tools-extra/CMakeLists.txt
@@ -27,6 +27,7 @@ add_subdirectory(include-cleaner)
 add_subdirectory(pp-trace)
 add_subdirectory(pseudo)
 add_subdirectory(tool-template)
+add_subdirectory(mlir-cast-refactor)
 
 option(CLANG_TOOLS_EXTRA_INCLUDE_DOCS "Generate build targets for the Clang 
Extra Tools docs."
   ${LLVM_INCLUDE_DOCS})
diff --git a/clang-tools-extra/mlir-cast-refactor/CMakeLists.txt 
b/clang-tools-extra/mlir-cast-refactor/CMakeLists.txt
new file mode 100644
index 0..ebdabf23fc53c
--- /dev/null
+++ b/clang-tools-extra/mlir-cast-refactor/CMakeLists.txt
@@ -0,0 +1,18 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_executable(mlirCastRefactor
+  MlirCastRefactor.cpp
+  )
+target_link_libraries(mlirCastRefactor
+  PRIVATE
+clangAST
+clangBasic
+clangFormat
+clangFrontend
+clangLex
+clangRewrite
+clangSerialization
+clangTooling
+clangToolingCore
+clangToolingRefactoring
+  )
\ No newline at end of file
diff --git a/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp 
b/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp
new file mode 100644
index 0..1cdf12a894d42
--- /dev/null
+++ b/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp
@@ -0,0 +1,178 @@
+//===-- MlirCastRefactor.cpp - mlir refactor implementation 
---===//
+//
+// 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
+//
+//===--===//
+
+// Declares clang::SyntaxOnlyAction.
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+// Declares llvm::cl::extrahelp.
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/Refactoring/AtomicChange.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace clang::tooling;
+using namespace llvm;
+
+// Apply a custom category to all command-line options so that they are the
+// only ones displayed.
+static llvm::cl::OptionCategory MyToolCategory("my-tool options");
+static cl::opt target_type("target-type",
+cl::desc("refactoring type name"),
+cl::value_desc("type name"),
+cl::ValueRequired, cl::NotHidden,
+cl::cat(MyToolCategory));
+
+// CommonOptionsParser declares HelpMessage with a description of the common
+// command-line options related to the compilation database and input files.
+// It's nice to have this help message in all tools.
+static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
+
+// A help message for this specific tool can be added afterwards.
+static cl::extrahelp MoreHelp("\nMore help text...\n");
+
+using namespace clang;
+using namespace clang::ast_matchers;
+
+class MemberFunctionCallMatcher : public MatchFinder::MatchCallback {
+public:
+  void run(const MatchFinder::MatchResult &Result) override {
+if (const CXXMemberCallExpr *MemberCall =
+Result.Nodes.getNodeAs("memberCall")) {
+  auto objExpr = MemberCall->getImplicitObjectArgument();
+  auto endLoc = MemberCall->getExprLoc();
+
+  auto exprRange = objExpr->getSourceRange();
+
+  SourceLocation StartLoc = objExpr->getBeginLoc();
+
+  const SourceManager &SM = *Result.SourceManager;
+  const char *StartPtr = SM.getCharacterData(StartLoc);
+  const char *EndPtr = SM.getCharacterData(endLoc);
+
+  tooling::AtomicChange change(*Result.SourceManager,
+   MemberCall->getExprLoc());
+  const auto *ME = Result.Nodes.getNodeAs("member");
+  size_t dropbackCount = ME->isArrow() ? 2 : 1;
+
+  {
+auto length = EndPtr - StartPtr;
+objExprStrings.emplace_back(StartPtr, length);
+change.replace(*Result.SourceManager, StartLoc, EndPtr - StartPtr, ""

[clang] [llvm] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)

2023-12-12 Thread via cfe-commits

eddyz87 wrote:

Some additional details on BPF verifier failure.
Consider the following example:

```llvm
@a = global i32 0, align 4
@g = global i32 0, align 4

define i64 @foo() {
entry:
  %a = load i32, ptr @a
  %a.cmp = icmp ugt i32 %a, 32
  br i1 %a.cmp, label %end, label %l1 ; establish %a in range [0, 32]

l1:
  %g = load i32, ptr @g
  %g.cmp.1 = icmp sgt i32 %g, -1
  %g.cmp.a = icmp slt i32 %g, %a
  %cond = and i1 %g.cmp.a, %g.cmp.1
  br i1 %cond, label %l2, label %end  ; establish %g in range [0, %a]

l2:
  %g.64 = sext i32 %g to i64
  ret i64 %g.64

end:
  ret i64 0
}
```

Also consider the following opt command:

```
opt -passes=instcombine,correlated-propagation -mtriple=bpf-pc-linux -S -o - 
t.ll
```

Before this MR generated code looked as follows:

```llvm
...
entry:
  %a = load i32, ptr @a, align 4
  %a.cmp = icmp ugt i32 %a, 32
  br i1 %a.cmp, label %end, label %l1

l1:
  %g = load i32, ptr @g, align 4
  %g.cmp.1 = icmp sgt i32 %g, -1
  %g.cmp.a = icmp slt i32 %g, %a
  %cond = and i1 %g.cmp.a, %g.cmp.1
  br i1 %cond, label %l2, label %end

l2:
  %g.64 = zext nneg i32 %g to i64 ; <--- note zext nneg
  ret i64 %g.64
...
```

After this MR generated code looks as follows:

```llvm
...
entry:
  %a = load i32, ptr @a, align 4
  %a.cmp = icmp ugt i32 %a, 32
  br i1 %a.cmp, label %end, label %l1

l1:
  %g = load i32, ptr @g, align 4
  %cond = icmp ult i32 %g, %a ; <--- conditions merged by instcombine
  br i1 %cond, label %l2, label %end

l2:
  %g.64 = sext i32 %g to i64  ; <--- note sext
  ret i64 %g.64
...
```

Updated `instcombine` replaces `%g.cmp.1` and `%g.cmp.a` with a single `ult`, 
however `correlated-propagation` pass can no longer infer that `%g` is 
non-negative and thus does not replace `g.64 = sext` by `%g.64 = zext nneg`.
Probably because of variable `%a`, used in `%cond = icmp` (replacing this 
variable by a constant `32` allows `correlated-propagation` to add `zext`). As 
far as I understand, previously non-negativity of `%g` was inferred from 
`%g.cmp.1 = icmp sgt i32 %g, -1` condition, which is now deleted.

I think that there are no issues with transformation applied by updated 
`instcombine`.
To resolve BPF regression we either need to extend `correlated-propagation` to 
better figure out range bounds (don't know how hard might that be), or teach 
verifier to understand that `sext` in this situation is equivalent to `zext`.


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


[clang] [llvm] [CodeGen][arm64e] Add methods and data members to Address, which are needed to authenticate signed pointers (PR #67454)

2023-12-12 Thread Eli Friedman via cfe-commits


@@ -232,19 +232,19 @@ static Value *MakeBinaryAtomicValue(
 
 static Value *EmitNontemporalStore(CodeGenFunction &CGF, const CallExpr *E) {
   Value *Val = CGF.EmitScalarExpr(E->getArg(0));
-  Value *Address = CGF.EmitScalarExpr(E->getArg(1));
+  Address Addr = CGF.EmitPointerWithAlignment(E->getArg(1));
 
   Val = CGF.EmitToMemory(Val, E->getArg(0)->getType());
-  LValue LV = CGF.MakeNaturalAlignAddrLValue(Address, E->getArg(0)->getType());
+  LValue LV = CGF.MakeAddrLValue(Addr, E->getArg(0)->getType());
   LV.setNontemporal(true);
   CGF.EmitStoreOfScalar(Val, LV, false);
   return nullptr;
 }
 
 static Value *EmitNontemporalLoad(CodeGenFunction &CGF, const CallExpr *E) {
-  Value *Address = CGF.EmitScalarExpr(E->getArg(0));
+  Address Addr = CGF.EmitPointerWithAlignment(E->getArg(0));
 
-  LValue LV = CGF.MakeNaturalAlignAddrLValue(Address, E->getType());
+  LValue LV = CGF.MakeAddrLValue(Addr, E->getType());

efriedma-quic wrote:

EmitPointerWithAlignment tries to compute the alignment based on the underlying 
lvalue.  This can be higher or lower than the natural alignment of the type.  
Say you have something like `vec f() { struct S { char c[16]; } x; return 
__temporal_load((vec*)x.c); }`.  It looks through the cast, sees the field is 
unaligned, and therefore concludes the pointer is unaligned.  This is arguably 
an improvement, but it's a significant change to the generated code.

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


[clang] [clang-format] Fix parsing of `operator<() {}` (PR #75144)

2023-12-12 Thread via cfe-commits

https://github.com/XDeme updated https://github.com/llvm/llvm-project/pull/75144

>From dddc20d967498c739baedb8d67303a28596f09e0 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Tue, 12 Dec 2023 03:06:56 -0300
Subject: [PATCH 1/2] Fix operator<() parsing

---
 clang/lib/Format/TokenAnnotator.cpp   |  9 +
 clang/unittests/Format/FormatTest.cpp |  7 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 11 +++
 3 files changed, 27 insertions(+)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index eaccb5881ca30..957612088c7bb 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -23,6 +23,9 @@
 
 namespace clang {
 namespace format {
+static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current,
+  const AnnotatedLine &Line,
+  FormatToken *&ClosingParen);
 
 static bool mustBreakAfterAttributes(const FormatToken &Tok,
  const FormatStyle &Style) {
@@ -164,6 +167,12 @@ class AnnotatingParser {
TT_OverloadedOperatorLParen))) {
 return false;
   }
+  FormatToken *ClosingParen = nullptr;
+  if (Previous.Previous->is(tok::kw_operator) &&
+  isFunctionDeclarationName(Style.isCpp(), *Previous.Previous, Line,
+ClosingParen)) {
+return false;
+  }
 }
 
 FormatToken *Left = CurrentToken->Previous;
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 24b2fd599dc39..79013a473a7c2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -11727,6 +11727,13 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
"  void func(type &a) { a & member; }\n"
"  anotherType &member;\n"
"}");
+
+  Style.ReferenceAlignment = FormatStyle::RAS_Left;
+  verifyFormat("class Foo {\n"
+   "  void operator<(Foo&) {}\n"
+   "  Foo& f;\n"
+   "};",
+   Style);
 }
 
 TEST_F(FormatTest, UnderstandsAttributes) {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 65b1f0f4b5765..58a782f909d6a 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -298,6 +298,17 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
   ASSERT_EQ(Tokens.size(), 12u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::identifier, TT_TypeName);
   EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
+
+  Tokens = annotate("class Foo {\n"
+"void operator<(Foo&) {}\n"
+"Foo& f;\n"
+"};");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[5], tok::less, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_OverloadedOperatorLParen);
+  EXPECT_TOKEN(Tokens[10], tok::l_brace, TT_FunctionLBrace);
+  EXPECT_TOKEN(Tokens[13], tok::amp, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {

>From 8e5f57d51f4d542ff6bb4bf5faab04ceb709f8d0 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Tue, 12 Dec 2023 23:39:52 -0300
Subject: [PATCH 2/2] Addresses comments

---
 clang/lib/Format/TokenAnnotator.cpp | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 957612088c7bb..bcf46d7ef4602 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -23,9 +23,6 @@
 
 namespace clang {
 namespace format {
-static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current,
-  const AnnotatedLine &Line,
-  FormatToken *&ClosingParen);
 
 static bool mustBreakAfterAttributes(const FormatToken &Tok,
  const FormatStyle &Style) {
@@ -167,10 +164,8 @@ class AnnotatingParser {
TT_OverloadedOperatorLParen))) {
 return false;
   }
-  FormatToken *ClosingParen = nullptr;
   if (Previous.Previous->is(tok::kw_operator) &&
-  isFunctionDeclarationName(Style.isCpp(), *Previous.Previous, Line,
-ClosingParen)) {
+  CurrentToken->is(tok::l_paren)) {
 return false;
   }
 }

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


[libcxx] [libc] [clang] [clang-tools-extra] [compiler-rt] [flang] [llvm] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)

2023-12-12 Thread Bill Wendling via cfe-commits


@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const 
ArraySubscriptExpr *E,
   ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true);
 else
   ArrayLV = EmitLValue(Array);
+
 auto *Idx = EmitIdxAfterBase(/*Promote*/true);
 
+if (SanOpts.has(SanitizerKind::ArrayBounds)) {

bwendling wrote:

> You should be able to refactor some code out of 
> CodeGenFunction::EmitMemberExpr so it's not a completely independent codepath.

I could use it as a template, but refactoring probably won't work very well, 
because even if I could call it to generate the FAM array access, I don't have 
an Expr for the count.

> the nastiest problems are caused by one piece of code making assumptions 
> about how an apparently unrelated part of the code behaves.

This is why I'm being very stubborn about *not* skipping the existing Emit 
functions. The assumption we're making are that generating the GEPs by hand for 
both fields is "easy". We can make that assumption for the `count` field, 
because of the expectations I mentioned above (how it's at the top-level of the 
struct, etc.). But I don't want to make those assumptions about the flexible 
array field.

As it turns out, I should be able to use `getSourceElementType` on a GEP to 
know when to stop skipping GEPs.

Keep in mind, the code we generate is for bounds checking, so we have a 
fallback if we're unable to generate a proper bounds check using the `count`. 
I.e., if we run into something unexpected, we can abort the bounds checking 
generation.

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


[clang] [HLSL] Vector standard conversions (PR #71098)

2023-12-12 Thread Eli Friedman via cfe-commits


@@ -1422,6 +1424,9 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value 
*Src, QualType SrcType,
 return Builder.CreateVectorSplat(NumElements, Src, "splat");
   }
 
+  if (SrcType->isExtVectorType() && DstType->isExtVectorType())
+return EmitVectorElementConversion(SrcType, DstType, Src);

efriedma-quic wrote:

EmitScalarConversion is a mess; we have cast kinds, but we never taught this 
part of CodeGen to use them, so it just guesses the cast kind based on the 
source and destination types.  This is particularly bad for vectors, since it's 
often possible to cast them in multiple different ways; I'm not confident this 
change won't have unintended side-effects.  Please fix the code for the 
relevant cast kinds to avoid going through EmitScalarConversion.

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


[clang] [clang-format] Fix parsing of `operator<() {}` (PR #75144)

2023-12-12 Thread Owen Pan via cfe-commits


@@ -164,6 +167,12 @@ class AnnotatingParser {
TT_OverloadedOperatorLParen))) {
 return false;
   }
+  FormatToken *ClosingParen = nullptr;
+  if (Previous.Previous->is(tok::kw_operator) &&
+  isFunctionDeclarationName(Style.isCpp(), *Previous.Previous, Line,
+ClosingParen)) {

owenca wrote:

It seems that the following would suffice:
```suggestion
  if (Previous.Previous->is(tok::kw_operator) &&
  CurrentToken->is(tok::l_paren)) {
```

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


[clang] [Cygwin] Reduced number of inline elements of CallArgList. (PR #74977)

2023-12-12 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

Adding workarounds to LLVM for host compiler bugs is something we do from time 
to time, but any such workarounds need to be clearly documented in the source 
code, and as narrowly targeted as possible (for example, under an `#ifdef 
__CYGWIN__`).

Since this is an issue with the latest version of gcc, please also report it to 
the gcc bugtracker.

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


[clang] [Sema] atomic_compare_exchange: check failure memory order (PR #74959)

2023-12-12 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

Did this change anything for the `scoped_atomic_compare_exchange_n` variant I 
added recently?

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


[clang] [RISCV] Reduce the size of the index used for RVV intrinsics. NFC (PR #74906)

2023-12-12 Thread Craig Topper via cfe-commits

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


[clang] 0523bf1 - [RISCV] Reduce the size of the index used for RVV intrinsics. NFC (#74906)

2023-12-12 Thread via cfe-commits

Author: Craig Topper
Date: 2023-12-12T17:40:54-08:00
New Revision: 0523bf1eca4475edafc8aab830c2ce48b01900c3

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

LOG: [RISCV] Reduce the size of the index used for RVV intrinsics. NFC (#74906)

Rather than using size_t, use uint32_t. We don't have more than 4
billion intrinsics.

Added: 


Modified: 
clang/lib/Sema/SemaRISCVVectorLookup.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp 
b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
index 0d411fca0f9c82..e4642e4da016a4 100644
--- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -43,7 +43,7 @@ struct RVVIntrinsicDef {
 
 struct RVVOverloadIntrinsicDef {
   // Indexes of RISCVIntrinsicManagerImpl::IntrinsicList.
-  SmallVector Indexes;
+  SmallVector Indexes;
 };
 
 } // namespace
@@ -162,7 +162,7 @@ class RISCVIntrinsicManagerImpl : public 
sema::RISCVIntrinsicManager {
   // List of all RVV intrinsic.
   std::vector IntrinsicList;
   // Mapping function name to index of IntrinsicList.
-  StringMap Intrinsics;
+  StringMap Intrinsics;
   // Mapping function name to RVVOverloadIntrinsicDef.
   StringMap OverloadIntrinsics;
 
@@ -174,7 +174,7 @@ class RISCVIntrinsicManagerImpl : public 
sema::RISCVIntrinsicManager {
 
   // Create FunctionDecl for a vector intrinsic.
   void CreateRVVIntrinsicDecl(LookupResult &LR, IdentifierInfo *II,
-  Preprocessor &PP, unsigned Index,
+  Preprocessor &PP, uint32_t Index,
   bool IsOverload);
 
   void ConstructRVVIntrinsics(ArrayRef Recs,
@@ -386,7 +386,7 @@ void RISCVIntrinsicManagerImpl::InitRVVIntrinsic(
  Record.HasFRMRoundModeOp);
 
   // Put into IntrinsicList.
-  size_t Index = IntrinsicList.size();
+  uint32_t Index = IntrinsicList.size();
   IntrinsicList.push_back({BuiltinName, Signature});
 
   // Creating mapping to Intrinsics.
@@ -403,7 +403,7 @@ void RISCVIntrinsicManagerImpl::InitRVVIntrinsic(
 void RISCVIntrinsicManagerImpl::CreateRVVIntrinsicDecl(LookupResult &LR,
IdentifierInfo *II,
Preprocessor &PP,
-   unsigned Index,
+   uint32_t Index,
bool IsOverload) {
   ASTContext &Context = S.Context;
   RVVIntrinsicDef &IDef = IntrinsicList[Index];



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


[libcxx] [clang] [PowerPC] Emit libcall to frexpl for calls to frexp(ppcDoublDouble) (PR #75226)

2023-12-12 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic commented:

If the PPC backend maintainers intend to deprecate ppc-long-double support in 
LLVM, I guess we can hack clang to limp along until the cut happens.

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


[libcxx] [clang] [PowerPC] Emit libcall to frexpl for calls to frexp(ppcDoublDouble) (PR #75226)

2023-12-12 Thread Eli Friedman via cfe-commits


@@ -3410,9 +3419,15 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
{ Src0->getType(), Src1->getType() });
 return RValue::get(Builder.CreateCall(F, { Src0, Src1 }));
   }
+  case Builtin::BI__builtin_frexpl: {
+auto &Triple = getTarget().getTriple();
+if (Triple.isPPC() && Triple.isOSLinux() &&

efriedma-quic wrote:

Checking isOSLinux() seems more likely to cause trouble than to solve anything; 
checking the floating-point format should be sufficient to ensure this doesn't 
trigger by accident.

Maybe add a brief comment here explaining why this special case is necessary.

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


[libcxx] [clang] [PowerPC] Emit libcall to frexpl for calls to frexp(ppcDoublDouble) (PR #75226)

2023-12-12 Thread Eli Friedman via cfe-commits


@@ -149,6 +153,11 @@ llvm::Constant *CodeGenModule::getBuiltinLibFunction(const 
FunctionDecl *FD,
 &getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEquad() &&
 F128Builtins.contains(BuiltinID))
   Name = F128Builtins[BuiltinID];
+else if (getTriple().isPPC() && getTriple().isOSLinux() &&
+ &getTarget().getLongDoubleFormat() ==
+ &llvm::APFloat::PPCDoubleDouble() &&
+ PPCDoubleDoubleBuiltins.contains(BuiltinID))
+  Name = PPCDoubleDoubleBuiltins[BuiltinID];

efriedma-quic wrote:

Does adding this codepath actually change the computed name here?  The default 
codepath should just chop off the beginning of the string "__builtin_frexpl" to 
produce the same thing.

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


[libcxx] [clang] [PowerPC] Emit libcall to frexpl for calls to frexp(ppcDoublDouble) (PR #75226)

2023-12-12 Thread Eli Friedman via cfe-commits

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


[clang-tools-extra] [libc] [llvm] [libcxx] [clang] [compiler-rt] [flang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)

2023-12-12 Thread Eli Friedman via cfe-commits


@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const 
ArraySubscriptExpr *E,
   ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true);
 else
   ArrayLV = EmitLValue(Array);
+
 auto *Idx = EmitIdxAfterBase(/*Promote*/true);
 
+if (SanOpts.has(SanitizerKind::ArrayBounds)) {

efriedma-quic wrote:

Yes.  You should be able to refactor some code out of 
CodeGenFunction::EmitMemberExpr so it's not a completely independent codepath.

I mean, I see why you're concerned about re-implementing EmitMemberExpr, but 
fragility isn't just about simplifying the control flow within the compiler; 
the nastiest problems are caused by one piece of code making assumptions about 
how an apparently unrelated part of the code behaves.

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


[clang] [Windows] Add git-clang-format wrapper bat file (PR #69228)

2023-12-12 Thread Owen Pan via cfe-commits

owenca wrote:

See #75268.

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


[clang] [clang-format] Fix a bug in git-clang-format.bat (PR #75268)

2023-12-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Pass the fully-qualified path name (less the file extension) of
git-clang-format.bat to py so that it can be run from anywhere.

Fixes #75265.

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


1 Files Affected:

- (modified) clang/tools/clang-format/git-clang-format.bat (+1-1) 


``diff
diff --git a/clang/tools/clang-format/git-clang-format.bat 
b/clang/tools/clang-format/git-clang-format.bat
index d4bc5172989cb..9965cd4312fe3 100644
--- a/clang/tools/clang-format/git-clang-format.bat
+++ b/clang/tools/clang-format/git-clang-format.bat
@@ -1 +1 @@
-py -3 git-clang-format %*
+py -3 %~pn0 %*

``




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


[clang] [clang-format] Fix a bug in git-clang-format.bat (PR #75268)

2023-12-12 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/75268

Pass the fully-qualified path name (less the file extension) of
git-clang-format.bat to py so that it can be run from anywhere.

Fixes #75265.

>From 1eb01de0a5bcd20c903348ecccbc559751d97be5 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 12 Dec 2023 16:57:21 -0800
Subject: [PATCH] [clang-format] Fix a bug in git-clang-format.bat

Pass the fully-qualified path name (less the file extension) of
git-clang-format.bat to py so that it can be run from anywhere.

Fixes #75265.
---
 clang/tools/clang-format/git-clang-format.bat | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/clang-format/git-clang-format.bat 
b/clang/tools/clang-format/git-clang-format.bat
index d4bc5172989cb..9965cd4312fe3 100644
--- a/clang/tools/clang-format/git-clang-format.bat
+++ b/clang/tools/clang-format/git-clang-format.bat
@@ -1 +1 @@
-py -3 git-clang-format %*
+py -3 %~pn0 %*

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


[clang] [clang] Add size filter for stack auto init (PR #74777)

2023-12-12 Thread Eli Friedman via cfe-commits


@@ -1759,20 +1759,29 @@ void 
CodeGenFunction::emitZeroOrPatternForAutoVarInit(QualType type,
   const VarDecl &D,
   Address Loc) {
   auto trivialAutoVarInit = getContext().getLangOpts().getTrivialAutoVarInit();
+  auto trivialAutoVarInitSizeBound =
+  getContext().getLangOpts().TrivialAutoVarInitSizeBound;
   CharUnits Size = getContext().getTypeSizeInChars(type);
   bool isVolatile = type.isVolatileQualified();
   if (!Size.isZero()) {
+auto allocSize = 
CGM.getDataLayout().getTypeAllocSize(Loc.getElementType());

efriedma-quic wrote:

Ignoring a few less common cases (C++ classes with non-trivial constructors, 
unions, self-referencing initializers), variable initialization is generally is 
an all-or-nothing proposition. If you write something like `struct X { int 
x,y,z; }; struct X x[100] = {0};`, that initializes every field of every 
element.  What examples are you worried about?

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


[clang] [Sema] atomic_compare_exchange: check failure memory order (PR #74959)

2023-12-12 Thread Fangrui Song via cfe-commits

MaskRay wrote:

@jyknight If this looks good, mind changing the status from "request changes"? 
:)

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


[clang-tools-extra] [compiler-rt] [libcxx] [clang] [libc] [llvm] [flang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)

2023-12-12 Thread Bill Wendling via cfe-commits


@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const 
ArraySubscriptExpr *E,
   ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true);
 else
   ArrayLV = EmitLValue(Array);
+
 auto *Idx = EmitIdxAfterBase(/*Promote*/true);
 
+if (SanOpts.has(SanitizerKind::ArrayBounds)) {

bwendling wrote:

So just to be clear, you want me to bypass this code:

```
LValue ArrayLV;
// For simple multidimensional array indexing, set the 'accessed' flag for
// better bounds-checking of the base expression.
if (const auto *ASE = dyn_cast(Array))
  ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true);
else
  ArrayLV = EmitLValue(Array);
auto *Idx = EmitIdxAfterBase(/*Promote*/true);
```

and instead calculate the base pointer from the `Array` that will point to both 
`count` and `array`. Then emit that pointer, and then append to that GEPs to 
access `count` and `array` that I calculate by hand?

That sounds incredibly fragile, given the complexity of both of the above 
`Emit*Expr` methods. But if that will finally get some approval, I'll cobble it 
together. It'll almost certainly fail for some side case, but I'm stupid, so 
what do I know.

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


[mlir] [clang-tools-extra] [lldb] [llvm] [libc] [libcxx] [clang] [libcxxabi] [libunwind] [compiler-rt] [flang] [lld] [libc++] Implement ranges::contains (PR #65148)

2023-12-12 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/65148

>From 02e9afd761228f401df4d9f8dfaaca44ffae0c6e Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 31 Aug 2023 20:08:32 +
Subject: [PATCH 01/21] [libc++] Implement ranges::contains

Differential Revision: https://reviews.llvm.org/D159232
---
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__algorithm/ranges_contains.h  |  60 ++
 libcxx/include/algorithm  |   9 +
 ...obust_against_copying_projections.pass.cpp |   4 +
 .../alg.contains/ranges.contains.pass.cpp | 190 ++
 .../niebloid.compile.pass.cpp |   1 +
 6 files changed, 265 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 77a7269121ec14..024aa8959fb720 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -104,6 +104,7 @@ set(files
   __algorithm/ranges_any_of.h
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
+  __algorithm/ranges_contains.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains.h 
b/libcxx/include/__algorithm/ranges_contains.h
new file mode 100644
index 00..647b7ea34be342
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains.h
@@ -0,0 +1,60 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+
+#include <__algorithm/in_in_result.h>
+#include <__algorithm/ranges_find.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains {
+struct __fn {
+  template  _Sent, class _Type, 
class _Proj = identity>
+requires indirect_binary_predicate, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = 
{}) const {
+return ranges::find(std::move(__first), std::move(__last), __value, 
std::ref(__proj)) != __last;
+  }
+
+  template 
+requires indirect_binary_predicate, _Proj>, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) const {
+return ranges::find(ranges::begin(__range), ranges::end(__range), __value, 
std::ref(__proj)) != ranges::end(__range);
+  }
+};
+} // namespace __contains
+inline namespace __cpo {
+inline constexpr auto contains = __contains::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER >= 23
+
+#endif // _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index 76e0d22bf73ef8..003bf132b38b4d 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -226,6 +226,14 @@ namespace ranges {
   template
 using copy_backward_result = in_out_result;
 // since C++20
 
+  template S, class T, class Proj = identity>
+requires indirect_binary_predicate, 
const T*>
+constexpr bool ranges::contains(I first, S last, const T& value, Proj proj 
= {});   // since C++23
+
+  template
+requires indirect_binary_predicate, Proj>, const T*>
+constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {});
 // since C++23
+
   template S, weakly_incrementable O>
 requires indirectly_copyable
 constexpr ranges::copy_result ranges::copy(I first, S last, O 
result);// since C++20
@@ -1827,6 +1835,7 @@ template 
 #include <__algorithm/ranges_any_of.h>
 #include <__algorithm/ranges_binary_search.h>
 #include <__algorithm/ranges_clamp.h>
+#include <__algorithm/ranges_contains.h>
 #include <__algorithm/ranges_copy.h>
 #include <__algorithm/ranges_copy_backward.h>
 #include <__algorithm/ranges_copy_if.h>
diff --git 
a/libcxx/test/libcxx/algorithms/ranges_robust_against_copying

[clang-tools-extra] [compiler-rt] [libcxx] [clang] [libc] [llvm] [flang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)

2023-12-12 Thread Eli Friedman via cfe-commits


@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const 
ArraySubscriptExpr *E,
   ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true);
 else
   ArrayLV = EmitLValue(Array);
+
 auto *Idx = EmitIdxAfterBase(/*Promote*/true);
 
+if (SanOpts.has(SanitizerKind::ArrayBounds)) {

efriedma-quic wrote:

Right. I've suggested a couple alternatives.  (You can explicitly compute the 
offset between the array and corresponding counted_by field.  Or you can start 
at the relevant base, and write out code to GEP to both the counted_by field 
and the array.)

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


[clang] [llvm] [polly] [polly][ScheduleOptimizer] Fix long compile time(hang) reported in polly (PR #75141)

2023-12-12 Thread Eli Friedman via cfe-commits


@@ -860,7 +867,25 @@ static void runIslScheduleOptimizer(
 SC = SC.set_proximity(Proximity);
 SC = SC.set_validity(Validity);
 SC = SC.set_coincidence(Validity);
+
+// Save error handling behavior

efriedma-quic wrote:

Would it be possible to use the IslMaxOperationsGuard helper here?  In addition 
to the code reuse, the RAII pattern is easier to read.

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


[llvm] [clang] [polly] [polly][ScheduleOptimizer] Fix long compile time(hang) reported in polly (PR #75141)

2023-12-12 Thread Eli Friedman via cfe-commits


@@ -860,7 +867,25 @@ static void runIslScheduleOptimizer(
 SC = SC.set_proximity(Proximity);
 SC = SC.set_validity(Validity);
 SC = SC.set_coincidence(Validity);
+
+// Save error handling behavior
+long MaxOperations = isl_ctx_get_max_operations(Ctx);
+isl_ctx_set_max_operations(Ctx, ScheduleComputeOut);
 Schedule = SC.compute_schedule();
+bool ScheduleQuota = false;
+if (isl_ctx_last_error(Ctx) == isl_error_quota) {
+  isl_ctx_reset_error(Ctx);
+  LLVM_DEBUG(
+  dbgs() << "Schedule optimizer calculation exceeds ISL quota\n");
+  ScheduleQuota = true;
+}
+isl_options_set_on_error(Ctx, ISL_ON_ERROR_ABORT);

efriedma-quic wrote:

This isl_options_set_on_error call doesn't seem right; we should move the 
existing call to `isl_options_set_on_error(Ctx, OnErrorStatus);` before the 
early return.

(Not sure my suggested change actually has any visible effect given the actual 
usage of isl here, but still, it's confusing to save the on_error and not 
restore it properly.)

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


[clang] [Windows] Add git-clang-format wrapper bat file (PR #69228)

2023-12-12 Thread Owen Pan via cfe-commits


@@ -0,0 +1 @@
+py -3 git-clang-format %*

owenca wrote:

@llvm-beanz This doesn't seem to work if `git-clang-format` is run from another 
directory:
```
C:\Users\Owen\llvm-project>clang\tools\clang-format\git-clang-format

C:\Users\Owen\llvm-project>py -3 git-clang-format
C:\Users\Owen\AppData\Local\Programs\Python\Python39\python.exe: can't open 
file 'C:\Users\Owen\llvm-project\git-clang-format': [Errno 2] No such file or 
directory

C:\Users\Owen\llvm-project>
```

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


[clang-tools-extra] [lldb] [compiler-rt] [libcxx] [lld] [clang] [llvm] [mlir] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)

2023-12-12 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/66963

>From 5a2c930770cf548c5e3f3451e76b48cb067e6762 Mon Sep 17 00:00:00 2001
From: Zijun Zhao 
Date: Wed, 13 Sep 2023 14:26:01 -0700
Subject: [PATCH 1/6] [libc++] Implement ranges::contains_subrange

---
 libcxx/include/CMakeLists.txt |   1 +
 .../__algorithm/ranges_contains_subrange.h| 145 +
 libcxx/include/algorithm  |  14 +
 ...obust_against_copying_projections.pass.cpp |   4 +
 .../ranges.contains_subrange.pass.cpp | 293 ++
 .../niebloid.compile.pass.cpp |   3 +
 6 files changed, 460 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains_subrange.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbae..b096259f85f6a 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -104,6 +104,7 @@ set(files
   __algorithm/ranges_any_of.h
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
+  __algorithm/ranges_contains_subrange.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains_subrange.h 
b/libcxx/include/__algorithm/ranges_contains_subrange.h
new file mode 100644
index 0..16de6c29cb2a1
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains_subrange.h
@@ -0,0 +1,145 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+
+#include <__algorithm/ranges_starts_with.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains_subrange {
+struct __fn {
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred,
+class _Proj1,
+class _Proj2,
+class _Offset>
+  static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred& __pred,
+  _Proj1& __proj1,
+  _Proj2& __proj2,
+  _Offset __offset) {
+if (__offset < 0)
+  return false;
+else {
+  for (; __offset >= 0; __offset--, __first1++) {
+auto result = ranges::starts_with(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+std::ref(__pred),
+std::ref(__proj1),
+std::ref(__proj2));
+if (result)
+  return true;
+  }
+  return false;
+}
+  }
+
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred  = ranges::equal_to,
+class _Proj1 = identity,
+class _Proj2 = identity>
+requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred __pred   = {},
+  _Proj1 __proj1 = {},
+  _Proj2 __proj2 = {}) const {
+auto __n1 = ranges::distance(__first1, __last1);
+auto __n2 = ranges::distance(__first2, __last2);
+auto __offset = __n1 - __n2;
+
+return __contains_subrange_fn_impl(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+__pred,
+__proj1,
+__proj2,
+std::move(__offset));
+  }
+
+  template 
+requires indirectly_comparable, iterator_t<_Range2>, 
_Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 
__proj1 = {}, _Proj2 __proj2 = {}) const {
+auto __n1 = 0;
+auto __n2 = 0;
+
+if constexpr (s

[clang] [clang][Sema] Resolving Inconsistent Arguments Panic in Variadic Template Variables (PR #70280)

2023-12-12 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/70280

>From 95180e1765fea3ec6de822d0b9926056d0d12404 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Thu, 26 Oct 2023 09:25:58 +0800
Subject: [PATCH 1/2] [clang][Sema] Resolving Panic Caused by Inconsistent
 Arguments in Variadic Template Variables

When template variables are variadic, sema may panic, potentially leading to a 
situation
 where the number of function variables exceeds the number of template 
variables.
The sema compares the template signature and function signature parameters one 
by one,
 which can trigger an assertion error. This PR, when encountering variadic 
templates,
avoids comparing the template signature and function signature parameters one 
by one.

issue: https://github.com/llvm/llvm-project/issues/70191
---
 clang/docs/ReleaseNotes.rst |  3 +++
 clang/lib/Sema/SemaOverload.cpp | 13 +++--
 clang/test/SemaCXX/GH70280.cpp  |  9 +
 3 files changed, 23 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/GH70280.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d6719680d2ac70..456be476a95447 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1069,6 +1069,9 @@ Static Analyzer
   `#65888 `_, and
   `#65887 `_
 
+- Resolving Inconsistent Arguments Panic in Variadic Template Variables.
+  (`#70280: `_).
+
 .. _release-notes-sanitizers:
 
 Sanitizers
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 5026e1d603e5ee..320f53a7159f3e 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11092,6 +11092,14 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   I--;
   }
 
+  bool isVariadic = false;
+  for (unsigned N = 0; N < Fn->getNumParams(); N++) {
+if (Fn->getParamDecl(N)->isParameterPack()) {
+  isVariadic = true;
+  break;
+}
+  }
+
   std::string FnDesc;
   std::pair FnKindPair =
   ClassifyOverloadCandidate(S, Cand->FoundDecl, Fn, Cand->getRewriteKind(),
@@ -11100,8 +11108,9 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange = !isObjectArgument && !isVariadic
+ ? Fn->getParamDecl(I)->getSourceRange()
+ : SourceRange();
 
   if (FromTy == S.Context.OverloadTy) {
 assert(FromExpr && "overload set argument came from implicit argument?");
diff --git a/clang/test/SemaCXX/GH70280.cpp b/clang/test/SemaCXX/GH70280.cpp
new file mode 100644
index 00..c7f62ffbf27b35
--- /dev/null
+++ b/clang/test/SemaCXX/GH70280.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+namespace PR70280 {
+  typedef a; // expected-error {{a type specifier is required for all 
declarations}}
+  using b = char*;
+  template  void d(c...) = d(0, ""); // expected-error 
{{no matching function for call to 'd'}}
+  // expected-error@-1 {{illegal initializer (only variables can be 
initialized)}}
+  // expected-note@-2 {{candidate function template not viable: no known 
conversion from 'const char[1]' to 'a' (aka 'int') for 2nd argument}}
+}
\ No newline at end of file

>From f1242c3627db8449a78912e8d62ff9f1a2951068 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Wed, 13 Dec 2023 08:36:46 +0800
Subject: [PATCH 2/2] fix conflicts

---
 clang/docs/ReleaseNotes.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 456be476a95447..38493aac38a273 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -836,6 +836,9 @@ Bug Fixes to C++ Support
   completes (except deduction guides). Fixes:
   (`#59827 `_)
 
+- Fixed crash when parsing inconsistent arguments in variadic template 
variables. Fixes:
+  `(#70280: https://github.com/llvm/llvm-project/issues/70191>`_)
+
 - Fix crash when parsing nested requirement. Fixes:
   (`#73112 `_)
 
@@ -1069,9 +1072,6 @@ Static Analyzer
   `#65888 `_, and
   `#65887 `_
 
-- Resolving Inconsistent Arguments Panic in Variadic Template Variables.
-  (`#70280: `_).
-
 .. _release-notes-sanitizers:
 
 Sanitizers

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

[clang] Remove the builtin_headers_in_system_modules feature (PR #75262)

2023-12-12 Thread Juergen Ributzka via cfe-commits

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

LGTM. Thanks for cleaning this up.

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


[llvm] [compiler-rt] [libcxx] [clang-tools-extra] [clang] [libc] [flang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)

2023-12-12 Thread Bill Wendling via cfe-commits


@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const 
ArraySubscriptExpr *E,
   ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true);
 else
   ArrayLV = EmitLValue(Array);
+
 auto *Idx = EmitIdxAfterBase(/*Promote*/true);
 
+if (SanOpts.has(SanitizerKind::ArrayBounds)) {

bwendling wrote:

Unfortunately, all pointers are opaque now, so there's no way to tell what type 
it is. So it's hard to know when to stop.

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


[clang] Remove the builtin_headers_in_system_modules feature (PR #75262)

2023-12-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ian Anderson (ian-twilightcoder)


Changes

__has_feature(builtin_headers_in_system_modules) was added in 
https://reviews.llvm.org/D159483 to be used in the stdarg/stddef implementation 
headers. It ended up being unnecessary, but I forgot to remove the feature 
definition.

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


2 Files Affected:

- (modified) clang/include/clang/Basic/Features.def (-1) 
- (modified) clang/test/Driver/darwin-builtin-modules.c (-16) 


``diff
diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 7473e00a7bd86b..06efac0cf1abd7 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -282,7 +282,6 @@ EXTENSION(matrix_types_scalar_division, true)
 EXTENSION(cxx_attributes_on_using_declarations, LangOpts.CPlusPlus11)
 EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
-FEATURE(builtin_headers_in_system_modules, 
LangOpts.BuiltinHeadersInSystemModules)
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
 // CUDA/HIP Features
diff --git a/clang/test/Driver/darwin-builtin-modules.c 
b/clang/test/Driver/darwin-builtin-modules.c
index 215f2b8d2c142a..1c56e13bfb9293 100644
--- a/clang/test/Driver/darwin-builtin-modules.c
+++ b/clang/test/Driver/darwin-builtin-modules.c
@@ -9,19 +9,3 @@
 // RUN: %clang -isysroot %S/Inputs/MacOSX99.0.sdk -target 
x86_64-apple-macos98.0 -### %s 2>&1 | FileCheck --check-prefix=CHECK_FUTURE %s
 // RUN: %clang -isysroot %S/Inputs/MacOSX99.0.sdk -target 
x86_64-apple-macos99.0 -### %s 2>&1 | FileCheck --check-prefix=CHECK_FUTURE %s
 // CHECK_FUTURE-NOT: -fbuiltin-headers-in-system-modules
-
-
-// Check that builtin_headers_in_system_modules is only set if 
-fbuiltin-headers-in-system-modules and -fmodules are both set.
-
-// RUN: %clang -isysroot %S/Inputs/iPhoneOS13.0.sdk -target 
arm64-apple-ios13.0 -fsyntax-only %s -Xclang -verify=no-feature
-// RUN: %clang -isysroot %S/Inputs/iPhoneOS13.0.sdk -target 
arm64-apple-ios13.0 -fsyntax-only %s -fmodules -Xclang -verify=yes-feature
-// RUN: %clang -isysroot %S/Inputs/MacOSX99.0.sdk -target 
x86_64-apple-macos99.0 -fsyntax-only %s -Xclang -verify=no-feature
-// RUN: %clang -isysroot %S/Inputs/MacOSX99.0.sdk -target 
x86_64-apple-macos99.0 -fsyntax-only %s -fmodules -Xclang -verify=no-feature
-
-#if __has_feature(builtin_headers_in_system_modules)
-#error "has builtin_headers_in_system_modules"
-// yes-feature-error@-1 {{}}
-#else
-#error "no builtin_headers_in_system_modules"
-// no-feature-error@-1 {{}}
-#endif

``




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


[clang] Remove the builtin_headers_in_system_modules feature (PR #75262)

2023-12-12 Thread Ian Anderson via cfe-commits

https://github.com/ian-twilightcoder created 
https://github.com/llvm/llvm-project/pull/75262

__has_feature(builtin_headers_in_system_modules) was added in 
https://reviews.llvm.org/D159483 to be used in the stdarg/stddef implementation 
headers. It ended up being unnecessary, but I forgot to remove the feature 
definition.

>From 120be30b2056b6f03d692d1e79a2f4ef60d5e5f4 Mon Sep 17 00:00:00 2001
From: Ian Anderson 
Date: Tue, 12 Dec 2023 16:33:33 -0800
Subject: [PATCH] Remove the builtin_headers_in_system_modules feature

__has_feature(builtin_headers_in_system_modules) was added in 
https://reviews.llvm.org/D159483 to be used in the stdarg/stddef implementation 
headers. It ended up being unnecessary, but I forgot to remove the feature 
definition.
---
 clang/include/clang/Basic/Features.def |  1 -
 clang/test/Driver/darwin-builtin-modules.c | 16 
 2 files changed, 17 deletions(-)

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 7473e00a7bd86b..06efac0cf1abd7 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -282,7 +282,6 @@ EXTENSION(matrix_types_scalar_division, true)
 EXTENSION(cxx_attributes_on_using_declarations, LangOpts.CPlusPlus11)
 EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
-FEATURE(builtin_headers_in_system_modules, 
LangOpts.BuiltinHeadersInSystemModules)
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
 // CUDA/HIP Features
diff --git a/clang/test/Driver/darwin-builtin-modules.c 
b/clang/test/Driver/darwin-builtin-modules.c
index 215f2b8d2c142a..1c56e13bfb9293 100644
--- a/clang/test/Driver/darwin-builtin-modules.c
+++ b/clang/test/Driver/darwin-builtin-modules.c
@@ -9,19 +9,3 @@
 // RUN: %clang -isysroot %S/Inputs/MacOSX99.0.sdk -target 
x86_64-apple-macos98.0 -### %s 2>&1 | FileCheck --check-prefix=CHECK_FUTURE %s
 // RUN: %clang -isysroot %S/Inputs/MacOSX99.0.sdk -target 
x86_64-apple-macos99.0 -### %s 2>&1 | FileCheck --check-prefix=CHECK_FUTURE %s
 // CHECK_FUTURE-NOT: -fbuiltin-headers-in-system-modules
-
-
-// Check that builtin_headers_in_system_modules is only set if 
-fbuiltin-headers-in-system-modules and -fmodules are both set.
-
-// RUN: %clang -isysroot %S/Inputs/iPhoneOS13.0.sdk -target 
arm64-apple-ios13.0 -fsyntax-only %s -Xclang -verify=no-feature
-// RUN: %clang -isysroot %S/Inputs/iPhoneOS13.0.sdk -target 
arm64-apple-ios13.0 -fsyntax-only %s -fmodules -Xclang -verify=yes-feature
-// RUN: %clang -isysroot %S/Inputs/MacOSX99.0.sdk -target 
x86_64-apple-macos99.0 -fsyntax-only %s -Xclang -verify=no-feature
-// RUN: %clang -isysroot %S/Inputs/MacOSX99.0.sdk -target 
x86_64-apple-macos99.0 -fsyntax-only %s -fmodules -Xclang -verify=no-feature
-
-#if __has_feature(builtin_headers_in_system_modules)
-#error "has builtin_headers_in_system_modules"
-// yes-feature-error@-1 {{}}
-#else
-#error "no builtin_headers_in_system_modules"
-// no-feature-error@-1 {{}}
-#endif

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


[clang-tools-extra] [compiler-rt] [lldb] [libcxx] [libunwind] [lld] [libcxxabi] [clang] [libc] [flang] [llvm] [mlir] [libc++] Implement ranges::contains (PR #65148)

2023-12-12 Thread via cfe-commits


@@ -0,0 +1,49 @@
+//===--===//

ZijunZhaoCCK wrote:

Done! already add here: 
https://github.com/llvm/llvm-project/pull/65148#issue-1876098703 Thank you for 
helping review!

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


[clang-tools-extra] [compiler-rt] [lldb] [libcxx] [libunwind] [lld] [libcxxabi] [clang] [libc] [flang] [llvm] [mlir] [libc++] Implement ranges::contains (PR #65148)

2023-12-12 Thread via cfe-commits

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


[llvm] [lldb] [compiler-rt] [libcxx] [clang-tools-extra] [clang] [mlir] [libc] [libcxxabi] [lld] [libunwind] [flang] [libc++] Implement ranges::contains (PR #65148)

2023-12-12 Thread via cfe-commits

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


[clang-tools-extra] [compiler-rt] [lldb] [libcxx] [libunwind] [lld] [libcxxabi] [clang] [libc] [flang] [llvm] [mlir] [libc++] Implement ranges::contains (PR #65148)

2023-12-12 Thread via cfe-commits

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


[llvm] [lldb] [compiler-rt] [libcxx] [clang-tools-extra] [clang] [mlir] [libc] [libcxxabi] [lld] [libunwind] [flang] [libc++] Implement ranges::contains (PR #65148)

2023-12-12 Thread via cfe-commits

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


[mlir] [clang-tools-extra] [lldb] [llvm] [libc] [libcxx] [clang] [libcxxabi] [libunwind] [compiler-rt] [flang] [lld] [libc++] Implement ranges::contains (PR #65148)

2023-12-12 Thread via cfe-commits

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


[llvm] [compiler-rt] [libcxx] [clang-tools-extra] [clang] [libc] [flang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)

2023-12-12 Thread Eli Friedman via cfe-commits


@@ -740,3 +1058,589 @@ void test10(struct union_of_fams *p, int index) {
 void test11(struct annotated *p, int index) {
   p->array[index] = __builtin_dynamic_object_size(&p->count, 1);
 }
+
+// SANITIZE-WITH-ATTR-LABEL: define dso_local i64 @test11_bdos(
+// SANITIZE-WITH-ATTR-SAME: ptr nocapture noundef readnone [[P:%.*]]) 
local_unnamed_addr #[[ATTR4:[0-9]+]] {
+// SANITIZE-WITH-ATTR-NEXT:  entry:
+// SANITIZE-WITH-ATTR-NEXT:ret i64 4
+//
+// NO-SANITIZE-WITH-ATTR-LABEL: define dso_local i64 @test11_bdos(
+// NO-SANITIZE-WITH-ATTR-SAME: ptr nocapture noundef readnone [[P:%.*]]) 
local_unnamed_addr #[[ATTR5:[0-9]+]] {
+// NO-SANITIZE-WITH-ATTR-NEXT:  entry:
+// NO-SANITIZE-WITH-ATTR-NEXT:ret i64 4
+//
+// SANITIZE-WITHOUT-ATTR-LABEL: define dso_local i64 @test11_bdos(
+// SANITIZE-WITHOUT-ATTR-SAME: ptr nocapture noundef readnone [[P:%.*]]) 
local_unnamed_addr #[[ATTR2:[0-9]+]] {
+// SANITIZE-WITHOUT-ATTR-NEXT:  entry:
+// SANITIZE-WITHOUT-ATTR-NEXT:ret i64 4
+//
+// NO-SANITIZE-WITHOUT-ATTR-LABEL: define dso_local i64 @test11_bdos(
+// NO-SANITIZE-WITHOUT-ATTR-SAME: ptr nocapture noundef readnone [[P:%.*]]) 
local_unnamed_addr #[[ATTR3:[0-9]+]] {
+// NO-SANITIZE-WITHOUT-ATTR-NEXT:  entry:
+// NO-SANITIZE-WITHOUT-ATTR-NEXT:ret i64 4
+//
+size_t test11_bdos(struct annotated *p) {
+  return __builtin_dynamic_object_size(&p->count, 1);
+}
+
+struct {
+  struct {
+struct {
+  int num_entries;
+};
+  };
+  int entries[] __attribute__((__counted_by__(num_entries)));
+} test12_foo;
+
+struct hang {
+  int entries[6];
+} test12_bar;
+
+int test12_a, test12_b;
+
+// SANITIZE-WITH-ATTR-LABEL: define dso_local i32 @test12(
+// SANITIZE-WITH-ATTR-SAME: i32 noundef [[INDEX:%.*]]) local_unnamed_addr 
#[[ATTR5:[0-9]+]] {
+// SANITIZE-WITH-ATTR-NEXT:  entry:
+// SANITIZE-WITH-ATTR-NEXT:[[BAZ:%.*]] = alloca [[STRUCT_HANG:%.*]], align 
4
+// SANITIZE-WITH-ATTR-NEXT:call void @llvm.lifetime.start.p0(i64 24, ptr 
nonnull [[BAZ]]) #[[ATTR11:[0-9]+]]
+// SANITIZE-WITH-ATTR-NEXT:call void @llvm.memcpy.p0.p0.i64(ptr noundef 
nonnull align 4 dereferenceable(24) [[BAZ]], ptr noundef nonnull align 4 
dereferenceable(24) @test12_bar, i64 24, i1 false), !tbaa.struct 
[[TBAA_STRUCT9:![0-9]+]]
+// SANITIZE-WITH-ATTR-NEXT:[[TMP0:%.*]] = icmp ult i32 [[INDEX]], 6
+// SANITIZE-WITH-ATTR-NEXT:[[TMP1:%.*]] = zext i32 [[INDEX]] to i64
+// SANITIZE-WITH-ATTR-NEXT:br i1 [[TMP0]], label [[TRAP8:%.*]], label 
[[HANDLER_OUT_OF_BOUNDS:%.*]], !prof [[PROF3]], !nosanitize [[META2]]
+// SANITIZE-WITH-ATTR:   handler.out_of_bounds:
+// SANITIZE-WITH-ATTR-NEXT:tail call void 
@__ubsan_handle_out_of_bounds_abort(ptr nonnull @[[GLOB18:[0-9]+]], i64 
[[TMP1]]) #[[ATTR10]], !nosanitize [[META2]]
+// SANITIZE-WITH-ATTR-NEXT:unreachable, !nosanitize [[META2]]
+// SANITIZE-WITH-ATTR:   trap8:
+// SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds [6 x 
i32], ptr [[BAZ]], i64 0, i64 [[TMP1]]
+// SANITIZE-WITH-ATTR-NEXT:[[TMP2:%.*]] = load i32, ptr [[ARRAYIDX]], 
align 4, !tbaa [[TBAA4]]
+// SANITIZE-WITH-ATTR-NEXT:store i32 [[TMP2]], ptr @test12_b, align 4, 
!tbaa [[TBAA4]]
+// SANITIZE-WITH-ATTR-NEXT:tail call void @llvm.trap() #[[ATTR10]]
+// SANITIZE-WITH-ATTR-NEXT:unreachable
+//
+// NO-SANITIZE-WITH-ATTR-LABEL: define dso_local i32 @test12(
+// NO-SANITIZE-WITH-ATTR-SAME: i32 noundef [[INDEX:%.*]]) local_unnamed_addr 
#[[ATTR6:[0-9]+]] {
+// NO-SANITIZE-WITH-ATTR-NEXT:  entry:
+// NO-SANITIZE-WITH-ATTR-NEXT:[[BAZ:%.*]] = alloca [[STRUCT_HANG:%.*]], 
align 4
+// NO-SANITIZE-WITH-ATTR-NEXT:call void @llvm.lifetime.start.p0(i64 24, 
ptr nonnull [[BAZ]]) #[[ATTR13:[0-9]+]]
+// NO-SANITIZE-WITH-ATTR-NEXT:call void @llvm.memcpy.p0.p0.i64(ptr noundef 
nonnull align 4 dereferenceable(24) [[BAZ]], ptr noundef nonnull align 4 
dereferenceable(24) @test12_bar, i64 24, i1 false), !tbaa.struct 
[[TBAA_STRUCT7:![0-9]+]]
+// NO-SANITIZE-WITH-ATTR-NEXT:[[IDXPROM:%.*]] = sext i32 [[INDEX]] to i64
+// NO-SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds [6 
x i32], ptr [[BAZ]], i64 0, i64 [[IDXPROM]]
+// NO-SANITIZE-WITH-ATTR-NEXT:[[TMP0:%.*]] = load i32, ptr [[ARRAYIDX]], 
align 4, !tbaa [[TBAA2]]
+// NO-SANITIZE-WITH-ATTR-NEXT:store i32 [[TMP0]], ptr @test12_b, align 4, 
!tbaa [[TBAA2]]
+// NO-SANITIZE-WITH-ATTR-NEXT:[[TMP1:%.*]] = load i32, ptr getelementptr 
inbounds ([[STRUCT_ANON_5:%.*]], ptr @test12_foo, i64 1, i32 0, i32 0, i32 0), 
align 4, !tbaa [[TBAA2]]
+// NO-SANITIZE-WITH-ATTR-NEXT:store i32 [[TMP1]], ptr @test12_a, align 4, 
!tbaa [[TBAA2]]
+// NO-SANITIZE-WITH-ATTR-NEXT:br label [[FOR_COND:%.*]]
+// NO-SANITIZE-WITH-ATTR:   for.cond:
+// NO-SANITIZE-WITH-ATTR-NEXT:br label [[FOR_COND]]
+//
+// SANITIZE-WITHOUT-ATTR-LABEL: define dso_local i32 @test12(
+// SANITIZE-WITHOUT-ATTR-SAME: i32 noundef [[INDEX:%.*]]) local_unnamed_addr 
#[[ATTR3:[0-9]+]] {
+// SANITIZE-WITHOUT-ATTR-

[clang-tools-extra] [libc] [llvm] [libcxx] [clang] [compiler-rt] [flang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)

2023-12-12 Thread Eli Friedman via cfe-commits


@@ -4022,8 +4169,36 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const 
ArraySubscriptExpr *E,
   ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true);
 else
   ArrayLV = EmitLValue(Array);
+
 auto *Idx = EmitIdxAfterBase(/*Promote*/true);
 
+if (SanOpts.has(SanitizerKind::ArrayBounds)) {

efriedma-quic wrote:

Recursively skipping over all GEPs seems, at best, extremely fragile; there 
could be GEPs for reasons other than the member expressions you care about.

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


[llvm] [lldb] [compiler-rt] [libcxx] [clang-tools-extra] [clang] [mlir] [libc] [libcxxabi] [lld] [libunwind] [flang] [libc++] Implement ranges::contains (PR #65148)

2023-12-12 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/65148

>From 02e9afd761228f401df4d9f8dfaaca44ffae0c6e Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 31 Aug 2023 20:08:32 +
Subject: [PATCH 01/20] [libc++] Implement ranges::contains

Differential Revision: https://reviews.llvm.org/D159232
---
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__algorithm/ranges_contains.h  |  60 ++
 libcxx/include/algorithm  |   9 +
 ...obust_against_copying_projections.pass.cpp |   4 +
 .../alg.contains/ranges.contains.pass.cpp | 190 ++
 .../niebloid.compile.pass.cpp |   1 +
 6 files changed, 265 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 77a7269121ec1..024aa8959fb72 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -104,6 +104,7 @@ set(files
   __algorithm/ranges_any_of.h
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
+  __algorithm/ranges_contains.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains.h 
b/libcxx/include/__algorithm/ranges_contains.h
new file mode 100644
index 0..647b7ea34be34
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains.h
@@ -0,0 +1,60 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+
+#include <__algorithm/in_in_result.h>
+#include <__algorithm/ranges_find.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains {
+struct __fn {
+  template  _Sent, class _Type, 
class _Proj = identity>
+requires indirect_binary_predicate, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = 
{}) const {
+return ranges::find(std::move(__first), std::move(__last), __value, 
std::ref(__proj)) != __last;
+  }
+
+  template 
+requires indirect_binary_predicate, _Proj>, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) const {
+return ranges::find(ranges::begin(__range), ranges::end(__range), __value, 
std::ref(__proj)) != ranges::end(__range);
+  }
+};
+} // namespace __contains
+inline namespace __cpo {
+inline constexpr auto contains = __contains::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER >= 23
+
+#endif // _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index 76e0d22bf73ef..003bf132b38b4 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -226,6 +226,14 @@ namespace ranges {
   template
 using copy_backward_result = in_out_result;
 // since C++20
 
+  template S, class T, class Proj = identity>
+requires indirect_binary_predicate, 
const T*>
+constexpr bool ranges::contains(I first, S last, const T& value, Proj proj 
= {});   // since C++23
+
+  template
+requires indirect_binary_predicate, Proj>, const T*>
+constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {});
 // since C++23
+
   template S, weakly_incrementable O>
 requires indirectly_copyable
 constexpr ranges::copy_result ranges::copy(I first, S last, O 
result);// since C++20
@@ -1827,6 +1835,7 @@ template 
 #include <__algorithm/ranges_any_of.h>
 #include <__algorithm/ranges_binary_search.h>
 #include <__algorithm/ranges_clamp.h>
+#include <__algorithm/ranges_contains.h>
 #include <__algorithm/ranges_copy.h>
 #include <__algorithm/ranges_copy_backward.h>
 #include <__algorithm/ranges_copy_if.h>
diff --git 
a/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_proje

[lld] [llvm] [mlir] [compiler-rt] [clang] [libcxx] [clang-tools-extra] [lldb] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)

2023-12-12 Thread Konstantin Varlamov via cfe-commits

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


[llvm] [compiler-rt] [lldb] [clang] [clang-tools-extra] [lld] [mlir] [libcxx] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)

2023-12-12 Thread Konstantin Varlamov via cfe-commits

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


[llvm] [lldb] [compiler-rt] [libcxx] [clang-tools-extra] [clang] [mlir] [libc] [libcxxabi] [lld] [libunwind] [flang] [libc++] Implement ranges::contains (PR #65148)

2023-12-12 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/65148

>From 02e9afd761228f401df4d9f8dfaaca44ffae0c6e Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 31 Aug 2023 20:08:32 +
Subject: [PATCH 01/19] [libc++] Implement ranges::contains

Differential Revision: https://reviews.llvm.org/D159232
---
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__algorithm/ranges_contains.h  |  60 ++
 libcxx/include/algorithm  |   9 +
 ...obust_against_copying_projections.pass.cpp |   4 +
 .../alg.contains/ranges.contains.pass.cpp | 190 ++
 .../niebloid.compile.pass.cpp |   1 +
 6 files changed, 265 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 77a7269121ec14..024aa8959fb720 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -104,6 +104,7 @@ set(files
   __algorithm/ranges_any_of.h
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
+  __algorithm/ranges_contains.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains.h 
b/libcxx/include/__algorithm/ranges_contains.h
new file mode 100644
index 00..647b7ea34be342
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains.h
@@ -0,0 +1,60 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+
+#include <__algorithm/in_in_result.h>
+#include <__algorithm/ranges_find.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains {
+struct __fn {
+  template  _Sent, class _Type, 
class _Proj = identity>
+requires indirect_binary_predicate, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = 
{}) const {
+return ranges::find(std::move(__first), std::move(__last), __value, 
std::ref(__proj)) != __last;
+  }
+
+  template 
+requires indirect_binary_predicate, _Proj>, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) const {
+return ranges::find(ranges::begin(__range), ranges::end(__range), __value, 
std::ref(__proj)) != ranges::end(__range);
+  }
+};
+} // namespace __contains
+inline namespace __cpo {
+inline constexpr auto contains = __contains::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER >= 23
+
+#endif // _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index 76e0d22bf73ef8..003bf132b38b4d 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -226,6 +226,14 @@ namespace ranges {
   template
 using copy_backward_result = in_out_result;
 // since C++20
 
+  template S, class T, class Proj = identity>
+requires indirect_binary_predicate, 
const T*>
+constexpr bool ranges::contains(I first, S last, const T& value, Proj proj 
= {});   // since C++23
+
+  template
+requires indirect_binary_predicate, Proj>, const T*>
+constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {});
 // since C++23
+
   template S, weakly_incrementable O>
 requires indirectly_copyable
 constexpr ranges::copy_result ranges::copy(I first, S last, O 
result);// since C++20
@@ -1827,6 +1835,7 @@ template 
 #include <__algorithm/ranges_any_of.h>
 #include <__algorithm/ranges_binary_search.h>
 #include <__algorithm/ranges_clamp.h>
+#include <__algorithm/ranges_contains.h>
 #include <__algorithm/ranges_copy.h>
 #include <__algorithm/ranges_copy_backward.h>
 #include <__algorithm/ranges_copy_if.h>
diff --git 
a/libcxx/test/libcxx/algorithms/ranges_robust_against_copying

[clang] [RISCV] Reduce the size of the index used for RVV intrinsics. NFC (PR #74906)

2023-12-12 Thread Craig Topper via cfe-commits

https://github.com/topperc updated 
https://github.com/llvm/llvm-project/pull/74906

>From 83579bb66f49f8f41f5030f861704b5c97729805 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Fri, 8 Dec 2023 17:06:36 -0800
Subject: [PATCH 1/4] [RISCV] Reduce the size of the index used for RVV
 intrinsics. NFC

Rather than using size_t, use unsigned. We don't have more than
4 billion intrinsics.
---
 clang/lib/Sema/SemaRISCVVectorLookup.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp 
b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
index 0d411fca0f9c82..e6900c309e0d0a 100644
--- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -43,7 +43,7 @@ struct RVVIntrinsicDef {
 
 struct RVVOverloadIntrinsicDef {
   // Indexes of RISCVIntrinsicManagerImpl::IntrinsicList.
-  SmallVector Indexes;
+  SmallVector Indexes;
 };
 
 } // namespace
@@ -162,7 +162,7 @@ class RISCVIntrinsicManagerImpl : public 
sema::RISCVIntrinsicManager {
   // List of all RVV intrinsic.
   std::vector IntrinsicList;
   // Mapping function name to index of IntrinsicList.
-  StringMap Intrinsics;
+  StringMap Intrinsics;
   // Mapping function name to RVVOverloadIntrinsicDef.
   StringMap OverloadIntrinsics;
 
@@ -386,7 +386,7 @@ void RISCVIntrinsicManagerImpl::InitRVVIntrinsic(
  Record.HasFRMRoundModeOp);
 
   // Put into IntrinsicList.
-  size_t Index = IntrinsicList.size();
+  unsigned Index = IntrinsicList.size();
   IntrinsicList.push_back({BuiltinName, Signature});
 
   // Creating mapping to Intrinsics.

>From 86ffbd6457dc528d323c6c68104392a87d741d45 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Tue, 12 Dec 2023 09:30:52 -0800
Subject: [PATCH 2/4] fixup! use uint32_t.

---
 clang/lib/Sema/SemaRISCVVectorLookup.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp 
b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
index e6900c309e0d0a..c275eb6246d386 100644
--- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -43,7 +43,7 @@ struct RVVIntrinsicDef {
 
 struct RVVOverloadIntrinsicDef {
   // Indexes of RISCVIntrinsicManagerImpl::IntrinsicList.
-  SmallVector Indexes;
+  SmallVector Indexes;
 };
 
 } // namespace
@@ -162,7 +162,7 @@ class RISCVIntrinsicManagerImpl : public 
sema::RISCVIntrinsicManager {
   // List of all RVV intrinsic.
   std::vector IntrinsicList;
   // Mapping function name to index of IntrinsicList.
-  StringMap Intrinsics;
+  StringMap Intrinsics;
   // Mapping function name to RVVOverloadIntrinsicDef.
   StringMap OverloadIntrinsics;
 
@@ -174,7 +174,7 @@ class RISCVIntrinsicManagerImpl : public 
sema::RISCVIntrinsicManager {
 
   // Create FunctionDecl for a vector intrinsic.
   void CreateRVVIntrinsicDecl(LookupResult &LR, IdentifierInfo *II,
-  Preprocessor &PP, unsigned Index,
+  Preprocessor &PP, uint32_t Index,
   bool IsOverload);
 
   void ConstructRVVIntrinsics(ArrayRef Recs,

>From 0acff799137f1c7f169adac1ebe3c57f5f974f08 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Tue, 12 Dec 2023 11:18:39 -0800
Subject: [PATCH 3/4] missed a spot

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

diff --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp 
b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
index c275eb6246d386..d3da25524aeab8 100644
--- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -386,7 +386,7 @@ void RISCVIntrinsicManagerImpl::InitRVVIntrinsic(
  Record.HasFRMRoundModeOp);
 
   // Put into IntrinsicList.
-  unsigned Index = IntrinsicList.size();
+  uint32_t Index = IntrinsicList.size();
   IntrinsicList.push_back({BuiltinName, Signature});
 
   // Creating mapping to Intrinsics.

>From 4fdd3a9d8e044351832c1c00d37ad4a14eae2e11 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Tue, 12 Dec 2023 16:09:30 -0800
Subject: [PATCH 4/4] another spot

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

diff --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp 
b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
index d3da25524aeab8..e4642e4da016a4 100644
--- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -403,7 +403,7 @@ void RISCVIntrinsicManagerImpl::InitRVVIntrinsic(
 void RISCVIntrinsicManagerImpl::CreateRVVIntrinsicDecl(LookupResult &LR,
IdentifierInfo *II,
Preprocessor &PP,
-   unsigned Index,
+   uint32_t Index,
bo

[clang] [clang][sema] make sure arguments of __atomic_exchange complete type (PR #75135)

2023-12-12 Thread via cfe-commits

knightXun wrote:

> Why only `__atomic_exchange`? Presumably we need to be doing the same with 
> every other of the atomic builtins as well (unless they already have this 
> check and we only missed it on exchange?)

I agree! I will do this check on every other of the atomic builtins.

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


  1   2   3   4   >