[clang] [clang-tools-extra] [libcxx] Reland "[clang] Enable sized deallocation by default in C++14 onwards" (PR #90373)

2024-05-23 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

> > > Based on my rough understanding, this is expected?
> > 
> > 
> > What do you mean?
> > Isn't this test needs to be updated or disabled?
> 
> I think this ASAN failure is not caused by this PR because these memorys are 
> allocated/deallocated by

100% sure by this PR
https://lab.llvm.org/buildbot/#/builders/168/builds/20461 only two patches on 
the blame list and the second one is unrelated for sure.

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


[clang] [clang-tools-extra] [libcxx] Reland "[clang] Enable sized deallocation by default in C++14 onwards" (PR #90373)

2024-05-23 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

Internally ::allocate uses sided new:

```
 void*
allocate(size_t __bytes, size_t __alignment = _S_max_align)
__attribute__((__returns_nonnull__,__alloc_size__(2),__alloc_align__(3)))
{ return ::operator new(__bytes, do_allocate(__bytes, __alignment)); }

```

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


[clang] Reland #90786 ([BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C) (PR #93121)

2024-05-23 Thread Dan Liew via cfe-commits

https://github.com/delcypher updated 
https://github.com/llvm/llvm-project/pull/93121

>From 7f5af7cc180825e07b5f5292e3f6b860c8e8591e Mon Sep 17 00:00:00 2001
From: Dan Liew 
Date: Fri, 17 May 2024 12:07:40 -0700
Subject: [PATCH 1/6] [BoundsSafety] Allow 'counted_by' attribute on pointers
 in structs in C (#90786)

Previously the attribute was only allowed on flexible array members.
This patch patch changes this to also allow the attribute on pointer
fields in structs and also allows late parsing of the attribute in some
contexts.

For example this previously wasn't allowed:

```
struct BufferTypeDeclAttributePosition {
  size_t count;
  char* buffer __counted_by(count); // Now allowed
}
```

Note the attribute is prevented on pointee types where the size isn't
known at compile time. In particular pointee types that are:

* Incomplete (e.g. `void`) and sizeless types
* Function types (e.g. the pointee of a function pointer)
* Struct types with a flexible array member

This patch also introduces late parsing of the attribute when used in
the declaration attribute position. For example

```
struct BufferTypeDeclAttributePosition {
  char* buffer __counted_by(count); // Now allowed
  size_t count;
}
```

is now allowed but **only** when passing
`-fexperimental-late-parse-attributes`. The motivation for using late
parsing here is to avoid breaking the data layout of structs in existing
code that want to use the `counted_by` attribute. This patch is the
first use of `LateAttrParseExperimentalExt` in `Attr.td` that was
introduced in a previous patch.

Note by allowing the attribute on struct member pointers this now allows
the possiblity of writing the attribute in the type attribute position.
For example:

```
struct BufferTypeAttributePosition {
  size_t count;
  char *__counted_by(count) buffer; // Now allowed
}
```

However, the attribute in this position is still currently parsed
immediately rather than late parsed. So this will not parse currently:

```
struct BufferTypeAttributePosition {
  char *__counted_by(count) buffer; // Fails to parse
  size_t count;
}
```

The intention is to lift this restriction in future patches. It has not
been done in this patch to keep this size of this commit small.

There are also several other follow up changes that will need to be
addressed in future patches:

* Make late parsing working with anonymous structs (see
`on_pointer_anon_buf` in `attr-counted-by-late-parsed-struct-ptrs.c`).
* Allow `counted_by` on more subjects (e.g. parameters, returns types)
when `-fbounds-safety` is enabled.
* Make use of the attribute on pointer types in code gen (e.g. for
`_builtin_dynamic_object_size` and UBSan's array-bounds checks).

This work is heavily based on a patch originally written by Yeoul Na.

rdar://125400257

Co-authored-by: Dan Liew 
---
 clang/docs/ReleaseNotes.rst   |  21 +-
 clang/include/clang/AST/Type.h|   1 +
 clang/include/clang/Basic/Attr.td |   3 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  17 +-
 clang/include/clang/Parse/Parser.h|   7 +-
 clang/include/clang/Sema/Sema.h   |   3 +-
 clang/lib/AST/Type.cpp|  10 +
 clang/lib/Parse/ParseDecl.cpp | 104 ++-
 clang/lib/Parse/ParseObjc.cpp |  10 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  82 --
 clang/lib/Sema/SemaType.cpp   |   6 +-
 clang/lib/Sema/TreeTransform.h|   2 +-
 .../attr-counted-by-late-parsed-struct-ptrs.c |  45 
 clang/test/AST/attr-counted-by-struct-ptrs.c  | 117 
 .../Sema/attr-counted-by-late-parsed-off.c|  26 ++
 .../attr-counted-by-late-parsed-struct-ptrs.c | 254 ++
 ...tr-counted-by-struct-ptrs-sizeless-types.c |  17 ++
 clang/test/Sema/attr-counted-by-struct-ptrs.c | 224 +++
 .../Sema/attr-counted-by-vla-sizeless-types.c |  11 +
 clang/test/Sema/attr-counted-by-vla.c | 193 +
 clang/test/Sema/attr-counted-by.c | 112 
 21 files changed, 1117 insertions(+), 148 deletions(-)
 create mode 100644 clang/test/AST/attr-counted-by-late-parsed-struct-ptrs.c
 create mode 100644 clang/test/AST/attr-counted-by-struct-ptrs.c
 create mode 100644 clang/test/Sema/attr-counted-by-late-parsed-off.c
 create mode 100644 clang/test/Sema/attr-counted-by-late-parsed-struct-ptrs.c
 create mode 100644 clang/test/Sema/attr-counted-by-struct-ptrs-sizeless-types.c
 create mode 100644 clang/test/Sema/attr-counted-by-struct-ptrs.c
 create mode 100644 clang/test/Sema/attr-counted-by-vla-sizeless-types.c
 create mode 100644 clang/test/Sema/attr-counted-by-vla.c
 delete mode 100644 clang/test/Sema/attr-counted-by.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 81e9d0423f96a..5d59b3b053600 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -317,7 +317,8 @@ New Compiler Flags
 
 - ``-fexperimental-late-parse-attribut

[clang] Reland #90786 ([BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C) (PR #93121)

2024-05-23 Thread Dan Liew via cfe-commits

https://github.com/delcypher updated 
https://github.com/llvm/llvm-project/pull/93121

>From 7f5af7cc180825e07b5f5292e3f6b860c8e8591e Mon Sep 17 00:00:00 2001
From: Dan Liew 
Date: Fri, 17 May 2024 12:07:40 -0700
Subject: [PATCH 1/7] [BoundsSafety] Allow 'counted_by' attribute on pointers
 in structs in C (#90786)

Previously the attribute was only allowed on flexible array members.
This patch patch changes this to also allow the attribute on pointer
fields in structs and also allows late parsing of the attribute in some
contexts.

For example this previously wasn't allowed:

```
struct BufferTypeDeclAttributePosition {
  size_t count;
  char* buffer __counted_by(count); // Now allowed
}
```

Note the attribute is prevented on pointee types where the size isn't
known at compile time. In particular pointee types that are:

* Incomplete (e.g. `void`) and sizeless types
* Function types (e.g. the pointee of a function pointer)
* Struct types with a flexible array member

This patch also introduces late parsing of the attribute when used in
the declaration attribute position. For example

```
struct BufferTypeDeclAttributePosition {
  char* buffer __counted_by(count); // Now allowed
  size_t count;
}
```

is now allowed but **only** when passing
`-fexperimental-late-parse-attributes`. The motivation for using late
parsing here is to avoid breaking the data layout of structs in existing
code that want to use the `counted_by` attribute. This patch is the
first use of `LateAttrParseExperimentalExt` in `Attr.td` that was
introduced in a previous patch.

Note by allowing the attribute on struct member pointers this now allows
the possiblity of writing the attribute in the type attribute position.
For example:

```
struct BufferTypeAttributePosition {
  size_t count;
  char *__counted_by(count) buffer; // Now allowed
}
```

However, the attribute in this position is still currently parsed
immediately rather than late parsed. So this will not parse currently:

```
struct BufferTypeAttributePosition {
  char *__counted_by(count) buffer; // Fails to parse
  size_t count;
}
```

The intention is to lift this restriction in future patches. It has not
been done in this patch to keep this size of this commit small.

There are also several other follow up changes that will need to be
addressed in future patches:

* Make late parsing working with anonymous structs (see
`on_pointer_anon_buf` in `attr-counted-by-late-parsed-struct-ptrs.c`).
* Allow `counted_by` on more subjects (e.g. parameters, returns types)
when `-fbounds-safety` is enabled.
* Make use of the attribute on pointer types in code gen (e.g. for
`_builtin_dynamic_object_size` and UBSan's array-bounds checks).

This work is heavily based on a patch originally written by Yeoul Na.

rdar://125400257

Co-authored-by: Dan Liew 
---
 clang/docs/ReleaseNotes.rst   |  21 +-
 clang/include/clang/AST/Type.h|   1 +
 clang/include/clang/Basic/Attr.td |   3 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  17 +-
 clang/include/clang/Parse/Parser.h|   7 +-
 clang/include/clang/Sema/Sema.h   |   3 +-
 clang/lib/AST/Type.cpp|  10 +
 clang/lib/Parse/ParseDecl.cpp | 104 ++-
 clang/lib/Parse/ParseObjc.cpp |  10 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  82 --
 clang/lib/Sema/SemaType.cpp   |   6 +-
 clang/lib/Sema/TreeTransform.h|   2 +-
 .../attr-counted-by-late-parsed-struct-ptrs.c |  45 
 clang/test/AST/attr-counted-by-struct-ptrs.c  | 117 
 .../Sema/attr-counted-by-late-parsed-off.c|  26 ++
 .../attr-counted-by-late-parsed-struct-ptrs.c | 254 ++
 ...tr-counted-by-struct-ptrs-sizeless-types.c |  17 ++
 clang/test/Sema/attr-counted-by-struct-ptrs.c | 224 +++
 .../Sema/attr-counted-by-vla-sizeless-types.c |  11 +
 clang/test/Sema/attr-counted-by-vla.c | 193 +
 clang/test/Sema/attr-counted-by.c | 112 
 21 files changed, 1117 insertions(+), 148 deletions(-)
 create mode 100644 clang/test/AST/attr-counted-by-late-parsed-struct-ptrs.c
 create mode 100644 clang/test/AST/attr-counted-by-struct-ptrs.c
 create mode 100644 clang/test/Sema/attr-counted-by-late-parsed-off.c
 create mode 100644 clang/test/Sema/attr-counted-by-late-parsed-struct-ptrs.c
 create mode 100644 clang/test/Sema/attr-counted-by-struct-ptrs-sizeless-types.c
 create mode 100644 clang/test/Sema/attr-counted-by-struct-ptrs.c
 create mode 100644 clang/test/Sema/attr-counted-by-vla-sizeless-types.c
 create mode 100644 clang/test/Sema/attr-counted-by-vla.c
 delete mode 100644 clang/test/Sema/attr-counted-by.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 81e9d0423f96a..5d59b3b053600 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -317,7 +317,8 @@ New Compiler Flags
 
 - ``-fexperimental-late-parse-attribut

[clang] af68120 - [clang][Interp] Fix initializing a union from an InitLIstExpr

2024-05-23 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-05-23T09:17:56+02:00
New Revision: af6812085cc7a7251a3095acbc96343ce660f135

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

LOG: [clang][Interp] Fix initializing a union from an InitLIstExpr

We can't just count the field to initialize but need to consult the
InitListExpr to give us the right field.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/unions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 50c85bf7d35f5..e64d3a94b5091 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1050,38 +1050,71 @@ bool 
ByteCodeExprGen::visitInitList(ArrayRef Inits,
   if (T->isRecordType()) {
 const Record *R = getRecord(E->getType());
 
-if (Inits.size() == 1 && E->getType() == Inits[0]->getType()) {
+if (Inits.size() == 1 && E->getType() == Inits[0]->getType())
   return this->visitInitializer(Inits[0]);
+
+auto initPrimitiveField = [=](const Record::Field *FieldToInit,
+  const Expr *Init, PrimType T) -> bool {
+  if (!this->visit(Init))
+return false;
+
+  if (FieldToInit->isBitField()) {
+if (!this->emitInitBitField(T, FieldToInit, E))
+  return false;
+  } else {
+if (!this->emitInitField(T, FieldToInit->Offset, E))
+  return false;
+  }
+  return this->emitPopPtr(E);
+};
+
+auto initCompositeField = [=](const Record::Field *FieldToInit,
+  const Expr *Init) -> bool {
+  // Non-primitive case. Get a pointer to the field-to-initialize
+  // on the stack and recurse into visitInitializer().
+  if (!this->emitGetPtrField(FieldToInit->Offset, Init))
+return false;
+  if (!this->visitInitializer(Init))
+return false;
+  return this->emitPopPtr(E);
+};
+
+if (R->isUnion()) {
+  assert(Inits.size() == 1);
+  const Expr *Init = Inits[0];
+  const FieldDecl *FToInit = nullptr;
+  if (const auto *ILE = dyn_cast(E))
+FToInit = ILE->getInitializedFieldInUnion();
+  else
+FToInit = cast(E)->getInitializedFieldInUnion();
+
+  if (!this->emitDupPtr(E))
+return false;
+
+  const Record::Field *FieldToInit = R->getField(FToInit);
+  if (std::optional T = classify(Init)) {
+if (!initPrimitiveField(FieldToInit, Init, *T))
+  return false;
+  } else {
+if (!initCompositeField(FieldToInit, Init))
+  return false;
+  }
+  return this->emitFinishInit(E);
 }
 
+assert(!R->isUnion());
 unsigned InitIndex = 0;
 for (const Expr *Init : Inits) {
   // Skip unnamed bitfields.
   while (InitIndex < R->getNumFields() &&
  R->getField(InitIndex)->Decl->isUnnamedBitField())
 ++InitIndex;
-
-  // Potentially skip ahead. This is especially relevant in unions.
-  if (const auto *D = dyn_cast(Init))
-InitIndex = D->getField()->getFieldIndex();
-
   if (!this->emitDupPtr(E))
 return false;
 
   if (std::optional T = classify(Init)) {
 const Record::Field *FieldToInit = R->getField(InitIndex);
-if (!this->visit(Init))
-  return false;
-
-if (FieldToInit->isBitField()) {
-  if (!this->emitInitBitField(*T, FieldToInit, E))
-return false;
-} else {
-  if (!this->emitInitField(*T, FieldToInit->Offset, E))
-return false;
-}
-
-if (!this->emitPopPtr(E))
+if (!initPrimitiveField(FieldToInit, Init, *T))
   return false;
 ++InitIndex;
   } else {
@@ -1099,21 +1132,13 @@ bool 
ByteCodeExprGen::visitInitList(ArrayRef Inits,
   // into the Record's fields.
 } else {
   const Record::Field *FieldToInit = R->getField(InitIndex);
-  // Non-primitive case. Get a pointer to the field-to-initialize
-  // on the stack and recurse into visitInitializer().
-  if (!this->emitGetPtrField(FieldToInit->Offset, Init))
-return false;
-
-  if (!this->visitInitializer(Init))
-return false;
-
-  if (!this->emitPopPtr(E))
+  if (!initCompositeField(FieldToInit, Init))
 return false;
   ++InitIndex;
 }
   }
 }
-return true;
+return this->emitFinishInit(E);
   }
 
   if (T->isArrayType()) {
@@ -1137,7 +1162,7 @@ bool 
ByteCodeExprGen::visitInitList(ArrayRef Inits,
   }
 }
 
-return true;
+return this->emitFinishInit(E);
   }
 
   if (const auto *ComplexTy = E->getType()->getAs()) {

di

[clang] Reland #90786 ([BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C) (PR #93121)

2024-05-23 Thread Dan Liew via cfe-commits

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


[clang] Reland #90786 ([BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C) (PR #93121)

2024-05-23 Thread Dan Liew via cfe-commits


@@ -4993,20 +4993,8 @@ void Parser::ParseLexedCAttribute(LateParsedAttribute 
&LA,
  "late field attribute expects to have at most one declaration.");
 
   // Dispatch based on the attribute and parse it
-  const AttributeCommonInfo::Form ParsedForm = ParsedAttr::Form::GNU();

delcypher wrote:

@hnrklssn @rapidsna Heads up I plan to land this change too. I discovered that 
this this switch statement doesn't need to exist because 
`ParseGNUAttributeArgs` effectively already does what we need.

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


[clang] [llvm] [IR] Avoid creating icmp/fcmp constant expressions (PR #92885)

2024-05-23 Thread Nikita Popov via cfe-commits

nikic wrote:

Unfortunately this is a Darwin-only test, and I don't have access to any MacOS 
systems.

@JDevlieghere Could you please help me debug this issue? The test fails when 
trying to evaluate this expression: 
https://github.com/llvm/llvm-project/blob/58ddf3a0c6b6bbdf682ef3421d05e846a6e00527/lldb/test/API/commands/expression/weak_symbols/TestWeakSymbols.py#L37-L42

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


[clang] [clang][analyzer] Move checker 'cert.pos.34c' (in alpha.security) into 'PutenvStackArray' (PR #92424)

2024-05-23 Thread Balázs Kéri via cfe-commits

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


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

2024-05-23 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

Sema.h changes look good.

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


[clang] [clang-tools-extra] [libcxx] Reland "[clang] Enable sized deallocation by default in C++14 onwards" (PR #90373)

2024-05-23 Thread Pengcheng Wang via cfe-commits

wangpc-pp wrote:

Thanks @vitalybuka! After some investigations, I think this PR just uncovered 
the existed ASAN problem.
```cpp
#if !defined(__cpp_sized_deallocation) || __cpp_sized_deallocation < 201309L
#  define _LIBCPP_HAS_NO_LANGUAGE_SIZED_DEALLOCATION
#endif

#if !defined(_LIBCPP_BUILDING_LIBRARY) && _LIBCPP_STD_VER < 14 && 
defined(_LIBCPP_HAS_NO_LANGUAGE_SIZED_DEALLOCATION)
#  define _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION
#endif

#if defined(_LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION) || 
defined(_LIBCPP_HAS_NO_LANGUAGE_SIZED_DEALLOCATION)
#  define _LIBCPP_HAS_NO_SIZED_DEALLOCATION
#endif

template 
_LIBCPP_HIDE_FROM_ABI void __do_deallocate_handle_size(void* __ptr, size_t 
__size, _Args... __args) {
#ifdef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
  (void)__size;
  return std::__libcpp_operator_delete(__ptr, __args...);
#else
  return std::__libcpp_operator_delete(__ptr, __size, __args...);
#endif
}
```
The `__do_deallocate_handle_size` ignored the `__size` before this PR.

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


[clang] [clang] Introduce `SemaX86` (PR #93098)

2024-05-23 Thread Vlad Serebrennikov via cfe-commits

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


[clang] 781b135 - [clang] Introduce `SemaX86` (#93098)

2024-05-23 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-05-23T12:11:15+04:00
New Revision: 781b13538e55a42b2d02bb4d21779f15ff8a640c

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

LOG: [clang] Introduce `SemaX86` (#93098)

This patch moves `Sema` functions that are specific for x86 into the new
`SemaX86` class. This continues previous efforts to split `Sema` up.
Additional context can be found in #84184 and #92682.

Added: 
clang/include/clang/Sema/SemaX86.h
clang/lib/Sema/SemaX86.cpp

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/CMakeLists.txt
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 97784f5ae0dc8..057ff61ccc644 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -177,6 +177,7 @@ class SemaOpenMP;
 class SemaPseudoObject;
 class SemaRISCV;
 class SemaSYCL;
+class SemaX86;
 class StandardConversionSequence;
 class Stmt;
 class StringLiteral;
@@ -1037,6 +1038,11 @@ class Sema final : public SemaBase {
 return *SYCLPtr;
   }
 
+  SemaX86 &X86() {
+assert(X86Ptr);
+return *X86Ptr;
+  }
+
   /// Source of additional semantic information.
   IntrusiveRefCntPtr ExternalSource;
 
@@ -1076,6 +1082,7 @@ class Sema final : public SemaBase {
   std::unique_ptr PseudoObjectPtr;
   std::unique_ptr RISCVPtr;
   std::unique_ptr SYCLPtr;
+  std::unique_ptr X86Ptr;
 
   ///@}
 
@@ -2122,16 +2129,6 @@ class Sema final : public SemaBase {
CallExpr *TheCall);
   bool CheckMipsBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall);
   bool CheckSystemZBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
-  bool CheckX86BuiltinRoundingOrSAE(unsigned BuiltinID, CallExpr *TheCall);
-  bool CheckX86BuiltinGatherScatterScale(unsigned BuiltinID, CallExpr 
*TheCall);
-  bool CheckX86BuiltinTileArguments(unsigned BuiltinID, CallExpr *TheCall);
-  bool CheckX86BuiltinTileArgumentsRange(CallExpr *TheCall,
- ArrayRef ArgNums);
-  bool CheckX86BuiltinTileDuplicate(CallExpr *TheCall, ArrayRef ArgNums);
-  bool CheckX86BuiltinTileRangeAndDuplicate(CallExpr *TheCall,
-ArrayRef ArgNums);
-  bool CheckX86BuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
-   CallExpr *TheCall);
   bool CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
CallExpr *TheCall);
   bool CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);

diff  --git a/clang/include/clang/Sema/SemaX86.h 
b/clang/include/clang/Sema/SemaX86.h
new file mode 100644
index 0..e322483294ec7
--- /dev/null
+++ b/clang/include/clang/Sema/SemaX86.h
@@ -0,0 +1,38 @@
+//===- SemaX86.h --- X86 target-specific routines -*- C++ 
-*---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+/// \file
+/// This file declares semantic analysis functions specific to X86.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_SEMA_SEMAX86_H
+#define LLVM_CLANG_SEMA_SEMAX86_H
+
+#include "clang/AST/Expr.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Sema/SemaBase.h"
+
+namespace clang {
+class SemaX86 : public SemaBase {
+public:
+  SemaX86(Sema &S);
+
+  bool CheckBuiltinRoundingOrSAE(unsigned BuiltinID, CallExpr *TheCall);
+  bool CheckBuiltinGatherScatterScale(unsigned BuiltinID, CallExpr *TheCall);
+  bool CheckBuiltinTileArguments(unsigned BuiltinID, CallExpr *TheCall);
+  bool CheckBuiltinTileArgumentsRange(CallExpr *TheCall, ArrayRef 
ArgNums);
+  bool CheckBuiltinTileDuplicate(CallExpr *TheCall, ArrayRef ArgNums);
+  bool CheckBuiltinTileRangeAndDuplicate(CallExpr *TheCall,
+ ArrayRef ArgNums);
+  bool CheckBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
+CallExpr *TheCall);
+};
+} // namespace clang
+
+#endif // LLVM_CLANG_SEMA_SEMAX86_H

diff  --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index 6b7742cae2db9..fe6471c81ff01 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -71,6 +71,7 @@ add_clang_library(clangSema
   SemaTemplateInstantiateDecl.cpp
   SemaTemplateVariadic.cpp
   SemaType.cpp
+  SemaX86.cpp
   TypeLocBuilder.cpp
 
   DEPENDS

diff  --git a/clang/lib/Se

[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-23 Thread Vikram Hegde via cfe-commits


@@ -6086,6 +6086,62 @@ static SDValue lowerBALLOTIntrinsic(const 
SITargetLowering &TLI, SDNode *N,
   DAG.getConstant(0, SL, MVT::i32), DAG.getCondCode(ISD::SETNE));
 }
 
+static SDValue lowerLaneOp(const SITargetLowering &TLI, SDNode *N,
+   SelectionDAG &DAG) {
+  EVT VT = N->getValueType(0);
+  unsigned ValSize = VT.getSizeInBits();
+  unsigned IntrinsicID = N->getConstantOperandVal(0);
+  SDValue Src0 = N->getOperand(1);
+  SDLoc SL(N);
+  MVT IntVT = MVT::getIntegerVT(ValSize);
+
+  auto createLaneOp = [&DAG, &SL](SDValue Src0, SDValue Src1, SDValue Src2,
+  MVT VT) -> SDValue {
+return (Src2 ? DAG.getNode(AMDGPUISD::WRITELANE, SL, VT, {Src0, Src1, 
Src2})
+: Src1 ? DAG.getNode(AMDGPUISD::READLANE, SL, VT, {Src0, Src1})
+   : DAG.getNode(AMDGPUISD::READFIRSTLANE, SL, VT, {Src0}));
+  };
+
+  SDValue Src1, Src2;
+  if (IntrinsicID == Intrinsic::amdgcn_readlane ||
+  IntrinsicID == Intrinsic::amdgcn_writelane) {
+Src1 = N->getOperand(2);
+if (IntrinsicID == Intrinsic::amdgcn_writelane)
+  Src2 = N->getOperand(3);
+  }
+
+  if (ValSize == 32) {
+// Already legal
+return SDValue();
+  }
+
+  if (ValSize < 32) {
+SDValue InitBitCast = DAG.getBitcast(IntVT, Src0);
+Src0 = DAG.getAnyExtOrTrunc(InitBitCast, SL, MVT::i32);
+if (Src2.getNode()) {
+  SDValue Src2Cast = DAG.getBitcast(IntVT, Src2);

vikramRH wrote:

What would be the proper way to legalize f16 and bf16 for SDAG case without 
bitcasts ? (Im currently thinking  "fp_extend -> LaneOp -> Fptrunc" which seems 
wrong)

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


[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-23 Thread Vikram Hegde via cfe-commits

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


[clang] Reland #90786 ([BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C) (PR #93121)

2024-05-23 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

`Sema.h` changes look good.

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


[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-23 Thread Daniel Krupp via cfe-commits

https://github.com/dkrupp updated 
https://github.com/llvm/llvm-project/pull/92420

>From 80767176cbe8e5717c5f42b113f305d81b635cb9 Mon Sep 17 00:00:00 2001
From: Daniel Krupp 
Date: Tue, 30 Apr 2024 15:20:52 +0200
Subject: [PATCH 1/2] [analyzer] Adding taint analysis capability to
 unix.Malloc checker

unix.Malloc checker will warn if a memory allocation function
(malloc, calloc, realloc, alloca) is called with a tainted
(attacker controlled) size parameter.
A large, maliciously set size value can trigger memory exhaustion.
To get this warning, the alpha.security.taint.TaintPropagation checker
also needs to be switched on.

The warning will only be emitted, if the analyzer cannot prove
that the size is below reasonable bounds (https://wiki.sei.cmu.edu/confluence/display/c/INT04-C.+Enforce+limits+on+integer+values+originating+from+tainted+sources>`_.
+
+You can silence this warning either by bound checking the ``size`` parameter, 
or
+by explicitly marking the ``size`` parameter as sanitized. See the
+:ref:`alpha-security-taint-TaintPropagation` checker for more details.
+
+.. code-block:: c
+
+  void t1(void) {
+size_t size;
+scanf("%zu", &size);
+int *p = malloc(size); // warn: malloc is called with a tainted 
(potentially attacker controlled) value
+free(p);
+  }
+
+  void t3(void) {
+size_t size;
+scanf("%zu", &size);
+if (1024 BT_MismatchedDealloc;
   mutable std::unique_ptr BT_OffsetFree[CK_NumCheckKinds];
   mutable std::unique_ptr BT_UseZerroAllocated[CK_NumCheckKinds];
+  mutable std::unique_ptr BT_TaintedAlloc[CK_NumCheckKinds];
 
 #define CHECK_FN(NAME) 
\
   void NAME(const CallEvent &Call, CheckerContext &C) const;
@@ -462,6 +464,13 @@ class MallocChecker
   };
 
   bool isMemCall(const CallEvent &Call) const;
+  void reportTaintBug(StringRef Msg, ProgramStateRef State, CheckerContext &C,
+  llvm::ArrayRef TaintedSyms,
+  AllocationFamily Family, const Expr *SizeEx) const;
+
+  void CheckTaintedness(CheckerContext &C, const CallEvent &Call,
+const SVal SizeSVal, ProgramStateRef State,
+AllocationFamily Family) const;
 
   // TODO: Remove mutable by moving the initializtaion to the registry 
function.
   mutable std::optional KernelZeroFlagVal;
@@ -521,9 +530,9 @@ class MallocChecker
   /// malloc leaves it undefined.
   /// \param [in] State The \c ProgramState right before allocation.
   /// \returns The ProgramState right after allocation.
-  [[nodiscard]] static ProgramStateRef
+  [[nodiscard]] ProgramStateRef
   MallocMemAux(CheckerContext &C, const CallEvent &Call, const Expr *SizeEx,
-   SVal Init, ProgramStateRef State, AllocationFamily Family);
+   SVal Init, ProgramStateRef State, AllocationFamily Family) 
const;
 
   /// Models memory allocation.
   ///
@@ -534,9 +543,10 @@ class MallocChecker
   /// malloc leaves it undefined.
   /// \param [in] State The \c ProgramState right before allocation.
   /// \returns The ProgramState right after allocation.
-  [[nodiscard]] static ProgramStateRef
-  MallocMemAux(CheckerContext &C, const CallEvent &Call, SVal Size, SVal Init,
-   ProgramStateRef State, AllocationFamily Family);
+  [[nodiscard]] ProgramStateRef MallocMemAux(CheckerContext &C,
+ const CallEvent &Call, SVal Size,
+ SVal Init, ProgramStateRef State,
+ AllocationFamily Family) const;
 
   // Check if this malloc() for special flags. At present that means M_ZERO or
   // __GFP_ZERO (in which case, treat it like calloc).
@@ -649,8 +659,9 @@ class MallocChecker
   /// \param [in] Call The expression that reallocated memory
   /// \param [in] State The \c ProgramState right before reallocation.
   /// \returns The ProgramState right after allocation.
-  [[nodiscard]] static ProgramStateRef
-  CallocMem(CheckerContext &C, const CallEvent &Call, ProgramStateRef State);
+  [[nodiscard]] ProgramStateRef CallocMem(CheckerContext &C,
+  const CallEvent &Call,
+  ProgramStateRef State) const;
 
   /// See if deallocation happens in a suspicious context. If so, escape the
   /// pointers that otherwise would have been deallocated and return true.
@@ -1779,7 +1790,7 @@ ProgramStateRef 
MallocChecker::MallocMemAux(CheckerContext &C,
 const CallEvent &Call,
 const Expr *SizeEx, SVal Init,
 ProgramStateRef State,
-AllocationFamily Family) {
+AllocationFamily Family) const {
   if (!State)
 return nullptr;
 
@@ -1787,10 +1798,71 @@ ProgramStateRef 
MallocChecker:

[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-23 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 1cde1240ed6e45012d7510f4aa39badbdb4a4721 
b31ec694c88635404b252f00472140e83083fd02 -- 
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
clang/test/Analysis/malloc.c clang/test/Analysis/taint-diagnostic-visitor.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 0167dd1336..84fc6700d2 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1824,219 +1824,232 @@ void MallocChecker::reportTaintBug(StringRef Msg, 
ProgramStateRef State,
   }
 }
 
-void MallocChecker::CheckTaintedness(
-  CheckerContext & C, const CallEvent &Call, const SVal SizeSVal,
-  ProgramStateRef State, AllocationFamily Family) const {
-std::vector TaintedSyms =
-taint::getTaintedSymbols(State, SizeSVal);
-if (TaintedSyms.empty())
-  return;
-
-SValBuilder &SVB = C.getSValBuilder();
-QualType SizeTy = SVB.getContext().getSizeType();
-QualType CmpTy = SVB.getConditionType();
-// In case the symbol is tainted, we give a warning if the
-// size is larger than SIZE_MAX/4
-BasicValueFactory &BVF = SVB.getBasicValueFactory();
-const llvm::APSInt MaxValInt = BVF.getMaxValue(SizeTy);
-NonLoc MaxLength =
-SVB.makeIntVal(MaxValInt / APSIntType(MaxValInt).getValue(4));
-std::optional SizeNL = SizeSVal.getAs();
-auto Cmp = SVB.evalBinOpNN(State, BO_GE, *SizeNL, MaxLength, CmpTy)
-   .getAs();
-if (!Cmp)
-  return;
-auto [StateTooLarge, StateNotTooLarge] = State->assume(*Cmp);
-if (!StateTooLarge && StateNotTooLarge) {
-  // we can prove that size is not too large so ok.
-  return;
-}
+void MallocChecker::CheckTaintedness(CheckerContext &C, const CallEvent &Call,
+ const SVal SizeSVal, ProgramStateRef 
State,
+ AllocationFamily Family) const {
+  std::vector TaintedSyms =
+  taint::getTaintedSymbols(State, SizeSVal);
+  if (TaintedSyms.empty())
+return;
 
-std::string Callee = "Memory allocation function";
-if (Call.getCalleeIdentifier())
-  Callee = Call.getCalleeIdentifier()->getName().str();
-reportTaintBug(
-Callee + " is called with a tainted (potentially attacker controlled) "
- "value. Make sure the value is bound checked.",
-State, C, TaintedSyms, Family, Call.getArgExpr(0));
+  SValBuilder &SVB = C.getSValBuilder();
+  QualType SizeTy = SVB.getContext().getSizeType();
+  QualType CmpTy = SVB.getConditionType();
+  // In case the symbol is tainted, we give a warning if the
+  // size is larger than SIZE_MAX/4
+  BasicValueFactory &BVF = SVB.getBasicValueFactory();
+  const llvm::APSInt MaxValInt = BVF.getMaxValue(SizeTy);
+  NonLoc MaxLength =
+  SVB.makeIntVal(MaxValInt / APSIntType(MaxValInt).getValue(4));
+  std::optional SizeNL = SizeSVal.getAs();
+  auto Cmp = SVB.evalBinOpNN(State, BO_GE, *SizeNL, MaxLength, CmpTy)
+ .getAs();
+  if (!Cmp)
+return;
+  auto [StateTooLarge, StateNotTooLarge] = State->assume(*Cmp);
+  if (!StateTooLarge && StateNotTooLarge) {
+// we can prove that size is not too large so ok.
+return;
   }
 
-  ProgramStateRef MallocChecker::MallocMemAux(
-  CheckerContext & C, const CallEvent &Call, SVal Size, SVal Init,
-  ProgramStateRef State, AllocationFamily Family) const {
-if (!State)
-  return nullptr;
+  std::string Callee = "Memory allocation function";
+  if (Call.getCalleeIdentifier())
+Callee = Call.getCalleeIdentifier()->getName().str();
+  reportTaintBug(
+  Callee + " is called with a tainted (potentially attacker controlled) "
+   "value. Make sure the value is bound checked.",
+  State, C, TaintedSyms, Family, Call.getArgExpr(0));
+}
 
-const Expr *CE = Call.getOriginExpr();
+ProgramStateRef MallocChecker::MallocMemAux(CheckerContext &C,
+const CallEvent &Call, SVal Size,
+SVal Init, ProgramStateRef State,
+AllocationFamily Family) const {
+  if (!State)
+return nullptr;
 
-// We expect the malloc functions to return a pointer.
-if (!Loc::isLocType(CE->getType()))
-  return nullptr;
+  const Expr *CE = Call.getOriginExpr();
 
-// Bind the return value to the symbolic value from the heap region.
-// TODO: move use of this functions to an EvalCall callback, becasue
-// BindExpr() should'nt be used elsewhere.
-unsigned Count = C.blockCount();
-SValBuilder &SVB = C.getSValBuilder();
-const Locat

[clang] 951b13d - [clang][Interp][NFC] Save IsUnion bit for Records

2024-05-23 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-05-23T10:21:02+02:00
New Revision: 951b13d9a7220d761b1ee0dc09a50b635692ecf8

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

LOG: [clang][Interp][NFC] Save IsUnion bit for Records

Now that we call this more often, try to keep pointer chasing to a
minimum.

Added: 


Modified: 
clang/lib/AST/Interp/Record.cpp
clang/lib/AST/Interp/Record.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Record.cpp b/clang/lib/AST/Interp/Record.cpp
index 6a0a28bc9124b..8ded765fc1c41 100644
--- a/clang/lib/AST/Interp/Record.cpp
+++ b/clang/lib/AST/Interp/Record.cpp
@@ -16,7 +16,7 @@ Record::Record(const RecordDecl *Decl, BaseList &&SrcBases,
FieldList &&SrcFields, VirtualBaseList &&SrcVirtualBases,
unsigned VirtualSize, unsigned BaseSize)
 : Decl(Decl), Bases(std::move(SrcBases)), Fields(std::move(SrcFields)),
-  BaseSize(BaseSize), VirtualSize(VirtualSize) {
+  BaseSize(BaseSize), VirtualSize(VirtualSize), IsUnion(Decl->isUnion()) {
   for (Base &V : SrcVirtualBases)
 VirtualBases.push_back({ V.Decl, V.Offset + BaseSize, V.Desc, V.R });
 

diff  --git a/clang/lib/AST/Interp/Record.h b/clang/lib/AST/Interp/Record.h
index cf0480b3f62fa..83e15b125f77a 100644
--- a/clang/lib/AST/Interp/Record.h
+++ b/clang/lib/AST/Interp/Record.h
@@ -53,7 +53,7 @@ class Record final {
   /// Returns the name of the underlying declaration.
   const std::string getName() const;
   /// Checks if the record is a union.
-  bool isUnion() const { return getDecl()->isUnion(); }
+  bool isUnion() const { return IsUnion; }
   /// Returns the size of the record.
   unsigned getSize() const { return BaseSize; }
   /// Returns the full size of the record, including records.
@@ -132,6 +132,8 @@ class Record final {
   unsigned BaseSize;
   /// Size of all virtual bases.
   unsigned VirtualSize;
+  /// If this record is a union.
+  bool IsUnion;
 };
 
 } // namespace interp



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


[clang] 335e00f - [clang][Interp][NFC] Add another union test case

2024-05-23 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-05-23T10:21:02+02:00
New Revision: 335e00faaf74f3f7463b32a415d39af0973f521f

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

LOG: [clang][Interp][NFC] Add another union test case

Added: 


Modified: 
clang/test/AST/Interp/unions.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/unions.cpp 
b/clang/test/AST/Interp/unions.cpp
index bc5604c2b2d04..73e42d57a7b77 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -30,3 +30,16 @@ constexpr A ab = {.d = 1.0};
 static_assert(ab.d == 1.0, "");
 static_assert(ab.a == 1, ""); // both-error {{not an integral constant 
expression}} \
   // both-note {{read of member 'a' of union with 
active member 'd'}}
+
+namespace SimpleStore {
+  union A {
+int a;
+int b;
+  };
+  constexpr int foo() {
+A a{.b = 4};
+a.b = 10;
+return a.b;
+  }
+  static_assert(foo() == 10, "");
+}



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


[clang] [clang][FMV] Allow declaration of function versions in namespaces. (PR #93044)

2024-05-23 Thread Alexandros Lamprineas via cfe-commits


@@ -11868,8 +11868,10 @@ static bool CheckMultiVersionFunction(Sema &S, 
FunctionDecl *NewFD,
 return false;
 
   if (!OldDecl || !OldDecl->getAsFunction() ||
-  OldDecl->getDeclContext()->getRedeclContext() !=
-  NewFD->getDeclContext()->getRedeclContext()) {
+  (OldDecl->getDeclContext()->getRedeclContext() !=
+   NewFD->getDeclContext()->getRedeclContext() &&
+   OldDecl->getDeclContext()->getEnclosingNamespaceContext() !=
+   NewFD->getDeclContext()->getEnclosingNamespaceContext())) {

labrinea wrote:

Thanks for the suggestion! I'll push a revised version.

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


[clang] [clang][FMV] Allow declaration of function versions in namespaces. (PR #93044)

2024-05-23 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/93044

>From 730c8c5081862b330d66455a0495e9d317da1795 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Wed, 22 May 2024 15:55:58 +0100
Subject: [PATCH] [clang][FMV] Allow declaration of function versions in
 namespaces.

Fixes the following bug:

namespace Name {
int __attribute((target_version("default"))) foo() { return 0; }
}

namespace Name {
int __attribute((target_version("sve"))) foo() { return 1; }
}

int bar() { return Name::foo(); }

error: redefinition of 'foo'
  int __attribute((target_version("sve"))) foo() { return 1; }

note: previous definition is here
  int __attribute((target_version("default"))) foo() { return 0; }

While fixing this I also found that in the absence of default version
declaration, the one we implicitly create has incorrect mangling if
we are in a namespace:

namespace OtherName {
int __attribute((target_version("sve"))) foo() { return 2; }
}

int baz() { return OtherName::foo(); }

In this example instead of creating a declaration for the symbol
@_ZN9OtherName3fooEv.default we are creating one for the symbol
@_Z3foov.default (the namespace mangling prefix is omitted).
This has now been fixed.
---
 clang/lib/CodeGen/CodeGenModule.cpp |  2 +-
 clang/lib/Sema/SemaDecl.cpp |  4 +-
 clang/test/CodeGenCXX/fmv-namespace.cpp | 93 +
 clang/test/Sema/fmv-namespace.cpp   | 12 
 4 files changed, 108 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/fmv-namespace.cpp
 create mode 100644 clang/test/Sema/fmv-namespace.cpp

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 60ef28a0effaa..e4774a587707a 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4150,7 +4150,7 @@ llvm::GlobalValue::LinkageTypes 
getMultiversionLinkage(CodeGenModule &CGM,
 }
 
 static FunctionDecl *createDefaultTargetVersionFrom(const FunctionDecl *FD) {
-  DeclContext *DeclCtx = FD->getASTContext().getTranslationUnitDecl();
+  auto *DeclCtx = const_cast(FD->getDeclContext());
   TypeSourceInfo *TInfo = FD->getTypeSourceInfo();
   StorageClass SC = FD->getStorageClass();
   DeclarationName Name = FD->getNameInfo().getName();
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b5c3a27ab06e9..10105d5fe9efd 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11868,8 +11868,8 @@ static bool CheckMultiVersionFunction(Sema &S, 
FunctionDecl *NewFD,
 return false;
 
   if (!OldDecl || !OldDecl->getAsFunction() ||
-  OldDecl->getDeclContext()->getRedeclContext() !=
-  NewFD->getDeclContext()->getRedeclContext()) {
+  !OldDecl->getDeclContext()->getRedeclContext()->Equals(
+   NewFD->getDeclContext()->getRedeclContext())) {
 // If there's no previous declaration, AND this isn't attempting to cause
 // multiversioning, this isn't an error condition.
 if (MVKind == MultiVersionKind::None)
diff --git a/clang/test/CodeGenCXX/fmv-namespace.cpp 
b/clang/test/CodeGenCXX/fmv-namespace.cpp
new file mode 100644
index 0..5bcd0da06eebc
--- /dev/null
+++ b/clang/test/CodeGenCXX/fmv-namespace.cpp
@@ -0,0 +1,93 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals all --include-generated-funcs --version 5
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+namespace Name {
+int __attribute((target_version("default"))) foo() { return 0; }
+}
+
+namespace Name {
+int __attribute((target_version("sve"))) foo() { return 1; }
+}
+
+int bar() { return Name::foo(); }
+
+namespace OtherName {
+int __attribute((target_version("sve"))) foo() { return 2; }
+}
+
+int baz() { return OtherName::foo(); }
+
+//.
+// CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
+// CHECK: @_ZN4Name3fooEv.ifunc = weak_odr alias i32 (), ptr @_ZN4Name3fooEv
+// CHECK: @_ZN9OtherName3fooEv.ifunc = weak_odr alias i32 (), ptr 
@_ZN9OtherName3fooEv
+// CHECK: @_ZN4Name3fooEv = weak_odr ifunc i32 (), ptr @_ZN4Name3fooEv.resolver
+// CHECK: @_ZN9OtherName3fooEv = weak_odr ifunc i32 (), ptr 
@_ZN9OtherName3fooEv.resolver
+//.
+// CHECK-LABEL: define dso_local noundef i32 @_ZN4Name3fooEv.default(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:ret i32 0
+//
+//
+// CHECK-LABEL: define dso_local noundef i32 @_ZN4Name3fooEv._Msve(
+// CHECK-SAME: ) #[[ATTR1:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:ret i32 1
+//
+//
+// CHECK-LABEL: define dso_local noundef i32 @_Z3barv(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[CALL:%.*]] = call noundef i32 @_ZN4Name3fooEv()
+// CHECK-NEXT:ret i32 [[CALL]]
+//
+//
+// CHECK-LABEL: define weak_odr ptr @_ZN4Name3fooEv.resolver() comdat {
+// CHECK-NEXT:  [[RESOLVER_ENTRY:.*:]]
+// CHECK-NEXT:ca

[clang] [clang][FMV] Allow declaration of function versions in namespaces. (PR #93044)

2024-05-23 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/93044

>From ba2b8b53d80e17b1477a7d6fed51f0450bc539a3 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Wed, 22 May 2024 15:55:58 +0100
Subject: [PATCH] [clang][FMV] Allow declaration of function versions in
 namespaces.

Fixes the following bug:

namespace Name {
int __attribute((target_version("default"))) foo() { return 0; }
}

namespace Name {
int __attribute((target_version("sve"))) foo() { return 1; }
}

int bar() { return Name::foo(); }

error: redefinition of 'foo'
  int __attribute((target_version("sve"))) foo() { return 1; }

note: previous definition is here
  int __attribute((target_version("default"))) foo() { return 0; }

While fixing this I also found that in the absence of default version
declaration, the one we implicitly create has incorrect mangling if
we are in a namespace:

namespace OtherName {
int __attribute((target_version("sve"))) foo() { return 2; }
}

int baz() { return OtherName::foo(); }

In this example instead of creating a declaration for the symbol
@_ZN9OtherName3fooEv.default we are creating one for the symbol
@_Z3foov.default (the namespace mangling prefix is omitted).
This has now been fixed.
---
 clang/lib/CodeGen/CodeGenModule.cpp |  2 +-
 clang/lib/Sema/SemaDecl.cpp |  4 +-
 clang/test/CodeGenCXX/fmv-namespace.cpp | 93 +
 clang/test/Sema/fmv-namespace.cpp   | 12 
 4 files changed, 108 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/fmv-namespace.cpp
 create mode 100644 clang/test/Sema/fmv-namespace.cpp

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 60ef28a0effaa..e4774a587707a 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4150,7 +4150,7 @@ llvm::GlobalValue::LinkageTypes 
getMultiversionLinkage(CodeGenModule &CGM,
 }
 
 static FunctionDecl *createDefaultTargetVersionFrom(const FunctionDecl *FD) {
-  DeclContext *DeclCtx = FD->getASTContext().getTranslationUnitDecl();
+  auto *DeclCtx = const_cast(FD->getDeclContext());
   TypeSourceInfo *TInfo = FD->getTypeSourceInfo();
   StorageClass SC = FD->getStorageClass();
   DeclarationName Name = FD->getNameInfo().getName();
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b5c3a27ab06e9..2a87b26f17a2b 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11868,8 +11868,8 @@ static bool CheckMultiVersionFunction(Sema &S, 
FunctionDecl *NewFD,
 return false;
 
   if (!OldDecl || !OldDecl->getAsFunction() ||
-  OldDecl->getDeclContext()->getRedeclContext() !=
-  NewFD->getDeclContext()->getRedeclContext()) {
+  !OldDecl->getDeclContext()->getRedeclContext()->Equals(
+  NewFD->getDeclContext()->getRedeclContext())) {
 // If there's no previous declaration, AND this isn't attempting to cause
 // multiversioning, this isn't an error condition.
 if (MVKind == MultiVersionKind::None)
diff --git a/clang/test/CodeGenCXX/fmv-namespace.cpp 
b/clang/test/CodeGenCXX/fmv-namespace.cpp
new file mode 100644
index 0..5bcd0da06eebc
--- /dev/null
+++ b/clang/test/CodeGenCXX/fmv-namespace.cpp
@@ -0,0 +1,93 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals all --include-generated-funcs --version 5
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+namespace Name {
+int __attribute((target_version("default"))) foo() { return 0; }
+}
+
+namespace Name {
+int __attribute((target_version("sve"))) foo() { return 1; }
+}
+
+int bar() { return Name::foo(); }
+
+namespace OtherName {
+int __attribute((target_version("sve"))) foo() { return 2; }
+}
+
+int baz() { return OtherName::foo(); }
+
+//.
+// CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
+// CHECK: @_ZN4Name3fooEv.ifunc = weak_odr alias i32 (), ptr @_ZN4Name3fooEv
+// CHECK: @_ZN9OtherName3fooEv.ifunc = weak_odr alias i32 (), ptr 
@_ZN9OtherName3fooEv
+// CHECK: @_ZN4Name3fooEv = weak_odr ifunc i32 (), ptr @_ZN4Name3fooEv.resolver
+// CHECK: @_ZN9OtherName3fooEv = weak_odr ifunc i32 (), ptr 
@_ZN9OtherName3fooEv.resolver
+//.
+// CHECK-LABEL: define dso_local noundef i32 @_ZN4Name3fooEv.default(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:ret i32 0
+//
+//
+// CHECK-LABEL: define dso_local noundef i32 @_ZN4Name3fooEv._Msve(
+// CHECK-SAME: ) #[[ATTR1:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:ret i32 1
+//
+//
+// CHECK-LABEL: define dso_local noundef i32 @_Z3barv(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[CALL:%.*]] = call noundef i32 @_ZN4Name3fooEv()
+// CHECK-NEXT:ret i32 [[CALL]]
+//
+//
+// CHECK-LABEL: define weak_odr ptr @_ZN4Name3fooEv.resolver() comdat {
+// CHECK-NEXT:  [[RESOLVER_ENTRY:.*:]]
+// CHECK-NEXT:cal

[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-23 Thread Vikram Hegde via cfe-commits


@@ -5387,6 +5387,192 @@ bool 
AMDGPULegalizerInfo::legalizeDSAtomicFPIntrinsic(LegalizerHelper &Helper,
   return true;
 }
 
+bool AMDGPULegalizerInfo::legalizeLaneOp(LegalizerHelper &Helper,
+ MachineInstr &MI,
+ Intrinsic::ID IID) const {
+
+  MachineIRBuilder &B = Helper.MIRBuilder;
+  MachineRegisterInfo &MRI = *B.getMRI();
+
+  Register DstReg = MI.getOperand(0).getReg();
+  Register Src0 = MI.getOperand(2).getReg();
+
+  auto createLaneOp = [&](Register Src0, Register Src1,
+  Register Src2) -> Register {
+auto LaneOp = B.buildIntrinsic(IID, {S32}).addUse(Src0);
+switch (IID) {
+case Intrinsic::amdgcn_readfirstlane:
+  return LaneOp.getReg(0);
+case Intrinsic::amdgcn_readlane:
+  return LaneOp.addUse(Src1).getReg(0);
+case Intrinsic::amdgcn_writelane:
+  return LaneOp.addUse(Src1).addUse(Src2).getReg(0);
+default:
+  llvm_unreachable("unhandled lane op");
+}
+  };
+
+  Register Src1, Src2;
+  if (IID == Intrinsic::amdgcn_readlane || IID == Intrinsic::amdgcn_writelane) 
{
+Src1 = MI.getOperand(3).getReg();
+if (IID == Intrinsic::amdgcn_writelane) {
+  Src2 = MI.getOperand(4).getReg();
+}
+  }
+
+  LLT Ty = MRI.getType(DstReg);
+  unsigned Size = Ty.getSizeInBits();
+
+  if (Size == 32) {
+// Already legal
+return true;
+  }
+
+  if (Size < 32) {
+Register Src0Cast = MRI.getType(Src0).isScalar()
+? Src0
+: B.buildBitcast(LLT::scalar(Size), 
Src0).getReg(0);
+Src0 = B.buildAnyExt(S32, Src0Cast).getReg(0);
+if (Src2.isValid()) {
+  Register Src2Cast =
+  MRI.getType(Src2).isScalar()
+  ? Src2
+  : B.buildBitcast(LLT::scalar(Size), Src2).getReg(0);
+  Src2 = B.buildAnyExt(LLT::scalar(32), Src2Cast).getReg(0);
+}
+
+Register LaneOpDst = createLaneOp(Src0, Src1, Src2);
+if (Ty.isScalar())
+  B.buildTrunc(DstReg, LaneOpDst);
+else {
+  auto Trunc = B.buildTrunc(LLT::scalar(Size), LaneOpDst);
+  B.buildBitcast(DstReg, Trunc);
+}
+
+MI.eraseFromParent();
+return true;
+  }
+
+  if ((Size % 32) == 0) {
+SmallVector PartialRes;
+unsigned NumParts = Size / 32;
+auto IsS16Vec = Ty.isVector() && Ty.getElementType() == S16;
+MachineInstrBuilder Src0Parts;
+
+if (Ty.isPointer()) {
+  auto PtrToInt = B.buildPtrToInt(LLT::scalar(Size), Src0);
+  Src0Parts = B.buildUnmerge(S32, PtrToInt);
+} else if (Ty.isPointerVector()) {
+  LLT IntVecTy = Ty.changeElementType(
+  LLT::scalar(Ty.getElementType().getSizeInBits()));
+  auto PtrToInt = B.buildPtrToInt(IntVecTy, Src0);
+  Src0Parts = B.buildUnmerge(S32, PtrToInt);
+} else
+  Src0Parts =
+  IsS16Vec ? B.buildUnmerge(V2S16, Src0) : B.buildUnmerge(S32, Src0);
+
+switch (IID) {
+case Intrinsic::amdgcn_readlane: {
+  Register Src1 = MI.getOperand(3).getReg();
+  for (unsigned i = 0; i < NumParts; ++i) {
+Src0 = IsS16Vec ? B.buildBitcast(S32, Src0Parts.getReg(i)).getReg(0)
+: Src0Parts.getReg(i);
+PartialRes.push_back(
+(B.buildIntrinsic(Intrinsic::amdgcn_readlane, {S32})
+ .addUse(Src0)
+ .addUse(Src1))
+.getReg(0));
+  }
+  break;
+}
+case Intrinsic::amdgcn_readfirstlane: {
+  for (unsigned i = 0; i < NumParts; ++i) {
+Src0 = IsS16Vec ? B.buildBitcast(S32, Src0Parts.getReg(i)).getReg(0)
+: Src0Parts.getReg(i);
+PartialRes.push_back(
+(B.buildIntrinsic(Intrinsic::amdgcn_readfirstlane, {S32})
+ .addUse(Src0)
+ .getReg(0)));
+  }
+
+  break;
+}
+case Intrinsic::amdgcn_writelane: {
+  Register Src1 = MI.getOperand(3).getReg();
+  Register Src2 = MI.getOperand(4).getReg();
+  MachineInstrBuilder Src2Parts;
+
+  if (Ty.isPointer()) {
+auto PtrToInt = B.buildPtrToInt(S64, Src2);
+Src2Parts = B.buildUnmerge(S32, PtrToInt);
+  } else if (Ty.isPointerVector()) {
+LLT IntVecTy = Ty.changeElementType(
+LLT::scalar(Ty.getElementType().getSizeInBits()));
+auto PtrToInt = B.buildPtrToInt(IntVecTy, Src2);
+Src2Parts = B.buildUnmerge(S32, PtrToInt);
+  } else
+Src2Parts =
+IsS16Vec ? B.buildUnmerge(V2S16, Src2) : B.buildUnmerge(S32, Src2);

vikramRH wrote:

done

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


[clang] [clang][analyzer] Move checker 'cert.pos.34c' (in alpha.security) into 'PutenvStackArray' (PR #92424)

2024-05-23 Thread Balázs Kéri via cfe-commits

https://github.com/balazske updated 
https://github.com/llvm/llvm-project/pull/92424

From 769523d392204eac6c48cb80a2282212f3edbbe4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Fri, 10 May 2024 17:30:23 +0200
Subject: [PATCH 1/4] [clang][analyzer] Move checker
 alpha.security.cert.pos.34c into security.PutenvWithAuto .

The "cert" package looks not useful and the checker has not a meaningful name
with the old naming scheme.
Additionally tests and documentation is updated.
The checker looks good enough to be moved into non-alpha package.
---
 clang/docs/analyzer/checkers.rst  | 97 +--
 .../clang/StaticAnalyzer/Checkers/Checkers.td | 10 +-
 .../Analysis/cert/pos34-c-fp-suppression.cpp  | 51 --
 clang/test/Analysis/cert/pos34-c.cpp  | 61 
 clang/test/Analysis/putenv-with-auto.c| 66 +
 5 files changed, 119 insertions(+), 166 deletions(-)
 delete mode 100644 clang/test/Analysis/cert/pos34-c-fp-suppression.cpp
 delete mode 100644 clang/test/Analysis/cert/pos34-c.cpp
 create mode 100644 clang/test/Analysis/putenv-with-auto.c

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index eb8b58323da4d..6ea768d003378 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -1179,6 +1179,54 @@ security.insecureAPI.DeprecatedOrUnsafeBufferHandling (C)
strncpy(buf, "a", 1); // warn
  }
 
+.. _security-putenv-with-auto:
+
+security.PutenvWithAuto
+"""
+Finds calls to the ``putenv`` function which pass a pointer to an automatic 
variable as the argument.
+Function ``putenv`` does not copy the passed string, only a pointer to the 
data is stored.
+Content of an automatic variable is likely to be overwritten after returning 
from the parent function.
+
+The problem can be solved by using a static variable or dynamically allocated
+memory. Even better is to avoid using ``putenv`` (it has other problems
+related to memory leaks) and use ``setenv`` instead.
+
+The check corresponds to CERT rule
+`POS34-C. Do not call putenv() with a pointer to an automatic variable as the 
argument
+`_.
+
+.. code-block:: c
+
+  int f() {
+char[] env = "NAME=value";
+return putenv(env); // putenv function should not be called with auto 
variables
+  }
+
+Limitations:
+
+   - In specific cases one can pass automatic variables to ``putenv``,
+ but one needs to ensure that the given environment key stays
+ alive until it's removed or overwritten.
+ Since the analyzer cannot keep track if and when the string passed to 
``putenv``
+ gets deallocated or overwritten, it needs to be slightly more aggressive
+ and warn for each case, leading in some cases to false-positive reports 
like this:
+
+ .. code-block:: c
+
+void baz() {
+  char env[] = "NAME=value";
+  putenv(env); // false-positive warning: putenv function should not 
be called...
+  // More code...
+  // FIXME: It looks like that if one string was passed to putenv,
+  // it should not be deallocated at all, because when reading the
+  // environment variable a pointer into this string is returned.
+  // In this case, if another (or the same) thread reads variable 
"NAME"
+  // at this point and does not copy the returned string, the data may
+  // become invalid.
+  putenv((char *)"NAME=anothervalue");
+  // This putenv call overwrites the previous entry, thus that can no 
longer dangle.
+} // 'env' array becomes dead only here.
+
 .. _unix-checkers:
 
 unix
@@ -2818,55 +2866,6 @@ alpha.security.cert
 
 SEI CERT checkers which tries to find errors based on their `C coding rules 
`_.
 
-.. _alpha-security-cert-pos-checkers:
-
-alpha.security.cert.pos
-^^^
-
-SEI CERT checkers of `POSIX C coding rules 
`_.
-
-.. _alpha-security-cert-pos-34c:
-
-alpha.security.cert.pos.34c
-"""
-Finds calls to the ``putenv`` function which pass a pointer to an automatic 
variable as the argument.
-
-.. code-block:: c
-
-  int func(const char *var) {
-char env[1024];
-int retval = snprintf(env, sizeof(env),"TEST=%s", var);
-if (retval < 0 || (size_t)retval >= sizeof(env)) {
-/* Handle error */
-}
-
-return putenv(env); // putenv function should not be called with auto 
variables
-  }
-
-Limitations:
-
-   - Technically, one can pass automatic variables to ``putenv``,
- but one needs to ensure that the given environment key stays
- alive until it's removed or overwritten.
- Since the analyzer cannot keep track of which envvars get overwritten
- a

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

2024-05-23 Thread via cfe-commits
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= 
Message-ID:
In-Reply-To: 


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


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


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

2024-05-23 Thread via cfe-commits
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,150 @@
+// RUN: %check_clang_tidy -std=c++98-or-later %s 
bugprone-tagged-union-member-count %t \
+// RUN:   -config='{CheckOptions: { \
+// RUN: bugprone-tagged-union-member-count.StrictMode: 1, \
+// RUN: bugprone-tagged-union-member-count.EnumCounterHeuristicIsEnabled: 
0, \
+// RUN: bugprone-tagged-union-member-count.EnumCounterSuffix: "count", \
+// RUN:  }}' --
+
+typedef enum tags3 {
+   tags3_1,
+   tags3_2,
+   tags3_3,
+} tags3;
+
+typedef enum tags4 {
+   tags4_1,
+   tags4_2,
+   tags4_3,
+   tags4_4,
+} tags4;
+
+typedef enum tags5 {
+   tags5_1,
+   tags5_2,
+   tags5_3,
+   tags5_4,
+   tags5_5,
+} tags5;
+
+enum class classtags3 {
+   classtags3_1,
+   classtags3_2,
+   classtags3_3,
+};
+
+enum class classtags4 {
+   classtags4_1,
+   classtags4_2,
+   classtags4_3,
+   classtags4_4,
+};
+
+enum class classtags5 {
+   classtags5_1,
+   classtags5_2,
+   classtags5_3,
+   classtags5_4,
+   classtags5_5,
+};
+
+enum class typedtags3 : unsigned int {
+   typedtags3_1,
+   typedtags3_2,
+   typedtags3_3,
+};
+
+enum class typedtags4 : long {
+   typedtags4_1,
+   typedtags4_2,
+   typedtags4_3,
+   typedtags4_4,
+};
+
+enum class typedtags5 {
+   typedtags5_1,
+   typedtags5_2,
+   typedtags5_3,
+   typedtags5_4,
+   typedtags5_5,
+};
+
+typedef union union3 {
+   short *shorts;
+   int *ints;
+   float *floats;
+} union3;
+
+typedef union union4 {
+   short *shorts;
+   double *doubles;
+   int *ints;
+   float *floats;
+} union4;
+
+// Technically this means that every enum value is defined from 0-256 and 
therefore a warning is given.
+enum mycolor {
+   mycolor_black = 0x00,
+   mycolor_gray  = 0xcc,
+   mycolor_white = 0xff,
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:8: warning: Tagged union has fewer data 
members (3) than tags (256)! [bugprone-tagged-union-member-count]
+struct taggedunion9 { 
+   enum mycolor tag;
+   union {
+   int a;
+   float b;
+   struct {
+   double re;
+   double im;
+   } complex;
+   } data;
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:8: warning: Tagged union has fewer data 
members (3) than tags (4)! [bugprone-tagged-union-member-count]

whisperity wrote:

```suggestion
// CHECK-MESSAGES: :[[@LINE+1]]:8: warning: Tagged union has fewer data members 
(3) than tags (4)
```

There is no need to repeat the full message in every line, as the check is 
applied as a substring and regular expression match, it is enough to type out 
the prefix only until the last dynamically generated part.

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


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

2024-05-23 Thread via cfe-commits
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= 
Message-ID:
In-Reply-To: 


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


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

2024-05-23 Thread via cfe-commits
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,37 @@
+//===--- TaggedUnionMemberCountCheck.h - clang-tidy -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_TAGGEDUNIONMEMBERCOUNTCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_TAGGEDUNIONMEMBERCOUNTCHECK_H
+
+#include "../ClangTidyCheck.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace clang::tidy::bugprone {
+
+// Gives warnings for tagged unions, where the number of tags is
+// different from the number of data members inside the union.
+//
+// For the user-facing documentation see:
+// 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone/tagged-union-member-count.html
+class TaggedUnionMemberCountCheck : public ClangTidyCheck {
+public:
+  TaggedUnionMemberCountCheck(StringRef Name, ClangTidyContext *Context);
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+  bool EnumCounterHeuristicIsEnabled;
+  StringRef EnumCounterSuffix;

whisperity wrote:

Perhaps this should be a `vector` or something of sorts. Using 
`Foo;Bar;Baz` as the input from the user, you can use something called 
`splitOptions` under `utils`. It would allow to support various styles at the 
same time, as some enums might be called `_Count` but others `Last_`.

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


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

2024-05-23 Thread via cfe-commits
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,37 @@
+//===--- TaggedUnionMemberCountCheck.h - clang-tidy -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_TAGGEDUNIONMEMBERCOUNTCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_TAGGEDUNIONMEMBERCOUNTCHECK_H
+
+#include "../ClangTidyCheck.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace clang::tidy::bugprone {
+
+// Gives warnings for tagged unions, where the number of tags is
+// different from the number of data members inside the union.
+//
+// For the user-facing documentation see:
+// 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone/tagged-union-member-count.html
+class TaggedUnionMemberCountCheck : public ClangTidyCheck {
+public:
+  TaggedUnionMemberCountCheck(StringRef Name, ClangTidyContext *Context);
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+  bool EnumCounterHeuristicIsEnabled;
+  StringRef EnumCounterSuffix;
+  bool StrictMode;

whisperity wrote:

If these are the values to store the check config options the user specified, 
these should be `const` and not modified during analysis.

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


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

2024-05-23 Thread via cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-23 Thread via cfe-commits
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,145 @@
+//===--- TaggedUnionMemberCountCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TaggedUnionMemberCountCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/AST/PrettyPrinter.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Casting.h"
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+TaggedUnionMemberCountCheck::TaggedUnionMemberCountCheck(StringRef Name, 
ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context),
+
EnumCounterHeuristicIsEnabled(Options.get("EnumCounterHeuristicIsEnabled", 
true)),
+EnumCounterSuffix(Options.get("EnumCounterSuffix", "count")),
+StrictMode(Options.get("StrictMode", true)) { }
+
+void TaggedUnionMemberCountCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "StrictMode", StrictMode);
+  Options.store(Opts, "EnumCounterHeuristicIsEnabled", 
EnumCounterHeuristicIsEnabled);
+  Options.store(Opts, "EnumCounterSuffix", EnumCounterSuffix);
+}
+
+void TaggedUnionMemberCountCheck::registerMatchers(MatchFinder *Finder) {
+Finder->addMatcher(
+  recordDecl(
+  allOf(isStruct(),
+   
has(fieldDecl(hasType(qualType(hasCanonicalType(recordType().bind("union")),
+   
has(fieldDecl(hasType(qualType(hasCanonicalType(enumType().bind("tags"
+  .bind("root"),
+  this);
+}
+
+static bool isUnion(const FieldDecl *R) {
+   return R->getType().getCanonicalType().getTypePtr()->isUnionType();
+}
+
+static bool isEnum(const FieldDecl *R) {
+   return R->getType().getCanonicalType().getTypePtr()->isEnumeralType();
+}
+
+static bool hasMultipleUnionsOrEnums(const RecordDecl *rec) {
+  return llvm::count_if(rec->fields(), isUnion) > 1 ||
+ llvm::count_if(rec->fields(), isEnum) > 1;
+}
+
+static size_t getNumberOfValidEnumValues(const EnumDecl *ed, bool 
EnumCounterHeuristicIsEnabled, StringRef EnumCounterSuffix) {
+  int64_t maxTagValue = std::numeric_limits::min();
+  int64_t minTagValue = std::numeric_limits::max();
+
+  // Heuristic for counter enum constants.
+  //
+  //   enum tag_with_counter {
+  // tag1,
+  // tag2,
+  // tag_count, <-- Searching for these enum constants
+  //   };
+  //
+  // The 'ce' prefix is used to abbreviate counterEnum.
+  // The final tag count is decreased by 1 if and only if:
+  // 1. The number of counting enum constants = 1,
+  int ceCount = 0;
+  // 2. The counting enum constant is the last enum constant that is defined,
+  int ceFirstIndex = 0;
+  // 3. The value of the counting enum constant is the largest out of every 
enum constant.
+  int64_t ceValue = 0;
+
+  int64_t enumConstantsCount = 0;
+  for (auto En : llvm::enumerate(ed->enumerators())) {
+enumConstantsCount += 1;
+
+int64_t enumValue = En.value()->getInitVal().getExtValue();
+StringRef enumName = En.value()->getName();
+
+if (enumValue > maxTagValue)
+  maxTagValue = enumValue;
+if (enumValue < minTagValue)
+  minTagValue = enumValue;
+
+if (enumName.ends_with_insensitive(EnumCounterSuffix)) {
+  if (ceCount == 0) {
+ceFirstIndex = En.index();
+  }
+  ceValue = enumValue;
+  ceCount += 1;
+}
+  }
+
+  int64_t validValuesCount = maxTagValue - minTagValue + 1;
+  if (EnumCounterHeuristicIsEnabled &&
+  ceCount == 1 &&
+  ceFirstIndex == enumConstantsCount - 1 &&
+  ceValue == maxTagValue) {
+validValuesCount -= 1;
+  }
+  return validValuesCount;
+}
+
+// Feladatok:
+// - typedef tesztelés
+// - template tesztelés
+// - névtelen union tesztelés
+// - "count" paraméterezése

whisperity wrote:

In-development comments remained in the patch.

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


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

2024-05-23 Thread via cfe-commits
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,145 @@
+//===--- TaggedUnionMemberCountCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TaggedUnionMemberCountCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/AST/PrettyPrinter.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Casting.h"
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+TaggedUnionMemberCountCheck::TaggedUnionMemberCountCheck(StringRef Name, 
ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context),
+
EnumCounterHeuristicIsEnabled(Options.get("EnumCounterHeuristicIsEnabled", 
true)),
+EnumCounterSuffix(Options.get("EnumCounterSuffix", "count")),
+StrictMode(Options.get("StrictMode", true)) { }
+
+void TaggedUnionMemberCountCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "StrictMode", StrictMode);
+  Options.store(Opts, "EnumCounterHeuristicIsEnabled", 
EnumCounterHeuristicIsEnabled);
+  Options.store(Opts, "EnumCounterSuffix", EnumCounterSuffix);
+}
+
+void TaggedUnionMemberCountCheck::registerMatchers(MatchFinder *Finder) {
+Finder->addMatcher(
+  recordDecl(
+  allOf(isStruct(),
+   
has(fieldDecl(hasType(qualType(hasCanonicalType(recordType().bind("union")),
+   
has(fieldDecl(hasType(qualType(hasCanonicalType(enumType().bind("tags"
+  .bind("root"),
+  this);
+}

whisperity wrote:

(Nit, but this should be re-formatted.)

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


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

2024-05-23 Thread via cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-23 Thread Vikram Hegde via cfe-commits

vikramRH wrote:

updated the GIsel legalizer, I still have couple of questions for SDAG case 
though,
1. What's the proper way to legalize f16 and bf16 for SDAG case without 
bitcasts ? (I would think  "fp_extend -> LaneOp -> Fptrunc" is wrong)
2. For scalar cases such as i64, f64, i128 .. (i.e 32 bit multiples), I guess 
bitcast to vectors (v2i32, v2f32, v4i32) is unavoidable since "UnrollVectorOp" 
wouldn't work otherwise. any alternalte suggestions here ?

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


[clang] 8930ba9 - [clang][FMV] Allow declaration of function versions in namespaces. (#93044)

2024-05-23 Thread via cfe-commits

Author: Alexandros Lamprineas
Date: 2024-05-23T10:09:22+01:00
New Revision: 8930ba98e01bc66949e482b396f8389d64388359

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

LOG: [clang][FMV] Allow declaration of function versions in namespaces. (#93044)

Fixes the following bug:

namespace Name {
int __attribute((target_version("default"))) foo() { return 0; }
}

namespace Name {
int __attribute((target_version("sve"))) foo() { return 1; }
}

int bar() { return Name::foo(); }

error: redefinition of 'foo'
  int __attribute((target_version("sve"))) foo() { return 1; }

note: previous definition is here
  int __attribute((target_version("default"))) foo() { return 0; }

While fixing this I also found that in the absence of default version
declaration, the one we implicitly create has incorrect mangling if
we are in a namespace:

namespace OtherName {
int __attribute((target_version("sve"))) foo() { return 2; }
}

int baz() { return OtherName::foo(); }

In this example instead of creating a declaration for the symbol
@_ZN9OtherName3fooEv.default we are creating one for the symbol
@_Z3foov.default (the namespace mangling prefix is omitted).
This has now been fixed.

Added: 
clang/test/CodeGenCXX/fmv-namespace.cpp
clang/test/Sema/fmv-namespace.cpp

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 60ef28a0effaa..e4774a587707a 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4150,7 +4150,7 @@ llvm::GlobalValue::LinkageTypes 
getMultiversionLinkage(CodeGenModule &CGM,
 }
 
 static FunctionDecl *createDefaultTargetVersionFrom(const FunctionDecl *FD) {
-  DeclContext *DeclCtx = FD->getASTContext().getTranslationUnitDecl();
+  auto *DeclCtx = const_cast(FD->getDeclContext());
   TypeSourceInfo *TInfo = FD->getTypeSourceInfo();
   StorageClass SC = FD->getStorageClass();
   DeclarationName Name = FD->getNameInfo().getName();

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b5c3a27ab06e9..2a87b26f17a2b 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11868,8 +11868,8 @@ static bool CheckMultiVersionFunction(Sema &S, 
FunctionDecl *NewFD,
 return false;
 
   if (!OldDecl || !OldDecl->getAsFunction() ||
-  OldDecl->getDeclContext()->getRedeclContext() !=
-  NewFD->getDeclContext()->getRedeclContext()) {
+  !OldDecl->getDeclContext()->getRedeclContext()->Equals(
+  NewFD->getDeclContext()->getRedeclContext())) {
 // If there's no previous declaration, AND this isn't attempting to cause
 // multiversioning, this isn't an error condition.
 if (MVKind == MultiVersionKind::None)

diff  --git a/clang/test/CodeGenCXX/fmv-namespace.cpp 
b/clang/test/CodeGenCXX/fmv-namespace.cpp
new file mode 100644
index 0..5bcd0da06eebc
--- /dev/null
+++ b/clang/test/CodeGenCXX/fmv-namespace.cpp
@@ -0,0 +1,93 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals all --include-generated-funcs --version 5
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+namespace Name {
+int __attribute((target_version("default"))) foo() { return 0; }
+}
+
+namespace Name {
+int __attribute((target_version("sve"))) foo() { return 1; }
+}
+
+int bar() { return Name::foo(); }
+
+namespace OtherName {
+int __attribute((target_version("sve"))) foo() { return 2; }
+}
+
+int baz() { return OtherName::foo(); }
+
+//.
+// CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
+// CHECK: @_ZN4Name3fooEv.ifunc = weak_odr alias i32 (), ptr @_ZN4Name3fooEv
+// CHECK: @_ZN9OtherName3fooEv.ifunc = weak_odr alias i32 (), ptr 
@_ZN9OtherName3fooEv
+// CHECK: @_ZN4Name3fooEv = weak_odr ifunc i32 (), ptr @_ZN4Name3fooEv.resolver
+// CHECK: @_ZN9OtherName3fooEv = weak_odr ifunc i32 (), ptr 
@_ZN9OtherName3fooEv.resolver
+//.
+// CHECK-LABEL: define dso_local noundef i32 @_ZN4Name3fooEv.default(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:ret i32 0
+//
+//
+// CHECK-LABEL: define dso_local noundef i32 @_ZN4Name3fooEv._Msve(
+// CHECK-SAME: ) #[[ATTR1:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:ret i32 1
+//
+//
+// CHECK-LABEL: define dso_local noundef i32 @_Z3barv(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[CALL:%.*]] = call noundef i32 @_ZN4Name3fooEv()
+// CHECK-NEXT:ret i32 [[CALL]]
+//
+//
+// CHECK-LABEL: define weak_odr ptr @_ZN4Name3fooEv.resolver() comdat {
+// CHECK-NEXT:  [[RESOLVER_ENTRY:.*:]]
+// CHECK-NEXT:call void @__init_cpu_features_resolve

[clang] [clang][FMV] Allow declaration of function versions in namespaces. (PR #93044)

2024-05-23 Thread Alexandros Lamprineas via cfe-commits

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


[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-23 Thread Jay Foad via cfe-commits

jayfoad wrote:

> 1. What's the proper way to legalize f16 and bf16 for SDAG case without 
> bitcasts ? (I would think  "fp_extend -> LaneOp -> Fptrunc" is wrong)

Bitcast to i16, anyext to i32, laneop, trunc to i16, bitcast to original type.

Why wouldn't you use bitcasts?

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


[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-23 Thread Daniel Krupp via cfe-commits

https://github.com/dkrupp updated 
https://github.com/llvm/llvm-project/pull/92420

>From 80767176cbe8e5717c5f42b113f305d81b635cb9 Mon Sep 17 00:00:00 2001
From: Daniel Krupp 
Date: Tue, 30 Apr 2024 15:20:52 +0200
Subject: [PATCH 1/2] [analyzer] Adding taint analysis capability to
 unix.Malloc checker

unix.Malloc checker will warn if a memory allocation function
(malloc, calloc, realloc, alloca) is called with a tainted
(attacker controlled) size parameter.
A large, maliciously set size value can trigger memory exhaustion.
To get this warning, the alpha.security.taint.TaintPropagation checker
also needs to be switched on.

The warning will only be emitted, if the analyzer cannot prove
that the size is below reasonable bounds (https://wiki.sei.cmu.edu/confluence/display/c/INT04-C.+Enforce+limits+on+integer+values+originating+from+tainted+sources>`_.
+
+You can silence this warning either by bound checking the ``size`` parameter, 
or
+by explicitly marking the ``size`` parameter as sanitized. See the
+:ref:`alpha-security-taint-TaintPropagation` checker for more details.
+
+.. code-block:: c
+
+  void t1(void) {
+size_t size;
+scanf("%zu", &size);
+int *p = malloc(size); // warn: malloc is called with a tainted 
(potentially attacker controlled) value
+free(p);
+  }
+
+  void t3(void) {
+size_t size;
+scanf("%zu", &size);
+if (1024 BT_MismatchedDealloc;
   mutable std::unique_ptr BT_OffsetFree[CK_NumCheckKinds];
   mutable std::unique_ptr BT_UseZerroAllocated[CK_NumCheckKinds];
+  mutable std::unique_ptr BT_TaintedAlloc[CK_NumCheckKinds];
 
 #define CHECK_FN(NAME) 
\
   void NAME(const CallEvent &Call, CheckerContext &C) const;
@@ -462,6 +464,13 @@ class MallocChecker
   };
 
   bool isMemCall(const CallEvent &Call) const;
+  void reportTaintBug(StringRef Msg, ProgramStateRef State, CheckerContext &C,
+  llvm::ArrayRef TaintedSyms,
+  AllocationFamily Family, const Expr *SizeEx) const;
+
+  void CheckTaintedness(CheckerContext &C, const CallEvent &Call,
+const SVal SizeSVal, ProgramStateRef State,
+AllocationFamily Family) const;
 
   // TODO: Remove mutable by moving the initializtaion to the registry 
function.
   mutable std::optional KernelZeroFlagVal;
@@ -521,9 +530,9 @@ class MallocChecker
   /// malloc leaves it undefined.
   /// \param [in] State The \c ProgramState right before allocation.
   /// \returns The ProgramState right after allocation.
-  [[nodiscard]] static ProgramStateRef
+  [[nodiscard]] ProgramStateRef
   MallocMemAux(CheckerContext &C, const CallEvent &Call, const Expr *SizeEx,
-   SVal Init, ProgramStateRef State, AllocationFamily Family);
+   SVal Init, ProgramStateRef State, AllocationFamily Family) 
const;
 
   /// Models memory allocation.
   ///
@@ -534,9 +543,10 @@ class MallocChecker
   /// malloc leaves it undefined.
   /// \param [in] State The \c ProgramState right before allocation.
   /// \returns The ProgramState right after allocation.
-  [[nodiscard]] static ProgramStateRef
-  MallocMemAux(CheckerContext &C, const CallEvent &Call, SVal Size, SVal Init,
-   ProgramStateRef State, AllocationFamily Family);
+  [[nodiscard]] ProgramStateRef MallocMemAux(CheckerContext &C,
+ const CallEvent &Call, SVal Size,
+ SVal Init, ProgramStateRef State,
+ AllocationFamily Family) const;
 
   // Check if this malloc() for special flags. At present that means M_ZERO or
   // __GFP_ZERO (in which case, treat it like calloc).
@@ -649,8 +659,9 @@ class MallocChecker
   /// \param [in] Call The expression that reallocated memory
   /// \param [in] State The \c ProgramState right before reallocation.
   /// \returns The ProgramState right after allocation.
-  [[nodiscard]] static ProgramStateRef
-  CallocMem(CheckerContext &C, const CallEvent &Call, ProgramStateRef State);
+  [[nodiscard]] ProgramStateRef CallocMem(CheckerContext &C,
+  const CallEvent &Call,
+  ProgramStateRef State) const;
 
   /// See if deallocation happens in a suspicious context. If so, escape the
   /// pointers that otherwise would have been deallocated and return true.
@@ -1779,7 +1790,7 @@ ProgramStateRef 
MallocChecker::MallocMemAux(CheckerContext &C,
 const CallEvent &Call,
 const Expr *SizeEx, SVal Init,
 ProgramStateRef State,
-AllocationFamily Family) {
+AllocationFamily Family) const {
   if (!State)
 return nullptr;
 
@@ -1787,10 +1798,71 @@ ProgramStateRef 
MallocChecker:

[clang] [llvm] [coro] Lower `llvm.coro.await.suspend.handle` to resume with tail call (PR #89751)

2024-05-23 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

It is pretty interesting that I can pass the test by:

```
$git diff -U10
diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp 
b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
index 450ea8234371..003bfbf7138a 100644
--- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
@@ -220,20 +220,21 @@ static void lowerAwaitSuspend(IRBuilder<> &Builder, 
CoroAwaitSuspendInst *CB,
 }

 coro::LowererBase LB(*Wrapper->getParent());
 auto *ResumeAddr = LB.makeSubFnCall(NewCall, CoroSubFnInst::ResumeIndex,
 &*Builder.GetInsertPoint());

 LLVMContext &Ctx = Builder.getContext();
 FunctionType *ResumeTy = FunctionType::get(
 Type::getVoidTy(Ctx), PointerType::getUnqual(Ctx), false);
 auto *ResumeCall = Builder.CreateCall(ResumeTy, ResumeAddr, {NewCall});
+ResumeCall->setCallingConv(CallingConv::Fast);

 // We can't insert the 'ret' instruction and adjust the cc until the
 // function has been split, so remember this for later.
 Shape.SymmetricTransfers.push_back(ResumeCall);

 NewCall = ResumeCall;
   }

   CB->replaceAllUsesWith(NewCall);
   CB->eraseFromParent();
```

The breaking only happens with optimizations in a workload.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-23 Thread James Henderson via cfe-commits

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-23 Thread James Henderson via cfe-commits


@@ -321,6 +321,11 @@ class ELFFile {
 
   std::vector decode_relrs(Elf_Relr_Range relrs) const;
 
+  uint64_t crelHeader(ArrayRef Content) const;

jh7370 wrote:

It's not clear without looking at the method definition what the return value 
actually represents. Indeed, this method name doesn't seem to conform to the 
LLVM naming guidelines, since it's neither a verb or adjective phrase or 
similar. Perhaps renaming the method would be wise (and also possibly a comment 
to explain it, if needed still after the renaming).

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-23 Thread James Henderson via cfe-commits

https://github.com/jh7370 commented:

I've made a start on this, but have run out of time. Will come back to 
reviewing it another day.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-23 Thread James Henderson via cfe-commits


@@ -934,10 +943,51 @@ void ELFWriter::WriteSecHdrEntry(uint32_t Name, uint32_t 
Type, uint64_t Flags,
   WriteWord(EntrySize); // sh_entsize
 }
 
+template 
+static void encodeCrel(ArrayRef Relocs, raw_ostream &os) {
+  uint OffsetMask = 8, Offset = 0, Addend = 0;
+  uint32_t Symidx = 0, Type = 0;
+  // hdr & 4 indicates 3 flag bits in delta offset and flags members.
+  for (size_t i = 0, e = Relocs.size(); i != e; ++i)

jh7370 wrote:

Nit: `i` and `e` -> `I` and `E`.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-23 Thread James Henderson via cfe-commits


@@ -474,9 +480,28 @@ struct Elf_Rel_Impl, true>
 : public Elf_Rel_Impl, false> {
   LLVM_ELF_IMPORT_TYPES(Endianness, true)
   static const bool IsRela = true;
+  static const bool IsCrel = false;
   Elf_Sxword r_addend; // Compute value for relocatable field by adding this.
 };
 
+template  struct Elf_Crel_Impl {
+  using uint = std::conditional_t;
+  static const bool IsRela = true;
+  static const bool IsCrel = true;
+  uint r_offset;
+  uint32_t r_symidx;
+  uint32_t r_type;
+  std::conditional_t r_addend;

jh7370 wrote:

Again, if I'm not mistaken, using the ELFType would avoid the need for the 
`std::conditional` here: you could use the Elf_Addend type, I believe.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-23 Thread James Henderson via cfe-commits


@@ -61,6 +61,9 @@ class MCTargetOptions {
 
   bool Dwarf64 : 1;
 
+  // Use CREL relocation format for ELF.
+  bool Crel = false;

jh7370 wrote:

Nit here and elsewhere: Is "Crel" a correct way of spelling this? Should it be 
"CRel" (for "CompressedRelocations")? I'm assuming you're deliberately avoiding 
using CREL in this context, but an argument could be made for that too.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-23 Thread James Henderson via cfe-commits


@@ -392,6 +393,70 @@ ELFFile::decode_relrs(Elf_Relr_Range relrs) const {
   return Relocs;
 }
 
+template 
+uint64_t ELFFile::crelHeader(ArrayRef Content) const {
+  DataExtractor Data(Content, true, 8); // endian/class is irrelevant
+  DataExtractor::Cursor Cur(0);
+  uint64_t Hdr = Data.getULEB128(Cur);
+  // In case of an error, return 0 and postpone error reporting to decodeCrel.
+  consumeError(Cur.takeError());

jh7370 wrote:

Throwing away the error like this means you lose the context about what went 
wrong when decoding. That doesn't seem great to me.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-23 Thread James Henderson via cfe-commits


@@ -392,6 +393,70 @@ ELFFile::decode_relrs(Elf_Relr_Range relrs) const {
   return Relocs;
 }
 
+template 
+uint64_t ELFFile::crelHeader(ArrayRef Content) const {
+  DataExtractor Data(Content, true, 8); // endian/class is irrelevant
+  DataExtractor::Cursor Cur(0);
+  uint64_t Hdr = Data.getULEB128(Cur);
+  // In case of an error, return 0 and postpone error reporting to decodeCrel.
+  consumeError(Cur.takeError());
+  return Hdr;
+}
+
+template 
+Expected::RelsOrRelas>
+ELFFile::decodeCrel(ArrayRef Content) const {
+  DataExtractor Data(Content, true, 8); // endian/class is irrelevant
+  DataExtractor::Cursor Cur(0);
+  const uint64_t Hdr = Data.getULEB128(Cur);
+  const size_t Count = Hdr / 8, FlagBits = Hdr & ELF::CREL_HDR_ADDEND ? 3 : 2,
+   Shift = Hdr % ELF::CREL_HDR_ADDEND;

jh7370 wrote:

This line is unnecessarily complicated. It would be much clearer to just define 
each variable on a separate line.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-23 Thread James Henderson via cfe-commits


@@ -474,9 +480,28 @@ struct Elf_Rel_Impl, true>
 : public Elf_Rel_Impl, false> {
   LLVM_ELF_IMPORT_TYPES(Endianness, true)
   static const bool IsRela = true;
+  static const bool IsCrel = false;
   Elf_Sxword r_addend; // Compute value for relocatable field by adding this.
 };
 
+template  struct Elf_Crel_Impl {
+  using uint = std::conditional_t;

jh7370 wrote:

If we passed the ELFType down the stack rather than just the Is64 boolean, we 
wouldn't need this extra `using`, since there already exists a `uint` defined 
in the ELFType class.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-23 Thread James Henderson via cfe-commits


@@ -392,6 +393,70 @@ ELFFile::decode_relrs(Elf_Relr_Range relrs) const {
   return Relocs;
 }
 
+template 
+uint64_t ELFFile::crelHeader(ArrayRef Content) const {
+  DataExtractor Data(Content, true, 8); // endian/class is irrelevant

jh7370 wrote:

Endian/class may be irrelevant, but since you have access to the ELFT here 
anyway, would it not make sense to just use the corresponding values? Same 
elsewhere.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-23 Thread James Henderson via cfe-commits


@@ -86,6 +86,8 @@ DYNAMIC_TAG(RELRSZ, 35)  // Size of Relr relocation table.
 DYNAMIC_TAG(RELR, 36)// Address of relocation table (Relr entries).
 DYNAMIC_TAG(RELRENT, 37) // Size of a Relr relocation entry.
 
+DYNAMIC_TAG(CREL,  38)   // CREL relocation table
+

jh7370 wrote:

I think we need to avoid generic numbers for dynamic tags/section types etc, 
except possibly generic numbers that are a long way from the "normal" range. 
The reason for this is we don't know what values are going to get standardised, 
assuming this feature even gets accepted into the standard. If, for example, 
another feature gets accepted into the standard before CREL, it might use up 
the slot you've "allocated" for the DT_CREL here, which could cause problems 
with loaders that have supported the experimental CREL implementation. On the 
other hand, a different special number (whether in a dedicated range or 
otherwise) that isn't adjacent to the list will not have the issue of a 
potential clash.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-23 Thread James Henderson via cfe-commits


@@ -259,7 +260,7 @@ class ELFObjectWriter : public MCObjectWriter {
   void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
 const MCFragment *Fragment, const MCFixup &Fixup,
 MCValue Target, uint64_t &FixedValue) override;
-  bool usesRela(const MCSectionELF &Sec) const;
+  bool usesRela(const MCTargetOptions *, const MCSectionELF &Sec) const;

jh7370 wrote:

Should the options parameter be named here?

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


[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-23 Thread Daniel Krupp via cfe-commits

dkrupp wrote:

Thanks for the reviews. I updated the patch.

@haoNoQ 
- I changed the report to non-fatal
- I factored out the warning into a new checker optin.taint.TaintMalloc. This 
way the checker can be enabled separately. Of course, the 
alpha.security.taint.TaintPropagation checker is a prerequisite as indicated in 
the checker doc.

@steakhal 
- New test is added to the taint-diagnostic-visitor.c to test the taint related 
notes diagnostics.

-Minor changes addressed as requested.

Could you please check again?


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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-23 Thread James Henderson via cfe-commits


@@ -934,10 +943,51 @@ void ELFWriter::WriteSecHdrEntry(uint32_t Name, uint32_t 
Type, uint64_t Flags,
   WriteWord(EntrySize); // sh_entsize
 }
 
+template 
+static void encodeCrel(ArrayRef Relocs, raw_ostream &os) {

jh7370 wrote:

Nit: `os` -> `OS`

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


[clang] [llvm] IR: Add module level attribution language-standard (PR #93159)

2024-05-23 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa created 
https://github.com/llvm/llvm-project/pull/93159

The backend may have interest on the language-standard level of source file. 
Let's pass it to IR.

In a ll file, it looks like
   language-standard = "gnu17"

>From 3e413bae6ba18276e4d47075d48d656e4f732b5e Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Thu, 23 May 2024 17:33:34 +0800
Subject: [PATCH] IR: Add module level attribution language-standard

The backend may have interest on the language-standard level
of source file. Let's pass it to IR.

In a ll file, it looks like
   language-standard = "gnu17"
---
 clang/lib/CodeGen/ModuleBuilder.cpp   |  3 +++
 llvm/include/llvm/Bitcode/LLVMBitCodes.h  |  3 +++
 llvm/include/llvm/IR/Module.h |  7 +++
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 22 +-
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 23 +++
 llvm/lib/IR/AsmWriter.cpp |  6 ++
 llvm/lib/IR/Module.cpp|  4 ++--
 7 files changed, 65 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/ModuleBuilder.cpp 
b/clang/lib/CodeGen/ModuleBuilder.cpp
index df85295cfb2e2..cf07b09b93fd7 100644
--- a/clang/lib/CodeGen/ModuleBuilder.cpp
+++ b/clang/lib/CodeGen/ModuleBuilder.cpp
@@ -153,6 +153,9 @@ namespace {
 
   M->setTargetTriple(Ctx->getTargetInfo().getTriple().getTriple());
   M->setDataLayout(Ctx->getTargetInfo().getDataLayoutString());
+  M->setLanguageStandard(
+  LangStandard::getLangStandardForKind(Ctx->getLangOpts().LangStd)
+  .getName());
   const auto &SDKVersion = Ctx->getTargetInfo().getSDKVersion();
   if (!SDKVersion.empty())
 M->setSDKVersion(SDKVersion);
diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h 
b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index 909eb833c601a..cba77c322fdb4 100644
--- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -120,6 +120,9 @@ enum ModuleCodes {
 
   // IFUNC: [ifunc value type, addrspace, resolver val#, linkage, visibility]
   MODULE_CODE_IFUNC = 18,
+
+  // LANGUAGE_STANDARD: [strchr x N]
+  MODULE_CODE_LANGUAGE_STANDARD = 19,
 };
 
 /// PARAMATTR blocks have code for defining a parameter attribute set.
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 6135e15fd030f..300dc5c5630dc 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -196,6 +196,7 @@ class LLVM_EXTERNAL_VISIBILITY Module {
   ///< recorded in bitcode.
   std::string TargetTriple;   ///< Platform target triple Module compiled 
on
   ///< Format: (arch)(sub)-(vendor)-(sys0-(abi)
+  std::string LanguageStandard;   ///< Language standard: c89/c99/c11/c23 etc.
   NamedMDSymTabType NamedMDSymTab;  ///< NamedMDNode names.
   DataLayout DL;  ///< DataLayout associated with the module
   StringMap
@@ -277,6 +278,9 @@ class LLVM_EXTERNAL_VISIBILITY Module {
   /// contain the source file name.
   const std::string &getSourceFileName() const { return SourceFileName; }
 
+  /// Get the module's language standard.
+  const std::string &getLanguageStandard() const { return LanguageStandard; }
+
   /// Get a short "name" for the module.
   ///
   /// This is useful for debugging or logging. It is essentially a convenience
@@ -339,6 +343,9 @@ class LLVM_EXTERNAL_VISIBILITY Module {
   /// Set the target triple.
   void setTargetTriple(StringRef T) { TargetTriple = std::string(T); }
 
+  /// Set the language standard.
+  void setLanguageStandard(StringRef S) { LanguageStandard = std::string(S); }
+
   /// Set the module-scope inline assembly blocks.
   /// A trailing newline is added if the input doesn't have one.
   void setModuleInlineAsm(StringRef Asm) {
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp 
b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index c9295344f8080..8078291477886 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -946,6 +946,9 @@ class ModuleSummaryIndexBitcodeReader : public 
BitcodeReaderBase {
   /// Original source file name recorded in a bitcode record.
   std::string SourceFileName;
 
+  /// Original language standard recorded in a bitcode record.
+  std::string LanguageStandard;
+
   /// The string identifier given to this module by the client, normally the
   /// path to the bitcode file.
   StringRef ModulePath;
@@ -4613,13 +4616,22 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit,
   VSTOffset = Record[0] - 1;
   break;
 /// MODULE_CODE_SOURCE_FILENAME: [namechar x N]
-case bitc::MODULE_CODE_SOURCE_FILENAME:
+case bitc::MODULE_CODE_SOURCE_FILENAME: {
   SmallString<128> ValueName;
   if (convertToString(Record, 0, ValueName))
 return error("Invalid record");
   TheModule->setSourceFileName(ValueName);
   break;
 }
+/// MODULE_CODE_LANGUAGE

[clang] [llvm] IR: Add module level attribution language-standard (PR #93159)

2024-05-23 Thread YunQiang Su via cfe-commits

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


[clang] [llvm] IR: Add module level attribution language-standard (PR #93159)

2024-05-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-ir

Author: YunQiang Su (wzssyqa)


Changes

The backend may have interest on the language-standard level of source file. 
Let's pass it to IR.

In a ll file, it looks like
   language-standard = "gnu17"

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


7 Files Affected:

- (modified) clang/lib/CodeGen/ModuleBuilder.cpp (+3) 
- (modified) llvm/include/llvm/Bitcode/LLVMBitCodes.h (+3) 
- (modified) llvm/include/llvm/IR/Module.h (+7) 
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+21-1) 
- (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+23) 
- (modified) llvm/lib/IR/AsmWriter.cpp (+6) 
- (modified) llvm/lib/IR/Module.cpp (+2-2) 


``diff
diff --git a/clang/lib/CodeGen/ModuleBuilder.cpp 
b/clang/lib/CodeGen/ModuleBuilder.cpp
index df85295cfb2e2..cf07b09b93fd7 100644
--- a/clang/lib/CodeGen/ModuleBuilder.cpp
+++ b/clang/lib/CodeGen/ModuleBuilder.cpp
@@ -153,6 +153,9 @@ namespace {
 
   M->setTargetTriple(Ctx->getTargetInfo().getTriple().getTriple());
   M->setDataLayout(Ctx->getTargetInfo().getDataLayoutString());
+  M->setLanguageStandard(
+  LangStandard::getLangStandardForKind(Ctx->getLangOpts().LangStd)
+  .getName());
   const auto &SDKVersion = Ctx->getTargetInfo().getSDKVersion();
   if (!SDKVersion.empty())
 M->setSDKVersion(SDKVersion);
diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h 
b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index 909eb833c601a..cba77c322fdb4 100644
--- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -120,6 +120,9 @@ enum ModuleCodes {
 
   // IFUNC: [ifunc value type, addrspace, resolver val#, linkage, visibility]
   MODULE_CODE_IFUNC = 18,
+
+  // LANGUAGE_STANDARD: [strchr x N]
+  MODULE_CODE_LANGUAGE_STANDARD = 19,
 };
 
 /// PARAMATTR blocks have code for defining a parameter attribute set.
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 6135e15fd030f..300dc5c5630dc 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -196,6 +196,7 @@ class LLVM_EXTERNAL_VISIBILITY Module {
   ///< recorded in bitcode.
   std::string TargetTriple;   ///< Platform target triple Module compiled 
on
   ///< Format: (arch)(sub)-(vendor)-(sys0-(abi)
+  std::string LanguageStandard;   ///< Language standard: c89/c99/c11/c23 etc.
   NamedMDSymTabType NamedMDSymTab;  ///< NamedMDNode names.
   DataLayout DL;  ///< DataLayout associated with the module
   StringMap
@@ -277,6 +278,9 @@ class LLVM_EXTERNAL_VISIBILITY Module {
   /// contain the source file name.
   const std::string &getSourceFileName() const { return SourceFileName; }
 
+  /// Get the module's language standard.
+  const std::string &getLanguageStandard() const { return LanguageStandard; }
+
   /// Get a short "name" for the module.
   ///
   /// This is useful for debugging or logging. It is essentially a convenience
@@ -339,6 +343,9 @@ class LLVM_EXTERNAL_VISIBILITY Module {
   /// Set the target triple.
   void setTargetTriple(StringRef T) { TargetTriple = std::string(T); }
 
+  /// Set the language standard.
+  void setLanguageStandard(StringRef S) { LanguageStandard = std::string(S); }
+
   /// Set the module-scope inline assembly blocks.
   /// A trailing newline is added if the input doesn't have one.
   void setModuleInlineAsm(StringRef Asm) {
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp 
b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index c9295344f8080..8078291477886 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -946,6 +946,9 @@ class ModuleSummaryIndexBitcodeReader : public 
BitcodeReaderBase {
   /// Original source file name recorded in a bitcode record.
   std::string SourceFileName;
 
+  /// Original language standard recorded in a bitcode record.
+  std::string LanguageStandard;
+
   /// The string identifier given to this module by the client, normally the
   /// path to the bitcode file.
   StringRef ModulePath;
@@ -4613,13 +4616,22 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit,
   VSTOffset = Record[0] - 1;
   break;
 /// MODULE_CODE_SOURCE_FILENAME: [namechar x N]
-case bitc::MODULE_CODE_SOURCE_FILENAME:
+case bitc::MODULE_CODE_SOURCE_FILENAME: {
   SmallString<128> ValueName;
   if (convertToString(Record, 0, ValueName))
 return error("Invalid record");
   TheModule->setSourceFileName(ValueName);
   break;
 }
+/// MODULE_CODE_LANGUAGE_STANDARD: [strchar x N]
+case bitc::MODULE_CODE_LANGUAGE_STANDARD: {
+  SmallString<128> ValueLangStd;
+  if (convertToString(Record, 0, ValueLangStd))
+return error("Invalid record");
+  TheModule->setLanguageStandard(ValueLangStd);
+  break;
+}
+}
 Record.clear();
   }
   this->ValueTypeCa

[clang] [llvm] IR: Add module level attribution language-standard (PR #93159)

2024-05-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: YunQiang Su (wzssyqa)


Changes

The backend may have interest on the language-standard level of source file. 
Let's pass it to IR.

In a ll file, it looks like
   language-standard = "gnu17"

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


7 Files Affected:

- (modified) clang/lib/CodeGen/ModuleBuilder.cpp (+3) 
- (modified) llvm/include/llvm/Bitcode/LLVMBitCodes.h (+3) 
- (modified) llvm/include/llvm/IR/Module.h (+7) 
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+21-1) 
- (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+23) 
- (modified) llvm/lib/IR/AsmWriter.cpp (+6) 
- (modified) llvm/lib/IR/Module.cpp (+2-2) 


``diff
diff --git a/clang/lib/CodeGen/ModuleBuilder.cpp 
b/clang/lib/CodeGen/ModuleBuilder.cpp
index df85295cfb2e2..cf07b09b93fd7 100644
--- a/clang/lib/CodeGen/ModuleBuilder.cpp
+++ b/clang/lib/CodeGen/ModuleBuilder.cpp
@@ -153,6 +153,9 @@ namespace {
 
   M->setTargetTriple(Ctx->getTargetInfo().getTriple().getTriple());
   M->setDataLayout(Ctx->getTargetInfo().getDataLayoutString());
+  M->setLanguageStandard(
+  LangStandard::getLangStandardForKind(Ctx->getLangOpts().LangStd)
+  .getName());
   const auto &SDKVersion = Ctx->getTargetInfo().getSDKVersion();
   if (!SDKVersion.empty())
 M->setSDKVersion(SDKVersion);
diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h 
b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index 909eb833c601a..cba77c322fdb4 100644
--- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -120,6 +120,9 @@ enum ModuleCodes {
 
   // IFUNC: [ifunc value type, addrspace, resolver val#, linkage, visibility]
   MODULE_CODE_IFUNC = 18,
+
+  // LANGUAGE_STANDARD: [strchr x N]
+  MODULE_CODE_LANGUAGE_STANDARD = 19,
 };
 
 /// PARAMATTR blocks have code for defining a parameter attribute set.
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 6135e15fd030f..300dc5c5630dc 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -196,6 +196,7 @@ class LLVM_EXTERNAL_VISIBILITY Module {
   ///< recorded in bitcode.
   std::string TargetTriple;   ///< Platform target triple Module compiled 
on
   ///< Format: (arch)(sub)-(vendor)-(sys0-(abi)
+  std::string LanguageStandard;   ///< Language standard: c89/c99/c11/c23 etc.
   NamedMDSymTabType NamedMDSymTab;  ///< NamedMDNode names.
   DataLayout DL;  ///< DataLayout associated with the module
   StringMap
@@ -277,6 +278,9 @@ class LLVM_EXTERNAL_VISIBILITY Module {
   /// contain the source file name.
   const std::string &getSourceFileName() const { return SourceFileName; }
 
+  /// Get the module's language standard.
+  const std::string &getLanguageStandard() const { return LanguageStandard; }
+
   /// Get a short "name" for the module.
   ///
   /// This is useful for debugging or logging. It is essentially a convenience
@@ -339,6 +343,9 @@ class LLVM_EXTERNAL_VISIBILITY Module {
   /// Set the target triple.
   void setTargetTriple(StringRef T) { TargetTriple = std::string(T); }
 
+  /// Set the language standard.
+  void setLanguageStandard(StringRef S) { LanguageStandard = std::string(S); }
+
   /// Set the module-scope inline assembly blocks.
   /// A trailing newline is added if the input doesn't have one.
   void setModuleInlineAsm(StringRef Asm) {
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp 
b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index c9295344f8080..8078291477886 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -946,6 +946,9 @@ class ModuleSummaryIndexBitcodeReader : public 
BitcodeReaderBase {
   /// Original source file name recorded in a bitcode record.
   std::string SourceFileName;
 
+  /// Original language standard recorded in a bitcode record.
+  std::string LanguageStandard;
+
   /// The string identifier given to this module by the client, normally the
   /// path to the bitcode file.
   StringRef ModulePath;
@@ -4613,13 +4616,22 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit,
   VSTOffset = Record[0] - 1;
   break;
 /// MODULE_CODE_SOURCE_FILENAME: [namechar x N]
-case bitc::MODULE_CODE_SOURCE_FILENAME:
+case bitc::MODULE_CODE_SOURCE_FILENAME: {
   SmallString<128> ValueName;
   if (convertToString(Record, 0, ValueName))
 return error("Invalid record");
   TheModule->setSourceFileName(ValueName);
   break;
 }
+/// MODULE_CODE_LANGUAGE_STANDARD: [strchar x N]
+case bitc::MODULE_CODE_LANGUAGE_STANDARD: {
+  SmallString<128> ValueLangStd;
+  if (convertToString(Record, 0, ValueLangStd))
+return error("Invalid record");
+  TheModule->setLanguageStandard(ValueLangStd);
+  break;
+}
+}
 Record.clear();
   }
   this->Value

[clang] [Clang][AArch64] Use __clang_arm_builtin_alias for overloaded svreinterpret's (PR #92427)

2024-05-23 Thread Sander de Smalen via cfe-commits

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


[clang] f81da75 - [Clang][AArch64] Use __clang_arm_builtin_alias for overloaded svreinterpret's (#92427)

2024-05-23 Thread via cfe-commits

Author: Sander de Smalen
Date: 2024-05-23T10:42:11+01:00
New Revision: f81da75693fff6c2ffefbb3883e08f11b21ee643

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

LOG: [Clang][AArch64] Use __clang_arm_builtin_alias for overloaded 
svreinterpret's (#92427)

The intrinsics are currently defined as:

```
  __aio __attribute__((target("sve")))
  svint8_t svreinterpret_s8(svuint8_t op) __arm_streaming_compatible {
return __builtin_sve_reinterpret_s8_u8(op);
  }
```

which doesn't work when calling it from an __arm_streaming function when
only +sme is available. By defining it in the same way as we've defined
all the other intrinsics, we can leave it to the code in SemaChecking to
verify that either +sve or +sme is available.

This PR also fixes the target guards for the svreinterpret_c and
svreinterpret_b intrinsics, that convert between svcount_t and svbool_t,
as these are available both in SME2 and SVE2p1.

Added: 


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

clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_reinterpret_svcount_svbool.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_reinterpret-bfloat.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_reinterpret.c
clang/utils/TableGen/SveEmitter.cpp

Removed: 

clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_reinterpret_from_streaming_mode.c



diff  --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index a9ea71cd07774..03570f94de666 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2186,9 +2186,6 @@ let TargetGuard = "sme2" in {
 
   def SVSQRSHRUN_X4 : SInst<"svqrshrun[_n]_{0}[_{d}_x4]", "b4i", "il", 
MergeNone, "aarch64_sve_sqrshrun_x4", [IsStreaming], [ImmCheck<1, 
ImmCheckShiftRight, 0>]>;
 
-  def REINTERPRET_SVBOOL_TO_SVCOUNT : Inst<"svreinterpret[_c]", "}P", "Pc", 
MergeNone, "", [IsStreamingCompatible], []>;
-  def REINTERPRET_SVCOUNT_TO_SVBOOL : Inst<"svreinterpret[_b]", "P}", "Pc", 
MergeNone, "", [IsStreamingCompatible], []>;
-
   // SQDMULH
   def SVSQDMULH_SINGLE_X2 : SInst<"svqdmulh[_single_{d}_x2]", "22d", "csil", 
MergeNone, "aarch64_sve_sqdmulh_single_vgx2", [IsStreaming], []>;
   def SVSQDMULH_SINGLE_X4 : SInst<"svqdmulh[_single_{d}_x4]", "44d", "csil", 
MergeNone, "aarch64_sve_sqdmulh_single_vgx4", [IsStreaming], []>;
@@ -2197,6 +2194,9 @@ let TargetGuard = "sme2" in {
 }
 
 let TargetGuard = "sve2p1|sme2" in {
+  def REINTERPRET_SVBOOL_TO_SVCOUNT : Inst<"svreinterpret[_c]", "}P", "Pc", 
MergeNone, "", [IsStreamingCompatible], []>;
+  def REINTERPRET_SVCOUNT_TO_SVBOOL : Inst<"svreinterpret[_b]", "P}", "Pc", 
MergeNone, "", [IsStreamingCompatible], []>;
+
   // SQRSHRN / UQRSHRN
   def SVQRSHRN_X2   : SInst<"svqrshrn[_n]_{0}[_{d}_x2]", "h2i", "i",
MergeNone, "aarch64_sve_sqrshrn_x2", [IsStreamingCompatible], [ImmCheck<1, 
ImmCheck1_16>]>;
   def SVUQRSHRN_X2  : SInst<"svqrshrn[_n]_{0}[_{d}_x2]", "e2i", "Ui",   
MergeNone, "aarch64_sve_uqrshrn_x2", [IsStreamingCompatible], [ImmCheck<1, 
ImmCheck1_16>]>;

diff  --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_reinterpret_svcount_svbool.c
 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_reinterpret_svcount_svbool.c
index c442d2c0c4750..d894e98451b41 100644
--- 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_reinterpret_svcount_svbool.c
+++ 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_reinterpret_svcount_svbool.c
@@ -2,12 +2,14 @@
 
 // REQUIRES: aarch64-registered-target
 
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sve2p1 -disable-O0-optnone 
-Werror -Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sve2p1 -disable-O0-optnone 
-Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
 // RUN: %clang_cc1 -triple aarch64 -target-feature +sme2 -disable-O0-optnone 
-Werror -Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s
 // RUN: %clang_cc1 -triple aarch64 -target-feature +sme2 -disable-O0-optnone 
-Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
 // RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64 -target-feature 
+sme2 -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
 // RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64 -target-feature 
+sme2 -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
 
-#include 
+#include 
 
 #if defined __ARM_FEATURE_SME
 #define MODE_ATT

[clang] [clang] Introduce `SemaX86` (PR #93098)

2024-05-23 Thread Simon Pilgrim via cfe-commits

RKSimon wrote:

@endilll Thanks for working on this - out of interest are you intending to do 
this for CGBuiltin as well? Is the plan to no longer have to include all target 
builtins in all clang builds?

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


[clang] 10dc3a8 - [clang][Interp] Fix empty InitListExprs for unions

2024-05-23 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-05-23T11:48:33+02:00
New Revision: 10dc3a8e916d73291269e5e2b82dd22681489aa1

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

LOG: [clang][Interp] Fix empty InitListExprs for unions

We still need to handle Inits.size() == 0, but we can do that earlier.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/unions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e64d3a94b5091..0c514236d4ca7 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1053,6 +1053,9 @@ bool 
ByteCodeExprGen::visitInitList(ArrayRef Inits,
 if (Inits.size() == 1 && E->getType() == Inits[0]->getType())
   return this->visitInitializer(Inits[0]);
 
+if (Inits.size() == 0)
+  return this->emitFinishInit(E);
+
 auto initPrimitiveField = [=](const Record::Field *FieldToInit,
   const Expr *Init, PrimType T) -> bool {
   if (!this->visit(Init))

diff  --git a/clang/test/AST/Interp/unions.cpp 
b/clang/test/AST/Interp/unions.cpp
index 73e42d57a7b77..b0b1b19617408 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -42,4 +42,10 @@ namespace SimpleStore {
 return a.b;
   }
   static_assert(foo() == 10, "");
+
+  constexpr int empty() {
+A a{}; /// Just test that this works.
+return 10;
+  }
+  static_assert(empty() == 10, "");
 }



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


[clang] [llvm] IR: Add module level attribution language-standard (PR #93159)

2024-05-23 Thread Matt Arsenault via cfe-commits

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

You cannot encode language standards in this. We should simply have different 
operations that provide the range of semantics and not make the IR modal 

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


[clang] 45a95c3 - [clang][Interp] Fix DeclRefExprs of void-typed dummy pointers

2024-05-23 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-05-23T11:56:23+02:00
New Revision: 45a95c3c543c88a669cffd3f7ee2a1b7e02b44e8

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

LOG: [clang][Interp] Fix DeclRefExprs of void-typed dummy pointers

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/c.c

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 0c514236d4ca7..b885cbe2c4b0e 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3795,6 +3795,8 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
   if (std::optional I = P.getOrCreateDummy(D)) {
 if (!this->emitGetPtrGlobal(*I, E))
   return false;
+if (E->getType()->isVoidType())
+  return true;
 // Convert the dummy pointer to another pointer type if we have to.
 if (PrimType PT = classifyPrim(E); PT != PT_Ptr) {
   if (!this->emitDecayPtr(PT_Ptr, PT, E))

diff  --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 2a75457a4693f..d680dbc912ab4 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -278,3 +278,9 @@ void addrlabelexpr(void) {
  a0: ;
   static void *ps[] = { &&a0 }; // pedantic-warning {{use of GNU 
address-of-label extension}}
 }
+
+extern void cv2;
+void *foo5 (void)
+{
+  return &cv2; // pedantic-warning{{address of an expression of type 'void'}}
+}



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


[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-23 Thread Matt Arsenault via cfe-commits


@@ -5456,43 +5444,32 @@ bool 
AMDGPULegalizerInfo::legalizeLaneOp(LegalizerHelper &Helper,
   if ((Size % 32) == 0) {
 SmallVector PartialRes;
 unsigned NumParts = Size / 32;
-auto IsS16Vec = Ty.isVector() && Ty.getElementType() == S16;
+bool IsS16Vec = Ty.isVector() && Ty.getElementType() == S16;

arsenm wrote:

Better to track this as the LLT to use for the pieces, rather than making it 
this conditional thing. This will simplify improved pointer handling in the 
future 

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


[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-23 Thread Matt Arsenault via cfe-commits


@@ -6086,6 +6086,62 @@ static SDValue lowerBALLOTIntrinsic(const 
SITargetLowering &TLI, SDNode *N,
   DAG.getConstant(0, SL, MVT::i32), DAG.getCondCode(ISD::SETNE));
 }
 
+static SDValue lowerLaneOp(const SITargetLowering &TLI, SDNode *N,
+   SelectionDAG &DAG) {
+  EVT VT = N->getValueType(0);
+  unsigned ValSize = VT.getSizeInBits();
+  unsigned IntrinsicID = N->getConstantOperandVal(0);
+  SDValue Src0 = N->getOperand(1);
+  SDLoc SL(N);
+  MVT IntVT = MVT::getIntegerVT(ValSize);
+
+  auto createLaneOp = [&DAG, &SL](SDValue Src0, SDValue Src1, SDValue Src2,
+  MVT VT) -> SDValue {
+return (Src2 ? DAG.getNode(AMDGPUISD::WRITELANE, SL, VT, {Src0, Src1, 
Src2})
+: Src1 ? DAG.getNode(AMDGPUISD::READLANE, SL, VT, {Src0, Src1})
+   : DAG.getNode(AMDGPUISD::READFIRSTLANE, SL, VT, {Src0}));
+  };
+
+  SDValue Src1, Src2;
+  if (IntrinsicID == Intrinsic::amdgcn_readlane ||
+  IntrinsicID == Intrinsic::amdgcn_writelane) {
+Src1 = N->getOperand(2);
+if (IntrinsicID == Intrinsic::amdgcn_writelane)
+  Src2 = N->getOperand(3);
+  }
+
+  if (ValSize == 32) {
+// Already legal
+return SDValue();
+  }
+
+  if (ValSize < 32) {
+SDValue InitBitCast = DAG.getBitcast(IntVT, Src0);
+Src0 = DAG.getAnyExtOrTrunc(InitBitCast, SL, MVT::i32);
+if (Src2.getNode()) {
+  SDValue Src2Cast = DAG.getBitcast(IntVT, Src2);

arsenm wrote:

Yes, bitcast for the f16/bf16 case to get to the int 

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


[clang] [llvm] IR: Add module level attribution language-standard (PR #93159)

2024-05-23 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

Let's close it.

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


[clang] [llvm] IR: Add module level attribution language-standard (PR #93159)

2024-05-23 Thread YunQiang Su via cfe-commits

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


[clang] [llvm] [coro] Lower `llvm.coro.await.suspend.handle` to resume with tail call (PR #89751)

2024-05-23 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

I land it directly given it looks straightforward and trivial in 
https://github.com/llvm/llvm-project/commit/31f1590e4fb324c43dc36199587c453e27b6f6fa

See the commit message if you're interested.

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


[clang] [clang] Introduce `SemaX86` (PR #93098)

2024-05-23 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

@RKSimon Not at the moment. The current goal is to reduce amount of 
declarations in `Sema`, and target-specific functions are easy to move out and, 
importantly, teach where new ones should be placed. No functional changes 
intended.

I don't know much about our CodeGen, so I'm not proposing anything myself. That 
said, if there's an appetite for something of this sort there, and someone 
knowledgeable of CodeGen is willing to guide me and help get stakeholders 
agree, I can do the work.

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


[clang] [clang] Add /Zc:__STDC__ flag to clang-cl (PR #68690)

2024-05-23 Thread via cfe-commits

https://github.com/xbjfk updated https://github.com/llvm/llvm-project/pull/68690

>From 26fdd2ef8b94d78c295afe5c6b811225b56e9f4e Mon Sep 17 00:00:00 2001
From: Reagan Bohan 
Date: Sun, 10 Mar 2024 01:49:37 +
Subject: [PATCH] [clang] Add /Zc:__STDC__ flag to clang-cl

This commit adds the /Zc:__STDC__ argument from MSVC, which defines __STDC__.
This means, alongside stronger feature parity with MSVC,
that things that rely on __STDC__, such as autoconf, can work.
---
 clang/docs/ReleaseNotes.rst   |  4 
 clang/include/clang/Basic/LangOptions.def |  1 +
 clang/include/clang/Driver/Options.td |  7 +++
 clang/lib/Driver/ToolChains/Clang.cpp |  6 +-
 clang/lib/Frontend/InitPreprocessor.cpp   |  3 ++-
 clang/test/Driver/ms-define-stdc.c| 11 +++
 clang/test/Preprocessor/stdc-ms-extension.cpp |  9 +
 7 files changed, 39 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Driver/ms-define-stdc.c
 create mode 100644 clang/test/Preprocessor/stdc-ms-extension.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c4a343b70009..e973d00dfb7b3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -341,6 +341,10 @@ New Compiler Flags
   ``__attribute__((section(...)))``. This enables linker GC to collect unused
   symbols without having to use a per-symbol section.
 
+- ``-fms-define-stdc`` and its clang-cl counterpart ``/Zc:__STDC__``.
+  Matches MSVC behaviour by defining ``__STDC__`` to ``1`` when
+  MSVC compatibility mode is used. It has no effect for C++ code.
+
 Deprecated Compiler Flags
 -
 
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 09eb92d6f10d2..4061451b2150a 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -300,6 +300,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations 
/ deallocations with
 
 LANGOPT(OpenACC   , 1, 0, "OpenACC Enabled")
 
+LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with 
'-fms-compatibility'")
 LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
 LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
 LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are 
unavailable")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 8cbb7f854ee72..9cc9a8f24dc1a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2981,6 +2981,10 @@ def fms_compatibility : Flag<["-"], 
"fms-compatibility">, Group,
   Visibility<[ClangOption, CC1Option, CLOption]>,
   HelpText<"Enable full Microsoft Visual C++ compatibility">,
   MarshallingInfoFlag>;
+def fms_define_stdc : Flag<["-"], "fms-define-stdc">, Group,
+  Visibility<[ClangOption, CC1Option, CLOption]>,
+  HelpText<"Define '__STDC__' to '1' in MSVC Compatibility mode">,
+  MarshallingInfoFlag>;
 def fms_extensions : Flag<["-"], "fms-extensions">, Group,
   Visibility<[ClangOption, CC1Option, CLOption]>,
   HelpText<"Accept some non-standard constructs supported by the Microsoft 
compiler">,
@@ -8312,6 +8316,9 @@ def _SLASH_vd : CLJoined<"vd">, HelpText<"Control 
vtordisp placement">,
   Alias;
 def _SLASH_X : CLFlag<"X">,
   HelpText<"Do not add %INCLUDE% to include search path">, Alias;
+def _SLASH_Zc___STDC__ : CLFlag<"Zc:__STDC__">,
+  HelpText<"Define __STDC__">,
+  Alias;
 def _SLASH_Zc_sizedDealloc : CLFlag<"Zc:sizedDealloc">,
   HelpText<"Enable C++14 sized global deallocation functions">,
   Alias;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 588f0c511cd2e..1ad7f56b55c3d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7027,8 +7027,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   options::OPT_fms_compatibility, options::OPT_fno_ms_compatibility,
   (IsWindowsMSVC && Args.hasFlag(options::OPT_fms_extensions,
  options::OPT_fno_ms_extensions, true)));
-  if (IsMSVCCompat)
+  if (IsMSVCCompat) {
 CmdArgs.push_back("-fms-compatibility");
+if (!types::isCXX(Input.getType()) &&
+Args.hasArg(options::OPT_fms_define_stdc))
+  CmdArgs.push_back("-fms-define-stdc");
+  }
 
   if (Triple.isWindowsMSVCEnvironment() && !D.IsCLMode() &&
   Args.hasArg(options::OPT_fms_runtime_lib_EQ))
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 68760e3e0..e8c8a5175f8f4 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -432,7 +432,8 @@ static void InitializeStandardPredefinedMacros(const 
TargetInfo &TI,
   //  [C++] Whether __STDC__ is predefined and if so, what its value is,
   //  are implementation-defined.
   // (Removed in C++20.)
-  if (!L

[clang] [llvm] [coro] Lower `llvm.coro.await.suspend.handle` to resume with tail call (PR #89751)

2024-05-23 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

Oh, it looks like some bots are not happy. I send the PR at 
https://github.com/llvm/llvm-project/pull/93167

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


[clang] 3c23047 - [clang][analyzer] Move checker 'cert.pos.34c' (in alpha.security) into 'PutenvStackArray' (#92424)

2024-05-23 Thread via cfe-commits

Author: Balázs Kéri
Date: 2024-05-23T12:56:16+02:00
New Revision: 3c23047413957024294872e38c27707c71d05805

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

LOG: [clang][analyzer] Move checker 'cert.pos.34c' (in alpha.security) into 
'PutenvStackArray' (#92424)

The "cert" package looks not useful and the checker has not a meaningful name 
with the old naming scheme.
Additionally tests and documentation is updated.

Added: 
clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp
clang/test/Analysis/putenv-stack-array.c

Modified: 
clang/docs/analyzer/checkers.rst
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt

Removed: 
clang/lib/StaticAnalyzer/Checkers/cert/PutenvWithAutoChecker.cpp
clang/test/Analysis/cert/pos34-c-fp-suppression.cpp
clang/test/Analysis/cert/pos34-c.cpp



diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index b4bd9dac1cbc2..ac9f0b06f63ba 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2833,6 +2833,31 @@ Warn on mmap() calls that are both writable and 
executable.
//   code
  }
 
+.. _alpha-security-putenv-stack-array:
+
+alpha.security.PutenvStackArray (C)
+"""
+Finds calls to the ``putenv`` function which pass a pointer to a 
stack-allocated
+(automatic) array as the argument. Function ``putenv`` does not copy the passed
+string, only a pointer to the data is stored and this data can be read even by
+other threads. Content of a stack-allocated array is likely to be overwritten
+after returning from the parent function.
+
+The problem can be solved by using a static array variable or dynamically
+allocated memory. Even better is to avoid using ``putenv`` (it has other
+problems related to memory leaks) and use ``setenv`` instead.
+
+The check corresponds to CERT rule
+`POS34-C. Do not call putenv() with a pointer to an automatic variable as the 
argument
+`_.
+
+.. code-block:: c
+
+  int f() {
+char env[] = "NAME=value";
+return putenv(env); // putenv function should not be called with 
stack-allocated string
+  }
+
 .. _alpha-security-ReturnPtrRange:
 
 alpha.security.ReturnPtrRange (C)
@@ -2859,55 +2884,6 @@ alpha.security.cert
 
 SEI CERT checkers which tries to find errors based on their `C coding rules 
`_.
 
-.. _alpha-security-cert-pos-checkers:
-
-alpha.security.cert.pos
-^^^
-
-SEI CERT checkers of `POSIX C coding rules 
`_.
-
-.. _alpha-security-cert-pos-34c:
-
-alpha.security.cert.pos.34c
-"""
-Finds calls to the ``putenv`` function which pass a pointer to an automatic 
variable as the argument.
-
-.. code-block:: c
-
-  int func(const char *var) {
-char env[1024];
-int retval = snprintf(env, sizeof(env),"TEST=%s", var);
-if (retval < 0 || (size_t)retval >= sizeof(env)) {
-/* Handle error */
-}
-
-return putenv(env); // putenv function should not be called with auto 
variables
-  }
-
-Limitations:
-
-   - Technically, one can pass automatic variables to ``putenv``,
- but one needs to ensure that the given environment key stays
- alive until it's removed or overwritten.
- Since the analyzer cannot keep track of which envvars get overwritten
- and when, it needs to be slightly more aggressive and warn for such
- cases too, leading in some cases to false-positive reports like this:
-
- .. code-block:: c
-
-void baz() {
-  char env[] = "NAME=value";
-  putenv(env); // false-positive warning: putenv function should not 
be called...
-  // More code...
-  putenv((char *)"NAME=anothervalue");
-  // This putenv call overwrites the previous entry, thus that can no 
longer dangle.
-} // 'env' array becomes dead only here.
-
-alpha.security.cert.env
-^^^
-
-SEI CERT checkers of `Environment C coding rules 
`_.
-
 alpha.security.taint
 
 

diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index d0ba1ce548403..40f443047bd4b 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1035,15 +1035,6 @@ let ParentPackage = ENV in {
 
 } // end "security.cert.env"
 
-let ParentPackage = POSAlpha in {
-
-  def Pute

[clang] [clang][analyzer] Move checker 'cert.pos.34c' (in alpha.security) into 'PutenvStackArray' (PR #92424)

2024-05-23 Thread Balázs Kéri via cfe-commits

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


[clang] 1d0e8b2 - [clang][Interp] Remove a no longer needed dummy check

2024-05-23 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-05-23T13:10:58+02:00
New Revision: 1d0e8b24001d854a848a3810b90244a6bc94cf03

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

LOG: [clang][Interp] Remove a no longer needed dummy check

Since we now have type info for dummy pointers, we don't need this
check anymore and can also have the same output for the test case
in records.cpp.

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 8430a7de24dff..fc496b66445aa 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1371,9 +1371,6 @@ inline bool GetPtrVirtBasePop(InterpState &S, CodePtr 
OpPC,
   const Pointer &Ptr = S.Stk.pop();
   if (!CheckNull(S, OpPC, Ptr, CSK_Base))
 return false;
-  if (Ptr.isDummy()) // FIXME: Once we have type info for dummy pointers, this
- // needs to go.
-return false;
   return VirtBaseHelper(S, OpPC, D, Ptr);
 }
 

diff  --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index 3a5ecd291a568..97ac3e9169555 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -1335,8 +1335,6 @@ namespace UnnamedBitFields {
   static_assert(a.c == 'a', "");
 }
 
-/// FIXME: This still doesn't work in the new interpreter because
-/// we lack type information for dummy pointers.
 namespace VirtualBases {
   /// This used to crash.
   namespace One {
@@ -1346,7 +1344,7 @@ namespace VirtualBases {
 };
 class B : public virtual A {
 public:
-  int getX() { return x; } // ref-note {{declared here}}
+  int getX() { return x; } // both-note {{declared here}}
 };
 
 class DV : virtual public B{};
@@ -1354,7 +1352,7 @@ namespace VirtualBases {
 void foo() {
   DV b;
   int a[b.getX()]; // both-warning {{variable length arrays}} \
-   // ref-note {{non-constexpr function 'getX' cannot be 
used}}
+   // both-note {{non-constexpr function 'getX' cannot be 
used}}
 }
   }
 



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


[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-23 Thread Vikram Hegde via cfe-commits

vikramRH wrote:

> > 1. What's the proper way to legalize f16 and bf16 for SDAG case without 
> > bitcasts ? (I would think  "fp_extend -> LaneOp -> Fptrunc" is wrong)
> 
> Bitcast to i16, anyext to i32, laneop, trunc to i16, bitcast to original type.
> 
> Why wouldn't you use bitcasts?

Just a doubt I had on previous comments, sorry for the noise !

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


[clang] [clang] fix printing of canonical template template parameters (PR #93124)

2024-05-23 Thread via cfe-commits

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

LGTM

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


[clang] 84729c9 - [clang][Interp] Don't diagnose ObjCIvarDecls as invalid reads

2024-05-23 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-05-23T13:47:54+02:00
New Revision: 84729c9df30b29d5f4e903ad71235a6aa0c764d6

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

LOG: [clang][Interp] Don't diagnose ObjCIvarDecls as invalid reads

Added: 
clang/test/AST/Interp/objc.mm

Modified: 
clang/lib/AST/Interp/Interp.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index cac678352e2ce..de5390596d632 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTDiagnostic.h"
 #include "clang/AST/CXXInheritance.h"
+#include "clang/AST/DeclObjC.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "llvm/ADT/APSInt.h"
@@ -101,6 +102,11 @@ static void diagnoseNonConstVariable(InterpState &S, 
CodePtr OpPC,
 return;
   }
 
+  // Rather random, but this is to match the diagnostic output of the current
+  // interpreter.
+  if (isa(VD))
+return;
+
   if (VD->getType()->isIntegralOrEnumerationType()) {
 S.FFDiag(Loc, diag::note_constexpr_ltor_non_const_int, 1) << VD;
 S.Note(VD->getLocation(), diag::note_declared_at);

diff  --git a/clang/test/AST/Interp/objc.mm b/clang/test/AST/Interp/objc.mm
new file mode 100644
index 0..44b74d193b66a
--- /dev/null
+++ b/clang/test/AST/Interp/objc.mm
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter 
-verify=expected,both %s
+// RUN: %clang_cc1 -verify=ref,both %s
+
+@interface A {
+  int a;
+  static_assert(a, ""); // both-error {{static assertion expression is not an 
integral constant expression}}
+}
+@end



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


[clang] fbd643f - [clang][Interp] Don't try to activate root pointers

2024-05-23 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-05-23T14:01:32+02:00
New Revision: fbd643fb22607b933a4e129ae86a7334b62c9b55

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

LOG: [clang][Interp] Don't try to activate root pointers

No inline descriptor means we can't do that.

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/cxx98.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index fc496b66445aa..bcb6fb4d65218 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1335,17 +1335,19 @@ inline bool GetPtrThisBase(InterpState &S, CodePtr 
OpPC, uint32_t Off) {
 
 inline bool FinishInitPop(InterpState &S, CodePtr OpPC) {
   const Pointer &Ptr = S.Stk.pop();
-  if (Ptr.canBeInitialized())
+  if (Ptr.canBeInitialized()) {
 Ptr.initialize();
-  Ptr.activate();
+Ptr.activate();
+  }
   return true;
 }
 
 inline bool FinishInit(InterpState &S, CodePtr OpPC) {
   const Pointer &Ptr = S.Stk.peek();
-  if (Ptr.canBeInitialized())
+  if (Ptr.canBeInitialized()) {
 Ptr.initialize();
-  Ptr.activate();
+Ptr.activate();
+  }
   return true;
 }
 

diff  --git a/clang/test/AST/Interp/cxx98.cpp b/clang/test/AST/Interp/cxx98.cpp
index be81735329db8..e68e4dbc8d74b 100644
--- a/clang/test/AST/Interp/cxx98.cpp
+++ b/clang/test/AST/Interp/cxx98.cpp
@@ -50,3 +50,7 @@ _Static_assert(c0_test == 0, "");
 int a = 0; // both-note {{declared here}}
 _Static_assert(a == 0, ""); // both-error {{static assertion expression is not 
an integral constant expression}} \
 // both-note {{read of non-const variable 'a' is 
not allowed in a constant expression}}
+
+struct SelfReference { SelfReference &r; };
+extern SelfReference self_reference_1;
+SelfReference self_reference_2 = {self_reference_1};



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


[clang] [clang][dataflow] Fix handling of cyclical data structures in HTMLLogger. (PR #66887)

2024-05-23 Thread via cfe-commits


@@ -88,10 +88,12 @@ class ModelDumper {
 
   void dump(Value &V) {
 JOS.attribute("value_id", llvm::to_string(&V));
-if (!Visited.insert(&V).second)
-  return;
-
 JOS.attribute("kind", debugString(V.getKind()));
+if (!Visited.insert(&V).second) {
+  JOS.attribute("[in_cycle]", " ");
+  return;
+}
+auto EraseVisited = llvm::make_scope_exit([&] { Visited.erase(&V); });

martinboehme wrote:

Sorry, this review has gone very stale because I had other things that grabbed 
my attention at the time and then forgot to get back to this PR.

Responding only to this comment first as it's about what we want the behavior 
to be (rather than the details of how we implement it).

> But I'm not sure the distinction is worth the code: the idea "we've seen this 
> node before, and won't print its details again" applies whether the reason is 
> a cycle or just multiple paths to a node, and they both benefit from some 
> explicit hint.

Well, part of the motivation of this PR is that I _do_ also want to change this 
existing behavior. Here's how repeated values are displayed today:

![repeated_value_before](https://github.com/llvm/llvm-project/assets/29098113/b8af43ac-1a14-4b6f-aa2a-c9e88834d5c6)

I see this very case pretty regularly; it was very confusing the first time 
(the "undefined" made me think I had a bug), and I still do a double-take when 
I see it now.

Even if this was displayed better (e.g. as an `AtomicBool` value with a 
"previously dumped" annotation), that still requires me to go looking for the 
previous value. In this case, that's easy, because the value is directly above, 
but I still need to compare the hex address to be sure.

Why do this work if I can have the computer do it for me?

![repeated_value_after](https://github.com/llvm/llvm-project/assets/29098113/1fd5f753-2a2e-4442-b6e0-f3f40d4a5b5e)

I assume your concern is that we could have data structures with lots and lots 
of repeated values, and this would bloat the JSON? Do we actually know that 
this is a problem though?

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


[clang] [clang] Introduce target-specific `Sema` components (PR #93179)

2024-05-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Vlad Serebrennikov (Endilll)


Changes

This patch introduces `SemaAMDGPU`, `SemaARM`, `SemaBPF`, `SemaHexagon`, 
`SemaLoongArch`, `SemaMIPS`, `SemaNVPTX`, `SemaPPC`, `SemaSystemZ`, `SemaWasm`. 
This continues previous efforts to split Sema up. Additional context can be 
found in #84184 and #92682.

I decided to bundle target-specific components together because of their low 
impact on `Sema`. That said, their impact on `SemaChecking.cpp` is far from 
low, and I consider it a success.

Somewhat accidentally, I also moved Wasm- and AMDGPU-specific function from 
`SemaDeclAttr.cpp`, because they were exposed in `Sema`. That went well, and I 
consider it a success, too. I'd like to move the rest of static target-specific 
functions out of `SemaDeclAttr.cpp` like we're doing with built-ins in 
`SemaChecking.cpp` .

---

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


30 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (+123-95) 
- (added) clang/include/clang/Sema/SemaAMDGPU.h (+68) 
- (added) clang/include/clang/Sema/SemaARM.h (+63) 
- (added) clang/include/clang/Sema/SemaBPF.h (+28) 
- (added) clang/include/clang/Sema/SemaHexagon.h (+29) 
- (added) clang/include/clang/Sema/SemaLoongArch.h (+30) 
- (added) clang/include/clang/Sema/SemaMIPS.h (+33) 
- (added) clang/include/clang/Sema/SemaNVPTX.h (+30) 
- (added) clang/include/clang/Sema/SemaPPC.h (+58) 
- (added) clang/include/clang/Sema/SemaSystemZ.h (+28) 
- (added) clang/include/clang/Sema/SemaWasm.h (+52) 
- (modified) clang/lib/Parse/ParseOpenMP.cpp (+3-2) 
- (modified) clang/lib/Sema/CMakeLists.txt (+10) 
- (modified) clang/lib/Sema/Sema.cpp (+20) 
- (added) clang/lib/Sema/SemaAMDGPU.cpp (+289) 
- (added) clang/lib/Sema/SemaARM.cpp (+1095) 
- (added) clang/lib/Sema/SemaBPF.cpp (+174) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+31-2979) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+8-6) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+50-382) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+2-1) 
- (added) clang/lib/Sema/SemaHexagon.cpp (+290) 
- (added) clang/lib/Sema/SemaLoongArch.cpp (+515) 
- (added) clang/lib/Sema/SemaMIPS.cpp (+240) 
- (added) clang/lib/Sema/SemaNVPTX.cpp (+35) 
- (added) clang/lib/Sema/SemaPPC.cpp (+439) 
- (added) clang/lib/Sema/SemaSystemZ.cpp (+94) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+4-3) 
- (added) clang/lib/Sema/SemaWasm.cpp (+340) 
- (modified) clang/utils/TableGen/MveEmitter.cpp (+5-4) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 057ff61ccc644..e19509c811805 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -67,6 +67,7 @@
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/TinyPtrVector.h"
 #include 
 #include 
@@ -168,15 +169,25 @@ class Preprocessor;
 class PseudoDestructorTypeStorage;
 class PseudoObjectExpr;
 class QualType;
+class SemaAMDGPU;
+class SemaARM;
+class SemaBPF;
 class SemaCodeCompletion;
 class SemaCUDA;
 class SemaHLSL;
+class SemaHexagon;
+class SemaLoongArch;
+class SemaMIPS;
+class SemaNVPTX;
 class SemaObjC;
 class SemaOpenACC;
 class SemaOpenMP;
+class SemaPPC;
 class SemaPseudoObject;
 class SemaRISCV;
 class SemaSYCL;
+class SemaSystemZ;
+class SemaWasm;
 class SemaX86;
 class StandardConversionSequence;
 class Stmt;
@@ -993,6 +1004,21 @@ class Sema final : public SemaBase {
   /// CurContext - This is the current declaration context of parsing.
   DeclContext *CurContext;
 
+  SemaAMDGPU &AMDGPU() {
+assert(AMDGPUPtr);
+return *AMDGPUPtr;
+  }
+
+  SemaARM &ARM() {
+assert(ARMPtr);
+return *ARMPtr;
+  }
+
+  SemaBPF &BPF() {
+assert(BPFPtr);
+return *BPFPtr;
+  }
+
   SemaCodeCompletion &CodeCompletion() {
 assert(CodeCompletionPtr);
 return *CodeCompletionPtr;
@@ -1008,6 +1034,26 @@ class Sema final : public SemaBase {
 return *HLSLPtr;
   }
 
+  SemaHexagon &Hexagon() {
+assert(HexagonPtr);
+return *HexagonPtr;
+  }
+
+  SemaLoongArch &LoongArch() {
+assert(LoongArchPtr);
+return *LoongArchPtr;
+  }
+
+  SemaMIPS &MIPS() {
+assert(MIPSPtr);
+return *MIPSPtr;
+  }
+
+  SemaNVPTX &NVPTX() {
+assert(NVPTXPtr);
+return *NVPTXPtr;
+  }
+
   SemaObjC &ObjC() {
 assert(ObjCPtr);
 return *ObjCPtr;
@@ -1023,6 +1069,11 @@ class Sema final : public SemaBase {
 return *OpenMPPtr;
   }
 
+  SemaPPC &PPC() {
+assert(PPCPtr);
+return *PPCPtr;
+  }
+
   SemaPseudoObject &PseudoObject() {
 assert(PseudoObjectPtr);
 return *PseudoObjectPtr;
@@ -1038,6 +1089,16 @@ class Sema final : public SemaBase {
 return *SYCLPtr;
   }
 
+  SemaSystemZ &SystemZ() {
+assert(SystemZPtr);
+return *SystemZPtr;
+  }
+
+  SemaWasm &Wasm() {
+assert(WasmPt

[clang] [clang] Introduce target-specific `Sema` components (PR #93179)

2024-05-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-systemz

Author: Vlad Serebrennikov (Endilll)


Changes

This patch introduces `SemaAMDGPU`, `SemaARM`, `SemaBPF`, `SemaHexagon`, 
`SemaLoongArch`, `SemaMIPS`, `SemaNVPTX`, `SemaPPC`, `SemaSystemZ`, `SemaWasm`. 
This continues previous efforts to split Sema up. Additional context can be 
found in #84184 and #92682.

I decided to bundle target-specific components together because of their low 
impact on `Sema`. That said, their impact on `SemaChecking.cpp` is far from 
low, and I consider it a success.

Somewhat accidentally, I also moved Wasm- and AMDGPU-specific function from 
`SemaDeclAttr.cpp`, because they were exposed in `Sema`. That went well, and I 
consider it a success, too. I'd like to move the rest of static target-specific 
functions out of `SemaDeclAttr.cpp` like we're doing with built-ins in 
`SemaChecking.cpp` .

---

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


30 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (+123-95) 
- (added) clang/include/clang/Sema/SemaAMDGPU.h (+68) 
- (added) clang/include/clang/Sema/SemaARM.h (+63) 
- (added) clang/include/clang/Sema/SemaBPF.h (+28) 
- (added) clang/include/clang/Sema/SemaHexagon.h (+29) 
- (added) clang/include/clang/Sema/SemaLoongArch.h (+30) 
- (added) clang/include/clang/Sema/SemaMIPS.h (+33) 
- (added) clang/include/clang/Sema/SemaNVPTX.h (+30) 
- (added) clang/include/clang/Sema/SemaPPC.h (+58) 
- (added) clang/include/clang/Sema/SemaSystemZ.h (+28) 
- (added) clang/include/clang/Sema/SemaWasm.h (+52) 
- (modified) clang/lib/Parse/ParseOpenMP.cpp (+3-2) 
- (modified) clang/lib/Sema/CMakeLists.txt (+10) 
- (modified) clang/lib/Sema/Sema.cpp (+20) 
- (added) clang/lib/Sema/SemaAMDGPU.cpp (+289) 
- (added) clang/lib/Sema/SemaARM.cpp (+1095) 
- (added) clang/lib/Sema/SemaBPF.cpp (+174) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+31-2979) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+8-6) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+50-382) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+2-1) 
- (added) clang/lib/Sema/SemaHexagon.cpp (+290) 
- (added) clang/lib/Sema/SemaLoongArch.cpp (+515) 
- (added) clang/lib/Sema/SemaMIPS.cpp (+240) 
- (added) clang/lib/Sema/SemaNVPTX.cpp (+35) 
- (added) clang/lib/Sema/SemaPPC.cpp (+439) 
- (added) clang/lib/Sema/SemaSystemZ.cpp (+94) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+4-3) 
- (added) clang/lib/Sema/SemaWasm.cpp (+340) 
- (modified) clang/utils/TableGen/MveEmitter.cpp (+5-4) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 057ff61ccc644..e19509c811805 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -67,6 +67,7 @@
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/TinyPtrVector.h"
 #include 
 #include 
@@ -168,15 +169,25 @@ class Preprocessor;
 class PseudoDestructorTypeStorage;
 class PseudoObjectExpr;
 class QualType;
+class SemaAMDGPU;
+class SemaARM;
+class SemaBPF;
 class SemaCodeCompletion;
 class SemaCUDA;
 class SemaHLSL;
+class SemaHexagon;
+class SemaLoongArch;
+class SemaMIPS;
+class SemaNVPTX;
 class SemaObjC;
 class SemaOpenACC;
 class SemaOpenMP;
+class SemaPPC;
 class SemaPseudoObject;
 class SemaRISCV;
 class SemaSYCL;
+class SemaSystemZ;
+class SemaWasm;
 class SemaX86;
 class StandardConversionSequence;
 class Stmt;
@@ -993,6 +1004,21 @@ class Sema final : public SemaBase {
   /// CurContext - This is the current declaration context of parsing.
   DeclContext *CurContext;
 
+  SemaAMDGPU &AMDGPU() {
+assert(AMDGPUPtr);
+return *AMDGPUPtr;
+  }
+
+  SemaARM &ARM() {
+assert(ARMPtr);
+return *ARMPtr;
+  }
+
+  SemaBPF &BPF() {
+assert(BPFPtr);
+return *BPFPtr;
+  }
+
   SemaCodeCompletion &CodeCompletion() {
 assert(CodeCompletionPtr);
 return *CodeCompletionPtr;
@@ -1008,6 +1034,26 @@ class Sema final : public SemaBase {
 return *HLSLPtr;
   }
 
+  SemaHexagon &Hexagon() {
+assert(HexagonPtr);
+return *HexagonPtr;
+  }
+
+  SemaLoongArch &LoongArch() {
+assert(LoongArchPtr);
+return *LoongArchPtr;
+  }
+
+  SemaMIPS &MIPS() {
+assert(MIPSPtr);
+return *MIPSPtr;
+  }
+
+  SemaNVPTX &NVPTX() {
+assert(NVPTXPtr);
+return *NVPTXPtr;
+  }
+
   SemaObjC &ObjC() {
 assert(ObjCPtr);
 return *ObjCPtr;
@@ -1023,6 +1069,11 @@ class Sema final : public SemaBase {
 return *OpenMPPtr;
   }
 
+  SemaPPC &PPC() {
+assert(PPCPtr);
+return *PPCPtr;
+  }
+
   SemaPseudoObject &PseudoObject() {
 assert(PseudoObjectPtr);
 return *PseudoObjectPtr;
@@ -1038,6 +1089,16 @@ class Sema final : public SemaBase {
 return *SYCLPtr;
   }
 
+  SemaSystemZ &SystemZ() {
+assert(SystemZPtr);
+return *SystemZPtr;
+  }
+
+  SemaWasm &Wasm() {
+assert(WasmP

[clang] [clang] Introduce target-specific `Sema` components (PR #93179)

2024-05-23 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 781b13538e55a42b2d02bb4d21779f15ff8a640c 
6e68c960bde622eb244f726d97982219b08a68bf -- 
clang/include/clang/Sema/SemaAMDGPU.h clang/include/clang/Sema/SemaARM.h 
clang/include/clang/Sema/SemaBPF.h clang/include/clang/Sema/SemaHexagon.h 
clang/include/clang/Sema/SemaLoongArch.h clang/include/clang/Sema/SemaMIPS.h 
clang/include/clang/Sema/SemaNVPTX.h clang/include/clang/Sema/SemaPPC.h 
clang/include/clang/Sema/SemaSystemZ.h clang/include/clang/Sema/SemaWasm.h 
clang/lib/Sema/SemaAMDGPU.cpp clang/lib/Sema/SemaARM.cpp 
clang/lib/Sema/SemaBPF.cpp clang/lib/Sema/SemaHexagon.cpp 
clang/lib/Sema/SemaLoongArch.cpp clang/lib/Sema/SemaMIPS.cpp 
clang/lib/Sema/SemaNVPTX.cpp clang/lib/Sema/SemaPPC.cpp 
clang/lib/Sema/SemaSystemZ.cpp clang/lib/Sema/SemaWasm.cpp 
clang/include/clang/Sema/Sema.h clang/lib/Parse/ParseOpenMP.cpp 
clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaChecking.cpp 
clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclAttr.cpp 
clang/lib/Sema/SemaExprCXX.cpp clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
clang/utils/TableGen/MveEmitter.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaARM.cpp b/clang/lib/Sema/SemaARM.cpp
index c1280190ff..f6e4a28d44 100644
--- a/clang/lib/Sema/SemaARM.cpp
+++ b/clang/lib/Sema/SemaARM.cpp
@@ -1082,11 +1082,18 @@ bool SemaARM::CheckAArch64BuiltinFunctionCall(const 
TargetInfo &TI,
   // range check them here.
   unsigned i = 0, l = 0, u = 0;
   switch (BuiltinID) {
-  default: return false;
+  default:
+return false;
   case AArch64::BI__builtin_arm_dmb:
   case AArch64::BI__builtin_arm_dsb:
-  case AArch64::BI__builtin_arm_isb: l = 0; u = 15; break;
-  case AArch64::BI__builtin_arm_tcancel: l = 0; u = 65535; break;
+  case AArch64::BI__builtin_arm_isb:
+l = 0;
+u = 15;
+break;
+  case AArch64::BI__builtin_arm_tcancel:
+l = 0;
+u = 65535;
+break;
   }
 
   return SemaRef.BuiltinConstantArgRange(TheCall, i, l, u + l);
diff --git a/clang/lib/Sema/SemaHexagon.cpp b/clang/lib/Sema/SemaHexagon.cpp
index 5c921c0bc9..25331fc3b3 100644
--- a/clang/lib/Sema/SemaHexagon.cpp
+++ b/clang/lib/Sema/SemaHexagon.cpp
@@ -35,214 +35,200 @@ bool SemaHexagon::CheckHexagonBuiltinArgument(unsigned 
BuiltinID,
   };
 
   static BuiltinInfo Infos[] = {
-{ Hexagon::BI__builtin_circ_ldd,  {{ 3, true,  4,  3 }} },
-{ Hexagon::BI__builtin_circ_ldw,  {{ 3, true,  4,  2 }} },
-{ Hexagon::BI__builtin_circ_ldh,  {{ 3, true,  4,  1 }} },
-{ Hexagon::BI__builtin_circ_lduh, {{ 3, true,  4,  1 }} },
-{ Hexagon::BI__builtin_circ_ldb,  {{ 3, true,  4,  0 }} },
-{ Hexagon::BI__builtin_circ_ldub, {{ 3, true,  4,  0 }} },
-{ Hexagon::BI__builtin_circ_std,  {{ 3, true,  4,  3 }} },
-{ Hexagon::BI__builtin_circ_stw,  {{ 3, true,  4,  2 }} },
-{ Hexagon::BI__builtin_circ_sth,  {{ 3, true,  4,  1 }} },
-{ Hexagon::BI__builtin_circ_sthhi,{{ 3, true,  4,  1 }} },
-{ Hexagon::BI__builtin_circ_stb,  {{ 3, true,  4,  0 }} },
+  {Hexagon::BI__builtin_circ_ldd, {{3, true, 4, 3}}},
+  {Hexagon::BI__builtin_circ_ldw, {{3, true, 4, 2}}},
+  {Hexagon::BI__builtin_circ_ldh, {{3, true, 4, 1}}},
+  {Hexagon::BI__builtin_circ_lduh, {{3, true, 4, 1}}},
+  {Hexagon::BI__builtin_circ_ldb, {{3, true, 4, 0}}},
+  {Hexagon::BI__builtin_circ_ldub, {{3, true, 4, 0}}},
+  {Hexagon::BI__builtin_circ_std, {{3, true, 4, 3}}},
+  {Hexagon::BI__builtin_circ_stw, {{3, true, 4, 2}}},
+  {Hexagon::BI__builtin_circ_sth, {{3, true, 4, 1}}},
+  {Hexagon::BI__builtin_circ_sthhi, {{3, true, 4, 1}}},
+  {Hexagon::BI__builtin_circ_stb, {{3, true, 4, 0}}},
 
-{ Hexagon::BI__builtin_HEXAGON_L2_loadrub_pci,{{ 1, true,  4,  0 }} },
-{ Hexagon::BI__builtin_HEXAGON_L2_loadrb_pci, {{ 1, true,  4,  0 }} },
-{ Hexagon::BI__builtin_HEXAGON_L2_loadruh_pci,{{ 1, true,  4,  1 }} },
-{ Hexagon::BI__builtin_HEXAGON_L2_loadrh_pci, {{ 1, true,  4,  1 }} },
-{ Hexagon::BI__builtin_HEXAGON_L2_loadri_pci, {{ 1, true,  4,  2 }} },
-{ Hexagon::BI__builtin_HEXAGON_L2_loadrd_pci, {{ 1, true,  4,  3 }} },
-{ Hexagon::BI__builtin_HEXAGON_S2_storerb_pci,{{ 1, true,  4,  0 }} },
-{ Hexagon::BI__builtin_HEXAGON_S2_storerh_pci,{{ 1, true,  4,  1 }} },
-{ Hexagon::BI__builtin_HEXAGON_S2_storerf_pci,{{ 1, true,  4,  1 }} },
-{ Hexagon::BI__builtin_HEXAGON_S2_storeri_pci,{{ 1, true,  4,  2 }} },
-{ Hexagon::BI__builtin_HEXAGON_S2_storerd_pci,{{ 1, true,  4,  3 }} },
+  {Hexagon::BI__builtin_HEXAGON_L2_loadrub_pci, {{1, true, 4, 0}}},
+  {Hexag

[clang] [clang-tools-extra] [clang-tidy][dataflow] Add `bugprone-null-check-after-dereference` check (PR #84166)

2024-05-23 Thread via cfe-commits

Discookie wrote:

gentle ping @martinboehme @gribozavr 

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


[clang] [clang] Introduce target-specific `Sema` components (PR #93179)

2024-05-23 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

The only thing clang-format complain about is switches for builtins for ARM, 
Hexagon, MIPS, and SystemZ. I don't feel like it makes improvements there, but 
open for input from contributors in those areas.

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


[clang] [clang] fix printing of canonical template template parameters (PR #93124)

2024-05-23 Thread Matheus Izvekov via cfe-commits

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


[clang] 01f143d - [clang] fix printing of canonical template template parameters (#93124)

2024-05-23 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2024-05-23T09:27:40-03:00
New Revision: 01f143dd39dc14029943dcf6eb2f7bbc2d82d6d4

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

LOG: [clang] fix printing of canonical template template parameters (#93124)

Added: 


Modified: 
clang/lib/AST/TemplateBase.cpp
clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
clang/test/SemaTemplate/deduction-guide.cpp
clang/test/SemaTemplate/make_integer_seq.cpp

Removed: 




diff  --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index 3310d7dc24c59..a7ee973b7f7d0 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -538,9 +538,19 @@ void TemplateArgument::print(const PrintingPolicy &Policy, 
raw_ostream &Out,
 Out << "nullptr";
 break;
 
-  case Template:
-getAsTemplate().print(Out, Policy, TemplateName::Qualified::Fully);
+  case Template: {
+TemplateName TN = getAsTemplate();
+if (const auto *TD = TN.getAsTemplateDecl();
+TD && TD->getDeclName().isEmpty()) {
+  assert(isa(TD) &&
+ "Unexpected anonymous template");
+  const auto *TTP = cast(TD);
+  Out << "template-parameter-" << TTP->getDepth() << "-" << 
TTP->getIndex();
+} else {
+  TN.print(Out, Policy, TemplateName::Qualified::Fully);
+}
 break;
+  }
 
   case TemplateExpansion:
 getAsTemplateOrTemplatePattern().print(Out, Policy);

diff  --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp 
b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
index 4c6ef5adae7d2..b71dfc6ccaf4f 100644
--- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
+++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
@@ -284,7 +284,7 @@ class Foo {};
 // Verify that template template type parameter TTP is referenced/used in the
 // template arguments of the RHS.
 template  typename TTP>
-using Bar = Foo>; // expected-note {{candidate template ignored: could 
not match 'Foo>' against 'int'}}
+using Bar = Foo>; // expected-note {{candidate template ignored: could 
not match 'Foo>' against 'int'}}
 
 template 
 class Container {};

diff  --git a/clang/test/SemaTemplate/deduction-guide.cpp 
b/clang/test/SemaTemplate/deduction-guide.cpp
index 0eaeb49e6b32d..c38b647e42f4c 100644
--- a/clang/test/SemaTemplate/deduction-guide.cpp
+++ b/clang/test/SemaTemplate/deduction-guide.cpp
@@ -102,9 +102,9 @@ using CT = C;
 // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'type-parameter-0-2' depth 0 index 
3 V
 // CHECK: | `-TemplateArgument {{.*}} expr
 // CHECK: |   `-IntegerLiteral {{.*}} 'int' 0
-// CHECK: |-CXXDeductionGuideDecl {{.*}} 'auto (A, Y<>, type-parameter-0-2) -> 
C'
+// CHECK: |-CXXDeductionGuideDecl {{.*}} 'auto (A, Y, 
type-parameter-0-2) -> C'
 // CHECK: | |-ParmVarDecl {{.*}} 'A'
-// CHECK: | |-ParmVarDecl {{.*}} 'Y<>'
+// CHECK: | |-ParmVarDecl {{.*}} 'Y'
 // CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-2'
 // CHECK: `-CXXDeductionGuideDecl {{.*}} 'auto (int, Y, int) -> C'
 // CHECK:  |-TemplateArgument type 'int'
@@ -114,12 +114,12 @@ using CT = C;
 // CHECK:  |-ParmVarDecl {{.*}} 'int'
 // CHECK:  |-ParmVarDecl {{.*}} 'Y'
 // CHECK:  `-ParmVarDecl {{.*}} 'int'
-// CHECK: FunctionProtoType {{.*}} 'auto (A, Y<>, type-parameter-0-2) -> C' 
dependent trailing_return cdecl
+// CHECK: FunctionProtoType {{.*}} 'auto (A, Y, 
type-parameter-0-2) -> C' dependent trailing_return cdecl
 // CHECK: |-InjectedClassNameType {{.*}} 'C' dependent
 // CHECK: |-TemplateTypeParmType {{.*}} 'A' dependent depth 0 index 0
 // CHECK: | `-TemplateTypeParm {{.*}} 'A'
-// CHECK: |-ElaboratedType {{.*}} 'Y<>' sugar dependent
-// CHECK: | `-TemplateSpecializationType {{.*}} 'Y<>' dependent Y
+// CHECK: |-ElaboratedType {{.*}} 'Y' sugar dependent
+// CHECK: | `-TemplateSpecializationType {{.*}} 'Y' 
dependent Y
 // CHECK: |   `-TemplateArgument template
 // CHECK: `-TemplateTypeParmType {{.*}} 'type-parameter-0-2' dependent depth 0 
index 2
 

diff  --git a/clang/test/SemaTemplate/make_integer_seq.cpp 
b/clang/test/SemaTemplate/make_integer_seq.cpp
index 3a692f5ae2bfb..c5a1e27053689 100644
--- a/clang/test/SemaTemplate/make_integer_seq.cpp
+++ b/clang/test/SemaTemplate/make_integer_seq.cpp
@@ -61,7 +61,7 @@ using test2 = B;
 
 template  class S, class T, int N> struct C {
   using test3 = __make_integer_seq;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 
test3 '__make_integer_seq':'__make_integer_seq'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 
test3 '__make_integer_seq':'__make_integer_seq'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 
'__make_integer_seq' sugar dependent alias __make_integer_seq
 // CHECK-NEXT:   |-TemplateArgument template S
@@ -7

[clang] [clang] Introduce target-specific `Sema` components (PR #93179)

2024-05-23 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm commented:

Should update the GitHub autolabeler paths for the targets 

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


[clang] [clang] Introduce target-specific `Sema` components (PR #93179)

2024-05-23 Thread Matt Arsenault via cfe-commits

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


[clang] [llvm] Reland "[X86] Remove knl/knm specific ISAs supports (#92883)" (PR #93136)

2024-05-23 Thread Simon Pilgrim via cfe-commits

RKSimon wrote:

Not sure - CI checks aren't running either

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


[clang] [llvm] [clang] Introduce target-specific `Sema` components (PR #93179)

2024-05-23 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

> Should update the GitHub autolabeler paths for the targets if they don't get 
> caught talready

AMDGPU has been already caught, I updated the rest. Thank you!

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


[clang] [Clang] Only check exprs that might be immediate escalating in evaluated contexts (PR #93187)

2024-05-23 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/93187

As per https://eel.is/c++draft/expr.const#17

Fixes #91308

>From faecc5c3d88f2e205c62424e4c76df92f66ea4fe Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Thu, 23 May 2024 14:58:49 +0200
Subject: [PATCH] [Clang] Only check exprs that might be immediate escalating
 in evaluated contexts

As per https://eel.is/c++draft/expr.const#17

Fixes #91308
---
 clang/docs/ReleaseNotes.rst  |  2 ++
 clang/include/clang/Sema/Sema.h  | 13 +
 clang/lib/Sema/SemaTemplateDeduction.cpp |  5 +
 clang/test/SemaCXX/cxx2b-consteval-propagate.cpp |  8 
 4 files changed, 28 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c4a343b70009..55b963657a1d7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -769,6 +769,8 @@ Bug Fixes to C++ Support
 - Fixed a crash when trying to emit captures in a lambda call operator with an 
explicit object
   parameter that is called on a derived type of the lambda.
   Fixes (#GH87210), (GH89541).
+- Clang no longer try to check if an expression is immediate-escalating in an 
unevaluated context.
+  Fixes (#GH91308).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 057ff61ccc644..bf3923823 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5112,6 +5112,13 @@ class Sema final : public SemaBase {
  Context == ExpressionEvaluationContext::UnevaluatedList;
 }
 
+bool isPotentiallyEvaluated() const {
+  return Context == ExpressionEvaluationContext::PotentiallyEvaluated ||
+ Context ==
+ ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed ||
+ Context == ExpressionEvaluationContext::ConstantEvaluated;
+}
+
 bool isConstantEvaluated() const {
   return Context == ExpressionEvaluationContext::ConstantEvaluated ||
  Context == ExpressionEvaluationContext::ImmediateFunctionContext;
@@ -5146,6 +5153,12 @@ class Sema final : public SemaBase {
 return ExprEvalContexts.back();
   };
 
+  const ExpressionEvaluationContextRecord &parentEvaluationContext() const {
+assert(ExprEvalContexts.size() >= 2 &&
+   "Must be in an expression evaluation context");
+return ExprEvalContexts[ExprEvalContexts.size() - 2];
+  };
+
   bool isBoundsAttrContext() const {
 return ExprEvalContexts.back().ExprContext ==
ExpressionEvaluationContextRecord::ExpressionKind::
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 76f47e9cb2560..08a69d3cb2589 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4788,8 +4788,13 @@ TemplateDeductionResult Sema::DeduceTemplateArguments(
   DeduceReturnType(Specialization, Info.getLocation(), false))
 return TemplateDeductionResult::MiscellaneousDeductionFailure;
 
+  // [C++26][expr.const]/p17
+  // An expression or conversion is immediate-escalating if it is not initially
+  // in an immediate function context and it is [...]
+  // a potentially-evaluated id-expression that denotes an immediate function.
   if (IsAddressOfFunction && getLangOpts().CPlusPlus20 &&
   Specialization->isImmediateEscalating() &&
+  parentEvaluationContext().isPotentiallyEvaluated() &&
   CheckIfFunctionSpecializationIsImmediate(Specialization,
Info.getLocation()))
 return TemplateDeductionResult::MiscellaneousDeductionFailure;
diff --git a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp 
b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
index 07937deb66738..b70c02201ac3c 100644
--- a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
+++ b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -446,3 +446,11 @@ int h(int x) {
 }
 
 #endif
+
+
+namespace GH91308 {
+constexpr void f(auto) {
+static_assert(false);
+}
+using R1 = decltype(&f);
+}

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


[clang] [Clang] Only check exprs that might be immediate escalating in evaluated contexts (PR #93187)

2024-05-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes

As per https://eel.is/c++draft/expr.const#17

Fixes #91308

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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Sema/Sema.h (+13) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+5) 
- (modified) clang/test/SemaCXX/cxx2b-consteval-propagate.cpp (+8) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c4a343b70009..55b963657a1d7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -769,6 +769,8 @@ Bug Fixes to C++ Support
 - Fixed a crash when trying to emit captures in a lambda call operator with an 
explicit object
   parameter that is called on a derived type of the lambda.
   Fixes (#GH87210), (GH89541).
+- Clang no longer try to check if an expression is immediate-escalating in an 
unevaluated context.
+  Fixes (#GH91308).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 057ff61ccc644..bf3923823 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5112,6 +5112,13 @@ class Sema final : public SemaBase {
  Context == ExpressionEvaluationContext::UnevaluatedList;
 }
 
+bool isPotentiallyEvaluated() const {
+  return Context == ExpressionEvaluationContext::PotentiallyEvaluated ||
+ Context ==
+ ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed ||
+ Context == ExpressionEvaluationContext::ConstantEvaluated;
+}
+
 bool isConstantEvaluated() const {
   return Context == ExpressionEvaluationContext::ConstantEvaluated ||
  Context == ExpressionEvaluationContext::ImmediateFunctionContext;
@@ -5146,6 +5153,12 @@ class Sema final : public SemaBase {
 return ExprEvalContexts.back();
   };
 
+  const ExpressionEvaluationContextRecord &parentEvaluationContext() const {
+assert(ExprEvalContexts.size() >= 2 &&
+   "Must be in an expression evaluation context");
+return ExprEvalContexts[ExprEvalContexts.size() - 2];
+  };
+
   bool isBoundsAttrContext() const {
 return ExprEvalContexts.back().ExprContext ==
ExpressionEvaluationContextRecord::ExpressionKind::
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 76f47e9cb2560..08a69d3cb2589 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4788,8 +4788,13 @@ TemplateDeductionResult Sema::DeduceTemplateArguments(
   DeduceReturnType(Specialization, Info.getLocation(), false))
 return TemplateDeductionResult::MiscellaneousDeductionFailure;
 
+  // [C++26][expr.const]/p17
+  // An expression or conversion is immediate-escalating if it is not initially
+  // in an immediate function context and it is [...]
+  // a potentially-evaluated id-expression that denotes an immediate function.
   if (IsAddressOfFunction && getLangOpts().CPlusPlus20 &&
   Specialization->isImmediateEscalating() &&
+  parentEvaluationContext().isPotentiallyEvaluated() &&
   CheckIfFunctionSpecializationIsImmediate(Specialization,
Info.getLocation()))
 return TemplateDeductionResult::MiscellaneousDeductionFailure;
diff --git a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp 
b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
index 07937deb66738..b70c02201ac3c 100644
--- a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
+++ b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -446,3 +446,11 @@ int h(int x) {
 }
 
 #endif
+
+
+namespace GH91308 {
+constexpr void f(auto) {
+static_assert(false);
+}
+using R1 = decltype(&f);
+}

``




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


[clang] 4feae05 - Remove some `try_compile` CMake checks for compiler flags (#92953)

2024-05-23 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-05-23T17:05:41+04:00
New Revision: 4feae05c6abda364a9295aecfa600d7d4e7dfeb6

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

LOG: Remove some `try_compile` CMake checks for compiler flags (#92953)

This patch remove 36 checks for compiler flags that are done via
invoking the compiler across LLVM, Clang, and LLDB. It's was made
possible by raising the bar for supported compilers that has been
happening over the years since the checks were added.

This is going to improve CMake configuration times. This topic was
highlighted in
https://discourse.llvm.org/t/cmake-compiler-flag-checks-are-really-slow-ideas-to-speed-them-up/78882.

Added: 


Modified: 
clang/CMakeLists.txt
clang/tools/scan-build-py/tests/functional/exec/CMakeLists.txt
lldb/cmake/modules/LLDBConfig.cmake
llvm/cmake/config-ix.cmake
llvm/cmake/modules/AddLLVM.cmake
llvm/cmake/modules/HandleLLVMOptions.cmake

Removed: 




diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index c20ce47a12abb..a6bcb853a464c 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -349,10 +349,7 @@ if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-long-long")
   endif ()
 
-  check_cxx_compiler_flag("-Werror -Wnested-anon-types" 
CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG)
-  if( CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG )
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types" )
-  endif()
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types" )
 endif ()
 
 # Determine HOST_LINK_VERSION on Darwin.

diff  --git a/clang/tools/scan-build-py/tests/functional/exec/CMakeLists.txt 
b/clang/tools/scan-build-py/tests/functional/exec/CMakeLists.txt
index 95c6fdb610e0f..cb6ebda183725 100644
--- a/clang/tools/scan-build-py/tests/functional/exec/CMakeLists.txt
+++ b/clang/tools/scan-build-py/tests/functional/exec/CMakeLists.txt
@@ -2,11 +2,7 @@ project(exec C)
 
 cmake_minimum_required(VERSION 3.20.0)
 
-include(CheckCCompilerFlag)
-check_c_compiler_flag("-std=c99" C99_SUPPORTED)
-if (C99_SUPPORTED)
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
-endif()
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
 
 include(CheckFunctionExists)
 include(CheckSymbolExists)

diff  --git a/lldb/cmake/modules/LLDBConfig.cmake 
b/lldb/cmake/modules/LLDBConfig.cmake
index 3c6223b015bb1..6458f2e174643 100644
--- a/lldb/cmake/modules/LLDBConfig.cmake
+++ b/lldb/cmake/modules/LLDBConfig.cmake
@@ -187,24 +187,18 @@ 
include_directories("${CMAKE_CURRENT_BINARY_DIR}/../clang/include")
 # form -W, and if supported, add the corresponding -Wno- option.
 
 # Disable GCC warnings
-check_cxx_compiler_flag("-Wdeprecated-declarations" 
CXX_SUPPORTS_DEPRECATED_DECLARATIONS)
-append_if(CXX_SUPPORTS_DEPRECATED_DECLARATIONS "-Wno-deprecated-declarations" 
CMAKE_CXX_FLAGS)
-
-check_cxx_compiler_flag("-Wunknown-pragmas" CXX_SUPPORTS_UNKNOWN_PRAGMAS)
-append_if(CXX_SUPPORTS_UNKNOWN_PRAGMAS "-Wno-unknown-pragmas" CMAKE_CXX_FLAGS)
-
-check_cxx_compiler_flag("-Wstrict-aliasing" CXX_SUPPORTS_STRICT_ALIASING)
-append_if(CXX_SUPPORTS_STRICT_ALIASING "-Wno-strict-aliasing" CMAKE_CXX_FLAGS)
+append("-Wno-deprecated-declarations" CMAKE_CXX_FLAGS)
+append("-Wno-unknown-pragmas" CMAKE_CXX_FLAGS)
+append("-Wno-strict-aliasing" CMAKE_CXX_FLAGS)
 
 check_cxx_compiler_flag("-Wstringop-truncation" 
CXX_SUPPORTS_STRINGOP_TRUNCATION)
 append_if(CXX_SUPPORTS_STRINGOP_TRUNCATION "-Wno-stringop-truncation" 
CMAKE_CXX_FLAGS)
 
 # Disable Clang warnings
-check_cxx_compiler_flag("-Wdeprecated-register" 
CXX_SUPPORTS_DEPRECATED_REGISTER)
-append_if(CXX_SUPPORTS_DEPRECATED_REGISTER "-Wno-deprecated-register" 
CMAKE_CXX_FLAGS)
-
-check_cxx_compiler_flag("-Wvla-extension" CXX_SUPPORTS_VLA_EXTENSION)
-append_if(CXX_SUPPORTS_VLA_EXTENSION "-Wno-vla-extension" CMAKE_CXX_FLAGS)
+if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+  append("-Wno-deprecated-register" CMAKE_CXX_FLAGS)
+  append("-Wno-vla-extension" CMAKE_CXX_FLAGS)
+endif()
 
 # Disable MSVC warnings
 if( MSVC )

diff  --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index bf1b110245bb2..5a884a5b0a0c0 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -415,15 +415,18 @@ if( LLVM_ENABLE_PIC )
   set(ENABLE_PIC 1)
 else()
   set(ENABLE_PIC 0)
-  check_cxx_compiler_flag("-fno-pie" SUPPORTS_NO_PIE_FLAG)
-  if(SUPPORTS_NO_PIE_FLAG)
-set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie")
-  endif()
+  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie")
 endif()
 
-check_cxx_compiler_flag("-Wvariadic-macros" SUPPORTS_VARIADIC_MACROS_FLAG)
-check_cxx_compiler_flag("-Wgnu-zero-variadic-macro-arguments"
-SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUM

[clang] [lldb] [llvm] Remove some `try_compile` CMake checks for compiler flags (PR #92953)

2024-05-23 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [llvm] [AMDGPU][Clang] Add check of size for __builtin_amdgcn_global_load_lds (PR #93064)

2024-05-23 Thread Shilei Tian via cfe-commits

https://github.com/shiltian updated 
https://github.com/llvm/llvm-project/pull/93064

>From e12473d466d7b354ecff0b8ea553b64d3059e1cf Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Thu, 23 May 2024 09:07:31 -0400
Subject: [PATCH] [AMDGPU][Clang] Add check of size for
 __builtin_amdgcn_global_load_lds

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 
 clang/lib/Sema/SemaChecking.cpp   | 22 +++
 .../SemaOpenCL/builtins-amdgcn-gfx940-err.cl  | 13 +++
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td  |  2 +-
 4 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaOpenCL/builtins-amdgcn-gfx940-err.cl

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index cc402182687f3..085f3111ff422 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12385,4 +12385,8 @@ def err_acc_reduction_composite_type
 def err_acc_reduction_composite_member_type :Error<
 "OpenACC 'reduction' composite variable must not have non-scalar field">;
 def note_acc_reduction_composite_member_loc : Note<"invalid field is here">;
+
+// AMDGCN builtins diagnostics
+def err_amdgcn_global_load_lds_size_invalid_value : Error<"invalid size 
value">;
+def note_amdgcn_global_load_lds_size_valid_value : Note<"size must be 1/2/4">;
 } // end of sema component.
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index dd48490e6dd42..fac9a58fa2689 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5696,6 +5696,28 @@ bool Sema::CheckAMDGCNBuiltinFunctionCall(unsigned 
BuiltinID,
   // position of memory order and scope arguments in the builtin
   unsigned OrderIndex, ScopeIndex;
   switch (BuiltinID) {
+  case AMDGPU::BI__builtin_amdgcn_global_load_lds: {
+constexpr const int SizeIdx = 2;
+llvm::APSInt Size;
+Expr *ArgExpr = TheCall->getArg(SizeIdx);
+ExprResult R = VerifyIntegerConstantExpression(ArgExpr, &Size);
+if (R.isInvalid())
+  return true;
+switch (Size.getSExtValue()) {
+case 1:
+case 2:
+case 4:
+  return false;
+default:
+  Diag(ArgExpr->getExprLoc(),
+   diag::err_amdgcn_global_load_lds_size_invalid_value)
+  << ArgExpr->getSourceRange();
+  Diag(ArgExpr->getExprLoc(),
+   diag::note_amdgcn_global_load_lds_size_valid_value)
+  << ArgExpr->getSourceRange();
+  return true;
+}
+  }
   case AMDGPU::BI__builtin_amdgcn_get_fpenv:
   case AMDGPU::BI__builtin_amdgcn_set_fpenv:
 return false;
diff --git a/clang/test/SemaOpenCL/builtins-amdgcn-gfx940-err.cl 
b/clang/test/SemaOpenCL/builtins-amdgcn-gfx940-err.cl
new file mode 100644
index 0..0ebe56197ed33
--- /dev/null
+++ b/clang/test/SemaOpenCL/builtins-amdgcn-gfx940-err.cl
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -triple amdgcn-unknown-unknown 
-target-cpu gfx940 -S -verify -o - %s
+// REQUIRES: amdgpu-registered-target
+
+typedef unsigned int u32;
+
+void test_global_load_lds_unsupported_size(global u32* src, local u32 *dst, 
u32 size) {
+  __builtin_amdgcn_global_load_lds(src, dst, size, /*offset=*/0, /*aux=*/0); 
// expected-error{{expression is not an integer constant expression}}
+  __builtin_amdgcn_global_load_lds(src, dst, /*size=*/5, /*offset=*/0, 
/*aux=*/0); // expected-error{{invalid size value}} expected-note {{size must 
be 1/2/4}}
+  __builtin_amdgcn_global_load_lds(src, dst, /*size=*/0, /*offset=*/0, 
/*aux=*/0); // expected-error{{invalid size value}} expected-note {{size must 
be 1/2/4}}
+  __builtin_amdgcn_global_load_lds(src, dst, /*size=*/3, /*offset=*/0, 
/*aux=*/0); // expected-error{{invalid size value}} expected-note {{size must 
be 1/2/4}}
+  __builtin_amdgcn_global_load_lds(src, dst, /*size=*/12, /*offset=*/0, 
/*aux=*/0); // expected-error{{invalid size value}} expected-note {{size must 
be 1/2/4}}
+  __builtin_amdgcn_global_load_lds(src, dst, /*size=*/16, /*offset=*/0, 
/*aux=*/0); // expected-error{{invalid size value}} expected-note {{size must 
be 1/2/4}}
+}
diff --git a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td 
b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
index 5c001a4dd6247..d4a8954a4cdac 100644
--- a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
+++ b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
@@ -2472,7 +2472,7 @@ class AMDGPUGlobalLoadLDS :
 [],
 [LLVMQualPointerType<1>,// Base global pointer to load from
  LLVMQualPointerType<3>,// LDS base pointer to store to
- llvm_i32_ty,   // Data byte size: 1/2/4 (/12/16 for 
gfx950)
+ llvm_i32_ty,   // Data byte size: 1/2/4
  llvm_i32_ty,   // imm offset (applied to both global 
and LDS address)
  llvm_i32_ty],  // auxiliary data (imm, cachepolicy 
(bit 0 = sc0,
 //  

[clang] [Analyzer][CFG] Correctly handle rebuilt default arg and default init expression (PR #91879)

2024-05-23 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/91879

>From f7b2ae00eebb272e0e5e221608ec3a36146a5d21 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sun, 12 May 2024 14:42:09 +0800
Subject: [PATCH 1/4] [Analyzer][CFG] Correctly handle rebuilted default arg
 and default init expression

Signed-off-by: yronglin 
---
 clang/lib/AST/ParentMap.cpp  | 16 +
 clang/lib/Analysis/CFG.cpp   | 38 +++-
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 35 ++
 3 files changed, 56 insertions(+), 33 deletions(-)

diff --git a/clang/lib/AST/ParentMap.cpp b/clang/lib/AST/ParentMap.cpp
index 3d6a1cc84c7b1..534793b837bbb 100644
--- a/clang/lib/AST/ParentMap.cpp
+++ b/clang/lib/AST/ParentMap.cpp
@@ -97,6 +97,22 @@ static void BuildParentMap(MapTy& M, Stmt* S,
   BuildParentMap(M, SubStmt, OVMode);
 }
 break;
+  case Stmt::CXXDefaultArgExprClass:
+if (auto *Arg = dyn_cast(S)) {
+  if (Arg->hasRewrittenInit()) {
+M[Arg->getExpr()] = S;
+BuildParentMap(M, Arg->getExpr(), OVMode);
+  }
+}
+break;
+  case Stmt::CXXDefaultInitExprClass:
+if (auto *Init = dyn_cast(S)) {
+  if (Init->hasRewrittenInit()) {
+M[Init->getExpr()] = S;
+BuildParentMap(M, Init->getExpr(), OVMode);
+  }
+}
+break;
   default:
 for (Stmt *SubStmt : S->children()) {
   if (SubStmt) {
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 64e6155de090c..2f3f3e92516ba 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -556,6 +556,8 @@ class CFGBuilder {
 
 private:
   // Visitors to walk an AST and construct the CFG.
+  CFGBlock *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Default, AddStmtChoice 
asc);
+  CFGBlock *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Default, AddStmtChoice 
asc);
   CFGBlock *VisitInitListExpr(InitListExpr *ILE, AddStmtChoice asc);
   CFGBlock *VisitAddrLabelExpr(AddrLabelExpr *A, AddStmtChoice asc);
   CFGBlock *VisitAttributedStmt(AttributedStmt *A, AddStmtChoice asc);
@@ -2254,16 +2256,10 @@ CFGBlock *CFGBuilder::Visit(Stmt * S, AddStmtChoice asc,
asc, ExternallyDestructed);
 
 case Stmt::CXXDefaultArgExprClass:
+  return VisitCXXDefaultArgExpr(cast(S), asc);
+
 case Stmt::CXXDefaultInitExprClass:
-  // FIXME: The expression inside a CXXDefaultArgExpr is owned by the
-  // called function's declaration, not by the caller. If we simply add
-  // this expression to the CFG, we could end up with the same Expr
-  // appearing multiple times (PR13385).
-  //
-  // It's likewise possible for multiple CXXDefaultInitExprs for the same
-  // expression to be used in the same function (through aggregate
-  // initialization).
-  return VisitStmt(S, asc);
+  return VisitCXXDefaultInitExpr(cast(S), asc);
 
 case Stmt::CXXBindTemporaryExprClass:
   return VisitCXXBindTemporaryExpr(cast(S), asc);
@@ -2433,6 +2429,30 @@ CFGBlock *CFGBuilder::VisitChildren(Stmt *S) {
   return B;
 }
 
+CFGBlock *CFGBuilder::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Arg,
+ AddStmtChoice asc) {
+  if (Arg->hasRewrittenInit()) {
+if (asc.alwaysAdd(*this, Arg)) {
+  autoCreateBlock();
+  appendStmt(Block, Arg);
+}
+return VisitStmt(Arg->getExpr(), asc);
+  }
+  return VisitStmt(Arg, asc);
+}
+
+CFGBlock *CFGBuilder::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Init,
+  AddStmtChoice asc) {
+  if (Init->hasRewrittenInit()) {
+if (asc.alwaysAdd(*this, Init)) {
+  autoCreateBlock();
+  appendStmt(Block, Init);
+}
+return VisitStmt(Init->getExpr(), asc);
+  }
+  return VisitStmt(Init, asc);
+}
+
 CFGBlock *CFGBuilder::VisitInitListExpr(InitListExpr *ILE, AddStmtChoice asc) {
   if (asc.alwaysAdd(*this, ILE)) {
 autoCreateBlock();
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 0b1edf3e5c96b..41cb4293a8451 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1964,11 +1964,8 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
 case Stmt::CXXDefaultArgExprClass:
 case Stmt::CXXDefaultInitExprClass: {
   Bldr.takeNodes(Pred);
-  ExplodedNodeSet PreVisit;
-  getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this);
-
-  ExplodedNodeSet Tmp;
-  StmtNodeBuilder Bldr2(PreVisit, Tmp, *currBldrCtx);
+  ExplodedNodeSet CheckedSet;
+  getCheckerManager().runCheckersForPreStmt(CheckedSet, Pred, S, *this);
 
   const Expr *ArgE;
   if (const auto *DefE = dyn_cast(S))
@@ -1978,25 +1975,15 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode 
*Pred,
   else
 llvm_unreachable("unknown constant wrapper kind");
 
-  bool IsTemporary = fals

[clang] [llvm] [AMDGPU][Clang] Add check of size for __builtin_amdgcn_global_load_lds (PR #93064)

2024-05-23 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -triple amdgcn-unknown-unknown 
-target-cpu gfx940 -S -verify -o - %s
+// REQUIRES: amdgpu-registered-target
+
+typedef unsigned int u32;
+
+void test_global_load_lds_unsupported_size(global u32* src, local u32 *dst, 
u32 size) {
+  __builtin_amdgcn_global_load_lds(src, dst, size, /*offset=*/0, /*aux=*/0); 
// expected-error{{expression is not an integer constant expression}}
+  __builtin_amdgcn_global_load_lds(src, dst, /*size=*/5, /*offset=*/0, 
/*aux=*/0); // expected-error{{invalid size value}} expected-note {{size must 
be 1/2/4}}
+  __builtin_amdgcn_global_load_lds(src, dst, /*size=*/0, /*offset=*/0, 
/*aux=*/0); // expected-error{{invalid size value}} expected-note {{size must 
be 1/2/4}}

arsenm wrote:

Didn't add negative value test 

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


[clang] [llvm] [AMDGPU][Clang] Add check of size for __builtin_amdgcn_global_load_lds (PR #93064)

2024-05-23 Thread Matt Arsenault via cfe-commits


@@ -12385,4 +12385,8 @@ def err_acc_reduction_composite_type
 def err_acc_reduction_composite_member_type :Error<
 "OpenACC 'reduction' composite variable must not have non-scalar field">;
 def note_acc_reduction_composite_member_loc : Note<"invalid field is here">;
+
+// AMDGCN builtins diagnostics
+def err_amdgcn_global_load_lds_size_invalid_value : Error<"invalid size 
value">;
+def note_amdgcn_global_load_lds_size_valid_value : Note<"size must be 1/2/4">;

arsenm wrote:

Not sure what the message phrasing guidelines are here, but probably should 
spill out 1, 2, or 4 rather than using / 

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


[clang] [Analyzer][CFG] Correctly handle rebuilt default arg and default init expression (PR #91879)

2024-05-23 Thread via cfe-commits


@@ -1964,39 +1964,55 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode 
*Pred,
 case Stmt::CXXDefaultArgExprClass:
 case Stmt::CXXDefaultInitExprClass: {
   Bldr.takeNodes(Pred);
-  ExplodedNodeSet PreVisit;
-  getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this);
+  ExplodedNodeSet CheckedSet;
+  getCheckerManager().runCheckersForPreStmt(CheckedSet, Pred, S, *this);
 
   ExplodedNodeSet Tmp;
-  StmtNodeBuilder Bldr2(PreVisit, Tmp, *currBldrCtx);
+  StmtNodeBuilder Bldr2(CheckedSet, Tmp, *currBldrCtx);
 
-  const Expr *ArgE;
-  if (const auto *DefE = dyn_cast(S))
+  bool HasRewrittenInit = false;
+  const Expr *ArgE = nullptr;
+  if (const auto *DefE = dyn_cast(S)) {
 ArgE = DefE->getExpr();
-  else if (const auto *DefE = dyn_cast(S))
+HasRewrittenInit = DefE->hasRewrittenInit();
+  } else if (const auto *DefE = dyn_cast(S)) {
 ArgE = DefE->getExpr();
-  else
+HasRewrittenInit = DefE->hasRewrittenInit();
+  } else
 llvm_unreachable("unknown constant wrapper kind");
 
-  bool IsTemporary = false;
-  if (const auto *MTE = dyn_cast(ArgE)) {
-ArgE = MTE->getSubExpr();
-IsTemporary = true;
-  }
+  if (HasRewrittenInit) {
+for (auto *I : CheckedSet) {
+  ProgramStateRef state = (*I).getState();
+  const LocationContext *LCtx = (*I).getLocationContext();
+  SVal Val = state->getSVal(ArgE, LCtx);
+  state = state->BindExpr(S, LCtx, Val);
+  Bldr2.generateNode(S, I, state);

yronglin wrote:

done

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


  1   2   3   4   5   6   >