[clang] [clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (PR #73290)

2023-11-24 Thread Balázs Kéri via cfe-commits

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

I think it is better to add the import of AttrName to the attribute import code 
(function `Import(const Attr *FromAttr)` and what is called from it). Probably 
it works to add it to `AttrImporter::cloneAttr` and do it like `const 
IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());`.

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


[clang] dd0b3c2 - [clang][analyzer] Support `fprintf` in the SecuritySyntaxChecker (#73247)

2023-11-24 Thread via cfe-commits

Author: Ben Shi
Date: 2023-11-24T16:23:56+08:00
New Revision: dd0b3c2fa62786d9e1fd8d70cdcfe778c74c0a7d

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

LOG: [clang][analyzer] Support `fprintf` in the SecuritySyntaxChecker (#73247)

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
clang/test/Analysis/security-syntax-checks.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
index 1a88615f01697cb..dbba12bb4355c3a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
@@ -144,38 +144,39 @@ void WalkAST::VisitCallExpr(CallExpr *CE) {
 Name = Name.substr(10);
 
   // Set the evaluation function by switching on the callee name.
-  FnCheck evalFunction = llvm::StringSwitch(Name)
-.Case("bcmp", &WalkAST::checkCall_bcmp)
-.Case("bcopy", &WalkAST::checkCall_bcopy)
-.Case("bzero", &WalkAST::checkCall_bzero)
-.Case("gets", &WalkAST::checkCall_gets)
-.Case("getpw", &WalkAST::checkCall_getpw)
-.Case("mktemp", &WalkAST::checkCall_mktemp)
-.Case("mkstemp", &WalkAST::checkCall_mkstemp)
-.Case("mkdtemp", &WalkAST::checkCall_mkstemp)
-.Case("mkstemps", &WalkAST::checkCall_mkstemp)
-.Cases("strcpy", "__strcpy_chk", &WalkAST::checkCall_strcpy)
-.Cases("strcat", "__strcat_chk", &WalkAST::checkCall_strcat)
-.Cases("sprintf", "vsprintf", "scanf", "wscanf", "fscanf", "fwscanf",
-   "vscanf", "vwscanf", "vfscanf", "vfwscanf",
-   &WalkAST::checkDeprecatedOrUnsafeBufferHandling)
-.Cases("sscanf", "swscanf", "vsscanf", "vswscanf", "swprintf",
-   "snprintf", "vswprintf", "vsnprintf", "memcpy", "memmove",
-   &WalkAST::checkDeprecatedOrUnsafeBufferHandling)
-.Cases("strncpy", "strncat", "memset",
-   &WalkAST::checkDeprecatedOrUnsafeBufferHandling)
-.Case("drand48", &WalkAST::checkCall_rand)
-.Case("erand48", &WalkAST::checkCall_rand)
-.Case("jrand48", &WalkAST::checkCall_rand)
-.Case("lrand48", &WalkAST::checkCall_rand)
-.Case("mrand48", &WalkAST::checkCall_rand)
-.Case("nrand48", &WalkAST::checkCall_rand)
-.Case("lcong48", &WalkAST::checkCall_rand)
-.Case("rand", &WalkAST::checkCall_rand)
-.Case("rand_r", &WalkAST::checkCall_rand)
-.Case("random", &WalkAST::checkCall_random)
-.Case("vfork", &WalkAST::checkCall_vfork)
-.Default(nullptr);
+  FnCheck evalFunction =
+  llvm::StringSwitch(Name)
+  .Case("bcmp", &WalkAST::checkCall_bcmp)
+  .Case("bcopy", &WalkAST::checkCall_bcopy)
+  .Case("bzero", &WalkAST::checkCall_bzero)
+  .Case("gets", &WalkAST::checkCall_gets)
+  .Case("getpw", &WalkAST::checkCall_getpw)
+  .Case("mktemp", &WalkAST::checkCall_mktemp)
+  .Case("mkstemp", &WalkAST::checkCall_mkstemp)
+  .Case("mkdtemp", &WalkAST::checkCall_mkstemp)
+  .Case("mkstemps", &WalkAST::checkCall_mkstemp)
+  .Cases("strcpy", "__strcpy_chk", &WalkAST::checkCall_strcpy)
+  .Cases("strcat", "__strcat_chk", &WalkAST::checkCall_strcat)
+  .Cases("sprintf", "vsprintf", "scanf", "wscanf", "fscanf", "fwscanf",
+ "vscanf", "vwscanf", "vfscanf", "vfwscanf",
+ &WalkAST::checkDeprecatedOrUnsafeBufferHandling)
+  .Cases("sscanf", "swscanf", "vsscanf", "vswscanf", "swprintf",
+ "snprintf", "vswprintf", "vsnprintf", "memcpy", "memmove",
+ &WalkAST::checkDeprecatedOrUnsafeBufferHandling)
+  .Cases("strncpy", "strncat", "memset", "fprintf",
+ &WalkAST::checkDeprecatedOrUnsafeBufferHandling)
+  .Case("drand48", &WalkAST::checkCall_rand)
+  .Case("erand48", &WalkAST::checkCall_rand)
+  .Case("jrand48", &WalkAST::checkCall_rand)
+  .Case("lrand48", &WalkAST::checkCall_rand)
+  .Case("mrand48", &WalkAST::checkCall_rand)
+  .Case("nrand48", &WalkAST::checkCall_rand)
+  .Case("lcong48", &WalkAST::checkCall_rand)
+  .Case("rand", &WalkAST::checkCall_rand)
+  .Case("rand_r", &WalkAST::checkCall_rand)
+  .Case("random", &WalkAST::checkCall_random)
+  .Case("vfork", &WalkAST::checkCall_vfork)
+  .Default(nullptr);
 
   // If the callee isn't defined, it is not of security concern.
   // Check and evaluate the call.
@@ -737,10 +738,10 @@ void WalkAST::checkCall_strcat(const CallExpr *CE, const 
FunctionDecl *FD) {
 // Check: Any use of 'sprintf', 'vsprintf', 'scanf', 'wscanf', 'fscanf',
 //'fwscanf', 'vscanf', 'vwscanf', 'vfscanf', 'vfwscanf', 'sscanf',
 //'swscan

[clang] [clang][analyzer] Support `fprintf` in the SecuritySyntaxChecker (PR #73247)

2023-11-24 Thread Ben Shi via cfe-commits

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


[clang] [clang] Fixes compile error that double colon operator cannot resolve macro with parentheses. (PR #68618)

2023-11-24 Thread Yonggang Luo via cfe-commits

lygstate wrote:

@AaronBallman is this OK ?

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


[clang] [clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (PR #73290)

2023-11-24 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/73290

>From 20aab6095691f3de5568bc61c83427f380e28350 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Fri, 24 Nov 2023 13:55:45 +0800
Subject: [PATCH] [clang][ASTImporter] IdentifierInfo of Attribute should be
 set using ToASTContext

---
 clang/include/clang/Basic/AttributeCommonInfo.h |  1 +
 clang/lib/AST/ASTImporter.cpp   |  1 +
 clang/unittests/AST/ASTImporterTest.cpp | 13 +++--
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 3140d1a838afcec..018b92fdc11f559 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -177,6 +177,7 @@ class AttributeCommonInfo {
 IsRegularKeywordAttribute);
   }
   const IdentifierInfo *getAttrName() const { return AttrName; }
+  void setAttrName(const IdentifierInfo *AttrNameII) { AttrName = AttrNameII; }
   SourceLocation getLoc() const { return AttrRange.getBegin(); }
   SourceRange getRange() const { return AttrRange; }
   void setRange(SourceRange R) { AttrRange = R; }
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index c4e931e220f69b5..4bc18d7b54dbc5a 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -9063,6 +9063,7 @@ class AttrImporter {
 
 ToAttr = FromAttr->clone(Importer.getToContext());
 ToAttr->setRange(ToRange);
+ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
   }
 
   // Get the result of the previous import attempt (can be used only once).
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 5f4d8d040772cb1..2df92ad9d5985a4 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -12,6 +12,7 @@
 
 #include "clang/AST/RecordLayout.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "llvm/Support/SmallVectorMemoryBuffer.h"
 
 #include "clang/AST/DeclContextInternals.h"
@@ -7362,11 +7363,12 @@ struct ImportAttributes : public 
ASTImporterOptionSpecificTestBase {
   }
 
   template 
-  void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr) {
+  void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr,
+  TestLanguage Lang = Lang_CXX11) {
 static_assert(std::is_base_of::value, "AT should be an Attr");
 static_assert(std::is_base_of::value, "DT should be a Decl");
 
-Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cc");
+Decl *FromTU = getTuDecl(Code, Lang, "input.cc");
 DT *FromD =
 FirstDeclMatcher().match(FromTU, namedDecl(hasName("test")));
 ASSERT_TRUE(FromD);
@@ -7652,6 +7654,13 @@ TEST_P(ImportAttributes, ImportLocksExcluded) {
   checkImportVariadicArg(FromAttr->args(), ToAttr->args());
 }
 
+TEST_P(ImportAttributes, ImportC99NoThrowAttr) {
+  NoThrowAttr *FromAttr, *ToAttr;
+  importAttr("void test () __attribute__ ((__nothrow__));",
+   FromAttr, ToAttr, Lang_C99);
+  checkImported(FromAttr->getAttrName(), ToAttr->getAttrName());
+}
+
 template 
 auto ExtendWithOptions(const T &Values, const std::vector &Args) {
   auto Copy = Values;

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


[clang] [clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (PR #73290)

2023-11-24 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

> I think it is better to add the import of AttrName to the attribute import 
> code (function `Import(const Attr *FromAttr)` and what is called from it). 
> Probably it works to add it to `AttrImporter::cloneAttr` and do it like 
> `const IdentifierInfo *ToAttrName = 
> Importer.Import(FromAttr->getAttrName());`.

Fixed according to your guidance.

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


[clang] b98a594 - [clang][analyzer] Move `security.cert.env.InvalidPtr` out of `alpha` (#71912)

2023-11-24 Thread via cfe-commits

Author: Endre Fülöp
Date: 2023-11-24T10:02:56+01:00
New Revision: b98a594977f25e555822e5ceef457f69c73cce45

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

LOG: [clang][analyzer] Move `security.cert.env.InvalidPtr` out of `alpha` 
(#71912)

Thanks to recent improvements in #67663, InvalidPtr checker does not
emit any false positives on the following OS projects: memcached, tmux,
curl, twin, vim, openssl, sqlite, ffmpeg, postgres, tinyxml2, libwebm,
xerces, bitcoin, protobuf, qtbase, contour, acid, openrct2. (Before the
changes mentioned above, there were 27 reports, catching the `getenv`
invalidates previous `getenv` results cases. That strict behaviour is
disabled by default)

Added: 


Modified: 
clang/docs/analyzer/checkers.rst
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/test/Analysis/analyzer-config.c
clang/test/Analysis/cert/env31-c.c
clang/test/Analysis/cert/env34-c-cert-examples.c
clang/test/Analysis/cert/env34-c.c
clang/test/Analysis/invalid-ptr-checker.c

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index 40aa06724ccb75c..f7b48e64e324f00 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -755,6 +755,75 @@ security
 
 Security related checkers.
 
+.. _security-cert-env-InvalidPtr:
+
+security.cert.env.InvalidPtr
+""
+
+Corresponds to SEI CERT Rules `ENV31-C 
`_
 and `ENV34-C 
`_.
+
+* **ENV31-C**:
+  Rule is about the possible problem with ``main`` function's third argument, 
environment pointer,
+  "envp". When environment array is modified using some modification function
+  such as ``putenv``, ``setenv`` or others, It may happen that memory is 
reallocated,
+  however "envp" is not updated to reflect the changes and points to old memory
+  region.
+
+* **ENV34-C**:
+  Some functions return a pointer to a statically allocated buffer.
+  Consequently, subsequent call of these functions will invalidate previous
+  pointer. These functions include: ``getenv``, ``localeconv``, ``asctime``, 
``setlocale``, ``strerror``
+
+.. code-block:: c
+
+  int main(int argc, const char *argv[], const char *envp[]) {
+if (setenv("MY_NEW_VAR", "new_value", 1) != 0) {
+  // setenv call may invalidate 'envp'
+  /* Handle error */
+}
+if (envp != NULL) {
+  for (size_t i = 0; envp[i] != NULL; ++i) {
+puts(envp[i]);
+// envp may no longer point to the current environment
+// this program has unanticipated behavior, since envp
+// does not reflect changes made by setenv function.
+  }
+}
+return 0;
+  }
+
+  void previous_call_invalidation() {
+char *p, *pp;
+
+p = getenv("VAR");
+setenv("SOMEVAR", "VALUE", /*overwrite = */1);
+// call to 'setenv' may invalidate p
+
+*p;
+// dereferencing invalid pointer
+  }
+
+
+The ``InvalidatingGetEnv`` option is available for treating ``getenv`` calls as
+invalidating. When enabled, the checker issues a warning if ``getenv`` is 
called
+multiple times and their results are used without first creating a copy.
+This level of strictness might be considered overly pedantic for the commonly
+used ``getenv`` implementations.
+
+To enable this option, use:
+``-analyzer-config security.cert.env.InvalidPtr:InvalidatingGetEnv=true``.
+
+By default, this option is set to *false*.
+
+When this option is enabled, warnings will be generated for scenarios like the
+following:
+
+.. code-block:: c
+
+  char* p = getenv("VAR");
+  char* pp = getenv("VAR2"); // assumes this call can invalidate `env`
+  strlen(p); // warns about accessing invalid ptr
+
 .. _security-FloatLoopCounter:
 
 security.FloatLoopCounter (C)
@@ -2549,75 +2618,6 @@ alpha.security.cert.env
 
 SEI CERT checkers of `Environment C coding rules 
`_.
 
-.. _alpha-security-cert-env-InvalidPtr:
-
-alpha.security.cert.env.InvalidPtr
-""
-
-Corresponds to SEI CERT Rules ENV31-C and ENV34-C.
-
-ENV31-C:
-Rule is about the possible problem with `main` function's third argument, 
environment pointer,
-"envp". When environment array is modified using some modification function
-such as putenv, setenv or others, It may happen that memory is reallocated,
-however "envp" is not updated to reflect the changes and points to old memory
-region.
-
-ENV34-C:
-Some functions return a pointer to a statically allocated buffer.
-Consequently, subsequent

[clang] [clang][analyzer] Move `security.cert.env.InvalidPtr` out of `alpha` (PR #71912)

2023-11-24 Thread Endre Fülöp via cfe-commits

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


[clang] [clang] Add missing LinkageSpec case to getCursorKindForDecl (PR #72401)

2023-11-24 Thread Sebastian Poeplau via cfe-commits

https://github.com/sebastianpoeplau updated 
https://github.com/llvm/llvm-project/pull/72401

>From df8bfc2cdb1488d3ad037ea26bad48e658e5d3c8 Mon Sep 17 00:00:00 2001
From: Matthieu Eyraud 
Date: Wed, 17 Aug 2022 19:22:53 +0200
Subject: [PATCH] [clang] Add missing LinkageSpec case to getCursorKindForDecl

The LinkageSpec case was omitted, and there is a declared CXCursor_Kind
for it. Adapt the testsuite drivers to print mangled names for
declarations with extern linkage. Also update the test baseline for the
recursive-cxx-member-calls.cpp test.
---
 clang/docs/ReleaseNotes.rst |  2 ++
 clang/lib/Sema/SemaCodeComplete.cpp |  3 +++
 clang/test/Index/recursive-cxx-member-calls.cpp | 10 +-
 clang/tools/c-index-test/c-index-test.c |  4 
 4 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ed1a978b5382d71..d321ec694c59914 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -861,6 +861,8 @@ libclang
 
 
 - Exposed arguments of ``clang::annotate``.
+- ``clang::getCursorKindForDecl`` now recognizes linkage specifications such as
+  ``extern "C"`` and reports them as ``CXCursor_LinkageSpec``.
 
 Static Analyzer
 ---
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 3355336d8c2c816..6169144ef1c2d48 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -4165,6 +4165,9 @@ CXCursorKind clang::getCursorKindForDecl(const Decl *D) {
   case Decl::Concept:
 return CXCursor_ConceptDecl;
 
+  case Decl::LinkageSpec:
+return CXCursor_LinkageSpec;
+
   default:
 if (const auto *TD = dyn_cast(D)) {
   switch (TD->getTagKind()) {
diff --git a/clang/test/Index/recursive-cxx-member-calls.cpp 
b/clang/test/Index/recursive-cxx-member-calls.cpp
index 09f3f414194c565..be908c506e74769 100644
--- a/clang/test/Index/recursive-cxx-member-calls.cpp
+++ b/clang/test/Index/recursive-cxx-member-calls.cpp
@@ -216,9 +216,9 @@ AttributeList::Kind AttributeList::getKind(const 
IdentifierInfo * Name) {
 // CHECK-tokens: Punctuation: "}" [4:63 - 4:64] ClassTemplate=pair:4:44 
(Definition)
 // CHECK-tokens: Punctuation: ";" [4:64 - 4:65] Namespace=std:3:11 (Definition)
 // CHECK-tokens: Punctuation: "}" [5:1 - 5:2] Namespace=std:3:11 (Definition)
-// CHECK-tokens: Keyword: "extern" [6:1 - 6:7]
-// CHECK-tokens: Literal: ""C"" [6:8 - 6:11] UnexposedDecl=:6:8 (Definition)
-// CHECK-tokens: Punctuation: "{" [6:12 - 6:13] UnexposedDecl=:6:8 (Definition)
+// CHECK-tokens: Keyword: "extern" [6:1 - 6:7] LinkageSpec=:6:8 (Definition)
+// CHECK-tokens: Literal: ""C"" [6:8 - 6:11] LinkageSpec=:6:8 (Definition)
+// CHECK-tokens: Punctuation: "{" [6:12 - 6:13] LinkageSpec=:6:8 (Definition)
 // CHECK-tokens: Keyword: "int" [7:3 - 7:6] FunctionDecl=memcmp:7:7
 // CHECK-tokens: Identifier: "memcmp" [7:7 - 7:13] FunctionDecl=memcmp:7:7
 // CHECK-tokens: Punctuation: "(" [7:13 - 7:14] FunctionDecl=memcmp:7:7
@@ -232,7 +232,7 @@ AttributeList::Kind AttributeList::getKind(const 
IdentifierInfo * Name) {
 // CHECK-tokens: Punctuation: "," [7:40 - 7:41] FunctionDecl=memcmp:7:7
 // CHECK-tokens: Identifier: "size_t" [7:42 - 7:48] TypeRef=size_t:2:25
 // CHECK-tokens: Punctuation: ")" [7:48 - 7:49] FunctionDecl=memcmp:7:7
-// CHECK-tokens: Punctuation: ";" [7:49 - 7:50] UnexposedDecl=:6:8 (Definition)
+// CHECK-tokens: Punctuation: ";" [7:49 - 7:50] LinkageSpec=:6:8 (Definition)
 // CHECK-tokens: Identifier: "size_t" [8:3 - 8:9] TypeRef=size_t:2:25
 // CHECK-tokens: Identifier: "strlen" [8:10 - 8:16] FunctionDecl=strlen:8:10
 // CHECK-tokens: Punctuation: "(" [8:16 - 8:17] FunctionDecl=strlen:8:10
@@ -1532,7 +1532,7 @@ AttributeList::Kind AttributeList::getKind(const 
IdentifierInfo * Name) {
 // CHECK: 4:20: TemplateTypeParameter=_T1:4:20 (Definition) Extent=[4:14 - 
4:23]
 // CHECK: 4:31: TemplateTypeParameter=_T2:4:31 (Definition) Extent=[4:25 - 
4:34]
 // CHECK: 4:55: FieldDecl=second:4:55 (Definition) Extent=[4:51 - 4:61]
-// CHECK: 6:8: UnexposedDecl=:6:8 (Definition) Extent=[6:1 - 9:2]
+// CHECK: 6:8: LinkageSpec=:6:8 (Definition) Extent=[6:1 - 9:2]
 // CHECK: 7:7: FunctionDecl=memcmp:7:7 Extent=[7:3 - 7:49]
 // CHECK: 7:26: ParmDecl=:7:26 (Definition) Extent=[7:14 - 7:26]
 // CHECK: 7:40: ParmDecl=:7:40 (Definition) Extent=[7:28 - 7:40]
diff --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 9d66a22f3b43b55..2c0c9cb8eb5e42f 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -1838,6 +1838,8 @@ static enum CXChildVisitResult PrintMangledName(CXCursor 
cursor, CXCursor p,
   CXString MangledName;
   if (clang_isUnexposed(clang_getCursorKind(cursor)))
 return CXChildVisit_Recurse;
+  if (clang_getCursorKind(cursor) == CXCursor_LinkageSpec)
+return CXChildVisit_Recurse;
   PrintCursor(cursor, NULL)

[clang] [clang] Add missing LinkageSpec case to getCursorKindForDecl (PR #72401)

2023-11-24 Thread Sebastian Poeplau via cfe-commits

sebastianpoeplau wrote:

I've added an entry to the release notes.

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


[clang] [clang] Classify vector types in __builtin_classify_type (PR #73299)

2023-11-24 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/73299

None

>From 6cfc5a63c2f8c3346fa3272c826074fa74da5e3b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 24 Nov 2023 10:09:12 +0100
Subject: [PATCH] [clang] Classify vector types in __builtin_classify_type

---
 clang/docs/ReleaseNotes.rst  | 4 ++--
 clang/lib/AST/ExprConstShared.h  | 3 ++-
 clang/lib/AST/ExprConstant.cpp   | 8 +---
 clang/test/Sema/builtin-classify-type.c  | 6 +++---
 clang/test/SemaCXX/builtin-classify-type.cpp | 6 +++---
 5 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7e2c990d03e7f27..362ce410356719b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -225,8 +225,8 @@ Non-comprehensive list of changes in this release
   determined at runtime.
 * The ``__datasizeof`` keyword has been added. It is similar to ``sizeof``
   except that it returns the size of a type ignoring tail padding.
-* ``__builtin_classify_type()`` now classifies ``_BitInt`` values as the 
return value ``18``,
-  to match GCC 14's behavior.
+* ``__builtin_classify_type()`` now classifies ``_BitInt`` values as the 
return value ``18``
+  and vector types as return value ``19``, to match GCC 14's behavior.
 
 New Compiler Flags
 --
diff --git a/clang/lib/AST/ExprConstShared.h b/clang/lib/AST/ExprConstShared.h
index 53ec9c6c7a3ef2e..a97eac85abc69e9 100644
--- a/clang/lib/AST/ExprConstShared.h
+++ b/clang/lib/AST/ExprConstShared.h
@@ -49,7 +49,8 @@ enum class GCCTypeClass {
   // literals.
   // Lang = 16,
   // OpaqueType = 17,
-  BitInt = 18
+  BitInt = 18,
+  Vector = 19
 };
 
 GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 3a41e9718bb5875..16697e5f076a8f8 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11615,16 +11615,18 @@ GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
 return EvaluateBuiltinClassifyType(
 CanTy->castAs()->getValueType(), LangOpts);
 
-  case Type::BlockPointer:
   case Type::Vector:
   case Type::ExtVector:
+return GCCTypeClass::Vector;
+
+  case Type::BlockPointer:
   case Type::ConstantMatrix:
   case Type::ObjCObject:
   case Type::ObjCInterface:
   case Type::ObjCObjectPointer:
   case Type::Pipe:
-// GCC classifies vectors as None. We follow its lead and classify all
-// other types that don't fit into the regular classification the same way.
+// Classify all other types that don't fit into the regular
+// classification the same way.
 return GCCTypeClass::None;
 
   case Type::BitInt:
diff --git a/clang/test/Sema/builtin-classify-type.c 
b/clang/test/Sema/builtin-classify-type.c
index 50f517fcbc852a2..21b212faeedcd81 100644
--- a/clang/test/Sema/builtin-classify-type.c
+++ b/clang/test/Sema/builtin-classify-type.c
@@ -13,7 +13,7 @@ enum gcc_type_class {
   record_type_class, union_type_class,
   array_type_class, string_type_class,
   lang_type_class, opaque_type_class,
-  bitint_type_class
+  bitint_type_class, vector_type_class
 };
 
 void foo(void) {
@@ -67,8 +67,8 @@ void foo(void) {
   int a11[__builtin_classify_type(arr) == pointer_type_class ? 1 : -1];
   int a12[__builtin_classify_type("abc") == pointer_type_class ? 1 : -1];
   int a13[__builtin_classify_type(block) == no_type_class ? 1 : -1];
-  int a14[__builtin_classify_type(vec) == no_type_class ? 1 : -1];
-  int a15[__builtin_classify_type(evec) == no_type_class ? 1 : -1];
+  int a14[__builtin_classify_type(vec) == vector_type_class ? 1 : -1];
+  int a15[__builtin_classify_type(evec) == vector_type_class ? 1 : -1];
   int a16[__builtin_classify_type(atomic_i) == integer_type_class ? 1 : -1];
   int a17[__builtin_classify_type(atomic_d) == real_type_class ? 1 : -1];
   int a18[__builtin_classify_type(complex_i) == complex_type_class ? 1 : -1];
diff --git a/clang/test/SemaCXX/builtin-classify-type.cpp 
b/clang/test/SemaCXX/builtin-classify-type.cpp
index 651dc8b24bf9483..6bae9cd6b1dc0dd 100644
--- a/clang/test/SemaCXX/builtin-classify-type.cpp
+++ b/clang/test/SemaCXX/builtin-classify-type.cpp
@@ -13,7 +13,7 @@ enum gcc_type_class {
   record_type_class, union_type_class,
   array_type_class, string_type_class,
   lang_type_class, opaque_type_class,
-  bitint_type_class
+  bitint_type_class, vector_type_class
 };
 
 class cl {
@@ -62,8 +62,8 @@ void foo() {
   int a14[__builtin_classify_type(arr) == pointer_type_class ? 1 : -1];
   int a15[__builtin_classify_type("abc") == pointer_type_class ? 1 : -1];
   int a16[__builtin_classify_type(block) == no_type_class ? 1 : -1];
-  int a17[__builtin_classify_type(vec) == no_type_class ? 1 : -1];
-  int a18[__builtin_classify_type(evec) == no_type_class ? 1 : -1];
+  int a17[__builtin_classify_type(vec) == vector_type_class ? 1 : -1];
+  int a18[__built

[clang] [clang] Classify vector types in __builtin_classify_type (PR #73299)

2023-11-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes



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


5 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2-2) 
- (modified) clang/lib/AST/ExprConstShared.h (+2-1) 
- (modified) clang/lib/AST/ExprConstant.cpp (+5-3) 
- (modified) clang/test/Sema/builtin-classify-type.c (+3-3) 
- (modified) clang/test/SemaCXX/builtin-classify-type.cpp (+3-3) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7e2c990d03e7f27..362ce410356719b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -225,8 +225,8 @@ Non-comprehensive list of changes in this release
   determined at runtime.
 * The ``__datasizeof`` keyword has been added. It is similar to ``sizeof``
   except that it returns the size of a type ignoring tail padding.
-* ``__builtin_classify_type()`` now classifies ``_BitInt`` values as the 
return value ``18``,
-  to match GCC 14's behavior.
+* ``__builtin_classify_type()`` now classifies ``_BitInt`` values as the 
return value ``18``
+  and vector types as return value ``19``, to match GCC 14's behavior.
 
 New Compiler Flags
 --
diff --git a/clang/lib/AST/ExprConstShared.h b/clang/lib/AST/ExprConstShared.h
index 53ec9c6c7a3ef2e..a97eac85abc69e9 100644
--- a/clang/lib/AST/ExprConstShared.h
+++ b/clang/lib/AST/ExprConstShared.h
@@ -49,7 +49,8 @@ enum class GCCTypeClass {
   // literals.
   // Lang = 16,
   // OpaqueType = 17,
-  BitInt = 18
+  BitInt = 18,
+  Vector = 19
 };
 
 GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 3a41e9718bb5875..16697e5f076a8f8 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11615,16 +11615,18 @@ GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
 return EvaluateBuiltinClassifyType(
 CanTy->castAs()->getValueType(), LangOpts);
 
-  case Type::BlockPointer:
   case Type::Vector:
   case Type::ExtVector:
+return GCCTypeClass::Vector;
+
+  case Type::BlockPointer:
   case Type::ConstantMatrix:
   case Type::ObjCObject:
   case Type::ObjCInterface:
   case Type::ObjCObjectPointer:
   case Type::Pipe:
-// GCC classifies vectors as None. We follow its lead and classify all
-// other types that don't fit into the regular classification the same way.
+// Classify all other types that don't fit into the regular
+// classification the same way.
 return GCCTypeClass::None;
 
   case Type::BitInt:
diff --git a/clang/test/Sema/builtin-classify-type.c 
b/clang/test/Sema/builtin-classify-type.c
index 50f517fcbc852a2..21b212faeedcd81 100644
--- a/clang/test/Sema/builtin-classify-type.c
+++ b/clang/test/Sema/builtin-classify-type.c
@@ -13,7 +13,7 @@ enum gcc_type_class {
   record_type_class, union_type_class,
   array_type_class, string_type_class,
   lang_type_class, opaque_type_class,
-  bitint_type_class
+  bitint_type_class, vector_type_class
 };
 
 void foo(void) {
@@ -67,8 +67,8 @@ void foo(void) {
   int a11[__builtin_classify_type(arr) == pointer_type_class ? 1 : -1];
   int a12[__builtin_classify_type("abc") == pointer_type_class ? 1 : -1];
   int a13[__builtin_classify_type(block) == no_type_class ? 1 : -1];
-  int a14[__builtin_classify_type(vec) == no_type_class ? 1 : -1];
-  int a15[__builtin_classify_type(evec) == no_type_class ? 1 : -1];
+  int a14[__builtin_classify_type(vec) == vector_type_class ? 1 : -1];
+  int a15[__builtin_classify_type(evec) == vector_type_class ? 1 : -1];
   int a16[__builtin_classify_type(atomic_i) == integer_type_class ? 1 : -1];
   int a17[__builtin_classify_type(atomic_d) == real_type_class ? 1 : -1];
   int a18[__builtin_classify_type(complex_i) == complex_type_class ? 1 : -1];
diff --git a/clang/test/SemaCXX/builtin-classify-type.cpp 
b/clang/test/SemaCXX/builtin-classify-type.cpp
index 651dc8b24bf9483..6bae9cd6b1dc0dd 100644
--- a/clang/test/SemaCXX/builtin-classify-type.cpp
+++ b/clang/test/SemaCXX/builtin-classify-type.cpp
@@ -13,7 +13,7 @@ enum gcc_type_class {
   record_type_class, union_type_class,
   array_type_class, string_type_class,
   lang_type_class, opaque_type_class,
-  bitint_type_class
+  bitint_type_class, vector_type_class
 };
 
 class cl {
@@ -62,8 +62,8 @@ void foo() {
   int a14[__builtin_classify_type(arr) == pointer_type_class ? 1 : -1];
   int a15[__builtin_classify_type("abc") == pointer_type_class ? 1 : -1];
   int a16[__builtin_classify_type(block) == no_type_class ? 1 : -1];
-  int a17[__builtin_classify_type(vec) == no_type_class ? 1 : -1];
-  int a18[__builtin_classify_type(evec) == no_type_class ? 1 : -1];
+  int a17[__builtin_classify_type(vec) == vector_type_class ? 1 : -1];
+  int a18[__builtin_classify_type(evec) == vector_type_class ? 1 : -1];
   int a19[__builtin_classify_type(atomic_i) == integer_type_class ? 1 : -1];
   int a20[__builtin_classify_type(atomic_

[clang] [clang] Print static_assert values of arithmetic binary operators (PR #71671)

2023-11-24 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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

>From 0724e6cdf2cc532a7b29eff9162265b6845ffef4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 8 Nov 2023 13:32:41 +0100
Subject: [PATCH 1/3] [clang] Print static_assert values of arithmetic binary
 operators

These are actually quite useful to print.
---
 clang/lib/Sema/SemaDeclCXX.cpp |  8 
 clang/test/SemaCXX/complex-folding.cpp | 27 +-
 clang/test/SemaCXX/static-assert.cpp   | 10 ++
 3 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 3688192e6cbe5c5..91c9a82bcfa0edc 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17218,10 +17218,10 @@ static bool UsefulToPrintExpr(const Expr *E) {
   if (const auto *UnaryOp = dyn_cast(E))
 return UsefulToPrintExpr(UnaryOp->getSubExpr());
 
-  // Ignore nested binary operators. This could be a FIXME for improvements
-  // to the diagnostics in the future.
-  if (isa(E))
-return false;
+  // Only print nested arithmetic operators.
+  if (const auto *BO = dyn_cast(E))
+return (BO->isShiftOp() || BO->isAdditiveOp() || BO->isMultiplicativeOp() 
||
+BO->isBitwiseOp());
 
   return true;
 }
diff --git a/clang/test/SemaCXX/complex-folding.cpp 
b/clang/test/SemaCXX/complex-folding.cpp
index 8c56cf0e5d984b0..054f159e9ce0dd2 100644
--- a/clang/test/SemaCXX/complex-folding.cpp
+++ b/clang/test/SemaCXX/complex-folding.cpp
@@ -3,7 +3,8 @@
 // Test the constant folding of builtin complex numbers.
 
 static_assert((0.0 + 0.0j) == (0.0 + 0.0j));
-static_assert((0.0 + 0.0j) != (0.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((0.0 + 0.0j) != (0.0 + 0.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 
 static_assert((0.0 + 0.0j) == 0.0);
 static_assert(0.0 == (0.0 + 0.0j));
@@ -14,21 +15,29 @@ static_assert(0.0 != 1.0j);
 
 // Walk around the complex plane stepping between angular differences and
 // equality.
-static_assert((1.0 + 0.0j) == (0.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((1.0 + 0.0j) == (0.0 + 0.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((1.0 + 0.0j) == (1.0 + 0.0j));
-static_assert((1.0 + 1.0j) == (1.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((1.0 + 1.0j) == (1.0 + 0.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((1.0 + 1.0j) == (1.0 + 1.0j));
-static_assert((0.0 + 1.0j) == (1.0 + 1.0j)); // expected-error {{static 
assertion}}
+static_assert((0.0 + 1.0j) == (1.0 + 1.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((0.0 + 1.0j) == (0.0 + 1.0j));
-static_assert((-1.0 + 1.0j) == (0.0 + 1.0j)); // expected-error {{static 
assertion}}
+static_assert((-1.0 + 1.0j) == (0.0 + 1.0j)); // expected-error {{static 
assertion}} \
+  // expected-note {{evaluates to}}
 static_assert((-1.0 + 1.0j) == (-1.0 + 1.0j));
-static_assert((-1.0 + 0.0j) == (-1.0 + 1.0j)); // expected-error {{static 
assertion}}
+static_assert((-1.0 + 0.0j) == (-1.0 + 1.0j)); // expected-error {{static 
assertion}} \
+   // expected-note {{evaluates 
to}}
 static_assert((-1.0 + 0.0j) == (-1.0 + 0.0j));
-static_assert((-1.0 - 1.0j) == (-1.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((-1.0 - 1.0j) == (-1.0 + 0.0j)); // expected-error {{static 
assertion}} \
+   // expected-note {{evaluates 
to}}
 static_assert((-1.0 - 1.0j) == (-1.0 - 1.0j));
-static_assert((0.0 - 1.0j) == (-1.0 - 1.0j)); // expected-error {{static 
assertion}}
+static_assert((0.0 - 1.0j) == (-1.0 - 1.0j)); // expected-error {{static 
assertion}} \
+  // expected-note {{evaluates to}}
 static_assert((0.0 - 1.0j) == (0.0 - 1.0j));
-static_assert((1.0 - 1.0j) == (0.0 - 1.0j)); // expected-error {{static 
assertion}}
+static_assert((1.0 - 1.0j) == (0.0 - 1.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((1.0 - 1.0j) == (1.0 - 1.0j));
 
 // Test basic mathematical folding of both complex and real operands.
diff --git a/clang/test/SemaCXX/static-assert.cpp 
b/clang/test/SemaCXX/static-assert.cpp
index 4200d821339edeb..6e1701602ae30cf 100644
--- a/clang/test/SemaCXX/static-assert.cpp
+++ b/clang/test/SemaCXX/static-assert.cpp
@@ -351,4 +351,14 @@ namespace Diagnost

[clang] 25b5e5c - Update links in AttrDocs.td for coro_lifetimebound

2023-11-24 Thread via cfe-commits

Author: Utkarsh Saxena
Date: 2023-11-24T10:18:24+01:00
New Revision: 25b5e5c4e9a39a86ca3c1a05ad6eae33771ab052

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

LOG: Update links in AttrDocs.td for coro_lifetimebound

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index c74ec2bc1218aa6..cfd806aa3a029be 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7585,11 +7585,11 @@ def CoroLifetimeBoundDoc : Documentation {
   let Category = DocCatDecl;
   let Content = [{
 The ``[[clang::coro_lifetimebound]]`` is a class attribute which can be applied
-to a `coroutine return type (CRT) 
` _ (i.e.
+to a `coroutine return type (`CRT`_) (i.e.
 it should also be annotated with ``[[clang::coro_return_type]]``).
 
-All parameters of a function are considered to be lifetime bound. See 
documentation
-of ``[[clang::lifetimebound]]`` for more `details 
 _`.
+All parameters of a function are considered to be lifetime bound. See 
`documentation`_
+of ``[[clang::lifetimebound]]`` for more details.
 if the function returns a coroutine return type (CRT) annotated with 
``[[clang::coro_lifetimebound]]``.
 
 Reference parameters of a coroutine are susceptible to capturing references to 
temporaries or local variables.
@@ -7606,9 +7606,8 @@ For example,
 return coro(a);
   }
 
-`Lifetime bound 
 _` static 
analysis
-can be used to detect such instances when coroutines capture references which 
may die earlier than the
-coroutine frame itself. In the above example, if the CRT `task` is annotated 
with
+Lifetime bound static analysis can be used to detect such instances when 
coroutines capture references
+which may die earlier than the coroutine frame itself. In the above example, 
if the CRT `task` is annotated with
 ``[[clang::coro_lifetimebound]]``, then lifetime bound analysis would detect 
capturing reference to
 temporaries or return address of a local variable.
 
@@ -7635,5 +7634,8 @@ Both coroutines and coroutine wrappers are part of this 
analysis.
   [[clang::coro_wrapper]] Task stack_reference(int a) {
 return coro(a); // warning: returning address of stack variable `a`.
   }
+
+.. _`documentation`: 
https://clang.llvm.org/docs/AttributeReference.html#lifetimebound
+.. _`CRT`: https://clang.llvm.org/docs/AttributeReference.html#coro-return-type
 }];
 }



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


[clang] 59edb43 - clang/APINotes: squelch a -Wparantheses warning (NFC)

2023-11-24 Thread Ramkumar Ramachandra via cfe-commits

Author: Ramkumar Ramachandra
Date: 2023-11-24T09:43:37Z
New Revision: 59edb432256064ee4f66c3a30fd4875030c5166b

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

LOG: clang/APINotes: squelch a -Wparantheses warning (NFC)

Added: 


Modified: 
clang/include/clang/APINotes/APINotesManager.h

Removed: 




diff  --git a/clang/include/clang/APINotes/APINotesManager.h 
b/clang/include/clang/APINotes/APINotesManager.h
index 823b52ed28b5981..c19082fdb597d84 100644
--- a/clang/include/clang/APINotes/APINotesManager.h
+++ b/clang/include/clang/APINotes/APINotesManager.h
@@ -159,7 +159,7 @@ class APINotesManager {
   ArrayRef getCurrentModuleReaders() const {
 bool HasPublic = CurrentModuleReaders[ReaderKind::Public];
 bool HasPrivate = CurrentModuleReaders[ReaderKind::Private];
-assert(!HasPrivate || HasPublic && "private module requires public 
module");
+assert(!HasPrivate || (HasPublic && "private module requires public 
module"));
 if (!HasPrivate && !HasPublic)
   return {};
 return ArrayRef(CurrentModuleReaders).slice(0, HasPrivate ? 2 : 1);



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


[clang] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2 (PR #72107)

2023-11-24 Thread via cfe-commits


@@ -34,20 +34,37 @@ using llvm::formatv;
 namespace {
 enum OOB_Kind { OOB_Precedes, OOB_Exceeds, OOB_Taint };
 
-class ArrayBoundCheckerV2 :
-public Checker {
+struct Messages {
+  std::string Short, Full;
+};
+
+class ArrayBoundCheckerV2 : public Checker,
+   check::PostStmt,
+   check::PostStmt> {
   BugType BT{this, "Out-of-bound access"};
   BugType TaintBT{this, "Out-of-bound access", categories::TaintedData};
 
+  void performCheck(const Expr *E, CheckerContext &C) const;
+
   void reportOOB(CheckerContext &C, ProgramStateRef ErrorState, OOB_Kind Kind,
- NonLoc Offset, std::string RegName, std::string Msg) const;
+ NonLoc Offset, Messages Msgs) const;
 
   static bool isFromCtypeMacro(const Stmt *S, ASTContext &AC);
 
 public:
-  void checkLocation(SVal l, bool isLoad, const Stmt *S,
- CheckerContext &C) const;
+  void checkPostStmt(const ArraySubscriptExpr *E, CheckerContext &C) const {

DonatNagyE wrote:

Good point, I don't think that there was any concrete reason for using 
`PostStmt`, so I'll switch to `PreStmt`.

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


[clang] [llvm] [SME2] Add LUTI2 and LUTI4 single Builtins and Intrinsics (PR #73304)

2023-11-24 Thread Matthew Devereau via cfe-commits

https://github.com/MDevereau created 
https://github.com/llvm/llvm-project/pull/73304

See https://github.com/ARM-software/acle/pull/217

Patch by: Hassnaa Hamdi 

>From bca5297fe897edf6faf51ffde3e8fe1baa26b148 Mon Sep 17 00:00:00 2001
From: Matt Devereau 
Date: Mon, 20 Nov 2023 15:50:28 +
Subject: [PATCH] [SME2] Add LUTI2 and LUTI4 single Builtins and Intrinsics

See https://github.com/ARM-software/acle/pull/217

Patch by: Hassnaa Hamdi 
---
 clang/include/clang/Basic/arm_sme.td  |  8 ++
 .../acle_sme2_luti2_lane_zt.c | 96 +++
 .../acle_sme2_luti4_lane_zt.c | 95 ++
 .../aarch64-sme2-intrinsics/acle_sme2_imm.cpp | 33 +++
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  9 ++
 .../Target/AArch64/AArch64ISelDAGToDAG.cpp|  7 +-
 .../Target/AArch64/AArch64RegisterInfo.cpp|  6 ++
 .../lib/Target/AArch64/AArch64SMEInstrInfo.td |  4 +-
 llvm/lib/Target/AArch64/SMEInstrFormats.td| 33 +--
 .../AArch64/sme2-intrinsics-luti2-lane.ll | 35 +++
 .../AArch64/sme2-intrinsics-luti4-lane.ll | 35 +++
 11 files changed, 349 insertions(+), 12 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt.c
 create mode 100644 clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_imm.cpp
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-luti2-lane.ll
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-luti4-lane.ll

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b5655afdf419ecf..1174e30cb0885e1 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,3 +298,11 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// lookup table expand one register
+//
+let TargetGuard = "sme2" in {
+  def SVLUTI2_LANE_ZT : Inst<"svluti2_lane_zt[_{d}]", "didi", "cUcsUsiUi", 
MergeNone, "aarch64_sme_luti2_lane_zt", [IsStreaming, IsSharedZA, 
IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_15>]>;
+  def SVLUTI4_LANE_ZT : Inst<"svluti4_lane_zt[_{d}]", "didi", "cUcsUsiUi", 
MergeNone, "aarch64_sme_luti4_lane_zt", [IsStreaming, IsSharedZA, 
IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_7>]>;
+}
diff --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c
new file mode 100644
index 000..ebabbfc815c1dfe
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c
@@ -0,0 +1,96 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -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-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+
+// CHECK-LABEL: @test_svluti2_lane_zt_u8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sme.luti2.lane.zt.nxv16i8(i32 0,  [[ZN:%.*]], 
i32 2)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z23test_svluti2_lane_zt_u8u11__SVUint8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sme.luti2.lane.zt.nxv16i8(i32 0,  [[ZN:%.*]], 
i32 2)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svuint8_t test_svluti2_lane_zt_u8(svuint8_t zn) __arm_streaming 
__arm_shared_za __arm_preserves_za {
+  return svluti2_lane_zt_u8(0, zn, 2);
+}
+
+
+// CHECK-LABEL: @test_svluti2_lane_zt_s8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sme.luti2.lane.zt.nxv16i8(i32 0,  [[ZN:%.*]], 
i32 2)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z23test_svluti2_lane_zt_s8u10__SVInt8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sme.luti2.lane.zt.nxv16i8(i32 0,  [[ZN:%.*]], 
i32 2)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svint8_t test_svluti2_lane_zt_s8(svint8_t zn) __arm_streaming __arm_shared_za 
__arm_preserves_za {
+  return svluti2_lane_zt_s8(0, zn, 2);
+}
+
+// CHECK-LABEL: @test_svluti2_lane_zt_u16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sme.luti2.lane.zt.nxv8i16(i32 0,  [[ZN:%.*]], 
i32 2)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z24test_svluti2_lane_zt_u16u12__SVUint16_

[clang] [llvm] [SME2] Add LUTI2 and LUTI4 single Builtins and Intrinsics (PR #73304)

2023-11-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-aarch64

Author: Matthew Devereau (MDevereau)


Changes

See https://github.com/ARM-software/acle/pull/217

Patch by: Hassnaa Hamdi 

---

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


11 Files Affected:

- (modified) clang/include/clang/Basic/arm_sme.td (+8) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c 
(+96) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt.c 
(+95) 
- (added) clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_imm.cpp (+33) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+9) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp (+6-1) 
- (modified) llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp (+6) 
- (modified) llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td (+2-2) 
- (modified) llvm/lib/Target/AArch64/SMEInstrFormats.td (+24-9) 
- (added) llvm/test/CodeGen/AArch64/sme2-intrinsics-luti2-lane.ll (+35) 
- (added) llvm/test/CodeGen/AArch64/sme2-intrinsics-luti4-lane.ll (+35) 


``diff
diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b5655afdf419ecf..1174e30cb0885e1 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,3 +298,11 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// lookup table expand one register
+//
+let TargetGuard = "sme2" in {
+  def SVLUTI2_LANE_ZT : Inst<"svluti2_lane_zt[_{d}]", "didi", "cUcsUsiUi", 
MergeNone, "aarch64_sme_luti2_lane_zt", [IsStreaming, IsSharedZA, 
IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_15>]>;
+  def SVLUTI4_LANE_ZT : Inst<"svluti4_lane_zt[_{d}]", "didi", "cUcsUsiUi", 
MergeNone, "aarch64_sme_luti4_lane_zt", [IsStreaming, IsSharedZA, 
IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_7>]>;
+}
diff --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c
new file mode 100644
index 000..ebabbfc815c1dfe
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c
@@ -0,0 +1,96 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -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-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+
+// CHECK-LABEL: @test_svluti2_lane_zt_u8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sme.luti2.lane.zt.nxv16i8(i32 0,  [[ZN:%.*]], 
i32 2)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z23test_svluti2_lane_zt_u8u11__SVUint8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sme.luti2.lane.zt.nxv16i8(i32 0,  [[ZN:%.*]], 
i32 2)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svuint8_t test_svluti2_lane_zt_u8(svuint8_t zn) __arm_streaming 
__arm_shared_za __arm_preserves_za {
+  return svluti2_lane_zt_u8(0, zn, 2);
+}
+
+
+// CHECK-LABEL: @test_svluti2_lane_zt_s8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sme.luti2.lane.zt.nxv16i8(i32 0,  [[ZN:%.*]], 
i32 2)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z23test_svluti2_lane_zt_s8u10__SVInt8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sme.luti2.lane.zt.nxv16i8(i32 0,  [[ZN:%.*]], 
i32 2)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svint8_t test_svluti2_lane_zt_s8(svint8_t zn) __arm_streaming __arm_shared_za 
__arm_preserves_za {
+  return svluti2_lane_zt_s8(0, zn, 2);
+}
+
+// CHECK-LABEL: @test_svluti2_lane_zt_u16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sme.luti2.lane.zt.nxv8i16(i32 0,  [[ZN:%.*]], 
i32 2)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z24test_svluti2_lane_zt_u16u12__SVUint16_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sme.luti2.lane.zt.nxv8i16(i32 0,  [[ZN:%.*]], 
i32 2)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svuint16_t test_svluti2_lane_zt_u16(svuint16_t zn) __arm_streaming 
__arm_shared_za __arm_preserves_za {
+  return svluti2_lane_zt_u16(0, zn, 2);
+}
+
+
+// CHECK-LABEL: @test_svluti2_lane_zt_s16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT

[clang] [llvm] [SME2] Add LUTI2 and LUTI4 single Builtins and Intrinsics (PR #73304)

2023-11-24 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-clang

Author: Matthew Devereau (MDevereau)


Changes

See https://github.com/ARM-software/acle/pull/217

Patch by: Hassnaa Hamdi 

---

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


11 Files Affected:

- (modified) clang/include/clang/Basic/arm_sme.td (+8) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c 
(+96) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt.c 
(+95) 
- (added) clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_imm.cpp (+33) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+9) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp (+6-1) 
- (modified) llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp (+6) 
- (modified) llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td (+2-2) 
- (modified) llvm/lib/Target/AArch64/SMEInstrFormats.td (+24-9) 
- (added) llvm/test/CodeGen/AArch64/sme2-intrinsics-luti2-lane.ll (+35) 
- (added) llvm/test/CodeGen/AArch64/sme2-intrinsics-luti4-lane.ll (+35) 


``diff
diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b5655afdf419ecf..1174e30cb0885e1 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,3 +298,11 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// lookup table expand one register
+//
+let TargetGuard = "sme2" in {
+  def SVLUTI2_LANE_ZT : Inst<"svluti2_lane_zt[_{d}]", "didi", "cUcsUsiUi", 
MergeNone, "aarch64_sme_luti2_lane_zt", [IsStreaming, IsSharedZA, 
IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_15>]>;
+  def SVLUTI4_LANE_ZT : Inst<"svluti4_lane_zt[_{d}]", "didi", "cUcsUsiUi", 
MergeNone, "aarch64_sme_luti4_lane_zt", [IsStreaming, IsSharedZA, 
IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_7>]>;
+}
diff --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c
new file mode 100644
index 000..ebabbfc815c1dfe
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c
@@ -0,0 +1,96 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -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-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+
+// CHECK-LABEL: @test_svluti2_lane_zt_u8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sme.luti2.lane.zt.nxv16i8(i32 0,  [[ZN:%.*]], 
i32 2)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z23test_svluti2_lane_zt_u8u11__SVUint8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sme.luti2.lane.zt.nxv16i8(i32 0,  [[ZN:%.*]], 
i32 2)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svuint8_t test_svluti2_lane_zt_u8(svuint8_t zn) __arm_streaming 
__arm_shared_za __arm_preserves_za {
+  return svluti2_lane_zt_u8(0, zn, 2);
+}
+
+
+// CHECK-LABEL: @test_svluti2_lane_zt_s8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sme.luti2.lane.zt.nxv16i8(i32 0,  [[ZN:%.*]], 
i32 2)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z23test_svluti2_lane_zt_s8u10__SVInt8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sme.luti2.lane.zt.nxv16i8(i32 0,  [[ZN:%.*]], 
i32 2)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svint8_t test_svluti2_lane_zt_s8(svint8_t zn) __arm_streaming __arm_shared_za 
__arm_preserves_za {
+  return svluti2_lane_zt_s8(0, zn, 2);
+}
+
+// CHECK-LABEL: @test_svluti2_lane_zt_u16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sme.luti2.lane.zt.nxv8i16(i32 0,  [[ZN:%.*]], 
i32 2)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z24test_svluti2_lane_zt_u16u12__SVUint16_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sme.luti2.lane.zt.nxv8i16(i32 0,  [[ZN:%.*]], 
i32 2)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svuint16_t test_svluti2_lane_zt_u16(svuint16_t zn) __arm_streaming 
__arm_shared_za __arm_preserves_za {
+  return svluti2_lane_zt_u16(0, zn, 2);
+}
+
+
+// CHECK-LABEL: @test_svluti2_lane_zt_s16(
+// CHECK-NEXT:  en

[clang] [llvm] [SME2] Add LUTI2 and LUTI4 double Builtins and Intrinsics (PR #73305)

2023-11-24 Thread Matthew Devereau via cfe-commits

https://github.com/MDevereau created 
https://github.com/llvm/llvm-project/pull/73305

See https://github.com/ARM-software/acle/pull/217

Patch by: Hassnaa Hamdi 

>From 5aba2f1d2fe34f721a8e85eef6eecc25cb60851f Mon Sep 17 00:00:00 2001
From: Matt Devereau 
Date: Mon, 20 Nov 2023 15:50:28 +
Subject: [PATCH] [SME2] Add LUTI2 and LUTI4 double Builtins and Intrinsics

See https://github.com/ARM-software/acle/pull/217

Patch by: Hassnaa Hamdi 
---
 clang/include/clang/Basic/arm_sme.td  |   8 +
 .../acle_sme2_luti2_lane_zt_x2.c  | 153 ++
 .../acle_sme2_luti4_lane_zt_x2.c  | 153 ++
 .../aarch64-sme2-intrinsics/acle_sme2_imm.cpp |  34 
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  10 ++
 .../Target/AArch64/AArch64ISelDAGToDAG.cpp|  63 
 .../Target/AArch64/AArch64RegisterInfo.cpp|   6 +
 llvm/lib/Target/AArch64/SMEInstrFormats.td|   1 +
 .../AArch64/sme2-intrinsics-luti2-lane-x2.ll  |  35 
 .../AArch64/sme2-intrinsics-luti4-lane-x2.ll  |  35 
 10 files changed, 498 insertions(+)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt_x2.c
 create mode 100644 clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_imm.cpp
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-luti2-lane-x2.ll
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-luti4-lane-x2.ll

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b5655afdf419ecf..c7b9dbacf071c43 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,3 +298,11 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// lookup table expand two contiguous registers
+//
+let TargetGuard = "sme2" in {
+  def SVLUTI2_LANE_ZT_X2 : Inst<"svluti2_lane_zt[_{d}]_x2", "2.dmdm", 
"cUcsUsiUi", MergeNone, "aarch64_sme_luti2_lane_zt_x2", [IsStreaming, 
IsSharedZA, IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, 
ImmCheck0_7>]>;
+  def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt[_{d}]_x2", "2.dmdm", 
"cUcsUsiUi", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, 
IsSharedZA, IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, 
ImmCheck0_3>]>;
+}
diff --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c
new file mode 100644
index 000..51adc31c6968e7e
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c
@@ -0,0 +1,153 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -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-none-linux-gnu 
-target-feature +sve -target-feature +sme2 -S -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-none-linux-gnu 
-target-feature +sve -target-feature +sme2 -S -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-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1, A2, A3, A4) A1##A2##A3##A4
+#endif
+
+
+// CHECK-LABEL: @test_svluti2_lane_zt_u8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call { ,  } @llvm.aarch64.sme.luti2.lane.zt.x2.nxv16i8(i32 0,  
[[ZN:%.*]], i32 0)
+// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { ,  } [[TMP0]], 0
+// CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( poison,  [[TMP1]], i64 0)
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP0]], 1
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( [[TMP2]],  [[TMP3]], i64 16)
+// CHECK-NEXT:ret  [[TMP4]]
+//
+// CPP-CHECK-LABEL: @_Z23test_svluti2_lane_zt_u8u11__SVUint8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call { ,  } @llvm.aarch64.sme.luti2.lane.zt.x2.nxv16i8(i32 0,  
[[ZN:%.*]], i32 0)
+

[clang] [llvm] [SME2] Add LUTI2 and LUTI4 double Builtins and Intrinsics (PR #73305)

2023-11-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-ir

Author: Matthew Devereau (MDevereau)


Changes

See https://github.com/ARM-software/acle/pull/217

Patch by: Hassnaa Hamdi 

---

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


10 Files Affected:

- (modified) clang/include/clang/Basic/arm_sme.td (+8) 
- (added) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c (+153) 
- (added) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt_x2.c (+153) 
- (added) clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_imm.cpp (+34) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+10) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp (+63) 
- (modified) llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp (+6) 
- (modified) llvm/lib/Target/AArch64/SMEInstrFormats.td (+1) 
- (added) llvm/test/CodeGen/AArch64/sme2-intrinsics-luti2-lane-x2.ll (+35) 
- (added) llvm/test/CodeGen/AArch64/sme2-intrinsics-luti4-lane-x2.ll (+35) 


``diff
diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b5655afdf419ecf..c7b9dbacf071c43 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,3 +298,11 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// lookup table expand two contiguous registers
+//
+let TargetGuard = "sme2" in {
+  def SVLUTI2_LANE_ZT_X2 : Inst<"svluti2_lane_zt[_{d}]_x2", "2.dmdm", 
"cUcsUsiUi", MergeNone, "aarch64_sme_luti2_lane_zt_x2", [IsStreaming, 
IsSharedZA, IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, 
ImmCheck0_7>]>;
+  def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt[_{d}]_x2", "2.dmdm", 
"cUcsUsiUi", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, 
IsSharedZA, IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, 
ImmCheck0_3>]>;
+}
diff --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c
new file mode 100644
index 000..51adc31c6968e7e
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c
@@ -0,0 +1,153 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -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-none-linux-gnu 
-target-feature +sve -target-feature +sme2 -S -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-none-linux-gnu 
-target-feature +sve -target-feature +sme2 -S -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-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1, A2, A3, A4) A1##A2##A3##A4
+#endif
+
+
+// CHECK-LABEL: @test_svluti2_lane_zt_u8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call { ,  } @llvm.aarch64.sme.luti2.lane.zt.x2.nxv16i8(i32 0,  
[[ZN:%.*]], i32 0)
+// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { ,  } [[TMP0]], 0
+// CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( poison,  [[TMP1]], i64 0)
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP0]], 1
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( [[TMP2]],  [[TMP3]], i64 16)
+// CHECK-NEXT:ret  [[TMP4]]
+//
+// CPP-CHECK-LABEL: @_Z23test_svluti2_lane_zt_u8u11__SVUint8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call { ,  } @llvm.aarch64.sme.luti2.lane.zt.x2.nxv16i8(i32 0,  
[[ZN:%.*]], i32 0)
+// CPP-CHECK-NEXT:[[TMP1:%.*]] = extractvalue { , 
 } [[TMP0]], 0
+// CPP-CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( poison,  [[TMP1]], i64 0)
+// CPP-CHECK-NEXT:[[TMP3:%.*]] = extractvalue { , 
 } [[TMP0]], 1
+// CPP-CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( [[TMP2]],  [[TMP3]], i64 16)
+// CPP-CHECK-NEXT:ret  [[TMP4]]
+//
+svuint8x2_t test_

[clang] [llvm] [SME2] Add LUTI2 and LUTI4 double Builtins and Intrinsics (PR #73305)

2023-11-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Matthew Devereau (MDevereau)


Changes

See https://github.com/ARM-software/acle/pull/217

Patch by: Hassnaa Hamdi 

---

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


10 Files Affected:

- (modified) clang/include/clang/Basic/arm_sme.td (+8) 
- (added) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c (+153) 
- (added) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt_x2.c (+153) 
- (added) clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_imm.cpp (+34) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+10) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp (+63) 
- (modified) llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp (+6) 
- (modified) llvm/lib/Target/AArch64/SMEInstrFormats.td (+1) 
- (added) llvm/test/CodeGen/AArch64/sme2-intrinsics-luti2-lane-x2.ll (+35) 
- (added) llvm/test/CodeGen/AArch64/sme2-intrinsics-luti4-lane-x2.ll (+35) 


``diff
diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b5655afdf419ecf..c7b9dbacf071c43 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,3 +298,11 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// lookup table expand two contiguous registers
+//
+let TargetGuard = "sme2" in {
+  def SVLUTI2_LANE_ZT_X2 : Inst<"svluti2_lane_zt[_{d}]_x2", "2.dmdm", 
"cUcsUsiUi", MergeNone, "aarch64_sme_luti2_lane_zt_x2", [IsStreaming, 
IsSharedZA, IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, 
ImmCheck0_7>]>;
+  def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt[_{d}]_x2", "2.dmdm", 
"cUcsUsiUi", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, 
IsSharedZA, IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, 
ImmCheck0_3>]>;
+}
diff --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c
new file mode 100644
index 000..51adc31c6968e7e
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c
@@ -0,0 +1,153 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -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-none-linux-gnu 
-target-feature +sve -target-feature +sme2 -S -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-none-linux-gnu 
-target-feature +sve -target-feature +sme2 -S -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-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1, A2, A3, A4) A1##A2##A3##A4
+#endif
+
+
+// CHECK-LABEL: @test_svluti2_lane_zt_u8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call { ,  } @llvm.aarch64.sme.luti2.lane.zt.x2.nxv16i8(i32 0,  
[[ZN:%.*]], i32 0)
+// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { ,  } [[TMP0]], 0
+// CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( poison,  [[TMP1]], i64 0)
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP0]], 1
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( [[TMP2]],  [[TMP3]], i64 16)
+// CHECK-NEXT:ret  [[TMP4]]
+//
+// CPP-CHECK-LABEL: @_Z23test_svluti2_lane_zt_u8u11__SVUint8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call { ,  } @llvm.aarch64.sme.luti2.lane.zt.x2.nxv16i8(i32 0,  
[[ZN:%.*]], i32 0)
+// CPP-CHECK-NEXT:[[TMP1:%.*]] = extractvalue { , 
 } [[TMP0]], 0
+// CPP-CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( poison,  [[TMP1]], i64 0)
+// CPP-CHECK-NEXT:[[TMP3:%.*]] = extractvalue { , 
 } [[TMP0]], 1
+// CPP-CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( [[TMP2]],  [[TMP3]], i64 16)
+// CPP-CHECK-NEXT:ret  [[TMP4]]
+//
+svuint8x2_t test_sv

[llvm] [clang] [SME2] Add LUTI2 and LUTI4 double Builtins and Intrinsics (PR #73305)

2023-11-24 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 6b87d84ff45d03c244e7511fba9359776ce27977 
5aba2f1d2fe34f721a8e85eef6eecc25cb60851f -- 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt_x2.c 
clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_imm.cpp 
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp 
llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
index 455a966ef0..378c3d8e5f 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
@@ -5114,7 +5114,7 @@ void AArch64DAGToDAGISel::Select(SDNode *Node) {
   Node->getValueType(0),
   {AArch64::LUTI4_2ZTZI_B, AArch64::LUTI4_2ZTZI_H,
AArch64::LUTI4_2ZTZI_S}))
-  // Second Immediate must be <= 3:
+// Second Immediate must be <= 3:
 SelectMultiVectorLuti<3>(Node, 2, Opc);
   return;
 }

``




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


[clang] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2 (PR #72107)

2023-11-24 Thread via cfe-commits

DonatNagyE wrote:

> Note that &array[idx] is perfectly valid code when `idx == number of 
> elements`. And it is relatively common to do that when one is using STL 
> algorithms on arrays:
> 
> ```
> auto it = std::find(&array[0], &array[size], foo);
> ```
>
> Of course, one could use the `begin/end` free functions, but those are only 
> available since C++11.

Oh, dammit, this language is _stupid_... I couldn't imagine a reason to use 
`&array[size]` instead of the cleaner `(array + size)`; but _of course_ STL 
containers need `&array[size]` with their overloaded `operator[]` (note: this 
is not an `ArraySubscriptExpr` but an overloaded operator call, so it's not 
handled by this checker) and then (if you say so) some developers will use this 
for plain arrays as well...

> Could you elaborate on alternative approaches you considered fixing the 
> problem and why you chose this one? E.g., would trying to look at the parent 
> regions for expressions like `foo[idx].bar` work? Or is the source of the 
> problem that you'd also need the exact expression for the subscript instead 
> of the `MemberExpr`?

I considered two approaches, this one and walking on the parent region layers 
(I don't think that there is a third distinct approach). I chose this because:
- This way the implementation is easier to understand and more "connected" to 
the concrete details of the analyzed code.
- A few months ago @steakhal realized that `check::Location` is not sufficient 
on its own and it should've been supplemented with a `check::Bind` callback to 
cover all relevant cases. The commit implementing this 
(https://reviews.llvm.org/D159106) was abandoned, but if we keep 
`check::Location`, we would need to reintroduce something like that as well.
- I _like_ that I have the exact expression for the subscript (or other 
dereferencing expression, like `*ptr` or `ptr->foo`) because this puts the 
warning message to the right source location (e.g. in a convoluted multiline 
expressions with several `[]` and `->` layers) and allows/could allow better 
customization of the message. 

> Alternatively, would it be possible to suppress warnings on the common 
> pattern `&array[idx]` by checking the parent of the subscript expression in 
> the AST (but still emitting a warning when the pointer is dereferenced)?

Yes, that was my plan for resolving this issue; and as you say that it's 
needed, I'll implement it. I'll squeeze the parent lookup into the `if` where 
we know that there's an overflow, so that (AFAIK expensive) operation won't run 
in the common case when the array access is in bounds. The "still emitting a 
warning when the pointer is dereferenced" will happen automatically as at that 
point we'll have the same overflowing pointer but without the `&` that negates 
the result. 

I think that I won't suppress the warning in situations like
```
int array[10];
int *f(int arg) {
  if (arg >= 10)
return &array[arg];
  return array;
}
```
where the analyzer knows that `idx >= size` and doesn't know that `idx == 
size`. Are there any crazy situations where this is also legitimate?

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


[clang] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2 (PR #72107)

2023-11-24 Thread via cfe-commits


@@ -64,6 +100,28 @@ double arrayInStructPtr(struct vec *pv) {
   // expected-note@-2 {{Access of the field 'elems' at index 64, while it 
holds only 64 'double' elements}}
 }
 
+struct item {
+  int a, b;
+} itemArray[20] = {0};
+
+int structOfArrays(void) {

DonatNagyE wrote:

Oops, nice catch!

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


[clang] [clang] Classify vector types in __builtin_classify_type (PR #73299)

2023-11-24 Thread via cfe-commits

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


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


[clang] 076ec9f - Fix build failure on certain bots

2023-11-24 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-11-24T11:39:16+01:00
New Revision: 076ec9f5f5bf03983f43f703e3f9d4600bad9653

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

LOG: Fix build failure on certain bots

Added: 


Modified: 
clang/lib/Basic/Targets/RISCV.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 0ecc35f3a332a9b..d1d9cc1c770e361 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -269,7 +269,7 @@ resolveTargetAttrOverride(const std::vector 
&FeaturesVec,
   std::vector NonISAExtFeature =
   collectNonISAExtFeature(FeaturesNeedOverride, XLen);
 
-  auto ResolvedFeature = std::vector(++I, FeaturesVec.end());
+  auto ResolvedFeature = std::vector(++I, FeaturesVec.end());
   ResolvedFeature.insert(ResolvedFeature.end(), NonISAExtFeature.begin(),
  NonISAExtFeature.end());
 



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


[clang] [llvm] [SME2] Add LUTI2 and LUTI4 quad Builtins and Intrinsics (PR #73317)

2023-11-24 Thread Matthew Devereau via cfe-commits

https://github.com/MDevereau created 
https://github.com/llvm/llvm-project/pull/73317

See https://github.com/ARM-software/acle/pull/217

Patch by: Hassnaa Hamdi 

>From f5b909e24e3cea49d98b40797880e4329a7a1e4f Mon Sep 17 00:00:00 2001
From: Matt Devereau 
Date: Mon, 20 Nov 2023 15:50:28 +
Subject: [PATCH] [SME2] Add LUTI2 and LUTI4 quad Builtins and Intrinsics

See https://github.com/ARM-software/acle/pull/217

Patch by: Hassnaa Hamdi 
---
 clang/include/clang/Basic/arm_sme.td  |   8 +
 .../acle_sme2_luti2_lane_zt_x4.c  | 201 ++
 .../acle_sme2_luti4_lane_zt_x4.c  | 148 +
 .../aarch64-sme2-intrinsics/acle_sme2_imm.cpp |  31 +++
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  11 +
 .../Target/AArch64/AArch64ISelDAGToDAG.cpp|  55 -
 .../Target/AArch64/AArch64RegisterInfo.cpp|   6 +
 llvm/lib/Target/AArch64/SMEInstrFormats.td|  11 +-
 .../AArch64/sme2-intrinsics-luti2-lane-x4.ll  |  35 +++
 .../AArch64/sme2-intrinsics-luti4-lane-x4.ll  |  25 +++
 10 files changed, 525 insertions(+), 6 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt_x4.c
 create mode 100644 clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_imm.cpp
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-luti2-lane-x4.ll
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-luti4-lane-x4.ll

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b5655afdf419ecf..53319a57d73fdd2 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,3 +298,11 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// lookup table expand four contiguous registers
+//
+let TargetGuard = "sme2" in {
+  def SVLUTI2_LANE_ZT_X4 : Inst<"svluti2_lane_zt[_{d}]_x4", "4.didi", 
"cUcsUsiUi", MergeNone, "aarch64_sme_luti2_lane_zt_x4", [IsStreaming, 
IsSharedZA, IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, 
ImmCheck0_3>]>;
+  def SVLUTI4_LANE_ZT_X4 : Inst<"svluti4_lane_zt[_{d}]_x4", "4.didi", 
"sUsiUi", MergeNone, "aarch64_sme_luti4_lane_zt_x4", [IsStreaming, IsSharedZA, 
IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_1>]>;
+}
diff --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c
new file mode 100644
index 000..5479fa109e839c5
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c
@@ -0,0 +1,201 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +sve -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +sve -S -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-none-linux-gnu 
-target-feature +sme2 -target-feature +sve -S -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-none-linux-gnu 
-target-feature +sme2 -target-feature +sve -S -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-none-linux-gnu -target-feature +sme2 
-target-feature +sve -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1, A2, A3, A4) A1##A2##A3##A4
+#endif
+
+
+
+// CHECK-LABEL: @test_svluti2_lane_zt_u8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call { , , ,  } 
@llvm.aarch64.sme.luti2.lane.zt.x4.nxv16i8(i32 0,  
[[ZN:%.*]], i32 0)
+// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { , , ,  } [[TMP0]], 0
+// CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.vector.insert.nxv64i8.nxv16i8( poison,  [[TMP1]], i64 0)
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { , , ,  } [[TMP0]], 1
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv64i8.nxv16i8( [[TMP2]],  [[TMP3]], i64 16)
+// CHECK-NEXT:[[TMP5:%.*]] = extractvalue { , , ,  } [[TMP0]], 2
+// CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv64i8.nxv16i8( [[TMP4]],  [[TMP5]], i64 32)
+// CHECK-NEXT:[[TMP7:%.*]] = extractvalue { , , ,  } [[

[clang] [llvm] [SME2] Add LUTI2 and LUTI4 quad Builtins and Intrinsics (PR #73317)

2023-11-24 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-aarch64

Author: Matthew Devereau (MDevereau)


Changes

See https://github.com/ARM-software/acle/pull/217

Patch by: Hassnaa Hamdi 

---

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


10 Files Affected:

- (modified) clang/include/clang/Basic/arm_sme.td (+8) 
- (added) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c (+201) 
- (added) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt_x4.c (+148) 
- (added) clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_imm.cpp (+31) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+11) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp (+54-1) 
- (modified) llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp (+6) 
- (modified) llvm/lib/Target/AArch64/SMEInstrFormats.td (+6-5) 
- (added) llvm/test/CodeGen/AArch64/sme2-intrinsics-luti2-lane-x4.ll (+35) 
- (added) llvm/test/CodeGen/AArch64/sme2-intrinsics-luti4-lane-x4.ll (+25) 


``diff
diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b5655afdf419ecf..53319a57d73fdd2 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,3 +298,11 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// lookup table expand four contiguous registers
+//
+let TargetGuard = "sme2" in {
+  def SVLUTI2_LANE_ZT_X4 : Inst<"svluti2_lane_zt[_{d}]_x4", "4.didi", 
"cUcsUsiUi", MergeNone, "aarch64_sme_luti2_lane_zt_x4", [IsStreaming, 
IsSharedZA, IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, 
ImmCheck0_3>]>;
+  def SVLUTI4_LANE_ZT_X4 : Inst<"svluti4_lane_zt[_{d}]_x4", "4.didi", 
"sUsiUi", MergeNone, "aarch64_sme_luti4_lane_zt_x4", [IsStreaming, IsSharedZA, 
IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_1>]>;
+}
diff --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c
new file mode 100644
index 000..5479fa109e839c5
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c
@@ -0,0 +1,201 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +sve -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +sve -S -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-none-linux-gnu 
-target-feature +sme2 -target-feature +sve -S -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-none-linux-gnu 
-target-feature +sme2 -target-feature +sve -S -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-none-linux-gnu -target-feature +sme2 
-target-feature +sve -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1, A2, A3, A4) A1##A2##A3##A4
+#endif
+
+
+
+// CHECK-LABEL: @test_svluti2_lane_zt_u8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call { , , ,  } 
@llvm.aarch64.sme.luti2.lane.zt.x4.nxv16i8(i32 0,  
[[ZN:%.*]], i32 0)
+// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { , , ,  } [[TMP0]], 0
+// CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.vector.insert.nxv64i8.nxv16i8( poison,  [[TMP1]], i64 0)
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { , , ,  } [[TMP0]], 1
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv64i8.nxv16i8( [[TMP2]],  [[TMP3]], i64 16)
+// CHECK-NEXT:[[TMP5:%.*]] = extractvalue { , , ,  } [[TMP0]], 2
+// CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv64i8.nxv16i8( [[TMP4]],  [[TMP5]], i64 32)
+// CHECK-NEXT:[[TMP7:%.*]] = extractvalue { , , ,  } [[TMP0]], 3
+// CHECK-NEXT:[[TMP8:%.*]] = tail call  
@llvm.vector.insert.nxv64i8.nxv16i8( [[TMP6]],  [[TMP7]], i64 48)
+// CHECK-NEXT:ret  [[TMP8]]
+//
+// CPP-CHECK-LABEL: @_Z23test_svluti2_lane_zt_u8u11__SVUint8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call { , , ,  } 
@llvm.aarch64.sme.luti2.lane.zt.x4.nxv16i8(i32 0,  
[[ZN:%.*]], i32 0)
+// CPP-CH

[clang] [clang][ASTImporter] Fix import of SubstTemplateTypeParmType in return type of function. (PR #69724)

2023-11-24 Thread via cfe-commits
=?utf-8?q?Bal=C3=A1zs_K=C3=A9ri?= 
Message-ID:
In-Reply-To: 


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

LGTM, congratulations for catching this corner case!

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


[clang] [clang][Interp] Implement __builtin_bit_cast (PR #68288)

2023-11-24 Thread via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 



@@ -73,6 +73,74 @@ template  class OptionScope final {
 } // namespace interp
 } // namespace clang
 
+//  This function is constexpr if and only if To, From, and the types of
+//  all subobjects of To and From are types T such that...
+//  (3.1) - is_union_v is false;
+//  (3.2) - is_pointer_v is false;
+//  (3.3) - is_member_pointer_v is false;
+//  (3.4) - is_volatile_v is false; and
+//  (3.5) - T has no non-static data members of reference type
+template 
+bool ByteCodeExprGen::emitBuiltinBitCast(const CastExpr *E) {
+  const Expr *SubExpr = E->getSubExpr();
+  QualType FromType = SubExpr->getType();
+  QualType ToType = E->getType();
+  std::optional ToT = classify(ToType);
+
+  // FIXME: This is wrong. We need to do the bitcast and then
+  //   throw away the result, so we still get the diagnostics.
+  if (DiscardResult)
+return this->discard(SubExpr);
+
+  if (ToType->isNullPtrType()) {
+if (!this->discard(SubExpr))
+  return false;
+
+return this->emitNullPtr(E);
+  }
+
+  if (FromType->isNullPtrType() && ToT) {
+if (!this->discard(SubExpr))
+  return false;
+
+return visitZeroInitializer(*ToT, ToType, E);
+  }
+  assert(!ToType->isReferenceType());
+
+  // Get a pointer to the value-to-cast on the stack.
+  if (!this->visit(SubExpr))
+return false;
+
+  if (!ToT || ToT == PT_Ptr) {
+// Conversion to an array or record type.
+return this->emitBitCastPtr(E);
+  }
+
+  assert(ToT);
+
+  // Conversion to a primitive type. FromType can be another
+  // primitive type, or a record/array.
+  //
+  // Same thing for floats, but we need the target
+  // semantics here.

cor3ntin wrote:

Does it actually make sense to have a complete different codepath? we could 
have a single function and pass a null pointer in the non floating point case.

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


[clang] [clang][Interp] Implement __builtin_bit_cast (PR #68288)

2023-11-24 Thread via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 



@@ -1561,6 +1576,59 @@ template  bool 
Cast(InterpState &S, CodePtr OpPC) {
   return true;
 }
 
+template ::T>
+bool BitCast(InterpState &S, CodePtr OpPC, bool TargetIsUCharOrByte) {
+  const Pointer &FromPtr = S.Stk.pop();
+
+  size_t BuffSize = ToT::valueReprBytes(S.getCtx());
+  std::vector Buff(BuffSize);

cor3ntin wrote:

an llvm small vector (with a buffer of ~8) would avoid almost all allocation 
here

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


[clang] [clang][Interp] Implement __builtin_bit_cast (PR #68288)

2023-11-24 Thread via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 



@@ -134,6 +141,10 @@ class Floating final {
 
 return Floating(APFloat(Sem, API));
   }
+  void bitcastToMemory(std::byte *Buff) {
+llvm::APInt API = F.bitcastToAPInt();
+llvm::StoreIntToMemory(API, (uint8_t *)Buff, bitWidth() / 8);

cor3ntin wrote:

Should that use `getCharWidth()` ?

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


[clang] [clang][Interp] Implement __builtin_bit_cast (PR #68288)

2023-11-24 Thread via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,455 @@
+//===--- InterpBitcast.cpp - Interpreter for the constexpr VM ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "Boolean.h"
+#include "Interp.h"
+#include "PrimType.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecordLayout.h"
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/BitVector.h"
+
+namespace clang {
+namespace interp {
+
+/// Used to iterate over pointer fields.
+using DataFunc =
+llvm::function_ref;
+
+#define BITCAST_TYPE_SWITCH(Expr, B)   
\
+  do { 
\
+switch (Expr) {
\
+  TYPE_SWITCH_CASE(PT_Sint8, B)
\
+  TYPE_SWITCH_CASE(PT_Uint8, B)
\
+  TYPE_SWITCH_CASE(PT_Sint16, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint16, B)   
\
+  TYPE_SWITCH_CASE(PT_Sint32, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint32, B)   
\
+  TYPE_SWITCH_CASE(PT_Sint64, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint64, B)   
\
+  TYPE_SWITCH_CASE(PT_Bool, B) 
\
+default:   
\
+  llvm_unreachable("Unhandled bitcast type");  
\
+}  
\
+  } while (0)
+
+/// Float is a special case that sometimes needs the floating point semantics
+/// to be available.
+#define BITCAST_TYPE_SWITCH_WITH_FLOAT(Expr, B)
\
+  do { 
\
+switch (Expr) {
\
+  TYPE_SWITCH_CASE(PT_Sint8, B)
\
+  TYPE_SWITCH_CASE(PT_Uint8, B)
\
+  TYPE_SWITCH_CASE(PT_Sint16, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint16, B)   
\
+  TYPE_SWITCH_CASE(PT_Sint32, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint32, B)   
\
+  TYPE_SWITCH_CASE(PT_Sint64, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint64, B)   
\
+  TYPE_SWITCH_CASE(PT_Bool, B) 
\
+  TYPE_SWITCH_CASE(PT_Float, B)
\
+default:   
\
+  llvm_unreachable("Unhandled bitcast type");  
\
+}  
\
+  } while (0)
+
+/// Rotate things around for big endian targets.
+static void swapBytes(std::byte *M, size_t N) {
+  for (size_t I = 0; I != (N / 2); ++I)
+std::swap(M[I], M[N - 1 - I]);
+}
+
+/// Track what bits have been initialized to known values and which ones
+/// have indeterminate value.
+/// All offsets are in bits.
+struct BitTracker {
+  llvm::BitVector Initialized;
+  llvm::BitVector Data_;
+
+  BitTracker() = default;
+
+  size_t size() const {
+assert(Initialized.size() == Data_.size());
+return Initialized.size();
+  }
+
+  const std::byte *getBytes(size_t BitOffset, int a) {
+assert(BitOffset % 8 == 0);
+return reinterpret_cast(Data_.getData().data()) +
+   (BitOffset / 8);
+  }
+
+  bool allInitialized(size_t Offset, size_t Size) const {
+return Initialized.find_first_unset_in(Offset, Offset + Size) == -1;
+  }
+
+  bool allInitialized() const { return Initialized.all(); }
+
+  void pushData(const std::byte *data, size_t BitOffset, size_t BitWidth) {
+assert(BitOffset >= Data_.size());
+// First, fill up the bit vector until BitOffset. The bits are all 0
+// but we record them as indeterminate.
+{
+  Data_.resize(BitOffset, false);
+  Initialized.resize(BitOffset, false);
+}
+
+size_t BitsHandled = 0;
+// Read all

[clang] [clang][Interp] Implement __builtin_bit_cast (PR #68288)

2023-11-24 Thread via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,455 @@
+//===--- InterpBitcast.cpp - Interpreter for the constexpr VM ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "Boolean.h"
+#include "Interp.h"
+#include "PrimType.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecordLayout.h"
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/BitVector.h"
+
+namespace clang {
+namespace interp {
+
+/// Used to iterate over pointer fields.
+using DataFunc =
+llvm::function_ref;
+
+#define BITCAST_TYPE_SWITCH(Expr, B)   
\
+  do { 
\
+switch (Expr) {
\
+  TYPE_SWITCH_CASE(PT_Sint8, B)
\
+  TYPE_SWITCH_CASE(PT_Uint8, B)
\
+  TYPE_SWITCH_CASE(PT_Sint16, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint16, B)   
\
+  TYPE_SWITCH_CASE(PT_Sint32, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint32, B)   
\
+  TYPE_SWITCH_CASE(PT_Sint64, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint64, B)   
\
+  TYPE_SWITCH_CASE(PT_Bool, B) 
\
+default:   
\
+  llvm_unreachable("Unhandled bitcast type");  
\

cor3ntin wrote:

I'd rather see a diagnostic here (such diag exist in the current interpreter 
https://compiler-explorer.com/z/xva6cG6rq )

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


[clang] [clang][Interp] Implement __builtin_bit_cast (PR #68288)

2023-11-24 Thread via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 



@@ -66,6 +67,12 @@ class Boolean final {
   Boolean toUnsigned() const { return *this; }
 
   constexpr static unsigned bitWidth() { return 1; }
+  constexpr static unsigned objectReprBits() { return 8; }
+  constexpr static unsigned valueReprBytes(const ASTContext &Ctx) { return 1; }
+  constexpr static unsigned valueReprBits(const ASTContext &Ctx) {
+return 8;
+  } // FIXME: Is this correct?

cor3ntin wrote:

`Ctx.getTargetInfo().getBoolWidth()` should do the trick

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


[clang] [clang][Interp] Implement __builtin_bit_cast (PR #68288)

2023-11-24 Thread via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 



@@ -9,14 +9,15 @@
 #ifndef LLVM_CLANG_AST_INTERP_BOOLEAN_H
 #define LLVM_CLANG_AST_INTERP_BOOLEAN_H
 
-#include 
-#include 
 #include "Integral.h"
 #include "clang/AST/APValue.h"
+#include "clang/AST/ASTContext.h"
 #include "clang/AST/ComparisonCategories.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
+#include 

cor3ntin wrote:

Is that actually needed?

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


[clang] [clang][Interp] Implement __builtin_bit_cast (PR #68288)

2023-11-24 Thread via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,455 @@
+//===--- InterpBitcast.cpp - Interpreter for the constexpr VM ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "Boolean.h"
+#include "Interp.h"
+#include "PrimType.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecordLayout.h"
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/BitVector.h"
+
+namespace clang {
+namespace interp {
+
+/// Used to iterate over pointer fields.
+using DataFunc =
+llvm::function_ref;
+
+#define BITCAST_TYPE_SWITCH(Expr, B)   
\
+  do { 
\
+switch (Expr) {
\
+  TYPE_SWITCH_CASE(PT_Sint8, B)
\
+  TYPE_SWITCH_CASE(PT_Uint8, B)
\
+  TYPE_SWITCH_CASE(PT_Sint16, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint16, B)   
\
+  TYPE_SWITCH_CASE(PT_Sint32, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint32, B)   
\
+  TYPE_SWITCH_CASE(PT_Sint64, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint64, B)   
\
+  TYPE_SWITCH_CASE(PT_Bool, B) 
\
+default:   
\
+  llvm_unreachable("Unhandled bitcast type");  
\
+}  
\
+  } while (0)
+
+/// Float is a special case that sometimes needs the floating point semantics
+/// to be available.
+#define BITCAST_TYPE_SWITCH_WITH_FLOAT(Expr, B)
\
+  do { 
\
+switch (Expr) {
\
+  TYPE_SWITCH_CASE(PT_Sint8, B)
\
+  TYPE_SWITCH_CASE(PT_Uint8, B)
\
+  TYPE_SWITCH_CASE(PT_Sint16, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint16, B)   
\
+  TYPE_SWITCH_CASE(PT_Sint32, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint32, B)   
\
+  TYPE_SWITCH_CASE(PT_Sint64, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint64, B)   
\
+  TYPE_SWITCH_CASE(PT_Bool, B) 
\
+  TYPE_SWITCH_CASE(PT_Float, B)
\
+default:   
\
+  llvm_unreachable("Unhandled bitcast type");  
\
+}  
\
+  } while (0)
+
+/// Rotate things around for big endian targets.
+static void swapBytes(std::byte *M, size_t N) {
+  for (size_t I = 0; I != (N / 2); ++I)
+std::swap(M[I], M[N - 1 - I]);
+}
+
+/// Track what bits have been initialized to known values and which ones
+/// have indeterminate value.
+/// All offsets are in bits.
+struct BitTracker {
+  llvm::BitVector Initialized;
+  llvm::BitVector Data_;
+
+  BitTracker() = default;
+
+  size_t size() const {
+assert(Initialized.size() == Data_.size());
+return Initialized.size();
+  }
+
+  const std::byte *getBytes(size_t BitOffset, int a) {
+assert(BitOffset % 8 == 0);
+return reinterpret_cast(Data_.getData().data()) +
+   (BitOffset / 8);
+  }
+
+  bool allInitialized(size_t Offset, size_t Size) const {
+return Initialized.find_first_unset_in(Offset, Offset + Size) == -1;
+  }
+
+  bool allInitialized() const { return Initialized.all(); }
+
+  void pushData(const std::byte *data, size_t BitOffset, size_t BitWidth) {
+assert(BitOffset >= Data_.size());
+// First, fill up the bit vector until BitOffset. The bits are all 0
+// but we record them as indeterminate.
+{
+  Data_.resize(BitOffset, false);
+  Initialized.resize(BitOffset, false);
+}
+
+size_t BitsHandled = 0;
+// Read all

[clang] [clang][Interp] Implement __builtin_bit_cast (PR #68288)

2023-11-24 Thread via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,455 @@
+//===--- InterpBitcast.cpp - Interpreter for the constexpr VM ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "Boolean.h"
+#include "Interp.h"
+#include "PrimType.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecordLayout.h"
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/BitVector.h"
+
+namespace clang {
+namespace interp {
+
+/// Used to iterate over pointer fields.
+using DataFunc =
+llvm::function_ref;
+
+#define BITCAST_TYPE_SWITCH(Expr, B)   
\
+  do { 
\
+switch (Expr) {
\
+  TYPE_SWITCH_CASE(PT_Sint8, B)
\
+  TYPE_SWITCH_CASE(PT_Uint8, B)
\
+  TYPE_SWITCH_CASE(PT_Sint16, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint16, B)   
\
+  TYPE_SWITCH_CASE(PT_Sint32, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint32, B)   
\
+  TYPE_SWITCH_CASE(PT_Sint64, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint64, B)   
\
+  TYPE_SWITCH_CASE(PT_Bool, B) 
\
+default:   
\
+  llvm_unreachable("Unhandled bitcast type");  
\
+}  
\
+  } while (0)
+
+/// Float is a special case that sometimes needs the floating point semantics
+/// to be available.
+#define BITCAST_TYPE_SWITCH_WITH_FLOAT(Expr, B)
\
+  do { 
\
+switch (Expr) {
\
+  TYPE_SWITCH_CASE(PT_Sint8, B)
\
+  TYPE_SWITCH_CASE(PT_Uint8, B)
\
+  TYPE_SWITCH_CASE(PT_Sint16, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint16, B)   
\
+  TYPE_SWITCH_CASE(PT_Sint32, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint32, B)   
\
+  TYPE_SWITCH_CASE(PT_Sint64, B)   
\
+  TYPE_SWITCH_CASE(PT_Uint64, B)   
\
+  TYPE_SWITCH_CASE(PT_Bool, B) 
\
+  TYPE_SWITCH_CASE(PT_Float, B)
\
+default:   
\
+  llvm_unreachable("Unhandled bitcast type");  
\
+}  
\
+  } while (0)
+
+/// Rotate things around for big endian targets.
+static void swapBytes(std::byte *M, size_t N) {
+  for (size_t I = 0; I != (N / 2); ++I)
+std::swap(M[I], M[N - 1 - I]);
+}
+
+/// Track what bits have been initialized to known values and which ones
+/// have indeterminate value.
+/// All offsets are in bits.
+struct BitTracker {
+  llvm::BitVector Initialized;
+  llvm::BitVector Data_;
+
+  BitTracker() = default;
+
+  size_t size() const {
+assert(Initialized.size() == Data_.size());
+return Initialized.size();
+  }
+
+  const std::byte *getBytes(size_t BitOffset, int a) {
+assert(BitOffset % 8 == 0);
+return reinterpret_cast(Data_.getData().data()) +
+   (BitOffset / 8);
+  }
+
+  bool allInitialized(size_t Offset, size_t Size) const {
+return Initialized.find_first_unset_in(Offset, Offset + Size) == -1;
+  }
+
+  bool allInitialized() const { return Initialized.all(); }
+
+  void pushData(const std::byte *data, size_t BitOffset, size_t BitWidth) {
+assert(BitOffset >= Data_.size());
+// First, fill up the bit vector until BitOffset. The bits are all 0
+// but we record them as indeterminate.
+{
+  Data_.resize(BitOffset, false);
+  Initialized.resize(BitOffset, false);
+}
+
+size_t BitsHandled = 0;
+// Read all

[clang] [llvm] [SME2] Add LUTI2 and LUTI4 double Builtins and Intrinsics (PR #73305)

2023-11-24 Thread Matthew Devereau via cfe-commits

https://github.com/MDevereau updated 
https://github.com/llvm/llvm-project/pull/73305

>From 5aba2f1d2fe34f721a8e85eef6eecc25cb60851f Mon Sep 17 00:00:00 2001
From: Matt Devereau 
Date: Mon, 20 Nov 2023 15:50:28 +
Subject: [PATCH 1/2] [SME2] Add LUTI2 and LUTI4 double Builtins and Intrinsics

See https://github.com/ARM-software/acle/pull/217

Patch by: Hassnaa Hamdi 
---
 clang/include/clang/Basic/arm_sme.td  |   8 +
 .../acle_sme2_luti2_lane_zt_x2.c  | 153 ++
 .../acle_sme2_luti4_lane_zt_x2.c  | 153 ++
 .../aarch64-sme2-intrinsics/acle_sme2_imm.cpp |  34 
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  10 ++
 .../Target/AArch64/AArch64ISelDAGToDAG.cpp|  63 
 .../Target/AArch64/AArch64RegisterInfo.cpp|   6 +
 llvm/lib/Target/AArch64/SMEInstrFormats.td|   1 +
 .../AArch64/sme2-intrinsics-luti2-lane-x2.ll  |  35 
 .../AArch64/sme2-intrinsics-luti4-lane-x2.ll  |  35 
 10 files changed, 498 insertions(+)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt_x2.c
 create mode 100644 clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_imm.cpp
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-luti2-lane-x2.ll
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-luti4-lane-x2.ll

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b5655afdf419ecf..c7b9dbacf071c43 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,3 +298,11 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// lookup table expand two contiguous registers
+//
+let TargetGuard = "sme2" in {
+  def SVLUTI2_LANE_ZT_X2 : Inst<"svluti2_lane_zt[_{d}]_x2", "2.dmdm", 
"cUcsUsiUi", MergeNone, "aarch64_sme_luti2_lane_zt_x2", [IsStreaming, 
IsSharedZA, IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, 
ImmCheck0_7>]>;
+  def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt[_{d}]_x2", "2.dmdm", 
"cUcsUsiUi", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, 
IsSharedZA, IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, 
ImmCheck0_3>]>;
+}
diff --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c
new file mode 100644
index 000..51adc31c6968e7e
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c
@@ -0,0 +1,153 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -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-none-linux-gnu 
-target-feature +sve -target-feature +sme2 -S -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-none-linux-gnu 
-target-feature +sve -target-feature +sme2 -S -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-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1, A2, A3, A4) A1##A2##A3##A4
+#endif
+
+
+// CHECK-LABEL: @test_svluti2_lane_zt_u8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call { ,  } @llvm.aarch64.sme.luti2.lane.zt.x2.nxv16i8(i32 0,  
[[ZN:%.*]], i32 0)
+// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { ,  } [[TMP0]], 0
+// CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( poison,  [[TMP1]], i64 0)
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP0]], 1
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( [[TMP2]],  [[TMP3]], i64 16)
+// CHECK-NEXT:ret  [[TMP4]]
+//
+// CPP-CHECK-LABEL: @_Z23test_svluti2_lane_zt_u8u11__SVUint8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call { ,  } @llvm.aarch64.sme.luti2.lane.zt.x2.nxv16i8(i32 0,  
[[ZN:%.*]], i32 0)
+// CPP-CHECK-NEXT:[[TMP1:%.*]] = extractvalue { , 
 } [[TMP0]], 0
+//

[clang] [clang][ASTImporter] Improve structural equivalence of overloadable operators. (PR #72242)

2023-11-24 Thread via cfe-commits

https://github.com/DonatNagyE commented:

As you write that unifying these different but equivalent expressions could've 
unintended consequences, perhaps you should check the effects of this change on 
CTU analysis of modern (a.k.a. crazy) C++ projects (or publish the results if 
you already did so).

Otherwise I can't find any problem in this code, but I'm not familiar enough 
with these intricate details of the standard, so this opinion is not too 
relevant.

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


[clang] [clang][ASTImporter] Improve structural equivalence of overloadable operators. (PR #72242)

2023-11-24 Thread via cfe-commits


@@ -437,12 +439,67 @@ class StmtComparer {
 };
 } // namespace
 
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const UnaryOperator *E1,
+ const CXXOperatorCallExpr *E2) {
+  return UnaryOperator::getOverloadedOperator(E1->getOpcode()) ==
+ E2->getOperator() &&
+ IsStructurallyEquivalent(Context, E1->getSubExpr(), E2->getArg(0));
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const CXXOperatorCallExpr *E1,
+ const UnaryOperator *E2) {
+  return E1->getOperator() ==
+ UnaryOperator::getOverloadedOperator(E2->getOpcode()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(0), E2->getSubExpr());
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const BinaryOperator *E1,
+ const CXXOperatorCallExpr *E2) {
+  return BinaryOperator::getOverloadedOperator(E1->getOpcode()) ==
+ E2->getOperator() &&
+ IsStructurallyEquivalent(Context, E1->getLHS(), E2->getArg(0)) &&
+ IsStructurallyEquivalent(Context, E1->getRHS(), E2->getArg(1));
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const CXXOperatorCallExpr *E1,
+ const BinaryOperator *E2) {
+  return E1->getOperator() ==
+ BinaryOperator::getOverloadedOperator(E2->getOpcode()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(0), E2->getLHS()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(1), E2->getRHS());
+}
+
 /// Determine structural equivalence of two statements.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  const Stmt *S1, const Stmt *S2) {
   if (!S1 || !S2)
 return S1 == S2;
 
+  // Check for statements with similar syntax but different AST.
+  // The unary and binary operators (like '+', '&') can be parsed as
+  // CXXOperatorCall too (and UnaryOperator or BinaryOperator).
+  // This depends on arguments with unresolved type and on the name lookup.

DonatNagyE wrote:

Could you perhaps elaborate this sentence a bit? Do I understand it correctly 
that e.g. in `CXXOperatorCallExprVsUnaryBinaryOperator` the presence of `struct 
Bar` in the second TU ensured that all the operators are parsed as 
`CXXOperatorCall`s, while in the first TU they are parsed as unary/binary 
operator expressions?

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


[clang] [clang][ASTImporter] Improve structural equivalence of overloadable operators. (PR #72242)

2023-11-24 Thread via cfe-commits


@@ -2252,6 +2252,176 @@ TEST_F(StructuralEquivalenceStmtTest, 
UnaryOperatorDifferentOps) {
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest,
+   CXXOperatorCallExprVsUnaryBinaryOperator) {
+  auto t = makeNamedDecls(
+  R"(
+  template 
+  class A;
+  template 
+  void foo(
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A y)>,
+A,
+A> y)>,
+A,
+A,
+A,
+A= y>,
+A y>,
+A,
+A,
+A,
+A,
+A,
+A* y>,
+A y>
+  );
+  )",
+  R"(
+  struct Bar {
+Bar& operator=(Bar&);
+Bar& operator->();
+  };
+
+  Bar& operator+(Bar&, Bar&);
+  Bar& operator+(Bar&);
+  Bar& operator-(Bar&, Bar&);
+  Bar& operator-(Bar&);
+  Bar& operator*(Bar&, Bar&);
+  Bar& operator*(Bar&);
+  Bar& operator/(Bar&, Bar&);
+  Bar& operator%(Bar&, Bar&);
+  Bar& operator^(Bar&, Bar&);
+  Bar& operator&(Bar&, Bar&);
+  Bar& operator&(Bar&);
+  Bar& operator|(Bar&, Bar&);
+  Bar& operator~(Bar&);
+  Bar& operator!(Bar&);
+  Bar& operator<(Bar&, Bar&);
+  Bar& operator>(Bar&, Bar&);
+  Bar& operator+=(Bar&, Bar&);
+  Bar& operator-=(Bar&, Bar&);
+  Bar& operator*=(Bar&, Bar&);
+  Bar& operator/=(Bar&, Bar&);
+  Bar& operator%=(Bar&, Bar&);
+  Bar& operator^=(Bar&, Bar&);
+  Bar& operator&=(Bar&, Bar&);
+  Bar& operator|=(Bar&, Bar&);
+  Bar& operator<<(Bar&, Bar&);
+  Bar& operator>>(Bar&, Bar&);
+  Bar& operator<<=(Bar&, Bar&);
+  Bar& operator>>=(Bar&, Bar&);
+  Bar& operator==(Bar&, Bar&);
+  Bar& operator!=(Bar&, Bar&);
+  Bar& operator<=(Bar&, Bar&);
+  Bar& operator>=(Bar&, Bar&);
+  Bar& operator<=>(Bar&, Bar&);
+  Bar& operator&&(Bar&, Bar&);
+  Bar& operator||(Bar&, Bar&);
+  Bar& operator++(Bar&);
+  Bar& operator--(Bar&);
+  Bar& operator,(Bar&, Bar&);
+  Bar& operator->*(Bar&, Bar&);
+
+  template 
+  class A;
+  template 
+  void foo(
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A y)>,
+A,
+A> y)>,
+A,
+A,
+A,
+A= y>,
+A y>,
+A,
+A,
+A,
+A,
+A,
+A* y>,
+A y>
+  );
+  )",
+  Lang_CXX20);
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest,
+   CXXOperatorCallExprVsUnaryBinaryOperatorNe) {
+  auto t = makeNamedDecls(
+  R"(
+  template 
+  class A;
+  template 
+  void foo(
+A
+  );
+  )",
+  R"(
+  struct Bar;
+
+  Bar& operator+(Bar&, Bar&);

DonatNagyE wrote:

Why is the presence of this `operator+` relevant if this TU doesn't use 
`operator+` at all?

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


[clang] [clang][ASTImporter] Improve structural equivalence of overloadable operators. (PR #72242)

2023-11-24 Thread via cfe-commits

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


[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-11-24 Thread via cfe-commits

cor3ntin wrote:

I'd like other to weight in on that but even though GCC has that flag (which 
clang recognizes and ignores), I'm, a bit reluctant to add a warning for it.
We have a policy to avoid off-by-default warnings most of the time... but more 
importantly, whether switch statements
should have a default is not something the industry seem to agree on, so it 
would be a very opinionated warning.

For example, Folks at google advise against using `default` when switching over 
an enum https://abseil.io/tips/147.
Misra requires a default statement, but makes an exception for enums. (6.4.6 in 
misra 2008)

LLVM development heavily relies on `-Wswitch-enum`, for example.

Maybe the existing tidy check is the right tool for this.
 

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


[clang] [analyzer] Use AllocaRegion in MallocChecker (PR #72402)

2023-11-24 Thread via cfe-commits
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


DonatNagyE wrote:

> I think the original `alloca(0)` warning message might be clearer/easier to 
> understand.

The difficulty is that we switch from the `SymbolicRegion` that represents the 
heap allocation to an `AllocaRegion` that doesn't have an associated symbol, 
while the code that produces the warnings about zero-allocated memory areas 
(essentially) maintains a set of _symbols_ that correspond to zero-allocated 
regions (I'd guess that this was implemented before the introduction of dynamic 
extent).

It would be possible to reintroduce the original `alloca(0)` message (while 
keeping the improvement that `alloca` returns an `AllocaRegion` and not a 
`SymbolicRegion` on the heap), but that would require significant refactoring 
(and/or ugly code duplication) and frankly I feel that `alloca` is rare and 
this would be a waste of time.

> While it might have platform or compiler dependent meaning, those behaviors 
> are non-portable, so I think it is undesirable in most cases and people 
> probably want to be notified about it.

I'd say that "non-portable" and "undesirable in most cases" is true for 
_practically all_ applications of `alloca`, not just the `alloca(0)` corner 
case. Experienced programmers who use `alloca` check that their code works with 
_their own particular_ `alloca` and wouldn't want to see generic messages that 
may or may not be relevant for them; while novices ( / projects that don't want 
to deal with `alloca` issues) would be better served by a generic "don't use 
`alloca`, it's platform-specific" warning.

> Regarding binding the return value outside of `evalCall`, I think that could 
> be addressed in a separate PR. This one does not make the current situation 
> any worse. But the very least we should add a FIXME now (and potentially open 
> a ticket), to reduce the chances of this getting forgotten.
> 
> Edit: we already have a TODO, but I think that one does not really do justice 
> to the urgency of the problem, it does not mention that doing bindings in 
> checkers outside of `evalCall` is not a good idea.

I'll spice up that TODO note; and after merging this commit I could start 
working on fixing it.

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


[clang] cf1bde3 - [clang] Fix sorting module headers (#73146)

2023-11-24 Thread via cfe-commits

Author: Tulio Magno Quites Machado Filho
Date: 2023-11-24T09:17:21-03:00
New Revision: cf1bde33423da5eb9b7dc95daac4aada3167de3c

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

LOG: [clang] Fix sorting module headers (#73146)

Struct Module::Header is not a POD type. As such, qsort() and
llvm::array_pod_sort() must not be used to sort it. This became an issue
with the new implementation of qsort() in glibc 2.39 that is not
guaranteed to be a stable sort, causing Headers to be re-ordered and
corrupted.

Replace the usage of llvm::array_pod_sort() with std::stable_sort() in
order to fix this issue. The signature of compareModuleHeaders() has to
be modified.

Fixes #73145.

Added: 


Modified: 
clang/lib/Lex/ModuleMap.cpp

Removed: 




diff  --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 00e13c9be4a7d73..1d67e275cb4775a 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -2509,9 +2509,9 @@ void ModuleMapParser::parseHeaderDecl(MMToken::TokenKind 
LeadingToken,
   << FixItHint::CreateReplacement(CurrModuleDeclLoc, "framework module");
 }
 
-static int compareModuleHeaders(const Module::Header *A,
-const Module::Header *B) {
-  return A->NameAsWritten.compare(B->NameAsWritten);
+static bool compareModuleHeaders(const Module::Header &A,
+ const Module::Header &B) {
+  return A.NameAsWritten < B.NameAsWritten;
 }
 
 /// Parse an umbrella directory declaration.
@@ -2574,7 +2574,7 @@ void ModuleMapParser::parseUmbrellaDirDecl(SourceLocation 
UmbrellaLoc) {
 }
 
 // Sort header paths so that the pcm doesn't depend on iteration order.
-llvm::array_pod_sort(Headers.begin(), Headers.end(), compareModuleHeaders);
+std::stable_sort(Headers.begin(), Headers.end(), compareModuleHeaders);
 
 for (auto &Header : Headers)
   Map.addHeader(ActiveModule, std::move(Header), ModuleMap::TextualHeader);



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


[clang] [clang] Fix sorting module headers (PR #73146)

2023-11-24 Thread Tulio Magno Quites Machado Filho via cfe-commits

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


[clang] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-11-24 Thread Paul Walker via cfe-commits

paulwalker-arm wrote:

Bike shedding here but shouldn't the header be arm_vector_types.h (i.e. 
plural)? or even arm_acle_types.h if we think it might grow more uses.

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


[clang] [analyzer] Use AllocaRegion in MallocChecker (PR #72402)

2023-11-24 Thread via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


https://github.com/DonatNagyE updated 
https://github.com/llvm/llvm-project/pull/72402

>From 703c06e2d6781c45e55d7021929a06cdb0275a14 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= 
Date: Wed, 15 Nov 2023 16:03:22 +0100
Subject: [PATCH 1/3] [analyzer] Use AllocaRegion in MallocChecker

...to model the results of alloca() and _alloca() calls. Previously it
acted as if these functions were returning memory from the heap, which
led to alpha.security.ArrayBoundV2 producing incorrect messages.
---
 .../Core/PathSensitive/SValBuilder.h  |  9 ++
 .../Checkers/BuiltinFunctionChecker.cpp   | 29 +--
 .../StaticAnalyzer/Checkers/MallocChecker.cpp | 10 ---
 clang/lib/StaticAnalyzer/Core/SValBuilder.cpp |  8 +
 clang/test/Analysis/malloc.c  | 14 +++--
 clang/test/Analysis/memory-model.cpp  |  2 +-
 .../test/Analysis/out-of-bounds-diagnostics.c |  8 ++---
 7 files changed, 52 insertions(+), 28 deletions(-)

diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
index 692c4384586569e..a64cf7ae4efcb82 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -215,6 +215,15 @@ class SValBuilder {
 const LocationContext *LCtx,
 QualType type, unsigned Count);
 
+  /// Create an SVal representing the result of an alloca()-like call, that is,
+  /// an AllocaRegion on the stack.
+  ///
+  /// After calling this function, it's a good idea to set the extent of the
+  /// returned AllocaRegion.
+  loc::MemRegionVal getAllocaRegionVal(const Expr *E,
+   const LocationContext *LCtx,
+   unsigned Count);
+
   DefinedOrUnknownSVal getDerivedRegionValueSymbolVal(
   SymbolRef parentSymbol, const TypedValueRegion *region);
 
diff --git a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
index 4a56156de4b27fe..143326c435cf815 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -81,22 +81,21 @@ bool BuiltinFunctionChecker::evalCall(const CallEvent &Call,
 
   case Builtin::BI__builtin_alloca_with_align:
   case Builtin::BI__builtin_alloca: {
-// FIXME: Refactor into StoreManager itself?
-MemRegionManager& RM = C.getStoreManager().getRegionManager();
-const AllocaRegion* R =
-  RM.getAllocaRegion(CE, C.blockCount(), C.getLocationContext());
-
-// Set the extent of the region in bytes. This enables us to use the
-// SVal of the argument directly. If we save the extent in bits, we
-// cannot represent values like symbol*8.
-auto Size = Call.getArgSVal(0);
-if (Size.isUndef())
-  return true; // Return true to model purity.
-
-state = setDynamicExtent(state, R, Size.castAs(),
- C.getSValBuilder());
+SValBuilder &SVB = C.getSValBuilder();
+const loc::MemRegionVal R =
+SVB.getAllocaRegionVal(CE, C.getLocationContext(), C.blockCount());
 
-C.addTransition(state->BindExpr(CE, LCtx, loc::MemRegionVal(R)));
+// Set the extent of the region in bytes. This enables us to use the SVal
+// of the argument directly. If we saved the extent in bits, it'd be more
+// difficult to reason about values like symbol*8.
+auto Size = Call.getArgSVal(0);
+if (auto DefSize = Size.getAs()) {
+  state = setDynamicExtent(state, R.getRegion(), *DefSize, SVB);
+  // FIXME: perhaps the following transition should be moved out of the
+  // 'if' to bind an AllocaRegion (with unknown/unspecified size) even in
+  // the unlikely case when the size argument is undefined.
+  C.addTransition(state->BindExpr(CE, LCtx, R));
+}
 return true;
   }
 
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index d3a4020280616b0..417305e26c41b09 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1731,10 +1731,12 @@ ProgramStateRef 
MallocChecker::MallocMemAux(CheckerContext &C,
   // TODO: We could rewrite post visit to eval call; 'malloc' does not have
   // side effects other than what we model here.
   unsigned Count = C.blockCount();
-  SValBuilder &svalBuilder = C.getSValBuilder();
+  SValBuilder &SVB = C.getSValBuilder();
   const LocationContext *LCtx = C.getPredecessor()->getLocationContext();
-  DefinedSVal RetVal = svalBuilder.getConjuredHeapSymbolVal(CE, LCtx, Count)
-  .castAs();
+  DefinedSVal RetVal =
+ 

[clang] [llvm] [SVE2.1][Clang][LLVM]Int/FP reduce builtin in Clang and LLVM intrinsic (PR #69926)

2023-11-24 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 d95d1c382bfc6abdf4b7764d57ba7e6098e98f5b 
436743700c92fc301a0d7df8b92d8a03cd28eecb -- 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_fp_reduce.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_int_reduce.c 
clang/test/CodeGen/arm-vector_type-params-returns.c 
clang/include/clang/Basic/TargetBuiltins.h clang/lib/CodeGen/CGBuiltin.cpp 
clang/utils/TableGen/NeonEmitter.cpp clang/utils/TableGen/SveEmitter.cpp 
clang/utils/TableGen/TableGen.cpp clang/utils/TableGen/TableGenBackends.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/utils/TableGen/NeonEmitter.cpp 
b/clang/utils/TableGen/NeonEmitter.cpp
index 03ed20d848..7aa78e15ba 100644
--- a/clang/utils/TableGen/NeonEmitter.cpp
+++ b/clang/utils/TableGen/NeonEmitter.cpp
@@ -2237,7 +2237,7 @@ static void emitNeonTypeDefs(const std::string& types, 
raw_ostream &OS) {
   for (auto &TS : TDTypeVec) {
 bool IsA64 = false;
 Type T(TS, ".");
- if (T.isDouble())
+if (T.isDouble())
   IsA64 = true;
 
 if (InIfdef && !IsA64) {

``




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


[clang] [clang] Fix sorting header paths (PR #73323)

2023-11-24 Thread Tulio Magno Quites Machado Filho via cfe-commits

https://github.com/tuliom created 
https://github.com/llvm/llvm-project/pull/73323

This code was initially written in commit
7ff29148ac7883881e62dc9e1714057c68ad4436 with the intention of sorting headers 
according to their path. At the time, the path was saved in field NameAsWritten 
of Module::Header.

Later, commit e6830b6028ec5434ccf8dbebdd992918f67b1751 added field 
PathRelativeToRootModuleDirectory to Module::Header and modified 
ModuleMapParser::parseUmbrellaDirDecl() so that it started to save the header 
path in the new field and started setting NameAsWritten = "". It didn't modify 
compareModuleHeaders() in order to adapt it to the new field.

After this commit, the sorting stopped working because it continued comparing 
only NameAsWritten.

This commit fixes it by treating NameAsWritten and 
PathRelativeToRootModuleDirectory as a tuple when comparing Module::Header.

>From 772d51724dda39baa7347f2c33af5c65786964a2 Mon Sep 17 00:00:00 2001
From: Tulio Magno Quites Machado Filho 
Date: Fri, 24 Nov 2023 09:26:12 -0300
Subject: [PATCH] [clang] Fix sorting header paths

This code was initially written in commit
7ff29148ac7883881e62dc9e1714057c68ad4436 with the intention of sorting
headers according to their path. At the time, the path was saved in
field NameAsWritten of Module::Header.

Later, commit e6830b6028ec5434ccf8dbebdd992918f67b1751 added field
PathRelativeToRootModuleDirectory to Module::Header and modified
ModuleMapParser::parseUmbrellaDirDecl() so that it started to save the
header path in the new field and started setting NameAsWritten = "".
It didn't modify compareModuleHeaders() in order to adapt it to the new
field.

After this commit, the sorting stopped working because it continued
comparing only NameAsWritten.

This commit fixes it by treating NameAsWritten and
PathRelativeToRootModuleDirectory as a tuple when comparing Module::Header.
---
 clang/lib/Lex/ModuleMap.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 1d67e275cb4775a..7bc89b2fed36bf2 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -49,6 +49,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 using namespace clang;
@@ -2511,7 +2512,8 @@ void ModuleMapParser::parseHeaderDecl(MMToken::TokenKind 
LeadingToken,
 
 static bool compareModuleHeaders(const Module::Header &A,
  const Module::Header &B) {
-  return A.NameAsWritten < B.NameAsWritten;
+  return std::tie(A.NameAsWritten, A.PathRelativeToRootModuleDirectory) <
+ std::tie(B.NameAsWritten, B.PathRelativeToRootModuleDirectory);
 }
 
 /// Parse an umbrella directory declaration.

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


[clang] [clang] Fix sorting header paths (PR #73323)

2023-11-24 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-modules

@llvm/pr-subscribers-clang

Author: Tulio Magno Quites Machado Filho (tuliom)


Changes

This code was initially written in commit
7ff29148ac7883881e62dc9e1714057c68ad4436 with the intention of sorting headers 
according to their path. At the time, the path was saved in field NameAsWritten 
of Module::Header.

Later, commit e6830b6028ec5434ccf8dbebdd992918f67b1751 added field 
PathRelativeToRootModuleDirectory to Module::Header and modified 
ModuleMapParser::parseUmbrellaDirDecl() so that it started to save the header 
path in the new field and started setting NameAsWritten = "". It didn't modify 
compareModuleHeaders() in order to adapt it to the new field.

After this commit, the sorting stopped working because it continued comparing 
only NameAsWritten.

This commit fixes it by treating NameAsWritten and 
PathRelativeToRootModuleDirectory as a tuple when comparing Module::Header.

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


1 Files Affected:

- (modified) clang/lib/Lex/ModuleMap.cpp (+3-1) 


``diff
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 1d67e275cb4775a..7bc89b2fed36bf2 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -49,6 +49,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 using namespace clang;
@@ -2511,7 +2512,8 @@ void ModuleMapParser::parseHeaderDecl(MMToken::TokenKind 
LeadingToken,
 
 static bool compareModuleHeaders(const Module::Header &A,
  const Module::Header &B) {
-  return A.NameAsWritten < B.NameAsWritten;
+  return std::tie(A.NameAsWritten, A.PathRelativeToRootModuleDirectory) <
+ std::tie(B.NameAsWritten, B.PathRelativeToRootModuleDirectory);
 }
 
 /// Parse an umbrella directory declaration.

``




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


[llvm] [clang] [SystemZ] Properly support 16 byte atomic int/fp types and ops. (PR #73134)

2023-11-24 Thread Ulrich Weigand via cfe-commits

https://github.com/uweigand commented:

Not sure about the is_lock_free results, see inline comments.

What does recent GCC return for those?

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


[llvm] [clang] [SystemZ] Properly support 16 byte atomic int/fp types and ops. (PR #73134)

2023-11-24 Thread Ulrich Weigand via cfe-commits


@@ -0,0 +1,71 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple s390x-linux-gnu -O1 -emit-llvm %s -o - | FileCheck 
%s
+//
+// Test __atomic_is_lock_free() for __int128 with default alignment (8
+// bytes), atomic alignment (16 bytes) and with a null pointer. Also test
+// __atomic_always_lock_free() and __c11_atomic_is_lock_free().
+
+#include 
+#include 
+
+__int128 Ptr_Al8   __attribute__((aligned(8)));
+__int128 Ptr_Al16 __attribute__((aligned(16)));
+
+// CHECK-LABEL: @fun_PtrAl8_is_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = tail call zeroext i1 
@__atomic_is_lock_free(i64 noundef 16, ptr noundef nonnull @Ptr_Al8) 
#[[ATTR2:[0-9]+]]
+// CHECK-NEXT:ret i1 [[CALL]]
+//
+_Bool fun_PtrAl8_is_lock_free() {
+  return __atomic_is_lock_free(16, &Ptr_Al8);
+}
+
+// CHECK-LABEL: @fun_PtrAl8_always_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i1 false
+//
+_Bool fun_PtrAl8_always_lock_free() {
+  return __atomic_always_lock_free(16, &Ptr_Al8);
+}
+
+// CHECK-LABEL: @fun_PtrAl16_is_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = tail call zeroext i1 
@__atomic_is_lock_free(i64 noundef 16, ptr noundef nonnull @Ptr_Al16) #[[ATTR2]]

uweigand wrote:

Here I would have expected `true`, assuming the compiler correctly figures out 
the object is 16-byte aligned.

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


[clang] [llvm] [SystemZ] Properly support 16 byte atomic int/fp types and ops. (PR #73134)

2023-11-24 Thread Ulrich Weigand via cfe-commits


@@ -0,0 +1,71 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple s390x-linux-gnu -O1 -emit-llvm %s -o - | FileCheck 
%s
+//
+// Test __atomic_is_lock_free() for __int128 with default alignment (8
+// bytes), atomic alignment (16 bytes) and with a null pointer. Also test
+// __atomic_always_lock_free() and __c11_atomic_is_lock_free().
+
+#include 
+#include 
+
+__int128 Ptr_Al8   __attribute__((aligned(8)));
+__int128 Ptr_Al16 __attribute__((aligned(16)));
+
+// CHECK-LABEL: @fun_PtrAl8_is_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = tail call zeroext i1 
@__atomic_is_lock_free(i64 noundef 16, ptr noundef nonnull @Ptr_Al8) 
#[[ATTR2:[0-9]+]]
+// CHECK-NEXT:ret i1 [[CALL]]
+//
+_Bool fun_PtrAl8_is_lock_free() {
+  return __atomic_is_lock_free(16, &Ptr_Al8);
+}
+
+// CHECK-LABEL: @fun_PtrAl8_always_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i1 false
+//
+_Bool fun_PtrAl8_always_lock_free() {
+  return __atomic_always_lock_free(16, &Ptr_Al8);
+}
+
+// CHECK-LABEL: @fun_PtrAl16_is_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = tail call zeroext i1 
@__atomic_is_lock_free(i64 noundef 16, ptr noundef nonnull @Ptr_Al16) #[[ATTR2]]
+// CHECK-NEXT:ret i1 [[CALL]]
+//
+_Bool fun_PtrAl16_is_lock_free() {
+  return __atomic_is_lock_free(16, &Ptr_Al16);
+}
+
+// CHECK-LABEL: @fun_PtrAl16_always_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i1 false
+//
+_Bool fun_PtrAl16_always_lock_free() {
+  return __atomic_always_lock_free(16, &Ptr_Al16);
+}
+
+// CHECK-LABEL: @fun_noptr_is_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i1 true
+//
+_Bool fun_noptr_is_lock_free() {
+  return __atomic_is_lock_free(16, 0);

uweigand wrote:

But this seems actually incorrect - when using *default* assumptions, the 
operation should *not* be lock-free ...

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


[clang] [llvm] [SystemZ] Properly support 16 byte atomic int/fp types and ops. (PR #73134)

2023-11-24 Thread Ulrich Weigand via cfe-commits

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


[clang] [llvm] [SystemZ] Properly support 16 byte atomic int/fp types and ops. (PR #73134)

2023-11-24 Thread Ulrich Weigand via cfe-commits

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


[clang] fix: C++ empty record with align lead to va_list out of sync (PR #72197)

2023-11-24 Thread via cfe-commits


@@ -307,7 +307,12 @@ AArch64ABIInfo::classifyArgumentType(QualType Ty, bool 
IsVariadic,
 // 0.
 if (IsEmpty && Size == 0)
   return ABIArgInfo::getIgnore();
-return ABIArgInfo::getDirect(llvm::Type::getInt8Ty(getVMContext()));
+// An empty struct can have size greater than one byte if alignment is
+// involved.
+// When size <= 64, we still hold it by i8 in IR and lowering to registers.
+// When Size > 64, just fall through to avoid va_list out of sync.

hstk30-hw wrote:

https://github.com/llvm/llvm-project/commit/9bb857a4f1aec1c33d599672defb46b98d792719#diff-d5392fbd34fbb607cc468738adce16985f9461c9a3f5bc7c5ed64dba44137d19R3752
 This is I can found when  the `i8` was introduced. Guess @TNorthover know it.

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


[clang] fix: C++ empty record with align lead to va_list out of sync (PR #72197)

2023-11-24 Thread via cfe-commits

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


[clang] e8cd401 - Remove extraneous ` in AttrDocs.td

2023-11-24 Thread via cfe-commits

Author: Utkarsh Saxena
Date: 2023-11-24T14:21:45+01:00
New Revision: e8cd401eaefe8113cae4b4f85ee78600925a9481

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

LOG: Remove extraneous ` in AttrDocs.td

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index cfd806aa3a029be..be74535e28d8a60 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7585,7 +7585,7 @@ def CoroLifetimeBoundDoc : Documentation {
   let Category = DocCatDecl;
   let Content = [{
 The ``[[clang::coro_lifetimebound]]`` is a class attribute which can be applied
-to a `coroutine return type (`CRT`_) (i.e.
+to a coroutine return type (`CRT`_) (i.e.
 it should also be annotated with ``[[clang::coro_return_type]]``).
 
 All parameters of a function are considered to be lifetime bound. See 
`documentation`_



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


[clang] [llvm] [SystemZ] Properly support 16 byte atomic int/fp types and ops. (PR #73134)

2023-11-24 Thread Jonas Paulsson via cfe-commits


@@ -0,0 +1,71 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple s390x-linux-gnu -O1 -emit-llvm %s -o - | FileCheck 
%s
+//
+// Test __atomic_is_lock_free() for __int128 with default alignment (8
+// bytes), atomic alignment (16 bytes) and with a null pointer. Also test
+// __atomic_always_lock_free() and __c11_atomic_is_lock_free().
+
+#include 
+#include 
+
+__int128 Ptr_Al8   __attribute__((aligned(8)));
+__int128 Ptr_Al16 __attribute__((aligned(16)));
+
+// CHECK-LABEL: @fun_PtrAl8_is_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = tail call zeroext i1 
@__atomic_is_lock_free(i64 noundef 16, ptr noundef nonnull @Ptr_Al8) 
#[[ATTR2:[0-9]+]]
+// CHECK-NEXT:ret i1 [[CALL]]
+//
+_Bool fun_PtrAl8_is_lock_free() {
+  return __atomic_is_lock_free(16, &Ptr_Al8);
+}
+
+// CHECK-LABEL: @fun_PtrAl8_always_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i1 false
+//
+_Bool fun_PtrAl8_always_lock_free() {
+  return __atomic_always_lock_free(16, &Ptr_Al8);
+}
+
+// CHECK-LABEL: @fun_PtrAl16_is_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = tail call zeroext i1 
@__atomic_is_lock_free(i64 noundef 16, ptr noundef nonnull @Ptr_Al16) #[[ATTR2]]

JonPsson1 wrote:

fun_PtrAl16_is_lock_free:
GCC returns true

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


[clang] [llvm] [SystemZ] Properly support 16 byte atomic int/fp types and ops. (PR #73134)

2023-11-24 Thread Jonas Paulsson via cfe-commits


@@ -0,0 +1,71 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple s390x-linux-gnu -O1 -emit-llvm %s -o - | FileCheck 
%s
+//
+// Test __atomic_is_lock_free() for __int128 with default alignment (8
+// bytes), atomic alignment (16 bytes) and with a null pointer. Also test
+// __atomic_always_lock_free() and __c11_atomic_is_lock_free().
+
+#include 
+#include 
+
+__int128 Ptr_Al8   __attribute__((aligned(8)));
+__int128 Ptr_Al16 __attribute__((aligned(16)));
+
+// CHECK-LABEL: @fun_PtrAl8_is_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = tail call zeroext i1 
@__atomic_is_lock_free(i64 noundef 16, ptr noundef nonnull @Ptr_Al8) 
#[[ATTR2:[0-9]+]]
+// CHECK-NEXT:ret i1 [[CALL]]
+//
+_Bool fun_PtrAl8_is_lock_free() {
+  return __atomic_is_lock_free(16, &Ptr_Al8);
+}
+
+// CHECK-LABEL: @fun_PtrAl8_always_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i1 false
+//
+_Bool fun_PtrAl8_always_lock_free() {
+  return __atomic_always_lock_free(16, &Ptr_Al8);
+}
+
+// CHECK-LABEL: @fun_PtrAl16_is_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = tail call zeroext i1 
@__atomic_is_lock_free(i64 noundef 16, ptr noundef nonnull @Ptr_Al16) #[[ATTR2]]
+// CHECK-NEXT:ret i1 [[CALL]]
+//
+_Bool fun_PtrAl16_is_lock_free() {
+  return __atomic_is_lock_free(16, &Ptr_Al16);
+}
+
+// CHECK-LABEL: @fun_PtrAl16_always_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i1 false
+//
+_Bool fun_PtrAl16_always_lock_free() {
+  return __atomic_always_lock_free(16, &Ptr_Al16);
+}
+
+// CHECK-LABEL: @fun_noptr_is_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i1 true
+//
+_Bool fun_noptr_is_lock_free() {
+  return __atomic_is_lock_free(16, 0);

JonPsson1 wrote:

fun_noptr_is_lock_free:
GCC returns true.

GCC: (GNU) 14.0.0 20231121 (experimental)

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


[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)

2023-11-24 Thread Lu Weining via cfe-commits

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


[clang] [Clang] Emit TBAA info for enums in C (PR #73326)

2023-11-24 Thread David Sherwood via cfe-commits

https://github.com/david-arm created 
https://github.com/llvm/llvm-project/pull/73326

When emitting TBAA information for enums in C code we currently just treat the 
data as an 'omnipotent char'. However, with C strict aliasing this means we 
fail to optimise certain cases. For example, in the SPEC2017 xz benchmark there 
are structs that contain arrays of enums, and clang pessmistically assumes that 
accesses to those enums could alias with other struct members that have a 
different type.

According to

https://en.cppreference.com/w/c/language/enum

enums should be treated as 'int' types unless
explicitly specified (C23) or if 'int' would not be large enough to hold all 
the enumerated values. In the latter case the compiler is free to choose a 
suitable integer that would hold all such values.

When compiling C code this patch generates TBAA
information for the enum by using an equivalent integer of the size clang has 
already chosen for the enum. I have ignored C++ for now because the rules are 
more complex.

New test added here:

  clang/test/CodeGen/tbaa.c

>From af76f6b6b3469fd0f5f24427c5a175c8d9d7c83a Mon Sep 17 00:00:00 2001
From: David Sherwood 
Date: Fri, 24 Nov 2023 13:20:23 +
Subject: [PATCH] [Clang] Emit TBAA info for enums in C

When emitting TBAA information for enums in C code we
currently just treat the data as an 'omnipotent char'.
However, with C strict aliasing this means we fail to
optimise certain cases. For example, in the SPEC2017
xz benchmark there are structs that contain arrays of
enums, and clang pessmistically assumes that accesses
to those enums could alias with other struct members
that have a different type.

According to

https://en.cppreference.com/w/c/language/enum

enums should be treated as 'int' types unless
explicitly specified (C23) or if 'int' would not be
large enough to hold all the enumerated values. In the
latter case the compiler is free to choose a suitable
integer that would hold all such values.

When compiling C code this patch generates TBAA
information for the enum by using an equivalent integer
of the size clang has already chosen for the enum. I
have ignored C++ for now because the rules are more
complex.

New test added here:

  clang/test/CodeGen/tbaa.c
---
 clang/lib/CodeGen/CodeGenTBAA.cpp |   5 +-
 clang/test/CodeGen/tbaa.c | 116 ++
 2 files changed, 120 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/tbaa.c

diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 8705d3d65f1a573..f59d3d422d5209d 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -196,11 +196,14 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type 
*Ty) {
   // Enum types are distinct types. In C++ they have "underlying types",
   // however they aren't related for TBAA.
   if (const EnumType *ETy = dyn_cast(Ty)) {
+if (!Features.CPlusPlus)
+  return getTypeInfo(Context.getIntTypeForBitwidth(Size * 8, 0));
+
 // In C++ mode, types have linkage, so we can rely on the ODR and
 // on their mangled names, if they're external.
 // TODO: Is there a way to get a program-wide unique name for a
 // decl with local linkage or no linkage?
-if (!Features.CPlusPlus || !ETy->getDecl()->isExternallyVisible())
+if (!ETy->getDecl()->isExternallyVisible())
   return getChar();
 
 SmallString<256> OutName;
diff --git a/clang/test/CodeGen/tbaa.c b/clang/test/CodeGen/tbaa.c
new file mode 100644
index 000..0ab81f60a71941c
--- /dev/null
+++ b/clang/test/CodeGen/tbaa.c
@@ -0,0 +1,116 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -no-struct-path-tbaa 
-disable-llvm-passes %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -disable-llvm-passes %s 
-emit-llvm -o - | FileCheck %s -check-prefixes=PATH
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O0 -disable-llvm-passes %s 
-emit-llvm -o - | FileCheck %s -check-prefix=NO-TBAA
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -relaxed-aliasing 
-disable-llvm-passes %s -emit-llvm -o - | FileCheck %s -check-prefix=NO-TBAA
+// Test TBAA metadata generated by front-end.
+//
+// NO-TBAA-NOT: !tbaa
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+
+typedef enum {
+  RED_AUTO_32,
+  GREEN_AUTO_32,
+  BLUE_AUTO_32
+} EnumAuto32;
+
+typedef enum {
+  RED_AUTO_64,
+  GREEN_AUTO_64,
+  BLUE_AUTO_64 = 0x1ull
+} EnumAuto64;
+
+typedef enum : uint16_t {
+  RED_16,
+  GREEN_16,
+  BLUE_16
+} Enum16;
+
+typedef enum : uint8_t {
+  RED_8,
+  GREEN_8,
+  BLUE_8
+} Enum8;
+
+uint32_t g0(EnumAuto32 *E, uint32_t *val) {
+// CHECK-LABEL: define{{.*}} i32 @g0(
+// CHECK: store i32 5, ptr %{{.*}}, align 4, !tbaa [[TAG_i32:!.*]]
+// CHECK: store i32 0, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
+// CHECK: load i32, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]

[clang] [Clang] Emit TBAA info for enums in C (PR #73326)

2023-11-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: David Sherwood (david-arm)


Changes

When emitting TBAA information for enums in C code we currently just treat the 
data as an 'omnipotent char'. However, with C strict aliasing this means we 
fail to optimise certain cases. For example, in the SPEC2017 xz benchmark there 
are structs that contain arrays of enums, and clang pessmistically assumes that 
accesses to those enums could alias with other struct members that have a 
different type.

According to

https://en.cppreference.com/w/c/language/enum

enums should be treated as 'int' types unless
explicitly specified (C23) or if 'int' would not be large enough to hold all 
the enumerated values. In the latter case the compiler is free to choose a 
suitable integer that would hold all such values.

When compiling C code this patch generates TBAA
information for the enum by using an equivalent integer of the size clang has 
already chosen for the enum. I have ignored C++ for now because the rules are 
more complex.

New test added here:

  clang/test/CodeGen/tbaa.c

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenTBAA.cpp (+4-1) 
- (added) clang/test/CodeGen/tbaa.c (+116) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 8705d3d65f1a573..f59d3d422d5209d 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -196,11 +196,14 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type 
*Ty) {
   // Enum types are distinct types. In C++ they have "underlying types",
   // however they aren't related for TBAA.
   if (const EnumType *ETy = dyn_cast(Ty)) {
+if (!Features.CPlusPlus)
+  return getTypeInfo(Context.getIntTypeForBitwidth(Size * 8, 0));
+
 // In C++ mode, types have linkage, so we can rely on the ODR and
 // on their mangled names, if they're external.
 // TODO: Is there a way to get a program-wide unique name for a
 // decl with local linkage or no linkage?
-if (!Features.CPlusPlus || !ETy->getDecl()->isExternallyVisible())
+if (!ETy->getDecl()->isExternallyVisible())
   return getChar();
 
 SmallString<256> OutName;
diff --git a/clang/test/CodeGen/tbaa.c b/clang/test/CodeGen/tbaa.c
new file mode 100644
index 000..0ab81f60a71941c
--- /dev/null
+++ b/clang/test/CodeGen/tbaa.c
@@ -0,0 +1,116 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -no-struct-path-tbaa 
-disable-llvm-passes %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -disable-llvm-passes %s 
-emit-llvm -o - | FileCheck %s -check-prefixes=PATH
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O0 -disable-llvm-passes %s 
-emit-llvm -o - | FileCheck %s -check-prefix=NO-TBAA
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -relaxed-aliasing 
-disable-llvm-passes %s -emit-llvm -o - | FileCheck %s -check-prefix=NO-TBAA
+// Test TBAA metadata generated by front-end.
+//
+// NO-TBAA-NOT: !tbaa
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+
+typedef enum {
+  RED_AUTO_32,
+  GREEN_AUTO_32,
+  BLUE_AUTO_32
+} EnumAuto32;
+
+typedef enum {
+  RED_AUTO_64,
+  GREEN_AUTO_64,
+  BLUE_AUTO_64 = 0x1ull
+} EnumAuto64;
+
+typedef enum : uint16_t {
+  RED_16,
+  GREEN_16,
+  BLUE_16
+} Enum16;
+
+typedef enum : uint8_t {
+  RED_8,
+  GREEN_8,
+  BLUE_8
+} Enum8;
+
+uint32_t g0(EnumAuto32 *E, uint32_t *val) {
+// CHECK-LABEL: define{{.*}} i32 @g0(
+// CHECK: store i32 5, ptr %{{.*}}, align 4, !tbaa [[TAG_i32:!.*]]
+// CHECK: store i32 0, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
+// CHECK: load i32, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
+// PATH-LABEL: define{{.*}} i32 @g0(
+// PATH: store i32 5, ptr %{{.*}}, align 4, !tbaa [[TAG_i32:!.*]]
+// PATH: store i32 0, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
+// PATH: load i32, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
+  *val = 5;
+  *E = RED_AUTO_32;
+  return *val;
+}
+
+uint64_t g1(EnumAuto64 *E, uint64_t *val) {
+// CHECK-LABEL: define{{.*}} i64 @g1(
+// CHECK: store i64 5, ptr %{{.*}}, align 8, !tbaa [[TAG_i64:!.*]]
+// CHECK: store i64 0, ptr %{{.*}}, align 8, !tbaa [[TAG_long:!.*]]
+// CHECK: load i64, ptr %{{.*}}, align 8, !tbaa [[TAG_i64]]
+// PATH-LABEL: define{{.*}} i64 @g1(
+// PATH: store i64 5, ptr %{{.*}}, align 8, !tbaa [[TAG_i64:!.*]]
+// PATH: store i64 0, ptr %{{.*}}, align 8, !tbaa [[TAG_long:!.*]]
+// PATH: load i64, ptr %{{.*}}, align 8, !tbaa [[TAG_i64]]
+  *val = 5;
+  *E = RED_AUTO_64;
+  return *val;
+}
+
+uint16_t g2(Enum16 *E, uint16_t *val) {
+// CHECK-LABEL: define{{.*}} i16 @g2(
+// CHECK: store i16 5, ptr %{{.*}}, align 2, !tbaa [[TAG_i16:!.*]]
+// CHECK: store i16 0, ptr %{{.*}}, align 2, !tbaa [[TAG_i16]]
+// CHECK: load i16, ptr %{{.*}}, align 2, !tbaa [[TAG_i16]]
+// PATH-LABEL: define{{.*}} i16 @g2(
+// PA

[clang] [Clang] Emit TBAA info for enums in C (PR #73326)

2023-11-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: David Sherwood (david-arm)


Changes

When emitting TBAA information for enums in C code we currently just treat the 
data as an 'omnipotent char'. However, with C strict aliasing this means we 
fail to optimise certain cases. For example, in the SPEC2017 xz benchmark there 
are structs that contain arrays of enums, and clang pessmistically assumes that 
accesses to those enums could alias with other struct members that have a 
different type.

According to

https://en.cppreference.com/w/c/language/enum

enums should be treated as 'int' types unless
explicitly specified (C23) or if 'int' would not be large enough to hold all 
the enumerated values. In the latter case the compiler is free to choose a 
suitable integer that would hold all such values.

When compiling C code this patch generates TBAA
information for the enum by using an equivalent integer of the size clang has 
already chosen for the enum. I have ignored C++ for now because the rules are 
more complex.

New test added here:

  clang/test/CodeGen/tbaa.c

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenTBAA.cpp (+4-1) 
- (added) clang/test/CodeGen/tbaa.c (+116) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 8705d3d65f1a573..f59d3d422d5209d 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -196,11 +196,14 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type 
*Ty) {
   // Enum types are distinct types. In C++ they have "underlying types",
   // however they aren't related for TBAA.
   if (const EnumType *ETy = dyn_cast(Ty)) {
+if (!Features.CPlusPlus)
+  return getTypeInfo(Context.getIntTypeForBitwidth(Size * 8, 0));
+
 // In C++ mode, types have linkage, so we can rely on the ODR and
 // on their mangled names, if they're external.
 // TODO: Is there a way to get a program-wide unique name for a
 // decl with local linkage or no linkage?
-if (!Features.CPlusPlus || !ETy->getDecl()->isExternallyVisible())
+if (!ETy->getDecl()->isExternallyVisible())
   return getChar();
 
 SmallString<256> OutName;
diff --git a/clang/test/CodeGen/tbaa.c b/clang/test/CodeGen/tbaa.c
new file mode 100644
index 000..0ab81f60a71941c
--- /dev/null
+++ b/clang/test/CodeGen/tbaa.c
@@ -0,0 +1,116 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -no-struct-path-tbaa 
-disable-llvm-passes %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -disable-llvm-passes %s 
-emit-llvm -o - | FileCheck %s -check-prefixes=PATH
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O0 -disable-llvm-passes %s 
-emit-llvm -o - | FileCheck %s -check-prefix=NO-TBAA
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -relaxed-aliasing 
-disable-llvm-passes %s -emit-llvm -o - | FileCheck %s -check-prefix=NO-TBAA
+// Test TBAA metadata generated by front-end.
+//
+// NO-TBAA-NOT: !tbaa
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+
+typedef enum {
+  RED_AUTO_32,
+  GREEN_AUTO_32,
+  BLUE_AUTO_32
+} EnumAuto32;
+
+typedef enum {
+  RED_AUTO_64,
+  GREEN_AUTO_64,
+  BLUE_AUTO_64 = 0x1ull
+} EnumAuto64;
+
+typedef enum : uint16_t {
+  RED_16,
+  GREEN_16,
+  BLUE_16
+} Enum16;
+
+typedef enum : uint8_t {
+  RED_8,
+  GREEN_8,
+  BLUE_8
+} Enum8;
+
+uint32_t g0(EnumAuto32 *E, uint32_t *val) {
+// CHECK-LABEL: define{{.*}} i32 @g0(
+// CHECK: store i32 5, ptr %{{.*}}, align 4, !tbaa [[TAG_i32:!.*]]
+// CHECK: store i32 0, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
+// CHECK: load i32, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
+// PATH-LABEL: define{{.*}} i32 @g0(
+// PATH: store i32 5, ptr %{{.*}}, align 4, !tbaa [[TAG_i32:!.*]]
+// PATH: store i32 0, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
+// PATH: load i32, ptr %{{.*}}, align 4, !tbaa [[TAG_i32]]
+  *val = 5;
+  *E = RED_AUTO_32;
+  return *val;
+}
+
+uint64_t g1(EnumAuto64 *E, uint64_t *val) {
+// CHECK-LABEL: define{{.*}} i64 @g1(
+// CHECK: store i64 5, ptr %{{.*}}, align 8, !tbaa [[TAG_i64:!.*]]
+// CHECK: store i64 0, ptr %{{.*}}, align 8, !tbaa [[TAG_long:!.*]]
+// CHECK: load i64, ptr %{{.*}}, align 8, !tbaa [[TAG_i64]]
+// PATH-LABEL: define{{.*}} i64 @g1(
+// PATH: store i64 5, ptr %{{.*}}, align 8, !tbaa [[TAG_i64:!.*]]
+// PATH: store i64 0, ptr %{{.*}}, align 8, !tbaa [[TAG_long:!.*]]
+// PATH: load i64, ptr %{{.*}}, align 8, !tbaa [[TAG_i64]]
+  *val = 5;
+  *E = RED_AUTO_64;
+  return *val;
+}
+
+uint16_t g2(Enum16 *E, uint16_t *val) {
+// CHECK-LABEL: define{{.*}} i16 @g2(
+// CHECK: store i16 5, ptr %{{.*}}, align 2, !tbaa [[TAG_i16:!.*]]
+// CHECK: store i16 0, ptr %{{.*}}, align 2, !tbaa [[TAG_i16]]
+// CHECK: load i16, ptr %{{.*}}, align 2, !tbaa [[TAG_i16]]
+// PATH-LABEL: define{{.*}} i16 @g2(
+// PATH: stor

[clang] [Clang] Emit TBAA info for enums in C (PR #73326)

2023-11-24 Thread David Sherwood via cfe-commits

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


[clang] [Clang] Emit TBAA info for enums in C (PR #73326)

2023-11-24 Thread David Sherwood via cfe-commits


@@ -196,11 +196,14 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type 
*Ty) {
   // Enum types are distinct types. In C++ they have "underlying types",
   // however they aren't related for TBAA.
   if (const EnumType *ETy = dyn_cast(Ty)) {
+if (!Features.CPlusPlus)
+  return getTypeInfo(Context.getIntTypeForBitwidth(Size * 8, 0));

david-arm wrote:

I am not sure if this is entirely correct so would appreciate some guidance 
here!

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


[clang] 3d8a910 - [clang][ASTImporter] Fix import of SubstTemplateTypeParmType in return type of function. (#69724)

2023-11-24 Thread via cfe-commits

Author: Balázs Kéri
Date: 2023-11-24T14:35:10+01:00
New Revision: 3d8a9105d7e0e4baa744428e55d1c2462803118a

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

LOG: [clang][ASTImporter] Fix import of SubstTemplateTypeParmType in return 
type of function. (#69724)

Import of a function with `auto` return type that is expanded to a
`SubstTemplateTypeParmType` could fail if the function itself is the
template specialization where the parameter was replaced.

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index c4e931e220f69b5..3dc33c10af11edf 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -3513,6 +3513,14 @@ class IsTypeDeclaredInsideVisitor
 return {};
   }
 
+  std::optional
+  VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
+// The "associated declaration" can be the same as ParentDC.
+if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
+  return true;
+return {};
+  }
+
   std::optional VisitConstantArrayType(const ConstantArrayType *T) {
 if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, 
T->getSizeExpr()))
   return true;
@@ -3573,6 +3581,8 @@ class IsTypeDeclaredInsideVisitor
 };
 } // namespace
 
+/// This function checks if the function has 'auto' return type that contains
+/// a reference (in any way) to a declaration inside the same function.
 bool ASTNodeImporter::hasAutoReturnTypeDeclaredInside(FunctionDecl *D) {
   QualType FromTy = D->getType();
   const auto *FromFPT = FromTy->getAs();

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 5f4d8d040772cb1..902b740a5106c0d 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -6790,10 +6790,13 @@ TEST_P(ASTImporterOptionSpecificTestBase,
 }
 
 struct ImportAutoFunctions : ASTImporterOptionSpecificTestBase {
-  void testImport(llvm::StringRef Code, clang::TestLanguage Lang = Lang_CXX14) 
{
+  void testImport(llvm::StringRef Code, clang::TestLanguage Lang = Lang_CXX14,
+  bool FindLast = false) {
 Decl *FromTU = getTuDecl(Code, Lang, "input0.cc");
-FunctionDecl *From = FirstDeclMatcher().match(
-FromTU, functionDecl(hasName("foo")));
+FunctionDecl *From = FindLast ? LastDeclMatcher().match(
+FromTU, functionDecl(hasName("foo")))
+  : FirstDeclMatcher().match(
+FromTU, functionDecl(hasName("foo")));
 
 FunctionDecl *To = Import(From, Lang);
 EXPECT_TRUE(To);
@@ -7232,6 +7235,20 @@ TEST_P(ImportAutoFunctions, ReturnWithTypeInSwitch) {
   Lang_CXX17);
 }
 
+TEST_P(ImportAutoFunctions, ReturnWithAutoTemplateType) {
+  testImport(
+  R"(
+  template
+  struct S {};
+  template
+  auto foo() {
+return S{};
+  }
+  auto a = foo();
+  )",
+  Lang_CXX14, /*FindLast=*/true);
+}
+
 struct ImportSourceLocations : ASTImporterOptionSpecificTestBase {};
 
 TEST_P(ImportSourceLocations, PreserveFileIDTreeStructure) {



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


[clang] [clang][ASTImporter] Fix import of SubstTemplateTypeParmType in return type of function. (PR #69724)

2023-11-24 Thread Balázs Kéri via cfe-commits

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


[clang] [llvm] [SystemZ] Properly support 16 byte atomic int/fp types and ops. (PR #73134)

2023-11-24 Thread Jonas Paulsson via cfe-commits


@@ -0,0 +1,71 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple s390x-linux-gnu -O1 -emit-llvm %s -o - | FileCheck 
%s
+//
+// Test __atomic_is_lock_free() for __int128 with default alignment (8
+// bytes), atomic alignment (16 bytes) and with a null pointer. Also test
+// __atomic_always_lock_free() and __c11_atomic_is_lock_free().
+
+#include 
+#include 
+
+__int128 Ptr_Al8   __attribute__((aligned(8)));
+__int128 Ptr_Al16 __attribute__((aligned(16)));
+
+// CHECK-LABEL: @fun_PtrAl8_is_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = tail call zeroext i1 
@__atomic_is_lock_free(i64 noundef 16, ptr noundef nonnull @Ptr_Al8) 
#[[ATTR2:[0-9]+]]
+// CHECK-NEXT:ret i1 [[CALL]]
+//
+_Bool fun_PtrAl8_is_lock_free() {
+  return __atomic_is_lock_free(16, &Ptr_Al8);
+}
+
+// CHECK-LABEL: @fun_PtrAl8_always_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i1 false
+//
+_Bool fun_PtrAl8_always_lock_free() {
+  return __atomic_always_lock_free(16, &Ptr_Al8);
+}
+
+// CHECK-LABEL: @fun_PtrAl16_is_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = tail call zeroext i1 
@__atomic_is_lock_free(i64 noundef 16, ptr noundef nonnull @Ptr_Al16) #[[ATTR2]]
+// CHECK-NEXT:ret i1 [[CALL]]
+//
+_Bool fun_PtrAl16_is_lock_free() {
+  return __atomic_is_lock_free(16, &Ptr_Al16);
+}
+
+// CHECK-LABEL: @fun_PtrAl16_always_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i1 false
+//
+_Bool fun_PtrAl16_always_lock_free() {
+  return __atomic_always_lock_free(16, &Ptr_Al16);
+}
+
+// CHECK-LABEL: @fun_noptr_is_lock_free(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i1 true
+//
+_Bool fun_noptr_is_lock_free() {
+  return __atomic_is_lock_free(16, 0);

JonPsson1 wrote:

Hmm, it seems that GCC is returning true for all of these in this test case, 
probably because the way it is written: the Ptr_Al8 is placed after the 16-byte 
aligned Ptr_Al16, so Ptr_Al8 also gets the greater (over)alignment.

Maybe I should try these in two separate files instead.

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


[clang] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2 (PR #72107)

2023-11-24 Thread via cfe-commits


@@ -34,20 +34,37 @@ using llvm::formatv;
 namespace {
 enum OOB_Kind { OOB_Precedes, OOB_Exceeds, OOB_Taint };
 
-class ArrayBoundCheckerV2 :
-public Checker {
+struct Messages {
+  std::string Short, Full;
+};
+
+class ArrayBoundCheckerV2 : public Checker,
+   check::PostStmt,
+   check::PostStmt> {
   BugType BT{this, "Out-of-bound access"};
   BugType TaintBT{this, "Out-of-bound access", categories::TaintedData};
 
+  void performCheck(const Expr *E, CheckerContext &C) const;
+
   void reportOOB(CheckerContext &C, ProgramStateRef ErrorState, OOB_Kind Kind,
- NonLoc Offset, std::string RegName, std::string Msg) const;
+ NonLoc Offset, Messages Msgs) const;
 
   static bool isFromCtypeMacro(const Stmt *S, ASTContext &AC);
 
 public:
-  void checkLocation(SVal l, bool isLoad, const Stmt *S,
- CheckerContext &C) const;
+  void checkPostStmt(const ArraySubscriptExpr *E, CheckerContext &C) const {

DonatNagyE wrote:

Actually there **was** a reason for using `PostStmt`: I'm using 
`CheckerContext::getSVal(const Expr *)` to get the _result_ of the analyzed 
subscript/dereference expression, and that's not yet available in the `PreStmt` 
callback. I could switch to `PreStmt` if I reimplemented the evaluation of 
these statements, but I don't think that it has any concrete advantages. I'll 
probably add a comment to mention this.

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


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-24 Thread Michael Klemm via cfe-commits


@@ -0,0 +1,13 @@
+! RUN: %clang -x c -o %t.c-part -c %s.c-part

mjklemm wrote:

That has worked.  I haven't thought about that at all, so many thanks for the 
suggestion.  This greatly simplifies things!

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


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-24 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm updated 
https://github.com/llvm/llvm-project/pull/73124

>From ba38aec7ac04c63fd5167908fe7f91d6ac7bceed Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 14:22:20 +0100
Subject: [PATCH 1/9] Let the linker fail on multiple definitions of main()

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 5d2cd1959b06925..30c249d05677ce5 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1018,7 +1018,20 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, 
const ArgList &Args,
   break;
 }
   } else {
+// --whole-archive needs to be part of the link line to make sure
+// that the main() function from Fortran_main.a is pulled in by
+// the linker.
+//
+// We are using this --whole-archive/--no-whole-archive bracket w/o
+// any further checks, because -Wl,--whole-archive at the flang-new new
+// line will not sucessfully complete, unless the user correctly specified
+// -Wl,--no-whole-archive (e.g., -Wl,--whole-archive -ldummy
+// -Wl,--no-whole-archive).
+CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lFortran_main");
+CmdArgs.push_back("--no-whole-archive");
+
+// Perform regular linkage of the remaining runtime libraries.
 CmdArgs.push_back("-lFortranRuntime");
 CmdArgs.push_back("-lFortranDecimal");
   }
@@ -1029,7 +1042,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain 
&TC,
  ArgStringList &CmdArgs) {
   // Default to the /../lib directory. This works fine on the
   // platforms that we have tested so far. We will probably have to re-fine
-  // this in the future. In particular, on some platforms, we may need to use
+  // this in the future. In particular, on some platforms, we may need to useq
   // lib64 instead of lib.
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);

>From 7d1180b11ed02cedf1c9fea56bf2ff329274c066 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 15:18:51 +0100
Subject: [PATCH 2/9] Improve comments and remove accidental typo

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 30c249d05677ce5..12e3ce184898250 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1023,10 +1023,10 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, 
const ArgList &Args,
 // the linker.
 //
 // We are using this --whole-archive/--no-whole-archive bracket w/o
-// any further checks, because -Wl,--whole-archive at the flang-new new
-// line will not sucessfully complete, unless the user correctly specified
-// -Wl,--no-whole-archive (e.g., -Wl,--whole-archive -ldummy
-// -Wl,--no-whole-archive).
+// any further checks, because -Wl,--whole-archive at the flang
+// driver's link line will not sucessfully complete, unless the user
+// correctly specified -Wl,--whole-archive/-Wl,--no-whole-archive
+// (e.g., -Wl,--whole-archive -ldummy -Wl,--no-whole-archive).
 CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lFortran_main");
 CmdArgs.push_back("--no-whole-archive");
@@ -1042,7 +1042,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain 
&TC,
  ArgStringList &CmdArgs) {
   // Default to the /../lib directory. This works fine on the
   // platforms that we have tested so far. We will probably have to re-fine
-  // this in the future. In particular, on some platforms, we may need to useq
+  // this in the future. In particular, on some platforms, we may need to use
   // lib64 instead of lib.
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);

>From 30dab7ebddf1de4836fc3d532fc33b4a7e58837d Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 20:26:02 +0100
Subject: [PATCH 3/9] Correct link line test for flang-new (for Linux)

---
 flang/test/Driver/linker-flags.f90 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index a1417057d4da068..55b13952db43c17 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -31,7 +31,7 @@
 !   executable and may find the GNU linker from MinGW or Cygwin.
 ! UNIX-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! UNIX-SAME: "[[object_file]]"
-! UNIX-SAME: "-lFortran_main" "-lFortranRuntime" "-lFortranDecimal" "-lm"
+! UNIX-SAME: "--whole-archive" "-lFortran_main" "--no-whole-archive" 
"-lFortranRuntime" 

[clang] [clang] Classify vector types in __builtin_classify_type (PR #73299)

2023-11-24 Thread Timm Baeder via cfe-commits

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


[clang] a79a561 - [clang] Classify vector types in __builtin_classify_type (#73299)

2023-11-24 Thread via cfe-commits

Author: Timm Baeder
Date: 2023-11-24T14:40:58+01:00
New Revision: a79a5611bd18baab02ea6ad31f7b6b767f4028a7

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

LOG: [clang] Classify vector types in __builtin_classify_type (#73299)

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ExprConstShared.h
clang/lib/AST/ExprConstant.cpp
clang/test/Sema/builtin-classify-type.c
clang/test/SemaCXX/builtin-classify-type.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7e2c990d03e7f27..362ce410356719b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -225,8 +225,8 @@ Non-comprehensive list of changes in this release
   determined at runtime.
 * The ``__datasizeof`` keyword has been added. It is similar to ``sizeof``
   except that it returns the size of a type ignoring tail padding.
-* ``__builtin_classify_type()`` now classifies ``_BitInt`` values as the 
return value ``18``,
-  to match GCC 14's behavior.
+* ``__builtin_classify_type()`` now classifies ``_BitInt`` values as the 
return value ``18``
+  and vector types as return value ``19``, to match GCC 14's behavior.
 
 New Compiler Flags
 --

diff  --git a/clang/lib/AST/ExprConstShared.h b/clang/lib/AST/ExprConstShared.h
index 53ec9c6c7a3ef2e..a97eac85abc69e9 100644
--- a/clang/lib/AST/ExprConstShared.h
+++ b/clang/lib/AST/ExprConstShared.h
@@ -49,7 +49,8 @@ enum class GCCTypeClass {
   // literals.
   // Lang = 16,
   // OpaqueType = 17,
-  BitInt = 18
+  BitInt = 18,
+  Vector = 19
 };
 
 GCCTypeClass EvaluateBuiltinClassifyType(QualType T,

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 3a41e9718bb5875..16697e5f076a8f8 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11615,16 +11615,18 @@ GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
 return EvaluateBuiltinClassifyType(
 CanTy->castAs()->getValueType(), LangOpts);
 
-  case Type::BlockPointer:
   case Type::Vector:
   case Type::ExtVector:
+return GCCTypeClass::Vector;
+
+  case Type::BlockPointer:
   case Type::ConstantMatrix:
   case Type::ObjCObject:
   case Type::ObjCInterface:
   case Type::ObjCObjectPointer:
   case Type::Pipe:
-// GCC classifies vectors as None. We follow its lead and classify all
-// other types that don't fit into the regular classification the same way.
+// Classify all other types that don't fit into the regular
+// classification the same way.
 return GCCTypeClass::None;
 
   case Type::BitInt:

diff  --git a/clang/test/Sema/builtin-classify-type.c 
b/clang/test/Sema/builtin-classify-type.c
index 50f517fcbc852a2..21b212faeedcd81 100644
--- a/clang/test/Sema/builtin-classify-type.c
+++ b/clang/test/Sema/builtin-classify-type.c
@@ -13,7 +13,7 @@ enum gcc_type_class {
   record_type_class, union_type_class,
   array_type_class, string_type_class,
   lang_type_class, opaque_type_class,
-  bitint_type_class
+  bitint_type_class, vector_type_class
 };
 
 void foo(void) {
@@ -67,8 +67,8 @@ void foo(void) {
   int a11[__builtin_classify_type(arr) == pointer_type_class ? 1 : -1];
   int a12[__builtin_classify_type("abc") == pointer_type_class ? 1 : -1];
   int a13[__builtin_classify_type(block) == no_type_class ? 1 : -1];
-  int a14[__builtin_classify_type(vec) == no_type_class ? 1 : -1];
-  int a15[__builtin_classify_type(evec) == no_type_class ? 1 : -1];
+  int a14[__builtin_classify_type(vec) == vector_type_class ? 1 : -1];
+  int a15[__builtin_classify_type(evec) == vector_type_class ? 1 : -1];
   int a16[__builtin_classify_type(atomic_i) == integer_type_class ? 1 : -1];
   int a17[__builtin_classify_type(atomic_d) == real_type_class ? 1 : -1];
   int a18[__builtin_classify_type(complex_i) == complex_type_class ? 1 : -1];

diff  --git a/clang/test/SemaCXX/builtin-classify-type.cpp 
b/clang/test/SemaCXX/builtin-classify-type.cpp
index 651dc8b24bf9483..6bae9cd6b1dc0dd 100644
--- a/clang/test/SemaCXX/builtin-classify-type.cpp
+++ b/clang/test/SemaCXX/builtin-classify-type.cpp
@@ -13,7 +13,7 @@ enum gcc_type_class {
   record_type_class, union_type_class,
   array_type_class, string_type_class,
   lang_type_class, opaque_type_class,
-  bitint_type_class
+  bitint_type_class, vector_type_class
 };
 
 class cl {
@@ -62,8 +62,8 @@ void foo() {
   int a14[__builtin_classify_type(arr) == pointer_type_class ? 1 : -1];
   int a15[__builtin_classify_type("abc") == pointer_type_class ? 1 : -1];
   int a16[__builtin_classify_type(block) == no_type_class ? 1 : -1];
-  int a17[__builtin_classify_type(vec) == no_type_class ? 1 : -1];
-  int a18[__builtin_classify_type(evec) == no_type_class ? 1 : -1];
+  int a17[__builtin_classify_type(vec) == ve

[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-24 Thread Michael Klemm via cfe-commits


@@ -122,6 +122,7 @@
 # the build directory holding that tool.
 tools = [
 ToolSubst("%flang", command=FindTool("flang-new"), unresolved="fatal"),
+ToolSubst("%clang", command=FindTool("clang"), unresolved="fatal"),

mjklemm wrote:

I have removed this in favor of compiling a LL file instead, like suggest below.

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


[clang] [clang][ASTImporter] Improve structural equivalence of overloadable operators. (PR #72242)

2023-11-24 Thread Balázs Kéri via cfe-commits


@@ -437,12 +439,67 @@ class StmtComparer {
 };
 } // namespace
 
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const UnaryOperator *E1,
+ const CXXOperatorCallExpr *E2) {
+  return UnaryOperator::getOverloadedOperator(E1->getOpcode()) ==
+ E2->getOperator() &&
+ IsStructurallyEquivalent(Context, E1->getSubExpr(), E2->getArg(0));
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const CXXOperatorCallExpr *E1,
+ const UnaryOperator *E2) {
+  return E1->getOperator() ==
+ UnaryOperator::getOverloadedOperator(E2->getOpcode()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(0), E2->getSubExpr());
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const BinaryOperator *E1,
+ const CXXOperatorCallExpr *E2) {
+  return BinaryOperator::getOverloadedOperator(E1->getOpcode()) ==
+ E2->getOperator() &&
+ IsStructurallyEquivalent(Context, E1->getLHS(), E2->getArg(0)) &&
+ IsStructurallyEquivalent(Context, E1->getRHS(), E2->getArg(1));
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const CXXOperatorCallExpr *E1,
+ const BinaryOperator *E2) {
+  return E1->getOperator() ==
+ BinaryOperator::getOverloadedOperator(E2->getOpcode()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(0), E2->getLHS()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(1), E2->getRHS());
+}
+
 /// Determine structural equivalence of two statements.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  const Stmt *S1, const Stmt *S2) {
   if (!S1 || !S2)
 return S1 == S2;
 
+  // Check for statements with similar syntax but different AST.
+  // The unary and binary operators (like '+', '&') can be parsed as
+  // CXXOperatorCall too (and UnaryOperator or BinaryOperator).
+  // This depends on arguments with unresolved type and on the name lookup.

balazske wrote:

The idea was coming from this post:
https://discourse.llvm.org/t/different-ast-translations-for-the-same-body-why/22741
The presence of `operator+` declaration is needed to change the parsed AST from 
`BinaryOperator` to `CXXOverloadedOperatorCallExpr`.

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


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-24 Thread Michael Klemm via cfe-commits


@@ -0,0 +1,8 @@
+#include 
+
+int main(int argc, char * argv[]) {
+// Irrelevant what to do in here.
+// Test is supposed to fail at link time.
+printf("Hello from C [%s]\n", __FUNCTION__);

mjklemm wrote:

This is also gone with the move to an LL file.

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


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-24 Thread Michael Klemm via cfe-commits


@@ -0,0 +1,15 @@
+! UNSUPPORTED: system-windows
+
+! RUN: %clang -o %t.c-object -c %S/Inputs/main_dupes.c

mjklemm wrote:

This change is also gone now and has been removed.

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


[clang] [clang] Avoid memcopy for small structure with padding under -ftrivial-auto-var-init (PR #71677)

2023-11-24 Thread via cfe-commits

serge-sans-paille wrote:

> @serge-sans-paille those test failures were also highlighted by the precommit 
> checks, would be good to check those before landing

I did validate locally, but I forgot I had some targets disabled :-/

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


[clang] [clang][ASTImporter] Improve structural equivalence of overloadable operators. (PR #72242)

2023-11-24 Thread Balázs Kéri via cfe-commits

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


[clang] [clang][ASTImporter] Improve structural equivalence of overloadable operators. (PR #72242)

2023-11-24 Thread Balázs Kéri via cfe-commits


@@ -2252,6 +2252,176 @@ TEST_F(StructuralEquivalenceStmtTest, 
UnaryOperatorDifferentOps) {
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest,
+   CXXOperatorCallExprVsUnaryBinaryOperator) {
+  auto t = makeNamedDecls(
+  R"(
+  template 
+  class A;
+  template 
+  void foo(
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A y)>,
+A,
+A> y)>,
+A,
+A,
+A,
+A= y>,
+A y>,
+A,
+A,
+A,
+A,
+A,
+A* y>,
+A y>
+  );
+  )",
+  R"(
+  struct Bar {
+Bar& operator=(Bar&);
+Bar& operator->();
+  };
+
+  Bar& operator+(Bar&, Bar&);
+  Bar& operator+(Bar&);
+  Bar& operator-(Bar&, Bar&);
+  Bar& operator-(Bar&);
+  Bar& operator*(Bar&, Bar&);
+  Bar& operator*(Bar&);
+  Bar& operator/(Bar&, Bar&);
+  Bar& operator%(Bar&, Bar&);
+  Bar& operator^(Bar&, Bar&);
+  Bar& operator&(Bar&, Bar&);
+  Bar& operator&(Bar&);
+  Bar& operator|(Bar&, Bar&);
+  Bar& operator~(Bar&);
+  Bar& operator!(Bar&);
+  Bar& operator<(Bar&, Bar&);
+  Bar& operator>(Bar&, Bar&);
+  Bar& operator+=(Bar&, Bar&);
+  Bar& operator-=(Bar&, Bar&);
+  Bar& operator*=(Bar&, Bar&);
+  Bar& operator/=(Bar&, Bar&);
+  Bar& operator%=(Bar&, Bar&);
+  Bar& operator^=(Bar&, Bar&);
+  Bar& operator&=(Bar&, Bar&);
+  Bar& operator|=(Bar&, Bar&);
+  Bar& operator<<(Bar&, Bar&);
+  Bar& operator>>(Bar&, Bar&);
+  Bar& operator<<=(Bar&, Bar&);
+  Bar& operator>>=(Bar&, Bar&);
+  Bar& operator==(Bar&, Bar&);
+  Bar& operator!=(Bar&, Bar&);
+  Bar& operator<=(Bar&, Bar&);
+  Bar& operator>=(Bar&, Bar&);
+  Bar& operator<=>(Bar&, Bar&);
+  Bar& operator&&(Bar&, Bar&);
+  Bar& operator||(Bar&, Bar&);
+  Bar& operator++(Bar&);
+  Bar& operator--(Bar&);
+  Bar& operator,(Bar&, Bar&);
+  Bar& operator->*(Bar&, Bar&);
+
+  template 
+  class A;
+  template 
+  void foo(
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A,
+A y)>,
+A,
+A> y)>,
+A,
+A,
+A,
+A= y>,
+A y>,
+A,
+A,
+A,
+A,
+A,
+A* y>,
+A y>
+  );
+  )",
+  Lang_CXX20);
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest,
+   CXXOperatorCallExprVsUnaryBinaryOperatorNe) {
+  auto t = makeNamedDecls(
+  R"(
+  template 
+  class A;
+  template 
+  void foo(
+A
+  );
+  )",
+  R"(
+  struct Bar;
+
+  Bar& operator+(Bar&, Bar&);

balazske wrote:

I do not know exactly what was the purpose, but likely it should be `operator 
-` instead.

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


[llvm] [clang] ms inline asm: Fix {call,jmp} fptr (PR #73207)

2023-11-24 Thread Shengchen Kan via cfe-commits

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

LGTM

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


[clang] [AArch64][SME2] Add PEXT, PSEL builtins for SME2 (PR #72827)

2023-11-24 Thread Matthew Devereau via cfe-commits


@@ -1,10 +1,17 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // REQUIRES: aarch64-registered-target
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-O1 -Werror -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme -target-feature +sme2 -S -O1 -Werror -emit-llvm -o - %s | 
FileCheck %s

MDevereau wrote:

```suggestion
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s
```
I don't think we need `-target-feature +sme` in this file?

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


[clang] [AArch64][SME2] Add PEXT, PSEL builtins for SME2 (PR #72827)

2023-11-24 Thread Matthew Devereau via cfe-commits


@@ -1859,19 +1859,28 @@ def SVBGRP   : SInst<"svbgrp[_{d}]",   "ddd", 
"UcUsUiUl", MergeNone, "aarch64_sv
 def SVBGRP_N : SInst<"svbgrp[_n_{d}]", "dda", "UcUsUiUl", MergeNone, 
"aarch64_sve_bgrp_x">;
 }
 
+let TargetGuard = "sve2p1|sme" in {

MDevereau wrote:

```suggestion
let TargetGuard = "sve2p1|sme2" in {
```
Should this be sme2?

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


[clang] [AArch64][SME2] Add PEXT, PSEL builtins for SME2 (PR #72827)

2023-11-24 Thread Matthew Devereau via cfe-commits


@@ -5,6 +5,11 @@
 // RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu \
 // RUN:   -target-feature +sve2p1 -S -O1 -Werror -emit-llvm -o - -x c++ %s | 
FileCheck %s -check-prefix=CPP-CHECK
 // RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu \

MDevereau wrote:

As per 
https://github.com/ARM-software/acle/pull/217/files#diff-516526d4a18101dc85300bc2033d0f86dc46c505b7510a7694baabea851aedfaR11352-R11358
should this be `__arm_streaming_compatible` instead of `__arm_streaming` for 
psel?

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


[llvm] [clang] [SystemZ] Properly support 16 byte atomic int/fp types and ops. (PR #73134)

2023-11-24 Thread Jonas Paulsson via cfe-commits

https://github.com/JonPsson1 updated 
https://github.com/llvm/llvm-project/pull/73134

>From bf9b6b735c131833ec9457f23b72322fd50ef821 Mon Sep 17 00:00:00 2001
From: Jonas Paulsson 
Date: Fri, 3 Feb 2023 14:32:58 +0100
Subject: [PATCH 1/2] [SystemZ] Improve support for 16 byte atomic int/fp types
 and operations.

- Clang FE now has MaxAtomicPromoteWidth and MaxAtomicInlineWidth with a value
  of 128. It now produces IR instead of calls to __atomic instrinsics for 16
  bytes as well. FP loads are first loaded as i128 and then casted to fp128.
- Atomic __int128 (and long double) variables are aligned to 16 bytes
  (like gcc 14).
- AtomicExpand pass now expands also 16 byte operations.

- tests for __atomic builtins for all integer widths, with test for i128 in
  both align=8 and align=16 cases.
- Resulting behavior of __atomic_is_lock_free / __atomic_always_lock_free /
  __c11_atomic_is_lock_free is tested in gnu-atomic_is_lock_free.c
- shouldExpandAtomicRMWInIR() was already returning true for any FP type. Now
  that the backend is acepting 16 byte atomics, 16 byte FP atomicrmw:s now also
  get expanded by AtomicExpand. The default (and used)
  shouldCastAtomicRMWIInIR() says that if the type is FP, it is casted to
  integer (see atomicrmw-xchg-07.ll).
- TODO: AtomicExpand pass handles with this patch expansion of i128 atomicrmw:s.
  As a next step smaller integer types should also be possible to handle this
  way instead of in backend.

Original patch rebased.
Remove the regalloc handling for CDSG loops.
Tests improved.
---
 clang/lib/Basic/Targets/SystemZ.h |   2 +-
 clang/test/CodeGen/SystemZ/atomic-alignment.c |  35 ++
 .../SystemZ/gnu-atomic-builtins-i128-16Al.c   | 257 +
 .../SystemZ/gnu-atomic-builtins-i128-8Al.c| 301 +++
 .../CodeGen/SystemZ/gnu-atomic-builtins-i16.c | 219 
 .../CodeGen/SystemZ/gnu-atomic-builtins-i32.c | 219 
 .../CodeGen/SystemZ/gnu-atomic-builtins-i64.c | 219 
 .../CodeGen/SystemZ/gnu-atomic-builtins-i8.c  | 219 
 .../gnu-atomic_is_lock_free-i128-16Al.c   |  54 ++
 .../gnu-atomic_is_lock_free-i128-8Al.c|  28 +
 .../Target/SystemZ/SystemZISelLowering.cpp|   6 +-
 .../CodeGen/SystemZ/atomicrmw-ops-i128.ll | 496 --
 .../test/CodeGen/SystemZ/atomicrmw-xchg-07.ll |  37 +-
 13 files changed, 2030 insertions(+), 62 deletions(-)
 create mode 100644 clang/test/CodeGen/SystemZ/atomic-alignment.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i128-16Al.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i128-8Al.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i16.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i32.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i64.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i8.c
 create mode 100644 
clang/test/CodeGen/SystemZ/gnu-atomic_is_lock_free-i128-16Al.c
 create mode 100644 
clang/test/CodeGen/SystemZ/gnu-atomic_is_lock_free-i128-8Al.c

diff --git a/clang/lib/Basic/Targets/SystemZ.h 
b/clang/lib/Basic/Targets/SystemZ.h
index 9ba255745cf2cc52..e4ec338880f21095 100644
--- a/clang/lib/Basic/Targets/SystemZ.h
+++ b/clang/lib/Basic/Targets/SystemZ.h
@@ -60,7 +60,7 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public 
TargetInfo {
   resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64"
   "-v128:64-a:8:16-n32:64");
 }
-MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
+MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 128;
 HasStrictFP = true;
   }
 
diff --git a/clang/test/CodeGen/SystemZ/atomic-alignment.c 
b/clang/test/CodeGen/SystemZ/atomic-alignment.c
new file mode 100644
index ..da478842ca31b2b0
--- /dev/null
+++ b/clang/test/CodeGen/SystemZ/atomic-alignment.c
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -triple s390x-linux-gnu -O3 -emit-llvm %s -o - | FileCheck 
%s
+//
+// Test alignment of 128 bit Atomic int/fp types, as well as loading
+// from memory with a simple addition. The fp128 is loaded as i128 and
+// then casted.
+
+// CHECK: @Atomic_int128 = {{.*}} i128 0, align 16
+// CHECK: @Atomic_fp128 = {{.*}} fp128 0xL, 
align 16
+
+// CHECK-LABEL:  @f1
+// CHECK:  %atomic-load = load atomic i128, ptr @Atomic_int128 seq_cst, 
align 16
+// CHECK-NEXT: %add = add nsw i128 %atomic-load, 1
+// CHECK-NEXT: store i128 %add, ptr %agg.result, align 8
+// CHECK-NEXT: ret void
+
+// CHECK-LABEL:  @f2
+// CHECK:  %atomic-load = load atomic i128, ptr @Atomic_fp128 seq_cst, 
align 16
+// CHECK-NEXT: %0 = bitcast i128 %atomic-load to fp128
+// CHECK-NEXT: %add = fadd fp128 %0, 0xL3FFF
+// CHECK-NEXT: store fp128 %add, ptr %agg.result, align 8
+// CHECK-NEXT: ret void
+
+
+#include 
+
+_Atomic __int128Atomic_int128;
+_Atomic long double Atomic_fp128;
+
+__int128 f1() {
+  return Atomic_int128 + 1;
+}
+
+long double

[llvm] [clang] [SystemZ] Properly support 16 byte atomic int/fp types and ops. (PR #73134)

2023-11-24 Thread Jonas Paulsson via cfe-commits


@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple s390x-linux-gnu -O1 -emit-llvm %s -o - | FileCheck 
%s
+//
+// Test __atomic_is_lock_free() and __atomic_always_lock_free() for __int128
+// with 16 byte alignment.
+
+#include 
+#include 
+

JonPsson1 wrote:

The first two functions here should return true..?

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


[llvm] [clang] [SystemZ] Properly support 16 byte atomic int/fp types and ops. (PR #73134)

2023-11-24 Thread Jonas Paulsson via cfe-commits


@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple s390x-linux-gnu -O1 -emit-llvm %s -o - | FileCheck 
%s
+//
+// Test __atomic_is_lock_free() and __atomic_always_lock_free() for __int128
+// with 16 byte alignment.
+
+#include 
+#include 
+
+__int128 Int128_Al16 __attribute__((aligned(16)));
+
+// CHECK-LABEL: @fun0
+// CHECK:   tail call zeroext i1 @__atomic_is_lock_free
+_Bool fun0() {
+  return __atomic_is_lock_free(16, &Int128_Al16);
+}
+
+// CHECK-LABEL: @fun1
+// CHECK:   ret i1 false
+_Bool fun1() {
+  return __atomic_always_lock_free(16, &Int128_Al16);
+}
+
+// Also test these with a 16 byte size and null-pointer.
+// CHECK-LABEL: @fun2
+// CHECK:   ret i1 true
+_Bool fun2() {
+  return __atomic_is_lock_free(16, 0);

JonPsson1 wrote:

> But this seems actually incorrect - when using default assumptions, the 
> operation should not be lock-free ...

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


[llvm] [clang] [SystemZ] Properly support 16 byte atomic int/fp types and ops. (PR #73134)

2023-11-24 Thread Jonas Paulsson via cfe-commits

JonPsson1 wrote:

Not sure about GCC here, as far as I can see, it is returning true for both of 
the 8-byte aligned cases in gnu-atomic_is_lock_free-i128-8Al.c, also now that 
the alignment is actually 8...

GCC is returning true for all in gnu-atomic_is_lock_free-i128-16Al.c, except 
for except for emitting a call to __c11_atomic_is_lock_free.

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


[clang] [clang] Add missing LinkageSpec case to getCursorKindForDecl (PR #72401)

2023-11-24 Thread Sebastian Poeplau via cfe-commits

sebastianpoeplau wrote:

By the way, I don't have permission to merge, so feel free to do it when you 
think it's ready.

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


[clang] [Clang] Emit TBAA info for enums in C (PR #73326)

2023-11-24 Thread Momchil Velikov via cfe-commits


@@ -196,11 +196,14 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type 
*Ty) {
   // Enum types are distinct types. In C++ they have "underlying types",
   // however they aren't related for TBAA.
   if (const EnumType *ETy = dyn_cast(Ty)) {
+if (!Features.CPlusPlus)
+  return getTypeInfo(Context.getIntTypeForBitwidth(Size * 8, 0));

momchil-velikov wrote:

Maybe `ETy->getDecl()->getIntegerType()` ?


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


[flang] [clang] [Flang][Clang] Add support for frame pointers in Flang Driver (PR #72146)

2023-11-24 Thread Kiran Chandramohan via cfe-commits


@@ -49,6 +49,26 @@ class CodeGenOptionsBase {
 class CodeGenOptions : public CodeGenOptionsBase {
 
 public:
+  /// The type of frame pointer used
+  enum class FramePointerKind {
+None,// Omit all frame pointers.
+NonLeaf, // Keep non-leaf frame pointers.
+All, // Keep all frame pointers.
+  };
+
+  static llvm::StringRef getFramePointerKindName(FramePointerKind Kind) {
+switch (Kind) {
+case FramePointerKind::None:
+  return "none";
+case FramePointerKind::NonLeaf:
+  return "non-leaf";
+case FramePointerKind::All:
+  return "all";
+}
+
+llvm_unreachable("invalid FramePointerKind");
+  };
+

kiranchandramohan wrote:

Move this code and the same code in 
`clang/include/clang/Basic/CodeGenOptions.h` to 
llvm/include/llvm/Frontend/Driver.

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


[clang] [clang][analyzer] Support `fputs` in the StreamChecker (PR #73335)

2023-11-24 Thread Ben Shi via cfe-commits

https://github.com/benshi001 created 
https://github.com/llvm/llvm-project/pull/73335

None

>From c59788f4b918c5335efe7444b8d588878565cb26 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Fri, 24 Nov 2023 22:51:27 +0800
Subject: [PATCH] [clang][analyzer] Support `fputs` in the StreamChecker

---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 61 +--
 .../Analysis/Inputs/system-header-simulator.h |  1 +
 clang/test/Analysis/stream-error.c| 18 ++
 clang/test/Analysis/stream.c  |  6 ++
 4 files changed, 68 insertions(+), 18 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 8eca989d7bcdea4..0e85f1fd0655143 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -252,10 +252,16 @@ class StreamChecker : public Checker PutVal = Call.getArgSVal(0).getAs();
-if (!PutVal)
-  return;
-ProgramStateRef StateNotFailed =
-State->BindExpr(CE, C.getLocationContext(), *PutVal);
-StateNotFailed =
-StateNotFailed->set(StreamSym, 
StreamState::getOpened(Desc));
-C.addTransition(StateNotFailed);
+// Generddate a transition for the success state of `fputc`.
+if (SingleChar) {
+  std::optional PutVal = Call.getArgSVal(0).getAs();
+  if (!PutVal)
+return;
+  ProgramStateRef StateNotFailed =
+  State->BindExpr(CE, C.getLocationContext(), *PutVal);
+  StateNotFailed = StateNotFailed->set(
+  StreamSym, StreamState::getOpened(Desc));
+  C.addTransition(StateNotFailed);
+}
+// Generddate a transition for the success state of `fputs`.
+else {
+  NonLoc RetVal = makeRetVal(C, CE).castAs();
+  ProgramStateRef StateNotFailed =
+  State->BindExpr(CE, C.getLocationContext(), RetVal);
+  auto Cond =
+  SVB.evalBinOp(State, BO_GE, RetVal, SVB.makeZeroVal(ASTC.IntTy),
+SVB.getConditionType())
+  .getAs();
+  if (!Cond)
+return;
+  StateNotFailed = StateNotFailed->assume(*Cond, true);
+  if (!StateNotFailed)
+return;
+  C.addTransition(StateNotFailed);
+}
   }
-  // Generate a transition for the success state of fgetc.
+  // Generate a transition for the success state of `fgetc`.
   // If we know the state to be FEOF at fgetc, do not add a success state.
   else if (OldSS->ErrorState != ErrorFEof) {
 NonLoc RetVal = makeRetVal(C, CE).castAs();
 ProgramStateRef StateNotFailed =
 State->BindExpr(CE, C.getLocationContext(), RetVal);
-SValBuilder &SVB = C.getSValBuilder();
-auto &ASTC = C.getASTContext();
 // The returned 'unsigned char' of `fgetc` is converted to 'int',
 // so we need to check if it is in range [0, 255].
 auto CondLow =
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index fc57e8bdc3d30c3..351de8c132fecc7 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -50,6 +50,7 @@ size_t fread(void *restrict, size_t, size_t, FILE *restrict);
 size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
 int fgetc(FILE *stream);
 int fputc(int ch, FILE *stream);
+int fputs(const char *str, FILE *stream);
 int fseek(FILE *__stream, long int __off, int __whence);
 long int ftell(FILE *__stream);
 void rewind(FILE *__stream);
diff --git a/clang/test/Analysis/stream-error.c 
b/clang/test/Analysis/stream-error.c
index 38e6b77b9bb5053..04e6b834fe9d4b5 100644
--- a/clang/test/Analysis/stream-error.c
+++ b/clang/test/Analysis/stream-error.c
@@ -141,6 +141,24 @@ void error_fputc(void) {
   fputc('A', F); // expected-warning {{Stream might be already closed}}
 }
 
+void error_fputs(void) {
+  FILE *F = tmpfile();
+  if (!F)
+return;
+  int Ret = fputs("XYZ", F);
+  if (Ret >= 0) {
+clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{FALSE}}
+fputs("QWD", F);   // no-warning
+  } else {
+clang_analyzer_eval(Ret == EOF); // expected-warning {{TRUE}}
+clang_analyzer_eval(ferror(F));  // expected-warning {{TRUE}}
+clang_analyzer_eval(feof(F));// expected-warning {{FALSE}}
+fputs("QWD", F); // expected-warning {{might be 
'indeterminate'}}
+  }
+  fclose(F);
+  fputs("ABC", F);   // expected-warning {{Stream might be 
already closed}}
+}
+
 void freadwrite_zerosize(FILE *F) {
   size_t Ret;
   Ret = fwrite(0, 1, 0, F);
diff --git a/clang/test/Analysis/stream.c b/clang/test/Analysis/stream.c
index a7ee9982478bb96..b0f39af8eb2f3a3 100644
--- a/clang/test/Analysis/stream.c
+++ b/clang/test/Analysis/stream.c
@@ -26,6 +26,12 @@ void check_fputc(void) {
   fclose(fp);
 }
 
+void check_fputs(void) {
+  FILE *fp = tmpfile();
+  fputs("ABC", fp); // expected-warning {{Stream 

[clang] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2 (PR #72107)

2023-11-24 Thread via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


https://github.com/DonatNagyE updated 
https://github.com/llvm/llvm-project/pull/72107

>From ab102e949994a4462382e4c10c0153d61fb00306 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= 
Date: Mon, 13 Nov 2023 11:16:26 +0100
Subject: [PATCH 1/3] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2

...instead of the currently used, more abstract Location callback. The
main advantage of this change is that after it the checker will check
`array[index].field` while the previous implementation ignored this
situation (because here the ElementRegion is wrapped in a FieldRegion
object). This improvement fixes PR #70187.

Note that after this change `&array[idx]` will be handled as an access
to the `idx`th element of `array`, which is technically incorrect but
matches the programmer intuitions. In my opinion it's more helpful if
the report points to the source location where the indexing happens
(instead of the location where a pointer is finally dereferenced).

This change introduces false positives in the exceptional corner case
when the past-the-end pointer of an array is formed as `&arr[length]`. I
think this is just unimportant pedantery (because it's cleaner to write
the past-the-end pointer as `(arr+length)` and that form isn't affected
by this checker), but if it does appear in real code, then we could
introduce a special case for it.

In addition to this primary improvement, this change tweaks the message
for the tainted index/offset case (using the more concrete information
that's available now) and clarifies/improves a few testcases.

The main change of this commit (replacing `check::Location` with
`check::PostStmt<...>` callbacks) was already proposed in my change
https://reviews.llvm.org/D150446 and https://reviews.llvm.org/D159107 by
@steakhal. Those reviews were both abandoned, but the issues were
unrelated to the change that is introduced in this PR.
---
 .../Checkers/ArrayBoundCheckerV2.cpp  | 96 ---
 .../test/Analysis/out-of-bounds-diagnostics.c | 74 --
 .../test/Analysis/taint-diagnostic-visitor.c  |  4 +-
 3 files changed, 129 insertions(+), 45 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
index ffc7236d1e2551a..ef3ae42d57c6e88 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
@@ -34,20 +34,37 @@ using llvm::formatv;
 namespace {
 enum OOB_Kind { OOB_Precedes, OOB_Exceeds, OOB_Taint };
 
-class ArrayBoundCheckerV2 :
-public Checker {
+struct Messages {
+  std::string Short, Full;
+};
+
+class ArrayBoundCheckerV2 : public Checker,
+   check::PostStmt,
+   check::PostStmt> {
   BugType BT{this, "Out-of-bound access"};
   BugType TaintBT{this, "Out-of-bound access", categories::TaintedData};
 
+  void performCheck(const Expr *E, CheckerContext &C) const;
+
   void reportOOB(CheckerContext &C, ProgramStateRef ErrorState, OOB_Kind Kind,
- NonLoc Offset, std::string RegName, std::string Msg) const;
+ NonLoc Offset, Messages Msgs) const;
 
   static bool isFromCtypeMacro(const Stmt *S, ASTContext &AC);
 
 public:
-  void checkLocation(SVal l, bool isLoad, const Stmt *S,
- CheckerContext &C) const;
+  void checkPostStmt(const ArraySubscriptExpr *E, CheckerContext &C) const {
+performCheck(E, C);
+  }
+  void checkPostStmt(const UnaryOperator *E, CheckerContext &C) const {
+if (E->getOpcode() == UO_Deref)
+  performCheck(E, C);
+  }
+  void checkPostStmt(const MemberExpr *E, CheckerContext &C) const {
+if (E->isArrow())
+  performCheck(E->getBase(), C);
+  }
 };
+
 } // anonymous namespace
 
 /// For a given Location that can be represented as a symbolic expression
@@ -217,16 +234,19 @@ static std::string getShortMsg(OOB_Kind Kind, std::string 
RegName) {
   return formatv(ShortMsgTemplates[Kind], RegName);
 }
 
-static std::string getPrecedesMsg(std::string RegName, NonLoc Offset) {
+static Messages getPrecedesMsgs(const SubRegion *Region, NonLoc Offset) {
+  std::string RegName = getRegionName(Region);
   SmallString<128> Buf;
   llvm::raw_svector_ostream Out(Buf);
   Out << "Access of " << RegName << " at negative byte offset";
   if (auto ConcreteIdx = Offset.getAs())
 Out << ' ' << ConcreteIdx->getValue();
-  return std::string(Buf);
+  return {getShortMsg(OOB_Precedes, RegName), std::string(Buf)};
 }
-static std::string getExceedsMsg(ASTContext &ACtx, std::string RegName,
- NonLoc Offset, NonLoc Extent, SVal Location) {
+
+static Messages getExceedsMsgs(ASTContext &ACtx, const SubRegion *Region,
+   NonLoc Offset, NonLoc Extent, SVal Location) {
+  std::string RegName = getRe

[clang] [clang][analyzer] Support `fputs` in the StreamChecker (PR #73335)

2023-11-24 Thread via cfe-commits

llvmbot wrote:



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

@llvm/pr-subscribers-clang

Author: Ben Shi (benshi001)


Changes



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


4 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp (+43-18) 
- (modified) clang/test/Analysis/Inputs/system-header-simulator.h (+1) 
- (modified) clang/test/Analysis/stream-error.c (+18) 
- (modified) clang/test/Analysis/stream.c (+6) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 8eca989d7bcdea4..0e85f1fd0655143 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -252,10 +252,16 @@ class StreamChecker : public Checker PutVal = Call.getArgSVal(0).getAs();
-if (!PutVal)
-  return;
-ProgramStateRef StateNotFailed =
-State->BindExpr(CE, C.getLocationContext(), *PutVal);
-StateNotFailed =
-StateNotFailed->set(StreamSym, 
StreamState::getOpened(Desc));
-C.addTransition(StateNotFailed);
+// Generddate a transition for the success state of `fputc`.
+if (SingleChar) {
+  std::optional PutVal = Call.getArgSVal(0).getAs();
+  if (!PutVal)
+return;
+  ProgramStateRef StateNotFailed =
+  State->BindExpr(CE, C.getLocationContext(), *PutVal);
+  StateNotFailed = StateNotFailed->set(
+  StreamSym, StreamState::getOpened(Desc));
+  C.addTransition(StateNotFailed);
+}
+// Generddate a transition for the success state of `fputs`.
+else {
+  NonLoc RetVal = makeRetVal(C, CE).castAs();
+  ProgramStateRef StateNotFailed =
+  State->BindExpr(CE, C.getLocationContext(), RetVal);
+  auto Cond =
+  SVB.evalBinOp(State, BO_GE, RetVal, SVB.makeZeroVal(ASTC.IntTy),
+SVB.getConditionType())
+  .getAs();
+  if (!Cond)
+return;
+  StateNotFailed = StateNotFailed->assume(*Cond, true);
+  if (!StateNotFailed)
+return;
+  C.addTransition(StateNotFailed);
+}
   }
-  // Generate a transition for the success state of fgetc.
+  // Generate a transition for the success state of `fgetc`.
   // If we know the state to be FEOF at fgetc, do not add a success state.
   else if (OldSS->ErrorState != ErrorFEof) {
 NonLoc RetVal = makeRetVal(C, CE).castAs();
 ProgramStateRef StateNotFailed =
 State->BindExpr(CE, C.getLocationContext(), RetVal);
-SValBuilder &SVB = C.getSValBuilder();
-auto &ASTC = C.getASTContext();
 // The returned 'unsigned char' of `fgetc` is converted to 'int',
 // so we need to check if it is in range [0, 255].
 auto CondLow =
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index fc57e8bdc3d30c3..351de8c132fecc7 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -50,6 +50,7 @@ size_t fread(void *restrict, size_t, size_t, FILE *restrict);
 size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
 int fgetc(FILE *stream);
 int fputc(int ch, FILE *stream);
+int fputs(const char *str, FILE *stream);
 int fseek(FILE *__stream, long int __off, int __whence);
 long int ftell(FILE *__stream);
 void rewind(FILE *__stream);
diff --git a/clang/test/Analysis/stream-error.c 
b/clang/test/Analysis/stream-error.c
index 38e6b77b9bb5053..04e6b834fe9d4b5 100644
--- a/clang/test/Analysis/stream-error.c
+++ b/clang/test/Analysis/stream-error.c
@@ -141,6 +141,24 @@ void error_fputc(void) {
   fputc('A', F); // expected-warning {{Stream might be already closed}}
 }
 
+void error_fputs(void) {
+  FILE *F = tmpfile();
+  if (!F)
+return;
+  int Ret = fputs("XYZ", F);
+  if (Ret >= 0) {
+clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{FALSE}}
+fputs("QWD", F);   // no-warning
+  } else {
+clang_analyzer_eval(Ret == EOF); // expected-warning {{TRUE}}
+clang_analyzer_eval(ferror(F));  // expected-warning {{TRUE}}
+clang_analyzer_eval(feof(F));// expected-warning {{FALSE}}
+fputs("QWD", F); // expected-warning {{might be 
'indeterminate'}}
+  }
+  fclose(F);
+  fputs("ABC", F);   // expected-warning {{Stream might be 
already closed}}
+}
+
 void freadwrite_zerosize(FILE *F) {
   size_t Ret;
   Ret = fwrite(0, 1, 0, F);
diff --git a/clang/test/Analysis/stream.c b/clang/test/Analysis/stream.c
index a7ee9982478bb96..b0f39af8eb2f3a3 100644
--- a/clang/test/Analysis/stream.c
+++ b/clang/test/Analysis/stream.c
@@ -26,6 +26,12 @@ void check_fputc(void) {
   fclose(fp);
 }
 
+void check_fputs(void) {
+  FILE *fp = tmpfile();
+  fputs("ABC", fp); // expected-warning {{Stream pointer might be NULL}}
+  fclose(fp);
+}
+
 void check_fseek(void) {
   FILE *fp = tmpfile();
   f

[clang] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2 (PR #72107)

2023-11-24 Thread via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


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


[clang] [Clang] Fix `-Wdocumentation` warning (NFC) (PR #73243)

2023-11-24 Thread via cfe-commits

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

LGTM

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


  1   2   >