[clang] [clang][analyzer] Improve modeling of 'fdopen' in StdLibraryFunctionsChecker (PR #78680)

2024-01-19 Thread Ben Shi via cfe-commits

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

None

>From 29b2f54387096951ecad53514251c4729d7c1947 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Fri, 19 Jan 2024 16:08:30 +0800
Subject: [PATCH] [clang][analyzer] Improve modeling of 'fdopen' in
 StdLibraryFunctionsChecker

---
 .../Checkers/StdLibraryFunctionsChecker.cpp   | 19 ++-
 .../Analysis/std-c-library-functions-POSIX.c  |  2 +-
 clang/test/Analysis/stream-errno.c| 10 ++
 clang/test/Analysis/stream-note.c |  1 +
 4 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 83f972c7072ec5..d0eb5091444f6b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2171,6 +2171,16 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(0)))
 .ArgConstraint(NotNull(ArgNo(1;
 
+// FILE *fdopen(int fd, const char *mode);
+addToFunctionSummaryMap(
+"fdopen",
+Signature(ArgTypes{IntTy, ConstCharPtrTy}, RetType{FilePtrTy}),
+Summary(NoEvalCall)
+.Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(ArgumentCondition(0, WithinRange, Range(0, IntMax)))
+.ArgConstraint(NotNull(ArgNo(1;
+
 // FILE *tmpfile(void);
 addToFunctionSummaryMap(
 "tmpfile", Signature(ArgTypes{}, RetType{FilePtrTy}),
@@ -2853,15 +2863,6 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 "pathconf", Signature(ArgTypes{ConstCharPtrTy, IntTy}, 
RetType{LongTy}),
 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0;
 
-// FILE *fdopen(int fd, const char *mode);
-// FIXME: Improve for errno modeling.
-addToFunctionSummaryMap(
-"fdopen",
-Signature(ArgTypes{IntTy, ConstCharPtrTy}, RetType{FilePtrTy}),
-Summary(NoEvalCall)
-.ArgConstraint(ArgumentCondition(0, WithinRange, Range(0, IntMax)))
-.ArgConstraint(NotNull(ArgNo(1;
-
 // void rewinddir(DIR *dir);
 addToFunctionSummaryMap(
 "rewinddir", Signature(ArgTypes{DirPtrTy}, RetType{VoidTy}),
diff --git a/clang/test/Analysis/std-c-library-functions-POSIX.c 
b/clang/test/Analysis/std-c-library-functions-POSIX.c
index 8a26e0b0f27286..51b136d9ba3567 100644
--- a/clang/test/Analysis/std-c-library-functions-POSIX.c
+++ b/clang/test/Analysis/std-c-library-functions-POSIX.c
@@ -17,6 +17,7 @@
 // RUN:   -triple i686-unknown-linux 2>&1 | FileCheck %s
 
 // CHECK: Loaded summary for: FILE *fopen(const char *restrict pathname, const 
char *restrict mode)
+// CHECK: Loaded summary for: FILE *fdopen(int fd, const char *mode)
 // CHECK: Loaded summary for: FILE *tmpfile(void)
 // CHECK: Loaded summary for: FILE *freopen(const char *restrict pathname, 
const char *restrict mode, FILE *restrict stream)
 // CHECK: Loaded summary for: int fclose(FILE *stream)
@@ -78,7 +79,6 @@
 // CHECK: Loaded summary for: int close(int fildes)
 // CHECK: Loaded summary for: long fpathconf(int fildes, int name)
 // CHECK: Loaded summary for: long pathconf(const char *path, int name)
-// CHECK: Loaded summary for: FILE *fdopen(int fd, const char *mode)
 // CHECK: Loaded summary for: void rewinddir(DIR *dir)
 // CHECK: Loaded summary for: void seekdir(DIR *dirp, long loc)
 // CHECK: Loaded summary for: int rand_r(unsigned int *seedp)
diff --git a/clang/test/Analysis/stream-errno.c 
b/clang/test/Analysis/stream-errno.c
index 13981e9094d1c9..fab6a58b3275a8 100644
--- a/clang/test/Analysis/stream-errno.c
+++ b/clang/test/Analysis/stream-errno.c
@@ -18,6 +18,16 @@ void check_fopen(void) {
   if (errno) {} // expected-warning{{An undefined value may be read from 
'errno' [unix.Errno]}}
 }
 
+void check_fdopen(int Fd) {
+  FILE *F = fdopen(Fd, "r");
+  if (!F) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+if (errno) {}// no-warning
+  } else {
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno' [unix.Errno]}}
+  }
+}
+
 void check_tmpfile(void) {
   FILE *F = tmpfile();
   if (!F) {
diff --git a/clang/test/Analysis/stream-note.c 
b/clang/test/Analysis/stream-note.c
index e412015eb68393..abb4784c078aa8 100644
--- a/clang/test/Analysis/stream-note.c
+++ b/clang/test/Analysis/stream-note.c
@@ -56,6 +56,7 @@ void check_note_freopen(void) {
 
 void check_note_fdopen(int fd) {
   FILE *F = fdopen(fd, "r"); // expected-note {{Stream opened here}}
+  // stdargs-note@-1 {{'fdopen' is successful}}
   if (!F)
 // expected-note@-1 {{'F' is non-null}}
 // expected-note@-2 {{Taking false branch}}


[clang] [clang][analyzer] Improve modeling of 'fdopen' in StdLibraryFunctionsChecker (PR #78680)

2024-01-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ben Shi (benshi001)


Changes



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


4 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
(+10-9) 
- (modified) clang/test/Analysis/std-c-library-functions-POSIX.c (+1-1) 
- (modified) clang/test/Analysis/stream-errno.c (+10) 
- (modified) clang/test/Analysis/stream-note.c (+1) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 83f972c7072ec5..d0eb5091444f6b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2171,6 +2171,16 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(0)))
 .ArgConstraint(NotNull(ArgNo(1;
 
+// FILE *fdopen(int fd, const char *mode);
+addToFunctionSummaryMap(
+"fdopen",
+Signature(ArgTypes{IntTy, ConstCharPtrTy}, RetType{FilePtrTy}),
+Summary(NoEvalCall)
+.Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(ArgumentCondition(0, WithinRange, Range(0, IntMax)))
+.ArgConstraint(NotNull(ArgNo(1;
+
 // FILE *tmpfile(void);
 addToFunctionSummaryMap(
 "tmpfile", Signature(ArgTypes{}, RetType{FilePtrTy}),
@@ -2853,15 +2863,6 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 "pathconf", Signature(ArgTypes{ConstCharPtrTy, IntTy}, 
RetType{LongTy}),
 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0;
 
-// FILE *fdopen(int fd, const char *mode);
-// FIXME: Improve for errno modeling.
-addToFunctionSummaryMap(
-"fdopen",
-Signature(ArgTypes{IntTy, ConstCharPtrTy}, RetType{FilePtrTy}),
-Summary(NoEvalCall)
-.ArgConstraint(ArgumentCondition(0, WithinRange, Range(0, IntMax)))
-.ArgConstraint(NotNull(ArgNo(1;
-
 // void rewinddir(DIR *dir);
 addToFunctionSummaryMap(
 "rewinddir", Signature(ArgTypes{DirPtrTy}, RetType{VoidTy}),
diff --git a/clang/test/Analysis/std-c-library-functions-POSIX.c 
b/clang/test/Analysis/std-c-library-functions-POSIX.c
index 8a26e0b0f27286..51b136d9ba3567 100644
--- a/clang/test/Analysis/std-c-library-functions-POSIX.c
+++ b/clang/test/Analysis/std-c-library-functions-POSIX.c
@@ -17,6 +17,7 @@
 // RUN:   -triple i686-unknown-linux 2>&1 | FileCheck %s
 
 // CHECK: Loaded summary for: FILE *fopen(const char *restrict pathname, const 
char *restrict mode)
+// CHECK: Loaded summary for: FILE *fdopen(int fd, const char *mode)
 // CHECK: Loaded summary for: FILE *tmpfile(void)
 // CHECK: Loaded summary for: FILE *freopen(const char *restrict pathname, 
const char *restrict mode, FILE *restrict stream)
 // CHECK: Loaded summary for: int fclose(FILE *stream)
@@ -78,7 +79,6 @@
 // CHECK: Loaded summary for: int close(int fildes)
 // CHECK: Loaded summary for: long fpathconf(int fildes, int name)
 // CHECK: Loaded summary for: long pathconf(const char *path, int name)
-// CHECK: Loaded summary for: FILE *fdopen(int fd, const char *mode)
 // CHECK: Loaded summary for: void rewinddir(DIR *dir)
 // CHECK: Loaded summary for: void seekdir(DIR *dirp, long loc)
 // CHECK: Loaded summary for: int rand_r(unsigned int *seedp)
diff --git a/clang/test/Analysis/stream-errno.c 
b/clang/test/Analysis/stream-errno.c
index 13981e9094d1c9..fab6a58b3275a8 100644
--- a/clang/test/Analysis/stream-errno.c
+++ b/clang/test/Analysis/stream-errno.c
@@ -18,6 +18,16 @@ void check_fopen(void) {
   if (errno) {} // expected-warning{{An undefined value may be read from 
'errno' [unix.Errno]}}
 }
 
+void check_fdopen(int Fd) {
+  FILE *F = fdopen(Fd, "r");
+  if (!F) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+if (errno) {}// no-warning
+  } else {
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno' [unix.Errno]}}
+  }
+}
+
 void check_tmpfile(void) {
   FILE *F = tmpfile();
   if (!F) {
diff --git a/clang/test/Analysis/stream-note.c 
b/clang/test/Analysis/stream-note.c
index e412015eb68393..abb4784c078aa8 100644
--- a/clang/test/Analysis/stream-note.c
+++ b/clang/test/Analysis/stream-note.c
@@ -56,6 +56,7 @@ void check_note_freopen(void) {
 
 void check_note_fdopen(int fd) {
   FILE *F = fdopen(fd, "r"); // expected-note {{Stream opened here}}
+  // stdargs-note@-1 {{'fdopen' is successful}}
   if (!F)
 // expected-note@-1 {{'F' is non-null}}
 // expected-note@-2 {{Taking false branch}}

``




https://github.com/llvm/llvm-project/pull/78680
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llv

[clang] [clang-tools-extra] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (re-land) (PR #71417)

2024-01-19 Thread via cfe-commits

tomasz-kaminski-sonarsource wrote:

> What I don't want to lose from this patch are the changes to places like 
> `InitializationStyle getInitializationStyle() const` and 
> `CXXNewExpr::CXXNewExpr` where the old code was unclear and the new code is 
> significantly more clear. We should not be performing math on the enumerator 
> values to encode in-band extra information. What I see being clarified by 
> this patch is:
> 
> ```
> struct S { int x; };
> auto *s0 = new int; // None, scalar types have no notional constructor 
> initialization
> auto *s1 = new S; // Implicit, class type has a notional constructor call
> auto *s2 = new S(0); // Call (ParenList is a much better name)
> auto *s3 = new S{0}; // List (BraceList is a much better name)
> ```
> 
> > In both cases, the news would report the initialization as Implicit, where 
> > actually no initialization is performed. There is no call to the 
> > constructor inserted.
> 
> There is an implicit constructor call but it's a noop because the type is 
> trivial, so I think `Implicit` is what I would expect given the comment `/// 
> New-expression has no written initializer, but has an implicit one.` 
> https://godbolt.org/z/353G45vnc
> 
> That said, I can see why it may be confusing to say there's an implicit 
> initialization for something that is a noop which performs no initialization 
> and we have an enumerator for "no initialization". I think 
> @tomasz-kaminski-sonarsource would like for the extra enumerator to be 
> removed, but I don't think that's possible to do without also losing the 
> benefits of the changes. But perhaps we could rename `Implicit` and `None` to 
> something more clear?

Yes, this is the thing that I am aiming for.
As far as changes LLVM code goes, I see that everywhere expect 
`hasInitializer()` where `NoInit` is used, then `Implicit` is handled in the 
same manner, so as far as this particular PR goes removing the `Implicit` will 
make the code simpler. I do not think that changing public-facing API to 
eliminate storage-hack is the right direction. 

> 
> > In short, as the downstream that uses AST for writing rules, we will need 
> > to update all the uses of NoInit to also check for Implicit, without 
> > getting any value from the distinction.
> 
> The C++ APIs have no stability guarantees and not every change will be to the 
> benefit of all downstreams; I see the changes in this PR as being an 
> improvement over the status quo because they clarify code in our code base 
> and I'm not seeing the same level of confusion you are in your downstream. 
> (That said, I'm also totally happy to rename enumeration members to pick more 
> descriptive names.)

With this change, I am no longer able to explain what the meaning of this 
enumeration is supposed to be. Previously it was all about the syntax, and the 
meaning of values was clear. Now we separate two cases, where we differentiate 
lack of initializer being spelled between doing no constructor calls and doing 
possibly implicit constructor calls. 
If we go with that direction, we should also differentiate between parents 
(`Call`) doing various semantics effects, such as calling constructor, 
construction aggregate, or initializing built-in types. Same for the braces. 
This would lead to an unwieldy number of the enumerator's values, which 
illustrates the problem of trying to shoehorn two orthogonal aspects into one 
enumerator.
For example, if we decide to introduce AST that would represent performing 
default initialization of trivial object (for example to capture Erroneous 
Behavior), all uses of `NoInit` would turn into `Implicit` because there was an 
initializer node.

I am less concerned about the number of changes required downstream, but the 
long-standing impact on the API. Where I would need to explain that the 
`NoInit` value does not mean that:
 * no initializer was written  (because it is also Implicit)
 * no initialization was performed (because `Implicit` also means that).
 

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


[llvm] [clang] [docs] Add llvm and clang release notes for the global-var code model attribute (PR #78664)

2024-01-19 Thread WÁNG Xuěruì via cfe-commits


@@ -130,6 +132,8 @@ Changes to the Hexagon Backend
 
 Changes to the LoongArch Backend
 
+* Respect the code model attribute of global variables when different from
+  their default values.

xen0n wrote:

"Code model of global variables can now be overridden by means of the 
newly-added `code_model` LLVM IR attribute."?

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


[clang] [llvm] [docs] Add llvm and clang release notes for the global-var code model attribute (PR #78664)

2024-01-19 Thread WÁNG Xuěruì via cfe-commits


@@ -1119,6 +1119,14 @@ Windows Support
 
 LoongArch Support
 ^
+- Added a code model attribute for the global variable. The following values

xen0n wrote:

"The `model` attribute is now supported for overriding the default code model 
used to access global variables." or something like that?

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


[llvm] [clang] [docs] Add llvm and clang release notes for the global-var code model attribute (PR #78664)

2024-01-19 Thread WÁNG Xuěruì via cfe-commits


@@ -70,6 +70,8 @@ Changes to the LLVM IR
 
 * Added `llvm.exp10` intrinsic.
 
+* Added a code model attribute for the `global variable 
`_.

xen0n wrote:

Refer to the IR construct verbatim, i.e. `code_model`, for better readability?

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


[clang] [clang-format] Add SkipMacroDefinitionBody option (PR #78682)

2024-01-19 Thread Owen Pan via cfe-commits

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

Closes #67991.

Co-authored-by: @tomekpaszek

>From 620e614b242055c3b8cbd81efd9bbc64a0ee4e56 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 18 Jan 2024 23:34:13 -0800
Subject: [PATCH] [clang-format] Option to ignore macro definitions

---
 clang/docs/ClangFormatStyleOptions.rst |   5 +
 clang/docs/ReleaseNotes.rst|   1 +
 clang/include/clang/Format/Format.h|   5 +
 clang/lib/Format/Format.cpp|   2 +
 clang/lib/Format/UnwrappedLineParser.cpp   |   9 ++
 clang/unittests/Format/ConfigParseTest.cpp |   1 +
 clang/unittests/Format/FormatTest.cpp  | 132 +
 7 files changed, 155 insertions(+)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 8bc13e45bf2f5f..4dc0de3a90f265 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4999,6 +4999,11 @@ the configuration (without a prefix: ``Auto``).
int bar;   int bar;
  } // namespace b   } // namespace b
 
+.. _SkipMacroDefinitionBody:
+
+**SkipMacroDefinitionBody** (``Boolean``) :versionbadge:`clang-format 18` 
:ref:`¶ `
+  Do not format macro definition body.
+
 .. _SortIncludes:
 
 **SortIncludes** (``SortIncludesOptions``) :versionbadge:`clang-format 3.8` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b400d75095421c..1045fd6b92346b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1202,6 +1202,7 @@ clang-format
 - Add ``PenaltyBreakScopeResolution`` option.
 - Add ``.clang-format-ignore`` files.
 - Add ``AlignFunctionPointers`` sub-option for 
``AlignConsecutiveDeclarations``.
+- Add ``SkipMacroDefinitionBody`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 6fd7947bd21791..bc9eecd42f9ebf 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3932,6 +3932,10 @@ struct FormatStyle {
   /// \version 13
   unsigned ShortNamespaceLines;
 
+  /// Do not format macro definition body.
+  /// \version 18
+  bool SkipMacroDefinitionBody;
+
   /// Include sorting options.
   enum SortIncludesOptions : int8_t {
 /// Includes are never sorted.
@@ -4895,6 +4899,7 @@ struct FormatStyle {
RequiresExpressionIndentation == R.RequiresExpressionIndentation &&
SeparateDefinitionBlocks == R.SeparateDefinitionBlocks &&
ShortNamespaceLines == R.ShortNamespaceLines &&
+   SkipMacroDefinitionBody == R.SkipMacroDefinitionBody &&
SortIncludes == R.SortIncludes &&
SortJavaStaticImport == R.SortJavaStaticImport &&
SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 7c2f4dcf3d2308..ff326dc784783b 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1085,6 +1085,7 @@ template <> struct MappingTraits {
Style.RequiresExpressionIndentation);
 IO.mapOptional("SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
 IO.mapOptional("ShortNamespaceLines", Style.ShortNamespaceLines);
+IO.mapOptional("SkipMacroDefinitionBody", Style.SkipMacroDefinitionBody);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
 IO.mapOptional("SortJavaStaticImport", Style.SortJavaStaticImport);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
@@ -1556,6 +1557,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.RequiresExpressionIndentation = FormatStyle::REI_OuterScope;
   LLVMStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Leave;
   LLVMStyle.ShortNamespaceLines = 1;
+  LLVMStyle.SkipMacroDefinitionBody = false;
   LLVMStyle.SortIncludes = FormatStyle::SI_CaseSensitive;
   LLVMStyle.SortJavaStaticImport = FormatStyle::SJSIO_Before;
   LLVMStyle.SortUsingDeclarations = FormatStyle::SUD_LexicographicNumeric;
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 50d41c9f57a670..c08ce86449b6ea 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1170,6 +1170,15 @@ void UnwrappedLineParser::parsePPDefine() {
   assert((int)Line->PPLevel >= 0);
   Line->InMacroBody = true;
 
+  if (Style.SkipMacroDefinitionBody) {
+do {
+  FormatTok->Finalized = true;
+  nextToken();
+} while (!eof());
+addUnwrappedLine();
+return;
+  }
+
   if (FormatTok->is(tok::identifier) &&
   Tokens->peekNextToken()->is(tok::colon)) {
 nextToken();
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index 172aaab5988ce5..2a8d79359a49b4 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unitte

[clang] [clang-format] Add SkipMacroDefinitionBody option (PR #78682)

2024-01-19 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Closes #67991.

Co-authored-by: @tomekpaszek

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


7 Files Affected:

- (modified) clang/docs/ClangFormatStyleOptions.rst (+5) 
- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/include/clang/Format/Format.h (+5) 
- (modified) clang/lib/Format/Format.cpp (+2) 
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+9) 
- (modified) clang/unittests/Format/ConfigParseTest.cpp (+1) 
- (modified) clang/unittests/Format/FormatTest.cpp (+132) 


``diff
diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 8bc13e45bf2f5f..4dc0de3a90f265 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4999,6 +4999,11 @@ the configuration (without a prefix: ``Auto``).
int bar;   int bar;
  } // namespace b   } // namespace b
 
+.. _SkipMacroDefinitionBody:
+
+**SkipMacroDefinitionBody** (``Boolean``) :versionbadge:`clang-format 18` 
:ref:`¶ `
+  Do not format macro definition body.
+
 .. _SortIncludes:
 
 **SortIncludes** (``SortIncludesOptions``) :versionbadge:`clang-format 3.8` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b400d75095421c..1045fd6b92346b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1202,6 +1202,7 @@ clang-format
 - Add ``PenaltyBreakScopeResolution`` option.
 - Add ``.clang-format-ignore`` files.
 - Add ``AlignFunctionPointers`` sub-option for 
``AlignConsecutiveDeclarations``.
+- Add ``SkipMacroDefinitionBody`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 6fd7947bd21791..bc9eecd42f9ebf 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3932,6 +3932,10 @@ struct FormatStyle {
   /// \version 13
   unsigned ShortNamespaceLines;
 
+  /// Do not format macro definition body.
+  /// \version 18
+  bool SkipMacroDefinitionBody;
+
   /// Include sorting options.
   enum SortIncludesOptions : int8_t {
 /// Includes are never sorted.
@@ -4895,6 +4899,7 @@ struct FormatStyle {
RequiresExpressionIndentation == R.RequiresExpressionIndentation &&
SeparateDefinitionBlocks == R.SeparateDefinitionBlocks &&
ShortNamespaceLines == R.ShortNamespaceLines &&
+   SkipMacroDefinitionBody == R.SkipMacroDefinitionBody &&
SortIncludes == R.SortIncludes &&
SortJavaStaticImport == R.SortJavaStaticImport &&
SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 7c2f4dcf3d2308..ff326dc784783b 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1085,6 +1085,7 @@ template <> struct MappingTraits {
Style.RequiresExpressionIndentation);
 IO.mapOptional("SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
 IO.mapOptional("ShortNamespaceLines", Style.ShortNamespaceLines);
+IO.mapOptional("SkipMacroDefinitionBody", Style.SkipMacroDefinitionBody);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
 IO.mapOptional("SortJavaStaticImport", Style.SortJavaStaticImport);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
@@ -1556,6 +1557,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.RequiresExpressionIndentation = FormatStyle::REI_OuterScope;
   LLVMStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Leave;
   LLVMStyle.ShortNamespaceLines = 1;
+  LLVMStyle.SkipMacroDefinitionBody = false;
   LLVMStyle.SortIncludes = FormatStyle::SI_CaseSensitive;
   LLVMStyle.SortJavaStaticImport = FormatStyle::SJSIO_Before;
   LLVMStyle.SortUsingDeclarations = FormatStyle::SUD_LexicographicNumeric;
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 50d41c9f57a670..c08ce86449b6ea 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1170,6 +1170,15 @@ void UnwrappedLineParser::parsePPDefine() {
   assert((int)Line->PPLevel >= 0);
   Line->InMacroBody = true;
 
+  if (Style.SkipMacroDefinitionBody) {
+do {
+  FormatTok->Finalized = true;
+  nextToken();
+} while (!eof());
+addUnwrappedLine();
+return;
+  }
+
   if (FormatTok->is(tok::identifier) &&
   Tokens->peekNextToken()->is(tok::colon)) {
 nextToken();
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index 172aaab5988ce5..2a8d79359a49b4 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -184,6 +184,7 @@ TEST(ConfigParseTest, ParsesConfiguration

[clang] [clang][dataflow] Treat comma operator correctly in `getResultObjectLocation()`. (PR #78427)

2024-01-19 Thread via cfe-commits

martinboehme wrote:

> This change itself looks good to me, but I start to doubt whether we actually 
> need `getResultObjectLocation` the way it is currently implemented. One of 
> the red flags for me seeing some `getResultObjectLocation` calls in 
> `UncheckedOptionalAccessModel.cpp`. I think most (all?) of those calls are 
> redundant, the type of the expression already guarantees that we have the 
> right location. Moreover, I think the propagation should happen internally in 
> the built-in transfers, so authors of user code like 
> `UncheckedOptionalAccessModel` should never need to think about these 
> implementation details.
> 
> I think it might make sense to review all of the calls and after we removed 
> the redundant ones, we might want to reconsider if it makes sense to restrict 
> the use of this function somewhat.
> 
> Let me know if I am missing something.

The missing context here, I think, is that the current implementation of 
`getResultObjectLocation()` is deficient and I want to fix it (hopefully soon). 
This fix should be transparent to the existing callers of 
`getResultObjectLocation()` (but it does mean that we currently call 
`getResultObjectLocation()` in places where it looks as if we could do 
something simpler).

Let me expand. Currently, `getResultObjectLocation()` propagates the location 
from the "original record constructor" up towards any prvalue ancestors of the 
original record constructor. The location for the "original record constructor" 
is simply pulled out of thin air by the transfer function for that node.

But this is wrong. For example, consider the following code:

```cxx
  A a = some_condition()? A(1) : A(2, 3);
```

When either the `A(1)` or `A(2, 3)` constructor are called, the `this` pointer 
that is passed to them should be `&a`. But our current implementation doesn't 
do this. When visiting `A(1)` and `A(2, 3)`, it independently creates storage 
locations for them ("out of thin air") and tries to propagate them upwards 
(towards the root). This poses an unsolvable problem when processing the 
conditional operator; the "result object location" for the conditional operator 
should be identical to the result object location for both branches, but this 
is currently impossible to achieve. Instead, we currently don't really model 
the conditional operator at all -- we just invent a fresh location for it, and 
hence we claim that the conditional operator is an "original record 
constructor". See also [this 
comment](https://github.com/llvm/llvm-project/blob/c6a6547798ca641b985456997cdf986bb99b0707/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp#L751).

What we should instead be doing is propagating the result object location 
_downwards_ from the result object to any prvalues that might initialize it. 
This is described in a FIXME 
[here](https://github.com/llvm/llvm-project/blob/c6a6547798ca641b985456997cdf986bb99b0707/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h#L332).
 (By the way, this is what CodeGen does too -- not surprisingly.)

The current implementation is also terrible in other ways. We do actually get 
the following right:

```cxx
  A a = A(1);
```

If you query `getResultObjectLocation()` for `A(1)`, you'll find it gives you 
the same location that you get if we call `Environment::getStorageLocation()` 
for `a`. But the way we arrive here is a terrible hack: When processing the 
`VarDecl` for `a`, we retrieve the `RecordValue` for its initializer, look at 
its `RecordValue::getLoc()`, and "steal" this location as the location to use 
for the storage of the variable. But we can't actually always do this stealing; 
for example, when processing a member initializer, the location for the member 
variable has already been determined, and so we need to [perform a 
copy](https://github.com/llvm/llvm-project/blob/3b54337be54107a5f196bb98dfc858b10ec35b8a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp#L419)
 that should not actually be happening.

A nice side effect of fixing `getResultObjectLocation()` to do the right thing 
is that it will make `RecordValue::getLoc()` obsolete -- and because this is 
the last remaining reason for `RecordValue` to exist at all, this will allow us 
to eliminate `RecordValue` entirely, something I've been working towards for a 
while (see for example [this 
discussion](https://reviews.llvm.org/D155204#inline-1503204)).

Getting back to your original point: Yes, many of the existing 
`getResultObjectLocation()` calls are actually redundant -- they could be 
replaced with code that retrieves the `RecordValue`, then obtains the location 
from `RecordValue::getLoc()`. But the `getResultObjectLocation()` calls 
future-proof the code -- they will allow the code to continue to work when we 
change `getResultObjectLocation()` to propagate locations from result objects 
down towards the "original record constructors", rather than upwards as we do 
today.

This has been pretty lengthy, b

[clang] [clang-format] Add SkipMacroDefinitionBody option (PR #78682)

2024-01-19 Thread Owen Pan via cfe-commits

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


[clang] 8b4bb15 - [clang][Interp] Implement integral->complex casts (#75590)

2024-01-19 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-01-19T09:27:30+01:00
New Revision: 8b4bb15f6d879fd8655f9e41fee224a8a59f238c

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

LOG: [clang][Interp] Implement integral->complex casts (#75590)

Allocate storage for them, initialize the first member with the given
value and the second member to 0.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 138ffed392fcac3..82ef743e6a78191 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -294,6 +294,29 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
   case CK_ToVoid:
 return discard(SubExpr);
 
+  case CK_IntegralRealToComplex:
+  case CK_FloatingRealToComplex: {
+// We're creating a complex value here, so we need to
+// allocate storage for it.
+if (!Initializing) {
+  std::optional LocalIndex =
+  allocateLocal(CE, /*IsExtended=*/true);
+  if (!LocalIndex)
+return false;
+  if (!this->emitGetPtrLocal(*LocalIndex, CE))
+return false;
+}
+
+// Init the complex value to {SubExpr, 0}.
+if (!this->visitArrayElemInit(0, SubExpr))
+  return false;
+// Zero-init the second element.
+PrimType T = classifyPrim(SubExpr->getType());
+if (!this->visitZeroInitializer(T, SubExpr->getType(), SubExpr))
+  return false;
+return this->emitInitElem(T, 1, SubExpr);
+  }
+
   default:
 assert(false && "Cast not implemented");
   }
@@ -846,6 +869,10 @@ bool ByteCodeExprGen::VisitInitListExpr(const 
InitListExpr *E) {
 
   if (T->isAnyComplexType()) {
 unsigned NumInits = E->getNumInits();
+
+if (NumInits == 1)
+  return this->delegate(E->inits()[0]);
+
 QualType ElemQT = E->getType()->getAs()->getElementType();
 PrimType ElemT = classifyPrim(ElemQT);
 if (NumInits == 0) {

diff  --git a/clang/test/AST/Interp/complex.cpp 
b/clang/test/AST/Interp/complex.cpp
index e63693a0cfaa140..99c0dd141d0b77a 100644
--- a/clang/test/AST/Interp/complex.cpp
+++ b/clang/test/AST/Interp/complex.cpp
@@ -55,21 +55,20 @@ static_assert(ignoredCast() == 0, "");
 static_assert((int)I1 == 1, "");
 static_assert((float)D == 1.0f, "");
 
+static_assert(__real((_Complex unsigned)5) == 5);
+static_assert(__imag((_Complex unsigned)5) == 0);
 
 /// Standalone complex expressions.
 static_assert(__real((_Complex float){1.0, 3.0}) == 1.0, "");
 
 
-#if 0
-/// FIXME: This should work in the new interpreter.
 constexpr _Complex double D2 = {12};
 static_assert(__real(D2) == 12, "");
-static_assert(__imag(D2) == 12, "");
+static_assert(__imag(D2) == 0, "");
 
 constexpr _Complex int I3 = {15};
 static_assert(__real(I3) == 15, "");
-static_assert(__imag(I3) == 15, "");
-#endif
+static_assert(__imag(I3) == 0, "");
 
 /// FIXME: This should work in the new interpreter as well.
 // constexpr _Complex _BitInt(8) A = 0;// = {4};



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


[clang] [clang][Interp] Implement integral->complex casts (PR #75590)

2024-01-19 Thread Timm Baeder via cfe-commits

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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2024-01-19 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/66514

>From 41bb52dc591ce1c154a4272abb738c80a7a57b90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 15 Sep 2023 15:51:39 +0200
Subject: [PATCH 1/3] [clang][Diagnostics] Highlight code snippets

Add some primitive syntax highlighting to our code snippet output.
---
 clang/include/clang/Frontend/TextDiagnostic.h |  18 +-
 clang/include/clang/Lex/Preprocessor.h|   5 +
 clang/lib/Frontend/TextDiagnostic.cpp | 197 +-
 clang/lib/Frontend/TextDiagnosticPrinter.cpp  |   2 +-
 clang/lib/Lex/Preprocessor.cpp|  24 +++
 5 files changed, 232 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Frontend/TextDiagnostic.h 
b/clang/include/clang/Frontend/TextDiagnostic.h
index 7eb0ab0cdc9bca..a2fe8ae995423b 100644
--- a/clang/include/clang/Frontend/TextDiagnostic.h
+++ b/clang/include/clang/Frontend/TextDiagnostic.h
@@ -16,6 +16,7 @@
 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 
 #include "clang/Frontend/DiagnosticRenderer.h"
+#include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 
@@ -33,14 +34,22 @@ namespace clang {
 /// printing coming out of libclang.
 class TextDiagnostic : public DiagnosticRenderer {
   raw_ostream &OS;
+  const Preprocessor *PP;
 
 public:
-  TextDiagnostic(raw_ostream &OS,
- const LangOptions &LangOpts,
- DiagnosticOptions *DiagOpts);
+  TextDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
+ DiagnosticOptions *DiagOpts, const Preprocessor *PP = 
nullptr);
 
   ~TextDiagnostic() override;
 
+  struct StyleRange {
+unsigned Start;
+unsigned End;
+enum llvm::raw_ostream::Colors Color;
+StyleRange(unsigned S, unsigned E, enum llvm::raw_ostream::Colors C)
+: Start(S), End(E), Color(C){};
+  };
+
   /// Print the diagonstic level to a raw_ostream.
   ///
   /// This is a static helper that handles colorizing the level and formatting
@@ -104,7 +113,8 @@ class TextDiagnostic : public DiagnosticRenderer {
ArrayRef Hints);
 
   void emitSnippet(StringRef SourceLine, unsigned MaxLineNoDisplayWidth,
-   unsigned LineNo);
+   unsigned LineNo, unsigned DisplayLineNo,
+   ArrayRef Styles);
 
   void emitParseableFixits(ArrayRef Hints, const SourceManager &SM);
 };
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 4ec21a8b6be2c8..d89e2be1bf5ff5 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -284,6 +284,8 @@ class Preprocessor {
   /// The kind of translation unit we are processing.
   const TranslationUnitKind TUKind;
 
+  const char *getCheckPoint(FileID FID, const char *Start) const;
+
 private:
   /// The code-completion handler.
   CodeCompletionHandler *CodeComplete = nullptr;
@@ -311,6 +313,9 @@ class Preprocessor {
   /// The import path for named module that we're currently processing.
   SmallVector, 2> 
NamedModuleImportPath;
 
+  llvm::DenseMap> CheckPoints;
+  unsigned CheckPointCounter = 0;
+
   /// Whether the import is an `@import` or a standard c++ modules import.
   bool IsAtImport = false;
 
diff --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index 779dead5d058d1..691809ceded87b 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -12,6 +12,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -41,6 +42,14 @@ static const enum raw_ostream::Colors fatalColor = 
raw_ostream::RED;
 static const enum raw_ostream::Colors savedColor =
   raw_ostream::SAVEDCOLOR;
 
+// Magenta is taken for 'warning'. Red is already 'error' and 'cyan'
+// is already taken for 'note'. Green is already used to underline
+// source ranges. White and black are bad because of the usual
+// terminal backgrounds. Which leaves us only with TWO options.
+static constexpr raw_ostream::Colors CommentColor = raw_ostream::YELLOW;
+static constexpr raw_ostream::Colors LiteralColor = raw_ostream::GREEN;
+static constexpr raw_ostream::Colors KeywordColor = raw_ostream::BLUE;
+
 /// Add highlights to differences in template strings.
 static void applyTemplateHighlighting(raw_ostream &OS, StringRef Str,
   bool &Normal, bool Bold) {
@@ -644,10 +653,10 @@ static bool printWordWrapped(raw_ostream &OS, StringRef 
Str, unsigned Columns,
   return Wrapped;
 }
 
-TextDiagnostic::TextDiagnostic(raw_ostream &OS,
-   const LangOptions &LangOpts,
-   DiagnosticOptions *D

[compiler-rt] [libcxx] [clang] [mlir] [llvm] [asan] Enable StackSafetyAnalysis by default (PR #77210)

2024-01-19 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> @MaskRay can you help address [#77210 
> (comment)](https://github.com/llvm/llvm-project/pull/77210#issuecomment-1893860870)
>  , test cases are failing on LoZ buildbot. Thanks

The test (from https://reviews.llvm.org/D7098) is about the interaction
of VLA and alloca where the VLA causes alloca to have the same address.
This is mostly about behavior checking and less about instrumentation
correctness, so I think it is fair to disable it for a platform that
does not work after StackSafetyAnalysis is enabled by default (#77210).

Disabled the test on `s390{{.*}}` in c875567af352716e703a49c9445f5dc1d3cf0063

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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2024-01-19 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
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/66514

>From 41bb52dc591ce1c154a4272abb738c80a7a57b90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 15 Sep 2023 15:51:39 +0200
Subject: [PATCH 1/4] [clang][Diagnostics] Highlight code snippets

Add some primitive syntax highlighting to our code snippet output.
---
 clang/include/clang/Frontend/TextDiagnostic.h |  18 +-
 clang/include/clang/Lex/Preprocessor.h|   5 +
 clang/lib/Frontend/TextDiagnostic.cpp | 197 +-
 clang/lib/Frontend/TextDiagnosticPrinter.cpp  |   2 +-
 clang/lib/Lex/Preprocessor.cpp|  24 +++
 5 files changed, 232 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Frontend/TextDiagnostic.h 
b/clang/include/clang/Frontend/TextDiagnostic.h
index 7eb0ab0cdc9bca8..a2fe8ae995423b9 100644
--- a/clang/include/clang/Frontend/TextDiagnostic.h
+++ b/clang/include/clang/Frontend/TextDiagnostic.h
@@ -16,6 +16,7 @@
 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 
 #include "clang/Frontend/DiagnosticRenderer.h"
+#include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 
@@ -33,14 +34,22 @@ namespace clang {
 /// printing coming out of libclang.
 class TextDiagnostic : public DiagnosticRenderer {
   raw_ostream &OS;
+  const Preprocessor *PP;
 
 public:
-  TextDiagnostic(raw_ostream &OS,
- const LangOptions &LangOpts,
- DiagnosticOptions *DiagOpts);
+  TextDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
+ DiagnosticOptions *DiagOpts, const Preprocessor *PP = 
nullptr);
 
   ~TextDiagnostic() override;
 
+  struct StyleRange {
+unsigned Start;
+unsigned End;
+enum llvm::raw_ostream::Colors Color;
+StyleRange(unsigned S, unsigned E, enum llvm::raw_ostream::Colors C)
+: Start(S), End(E), Color(C){};
+  };
+
   /// Print the diagonstic level to a raw_ostream.
   ///
   /// This is a static helper that handles colorizing the level and formatting
@@ -104,7 +113,8 @@ class TextDiagnostic : public DiagnosticRenderer {
ArrayRef Hints);
 
   void emitSnippet(StringRef SourceLine, unsigned MaxLineNoDisplayWidth,
-   unsigned LineNo);
+   unsigned LineNo, unsigned DisplayLineNo,
+   ArrayRef Styles);
 
   void emitParseableFixits(ArrayRef Hints, const SourceManager &SM);
 };
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 4ec21a8b6be2c85..d89e2be1bf5ff55 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -284,6 +284,8 @@ class Preprocessor {
   /// The kind of translation unit we are processing.
   const TranslationUnitKind TUKind;
 
+  const char *getCheckPoint(FileID FID, const char *Start) const;
+
 private:
   /// The code-completion handler.
   CodeCompletionHandler *CodeComplete = nullptr;
@@ -311,6 +313,9 @@ class Preprocessor {
   /// The import path for named module that we're currently processing.
   SmallVector, 2> 
NamedModuleImportPath;
 
+  llvm::DenseMap> CheckPoints;
+  unsigned CheckPointCounter = 0;
+
   /// Whether the import is an `@import` or a standard c++ modules import.
   bool IsAtImport = false;
 
diff --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index 779dead5d058d1a..691809ceded87bf 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -12,6 +12,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -41,6 +42,14 @@ static const enum raw_ostream::Colors fatalColor = 
raw_ostream::RED;
 static const enum raw_ostream::Colors savedColor =
   raw_ostream::SAVEDCOLOR;
 
+// Magenta is taken for 'warning'. Red is already 'error' and 'cyan'
+// is already taken for 'note'. Green is already used to underline
+// source ranges. White and black are bad because of the usual
+// terminal backgrounds. Which leaves us only with TWO options.
+static constexpr raw_ostream::Colors CommentColor = raw_ostream::YELLOW;
+static constexpr raw_ostream::Colors LiteralColor = raw_ostream::GREEN;
+static constexpr raw_ostream::Colors KeywordColor = raw_ostream::BLUE;
+
 /// Add highlights to differences in template strings.
 static void applyTemplateHighlighting(raw_ostream &OS, StringRef Str,
   bool &Normal, bool Bold) {
@@ -644,10 +653,10 @@ static bool printWordWrapped(raw_ostream &OS, StringRef 
Str, unsigned Columns,
   return Wrapped;
 }
 
-TextDiagnostic::TextDiagnostic(raw_ostream &OS,
-   const LangOptions &LangOpts,
-

[clang] [clang][analyzer] Improve modeling of 'fdopen' in StdLibraryFunctionsChecker (PR #78680)

2024-01-19 Thread Balázs Kéri via cfe-commits

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


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


[openmp] [clang] [OpenMP][USM] Introduces -fopenmp-force-usm flag (PR #76571)

2024-01-19 Thread Jan Patrick Lehr via cfe-commits

jplehr wrote:

@carlobertolli can you have another look at the runtime test I added to see if 
that addresses your feedback?

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


[llvm] [clang] [clang-tools-extra] [CLANG] Fix : More Detailed "No expected directives found" (PR #78338)

2024-01-19 Thread Timm Baeder via cfe-commits


@@ -11,7 +11,7 @@
 #error
 // expected-error@-1 {{}}
 
-//  CHECK: error: no expected directives found: consider use of 
'expected-no-diagnostics'
+//  CHECK: error: no expected directives found: consider use of 
'{{.*}}-no-diagnostics'

tbaederr wrote:

This test only passes `-verify` though, what's the new output and why doesn't 
the old expected output work?

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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2024-01-19 Thread Timm Baeder 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?= 
Message-ID:
In-Reply-To: 


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

>From 41bb52dc591ce1c154a4272abb738c80a7a57b90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 15 Sep 2023 15:51:39 +0200
Subject: [PATCH 1/5] [clang][Diagnostics] Highlight code snippets

Add some primitive syntax highlighting to our code snippet output.
---
 clang/include/clang/Frontend/TextDiagnostic.h |  18 +-
 clang/include/clang/Lex/Preprocessor.h|   5 +
 clang/lib/Frontend/TextDiagnostic.cpp | 197 +-
 clang/lib/Frontend/TextDiagnosticPrinter.cpp  |   2 +-
 clang/lib/Lex/Preprocessor.cpp|  24 +++
 5 files changed, 232 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Frontend/TextDiagnostic.h 
b/clang/include/clang/Frontend/TextDiagnostic.h
index 7eb0ab0cdc9bca..a2fe8ae995423b 100644
--- a/clang/include/clang/Frontend/TextDiagnostic.h
+++ b/clang/include/clang/Frontend/TextDiagnostic.h
@@ -16,6 +16,7 @@
 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 
 #include "clang/Frontend/DiagnosticRenderer.h"
+#include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 
@@ -33,14 +34,22 @@ namespace clang {
 /// printing coming out of libclang.
 class TextDiagnostic : public DiagnosticRenderer {
   raw_ostream &OS;
+  const Preprocessor *PP;
 
 public:
-  TextDiagnostic(raw_ostream &OS,
- const LangOptions &LangOpts,
- DiagnosticOptions *DiagOpts);
+  TextDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
+ DiagnosticOptions *DiagOpts, const Preprocessor *PP = 
nullptr);
 
   ~TextDiagnostic() override;
 
+  struct StyleRange {
+unsigned Start;
+unsigned End;
+enum llvm::raw_ostream::Colors Color;
+StyleRange(unsigned S, unsigned E, enum llvm::raw_ostream::Colors C)
+: Start(S), End(E), Color(C){};
+  };
+
   /// Print the diagonstic level to a raw_ostream.
   ///
   /// This is a static helper that handles colorizing the level and formatting
@@ -104,7 +113,8 @@ class TextDiagnostic : public DiagnosticRenderer {
ArrayRef Hints);
 
   void emitSnippet(StringRef SourceLine, unsigned MaxLineNoDisplayWidth,
-   unsigned LineNo);
+   unsigned LineNo, unsigned DisplayLineNo,
+   ArrayRef Styles);
 
   void emitParseableFixits(ArrayRef Hints, const SourceManager &SM);
 };
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 4ec21a8b6be2c8..d89e2be1bf5ff5 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -284,6 +284,8 @@ class Preprocessor {
   /// The kind of translation unit we are processing.
   const TranslationUnitKind TUKind;
 
+  const char *getCheckPoint(FileID FID, const char *Start) const;
+
 private:
   /// The code-completion handler.
   CodeCompletionHandler *CodeComplete = nullptr;
@@ -311,6 +313,9 @@ class Preprocessor {
   /// The import path for named module that we're currently processing.
   SmallVector, 2> 
NamedModuleImportPath;
 
+  llvm::DenseMap> CheckPoints;
+  unsigned CheckPointCounter = 0;
+
   /// Whether the import is an `@import` or a standard c++ modules import.
   bool IsAtImport = false;
 
diff --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index 779dead5d058d1..691809ceded87b 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -12,6 +12,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -41,6 +42,14 @@ static const enum raw_ostream::Colors fatalColor = 
raw_ostream::RED;
 static const enum raw_ostream::Colors savedColor =
   raw_ostream::SAVEDCOLOR;
 
+// Magenta is taken for 'warning'. Red is already 'error' and 'cyan'
+// is already taken for 'note'. Green is already used to underline
+// source ranges. White and black are bad because of the usual
+// terminal backgrounds. Which leaves us only with TWO options.
+static constexpr raw_ostream::Colors CommentColor = raw_ostream::YELLOW;
+static constexpr raw_ostream::Colors LiteralColor = raw_ostream::GREEN;
+static constexpr raw_ostream::Colors KeywordColor = raw_ostream::BLUE;
+
 /// Add highlights to differences in template strings.
 static void applyTemplateHighlighting(raw_ostream &OS, StringRef Str,
   bool &Normal, bool Bold) {
@@ -644,10 +653,10 @@ static bool printWordWrapped(raw_ostream &OS, StringRef 
Str, unsigned Columns,
   return Wrapped;
 }
 
-TextDiagnostic::TextDiagnostic(raw_ostream &OS,
-   const LangOptions &LangOpts,
- 

[clang] 4e7cf1b - [clang][Interp] Add an EvaluationResult class (#71315)

2024-01-19 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-01-19T10:08:03+01:00
New Revision: 4e7cf1b1ed3824d1298d4232922f54c6295eab50

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

LOG: [clang][Interp] Add an EvaluationResult class (#71315)

Add an `EvaluationResult` class. This contains the result either as a
`Pointer` or as a `APValue`.

This way, we can inspect the result of the evaluation and diagnose
problems with it (e.g. uninitialized fields in global initializers or
pointers pointing to things they shouldn't point to).

Added: 
clang/lib/AST/Interp/EvaluationResult.cpp
clang/lib/AST/Interp/EvaluationResult.h

Modified: 
clang/lib/AST/CMakeLists.txt
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/Interp/ByteCodeEmitter.cpp
clang/lib/AST/Interp/ByteCodeEmitter.h
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/lib/AST/Interp/Context.cpp
clang/lib/AST/Interp/Context.h
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/EvalEmitter.h
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/lib/AST/Interp/Pointer.cpp
clang/lib/AST/Interp/Pointer.h
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index fe3f8c485ec1c5..ebcb3952198a5b 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -75,6 +75,7 @@ add_clang_library(clangAST
   Interp/Function.cpp
   Interp/InterpBuiltin.cpp
   Interp/Floating.cpp
+  Interp/EvaluationResult.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
   Interp/InterpFrame.cpp

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 0884988c48b4e8..f1d07d022b2584 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15439,11 +15439,13 @@ static bool EvaluateAsRValue(EvalInfo &Info, const 
Expr *E, APValue &Result) {
   if (Info.EnableNewConstInterp) {
 if (!Info.Ctx.getInterpContext().evaluateAsRValue(Info, E, Result))
   return false;
-  } else {
-if (!::Evaluate(Result, Info, E))
-  return false;
+return CheckConstantExpression(Info, E->getExprLoc(), E->getType(), Result,
+   ConstantExprKind::Normal);
   }
 
+  if (!::Evaluate(Result, Info, E))
+return false;
+
   // Implicit lvalue-to-rvalue cast.
   if (E->isGLValue()) {
 LValue LV;
@@ -15671,6 +15673,13 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, 
const ASTContext &Ctx,
   EvalInfo Info(Ctx, Result, EM);
   Info.InConstantContext = true;
 
+  if (Info.EnableNewConstInterp) {
+if (!Info.Ctx.getInterpContext().evaluate(Info, this, Result.Val))
+  return false;
+return CheckConstantExpression(Info, getExprLoc(),
+   getStorageType(Ctx, this), Result.Val, 
Kind);
+  }
+
   // The type of the object we're initializing is 'const T' for a class NTTP.
   QualType T = getType();
   if (Kind == ConstantExprKind::ClassTemplateArgument)
@@ -15746,10 +15755,16 @@ bool Expr::EvaluateAsInitializer(APValue &Value, 
const ASTContext &Ctx,
   Info.setEvaluatingDecl(VD, Value);
   Info.InConstantContext = IsConstantInitialization;
 
+  SourceLocation DeclLoc = VD->getLocation();
+  QualType DeclTy = VD->getType();
+
   if (Info.EnableNewConstInterp) {
 auto &InterpCtx = const_cast(Ctx).getInterpContext();
 if (!InterpCtx.evaluateAsInitializer(Info, VD, Value))
   return false;
+
+return CheckConstantExpression(Info, DeclLoc, DeclTy, Value,
+   ConstantExprKind::Normal);
   } else {
 LValue LVal;
 LVal.set(VD);
@@ -15779,8 +15794,6 @@ bool Expr::EvaluateAsInitializer(APValue &Value, const 
ASTContext &Ctx,
   llvm_unreachable("Unhandled cleanup; missing full expression marker?");
   }
 
-  SourceLocation DeclLoc = VD->getLocation();
-  QualType DeclTy = VD->getType();
   return CheckConstantExpression(Info, DeclLoc, DeclTy, Value,
  ConstantExprKind::Normal) &&
  CheckMemoryLeaks(Info);

diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index 045263447cbc91..fd2a92d9d3f91e 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -20,8 +20,7 @@
 using namespace clang;
 using namespace clang::interp;
 
-Expected
-ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
+Function *ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
   // Set up argument indices.
   unsigned ParamOffset = 0;
   SmallVector ParamTypes;
@@ -120,10 +119,6 @@ ByteCodeEmitter::compileFunc(const Funct

[clang] [clang][Interp] Add an EvaluationResult class (PR #71315)

2024-01-19 Thread Timm Baeder via cfe-commits

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


[clang] [llvm] [RISCV] Add B extension (PR #76893)

2024-01-19 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp updated 
https://github.com/llvm/llvm-project/pull/76893

>From c4f7441b2809dfbb6ed4b6d97d581e3d736819fe Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Thu, 4 Jan 2024 13:05:53 +0800
Subject: [PATCH] [RISCV] Add B extension

It seems that we have `B` extension again: https://github.com/riscv/riscv-b

According to the spec, `B` extension represents the collection of
the `Zba`, `Zbb`, `Zbs` extensions.

Though it hasn't been ratified, I set its version to `1.0`.
---
 clang/test/Driver/riscv-arch.c  |  5 -
 clang/test/Preprocessor/riscv-target-features.c | 12 
 llvm/docs/RISCVUsage.rst|  1 +
 llvm/lib/Support/RISCVISAInfo.cpp   |  5 -
 llvm/lib/Target/RISCV/RISCVFeatures.td  |  8 
 llvm/test/CodeGen/RISCV/attributes.ll   |  4 
 llvm/unittests/Support/RISCVISAInfoTest.cpp |  6 ++
 7 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index 0ac81ea982f1b61..7c9f880c74035ba 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -233,11 +233,6 @@
 // RV32-STD: error: invalid arch name 'rv32imqc',
 // RV32-STD: unsupported standard user-level extension 'q'
 
-// RUN: not %clang --target=riscv32-unknown-elf -march=rv32ib -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-B %s
-// RV32-B: error: invalid arch name 'rv32ib',
-// RV32-B: unsupported standard user-level extension 'b'
-
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32xabc -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32X %s
 // RV32X: error: invalid arch name 'rv32xabc',
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 8dc02f7efefbd6f..6acd7b1f2d6d6ad 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -7,6 +7,7 @@
 // CHECK-NOT: __riscv_64e {{.*$}}
 // CHECK-NOT: __riscv_a {{.*$}}
 // CHECK-NOT: __riscv_atomic
+// CHECK-NOT: __riscv_b {{.*$}}
 // CHECK-NOT: __riscv_c {{.*$}}
 // CHECK-NOT: __riscv_compressed {{.*$}}
 // CHECK-NOT: __riscv_d {{.*$}}
@@ -159,6 +160,17 @@
 // CHECK-A-EXT: __riscv_a 2001000{{$}}
 // CHECK-A-EXT: __riscv_atomic 1
 
+// RUN: %clang --target=riscv32-unknown-linux-gnu \
+// RUN: -march=rv32ib -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
+// RUN: %clang --target=riscv64-unknown-linux-gnu \
+// RUN: -march=rv64ib -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
+// CHECK-B-EXT: __riscv_b 100{{$}}
+// CHECK-B-EXT: __riscv_zba 100{{$}}
+// CHECK-B-EXT: __riscv_zbb 100{{$}}
+// CHECK-B-EXT: __riscv_zbs 100{{$}}
+
 // RUN: %clang --target=riscv32-unknown-linux-gnu \
 // RUN: -march=rv32ic -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-C-EXT %s
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index fc4d97b13437153..bfdceb81ce2dc76 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -85,6 +85,7 @@ on support follow.
  ExtensionStatus
  ===  =
  ``A``Supported
+ ``B``Supported
  ``C``Supported
  ``D``Supported
  ``F``Supported
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 8c9eb1bddb3cb52..1f194851d0681e4 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -46,6 +46,7 @@ static const char *RISCVGImplications[] = {
 // NOTE: This table should be sorted alphabetically by extension name.
 static const RISCVSupportedExtension SupportedExtensions[] = {
 {"a", {2, 1}},
+{"b", {1, 0}},
 {"c", {2, 0}},
 {"d", {2, 2}},
 {"e", {2, 0}},
@@ -848,7 +849,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool 
EnableExperimentalExtension,
 }
 
 // The order is OK, then push it into features.
-// Currently LLVM supports only "mafdcvh".
+// Currently LLVM supports only "mafdcbvh".
 if (!isSupportedExtension(StringRef(&C, 1))) {
   if (IgnoreUnknown) {
 GoToNextExt(I, ConsumeLength, Exts.end());
@@ -998,6 +999,7 @@ Error RISCVISAInfo::checkDependency() {
   return Error::success();
 }
 
+static const char *ImpliedExtsB[] = {"zba", "zbb", "zbs"};
 static const char *ImpliedExtsD[] = {"f"};
 static const char *ImpliedExtsF[] = {"zicsr"};
 static const char *ImpliedExtsV[] = {"zvl128b", "zve64d"};
@@ -1072,6 +1074,7 @@ struct ImpliedExtsEntry {
 
 // Note: The table needs to be sorted by name.
 static constexpr ImpliedExtsEntry ImpliedExts[] = {
+{{"b"}, {ImpliedExtsB}},
 {{"d"}, {ImpliedExtsD}},
 {{"f"}, {ImpliedExtsF}},
 {{"v"}, {ImpliedExtsV}},
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Tar

[clang] [Sema] Provide `-fno-/-fvisibility-global-new-delete` option (PR #75364)

2024-01-19 Thread via cfe-commits

https://github.com/bd1976bris updated 
https://github.com/llvm/llvm-project/pull/75364

>From 97efed8c73aed4fdca5510013c844e84953ec256 Mon Sep 17 00:00:00 2001
From: Ben Dunbobbin 
Date: Tue, 12 Dec 2023 08:07:17 +
Subject: [PATCH 1/4] [Sema] Provide `-fno-/-fvisibility-global-new-delete`
 option

By default the implicitly declared replaceable global new and delete
operators are given a `default` visibility attribute. Previous work,
see: https://reviews.llvm.org/D53787, added
`-fvisibility-global-new-delete-hidden` to change this to a `hidden`
visibility attribute.

This change adds: `-fno/-fvisibility-global-new-delete` which controls
whether or not to add a visibility attribute to the implicit
declarations for these functions. Without the attribute the replaceable
global new and delete operators behave normally (like other functions)
with respect to visibility attributes, pragmas and options.

The command line help for these options is rendered as:

  -fvisibility-global-new-delete
  Add a visibility attribute to the implicit
  global C++ operator new and delete declarations

  -fno-visibility-global-new-delete
  Do not add a visibility attribute to the implicit
  global C++ operator new and delete declarations

The motivation is to allow users to specify
`-fno-visibility-global-new-delete` when they intend to replace these
functions either for a single linkage unit or set of linkage units.

`-fno-visibility-global-new-delete` can be applied globally to the
compilations in a build where `-fvisibility-global-new-delete-hidden`
cannot; as it conflicts with a common pattern where these functions are
dynamically imported.

`-fno-visibility-global-new-delete` makes sense as the default for PS5.
Users that want the normal toolchain behaviour will be able to supply
`-fvisibility-global-new-delete`.
---
 clang/include/clang/Basic/LangOptions.def |  3 +-
 clang/include/clang/Driver/Options.td |  6 +++
 clang/lib/Driver/ToolChains/Clang.cpp | 12 +
 clang/lib/Driver/ToolChains/PS4CPU.cpp|  6 +++
 clang/lib/Sema/SemaExprCXX.cpp|  9 ++--
 .../visibility-global-new-delete.cpp  | 13 +
 .../Driver/visibility-global-new-delete.cl| 47 +++
 7 files changed, 91 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/visibility-global-new-delete.cpp
 create mode 100644 clang/test/Driver/visibility-global-new-delete.cl

diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index c3d5399905a3fd..1471fc11e11663 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -306,7 +306,8 @@ BENIGN_LANGOPT(IgnoreXCOFFVisibility, 1, 0, "All the 
visibility attributes that
 BENIGN_LANGOPT(VisibilityInlinesHiddenStaticLocalVar, 1, 0,
"hidden visibility for static local variables in inline C++ "
"methods when -fvisibility-inlines hidden is enabled")
-LANGOPT(GlobalAllocationFunctionVisibilityHidden , 1, 0, "hidden visibility 
for global operator new and delete declaration")
+LANGOPT(GlobalAllocationFunctionVisibility, 1, 1, "add a visibility attribute 
to the implicit global operator new and delete declarations")
+LANGOPT(GlobalAllocationFunctionVisibilityHidden, 1, 0, "hidden visibility for 
global operator new and delete declarations")
 LANGOPT(NewInfallible , 1, 0, "Treats throwing global C++ operator new as 
always returning valid memory (annotates with __attribute__((returns_nonnull)) 
and throw()). This is detectable in source.")
 BENIGN_LANGOPT(ParseUnknownAnytype, 1, 0, "__unknown_anytype")
 BENIGN_LANGOPT(DebuggerSupport , 1, 0, "debugger support")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index db2190318c931a..a9f43b18df6fbf 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3863,6 +3863,12 @@ defm visibility_inlines_hidden_static_local_var : 
BoolFOption<"visibility-inline
 def fvisibility_ms_compat : Flag<["-"], "fvisibility-ms-compat">, 
Group,
   HelpText<"Give global types 'default' visibility and global functions and "
"variables 'hidden' visibility by default">;
+defm visibility_global_new_delete : BoolFOption<"visibility-global-new-delete",
+  LangOpts<"GlobalAllocationFunctionVisibility">, DefaultTrue,
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [ClangOption, CC1Option],
+  " a visibility attribute to the implicit global C++ operator new and 
delete declarations">>;
 def fvisibility_global_new_delete_hidden : Flag<["-"], 
"fvisibility-global-new-delete-hidden">, Group,
   HelpText<"Give global C++ operator new and delete declarations hidden 
visibility">,
   Visibility<[ClangOption, CC1Option]>,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
inde

[clang] [Sema] Provide `-fvisibility-global-new-delete=` option (PR #75364)

2024-01-19 Thread via cfe-commits

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


[clang] [Sema] Provide `-fvisibility-global-new-delete=` option (PR #75364)

2024-01-19 Thread via cfe-commits

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


[clang] [Sema] Provide `-fvisibility-global-new-delete=` option (PR #75364)

2024-01-19 Thread via cfe-commits

bd1976bris wrote:

Given that there have been no objections I have modified this to match 
@zygoloid's suggestion of `-fvisibility-global-new-delete=`. Please take 
another look.

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


[clang-tools-extra] [clang-apply-replacements] Deduplicate Implementation of `collectReplacementsFromDirectory` (NFC) (PR #78630)

2024-01-19 Thread Congcong Cai via cfe-commits

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

LGTM

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


[clang] [llvm] [clang-tools-extra] [VPlan] Introduce VPSingleDefRecipe. (PR #77023)

2024-01-19 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/77023

>From ddecbda9f079584a55feed322d8d20b766349ab9 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Thu, 4 Jan 2024 22:07:31 +
Subject: [PATCH 1/3] [VPlan] Introduce VPSingleDefRecipe.

This patch introduces a new common base class for recipes defining
a single result VPValue. This has been discussed/mentioned at various
previous reviews as potential follow-up and helps to replace various
getVPSingleValue calls.
---
 .../Transforms/Vectorize/LoopVectorize.cpp|  28 ++-
 llvm/lib/Transforms/Vectorize/VPlan.h | 177 --
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp |   4 +-
 .../Transforms/Vectorize/VPlanTransforms.cpp  |  36 ++--
 4 files changed, 152 insertions(+), 93 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp 
b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 10c068e3b5895c..6cb77bfa0beffd 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8937,12 +8937,12 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
"AnyOf reductions are not allowed for in-loop reductions");
 
 // Collect the chain of "link" recipes for the reduction starting at PhiR.
-SetVector Worklist;
+SetVector Worklist;
 Worklist.insert(PhiR);
 for (unsigned I = 0; I != Worklist.size(); ++I) {
-  VPRecipeBase *Cur = Worklist[I];
-  for (VPUser *U : Cur->getVPSingleValue()->users()) {
-auto *UserRecipe = dyn_cast(U);
+  VPSingleDefRecipe *Cur = Worklist[I];
+  for (VPUser *U : Cur->users()) {
+auto *UserRecipe = dyn_cast(U);
 if (!UserRecipe)
   continue;
 assert(UserRecipe->getNumDefinedValues() == 1 &&
@@ -8956,10 +8956,8 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
 // (PreviousLink) to tell which of the two operands of a Link will remain
 // scalar and which will be reduced. For minmax by select(cmp), Link will 
be
 // the select instructions.
-VPRecipeBase *PreviousLink = PhiR; // Aka Worklist[0].
-for (VPRecipeBase *CurrentLink : Worklist.getArrayRef().drop_front()) {
-  VPValue *PreviousLinkV = PreviousLink->getVPSingleValue();
-
+VPSingleDefRecipe *PreviousLink = PhiR; // Aka Worklist[0].
+for (VPSingleDefRecipe *CurrentLink : Worklist.getArrayRef().drop_front()) 
{
   Instruction *CurrentLinkI = CurrentLink->getUnderlyingInstr();
 
   // Index of the first operand which holds a non-mask vector operand.
@@ -8974,7 +8972,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
 "Expected instruction to be a call to the llvm.fmuladd intrinsic");
 assert(((MinVF.isScalar() && isa(CurrentLink)) ||
 isa(CurrentLink)) &&
-   CurrentLink->getOperand(2) == PreviousLinkV &&
+   CurrentLink->getOperand(2) == PreviousLink &&
"expected a call where the previous link is the added operand");
 
 // If the instruction is a call to the llvm.fmuladd intrinsic then we
@@ -9005,15 +9003,15 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
 // Note that for non-commutable operands (cmp-selects), the semantics 
of
 // the cmp-select are captured in the recurrence kind.
 unsigned VecOpId =
-CurrentLink->getOperand(IndexOfFirstOperand) == PreviousLinkV
+CurrentLink->getOperand(IndexOfFirstOperand) == PreviousLink
 ? IndexOfFirstOperand + 1
 : IndexOfFirstOperand;
 VecOp = CurrentLink->getOperand(VecOpId);
-assert(VecOp != PreviousLinkV &&
+assert(VecOp != PreviousLink &&
CurrentLink->getOperand(CurrentLink->getNumOperands() - 1 -
(VecOpId - IndexOfFirstOperand)) ==
-   PreviousLinkV &&
-   "PreviousLinkV must be the operand other than VecOp");
+   PreviousLink &&
+   "PreviousLink must be the operand other than VecOp");
   }
 
   BasicBlock *BB = CurrentLinkI->getParent();
@@ -9025,13 +9023,13 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
   }
 
   VPReductionRecipe *RedRecipe = new VPReductionRecipe(
-  RdxDesc, CurrentLinkI, PreviousLinkV, VecOp, CondOp);
+  RdxDesc, CurrentLinkI, PreviousLink, VecOp, CondOp);
   // Append the recipe to the end of the VPBasicBlock because we need to
   // ensure that it comes after all of it's inputs, including CondOp.
   // Note that this transformation may leave over dead recipes (including
   // CurrentLink), which will be cleaned by a later VPlan transform.
   LinkVPBB->appendRecipe(RedRecipe);
-  CurrentLink->getVPSingleValue()->replaceAllUsesWith(RedRecipe);
+  CurrentLink->replaceAllUsesWith(RedRecipe);
   PreviousLink = RedRecipe;
 }
   }
diff --git a

[clang] Reland "[clang] Fix CTAD for aggregates for nested template classes" (PR #78670)

2024-01-19 Thread via cfe-commits

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


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


[clang] [Sema] Provide `-fvisibility-global-new-delete=` option (PR #75364)

2024-01-19 Thread via cfe-commits

https://github.com/bd1976bris updated 
https://github.com/llvm/llvm-project/pull/75364

>From 97efed8c73aed4fdca5510013c844e84953ec256 Mon Sep 17 00:00:00 2001
From: Ben Dunbobbin 
Date: Tue, 12 Dec 2023 08:07:17 +
Subject: [PATCH 1/5] [Sema] Provide `-fno-/-fvisibility-global-new-delete`
 option

By default the implicitly declared replaceable global new and delete
operators are given a `default` visibility attribute. Previous work,
see: https://reviews.llvm.org/D53787, added
`-fvisibility-global-new-delete-hidden` to change this to a `hidden`
visibility attribute.

This change adds: `-fno/-fvisibility-global-new-delete` which controls
whether or not to add a visibility attribute to the implicit
declarations for these functions. Without the attribute the replaceable
global new and delete operators behave normally (like other functions)
with respect to visibility attributes, pragmas and options.

The command line help for these options is rendered as:

  -fvisibility-global-new-delete
  Add a visibility attribute to the implicit
  global C++ operator new and delete declarations

  -fno-visibility-global-new-delete
  Do not add a visibility attribute to the implicit
  global C++ operator new and delete declarations

The motivation is to allow users to specify
`-fno-visibility-global-new-delete` when they intend to replace these
functions either for a single linkage unit or set of linkage units.

`-fno-visibility-global-new-delete` can be applied globally to the
compilations in a build where `-fvisibility-global-new-delete-hidden`
cannot; as it conflicts with a common pattern where these functions are
dynamically imported.

`-fno-visibility-global-new-delete` makes sense as the default for PS5.
Users that want the normal toolchain behaviour will be able to supply
`-fvisibility-global-new-delete`.
---
 clang/include/clang/Basic/LangOptions.def |  3 +-
 clang/include/clang/Driver/Options.td |  6 +++
 clang/lib/Driver/ToolChains/Clang.cpp | 12 +
 clang/lib/Driver/ToolChains/PS4CPU.cpp|  6 +++
 clang/lib/Sema/SemaExprCXX.cpp|  9 ++--
 .../visibility-global-new-delete.cpp  | 13 +
 .../Driver/visibility-global-new-delete.cl| 47 +++
 7 files changed, 91 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/visibility-global-new-delete.cpp
 create mode 100644 clang/test/Driver/visibility-global-new-delete.cl

diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index c3d5399905a3fd..1471fc11e11663 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -306,7 +306,8 @@ BENIGN_LANGOPT(IgnoreXCOFFVisibility, 1, 0, "All the 
visibility attributes that
 BENIGN_LANGOPT(VisibilityInlinesHiddenStaticLocalVar, 1, 0,
"hidden visibility for static local variables in inline C++ "
"methods when -fvisibility-inlines hidden is enabled")
-LANGOPT(GlobalAllocationFunctionVisibilityHidden , 1, 0, "hidden visibility 
for global operator new and delete declaration")
+LANGOPT(GlobalAllocationFunctionVisibility, 1, 1, "add a visibility attribute 
to the implicit global operator new and delete declarations")
+LANGOPT(GlobalAllocationFunctionVisibilityHidden, 1, 0, "hidden visibility for 
global operator new and delete declarations")
 LANGOPT(NewInfallible , 1, 0, "Treats throwing global C++ operator new as 
always returning valid memory (annotates with __attribute__((returns_nonnull)) 
and throw()). This is detectable in source.")
 BENIGN_LANGOPT(ParseUnknownAnytype, 1, 0, "__unknown_anytype")
 BENIGN_LANGOPT(DebuggerSupport , 1, 0, "debugger support")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index db2190318c931a..a9f43b18df6fbf 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3863,6 +3863,12 @@ defm visibility_inlines_hidden_static_local_var : 
BoolFOption<"visibility-inline
 def fvisibility_ms_compat : Flag<["-"], "fvisibility-ms-compat">, 
Group,
   HelpText<"Give global types 'default' visibility and global functions and "
"variables 'hidden' visibility by default">;
+defm visibility_global_new_delete : BoolFOption<"visibility-global-new-delete",
+  LangOpts<"GlobalAllocationFunctionVisibility">, DefaultTrue,
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [ClangOption, CC1Option],
+  " a visibility attribute to the implicit global C++ operator new and 
delete declarations">>;
 def fvisibility_global_new_delete_hidden : Flag<["-"], 
"fvisibility-global-new-delete-hidden">, Group,
   HelpText<"Give global C++ operator new and delete declarations hidden 
visibility">,
   Visibility<[ClangOption, CC1Option]>,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
inde

[clang] [llvm] [clang-tools-extra] [VPlan] Introduce VPSingleDefRecipe. (PR #77023)

2024-01-19 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/77023

>From ddecbda9f079584a55feed322d8d20b766349ab9 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Thu, 4 Jan 2024 22:07:31 +
Subject: [PATCH 1/4] [VPlan] Introduce VPSingleDefRecipe.

This patch introduces a new common base class for recipes defining
a single result VPValue. This has been discussed/mentioned at various
previous reviews as potential follow-up and helps to replace various
getVPSingleValue calls.
---
 .../Transforms/Vectorize/LoopVectorize.cpp|  28 ++-
 llvm/lib/Transforms/Vectorize/VPlan.h | 177 --
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp |   4 +-
 .../Transforms/Vectorize/VPlanTransforms.cpp  |  36 ++--
 4 files changed, 152 insertions(+), 93 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp 
b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 10c068e3b5895c..6cb77bfa0beffd 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8937,12 +8937,12 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
"AnyOf reductions are not allowed for in-loop reductions");
 
 // Collect the chain of "link" recipes for the reduction starting at PhiR.
-SetVector Worklist;
+SetVector Worklist;
 Worklist.insert(PhiR);
 for (unsigned I = 0; I != Worklist.size(); ++I) {
-  VPRecipeBase *Cur = Worklist[I];
-  for (VPUser *U : Cur->getVPSingleValue()->users()) {
-auto *UserRecipe = dyn_cast(U);
+  VPSingleDefRecipe *Cur = Worklist[I];
+  for (VPUser *U : Cur->users()) {
+auto *UserRecipe = dyn_cast(U);
 if (!UserRecipe)
   continue;
 assert(UserRecipe->getNumDefinedValues() == 1 &&
@@ -8956,10 +8956,8 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
 // (PreviousLink) to tell which of the two operands of a Link will remain
 // scalar and which will be reduced. For minmax by select(cmp), Link will 
be
 // the select instructions.
-VPRecipeBase *PreviousLink = PhiR; // Aka Worklist[0].
-for (VPRecipeBase *CurrentLink : Worklist.getArrayRef().drop_front()) {
-  VPValue *PreviousLinkV = PreviousLink->getVPSingleValue();
-
+VPSingleDefRecipe *PreviousLink = PhiR; // Aka Worklist[0].
+for (VPSingleDefRecipe *CurrentLink : Worklist.getArrayRef().drop_front()) 
{
   Instruction *CurrentLinkI = CurrentLink->getUnderlyingInstr();
 
   // Index of the first operand which holds a non-mask vector operand.
@@ -8974,7 +8972,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
 "Expected instruction to be a call to the llvm.fmuladd intrinsic");
 assert(((MinVF.isScalar() && isa(CurrentLink)) ||
 isa(CurrentLink)) &&
-   CurrentLink->getOperand(2) == PreviousLinkV &&
+   CurrentLink->getOperand(2) == PreviousLink &&
"expected a call where the previous link is the added operand");
 
 // If the instruction is a call to the llvm.fmuladd intrinsic then we
@@ -9005,15 +9003,15 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
 // Note that for non-commutable operands (cmp-selects), the semantics 
of
 // the cmp-select are captured in the recurrence kind.
 unsigned VecOpId =
-CurrentLink->getOperand(IndexOfFirstOperand) == PreviousLinkV
+CurrentLink->getOperand(IndexOfFirstOperand) == PreviousLink
 ? IndexOfFirstOperand + 1
 : IndexOfFirstOperand;
 VecOp = CurrentLink->getOperand(VecOpId);
-assert(VecOp != PreviousLinkV &&
+assert(VecOp != PreviousLink &&
CurrentLink->getOperand(CurrentLink->getNumOperands() - 1 -
(VecOpId - IndexOfFirstOperand)) ==
-   PreviousLinkV &&
-   "PreviousLinkV must be the operand other than VecOp");
+   PreviousLink &&
+   "PreviousLink must be the operand other than VecOp");
   }
 
   BasicBlock *BB = CurrentLinkI->getParent();
@@ -9025,13 +9023,13 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
   }
 
   VPReductionRecipe *RedRecipe = new VPReductionRecipe(
-  RdxDesc, CurrentLinkI, PreviousLinkV, VecOp, CondOp);
+  RdxDesc, CurrentLinkI, PreviousLink, VecOp, CondOp);
   // Append the recipe to the end of the VPBasicBlock because we need to
   // ensure that it comes after all of it's inputs, including CondOp.
   // Note that this transformation may leave over dead recipes (including
   // CurrentLink), which will be cleaned by a later VPlan transform.
   LinkVPBB->appendRecipe(RedRecipe);
-  CurrentLink->getVPSingleValue()->replaceAllUsesWith(RedRecipe);
+  CurrentLink->replaceAllUsesWith(RedRecipe);
   PreviousLink = RedRecipe;
 }
   }
diff --git a

[clang-tools-extra] [llvm] [clang] [VPlan] Introduce VPSingleDefRecipe. (PR #77023)

2024-01-19 Thread Florian Hahn via cfe-commits


@@ -12,6 +12,8 @@
 ///VPBlockBase, together implementing a Hierarchical CFG;
 /// 2. Pure virtual VPRecipeBase serving as the base class for recipes 
contained
 ///within VPBasicBlocks;
+/// 3. Pure virtual VPSingleDefRecipe serving as a base class for recipes that
+///also inherit from VPValue.
 /// 3. VPInstruction, a concrete Recipe and VPUser modeling a single planned
 ///instruction;
 /// 4. The VPlan class holding a candidate for vectorization;

fhahn wrote:

Done, thanks!

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


[clang] [llvm] [clang-tools-extra] [VPlan] Introduce VPSingleDefRecipe. (PR #77023)

2024-01-19 Thread Florian Hahn via cfe-commits


@@ -819,10 +812,77 @@ class VPRecipeBase : public 
ilist_node_with_parent,
   }
\
   static inline bool classof(const VPRecipeBase *R) {  
\
 return R->getVPDefID() == VPDefID; 
\
+  }
\
+  static inline bool classof(const VPSingleDefRecipe *R) { 
\
+return R->getVPDefID() == VPDefID; 
\
   }
 
+/// VPSingleDef is a base class for recipes for modeling a sequence of one or
+/// more output IR that define a single result VPValue.
+class VPSingleDefRecipe : public VPRecipeBase, public VPValue {
+public:
+  template 
+  VPSingleDefRecipe(const unsigned char SC, IterT Operands, DebugLoc DL = {})
+  : VPRecipeBase(SC, Operands, DL), VPValue(this) {}
+
+  VPSingleDefRecipe(const unsigned char SC, ArrayRef Operands,
+DebugLoc DL = {})
+  : VPRecipeBase(SC, Operands, DL), VPValue(this) {}
+
+  template 
+  VPSingleDefRecipe(const unsigned char SC, IterT Operands, Value *UV,
+DebugLoc DL = {})
+  : VPRecipeBase(SC, Operands, DL), VPValue(this, UV) {}
+
+  static inline bool classof(const VPRecipeBase *R) {
+switch (R->getVPDefID()) {
+case VPRecipeBase::VPDerivedIVSC:
+case VPRecipeBase::VPExpandSCEVSC:
+case VPRecipeBase::VPInstructionSC:
+case VPRecipeBase::VPReductionSC:
+case VPRecipeBase::VPReplicateSC:
+case VPRecipeBase::VPScalarIVStepsSC:
+case VPRecipeBase::VPVectorPointerSC:
+case VPRecipeBase::VPWidenCallSC:
+case VPRecipeBase::VPWidenCanonicalIVSC:
+case VPRecipeBase::VPWidenCastSC:
+case VPRecipeBase::VPWidenGEPSC:
+case VPRecipeBase::VPWidenSC:
+case VPRecipeBase::VPWidenSelectSC:
+case VPRecipeBase::VPBlendSC:
+case VPRecipeBase::VPPredInstPHISC:
+case VPRecipeBase::VPCanonicalIVPHISC:
+case VPRecipeBase::VPActiveLaneMaskPHISC:
+case VPRecipeBase::VPFirstOrderRecurrencePHISC:
+case VPRecipeBase::VPWidenPHISC:
+case VPRecipeBase::VPWidenIntOrFpInductionSC:
+case VPRecipeBase::VPWidenPointerInductionSC:
+case VPRecipeBase::VPReductionPHISC:
+  return true;
+case VPRecipeBase::VPInterleaveSC:
+case VPRecipeBase::VPBranchOnMaskSC:
+case VPRecipeBase::VPWidenMemoryInstructionSC:

fhahn wrote:

Yes exactly, added a TODO

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


[llvm] [clang] [clang-tools-extra] [VPlan] Introduce VPSingleDefRecipe. (PR #77023)

2024-01-19 Thread Florian Hahn via cfe-commits


@@ -819,10 +812,77 @@ class VPRecipeBase : public 
ilist_node_with_parent,
   }
\
   static inline bool classof(const VPRecipeBase *R) {  
\
 return R->getVPDefID() == VPDefID; 
\
+  }
\
+  static inline bool classof(const VPSingleDefRecipe *R) { 
\
+return R->getVPDefID() == VPDefID; 
\
   }
 
+/// VPSingleDef is a base class for recipes for modeling a sequence of one or
+/// more output IR that define a single result VPValue.

fhahn wrote:

Added, thanks!

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


[llvm] [clang] [clang-tools-extra] [VPlan] Introduce VPSingleDefRecipe. (PR #77023)

2024-01-19 Thread Florian Hahn via cfe-commits


@@ -819,10 +812,77 @@ class VPRecipeBase : public 
ilist_node_with_parent,
   }
\
   static inline bool classof(const VPRecipeBase *R) {  
\
 return R->getVPDefID() == VPDefID; 
\
+  }
\
+  static inline bool classof(const VPSingleDefRecipe *R) { 
\
+return R->getVPDefID() == VPDefID; 
\
   }
 
+/// VPSingleDef is a base class for recipes for modeling a sequence of one or
+/// more output IR that define a single result VPValue.
+class VPSingleDefRecipe : public VPRecipeBase, public VPValue {
+public:
+  template 
+  VPSingleDefRecipe(const unsigned char SC, IterT Operands, DebugLoc DL = {})
+  : VPRecipeBase(SC, Operands, DL), VPValue(this) {}
+
+  VPSingleDefRecipe(const unsigned char SC, ArrayRef Operands,
+DebugLoc DL = {})
+  : VPRecipeBase(SC, Operands, DL), VPValue(this) {}
+
+  template 
+  VPSingleDefRecipe(const unsigned char SC, IterT Operands, Value *UV,
+DebugLoc DL = {})
+  : VPRecipeBase(SC, Operands, DL), VPValue(this, UV) {}
+
+  static inline bool classof(const VPRecipeBase *R) {
+switch (R->getVPDefID()) {
+case VPRecipeBase::VPDerivedIVSC:
+case VPRecipeBase::VPExpandSCEVSC:
+case VPRecipeBase::VPInstructionSC:
+case VPRecipeBase::VPReductionSC:
+case VPRecipeBase::VPReplicateSC:
+case VPRecipeBase::VPScalarIVStepsSC:
+case VPRecipeBase::VPVectorPointerSC:
+case VPRecipeBase::VPWidenCallSC:
+case VPRecipeBase::VPWidenCanonicalIVSC:
+case VPRecipeBase::VPWidenCastSC:
+case VPRecipeBase::VPWidenGEPSC:
+case VPRecipeBase::VPWidenSC:
+case VPRecipeBase::VPWidenSelectSC:
+case VPRecipeBase::VPBlendSC:
+case VPRecipeBase::VPPredInstPHISC:
+case VPRecipeBase::VPCanonicalIVPHISC:
+case VPRecipeBase::VPActiveLaneMaskPHISC:
+case VPRecipeBase::VPFirstOrderRecurrencePHISC:
+case VPRecipeBase::VPWidenPHISC:
+case VPRecipeBase::VPWidenIntOrFpInductionSC:
+case VPRecipeBase::VPWidenPointerInductionSC:
+case VPRecipeBase::VPReductionPHISC:
+  return true;
+case VPRecipeBase::VPInterleaveSC:
+case VPRecipeBase::VPBranchOnMaskSC:
+case VPRecipeBase::VPWidenMemoryInstructionSC:
+  return false;
+}
+llvm_unreachable("Unhandled VPDefID");
+  }
+
+  static inline bool classof(const VPUser *U) {
+auto *R = dyn_cast(U);
+return R && classof(R);
+  }
+
+  /// Returns the underlying instruction.
+  Instruction *getUnderlyingInstr() {
+return cast(getUnderlyingValue());

fhahn wrote:

Yes, it must only be called from contexts where it is guaranteed to be non-null.

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


[llvm] [clang-tools-extra] [clang] [VPlan] Introduce VPSingleDefRecipe. (PR #77023)

2024-01-19 Thread Florian Hahn via cfe-commits


@@ -912,25 +970,28 @@ class VPRecipeWithIRFlags : public VPRecipeBase {
 } else if (auto *Op = dyn_cast(&I)) {
   OpType = OperationType::FPMathOp;
   FMFs = Op->getFastMathFlags();
+} else {
+  OpType = OperationType::Other;
+  AllFlags = 0;

fhahn wrote:

Yes that could be done, at the cost of slightly increasing VPRecipeBase's size.

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


[clang] [llvm] [clang-tools-extra] [VPlan] Introduce VPSingleDefRecipe. (PR #77023)

2024-01-19 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/77023

>From ddecbda9f079584a55feed322d8d20b766349ab9 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Thu, 4 Jan 2024 22:07:31 +
Subject: [PATCH 1/5] [VPlan] Introduce VPSingleDefRecipe.

This patch introduces a new common base class for recipes defining
a single result VPValue. This has been discussed/mentioned at various
previous reviews as potential follow-up and helps to replace various
getVPSingleValue calls.
---
 .../Transforms/Vectorize/LoopVectorize.cpp|  28 ++-
 llvm/lib/Transforms/Vectorize/VPlan.h | 177 --
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp |   4 +-
 .../Transforms/Vectorize/VPlanTransforms.cpp  |  36 ++--
 4 files changed, 152 insertions(+), 93 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp 
b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 10c068e3b5895c2..6cb77bfa0beffdc 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8937,12 +8937,12 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
"AnyOf reductions are not allowed for in-loop reductions");
 
 // Collect the chain of "link" recipes for the reduction starting at PhiR.
-SetVector Worklist;
+SetVector Worklist;
 Worklist.insert(PhiR);
 for (unsigned I = 0; I != Worklist.size(); ++I) {
-  VPRecipeBase *Cur = Worklist[I];
-  for (VPUser *U : Cur->getVPSingleValue()->users()) {
-auto *UserRecipe = dyn_cast(U);
+  VPSingleDefRecipe *Cur = Worklist[I];
+  for (VPUser *U : Cur->users()) {
+auto *UserRecipe = dyn_cast(U);
 if (!UserRecipe)
   continue;
 assert(UserRecipe->getNumDefinedValues() == 1 &&
@@ -8956,10 +8956,8 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
 // (PreviousLink) to tell which of the two operands of a Link will remain
 // scalar and which will be reduced. For minmax by select(cmp), Link will 
be
 // the select instructions.
-VPRecipeBase *PreviousLink = PhiR; // Aka Worklist[0].
-for (VPRecipeBase *CurrentLink : Worklist.getArrayRef().drop_front()) {
-  VPValue *PreviousLinkV = PreviousLink->getVPSingleValue();
-
+VPSingleDefRecipe *PreviousLink = PhiR; // Aka Worklist[0].
+for (VPSingleDefRecipe *CurrentLink : Worklist.getArrayRef().drop_front()) 
{
   Instruction *CurrentLinkI = CurrentLink->getUnderlyingInstr();
 
   // Index of the first operand which holds a non-mask vector operand.
@@ -8974,7 +8972,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
 "Expected instruction to be a call to the llvm.fmuladd intrinsic");
 assert(((MinVF.isScalar() && isa(CurrentLink)) ||
 isa(CurrentLink)) &&
-   CurrentLink->getOperand(2) == PreviousLinkV &&
+   CurrentLink->getOperand(2) == PreviousLink &&
"expected a call where the previous link is the added operand");
 
 // If the instruction is a call to the llvm.fmuladd intrinsic then we
@@ -9005,15 +9003,15 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
 // Note that for non-commutable operands (cmp-selects), the semantics 
of
 // the cmp-select are captured in the recurrence kind.
 unsigned VecOpId =
-CurrentLink->getOperand(IndexOfFirstOperand) == PreviousLinkV
+CurrentLink->getOperand(IndexOfFirstOperand) == PreviousLink
 ? IndexOfFirstOperand + 1
 : IndexOfFirstOperand;
 VecOp = CurrentLink->getOperand(VecOpId);
-assert(VecOp != PreviousLinkV &&
+assert(VecOp != PreviousLink &&
CurrentLink->getOperand(CurrentLink->getNumOperands() - 1 -
(VecOpId - IndexOfFirstOperand)) ==
-   PreviousLinkV &&
-   "PreviousLinkV must be the operand other than VecOp");
+   PreviousLink &&
+   "PreviousLink must be the operand other than VecOp");
   }
 
   BasicBlock *BB = CurrentLinkI->getParent();
@@ -9025,13 +9023,13 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
   }
 
   VPReductionRecipe *RedRecipe = new VPReductionRecipe(
-  RdxDesc, CurrentLinkI, PreviousLinkV, VecOp, CondOp);
+  RdxDesc, CurrentLinkI, PreviousLink, VecOp, CondOp);
   // Append the recipe to the end of the VPBasicBlock because we need to
   // ensure that it comes after all of it's inputs, including CondOp.
   // Note that this transformation may leave over dead recipes (including
   // CurrentLink), which will be cleaned by a later VPlan transform.
   LinkVPBB->appendRecipe(RedRecipe);
-  CurrentLink->getVPSingleValue()->replaceAllUsesWith(RedRecipe);
+  CurrentLink->replaceAllUsesWith(RedRecipe);
   PreviousLink = RedRecipe;
 }
   }
diff --git

[llvm] [clang] [libcxx] [mlir] [compiler-rt] [sanitizer] Skip /include/c++/ from summary (PR #78534)

2024-01-19 Thread via cfe-commits

zmodem wrote:

This broke lit tests on Darwin, see 
https://green.lab.llvm.org/green/job/clang-stage1-RA/37026/execution/node/39/log/?consoleFull
 and https://bugs.chromium.org/p/chromium/issues/detail?id=1519812

I've reverted in 4619147911c2a955bb605618bc518b45da994a81 for now.

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


[llvm] [libc] [lldb] [compiler-rt] [libcxxabi] [flang] [lld] [libcxx] [clang] [clang-tools-extra] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-19 Thread Aiden Grossman via cfe-commits

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


[clang-tools-extra] [libcxx] [flang] [clang] [compiler-rt] [libc] [llvm] [libc++] Implement LWG3940: std::expected::value() also needs E to be copy constructible (PR #71819)

2024-01-19 Thread via cfe-commits

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


[clang] [llvm] [ASAN] For Asan instrumented global, emit two symbols, one with actual size and other with instrumented size. (PR #70166)

2024-01-19 Thread via cfe-commits

https://github.com/skc7 updated https://github.com/llvm/llvm-project/pull/70166

>From 45d7b14e494ce771460ba263c5573f0fb4715246 Mon Sep 17 00:00:00 2001
From: skc7 
Date: Wed, 25 Oct 2023 10:46:10 +0530
Subject: [PATCH] [ASAN] For Asan instrumented globals, emit two symbols, with
 actual size and instrumented size.

---
 clang/test/CodeGen/asan_globals_symbols.cpp   | 15 ++
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp| 28 ++-
 .../Instrumentation/AddressSanitizer.cpp  |  3 ++
 .../AddressSanitizer/debug-info-global-var.ll |  2 +-
 4 files changed, 46 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/asan_globals_symbols.cpp

diff --git a/clang/test/CodeGen/asan_globals_symbols.cpp 
b/clang/test/CodeGen/asan_globals_symbols.cpp
new file mode 100644
index 00..d53afb2433b171
--- /dev/null
+++ b/clang/test/CodeGen/asan_globals_symbols.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -S -x c++ -std=c++11 -triple x86_64-linux \
+// RUN:   -fsanitize=address -o %t.out %s
+// RUN: FileCheck %s --input-file=%t.out --check-prefix=CHECK-A
+
+// CHECK-A: myGlobal:
+// CHECK-A: .size   myGlobal, 4
+// CHECK-A: myGlobal__sanitized_padded_global:
+// CHECK-A  .size   myGlobal__sanitized_padded_global, 32
+
+int myGlobal;
+
+int main() {
+myGlobal = 0;
+return 0;
+}
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 7df1c82bf357f6..cf1bdde6fc3425 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -801,6 +801,19 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable 
*GV) {
   // sections and expected to be contiguous (e.g. ObjC metadata).
   const Align Alignment = getGVAlignment(GV, DL);
 
+  // Identify globals with "SanitizedPaddedGlobal" attribute and extract
+  // the actual global variable size.
+  uint64_t ActualSize = 0;
+  if (GV->hasAttribute(Attribute::SanitizedPaddedGlobal)) {
+StructType *ST = dyn_cast(GV->getValueType());
+if (ST && ST->getNumElements() == 2) {
+  auto *ET0 = ST->getElementType(0);
+  if (ET0 && isa(ST->getElementType(1))) {
+ActualSize = DL.getTypeAllocSize(ET0);
+  }
+}
+  }
+
   for (const HandlerInfo &HI : Handlers) {
 NamedRegionTimer T(HI.TimerName, HI.TimerDescription,
HI.TimerGroupName, HI.TimerGroupDescription,
@@ -911,6 +924,18 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable 
*GV) {
 
   MCSymbol *EmittedInitSym = GVSym;
 
+  if (GV->hasAttribute(Attribute::SanitizedPaddedGlobal)) {
+OutStreamer->switchSection(TheSection);
+emitLinkage(GV, EmittedInitSym);
+OutStreamer->emitLabel(EmittedInitSym);
+if (MAI->hasDotTypeDotSizeDirective())
+  OutStreamer->emitELFSize(EmittedInitSym,
+   MCConstantExpr::create(ActualSize, OutContext));
+EmittedInitSym = OutContext.getOrCreateSymbol(
+GVSym->getName() + Twine("__sanitized_padded_global"));
+emitVisibility(EmittedInitSym, GV->getVisibility(), !GV->isDeclaration());
+  }
+
   OutStreamer->switchSection(TheSection);
 
   emitLinkage(GV, EmittedInitSym);
@@ -918,7 +943,8 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable 
*GV) {
 
   OutStreamer->emitLabel(EmittedInitSym);
   MCSymbol *LocalAlias = getSymbolPreferLocal(*GV);
-  if (LocalAlias != EmittedInitSym)
+  if ((LocalAlias != EmittedInitSym) &&
+  !GV->hasAttribute(Attribute::SanitizedPaddedGlobal))
 OutStreamer->emitLabel(LocalAlias);
 
   emitGlobalConstant(GV->getParent()->getDataLayout(), GV->getInitializer());
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp 
b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index caab98c732eeeb..a0dbc5224b3ebc 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2496,6 +2496,9 @@ void 
ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, Module &M,
 // zero so we can copy the metadata over as is.
 NewGlobal->copyMetadata(G, 0);
 
+// Attach "SanitizedPaddedGlobal" attribute to the new global.
+NewGlobal->addAttribute(Attribute::SanitizedPaddedGlobal);
+
 Value *Indices2[2];
 Indices2[0] = IRB.getInt32(0);
 Indices2[1] = IRB.getInt32(0);
diff --git 
a/llvm/test/Instrumentation/AddressSanitizer/debug-info-global-var.ll 
b/llvm/test/Instrumentation/AddressSanitizer/debug-info-global-var.ll
index 0b516e0174d6d1..2815c1f04bff15 100644
--- a/llvm/test/Instrumentation/AddressSanitizer/debug-info-global-var.ll
+++ b/llvm/test/Instrumentation/AddressSanitizer/debug-info-global-var.ll
@@ -2,7 +2,7 @@
 source_filename = "version.c"
 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-apple-macosx10.12.0"
-; CHECK: @version = constant { [5 x i8], [27 x i8] } {{.*}}, !dbg ![[GV:.*]]
+; CHECK: @version = constant { [5 x i8], [27 x i8] } {{.*}}, !dbg ![

[clang] [Clang][Sema] fix outline member function template with default align crash (PR #78400)

2024-01-19 Thread Qizhi Hu via cfe-commits

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

>From 08382e9f909bace4dbaf1f0c5d62d4e17978e3aa Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH] fix

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index fc80515b45e35b..ab3ac2d7dc0806 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -201,8 +201,16 @@ Response HandleFunction(const FunctionDecl *Function,
 // If this function was instantiated from a specialized member that is
 // a function template, we're done.
 assert(Function->getPrimaryTemplate() && "No function template?");
-if (Function->getPrimaryTemplate()->isMemberSpecialization())
+if (Function->getPrimaryTemplate()->isMemberSpecialization()) {
+  if (Function->isOutOfLine()) {
+FunctionDecl *PatternFD =
+Function->getTemplateInstantiationPattern(/*ForDefinition*/ false);
+unsigned Depth = PatternFD->getTemplateDepth();
+if (Depth > 0)
+  Result.addOuterRetainedLevels(Depth - 1);
+  }
   return Response::Done();
+}
 
 // If this function is a generic lambda specialization, we are done.
 if (!ForConstraintInstantiation &&

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


[clang] [libcxx] [SemaCXX] Implement CWG2137 (list-initialization from objects of the same type) (PR #77768)

2024-01-19 Thread via cfe-commits

cor3ntin wrote:

@MitalAshok the bot found some trailing whitespace issues

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


[llvm] [clang-tools-extra] [clang] [VPlan] Introduce VPSingleDefRecipe. (PR #77023)

2024-01-19 Thread Florian Hahn via cfe-commits

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


[llvm] [clang] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-01-19 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis updated 
https://github.com/llvm/llvm-project/pull/78432

>From ff9557fe913fd7901cd5a18757a2a41bffbe5c0e Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Tue, 16 Jan 2024 10:53:09 +
Subject: [PATCH 1/4] LAA cannot vectorize lib calls like modf/modff

Functions like modf/modff are math lib calls that set memory write-only
attribute. Given that a target has vectorized mappings, LAA should allow
vectorization.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 57 +++
 1 file changed, 57 insertions(+)
 create mode 100644 
clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
new file mode 100644
index 00..a449fac147058a
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --filter "call.*(frexp|modf)" --version 4
+// RUN: %clang --target=aarch64-linux-gnu -march=armv8-a+sve -O3 -mllvm 
-vector-library=ArmPL -mllvm -force-vector-interleave=1 -mllvm 
-prefer-predicate-over-epilogue=predicate-dont-vectorize -emit-llvm -S -o - %s 
| FileCheck %s
+
+// REQUIRES: aarch64-registered-target
+
+/*
+Testing vectorization of math functions that have the attribute write-only to
+memory set. Given they have vectorized counterparts, they should be able to
+vectorize.
+*/
+
+// The following define is required to access some math functions.
+#define _GNU_SOURCE
+#include 
+
+// frexp/frexpf have no TLI mappings yet.
+
+// CHECK-LABEL: define dso_local void @frexp_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK:[[CALL:%.*]] = tail call double @frexp(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2:[0-9]+]]
+//
+void frexp_f64(double *in, double *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexp(in[i], out2+i);
+}
+
+// CHECK-LABEL: define dso_local void @frexp_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @frexpf(float noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2]]
+//
+void frexp_f32(float *in, float *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexpf(in[i], out2+i);
+}
+
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call double @modf(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR3:[0-9]+]]
+//
+void modf_f64(double *in, double *out1, double *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modf(in[i], out2+i);
+}
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @modff(float noundef [[TMP0:%.*]], 
ptr noundef [[ADD_PTR:%.*]]) #[[ATTR4:[0-9]+]]
+//
+void modf_f32(float *in, float *out1, float *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modff(in[i], out2+i);
+}

>From 2a3b1e60c3f68c2f823a42bcd6e67111a0b8a529 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Wed, 17 Jan 2024 09:44:45 +
Subject: [PATCH 2/4] [LV][LAA] Vectorize math lib calls with mem write-only
 attribute

Teach LAA to consider safe specific math lib calls which are known to
have set the memory write-only attribute. Those attributes are set to
calls by inferNonMandatoryLibFuncAttrs, in BuildLibCalls.cpp, and the
current ones are modf/modff and frexp/frexpf.

This happens only when the calls are found through TLI to have
vectorized counterparts.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 15 ++-
 llvm/lib/Analysis/LoopAccessAnalysis.cpp  | 19 +++
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
index a449fac147058a..957b3f5cb235d3 100644
--- a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -17,7 +17,7 @@ vectorize.
 
 // CHE

[clang] [llvm] [Clang][SME] Detect always_inline used with mismatched streaming attributes (PR #77936)

2024-01-19 Thread Sam Tebbs via cfe-commits

SamTebbs33 wrote:

> clang has never emitted diagnostics for failure to inline an always_inline 
> function. But if gcc is doing it, maybe defaulting to an error isn't such a 
> big deal.

clang does actually emit an error when it finds always_inline on a callee with 
different target attributes to the caller: https://godbolt.org/z/37Yz4oPjo

> Separately, it's probably worth ensuring that the LLVM inlining passes don't 
> actually perform illegal inlining for functions marked always_inline; looking 
> at the code, it looks like we might end up skipping the relevant checks.

The `TargetTransformInfo::areInlineCompatible` function in llvm makes these 
checks.



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


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-01-19 Thread Paschalis Mpeis via cfe-commits


@@ -2274,6 +2274,26 @@ bool LoopAccessInfo::canAnalyzeLoop() {
   return true;
 }
 
+/// Returns whether \p I is a known math library call that has attribute
+/// 'memory(argmem: write)' set.
+static bool isMathLibCallMemWriteOnly(const TargetLibraryInfo *TLI,
+  const Instruction &I) {
+  auto *Call = dyn_cast(&I);
+  if (!Call)
+return false;
+
+  Function *F = Call->getCalledFunction();
+  if (!F->hasFnAttribute(Attribute::AttrKind::Memory))
+return false;
+
+  auto ME = F->getFnAttribute(Attribute::AttrKind::Memory).getMemoryEffects();

paschalis-mpeis wrote:

Good suggestion thanks, latest commit applies this.

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


[clang] [llvm] [compiler-rt] [lld] [libcxx] [flang] [clang-tools-extra] [libc] [lldb] [clang] Fix assertion failure with deleted overloaded unary operators (PR #78316)

2024-01-19 Thread Mariya Podchishchaeva via cfe-commits

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

>From cf33d7ce01aafe0fa29b8a38a9824a0b03d24f05 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 16 Jan 2024 09:16:10 -0800
Subject: [PATCH 1/4] [clang] Fix assertion failure with deleted overloaded
 unary operators

When emitting notes related to wrong number of arguments do not consider
implicit object argument.

Fixes https://github.com/llvm/llvm-project/issues/78314
---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaOverload.cpp|  4 ++--
 clang/test/SemaCXX/overloaded-operator.cpp | 27 ++
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6e31849ce16dd4..8382e5d55f6c6e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -750,6 +750,8 @@ Bug Fixes in This Version
   Fixes (`#77583 `_)
 - Fix an issue where CTAD fails for function-type/array-type arguments.
   Fixes (`#51710 `_)
+- Fixed assertion failure with deleted overloaded unary operators.
+  Fixes (`#78314 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 37c62b306b3cd3..83ab7cb0f3411b 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -14310,8 +14310,8 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, 
UnaryOperatorKind Opc,
 PartialDiagnosticAt(OpLoc, PDiag(diag::err_ovl_deleted_oper)
<< UnaryOperator::getOpcodeStr(Opc)
<< Input->getSourceRange()),
-*this, OCD_AllCandidates, ArgsArray, UnaryOperator::getOpcodeStr(Opc),
-OpLoc);
+*this, OCD_AllCandidates, ArgsArray.slice(1),
+UnaryOperator::getOpcodeStr(Opc), OpLoc);
 return ExprError();
   }
 
diff --git a/clang/test/SemaCXX/overloaded-operator.cpp 
b/clang/test/SemaCXX/overloaded-operator.cpp
index 83a7e65b43dd01..60332019f516cf 100644
--- a/clang/test/SemaCXX/overloaded-operator.cpp
+++ b/clang/test/SemaCXX/overloaded-operator.cpp
@@ -598,3 +598,30 @@ namespace B {
 }
 void g(B::X x) { A::f(x); }
 }
+
+namespace GH78314 {
+
+class a {
+public:
+  void operator--() = delete; // expected-note {{candidate function has been 
explicitly deleted}} \
+  // expected-note {{candidate function not 
viable: requires 0 arguments, but 1 was provided}}
+  void operator--(int) = delete; // expected-note {{candidate function has 
been explicitly deleted}} \
+ // expected-note {{candidate function not 
viable: requires 1 argument, but 0 were provided}}
+};
+
+void foo() {
+  a aa;
+  --aa; // expected-error {{overload resolution selected deleted operator 
'--'}}
+  aa--; // expected-error {{overload resolution selected deleted operator 
'--'}}
+}
+
+class b {
+  void operator++() = delete; // expected-note {{candidate function has been 
explicitly deleted}}
+  template  void operator++(int) { // expected-note {{function template 
not viable: requires 1 argument, but 0 were provided}}
+b bb;
+++bb; // expected-error {{overload resolution selected deleted operator 
'++'}}
+  }
+};
+
+
+}

>From 03daf97e74c05c1fa0c0c4b1637cbc76d3184404 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 17 Jan 2024 02:30:04 -0800
Subject: [PATCH 2/4] Add a test with explicit object parameter

---
 clang/test/SemaCXX/overloaded-operator.cpp | 30 ++
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/clang/test/SemaCXX/overloaded-operator.cpp 
b/clang/test/SemaCXX/overloaded-operator.cpp
index 60332019f516cf..887848c29b83c5 100644
--- a/clang/test/SemaCXX/overloaded-operator.cpp
+++ b/clang/test/SemaCXX/overloaded-operator.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx23 -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx23 -std=c++23 %s
+
 class X { };
 
 X operator+(X, X);
@@ -33,7 +35,9 @@ struct A {
 
 A make_A();
 
-bool operator==(A&, Z&); // expected-note 3{{candidate function}}
+bool operator==(A&, Z&); // expected-note 3{{candidate function}} \
+ // cxx23-note 2{{candidate function}}
+
 
 void h(A a, const A ac, Z z) {
   make_A() == z; // expected-warning{{equality comparison result unused}}
@@ -68,7 +72,9 @@ struct E2 {
 };
 
 // C++ [over.match.oper]p3 - enum restriction.
-float& operator==(E1, E2);  // expected-note{{candidate function}}
+float& operator==(E1, E2);  // expected-note{{candidate function}} \
+// cxx23-note{{candidate function}}
+
 
 void enum_test(Enum1 enum1, 

[clang] [clang][Interp] Handle std::move etc. builtins (PR #70772)

2024-01-19 Thread Timm Baeder via cfe-commits

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

>From c6c7d246b334a95306cda410e7d115353acb7c5e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 31 Oct 2023 07:17:16 +0100
Subject: [PATCH] [clang][Interp] Handle std::move etc. builtins

---
 clang/lib/AST/Interp/ByteCodeExprGen.h  |  9 +--
 clang/lib/AST/Interp/Context.h  | 13 +++-
 clang/lib/AST/Interp/Interp.cpp |  2 +-
 clang/lib/AST/Interp/InterpBuiltin.cpp  | 22 +-
 clang/test/AST/Interp/functions.cpp | 89 +
 clang/test/SemaCXX/builtin-std-move.cpp |  6 +-
 6 files changed, 129 insertions(+), 12 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index df4cb736299cb62..907e6f1f764502c 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -128,15 +128,8 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   // If the function does not exist yet, it is compiled.
   const Function *getFunction(const FunctionDecl *FD);
 
-  /// Classifies a type.
   std::optional classify(const Expr *E) const {
-if (E->isGLValue()) {
-  if (E->getType()->isFunctionType())
-return PT_FnPtr;
-  return PT_Ptr;
-}
-
-return classify(E->getType());
+return Ctx.classify(E);
   }
   std::optional classify(QualType Ty) const {
 return Ctx.classify(Ty);
diff --git a/clang/lib/AST/Interp/Context.h b/clang/lib/AST/Interp/Context.h
index ab83a8d13224670..c7620921e467e71 100644
--- a/clang/lib/AST/Interp/Context.h
+++ b/clang/lib/AST/Interp/Context.h
@@ -70,9 +70,20 @@ class Context final {
   /// Return the size of T in bits.
   uint32_t getBitWidth(QualType T) const { return Ctx.getIntWidth(T); }
 
-  /// Classifies an expression.
+  /// Classifies a type.
   std::optional classify(QualType T) const;
 
+  /// Classifies an expression.
+  std::optional classify(const Expr *E) const {
+if (E->isGLValue()) {
+  if (E->getType()->isFunctionType())
+return PT_FnPtr;
+  return PT_Ptr;
+}
+
+return classify(E->getType());
+  }
+
   const CXXMethodDecl *
   getOverridingFunction(const CXXRecordDecl *DynamicDecl,
 const CXXRecordDecl *StaticDecl,
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 807b860f3565d3a..38861253b217323 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -141,7 +141,7 @@ static bool CheckGlobal(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr) {
 namespace clang {
 namespace interp {
 static void popArg(InterpState &S, const Expr *Arg) {
-  PrimType Ty = S.getContext().classify(Arg->getType()).value_or(PT_Ptr);
+  PrimType Ty = S.getContext().classify(Arg).value_or(PT_Ptr);
   TYPE_SWITCH(Ty, S.Stk.discard());
 }
 
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 754ca96b0c645e5..280aa39398c8e9a 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -634,12 +634,23 @@ static bool interp__builtin_addressof(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_move(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame, const Function 
*Func,
+ const CallExpr *Call) {
+
+  PrimType ArgT = S.getContext().classify(Call->getArg(0)).value_or(PT_Ptr);
+
+  TYPE_SWITCH(ArgT, const T &Arg = S.Stk.peek(); S.Stk.push(Arg););
+
+  return Func->getDecl()->isConstexpr();
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
   const CallExpr *Call) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
 
-  std::optional ReturnT = S.getContext().classify(Call->getType());
+  std::optional ReturnT = S.getContext().classify(Call);
 
   // If classify failed, we assume void.
   assert(ReturnT || Call->getType()->isVoidType());
@@ -848,6 +859,15 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
   return false;
 break;
 
+  case Builtin::BIas_const:
+  case Builtin::BIforward:
+  case Builtin::BIforward_like:
+  case Builtin::BImove:
+  case Builtin::BImove_if_noexcept:
+if (!interp__builtin_move(S, OpPC, Frame, F, Call))
+  return false;
+break;
+
   default:
 return false;
   }
diff --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index 75f3c5d192b2cf2..6e995ce704e3949 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -413,3 +413,92 @@ namespace AddressOf {
   constexpr _Complex float F = {3, 4};
   static_assert(__builtin_addressof(F) == &F, "");
 }
+
+namespace std {
+template  struct remove_reference { using type = T; };
+template  struct remove_reference { using type = T; };
+template  struct remove_reference { using type = T; };
+template 
+constexpr type

[clang] [clang][Interp] Handle std::move etc. builtins (PR #70772)

2024-01-19 Thread Timm Baeder via cfe-commits


@@ -378,3 +378,92 @@ namespace Packs {
   static_assert(foo() == 2, "");
   static_assert(foo<>() == 0, "");
 }
+
+namespace std {
+template  struct remove_reference { using type = T; };
+template  struct remove_reference { using type = T; };
+template  struct remove_reference { using type = T; };
+template 
+constexpr typename std::remove_reference::type&& move(T &&t) noexcept {
+  return static_cast::type &&>(t);
+}
+}
+/// The std::move declaration above gets translated to a builtin function.
+namespace Move {

tbaederr wrote:

I've enabled `test/SemaCXX/builtin-std-move.cpp` with the new interpreter.

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


[clang] [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (PR #68846)

2024-01-19 Thread A. Jiang via cfe-commits

frederick-vs-ja wrote:

@Endilll Oh, I'm sorry for late replying. I wasn't wating for anybody and think 
this can be merged.

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


[llvm] [clang] [Clang][SME] Detect always_inline used with mismatched streaming attributes (PR #77936)

2024-01-19 Thread Sam Tebbs via cfe-commits

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


[clang] [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (PR #68846)

2024-01-19 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

@frederick-vs-ja PR description is going to be used as a commit message. You 
can edit it. Let me know when it's ready. 

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


[clang] [clang][analyzer] Add missing stream related functions to StdLibraryFunctionsChecker. (PR #76979)

2024-01-19 Thread Balázs Kéri via cfe-commits

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

From c45d8c9ef074c8dbce862d88222e16c2e60be619 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Thu, 4 Jan 2024 18:16:12 +0100
Subject: [PATCH 1/4] [clang][analyzer] Add missing stream related functions to
 StdCLibraryFunctionsChecker.

Some stream functions were recently added to StreamChecker that were not 
modeled by
StdCLibraryFunctionsChecker. To ensure consistency these functions are added
to the other checker too.
Some of the related tests are re-organized.
---
 .../Checkers/StdLibraryFunctionsChecker.cpp   |  94 +++
 clang/test/Analysis/std-c-library-functions.c |   4 +-
 clang/test/Analysis/stream-error.c|  26 -
 clang/test/Analysis/stream-noopen.c   | 110 ++
 clang/test/Analysis/stream-note.c |   1 +
 clang/test/Analysis/stream.c  |  25 +++-
 6 files changed, 190 insertions(+), 70 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 83f972c7072ec5..11c772d12be61c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2023,13 +2023,6 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
{{EOFv, EOFv}, {0, UCharRangeMax}},
"an unsigned char value or EOF")));
 
-  // The getc() family of functions that returns either a char or an EOF.
-  addToFunctionSummaryMap(
-  {"getc", "fgetc"}, Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
-  Summary(NoEvalCall)
-  .Case({ReturnValueCondition(WithinRange,
-  {{EOFv, EOFv}, {0, UCharRangeMax}})},
-ErrnoIrrelevant));
   addToFunctionSummaryMap(
   "getchar", Signature(ArgTypes{}, RetType{IntTy}),
   Summary(NoEvalCall)
@@ -2139,7 +2132,17 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 std::move(GetenvSummary));
   }
 
-  if (ModelPOSIX) {
+  if (!ModelPOSIX) {
+// Without POSIX use of 'errno' is not specified (in these cases).
+// Add these functions without 'errno' checks.
+addToFunctionSummaryMap(
+{"getc", "fgetc"}, Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(WithinRange,
+{{EOFv, EOFv}, {0, UCharRangeMax}})},
+  ErrnoIrrelevant)
+.ArgConstraint(NotNull(ArgNo(0;
+  } else {
 const auto ReturnsZeroOrMinusOne =
 ConstraintSet{ReturnValueCondition(WithinRange, Range(-1, 0))};
 const auto ReturnsZero =
@@ -2192,6 +2195,16 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(1)))
 .ArgConstraint(NotNull(ArgNo(2;
 
+// FILE *fdopen(int fd, const char *mode);
+addToFunctionSummaryMap(
+"fdopen",
+Signature(ArgTypes{IntTy, ConstCharPtrTy}, RetType{FilePtrTy}),
+Summary(NoEvalCall)
+.Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(ArgumentCondition(0, WithinRange, Range(0, IntMax)))
+.ArgConstraint(NotNull(ArgNo(1;
+
 // int fclose(FILE *stream);
 addToFunctionSummaryMap(
 "fclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
@@ -2201,6 +2214,59 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0;
 
+std::optional Off_tTy = lookupTy("off_t");
+std::optional Off_tMax = getMaxValue(Off_tTy);
+
+// int fgetc(FILE *stream);
+// 'getc' is the same as 'fgetc' but may be a macro
+addToFunctionSummaryMap(
+{"getc", "fgetc"}, Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(WithinRange, {{0, UCharRangeMax}})},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
+  ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
+
+// int fputc(int c, FILE *stream);
+// 'putc' is the same as 'fputc' but may be a macro
+addToFunctionSummaryMap(
+{"putc", "fputc"},
+Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(BO_EQ, ArgNo(0))},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
+  ErrnoNEZeroIrrelevant, GenericFailureMsg)

[clang] [clang][ExtractAPI] Record availability information only for the target platform (PR #76823)

2024-01-19 Thread Daniel Grumberg via cfe-commits

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


[clang] [HLSL][SPIR-V] Add support -fspv-target-env opt (PR #78611)

2024-01-19 Thread Nathan Gauër via cfe-commits

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


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


[clang] [clang][analyzer] Support 'getdelim' and 'getline' in StreamChecker (PR #78693)

2024-01-19 Thread Ben Shi via cfe-commits

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

None

>From 9af31b61fce0df9a26e46f2c83e7cd8f3432b4a4 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Fri, 19 Jan 2024 18:51:40 +0800
Subject: [PATCH] [clang][analyzer] Support 'getdelim' and 'getline' in
 StreamChecker

---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 66 +++
 .../Analysis/Inputs/system-header-simulator.h |  3 +
 clang/test/Analysis/stream-error.c| 44 +
 clang/test/Analysis/taint-tester.c|  1 -
 4 files changed, 113 insertions(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 95c7503e49e0d3..1a5b9b892163cb 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -269,6 +269,12 @@ class StreamChecker : public Checker(Call.getOriginExpr());
+  if (!CE)
+return;
+
+  const StreamState *OldSS = State->get(StreamSym);
+  if (!OldSS)
+return;
+
+  assertStreamStateOpened(OldSS);
+
+  // Upon successful completion, the getline() and getdelim() functions shall
+  // return the number of bytes written into the buffer.
+  // If the end-of-file indicator for the stream is set, the function shall
+  // return -1.
+  // If an error occurs, the function shall return -1 and set 'errno'.
+
+  // Add transition for the successful state.
+  if (OldSS->ErrorState != ErrorFEof) {
+NonLoc RetVal = makeRetVal(C, CE).castAs();
+ProgramStateRef StateNotFailed =
+State->BindExpr(CE, C.getLocationContext(), RetVal);
+SValBuilder &SVB = C.getSValBuilder();
+ASTContext &ASTC = C.getASTContext();
+auto Cond =
+SVB.evalBinOp(State, BO_GE, RetVal, SVB.makeZeroVal(CE->getType()),
+  SVB.getConditionType())
+.getAs();
+if (!Cond)
+  return;
+StateNotFailed = StateNotFailed->assume(*Cond, true);
+if (!StateNotFailed)
+  return;
+C.addTransition(StateNotFailed);
+  }
+
+  // Add transition for the failed state.
+  // If a (non-EOF) error occurs, the resulting value of the file position
+  // indicator for the stream is indeterminate.
+  ProgramStateRef StateFailed = bindInt(-1, State, C, CE);
+  StreamErrorState NewES =
+  OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError;
+  StreamState NewSS = StreamState::getOpened(Desc, NewES, !NewES.isFEof());
+  StateFailed = StateFailed->set(StreamSym, NewSS);
+  if (OldSS->ErrorState != ErrorFEof)
+C.addTransition(StateFailed, constructSetEofNoteTag(C, StreamSym));
+  else
+C.addTransition(StateFailed);
+}
+
 void StreamChecker::preFseek(const FnDescription *Desc, const CallEvent &Call,
  CheckerContext &C) const {
   ProgramStateRef State = C.getState();
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index f8e3e546a7aed5..96072741a8abc1 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -14,6 +14,7 @@ typedef long long __int64_t;
 typedef __int64_t __darwin_off_t;
 typedef __darwin_off_t fpos_t;
 typedef int off_t;
+typedef long ssize_t;
 
 typedef struct _FILE FILE;
 #define SEEK_SET 0 /* Seek from beginning of file. */
@@ -55,6 +56,8 @@ char *fgets(char *restrict str, int count, FILE *restrict 
stream);
 int fputc(int ch, FILE *stream);
 int fputs(const char *restrict s, FILE *restrict stream);
 int ungetc(int c, FILE *stream);
+ssize_t getdelim(char **restrict lineptr, size_t *restrict n, int delimiter, 
FILE *restrict stream);
+ssize_t getline(char **restrict lineptr, size_t *restrict n, FILE *restrict 
stream);
 int fseek(FILE *__stream, long int __off, int __whence);
 int fseeko(FILE *__stream, off_t __off, int __whence);
 long int ftell(FILE *__stream);
diff --git a/clang/test/Analysis/stream-error.c 
b/clang/test/Analysis/stream-error.c
index 0f7fdddc0dd4cd..a3c0f9629dffc2 100644
--- a/clang/test/Analysis/stream-error.c
+++ b/clang/test/Analysis/stream-error.c
@@ -224,6 +224,50 @@ void error_ungetc() {
   ungetc('A', F); // expected-warning {{Stream might be already closed}}
 }
 
+void error_getdelim(char *P, size_t Sz) {
+  FILE *F = tmpfile();
+  if (!F)
+return;
+  ssize_t Ret = getdelim(&P, &Sz, '\t', F);
+  if (Ret >= 0) {
+clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{FALSE}}
+  } else {
+clang_analyzer_eval(Ret == -1);// expected-warning {{TRUE}}
+clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{TRUE}}
+if (feof(F)) {
+  clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  getdelim(&P, &Sz, '\n', F); // expected-warning {{Read function 
called when stream is in EOF state}}
+} else {
+  clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
+  getdelim(&P, 

[clang] [clang][analyzer] Support 'getdelim' and 'getline' in StreamChecker (PR #78693)

2024-01-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ben Shi (benshi001)


Changes



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


4 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp (+66) 
- (modified) clang/test/Analysis/Inputs/system-header-simulator.h (+3) 
- (modified) clang/test/Analysis/stream-error.c (+44) 
- (modified) clang/test/Analysis/taint-tester.c (-1) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 95c7503e49e0d3..1a5b9b892163cb 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -269,6 +269,12 @@ class StreamChecker : public Checker(Call.getOriginExpr());
+  if (!CE)
+return;
+
+  const StreamState *OldSS = State->get(StreamSym);
+  if (!OldSS)
+return;
+
+  assertStreamStateOpened(OldSS);
+
+  // Upon successful completion, the getline() and getdelim() functions shall
+  // return the number of bytes written into the buffer.
+  // If the end-of-file indicator for the stream is set, the function shall
+  // return -1.
+  // If an error occurs, the function shall return -1 and set 'errno'.
+
+  // Add transition for the successful state.
+  if (OldSS->ErrorState != ErrorFEof) {
+NonLoc RetVal = makeRetVal(C, CE).castAs();
+ProgramStateRef StateNotFailed =
+State->BindExpr(CE, C.getLocationContext(), RetVal);
+SValBuilder &SVB = C.getSValBuilder();
+ASTContext &ASTC = C.getASTContext();
+auto Cond =
+SVB.evalBinOp(State, BO_GE, RetVal, SVB.makeZeroVal(CE->getType()),
+  SVB.getConditionType())
+.getAs();
+if (!Cond)
+  return;
+StateNotFailed = StateNotFailed->assume(*Cond, true);
+if (!StateNotFailed)
+  return;
+C.addTransition(StateNotFailed);
+  }
+
+  // Add transition for the failed state.
+  // If a (non-EOF) error occurs, the resulting value of the file position
+  // indicator for the stream is indeterminate.
+  ProgramStateRef StateFailed = bindInt(-1, State, C, CE);
+  StreamErrorState NewES =
+  OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError;
+  StreamState NewSS = StreamState::getOpened(Desc, NewES, !NewES.isFEof());
+  StateFailed = StateFailed->set(StreamSym, NewSS);
+  if (OldSS->ErrorState != ErrorFEof)
+C.addTransition(StateFailed, constructSetEofNoteTag(C, StreamSym));
+  else
+C.addTransition(StateFailed);
+}
+
 void StreamChecker::preFseek(const FnDescription *Desc, const CallEvent &Call,
  CheckerContext &C) const {
   ProgramStateRef State = C.getState();
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index f8e3e546a7aed5..96072741a8abc1 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -14,6 +14,7 @@ typedef long long __int64_t;
 typedef __int64_t __darwin_off_t;
 typedef __darwin_off_t fpos_t;
 typedef int off_t;
+typedef long ssize_t;
 
 typedef struct _FILE FILE;
 #define SEEK_SET 0 /* Seek from beginning of file. */
@@ -55,6 +56,8 @@ char *fgets(char *restrict str, int count, FILE *restrict 
stream);
 int fputc(int ch, FILE *stream);
 int fputs(const char *restrict s, FILE *restrict stream);
 int ungetc(int c, FILE *stream);
+ssize_t getdelim(char **restrict lineptr, size_t *restrict n, int delimiter, 
FILE *restrict stream);
+ssize_t getline(char **restrict lineptr, size_t *restrict n, FILE *restrict 
stream);
 int fseek(FILE *__stream, long int __off, int __whence);
 int fseeko(FILE *__stream, off_t __off, int __whence);
 long int ftell(FILE *__stream);
diff --git a/clang/test/Analysis/stream-error.c 
b/clang/test/Analysis/stream-error.c
index 0f7fdddc0dd4cd..a3c0f9629dffc2 100644
--- a/clang/test/Analysis/stream-error.c
+++ b/clang/test/Analysis/stream-error.c
@@ -224,6 +224,50 @@ void error_ungetc() {
   ungetc('A', F); // expected-warning {{Stream might be already closed}}
 }
 
+void error_getdelim(char *P, size_t Sz) {
+  FILE *F = tmpfile();
+  if (!F)
+return;
+  ssize_t Ret = getdelim(&P, &Sz, '\t', F);
+  if (Ret >= 0) {
+clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{FALSE}}
+  } else {
+clang_analyzer_eval(Ret == -1);// expected-warning {{TRUE}}
+clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{TRUE}}
+if (feof(F)) {
+  clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  getdelim(&P, &Sz, '\n', F); // expected-warning {{Read function 
called when stream is in EOF state}}
+} else {
+  clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
+  getdelim(&P, &Sz, '\n', F); // expected-warning {{might be 
'indeterminate'}}
+}
+  }
+  fclose(F);
+  getdelim(&P, &Sz, '\n', F); // expected-warning {{Stre

[clang] [llvm] [AMDGPU] Add GFX12 WMMA and SWMMAC instructions (PR #77795)

2024-01-19 Thread Jay Foad via cfe-commits

jayfoad wrote:

Some of the tests in this patch need regenerating now that #77438 has been 
merged.

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


[clang] [clang][analyzer] Improve modeling of 'fdopen' in StdLibraryFunctionsChecker (PR #78680)

2024-01-19 Thread via cfe-commits

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


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


[clang] [llvm] [ASAN] For Asan instrumented global, emit two symbols, one with actual size and other with instrumented size. (PR #70166)

2024-01-19 Thread via cfe-commits

skc7 wrote:

#68865 and #70166 have been rebased and updated as per review comments. Please 
review.

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


[clang] [Clang] fix static operator()/[] call not evaluating object (PR #78356)

2024-01-19 Thread Mital Ashok via cfe-commits


@@ -598,3 +600,27 @@ namespace B {
 }
 void g(B::X x) { A::f(x); }
 }
+
+namespace static_operator {
+#if __cplusplus >= 201703L

MitalAshok wrote:

No way to modify things in a C++11/14 constexpr function (`++x` is not a 
constant expression), so no way to make a positive test that the expression was 
evaluated. Though I guess I should have done `(non_constexpr_fn(), X())()` and 
see if that failed.

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


[clang] [Clang] fix static operator()/[] call not evaluating object (PR #78356)

2024-01-19 Thread Mital Ashok via cfe-commits

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


[clang] [Clang] fix static operator()/[] call not evaluating object (PR #78356)

2024-01-19 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

This pull request changes `E(...)` to produce the same AST as 
`E.operator()(...)`, which is similar to `E.f(...)` for a static member 
function `f`.

But the linked #68485 changes this to CXXOperatorCallExpr, which is more 
appropriate since it is used for non-member call operators like anyways

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


[clang] [clang][analyzer] Support 'getdelim' and 'getline' in StreamChecker (PR #78693)

2024-01-19 Thread Ben Shi via cfe-commits

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/78693

>From f047ec2137d63f04668f0b07be362a25fb612622 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Fri, 19 Jan 2024 18:51:40 +0800
Subject: [PATCH] [clang][analyzer] Support 'getdelim' and 'getline' in
 StreamChecker

---
 clang/docs/ReleaseNotes.rst   |  8 ++-
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 66 +++
 .../Analysis/Inputs/system-header-simulator.h |  3 +
 clang/test/Analysis/stream-error.c| 44 +
 clang/test/Analysis/taint-tester.c|  1 -
 5 files changed, 118 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 392f694065a242..ef54e453ae814c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1347,9 +1347,11 @@ Improvements
   `0954dc3fb921 
`_)
 
 - Improved the ``alpha.unix.Stream`` checker by modeling more functions
-  ``fputs``, ``fputc``, ``fgets``, ``fgetc``, ``fdopen``, ``ungetc``, 
``fflush``
-  and no not recognize alternative ``fopen`` and ``tmpfile`` implementations.
-  (`#76776 `_,
+  ``fputs``, ``fputc``, ``fgets``, ``fgetc``, ``fdopen``, ``ungetc``, 
``fflush``,
+  ``getdelim``, ``getline`` and no not recognize alternative
+  ``fopen`` and ``tmpfile`` implementations.
+  (`#78693 `_,
+  `#76776 `_,
   `#74296 `_,
   `#73335 `_,
   `#72627 `_,
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 95c7503e49e0d3..1a5b9b892163cb 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -269,6 +269,12 @@ class StreamChecker : public Checker(Call.getOriginExpr());
+  if (!CE)
+return;
+
+  const StreamState *OldSS = State->get(StreamSym);
+  if (!OldSS)
+return;
+
+  assertStreamStateOpened(OldSS);
+
+  // Upon successful completion, the getline() and getdelim() functions shall
+  // return the number of bytes written into the buffer.
+  // If the end-of-file indicator for the stream is set, the function shall
+  // return -1.
+  // If an error occurs, the function shall return -1 and set 'errno'.
+
+  // Add transition for the successful state.
+  if (OldSS->ErrorState != ErrorFEof) {
+NonLoc RetVal = makeRetVal(C, CE).castAs();
+ProgramStateRef StateNotFailed =
+State->BindExpr(CE, C.getLocationContext(), RetVal);
+SValBuilder &SVB = C.getSValBuilder();
+ASTContext &ASTC = C.getASTContext();
+auto Cond =
+SVB.evalBinOp(State, BO_GE, RetVal, SVB.makeZeroVal(CE->getType()),
+  SVB.getConditionType())
+.getAs();
+if (!Cond)
+  return;
+StateNotFailed = StateNotFailed->assume(*Cond, true);
+if (!StateNotFailed)
+  return;
+C.addTransition(StateNotFailed);
+  }
+
+  // Add transition for the failed state.
+  // If a (non-EOF) error occurs, the resulting value of the file position
+  // indicator for the stream is indeterminate.
+  ProgramStateRef StateFailed = bindInt(-1, State, C, CE);
+  StreamErrorState NewES =
+  OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError;
+  StreamState NewSS = StreamState::getOpened(Desc, NewES, !NewES.isFEof());
+  StateFailed = StateFailed->set(StreamSym, NewSS);
+  if (OldSS->ErrorState != ErrorFEof)
+C.addTransition(StateFailed, constructSetEofNoteTag(C, StreamSym));
+  else
+C.addTransition(StateFailed);
+}
+
 void StreamChecker::preFseek(const FnDescription *Desc, const CallEvent &Call,
  CheckerContext &C) const {
   ProgramStateRef State = C.getState();
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index f8e3e546a7aed5..96072741a8abc1 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -14,6 +14,7 @@ typedef long long __int64_t;
 typedef __int64_t __darwin_off_t;
 typedef __darwin_off_t fpos_t;
 typedef int off_t;
+typedef long ssize_t;
 
 typedef struct _FILE FILE;
 #define SEEK_SET 0 /* Seek from beginning of file. */
@@ -55,6 +56,8 @@ char *fgets(char *restrict str, int count, FILE *restrict 
stream);
 int fputc(int ch, FILE *stream);
 int fputs(const char *restrict s, FILE *restrict stream);
 int ungetc(int c, FILE *stream);
+ssize_t getdelim(char **restrict lineptr, size_t *restrict n, int delimiter, 
FILE *restrict stream);
+ssize_t getline(char **restrict lineptr, size_t *restrict n, FILE *restrict 

[clang] [Sema] Provide `-fvisibility-global-new-delete=` option (PR #75364)

2024-01-19 Thread via cfe-commits

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


[libcxx] [clang] [SemaCXX] Implement CWG2137 (list-initialization from objects of the same type) (PR #77768)

2024-01-19 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/77768

>From 644ec10fc357f70ca8af94ae6544e9631021eb5e Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sat, 22 Jul 2023 20:07:00 +0100
Subject: [PATCH 1/2] [SemaCXX] Implement CWG2137 (list-initialization from
 objects of the same type)

Differential Revision: https://reviews.llvm.org/D156032
---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/lib/Sema/SemaInit.cpp   | 14 +++---
 clang/lib/Sema/SemaOverload.cpp   | 38 +++-
 clang/test/CXX/drs/dr14xx.cpp | 10 -
 clang/test/CXX/drs/dr21xx.cpp | 45 +++
 clang/www/cxx_dr_status.html  |  2 +-
 .../pairs.pair/ctor.pair_U_V_move.pass.cpp| 21 -
 7 files changed, 103 insertions(+), 29 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 392f694065a242..745ec4f5b3a6d9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -229,6 +229,8 @@ C++2c Feature Support
 
 Resolutions to C++ Defect Reports
 ^
+- Implemented `CWG2137 `_ which allows
+  list-initialization from objects of the same type.
 
 - Implemented `CWG2598 `_ and `CWG2096 
`_,
   making unions (that have either no members or at least one literal member) 
literal types.
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 18440a69e3a3d9..6b2a77690049d2 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4200,7 +4200,7 @@ static OverloadingResult ResolveConstructorOverload(
 /// \param IsListInit Is this list-initialization?
 /// \param IsInitListCopy Is this non-list-initialization resulting from a
 ///   list-initialization from {x} where x is the same
-///   type as the entity?
+///   aggregate type as the entity?
 static void TryConstructorInitialization(Sema &S,
  const InitializedEntity &Entity,
  const InitializationKind &Kind,
@@ -4240,8 +4240,8 @@ static void TryConstructorInitialization(Sema &S,
   // ObjC++: Lambda captured by the block in the lambda to block conversion
   // should avoid copy elision.
   if (S.getLangOpts().CPlusPlus17 && !RequireActualConstructor &&
-  UnwrappedArgs.size() == 1 && UnwrappedArgs[0]->isPRValue() &&
-  S.Context.hasSameUnqualifiedType(UnwrappedArgs[0]->getType(), DestType)) 
{
+  Args.size() == 1 && Args[0]->isPRValue() &&
+  S.Context.hasSameUnqualifiedType(Args[0]->getType(), DestType)) {
 // Convert qualifications if necessary.
 Sequence.AddQualificationConversionStep(DestType, VK_PRValue);
 if (ILE)
@@ -4572,9 +4572,9 @@ static void TryListInitialization(Sema &S,
 return;
   }
 
-  // C++11 [dcl.init.list]p3, per DR1467:
-  // - If T is a class type and the initializer list has a single element of
-  //   type cv U, where U is T or a class derived from T, the object is
+  // C++11 [dcl.init.list]p3, per DR1467 and DR2137:
+  // - If T is an aggregate class and the initializer list has a single element
+  //   of type cv U, where U is T or a class derived from T, the object is
   //   initialized from that element (by copy-initialization for
   //   copy-list-initialization, or by direct-initialization for
   //   direct-list-initialization).
@@ -4585,7 +4585,7 @@ static void TryListInitialization(Sema &S,
   // - Otherwise, if T is an aggregate, [...] (continue below).
   if (S.getLangOpts().CPlusPlus11 && InitList->getNumInits() == 1 &&
   !IsDesignatedInit) {
-if (DestType->isRecordType()) {
+if (DestType->isRecordType() && DestType->isAggregateType()) {
   QualType InitType = InitList->getInit(0)->getType();
   if (S.Context.hasSameUnqualifiedType(InitType, DestType) ||
   S.IsDerivedFrom(InitList->getBeginLoc(), InitType, DestType)) {
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index bbbd0abc82d740..6ee5f26d55c3a5 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1568,19 +1568,37 @@ TryUserDefinedConversion(Sema &S, Expr *From, QualType 
ToType,
 //   called for those cases.
 if (CXXConstructorDecl *Constructor
   = dyn_cast(ICS.UserDefined.ConversionFunction)) {
-  QualType FromCanon
-= S.Context.getCanonicalType(From->getType().getUnqualifiedType());
+  QualType FromType;
+  SourceLocation FromLoc;
+  // C++11 [over.ics.list]p6, per DR2137:
+  // C++17 [over.ics.list]p6:
+  //   If C is not an initializer-list constructor and the initializer list
+  //   has a single element of type cv U, where U is X or a class derived
+  //   from X, the implicit conversion sequence has Exact Match rank if U 
i

[clang] [llvm] Adding support of AMDLIBM vector library (PR #78560)

2024-01-19 Thread Rohit Aggarwal via cfe-commits


@@ -3190,10 +3190,10 @@ def fno_experimental_isel : Flag<["-"], 
"fno-experimental-isel">, Group,
-
Values<"Accelerate,libmvec,MASSV,SVML,SLEEF,Darwin_libsystem_m,ArmPL,none">,
+
Values<"Accelerate,libmvec,MASSV,SVML,SLEEF,Darwin_libsystem_m,ArmPL,AMDLIBM,none">,

rohitaggarwal007 wrote:

I did not understood the comment. you meant to say formatting?

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


[clang] [Clang][NFC] Optimize isAsciiIdentifierContinue (PR #78699)

2024-01-19 Thread via cfe-commits

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

Precompute the isAsciiIdentifierContinue table which is on the hot path.

https://llvm-compile-time-tracker.com/compare.php?from=30da0f5a359ab4a684c5fdf0f4dbed20bae10f99&to=cb0e48db2b8193d2ee59c2a6e998317cb220d513&stat=instructions:u

>From 5b25a78e888086f5a9c25acab2dc446a85252ee4 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Fri, 19 Jan 2024 12:04:29 +0100
Subject: [PATCH] [Clang][NFC] Optimize isAsciiIdentifierContinue

Precompute the isAsciiIdentifierContinue table which
is on the hot path.

https://llvm-compile-time-tracker.com/compare.php?from=30da0f5a359ab4a684c5fdf0f4dbed20bae10f99&to=cb0e48db2b8193d2ee59c2a6e998317cb220d513&stat=instructions:u
---
 clang/include/clang/Basic/CharInfo.h | 23 ---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/CharInfo.h 
b/clang/include/clang/Basic/CharInfo.h
index 7d41193835089a6..18ebe1f3505b446 100644
--- a/clang/include/clang/Basic/CharInfo.h
+++ b/clang/include/clang/Basic/CharInfo.h
@@ -59,12 +59,29 @@ LLVM_READONLY inline bool isAsciiIdentifierStart(unsigned 
char c,
   return AllowDollar && c == '$';
 }
 
+
+LLVM_READONLY inline bool isAsciiIdentifierContinue(unsigned char c) {
+  // Precomputed CHAR_UPPER|CHAR_LOWER|CHAR_DIGIT|CHAR_UNDER
+  static constexpr unsigned char IDContinue[256] = {
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
+  0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+  1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+  return IDContinue[c];
+}
+
 /// Returns true if this is a body character of a C identifier,
 /// which is [a-zA-Z0-9_].
 LLVM_READONLY inline bool isAsciiIdentifierContinue(unsigned char c,
-bool AllowDollar = false) {
-  using namespace charinfo;
-  if (InfoTable[c] & (CHAR_UPPER|CHAR_LOWER|CHAR_DIGIT|CHAR_UNDER))
+bool AllowDollar) {
+  if (isAsciiIdentifierContinue(c))
 return true;
   return AllowDollar && c == '$';
 }

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


[clang] [Clang][NFC] Optimize isAsciiIdentifierContinue (PR #78699)

2024-01-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes

Precompute the isAsciiIdentifierContinue table which is on the hot path.

https://llvm-compile-time-tracker.com/compare.php?from=30da0f5a359ab4a684c5fdf0f4dbed20bae10f99&to=cb0e48db2b8193d2ee59c2a6e998317cb220d513&stat=instructions:u

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


1 Files Affected:

- (modified) clang/include/clang/Basic/CharInfo.h (+20-3) 


``diff
diff --git a/clang/include/clang/Basic/CharInfo.h 
b/clang/include/clang/Basic/CharInfo.h
index 7d41193835089a6..18ebe1f3505b446 100644
--- a/clang/include/clang/Basic/CharInfo.h
+++ b/clang/include/clang/Basic/CharInfo.h
@@ -59,12 +59,29 @@ LLVM_READONLY inline bool isAsciiIdentifierStart(unsigned 
char c,
   return AllowDollar && c == '$';
 }
 
+
+LLVM_READONLY inline bool isAsciiIdentifierContinue(unsigned char c) {
+  // Precomputed CHAR_UPPER|CHAR_LOWER|CHAR_DIGIT|CHAR_UNDER
+  static constexpr unsigned char IDContinue[256] = {
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
+  0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+  1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+  return IDContinue[c];
+}
+
 /// Returns true if this is a body character of a C identifier,
 /// which is [a-zA-Z0-9_].
 LLVM_READONLY inline bool isAsciiIdentifierContinue(unsigned char c,
-bool AllowDollar = false) {
-  using namespace charinfo;
-  if (InfoTable[c] & (CHAR_UPPER|CHAR_LOWER|CHAR_DIGIT|CHAR_UNDER))
+bool AllowDollar) {
+  if (isAsciiIdentifierContinue(c))
 return true;
   return AllowDollar && c == '$';
 }

``




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


[clang] [Clang][NFC] Optimize isAsciiIdentifierContinue (PR #78699)

2024-01-19 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 30da0f5a359ab4a684c5fdf0f4dbed20bae10f99 
5b25a78e888086f5a9c25acab2dc446a85252ee4 -- clang/include/clang/Basic/CharInfo.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Basic/CharInfo.h 
b/clang/include/clang/Basic/CharInfo.h
index 18ebe1f350..d807955311 100644
--- a/clang/include/clang/Basic/CharInfo.h
+++ b/clang/include/clang/Basic/CharInfo.h
@@ -59,7 +59,6 @@ LLVM_READONLY inline bool isAsciiIdentifierStart(unsigned 
char c,
   return AllowDollar && c == '$';
 }
 
-
 LLVM_READONLY inline bool isAsciiIdentifierContinue(unsigned char c) {
   // Precomputed CHAR_UPPER|CHAR_LOWER|CHAR_DIGIT|CHAR_UNDER
   static constexpr unsigned char IDContinue[256] = {

``




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


[clang] [clang][PP] Add extension to predefine target OS macros (PR #74676)

2024-01-19 Thread Florian Hahn via cfe-commits

fhahn wrote:

It looks like this may also break both Blender and Povray. Worked around build 
failures in SPEC2017 in llvm-test-suite in 
9b14a92d585657b87f2ca2b135ba9044685393be, but the projects will likely need to 
be fixed at the source.

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


[openmp] [mlir] [libcxxabi] [lld] [libc] [lldb] [compiler-rt] [clang-tools-extra] [llvm] [libunwind] [clang] [libcxx] [flang] [clang] static operators should evaluate object argument (PR #68485)

2024-01-19 Thread Tianlan Zhou via cfe-commits

SuperSodaSea wrote:

Ping.

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


[clang] [llvm] Adding support of AMDLIBM vector library (PR #78560)

2024-01-19 Thread Simon Pilgrim via cfe-commits


@@ -0,0 +1,332 @@
+; RUN: opt -vector-library=AMDLIBM -passes=inject-tli-mappings,loop-vectorize 
-S < %s | FileCheck %s
+
+; Test to verify that when math headers are built with
+; __FINITE_MATH_ONLY__ enabled, causing use of ___finite
+; function versions, vectorization can map these to vector versions.
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare float @__expf_finite(float) #0
+
+; CHECK-LABEL: @exp_f32
+; CHECK: <4 x float> @amd_vrs4_expf

RKSimon wrote:

Add RUNs for avx2 / avx512 capable targets to ensure amd_vrs8_expf / 
amd_vrs16_expf etc. are used when appropriate? 

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


[clang] [Clang][NFC] Optimize isAsciiIdentifierContinue (PR #78699)

2024-01-19 Thread Timm Baeder via cfe-commits


@@ -59,12 +59,29 @@ LLVM_READONLY inline bool isAsciiIdentifierStart(unsigned 
char c,
   return AllowDollar && c == '$';
 }
 
+
+LLVM_READONLY inline bool isAsciiIdentifierContinue(unsigned char c) {
+  // Precomputed CHAR_UPPER|CHAR_LOWER|CHAR_DIGIT|CHAR_UNDER
+  static constexpr unsigned char IDContinue[256] = {
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
+  0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+  1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+  return IDContinue[c];
+}
+
 /// Returns true if this is a body character of a C identifier,
 /// which is [a-zA-Z0-9_].
 LLVM_READONLY inline bool isAsciiIdentifierContinue(unsigned char c,
-bool AllowDollar = false) {
-  using namespace charinfo;
-  if (InfoTable[c] & (CHAR_UPPER|CHAR_LOWER|CHAR_DIGIT|CHAR_UNDER))
+bool AllowDollar) {

tbaederr wrote:

Why is the default value gone?

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


[clang] [Clang][NFC] Optimize isAsciiIdentifierContinue (PR #78699)

2024-01-19 Thread Timm Baeder via cfe-commits


@@ -59,12 +59,29 @@ LLVM_READONLY inline bool isAsciiIdentifierStart(unsigned 
char c,
   return AllowDollar && c == '$';
 }
 
+
+LLVM_READONLY inline bool isAsciiIdentifierContinue(unsigned char c) {
+  // Precomputed CHAR_UPPER|CHAR_LOWER|CHAR_DIGIT|CHAR_UNDER
+  static constexpr unsigned char IDContinue[256] = {
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
+  0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+  1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+  return IDContinue[c];
+}

tbaederr wrote:

```suggestion
  // Precomputed CHAR_UPPER|CHAR_LOWER|CHAR_DIGIT|CHAR_UNDER
  // clang-format off
  static constexpr unsigned char IDContinue[256] = {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
  0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  // clang-format on
  return IDContinue[c];
}
```

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


[clang] [Clang][NFC] Optimize isAsciiIdentifierContinue (PR #78699)

2024-01-19 Thread Timm Baeder via cfe-commits


@@ -59,12 +59,29 @@ LLVM_READONLY inline bool isAsciiIdentifierStart(unsigned 
char c,
   return AllowDollar && c == '$';
 }
 
+
+LLVM_READONLY inline bool isAsciiIdentifierContinue(unsigned char c) {
+  // Precomputed CHAR_UPPER|CHAR_LOWER|CHAR_DIGIT|CHAR_UNDER
+  static constexpr unsigned char IDContinue[256] = {
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
+  0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+  1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+  return IDContinue[c];
+}

tbaederr wrote:

Maybe?

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


[clang] [Clang][NFC] Optimize isAsciiIdentifierContinue (PR #78699)

2024-01-19 Thread Timm Baeder via cfe-commits


@@ -59,12 +59,29 @@ LLVM_READONLY inline bool isAsciiIdentifierStart(unsigned 
char c,
   return AllowDollar && c == '$';
 }
 
+
+LLVM_READONLY inline bool isAsciiIdentifierContinue(unsigned char c) {
+  // Precomputed CHAR_UPPER|CHAR_LOWER|CHAR_DIGIT|CHAR_UNDER
+  static constexpr unsigned char IDContinue[256] = {
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
+  0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+  1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+  return IDContinue[c];
+}

tbaederr wrote:

I screwed up the formatting in github myself but you get the gist.

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


[clang] [Clang] Fix build with GCC 14 on ARM (PR #78704)

2024-01-19 Thread Nikita Popov via cfe-commits

https://github.com/nikic created https://github.com/llvm/llvm-project/pull/78704

GCC 14 defines `__arm_streaming` as a macro expanding to `[[arm::streaming]]`. 
Due to the nested macro use, this gets expanded prior to concatenation.

It doesn't look like C++ has a really clean way to prevent macro expansion. The 
best I have found is to use `EMPTY ## X` where `EMPTY` is an empty macro 
argument, so this is the hack I'm implementing here.

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

>From 078c18de832328f743fb6e8dce728a030c81dc0d Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Fri, 19 Jan 2024 12:09:13 +0100
Subject: [PATCH] [Clang] Fix build with GCC 14 on ARM

GCC 14 defines `__arm_streaming` as a macro expanding to
`[[arm::streaming]]`. Due to the nested macro use, this gets
expanded prior to concatenation.

It doesn't look like C++ has a really clean way to prevent
macro expansion. The best I have found is to use `EMPTY ## X` where
`EMPTY` is an empty macro argument, so this is the hack I'm
implementing here.

Fixes https://github.com/llvm/llvm-project/issues/78691.
---
 clang/include/clang/Basic/AttributeCommonInfo.h | 2 +-
 clang/include/clang/Basic/TokenKinds.def| 3 ++-
 clang/utils/TableGen/ClangAttrEmitter.cpp   | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index d787e4959bfee3..ef2ddf525c9814 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -260,7 +260,7 @@ inline bool doesKeywordAttributeTakeArgs(tok::TokenKind 
Kind) {
   switch (Kind) {
   default:
 return false;
-#define KEYWORD_ATTRIBUTE(NAME, HASARG)
\
+#define KEYWORD_ATTRIBUTE(NAME, HASARG, ...)   
\
   case tok::kw_##NAME: 
\
 return HASARG;
 #include "clang/Basic/RegularKeywordAttrInfo.inc"
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index d15e4970b7d8f1..c10e2adfbe6e96 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -760,8 +760,9 @@ KEYWORD(__builtin_available  , KEYALL)
 KEYWORD(__builtin_sycl_unique_stable_name, KEYSYCL)
 
 // Keywords defined by Attr.td.
+// The "EMPTY ## X" is used to prevent early macro-expansion of the keyword.
 #ifndef KEYWORD_ATTRIBUTE
-#define KEYWORD_ATTRIBUTE(X, ...) KEYWORD(X, KEYALL)
+#define KEYWORD_ATTRIBUTE(X, HASARG, EMPTY) KEYWORD(EMPTY ## X, KEYALL)
 #endif
 #include "clang/Basic/RegularKeywordAttrInfo.inc"
 
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index a1827f8ce0ead8..3888e6c08ab0f4 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3589,7 +3589,7 @@ void EmitClangRegularKeywordAttributeInfo(RecordKeeper 
&Records,
 
   OS << "KEYWORD_ATTRIBUTE("
  << S.getSpellingRecord().getValueAsString("Name") << ", "
- << (HasArgs ? "true" : "false") << ")\n";
+ << (HasArgs ? "true" : "false") << ", )\n";
 }
   OS << "#undef KEYWORD_ATTRIBUTE\n";
 }

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


[clang] [Clang] Fix build with GCC 14 on ARM (PR #78704)

2024-01-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nikita Popov (nikic)


Changes

GCC 14 defines `__arm_streaming` as a macro expanding to `[[arm::streaming]]`. 
Due to the nested macro use, this gets expanded prior to concatenation.

It doesn't look like C++ has a really clean way to prevent macro expansion. The 
best I have found is to use `EMPTY ## X` where `EMPTY` is an empty macro 
argument, so this is the hack I'm implementing here.

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

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


3 Files Affected:

- (modified) clang/include/clang/Basic/AttributeCommonInfo.h (+1-1) 
- (modified) clang/include/clang/Basic/TokenKinds.def (+2-1) 
- (modified) clang/utils/TableGen/ClangAttrEmitter.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index d787e4959bfee3..ef2ddf525c9814 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -260,7 +260,7 @@ inline bool doesKeywordAttributeTakeArgs(tok::TokenKind 
Kind) {
   switch (Kind) {
   default:
 return false;
-#define KEYWORD_ATTRIBUTE(NAME, HASARG)
\
+#define KEYWORD_ATTRIBUTE(NAME, HASARG, ...)   
\
   case tok::kw_##NAME: 
\
 return HASARG;
 #include "clang/Basic/RegularKeywordAttrInfo.inc"
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index d15e4970b7d8f1..c10e2adfbe6e96 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -760,8 +760,9 @@ KEYWORD(__builtin_available  , KEYALL)
 KEYWORD(__builtin_sycl_unique_stable_name, KEYSYCL)
 
 // Keywords defined by Attr.td.
+// The "EMPTY ## X" is used to prevent early macro-expansion of the keyword.
 #ifndef KEYWORD_ATTRIBUTE
-#define KEYWORD_ATTRIBUTE(X, ...) KEYWORD(X, KEYALL)
+#define KEYWORD_ATTRIBUTE(X, HASARG, EMPTY) KEYWORD(EMPTY ## X, KEYALL)
 #endif
 #include "clang/Basic/RegularKeywordAttrInfo.inc"
 
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index a1827f8ce0ead8..3888e6c08ab0f4 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3589,7 +3589,7 @@ void EmitClangRegularKeywordAttributeInfo(RecordKeeper 
&Records,
 
   OS << "KEYWORD_ATTRIBUTE("
  << S.getSpellingRecord().getValueAsString("Name") << ", "
- << (HasArgs ? "true" : "false") << ")\n";
+ << (HasArgs ? "true" : "false") << ", )\n";
 }
   OS << "#undef KEYWORD_ATTRIBUTE\n";
 }

``




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


[llvm] [clang] [libcxx] [lld] [openmp] [lto] Add minimum macos sdk requirement to test (PR #77695)

2024-01-19 Thread Florian Hahn via cfe-commits


@@ -5,6 +5,8 @@
 ; RUN: %ld64 -lto_library %llvmshlibdir/libLTO.dylib -dylib -arch x86_64 
-macos_version_min 10.10.0 -o %t.dylib %t.o -save-temps  -undefined 
dynamic_lookup -exported_symbol _bar -lSystem -mllvm 
-lto-discard-value-names=false
 ; RUN: llvm-dis %t.dylib.lto.opt.bc -o - | FileCheck --check-prefix=KEEP %s
 
+; REQUIRES: macos-sdk-10.15

fhahn wrote:

I think the underlying issue should be fixed by 
74f6ae9f245f2ae9e832ba297f451e04e008ada8. Please let me know if that's not case

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


[clang] [Clang] Fix build with GCC 14 on ARM (PR #78704)

2024-01-19 Thread Sander de Smalen via cfe-commits


@@ -760,8 +760,9 @@ KEYWORD(__builtin_available  , KEYALL)
 KEYWORD(__builtin_sycl_unique_stable_name, KEYSYCL)
 
 // Keywords defined by Attr.td.
+// The "EMPTY ## X" is used to prevent early macro-expansion of the keyword.
 #ifndef KEYWORD_ATTRIBUTE
-#define KEYWORD_ATTRIBUTE(X, ...) KEYWORD(X, KEYALL)
+#define KEYWORD_ATTRIBUTE(X, HASARG, EMPTY) KEYWORD(EMPTY ## X, KEYALL)

sdesmalen-arm wrote:

Would the following suffice?
```
#define EMPTY
#define KEYWORD_ATTRIBUTE(X, HASARG) KEYWORD(EMPTY ## X, KEYALL)
```

Or is the crux of this fix that EMPTY must be an argument to the same macro in 
order for it not to get expanded?

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


[libcxx] [clang] [SemaCXX] Implement CWG2137 (list-initialization from objects of the same type) (PR #77768)

2024-01-19 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

@cor3ntin It looks like it was in an unrelated file. I've rebased and the 
format check is passing now

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


[libc] [clang-tools-extra] [compiler-rt] [flang] [llvm] [clang] [flang] use setsid to assign the child to prevent zombie as it will be clean up by init process (PR #77944)

2024-01-19 Thread Kiran Chandramohan via cfe-commits

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

LG.

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


[clang] [libc++] fix _Atomic c11 compare exchange does not update expected results (PR #78707)

2024-01-19 Thread via cfe-commits

https://github.com/huixie90 created 
https://github.com/llvm/llvm-project/pull/78707

None

>From 08092c466cc04a2e41634421a1bb7f18aa612815 Mon Sep 17 00:00:00 2001
From: Hui 
Date: Fri, 19 Jan 2024 12:33:43 +
Subject: [PATCH] [libc++] fix _Atomic c11 compare exchange does not update
 expected results

---
 clang/lib/CodeGen/CGAtomic.cpp | 59 +-
 1 file changed, 36 insertions(+), 23 deletions(-)

diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 52e6ddb7d6afb05..6edb98ff8db0bba 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -374,6 +374,7 @@ bool AtomicInfo::emitMemSetZeroIfNecessary() const {
 static void emitAtomicCmpXchg(CodeGenFunction &CGF, AtomicExpr *E, bool IsWeak,
   Address Dest, Address Ptr,
   Address Val1, Address Val2,
+  Address ExpectedResult,
   uint64_t Size,
   llvm::AtomicOrdering SuccessOrder,
   llvm::AtomicOrdering FailureOrder,
@@ -408,7 +409,15 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
 
   CGF.Builder.SetInsertPoint(StoreExpectedBB);
   // Update the memory at Expected with Old's value.
-  CGF.Builder.CreateStore(Old, Val1);
+
+  llvm::Type *ExpectedType = ExpectedResult.getElementType();
+  uint64_t OriginalSizeInBits = 
CGF.CGM.getDataLayout().getTypeSizeInBits(ExpectedType);
+  if (OriginalSizeInBits == Size) {
+CGF.Builder.CreateStore(Old, ExpectedResult);
+  } else {
+// How to just store N bytes to ExpectedResult ?
+CGF.Builder.CreateStore(Old, ExpectedResult);
+  }
   // Finally, branch to the exit point.
   CGF.Builder.CreateBr(ContinueBB);
 
@@ -423,6 +432,7 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
 static void emitAtomicCmpXchgFailureSet(CodeGenFunction &CGF, AtomicExpr *E,
 bool IsWeak, Address Dest, Address Ptr,
 Address Val1, Address Val2,
+Address ExpectedResult,
 llvm::Value *FailureOrderVal,
 uint64_t Size,
 llvm::AtomicOrdering SuccessOrder,
@@ -453,7 +463,7 @@ static void emitAtomicCmpXchgFailureSet(CodeGenFunction 
&CGF, AtomicExpr *E,
 // success argument". This condition has been lifted and the only
 // precondition is 31.7.2.18. Effectively treat this as a DR and skip
 // language version checks.
-emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, 
SuccessOrder,
+emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
   FailureOrder, Scope);
 return;
   }
@@ -478,17 +488,17 @@ static void emitAtomicCmpXchgFailureSet(CodeGenFunction 
&CGF, AtomicExpr *E,
 
   // Emit all the different atomics
   CGF.Builder.SetInsertPoint(MonotonicBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult,
 Size, SuccessOrder, llvm::AtomicOrdering::Monotonic, 
Scope);
   CGF.Builder.CreateBr(ContBB);
 
   CGF.Builder.SetInsertPoint(AcquireBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, SuccessOrder,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
 llvm::AtomicOrdering::Acquire, Scope);
   CGF.Builder.CreateBr(ContBB);
 
   CGF.Builder.SetInsertPoint(SeqCstBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, SuccessOrder,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
 llvm::AtomicOrdering::SequentiallyConsistent, Scope);
   CGF.Builder.CreateBr(ContBB);
 
@@ -521,6 +531,7 @@ static llvm::Value *EmitPostAtomicMinMax(CGBuilderTy 
&Builder,
 
 static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr *E, Address Dest,
  Address Ptr, Address Val1, Address Val2,
+ Address ExpectedResult,
  llvm::Value *IsWeak, llvm::Value *FailureOrder,
  uint64_t Size, llvm::AtomicOrdering Order,
  llvm::SyncScope::ID Scope) {
@@ -537,13 +548,13 @@ static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr 
*E, Address Dest,
   case AtomicExpr::AO__hip_atomic_compare_exchange_strong:
   case AtomicExpr::AO__opencl_atomic_compare_exchange_strong:
 emitAtomicCmpXchgFailureSet(CGF, E, false, Dest, Ptr, Val1, Val2,
-FailureOrder, Size, Order, Scope);
+ExpectedResult, FailureOrder, Size, Order, 
Scope);
 return;
   case AtomicExpr::AO__c11_atomic_c

[clang] [libc++] fix _Atomic c11 compare exchange does not update expected results (PR #78707)

2024-01-19 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 e4c8c5851738b7475efa1b9d500078133159369a 
08092c466cc04a2e41634421a1bb7f18aa612815 -- clang/lib/CodeGen/CGAtomic.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 6edb98ff8d..cc43ed297c 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -372,11 +372,9 @@ bool AtomicInfo::emitMemSetZeroIfNecessary() const {
 }
 
 static void emitAtomicCmpXchg(CodeGenFunction &CGF, AtomicExpr *E, bool IsWeak,
-  Address Dest, Address Ptr,
-  Address Val1, Address Val2,
-  Address ExpectedResult,
-  uint64_t Size,
-  llvm::AtomicOrdering SuccessOrder,
+  Address Dest, Address Ptr, Address Val1,
+  Address Val2, Address ExpectedResult,
+  uint64_t Size, llvm::AtomicOrdering SuccessOrder,
   llvm::AtomicOrdering FailureOrder,
   llvm::SyncScope::ID Scope) {
   // Note that cmpxchg doesn't support weak cmpxchg, at least at the moment.
@@ -411,7 +409,8 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
   // Update the memory at Expected with Old's value.
 
   llvm::Type *ExpectedType = ExpectedResult.getElementType();
-  uint64_t OriginalSizeInBits = 
CGF.CGM.getDataLayout().getTypeSizeInBits(ExpectedType);
+  uint64_t OriginalSizeInBits =
+  CGF.CGM.getDataLayout().getTypeSizeInBits(ExpectedType);
   if (OriginalSizeInBits == Size) {
 CGF.Builder.CreateStore(Old, ExpectedResult);
   } else {
@@ -429,14 +428,11 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
 /// Given an ordering required on success, emit all possible cmpxchg
 /// instructions to cope with the provided (but possibly only dynamically 
known)
 /// FailureOrder.
-static void emitAtomicCmpXchgFailureSet(CodeGenFunction &CGF, AtomicExpr *E,
-bool IsWeak, Address Dest, Address Ptr,
-Address Val1, Address Val2,
-Address ExpectedResult,
-llvm::Value *FailureOrderVal,
-uint64_t Size,
-llvm::AtomicOrdering SuccessOrder,
-llvm::SyncScope::ID Scope) {
+static void emitAtomicCmpXchgFailureSet(
+CodeGenFunction &CGF, AtomicExpr *E, bool IsWeak, Address Dest, Address 
Ptr,
+Address Val1, Address Val2, Address ExpectedResult,
+llvm::Value *FailureOrderVal, uint64_t Size,
+llvm::AtomicOrdering SuccessOrder, llvm::SyncScope::ID Scope) {
   llvm::AtomicOrdering FailureOrder;
   if (llvm::ConstantInt *FO = dyn_cast(FailureOrderVal)) {
 auto FOS = FO->getSExtValue();
@@ -463,8 +459,8 @@ static void emitAtomicCmpXchgFailureSet(CodeGenFunction 
&CGF, AtomicExpr *E,
 // success argument". This condition has been lifted and the only
 // precondition is 31.7.2.18. Effectively treat this as a DR and skip
 // language version checks.
-emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
-  FailureOrder, Scope);
+emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult,
+  Size, SuccessOrder, FailureOrder, Scope);
 return;
   }
 
@@ -488,18 +484,19 @@ static void emitAtomicCmpXchgFailureSet(CodeGenFunction 
&CGF, AtomicExpr *E,
 
   // Emit all the different atomics
   CGF.Builder.SetInsertPoint(MonotonicBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult,
-Size, SuccessOrder, llvm::AtomicOrdering::Monotonic, 
Scope);
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size,
+SuccessOrder, llvm::AtomicOrdering::Monotonic, Scope);
   CGF.Builder.CreateBr(ContBB);
 
   CGF.Builder.SetInsertPoint(AcquireBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
-llvm::AtomicOrdering::Acquire, Scope);
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size,
+SuccessOrder, llvm::AtomicOrdering::Acquire, Scope);
   CGF.Builder.CreateBr(ContBB);
 
   CGF.Builder.SetInsertPoint(SeqCstBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
-llvm::AtomicOrdering::SequentiallyConsistent, Scope);
+  emitAtomicCmpXchg(CGF, E, IsWe

[clang] [Clang] Fix build with GCC 14 on ARM (PR #78704)

2024-01-19 Thread Nikita Popov via cfe-commits


@@ -760,8 +760,9 @@ KEYWORD(__builtin_available  , KEYALL)
 KEYWORD(__builtin_sycl_unique_stable_name, KEYSYCL)
 
 // Keywords defined by Attr.td.
+// The "EMPTY ## X" is used to prevent early macro-expansion of the keyword.
 #ifndef KEYWORD_ATTRIBUTE
-#define KEYWORD_ATTRIBUTE(X, ...) KEYWORD(X, KEYALL)
+#define KEYWORD_ATTRIBUTE(X, HASARG, EMPTY) KEYWORD(EMPTY ## X, KEYALL)

nikic wrote:

Macros don't get expanded in `##` so this will produce something like 
`EMPTY__arm_streaming`. I believe the only way to actually get an empty 
concatenation is via an empty macro argument.

Here's a godbolt to experiment: https://cpp.godbolt.org/z/d9zc7hs3a

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


[clang] [libcxx] [SemaCXX] Implement CWG2137 (list-initialization from objects of the same type) (PR #77768)

2024-01-19 Thread via cfe-commits

cor3ntin wrote:

Do you want me to merge on your behalf?

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-19 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

I tried applying this patch to ROOT/Cling and it fails to build because 
something is of the opinion that `std::is_integral::value` is not true. I 
don't have time right now to investigate further, but since this is the only 
change I did it is highly likely that it's caused by this...

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


[llvm] [clang] [AMDGPU] Do not emit `V_DOT2C_F32_F16_e32` on GFX12 (PR #78709)

2024-01-19 Thread Jay Foad via cfe-commits

https://github.com/jayfoad created 
https://github.com/llvm/llvm-project/pull/78709

That instruction is not supported on GFX12.
Added a testcase which previously crashed without this change.


>From b212d63828ae87b8e40f9d6de7622bc7a14ce48f Mon Sep 17 00:00:00 2001
From: pvanhout 
Date: Mon, 30 Oct 2023 08:03:17 +0100
Subject: [PATCH] [AMDGPU] Do not emit `V_DOT2C_F32_F16_e32` on GFX12

That instruction is not supported on GFX12.
Added a testcase which previously crashed without this change.
---
 clang/test/CodeGenOpenCL/amdgpu-features.cl   | 4 ++--
 llvm/lib/Target/AMDGPU/AMDGPU.td  | 1 -
 llvm/lib/TargetParser/TargetParser.cpp| 1 -
 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.fdot2.ll | 4 
 4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/clang/test/CodeGenOpenCL/amdgpu-features.cl 
b/clang/test/CodeGenOpenCL/amdgpu-features.cl
index 7495bca72a9df5..1ba2b129f6895a 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-features.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-features.cl
@@ -100,8 +100,8 @@
 // GFX1103: 
"target-features"="+16-bit-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot10-insts,+dot5-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
 // GFX1150: 
"target-features"="+16-bit-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot10-insts,+dot5-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
 // GFX1151: 
"target-features"="+16-bit-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot10-insts,+dot5-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
-// GFX1200: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot10-insts,+dot5-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx12-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
-// GFX1201: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot10-insts,+dot5-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx12-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
+// GFX1200: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot10-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx12-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
+// GFX1201: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot10-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx12-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
 
 // GFX1103-W64: 
"target-features"="+16-bit-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot10-insts,+dot5-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize64"
 
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td
index 7b7fa906b2b1a3..92985f971f17a7 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.td
@@ -1487,7 +1487,6 @@ def FeatureISAVersion12 : FeatureSet<
   [FeatureGFX12,
FeatureLDSBankCount32,
FeatureDLInsts,
-   FeatureDot5Insts,
FeatureDot7Insts,
FeatureDot8Insts,
FeatureDot9Insts,
diff --git a/llvm/lib/TargetParser/TargetParser.cpp 
b/llvm/lib/TargetParser/TargetParser.cpp
index 2cfe23676d20f8..f6d5bfe913b419 100644
--- a/llvm/lib/TargetParser/TargetParser.cpp
+++ b/llvm/lib/TargetParser/TargetParser.cpp
@@ -275,7 +275,6 @@ void AMDGPU::fillAMDGPUFeatureMap(StringRef GPU, const 
Triple &T,
 case GK_GFX1201:
 case GK_GFX1200:
   Features["ci-insts"] = true;
-  Features["dot5-insts"] = true;
   Features["dot7-insts"] = true;
   Features["dot8-insts"] = true;
   Features["dot9-insts"] = true;
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.fdot2.ll 
b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.fdot2.ll
index 240997aeb9a687..26e6bde97f499d 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.fdot2.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.fdot2.ll
@@ -3,12 +3,14 @@
 ; RUN: llc -mtriple=amdgcn -mcpu=gfx1011 -verify-machineinstrs < %s | 
FileCheck %s --check-prefixes=GCN,GFX10
 ; RUN: llc -mtriple=amdgcn -mcpu=gfx1012 -verify-machineinstrs < %s | 
FileCheck %s --check-prefixes=GCN,GFX10
 ; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -

[llvm] [clang] [AMDGPU] Do not emit `V_DOT2C_F32_F16_e32` on GFX12 (PR #78709)

2024-01-19 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-amdgpu

@llvm/pr-subscribers-clang

Author: Jay Foad (jayfoad)


Changes

That instruction is not supported on GFX12.
Added a testcase which previously crashed without this change.


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


4 Files Affected:

- (modified) clang/test/CodeGenOpenCL/amdgpu-features.cl (+2-2) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPU.td (-1) 
- (modified) llvm/lib/TargetParser/TargetParser.cpp (-1) 
- (modified) llvm/test/CodeGen/AMDGPU/llvm.amdgcn.fdot2.ll (+4) 


``diff
diff --git a/clang/test/CodeGenOpenCL/amdgpu-features.cl 
b/clang/test/CodeGenOpenCL/amdgpu-features.cl
index 7495bca72a9df5..1ba2b129f6895a 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-features.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-features.cl
@@ -100,8 +100,8 @@
 // GFX1103: 
"target-features"="+16-bit-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot10-insts,+dot5-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
 // GFX1150: 
"target-features"="+16-bit-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot10-insts,+dot5-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
 // GFX1151: 
"target-features"="+16-bit-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot10-insts,+dot5-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
-// GFX1200: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot10-insts,+dot5-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx12-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
-// GFX1201: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot10-insts,+dot5-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx12-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
+// GFX1200: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot10-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx12-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
+// GFX1201: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot10-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx12-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
 
 // GFX1103-W64: 
"target-features"="+16-bit-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot10-insts,+dot5-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize64"
 
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td
index 7b7fa906b2b1a3..92985f971f17a7 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.td
@@ -1487,7 +1487,6 @@ def FeatureISAVersion12 : FeatureSet<
   [FeatureGFX12,
FeatureLDSBankCount32,
FeatureDLInsts,
-   FeatureDot5Insts,
FeatureDot7Insts,
FeatureDot8Insts,
FeatureDot9Insts,
diff --git a/llvm/lib/TargetParser/TargetParser.cpp 
b/llvm/lib/TargetParser/TargetParser.cpp
index 2cfe23676d20f8..f6d5bfe913b419 100644
--- a/llvm/lib/TargetParser/TargetParser.cpp
+++ b/llvm/lib/TargetParser/TargetParser.cpp
@@ -275,7 +275,6 @@ void AMDGPU::fillAMDGPUFeatureMap(StringRef GPU, const 
Triple &T,
 case GK_GFX1201:
 case GK_GFX1200:
   Features["ci-insts"] = true;
-  Features["dot5-insts"] = true;
   Features["dot7-insts"] = true;
   Features["dot8-insts"] = true;
   Features["dot9-insts"] = true;
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.fdot2.ll 
b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.fdot2.ll
index 240997aeb9a687..26e6bde97f499d 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.fdot2.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.fdot2.ll
@@ -3,12 +3,14 @@
 ; RUN: llc -mtriple=amdgcn -mcpu=gfx1011 -verify-machineinstrs < %s | 
FileCheck %s --check-prefixes=GCN,GFX10
 ; RUN: llc -mtriple=amdgcn -mcpu=gfx1012 -verify-machineinstrs < %s | 
FileCheck %s --check-prefixes=GCN,GFX10
 ; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -amdgpu-enable-vopd=0 
-verify-machineinstrs < %s | FileCheck %s --check-prefixes=GCN,GFX10
+; RUN: llc -mtriple=amdgcn -mcpu=gfx1200 -amdgpu-enable-vopd=0 
-verify-machineinstrs < %s | FileCheck

[mlir] [clang] [libcxx] [flang] [libc] [llvm] [clang-tools-extra] [lldb] [compiler-rt] Added settings for DEBUGINFOD cache location and timeout (PR #78605)

2024-01-19 Thread Kevin Frei via cfe-commits

https://github.com/kevinfrei updated 
https://github.com/llvm/llvm-project/pull/78605

>From 48c6e5edc1dc5f832f8f5c922c61af9070ad341d Mon Sep 17 00:00:00 2001
From: Kevin Frei 
Date: Thu, 18 Jan 2024 09:09:50 -0800
Subject: [PATCH 1/8] Added settings for cache location and timeout

---
 .../Debuginfod/SymbolLocatorDebuginfod.cpp| 82 +++
 .../SymbolLocatorDebuginfodProperties.td  |  8 +-
 llvm/include/llvm/Debuginfod/Debuginfod.h | 13 +++
 llvm/lib/Debuginfod/Debuginfod.cpp| 31 +--
 4 files changed, 108 insertions(+), 26 deletions(-)

diff --git 
a/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp 
b/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp
index 111be6be365240..a20437c256eb43 100644
--- a/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp
+++ b/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp
@@ -9,6 +9,7 @@
 #include "SymbolLocatorDebuginfod.h"
 
 #include "lldb/Core/PluginManager.h"
+#include "lldb/Interpreter/OptionValueString.h"
 #include "lldb/Utility/Args.h"
 
 #include "llvm/Debuginfod/Debuginfod.h"
@@ -54,6 +55,34 @@ class PluginProperties : public Properties {
 return urls;
   }
 
+  llvm::Expected GetCachePath() {
+OptionValueString *s =
+m_collection_sp->GetPropertyAtIndexAsOptionValueString(
+ePropertySymbolCachePath);
+// If we don't have a valid cache location, use the default one.
+if (!s || !s->GetCurrentValueAsRef().size()) {
+  llvm::Expected maybeCachePath =
+  llvm::getDefaultDebuginfodCacheDirectory();
+  if (!maybeCachePath) {
+return maybeCachePath;
+  }
+  m_cache_path = *maybeCachePath;
+  return llvm::StringRef(m_cache_path);
+}
+return s->GetCurrentValueAsRef();
+  }
+
+  std::chrono::milliseconds GetTimeout() const {
+std::optional seconds =
+m_collection_sp->GetPropertyAtIndexAs(ePropertyTimeout);
+if (seconds && *seconds != 0) {
+  return std::chrono::duration_cast(
+  std::chrono::seconds(*seconds));
+} else {
+  return llvm::getDefaultDebuginfodTimeout();
+}
+  }
+
 private:
   void ServerURLsChangedCallback() {
 m_server_urls = GetDebugInfoDURLs();
@@ -65,6 +94,7 @@ class PluginProperties : public Properties {
   }
   // Storage for the StringRef's used within the Debuginfod library.
   Args m_server_urls;
+  std::string m_cache_path;
 };
 
 } // namespace
@@ -112,31 +142,49 @@ SymbolLocator *SymbolLocatorDebuginfod::CreateInstance() {
   return new SymbolLocatorDebuginfod();
 }
 
-static std::optional GetFileForModule(
-const ModuleSpec &module_spec,
-std::function(llvm::object::BuildIDRef)>
-PullFromServer) {
-  if (!ModuleList::GetGlobalModuleListProperties().GetEnableExternalLookup())
-return {};
++ static std::optional +
+GetFileForModule(
+const ModuleSpec &module_spec,
+std::function UrlBuilder) {
   const UUID &module_uuid = module_spec.GetUUID();
-  if (module_uuid.IsValid() && llvm::canUseDebuginfod()) {
-llvm::object::BuildID build_id(module_uuid.GetBytes());
-llvm::Expected result = PullFromServer(build_id);
-if (result)
-  return FileSpec(*result);
-// An error here should be logged as a failure in the Debuginfod library,
-// so just consume it here
-consumeError(result.takeError());
-  }
+  // Don't bother if we don't have a valid UUID, Debuginfod isn't available,
+  // or if the 'symbols.enable-external-lookup' setting is false
+  if (!module_uuid.IsValid() || !llvm::canUseDebuginfod() ||
+  !ModuleList::GetGlobalModuleListProperties().GetEnableExternalLookup())
+return {};
+
+  // Grab the settings values we need
+  PluginProperties &plugin_props = GetGlobalPluginProperties();
+  llvm::Expected CacheDirectoryPathOrErr =
+  plugin_props.GetCachePath();
+  // A cache location is *required*
+  if (!CacheDirectoryPathOrErr)
+return {};
+  llvm::StringRef CacheDirectoryPath = *CacheDirectoryPathOrErr;
+  llvm::SmallVector DebuginfodUrls =
+  llvm::getDefaultDebuginfodUrls();
+  std::chrono::milliseconds Timeout = plugin_props.GetTimeout();
+
+  // We're ready to ask the Debuginfod library to find our file
+  llvm::object::BuildID build_id(module_uuid.GetBytes());
+  std::string UrlPath = UrlBuilder(build_id);
+  std::string CacheKey = llvm::getDebuginfodCacheKey(UrlPath);
+  llvm::Expected result = llvm::getCachedOrDownloadArtifact(
+  CacheKey, UrlPath, CacheDirectoryPath, DebuginfodUrls, Timeout);
+  if (result)
+return FileSpec(*result);
+  // An error here should be logged as a failure in the Debuginfod library,
+  // just consume it here
+  consumeError(result.takeError());
   return {};
 }
 
 std::optional SymbolLocatorDebuginfod::LocateExecutableObjectFile(
 const ModuleSpec &module_spec) {
-  return GetFileForModule(module_spec, llvm::getCachedOrDownloadExecutable);
+  return GetFileForModule

[clang] [Clang][NFC] Optimize isAsciiIdentifierContinue (PR #78699)

2024-01-19 Thread via cfe-commits


@@ -59,12 +59,29 @@ LLVM_READONLY inline bool isAsciiIdentifierStart(unsigned 
char c,
   return AllowDollar && c == '$';
 }
 
+
+LLVM_READONLY inline bool isAsciiIdentifierContinue(unsigned char c) {
+  // Precomputed CHAR_UPPER|CHAR_LOWER|CHAR_DIGIT|CHAR_UNDER
+  static constexpr unsigned char IDContinue[256] = {
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
+  0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+  1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+  return IDContinue[c];
+}
+
 /// Returns true if this is a body character of a C identifier,
 /// which is [a-zA-Z0-9_].
 LLVM_READONLY inline bool isAsciiIdentifierContinue(unsigned char c,
-bool AllowDollar = false) {
-  using namespace charinfo;
-  if (InfoTable[c] & (CHAR_UPPER|CHAR_LOWER|CHAR_DIGIT|CHAR_UNDER))
+bool AllowDollar) {

cor3ntin wrote:

Moved to a separate overload. Most of the calls don't check for $ so we can 
avoid doing the test at all in the comment case

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-19 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> I tried applying this patch to ROOT/Cling and it fails to build because 
> something is of the opinion that `std::is_integral::value` is not true. 
> I don't have time right now to investigate further, but since this is the 
> only change I did it is highly likely that it's caused by this...

In that case we need to understand how this patch differs from the one I pasted 
in phabricator since the one there works for that case I assume. 

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


[clang] [Clang][NFC] Optimize isAsciiIdentifierContinue (PR #78699)

2024-01-19 Thread via cfe-commits

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


[clang] [analyzer] Demonstrate superfluous unsigned >= 0 assumption (PR #78442)

2024-01-19 Thread Balazs Benics via cfe-commits

steakhal wrote:

I'd advise against introducing a separate file for this, but I'm okay with 
landing tests.
Given this issue, I'd be interested to look at how difficult it is to actually 
fix it and commit the case along with the fix.
Have you looked at potential solutions?

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


[clang] [Clang][NFC] Optimize isAsciiIdentifierContinue (PR #78699)

2024-01-19 Thread via cfe-commits

cor3ntin wrote:

I did try to apply the same treatment to the whitespace tables but it made 
thing strictly worse

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


[clang-tools-extra] [clang-apply-replacements] Deduplicate Implementation of `collectReplacementsFromDirectory` (NFC) (PR #78630)

2024-01-19 Thread Daniil Dudkin via cfe-commits

unterumarmung wrote:

The Windows build in the CI is stuck. The change is pretty trivial and doesn't 
use any features that cannot be found in C++98. So, we can skip the Windows 
check.

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


[clang-tools-extra] 24e5229 - [clang-apply-replacements] Deduplicate Implementation of `collectReplacementsFromDirectory` (NFC) (#78630)

2024-01-19 Thread via cfe-commits

Author: Daniil Dudkin
Date: 2024-01-19T15:57:02+03:00
New Revision: 24e5229230786b650a24d70bf7b10611ceb910fb

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

LOG: [clang-apply-replacements] Deduplicate Implementation of 
`collectReplacementsFromDirectory` (NFC) (#78630)

* Convert `collectReplacementsFromDirectory` into a function template.
* Employ explicit specialization to maintain implementation in the
source file.
* Utilize the function template in the source file to eliminate code
duplication.
* Update the documentation for the function.

Added: 


Modified: 

clang-tools-extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
 
b/clang-tools-extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
index 1f0d8737191402..7a8408bcdff8f7 100644
--- 
a/clang-tools-extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
+++ 
b/clang-tools-extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
@@ -51,19 +51,27 @@ using FileToChangesMap =
 /// Directories starting with '.' are ignored during traversal.
 ///
 /// \param[in] Directory Directory to begin search for serialized
-/// TranslationUnitReplacements.
+/// TranslationUnitReplacements or TranslationUnitDiagnostics.
 /// \param[out] TUs Collection of all found and deserialized
 /// TranslationUnitReplacements or TranslationUnitDiagnostics.
-/// \param[out] TUFiles Collection of all TranslationUnitReplacement files
-/// found in \c Directory.
+/// \param[out] TUFiles Collection of all TranslationUnitReplacement or
+/// TranslationUnitDiagnostics files found in \c Directory.
 /// \param[in] Diagnostics DiagnosticsEngine used for error output.
 ///
 /// \returns An error_code indicating success or failure in navigating the
 /// directory structure.
+template 
+std::error_code collectReplacementsFromDirectory(
+const llvm::StringRef Directory, TranslationUnits &TUs,
+TUReplacementFiles &TUFiles,
+clang::DiagnosticsEngine &Diagnostics) = delete;
+
+template <>
 std::error_code collectReplacementsFromDirectory(
 const llvm::StringRef Directory, TUReplacements &TUs,
 TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics);
 
+template <>
 std::error_code collectReplacementsFromDirectory(
 const llvm::StringRef Directory, TUDiagnostics &TUs,
 TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics);

diff  --git 
a/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp 
b/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
index b490780f48529e..87ed1b8797cb05 100644
--- 
a/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
+++ 
b/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
@@ -38,8 +38,10 @@ static void eatDiagnostics(const SMDiagnostic &, void *) {}
 namespace clang {
 namespace replace {
 
-std::error_code collectReplacementsFromDirectory(
-const llvm::StringRef Directory, TUReplacements &TUs,
+namespace detail {
+template 
+static std::error_code collectReplacementsFromDirectory(
+const llvm::StringRef Directory, TranslationUnits &TUs,
 TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics) {
   using namespace llvm::sys::fs;
   using namespace llvm::sys::path;
@@ -68,7 +70,7 @@ std::error_code collectReplacementsFromDirectory(
 }
 
 yaml::Input YIn(Out.get()->getBuffer(), nullptr, &eatDiagnostics);
-tooling::TranslationUnitReplacements TU;
+typename TranslationUnits::value_type TU;
 YIn >> TU;
 if (YIn.error()) {
   // File doesn't appear to be a header change description. Ignore it.
@@ -81,49 +83,22 @@ std::error_code collectReplacementsFromDirectory(
 
   return ErrorCode;
 }
+} // namespace detail
 
+template <>
 std::error_code collectReplacementsFromDirectory(
-const llvm::StringRef Directory, TUDiagnostics &TUs,
+const llvm::StringRef Directory, TUReplacements &TUs,
 TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics) {
-  using namespace llvm::sys::fs;
-  using namespace llvm::sys::path;
-
-  std::error_code ErrorCode;
-
-  for (recursive_directory_iterator I(Directory, ErrorCode), E;
-   I != E && !ErrorCode; I.increment(ErrorCode)) {
-if (filename(I->path())[0] == '.') {
-  // Indicate not to descend into directories beginning with '.'
-  I.no_push();
-  continue;
-}
-
-if (extension(I->path()) != ".yaml")

[clang-tools-extra] [clang-apply-replacements] Deduplicate Implementation of `collectReplacementsFromDirectory` (NFC) (PR #78630)

2024-01-19 Thread Daniil Dudkin via cfe-commits

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


  1   2   3   4   5   6   >