[PATCH] D129664: [Clang] Adjust extension warnings for delimited sequences

2022-07-13 Thread Corentin Jabot via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6882ca9aff07: [Clang] Adjust extension warnings for 
delimited sequences (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129664/new/

https://reviews.llvm.org/D129664

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/Lexer/char-escapes-delimited.c
  clang/test/Preprocessor/ucn-pp-identifier.c
  clang/test/Sema/ucn-identifiers.c

Index: clang/test/Sema/ucn-identifiers.c
===
--- clang/test/Sema/ucn-identifiers.c
+++ clang/test/Sema/ucn-identifiers.c
@@ -17,8 +17,8 @@
   \u00fcber(1);
   über(2);
   \U00FCber(3);
-  \u{FC}ber(4); // expected-warning {{Clang extension}}
-  \N{LATIN SMALL LETTER U WITH DIAERESIS}ber(4); // expected-warning {{Clang extension}}
+  \u{FC}ber(4); // expected-warning {{extension}}
+  \N{LATIN SMALL LETTER U WITH DIAERESIS}ber(4); // expected-warning {{extension}}
 }
 
 void badCalls(void) {
Index: clang/test/Preprocessor/ucn-pp-identifier.c
===
--- clang/test/Preprocessor/ucn-pp-identifier.c
+++ clang/test/Preprocessor/ucn-pp-identifier.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -verify -Wundef
-// RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify -Wundef
-// RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify -Wundef -ftrigraphs -DTRIGRAPHS=1
+// RUN: %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -verify=expected,ext -Wundef
+// RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef
+// RUN: %clang_cc1 %s -fsyntax-only -x c++ -std=c++2b -pedantic -ftrigraphs -verify=expected,cxx2b -Wundef -Wpre-c++2b-compat
+// RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef -ftrigraphs -DTRIGRAPHS=1
 // RUN: not %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -Wundef 2>&1 | FileCheck -strict-whitespace %s
 
 #define \u00FC
@@ -17,7 +18,7 @@
 #error "This should never happen"
 #endif
 
-#if a\u{FD}() //expected-warning {{Clang extension}}
+#if a\u{FD}() // ext-warning {{extension}} cxx2b-warning {{before C++2b}}
 #error "This should never happen"
 #endif
 
@@ -30,14 +31,15 @@
 
 // Make sure we reject disallowed UCNs
 #define \ufffe // expected-error {{macro name must be an identifier}}
-#define \U1000   // expected-error {{macro name must be an identifier}}
-#define \u0061   // expected-error {{character 'a' cannot be specified by a universal character name}} expected-error {{macro name must be an identifier}}
-#define \u{fffe}// expected-error {{macro name must be an identifier}} expected-warning {{Clang extension}}
+#define \U1000  // expected-error {{macro name must be an identifier}}
+#define \u0061  // expected-error {{character 'a' cannot be specified by a universal character name}} expected-error {{macro name must be an identifier}}
+#define \u{fffe}// expected-error {{macro name must be an identifier}} \
+// ext-warning {{extension}} cxx2b-warning {{before C++2b}}
 #define \N{ALERT}   // expected-error {{universal character name refers to a control character}} \
// expected-error {{macro name must be an identifier}} \
-   // expected-warning {{Clang extension}}
+   // ext-warning {{extension}} cxx2b-warning {{before C++2b}}
 #define \N{WASTEBASKET} // expected-error {{macro name must be an identifier}} \
-// expected-warning {{Clang extension}}
+// ext-warning {{extension}} cxx2b-warning {{before C++2b}}
 
 #define a\u0024
 
@@ -132,7 +134,7 @@
// expected-warning {{incomplete delimited universal character name}}
 
 #ifdef TRIGRAPHS
-int \N?? = 0; // expected-warning{{amed escape sequences are a Clang extension}} \
+int \N?? = 0; // expected-warning{{extension}} cxx2b-warning {{before C++2b}} \
 // expected-warning 2{{trigraph converted}}
 
 #endif
Index: clang/test/Lexer/char-escapes-delimited.c
===
--- clang/test/Lexer/char-escapes-delimited.c
+++ clang/test/Lexer/char-escapes-delimited.c
@@ -1,8 +1,9 @@
-// RUN: %clang_cc1 -x c++ -std=gnu++11 -fsyntax-only -pedantic -verify %s
-// RUN: %clang_cc1 -x c -std=gnu11 -fsyntax-only -pedantic -verify %s
-// RUN: %clang_cc1 -x c++ -std=gnu++11 -fwchar-type=short -fno-signed-wchar -fsyntax-only -pedantic -verify %s
-// RUN: %clang_cc1 -x c -std=gnu11 -fwchar-type=short -fno-signed-wchar -fsyntax-only -pedantic -verify %s
-// RUN: %clang_cc1 -x c++ -std=c++17 -ftrigraphs -fsyntax-only -pedantic -verify -DTRIGRAPHS=1 %s
+// 

[clang] 6882ca9 - [Clang] Adjust extension warnings for delimited sequences

2022-07-13 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-14T07:50:58+02:00
New Revision: 6882ca9aff076738bbffd68f73892187519554f8

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

LOG: [Clang] Adjust extension warnings for delimited sequences

WG21 approved delimited escape sequences and named escape
sequences.
Adjust the extension warnings accordingly, and update
the release notes.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D129664

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
clang/lib/Lex/LiteralSupport.cpp
clang/test/Lexer/char-escapes-delimited.c
clang/test/Preprocessor/ucn-pp-identifier.c
clang/test/Sema/ucn-identifiers.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f8977d5ac720b..a02bc0a2f6914 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -502,6 +502,10 @@ C++2b Feature Support
 - Implemented `P0849R8: auto(x): decay-copy in the language 
`_.
 - Implemented `P2242R3: Non-literal variables (and labels and gotos) in 
constexpr functions`_.
 - Implemented `LWG3659: Consider ATOMIC_FLAG_INIT undeprecation 
`_.
+- Implemented `P2290 Delimited escape sequences `_.
+  This feature is available as an extension in all C and C++ language modes.
+- Implemented `P2071 Named universal character escapes 
`_.
+  This feature is available as an extension in all C and C++ language modes.
 
 CUDA/HIP Language Changes in Clang
 --

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 38ee022e5f04c..dd09097044926 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -130,8 +130,15 @@ def warn_utf8_symbol_zero_width : Warning<
   "some environments">, InGroup>;
 
 def ext_delimited_escape_sequence : Extension<
-  "%select{delimited|named}0 escape sequences are a Clang extension">,
+  "%select{delimited|named}0 escape sequences are a "
+  "%select{Clang|C++2b}1 extension">,
   InGroup>;
+
+def warn_cxx2b_delimited_escape_sequence : Warning<
+  "%select{delimited|named}0 escape sequences are "
+  "incompatible with C++ standards before C++2b">,
+  InGroup, DefaultIgnore;
+
 def err_delimited_escape_empty : Error<
   "delimited escape sequence cannot be empty">;
 def err_delimited_escape_missing_brace: Error<

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 6b2767dcee3d5..b3aac9df65465 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -3287,7 +3287,10 @@ llvm::Optional Lexer::tryReadNumericUCN(const 
char *,
   }
 
   if (Delimited && PP) {
-Diag(BufferPtr, diag::ext_delimited_escape_sequence) << /*delimited*/ 0;
+Diag(BufferPtr, PP->getLangOpts().CPlusPlus2b
+? diag::warn_cxx2b_delimited_escape_sequence
+: diag::ext_delimited_escape_sequence)
+<< /*delimited*/ 0 << (PP->getLangOpts().CPlusPlus ? 1 : 0);
   }
 
   if (Result) {
@@ -3371,7 +3374,10 @@ llvm::Optional Lexer::tryReadNamedUCN(const 
char *,
   }
 
   if (Diagnose && PP && !LooseMatch)
-Diag(BufferPtr, diag::ext_delimited_escape_sequence) << /*named*/ 1;
+Diag(BufferPtr, PP->getLangOpts().CPlusPlus2b
+? diag::warn_cxx2b_delimited_escape_sequence
+: diag::ext_delimited_escape_sequence)
+<< /*named*/ 1 << (PP->getLangOpts().CPlusPlus ? 1 : 0);
 
   if (LooseMatch)
 Res = LooseMatch->CodePoint;

diff  --git a/clang/lib/Lex/LiteralSupport.cpp 
b/clang/lib/Lex/LiteralSupport.cpp
index ebf30c9f01a9e..53635a7385ec6 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -311,8 +311,9 @@ static unsigned ProcessCharEscape(const char *ThisTokBegin,
   << tok::r_brace;
 else if (!HadError) {
   Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
-   diag::ext_delimited_escape_sequence)
-  << /*delimited*/ 0;
+   Features.CPlusPlus2b ? diag::warn_cxx2b_delimited_escape_sequence
+: diag::ext_delimited_escape_sequence)
+  << /*delimited*/ 0 << (Features.CPlusPlus ? 1 : 0);
 }
   }
 
@@ -641,8 +642,9 @@ static bool ProcessUCNEscape(const char *ThisTokBegin, 
const char *,
 
   if ((IsDelimitedEscapeSequence || IsNamedEscapeSequence) && Diags)
 Diag(Diags, Features, Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
- diag::ext_delimited_escape_sequence)
-

[PATCH] D128907: [Clang] Disable noundef attribute for languages which allow uninitialized function arguments

2022-07-13 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert requested changes to this revision.
jdoerfert added a comment.
This revision now requires changes to proceed.

Wasn't there a discussion about this before, or some other patch? If so, could 
we please link such things (e.g., in the commit message) so people don't have 
to remember and find the links themselves.

FWIW, I don't think this is the right approach. For one, assuming we want such 
a logic, I would expect the default of the flag to change and not some hidden 
stuff that makes the still exposed flag meaningless.
That said, I doubt this is even what we want. Throwing away the benefits of the 
noundef for one special case. IIRC, I mentioned alternatives in the other 
discussion already,... not that I have a link handy.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128907/new/

https://reviews.llvm.org/D128907

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


[PATCH] D112374: [clang] Implement ElaboratedType sugaring for types written bare

2022-07-13 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

FWIW, this change also broke this check in Firefox's clang plugin: 
https://searchfox.org/mozilla-central/rev/0d11f3660945ce35c49501bb44bc4f82bb2b503c/build/clang-plugin/NoPrincipalGetURI.cpp


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112374/new/

https://reviews.llvm.org/D112374

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


[PATCH] D128907: [Clang] Disable noundef attribute for languages which allow uninitialized function arguments

2022-07-13 Thread Sameer Sahasrabuddhe via Phabricator via cfe-commits
sameerds added a comment.

The current set of reviewers is mostly loaded with HIP engineers who are 
familiar with the issue and the proposed solution. But this solution affects 
all languages with convergent functions, which is visible from the affected 
tests. It will be good to seek comments from people responsible for CUDA, 
OpenMP and OpenCL too.




Comment at: clang/include/clang/Basic/LangOptions.h:534
+  /// Return true if uninitialized function arguments are allowed.
+  bool allowUninitializedFunctionsArgs() const {
+/// CUDA/HIP etc. cross-lane APIs are convergent functions

The spelling should be "allowUninitializedFunctionArgs()", where the noun 
"Function" is singular.



Comment at: clang/lib/CodeGen/CGCall.cpp:2306
 
+  // Enable noundef attribute based on codegen options and
+  // skip adding the attribute for languages which allows uninitialized

This comment is merely an English translation of the Boolean expression. It 
should instead provide a bit of context. Like the fact that on HIP, CUDA, etc, 
some functions have multi-threaded semantics where it is enough for only one or 
some threads to provide defined arguments. Depending on semantics, undef 
arguments in some threads don't produce undefined results in the function call.

It might be worth adding this longer explanation to the commit description too, 
rather than just saying "strict constraints".


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128907/new/

https://reviews.llvm.org/D128907

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


[PATCH] D127187: [C++20] [Modules] Implement AllAdditionalTUReachable

2022-07-13 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

@iains @rsmith @MaskRay gentle ping~


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127187/new/

https://reviews.llvm.org/D127187

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


[PATCH] D129170: [Sema] Add deprecation warnings for some compiler provided __has_* type traits

2022-07-13 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D129170#3650618 , @glandium wrote:

> From the commit message:
>
>> This patch adds deprecation warnings for the usage of those builtins, except 
>> for __has_trivial_destructor which doesn't have a GCC alternative.
>
> The exception for __has_trivial_destructor doesn't seem to be true, FWIW.

Oh, I'm really sorry for that :/ It was changed because Aaron asked me to add 
it as well, but I forgot to update the summary.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129170/new/

https://reviews.llvm.org/D129170

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


[PATCH] D128465: [llvm] add zstd to `llvm::compression` namespace

2022-07-13 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Why was this reverted? Please make extensive tests especially for something 
dealing with the build system. When reverting a commit, briefly describe what 
happened.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128465/new/

https://reviews.llvm.org/D128465

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


[PATCH] D129170: [Sema] Add deprecation warnings for some compiler provided __has_* type traits

2022-07-13 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

From the commit message:

> This patch adds deprecation warnings for the usage of those builtins, except 
> for __has_trivial_destructor which doesn't have a GCC alternative.

This doesn't seem to be true, FWIW.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129170/new/

https://reviews.llvm.org/D129170

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


[PATCH] D129498: [analyzer] Add new function `clang_analyzer_value` to ExprInspectionChecker

2022-07-13 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D129498#3647348 , @ASDenysPetrov 
wrote:

> In D129498#3644222 , @NoQ wrote:
>
>> Maybe `clang_analyzer_range()` instead?
>
> This was its first name. I refused. First, because it emits concrete integers 
> as well and moreover we can extend it for arrays or strings e.g. Second, the 
> ranges is just an implementation detail and an actual thing we want to see is 
> an associated value.

Ok how about `clang_analyzer_constraint()`? A concrete value could be thought 
of as constraint, and so can be range, or anything else any exotic constraint 
managers may decide to dump.




Comment at: clang/test/Analysis/print-ranges.cpp:1
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection 
-analyzer-config eagerly-assume=false -verify %s
+

ASDenysPetrov wrote:
> NoQ wrote:
> > I suspect this test will crash when clang is built with Z3, because the Z3 
> > constraint manager doesn't implement your new function yet.
> Agree. Is it enough `REQUIRES: no-z3` or to add `#ifdef ANALYZER_CM_Z3`?
That should be good. My personal tradition in such cases is to double-check 
that this doesn't disable the test entirely.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129498/new/

https://reviews.llvm.org/D129498

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


[PATCH] D129654: [Clang][Driver] Fix include paths for `--sysroot /` on OpenBSD/FreeBSD

2022-07-13 Thread dana koch via Phabricator via cfe-commits
3405691582 added a comment.

In D129654#3650534 , @brad wrote:

> In D129654#3650412 , @3405691582 
> wrote:
>
>> Tested change on OpenBSD resolves downstream issues.
>
> What issues?

As mentioned, this replicates https://reviews.llvm.org/D126289 for OpenBSD 
which fixes #28283. That particular issue caused a build problem in Swift's use 
of VFS in which I verified this patch solves. I was trying to clarify the scope 
and mechanism in which I tested this change, sorry for the confusion.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129654/new/

https://reviews.llvm.org/D129654

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


[PATCH] D129461: [PowerPC] Support x86 compatible intrinsics on AIX

2022-07-13 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf added inline comments.



Comment at: clang/lib/Driver/ToolChains/AIX.cpp:232
+path::remove_filename(P);
+addSystemInclude(DriverArgs, CC1Args, P);
   }

shchenz wrote:
> Can we use `path::parent_path(P)` directly in `addSystemInclude()`? 
> `remove_filename()` sounds like `ppc_wrappers` is a file.
It just wraps `parent_path`, and `parent_path` only accepts (and returns) 
`StringRef`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129461/new/

https://reviews.llvm.org/D129461

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


[PATCH] D129654: [Clang][Driver] Fix include paths for `--sysroot /` on OpenBSD/FreeBSD

2022-07-13 Thread Brad Smith via Phabricator via cfe-commits
brad added a comment.

In D129654#3650412 , @3405691582 
wrote:

> Tested change on OpenBSD resolves downstream issues.

What issues?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129654/new/

https://reviews.llvm.org/D129654

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


[PATCH] D125291: Introduce @llvm.threadlocal.address intrinsic to access TLS variable

2022-07-13 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a reviewer: ychen.
ChuanqiXu added a comment.

@jyknight @nikic @rjmccall @efriedma @nhaehnle gentle ping~


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125291/new/

https://reviews.llvm.org/D125291

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


[PATCH] D128690: [ODRHash diagnostics] Preparation to minimize subsequent diffs. NFC.

2022-07-13 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/lib/Serialization/ASTReader.cpp:10621-10626
 // Compute the hash of the method as if it has no body.
-auto ComputeCXXMethodODRHash = [](const CXXMethodDecl *D) {
-  Hash.clear();
-  Hash.AddFunctionDecl(D, true /*SkipBody*/);
-  return Hash.CalculateHash();
+auto ComputeCXXMethodODRHash = [](const CXXMethodDecl *D) {
+  ODRHash Hasher;
+  Hasher.AddFunctionDecl(D, true /*SkipBody*/);
+  return Hasher.CalculateHash();
 };

vsapsai wrote:
> ChuanqiXu wrote:
> > Couldn't we hoist this like others?
> It is used only on the lines below - 10632 & 10634, so I think it is good to 
> keep its scope small. And not hoisting is consistent with other places using 
> lambdas close to their 2 calls like different kinds of `PopulateHashes`.
> 
> This is a good observation. I've checked the usage of other hoisted lambdas 
> and `ComputeTemplateParameterListODRHash` is used only in 2 places, so now I 
> think we shouldn't hoist it.
Makes sense to me : )


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128690/new/

https://reviews.llvm.org/D128690

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


[PATCH] D128465: [llvm] add zstd to `llvm::compression` namespace

2022-07-13 Thread Cole Kissane via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcef07169ec9f: [llvm] add zstd to `llvm::compression` 
namespace (authored by ckissane).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128465/new/

https://reviews.llvm.org/D128465

Files:
  llvm/CMakeLists.txt
  llvm/cmake/config-ix.cmake
  llvm/cmake/modules/FindZSTD.cmake
  llvm/cmake/modules/LLVMConfig.cmake.in
  llvm/include/llvm/Config/llvm-config.h.cmake
  llvm/include/llvm/Support/Compression.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/Compression.cpp
  llvm/test/lit.site.cfg.py.in
  llvm/unittests/Support/CompressionTest.cpp
  utils/bazel/llvm_configs/llvm-config.h.cmake

Index: utils/bazel/llvm_configs/llvm-config.h.cmake
===
--- utils/bazel/llvm_configs/llvm-config.h.cmake
+++ utils/bazel/llvm_configs/llvm-config.h.cmake
@@ -95,6 +95,9 @@
 /* Define if zlib compression is available */
 #cmakedefine01 LLVM_ENABLE_ZLIB
 
+/* Define if zstd compression is available */
+#cmakedefine01 LLVM_ENABLE_ZSTD
+
 /* Define if LLVM was built with a dependency to the libtensorflow dynamic library */
 #cmakedefine LLVM_HAVE_TF_API
 
Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -61,4 +61,42 @@
 }
 #endif
 
+#if LLVM_ENABLE_ZSTD
+static void testZstdCompression(StringRef Input, int Level) {
+  SmallVector Compressed;
+  SmallVector Uncompressed;
+  zstd::compress(arrayRefFromStringRef(Input), Compressed, Level);
+
+  // Check that uncompressed buffer is the same as original.
+  Error E = zstd::uncompress(Compressed, Uncompressed, Input.size());
+  consumeError(std::move(E));
+
+  EXPECT_EQ(Input, toStringRef(Uncompressed));
+  if (Input.size() > 0) {
+// Uncompression fails if expected length is too short.
+E = zstd::uncompress(Compressed, Uncompressed, Input.size() - 1);
+EXPECT_EQ("Destination buffer is too small", llvm::toString(std::move(E)));
+  }
+}
+
+TEST(CompressionTest, Zstd) {
+  testZstdCompression("", zstd::DefaultCompression);
+
+  testZstdCompression("hello, world!", zstd::NoCompression);
+  testZstdCompression("hello, world!", zstd::BestSizeCompression);
+  testZstdCompression("hello, world!", zstd::BestSpeedCompression);
+  testZstdCompression("hello, world!", zstd::DefaultCompression);
+
+  const size_t kSize = 1024;
+  char BinaryData[kSize];
+  for (size_t i = 0; i < kSize; ++i)
+BinaryData[i] = i & 255;
+  StringRef BinaryDataStr(BinaryData, kSize);
+
+  testZstdCompression(BinaryDataStr, zstd::NoCompression);
+  testZstdCompression(BinaryDataStr, zstd::BestSizeCompression);
+  testZstdCompression(BinaryDataStr, zstd::BestSpeedCompression);
+  testZstdCompression(BinaryDataStr, zstd::DefaultCompression);
+}
+#endif
 }
Index: llvm/test/lit.site.cfg.py.in
===
--- llvm/test/lit.site.cfg.py.in
+++ llvm/test/lit.site.cfg.py.in
@@ -37,6 +37,7 @@
 config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.have_zstd = @LLVM_ENABLE_ZSTD@
 config.have_libxar = @LLVM_HAVE_LIBXAR@
 config.have_libxml2 = @LLVM_ENABLE_LIBXML2@
 config.have_curl = @LLVM_ENABLE_CURL@
Index: llvm/lib/Support/Compression.cpp
===
--- llvm/lib/Support/Compression.cpp
+++ llvm/lib/Support/Compression.cpp
@@ -20,6 +20,9 @@
 #if LLVM_ENABLE_ZLIB
 #include 
 #endif
+#if LLVM_ENABLE_ZSTD
+#include 
+#endif
 
 using namespace llvm;
 using namespace llvm::compression;
@@ -100,3 +103,65 @@
   llvm_unreachable("zlib::uncompress is unavailable");
 }
 #endif
+
+#if LLVM_ENABLE_ZSTD
+
+bool zstd::isAvailable() { return true; }
+
+void zstd::compress(ArrayRef Input,
+SmallVectorImpl , int Level) {
+  unsigned long CompressedBufferSize = ::ZSTD_compressBound(Input.size());
+  CompressedBuffer.resize_for_overwrite(CompressedBufferSize);
+  unsigned long CompressedSize =
+  ::ZSTD_compress((char *)CompressedBuffer.data(), CompressedBufferSize,
+  (const char *)Input.data(), Input.size(), Level);
+  if (ZSTD_isError(CompressedSize))
+report_bad_alloc_error("Allocation failed");
+  // Tell MemorySanitizer that zstd output buffer is fully initialized.
+  // This avoids a false report when running LLVM with uninstrumented ZLib.
+  __msan_unpoison(CompressedBuffer.data(), CompressedSize);
+  if (CompressedSize < CompressedBuffer.size())
+CompressedBuffer.truncate(CompressedSize);
+}
+
+Error zstd::uncompress(ArrayRef Input, uint8_t *UncompressedBuffer,
+   size_t ) {
+  const size_t Res =
+  

[PATCH] D128465: [llvm] add zstd to `llvm::compression` namespace

2022-07-13 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 89.
ckissane added a comment.

- Merge remote-tracking branch 'origin/main' into ckissane.add-zstd
- [Support] update zstd interface to use uint8_t * and ArrayRef


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128465/new/

https://reviews.llvm.org/D128465

Files:
  llvm/CMakeLists.txt
  llvm/cmake/config-ix.cmake
  llvm/cmake/modules/FindZSTD.cmake
  llvm/cmake/modules/LLVMConfig.cmake.in
  llvm/include/llvm/Config/llvm-config.h.cmake
  llvm/include/llvm/Support/Compression.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/Compression.cpp
  llvm/test/lit.site.cfg.py.in
  llvm/unittests/Support/CompressionTest.cpp
  utils/bazel/llvm_configs/llvm-config.h.cmake

Index: utils/bazel/llvm_configs/llvm-config.h.cmake
===
--- utils/bazel/llvm_configs/llvm-config.h.cmake
+++ utils/bazel/llvm_configs/llvm-config.h.cmake
@@ -95,6 +95,9 @@
 /* Define if zlib compression is available */
 #cmakedefine01 LLVM_ENABLE_ZLIB
 
+/* Define if zstd compression is available */
+#cmakedefine01 LLVM_ENABLE_ZSTD
+
 /* Define if LLVM was built with a dependency to the libtensorflow dynamic library */
 #cmakedefine LLVM_HAVE_TF_API
 
Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -61,4 +61,42 @@
 }
 #endif
 
+#if LLVM_ENABLE_ZSTD
+static void testZstdCompression(StringRef Input, int Level) {
+  SmallVector Compressed;
+  SmallVector Uncompressed;
+  zstd::compress(arrayRefFromStringRef(Input), Compressed, Level);
+
+  // Check that uncompressed buffer is the same as original.
+  Error E = zstd::uncompress(Compressed, Uncompressed, Input.size());
+  consumeError(std::move(E));
+
+  EXPECT_EQ(Input, toStringRef(Uncompressed));
+  if (Input.size() > 0) {
+// Uncompression fails if expected length is too short.
+E = zstd::uncompress(Compressed, Uncompressed, Input.size() - 1);
+EXPECT_EQ("Destination buffer is too small", llvm::toString(std::move(E)));
+  }
+}
+
+TEST(CompressionTest, Zstd) {
+  testZstdCompression("", zstd::DefaultCompression);
+
+  testZstdCompression("hello, world!", zstd::NoCompression);
+  testZstdCompression("hello, world!", zstd::BestSizeCompression);
+  testZstdCompression("hello, world!", zstd::BestSpeedCompression);
+  testZstdCompression("hello, world!", zstd::DefaultCompression);
+
+  const size_t kSize = 1024;
+  char BinaryData[kSize];
+  for (size_t i = 0; i < kSize; ++i)
+BinaryData[i] = i & 255;
+  StringRef BinaryDataStr(BinaryData, kSize);
+
+  testZstdCompression(BinaryDataStr, zstd::NoCompression);
+  testZstdCompression(BinaryDataStr, zstd::BestSizeCompression);
+  testZstdCompression(BinaryDataStr, zstd::BestSpeedCompression);
+  testZstdCompression(BinaryDataStr, zstd::DefaultCompression);
+}
+#endif
 }
Index: llvm/test/lit.site.cfg.py.in
===
--- llvm/test/lit.site.cfg.py.in
+++ llvm/test/lit.site.cfg.py.in
@@ -37,6 +37,7 @@
 config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.have_zstd = @LLVM_ENABLE_ZSTD@
 config.have_libxar = @LLVM_HAVE_LIBXAR@
 config.have_libxml2 = @LLVM_ENABLE_LIBXML2@
 config.have_curl = @LLVM_ENABLE_CURL@
Index: llvm/lib/Support/Compression.cpp
===
--- llvm/lib/Support/Compression.cpp
+++ llvm/lib/Support/Compression.cpp
@@ -20,6 +20,9 @@
 #if LLVM_ENABLE_ZLIB
 #include 
 #endif
+#if LLVM_ENABLE_ZSTD
+#include 
+#endif
 
 using namespace llvm;
 using namespace llvm::compression;
@@ -100,3 +103,65 @@
   llvm_unreachable("zlib::uncompress is unavailable");
 }
 #endif
+
+#if LLVM_ENABLE_ZSTD
+
+bool zstd::isAvailable() { return true; }
+
+void zstd::compress(ArrayRef Input,
+SmallVectorImpl , int Level) {
+  unsigned long CompressedBufferSize = ::ZSTD_compressBound(Input.size());
+  CompressedBuffer.resize_for_overwrite(CompressedBufferSize);
+  unsigned long CompressedSize =
+  ::ZSTD_compress((char *)CompressedBuffer.data(), CompressedBufferSize,
+  (const char *)Input.data(), Input.size(), Level);
+  if (ZSTD_isError(CompressedSize))
+report_bad_alloc_error("Allocation failed");
+  // Tell MemorySanitizer that zstd output buffer is fully initialized.
+  // This avoids a false report when running LLVM with uninstrumented ZLib.
+  __msan_unpoison(CompressedBuffer.data(), CompressedSize);
+  if (CompressedSize < CompressedBuffer.size())
+CompressedBuffer.truncate(CompressedSize);
+}
+
+Error zstd::uncompress(ArrayRef Input, uint8_t *UncompressedBuffer,
+   size_t ) {
+  const size_t Res =
+  ::ZSTD_decompress(UncompressedBuffer, 

[PATCH] D129654: [Clang][Driver] Fix include paths for `--sysroot /` on OpenBSD/FreeBSD

2022-07-13 Thread dana koch via Phabricator via cfe-commits
3405691582 accepted this revision.
3405691582 added a comment.
This revision is now accepted and ready to land.

LGTM. Tested change on OpenBSD, was not able to check FreeBSD.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129654/new/

https://reviews.llvm.org/D129654

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


[clang] b370be3 - [CUDA] Allow the new driver to compile CUDA in non-RDC mode

2022-07-13 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-07-13T21:49:15-04:00
New Revision: b370be37cca760122903f1e202952fecf5182cc1

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

LOG: [CUDA] Allow the new driver to compile CUDA in non-RDC mode

The new driver primarily allows us to support RDC-mode compilations with
proper linking. This is not needed for non-RDC mode compilation, but we
still would like the new driver to be able to handle this mode so we can
transition away from the old driver in the future. This patch adds the
necessary code to support creating a fatbinary for CUDA code generation
as well as removing old assumptions and errors about RDC-mode with the
new driver.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D129655

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/CodeGen/CGCUDANV.cpp
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGenCUDA/offloading-entries.cu
clang/test/Driver/cuda-omp-unsupported-debug-options.cu
clang/test/Driver/cuda-openmp-driver.cu
clang/test/Driver/cuda-phases.cu

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 96219f83b0a53..68685baf76331 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -60,8 +60,6 @@ def err_drv_no_cuda_libdevice : Error<
   "cannot find libdevice for %0; provide path to 
diff erent CUDA installation "
   "via '--cuda-path', or pass '-nocudalib' to build without linking with "
   "libdevice">;
-def err_drv_no_rdc_new_driver : Error<
-  "Using '--offload-new-driver' requires '-fgpu-rdc'">;
 
 def err_drv_no_rocm_device_lib : Error<
   "cannot find ROCm device library%select{| for %1|for ABI version %1}0; 
provide its path via "

diff  --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 6a185c29d3cec..a8bb0dd65d1aa 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -212,8 +212,7 @@ static std::unique_ptr 
InitDeviceMC(CodeGenModule ) {
 CGNVCUDARuntime::CGNVCUDARuntime(CodeGenModule )
 : CGCUDARuntime(CGM), Context(CGM.getLLVMContext()),
   TheModule(CGM.getModule()),
-  RelocatableDeviceCode(CGM.getLangOpts().GPURelocatableDeviceCode ||
-CGM.getLangOpts().OffloadingNewDriver),
+  RelocatableDeviceCode(CGM.getLangOpts().GPURelocatableDeviceCode),
   DeviceMC(InitDeviceMC(CGM)) {
   CodeGen::CodeGenTypes  = CGM.getTypes();
   ASTContext  = CGM.getContext();
@@ -1172,10 +1171,11 @@ llvm::Function *CGNVCUDARuntime::finalizeModule() {
 }
 return nullptr;
   }
-  if (!(CGM.getLangOpts().OffloadingNewDriver && RelocatableDeviceCode))
+  if (CGM.getLangOpts().OffloadingNewDriver && RelocatableDeviceCode)
+createOffloadingEntries();
+  else
 return makeModuleCtorFunction();
 
-  createOffloadingEntries();
   return nullptr;
 }
 

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 80fa3c158abc2..5a53c4bb5308b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2930,7 +2930,7 @@ class OffloadingActionBuilder final {
 return false;
 
   Relocatable = Args.hasFlag(options::OPT_fgpu_rdc,
-  options::OPT_fno_gpu_rdc, /*Default=*/false);
+ options::OPT_fno_gpu_rdc, /*Default=*/false);
 
   const ToolChain *HostTC = 
C.getSingleOffloadToolChain();
   assert(HostTC && "No toolchain for host compilation.");
@@ -4486,11 +4486,23 @@ Action *Driver::BuildOffloadingActions(Compilation ,
   if (offloadDeviceOnly())
 return C.MakeAction(DDeps, types::TY_Nothing);
 
-  Action *OffloadPackager =
-  C.MakeAction(OffloadActions, types::TY_Image);
   OffloadAction::DeviceDependences DDep;
-  DDep.add(*OffloadPackager, *C.getSingleOffloadToolChain(),
-   nullptr, Action::OFK_None);
+  if (C.isOffloadingHostKind(Action::OFK_Cuda) &&
+  !Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false)) {
+// If we are not in RDC-mode we just emit the final CUDA fatbinary for each
+// translation unit without requiring any linking.
+Action *FatbinAction =
+C.MakeAction(OffloadActions, types::TY_CUDA_FATBIN);
+DDep.add(*FatbinAction, *C.getSingleOffloadToolChain(),
+ nullptr, Action::OFK_Cuda);
+  } else {
+// Package all the offloading actions into a single output that can be
+// embedded in the host and linked.
+Action *PackagerAction =
+C.MakeAction(OffloadActions, 
types::TY_Image);
+DDep.add(*PackagerAction, *C.getSingleOffloadToolChain(),
+ nullptr, 

[PATCH] D129655: [CUDA] Allow the new driver to compile CUDA in non-RDC mode

2022-07-13 Thread Joseph Huber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
jhuber6 marked an inline comment as done.
Closed by commit rGb370be37cca7: [CUDA] Allow the new driver to compile CUDA in 
non-RDC mode (authored by jhuber6).

Changed prior to commit:
  https://reviews.llvm.org/D129655?vs=444398=85#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129655/new/

https://reviews.llvm.org/D129655

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenCUDA/offloading-entries.cu
  clang/test/Driver/cuda-omp-unsupported-debug-options.cu
  clang/test/Driver/cuda-openmp-driver.cu
  clang/test/Driver/cuda-phases.cu

Index: clang/test/Driver/cuda-phases.cu
===
--- clang/test/Driver/cuda-phases.cu
+++ clang/test/Driver/cuda-phases.cu
@@ -221,25 +221,48 @@
 //
 // Test the phases generated when using the new offloading driver.
 //
-// RUN: %clang -### -target powerpc64le-ibm-linux-gnu -ccc-print-phases --offload-new-driver \
-// RUN: --offload-arch=sm_52 --offload-arch=sm_70 %s 2>&1 | FileCheck --check-prefix=NEW_DRIVER %s
-// NEW_DRIVER: 0: input, "[[INPUT:.+]]", cuda
-// NEW_DRIVER: 1: preprocessor, {0}, cuda-cpp-output
-// NEW_DRIVER: 2: compiler, {1}, ir
-// NEW_DRIVER: 3: input, "[[INPUT]]", cuda, (device-cuda, sm_52)
-// NEW_DRIVER: 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_52)
-// NEW_DRIVER: 5: compiler, {4}, ir, (device-cuda, sm_52)
-// NEW_DRIVER: 6: backend, {5}, assembler, (device-cuda, sm_52)
-// NEW_DRIVER: 7: assembler, {6}, object, (device-cuda, sm_52)
-// NEW_DRIVER: 8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_52)" {7}, object
-// NEW_DRIVER: 9: input, "[[INPUT]]", cuda, (device-cuda, sm_70)
-// NEW_DRIVER: 10: preprocessor, {9}, cuda-cpp-output, (device-cuda, sm_70)
-// NEW_DRIVER: 11: compiler, {10}, ir, (device-cuda, sm_70)
-// NEW_DRIVER: 12: backend, {11}, assembler, (device-cuda, sm_70)
-// NEW_DRIVER: 13: assembler, {12}, object, (device-cuda, sm_70)
-// NEW_DRIVER: 14: offload, "device-cuda (nvptx64-nvidia-cuda:sm_70)" {13}, object
-// NEW_DRIVER: 15: clang-offload-packager, {8, 14}, image
-// NEW_DRIVER: 16: offload, " (powerpc64le-ibm-linux-gnu)" {2}, " (powerpc64le-ibm-linux-gnu)" {15}, ir
-// NEW_DRIVER: 17: backend, {16}, assembler, (host-cuda)
-// NEW_DRIVER: 18: assembler, {17}, object, (host-cuda)
-// NEW_DRIVER: 19: clang-linker-wrapper, {18}, image, (host-cuda)
+// RUN: %clang -### -target powerpc64le-ibm-linux-gnu -ccc-print-phases --offload-new-driver -fgpu-rdc \
+// RUN: --offload-arch=sm_52 --offload-arch=sm_70 %s 2>&1 | FileCheck --check-prefix=NEW-DRIVER-RDC %s
+// NEW-DRIVER-RDC: 0: input, "[[INPUT:.+]]", cuda
+// NEW-DRIVER-RDC: 1: preprocessor, {0}, cuda-cpp-output
+// NEW-DRIVER-RDC: 2: compiler, {1}, ir
+// NEW-DRIVER-RDC: 3: input, "[[INPUT]]", cuda, (device-cuda, sm_52)
+// NEW-DRIVER-RDC: 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_52)
+// NEW-DRIVER-RDC: 5: compiler, {4}, ir, (device-cuda, sm_52)
+// NEW-DRIVER-RDC: 6: backend, {5}, assembler, (device-cuda, sm_52)
+// NEW-DRIVER-RDC: 7: assembler, {6}, object, (device-cuda, sm_52)
+// NEW-DRIVER-RDC: 8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_52)" {7}, object
+// NEW-DRIVER-RDC: 9: input, "[[INPUT]]", cuda, (device-cuda, sm_70)
+// NEW-DRIVER-RDC: 10: preprocessor, {9}, cuda-cpp-output, (device-cuda, sm_70)
+// NEW-DRIVER-RDC: 11: compiler, {10}, ir, (device-cuda, sm_70)
+// NEW-DRIVER-RDC: 12: backend, {11}, assembler, (device-cuda, sm_70)
+// NEW-DRIVER-RDC: 13: assembler, {12}, object, (device-cuda, sm_70)
+// NEW-DRIVER-RDC: 14: offload, "device-cuda (nvptx64-nvidia-cuda:sm_70)" {13}, object
+// NEW-DRIVER-RDC: 15: clang-offload-packager, {8, 14}, image
+// NEW-DRIVER-RDC: 16: offload, " (powerpc64le-ibm-linux-gnu)" {2}, " (powerpc64le-ibm-linux-gnu)" {15}, ir
+// NEW-DRIVER-RDC: 17: backend, {16}, assembler, (host-cuda)
+// NEW-DRIVER-RDC: 18: assembler, {17}, object, (host-cuda)
+// NEW-DRIVER-RDC: 19: clang-linker-wrapper, {18}, image, (host-cuda)
+
+// RUN: %clang -### -target powerpc64le-ibm-linux-gnu -ccc-print-phases --offload-new-driver -fgpu-rdc \
+// RUN: --offload-arch=sm_52 --offload-arch=sm_70 %s 2>&1 | FileCheck --check-prefix=NEW-DRIVER %s
+// NEW-DRIVER: 0: input, "[[INPUT:.+]]", cuda
+// NEW-DRIVER: 1: preprocessor, {0}, cuda-cpp-output
+// NEW-DRIVER: 2: compiler, {1}, ir
+// NEW-DRIVER: 3: input, "[[INPUT]]", cuda, (device-cuda, sm_52)
+// NEW-DRIVER: 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_52)
+// NEW-DRIVER: 5: compiler, {4}, ir, (device-cuda, sm_52)
+// NEW-DRIVER: 6: backend, {5}, assembler, (device-cuda, sm_52)
+// NEW-DRIVER: 7: assembler, {6}, object, (device-cuda, sm_52)
+// NEW-DRIVER: 8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_52)" {7}, object
+// NEW-DRIVER: 9: input, "[[INPUT]]", 

[PATCH] D129714: [Driver] Don't passs --dynamic-linker in -r mode

2022-07-13 Thread Brad Smith via Phabricator via cfe-commits
brad added a comment.

In D129714#3650371 , @MaskRay wrote:

> Thanks! This is trivially correct but consider giving folks one day to 
> respond.

Sure thing. No problem.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129714/new/

https://reviews.llvm.org/D129714

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


[PATCH] D129654: [Clang][Driver] Fix include paths for `--sysroot /` on OpenBSD/FreeBSD

2022-07-13 Thread Brad Smith via Phabricator via cfe-commits
brad added a comment.

There is already the initial --sysroot test in test/Driver/openbsd.c. It would 
be preferable to modify what is there. For FreeBSD a test should be added to 
test/Driver/freebsd.c.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129654/new/

https://reviews.llvm.org/D129654

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


[PATCH] D129714: [Driver] Don't passs --dynamic-linker in -r mode

2022-07-13 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Thanks! This is trivially correct but consider giving folks one day to respond.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129714/new/

https://reviews.llvm.org/D129714

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


[PATCH] D129714: [Driver] Don't passs --dynamic-linker in -r mode

2022-07-13 Thread Brad Smith via Phabricator via cfe-commits
brad created this revision.
brad added reviewers: MaskRay, emaste, zhmu, mgorny, phosek.
brad added a project: clang.
Herald added subscribers: abrachet, StephenFan.
Herald added a project: All.
brad requested review of this revision.

As mentioned in commit 57e43ebc42d4e572cab1e84532115c364d5db92a 
..

No behavior change as GNU ld/gold/ld.lld ignore --dynamic-linker in -r mode.
This change makes the intention clearer as we already suppress --dynamic-linker
for -shared, -static, and -static-pie.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129714

Files:
  clang/lib/Driver/ToolChains/Ananas.cpp
  clang/lib/Driver/ToolChains/DragonFly.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/NetBSD.cpp
  clang/lib/Driver/ToolChains/OpenBSD.cpp
  clang/test/Driver/ananas.c
  clang/test/Driver/dragonfly.c
  clang/test/Driver/freebsd.c
  clang/test/Driver/fuchsia.c
  clang/test/Driver/netbsd.c
  clang/test/Driver/openbsd.c

Index: clang/test/Driver/openbsd.c
===
--- clang/test/Driver/openbsd.c
+++ clang/test/Driver/openbsd.c
@@ -37,6 +37,7 @@
 // RUN: %clang --target=mips64el-unknown-openbsd -### %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MIPS64EL-LD %s
 // CHECK-LD-R: "-r"
+// CHECK-LD-R-NOT: "-dynamic-linker"
 // CHECK-LD-R-NOT: "-l
 // CHECK-LD-R-NOT: crt{{[^./]+}}.o
 // CHECK-LD-S: "-cc1" "-triple" "i686-pc-openbsd"
Index: clang/test/Driver/netbsd.c
===
--- clang/test/Driver/netbsd.c
+++ clang/test/Driver/netbsd.c
@@ -468,10 +468,12 @@
 // RUN:   | FileCheck -check-prefix=POWERPC-SECUREPLT %s
 // POWERPC-SECUREPLT: "-target-feature" "+secure-plt"
 
-// -r suppresses default -l and crt*.o like -nostdlib.
+// -r suppresses -dynamic-linker, default -l and crt*.o like -nostdlib.
 // RUN: %clang --target=x86_64-unknown-netbsd -r \
 // RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=RELOCATABLE %s
 // RELOCATABLE: "-r"
+// RELOCATABLE-NOT: "-pie"
+// RELOCATABLE-NOT: "-dynamic-linker"
 // RELOCATABLE-NOT: "-l
 // RELOCATABLE-NOT: crt{{[^./]+}}.o
Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -74,6 +74,7 @@
 // RUN: | FileCheck %s -check-prefix=CHECK-RELOCATABLE
 // CHECK-RELOCATABLE-NOT: "-pie"
 // CHECK-RELOCATABLE-NOT: "--build-id"
+// CHECK-RELOCATABLE-NOT "-dynamic-linker"
 // CHECK-RELOCATABLE: "-r"
 // CHECK-RELOCATABLE-NOT: "-l
 // CHECK-RELOCATABLE-NOT: crt{{[^./]+}}.o
Index: clang/test/Driver/freebsd.c
===
--- clang/test/Driver/freebsd.c
+++ clang/test/Driver/freebsd.c
@@ -206,9 +206,10 @@
 // RUN: FileCheck -check-prefix=PPC64-MUNWIND %s
 // PPC64-MUNWIND: "-funwind-tables=2"
 
-/// -r suppresses default -l and crt*.o like -nostdlib.
+/// -r suppresses -dynamic-linker, default -l and crt*.o like -nostdlib.
 // RUN: %clang -### %s --target=aarch64-pc-freebsd11 -r \
 // RUN:   --sysroot=%S/Inputs/basic_freebsd64_tree 2>&1 | FileCheck %s --check-prefix=RELOCATABLE
 // RELOCATABLE: "-r"
+// RELOCATABLE-NOT: "-dynamic-linker"
 // RELOCATABLE-NOT: "-l
 // RELOCATABLE-NOT: crt{{[^./]+}}.o
Index: clang/test/Driver/dragonfly.c
===
--- clang/test/Driver/dragonfly.c
+++ clang/test/Driver/dragonfly.c
@@ -4,9 +4,10 @@
 // CHECK: "-cc1" "-triple" "x86_64-pc-dragonfly"
 // CHECK: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/usr/libexec/ld-elf.so.{{.*}}" "--hash-style=gnu" "--enable-new-dtags" "-o" "a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbegin.o" "{{.*}}.o" "-L{{.*}}gcc{{.*}}" "-rpath" "{{.*}}gcc{{.*}}" "-lc" "-lgcc" "{{.*}}crtend.o" "{{.*}}crtn.o"
 
-// -r suppresses default -l and crt*.o like -nostdlib.
+// -r suppresses -dynamic-linker, default -l and crt*.o like -nostdlib.
 // RUN: %clang -### %s --target=x86_64-pc-dragonfly -r \
 // RUN:   2>&1 | FileCheck %s --check-prefix=RELOCATABLE
 // RELOCATABLE: "-r"
+// RELOCATABLE-NOT: "-dynamic-linker"
 // RELOCATABLE-NOT: "-l
 // RELOCATABLE-NOT: {{.*}}crt{{[^./]+}}.o
Index: clang/test/Driver/ananas.c
===
--- clang/test/Driver/ananas.c
+++ clang/test/Driver/ananas.c
@@ -16,9 +16,11 @@
 // CHECK-SHARED: crtendS.o
 // CHECK-SHARED: crtn.o
 
-// -r suppresses default -l and crt*.o like -nostdlib.
+// -r suppresses -dynamic-linker, default -l and crt*.o like -nostdlib.
 // RUN: %clang %s -### -o %t.o --target=x86_64-unknown-ananas -r 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-RELOCATABLE
 // CHECK-RELOCATABLE: "-r"
+// CHECK-RELOCATABLE-NOT: "-pie"
+// CHECK-RELOCATABLE-NOT: 

[PATCH] D129563: [docs] Document git-clang-format

2022-07-13 Thread Nico Weber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG422e6e762935: [docs] Document git-clang-format (authored by 
thakis).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129563/new/

https://reviews.llvm.org/D129563

Files:
  clang/docs/ClangFormat.rst


Index: clang/docs/ClangFormat.rst
===
--- clang/docs/ClangFormat.rst
+++ clang/docs/ClangFormat.rst
@@ -229,6 +229,59 @@
 
 Get the latest Visual Studio Code extension from the `Visual Studio 
Marketplace 
`_. The 
default key-binding is Alt-Shift-F.
 
+Git integration
+===
+
+The script `clang/tools/clang-format/git-clang-format` can be used to
+format just the lines touched in git commits:
+
+.. code-block:: console
+
+  % git clang-format -h
+  usage: git clang-format [OPTIONS] [] [|--staged] [--] 
[...]
+
+  If zero or one commits are given, run clang-format on all lines that differ
+  between the working directory and , which defaults to HEAD.  Changes 
are
+  only applied to the working directory, or in the stage/index.
+
+  Examples:
+To format staged changes, i.e everything that's been `git add`ed:
+  git clang-format
+
+To also format everything touched in the most recent commit:
+  git clang-format HEAD~1
+
+If you're on a branch off main, to format everything touched on your 
branch:
+  git clang-format main
+
+  If two commits are given (requires --diff), run clang-format on all lines in 
the
+  second  that differ from the first .
+
+  The following git-config settings set the default of the corresponding 
option:
+clangFormat.binary
+clangFormat.commit
+clangFormat.extensions
+clangFormat.style
+
+  positional arguments:
+  revision from which to compute the diff
+... if specified, only consider differences in these 
files
+
+  optional arguments:
+-h, --helpshow this help message and exit
+--binary BINARY   path to clang-format
+--commit COMMIT   default commit to use if none is specified
+--diffprint a diff instead of applying the changes
+--diffstatprint a diffstat instead of applying the changes
+--extensions EXTENSIONS
+  comma-separated list of file extensions to format, 
excluding the period and case-insensitive
+-f, --force   allow changes to unstaged files
+-p, --patch   select hunks interactively
+-q, --quiet   print less information
+--staged, --cachedformat lines in the stage instead of the working dir
+--style STYLE passed to clang-format
+-v, --verbose print extra information
+
 
 Script for patch reformatting
 =


Index: clang/docs/ClangFormat.rst
===
--- clang/docs/ClangFormat.rst
+++ clang/docs/ClangFormat.rst
@@ -229,6 +229,59 @@
 
 Get the latest Visual Studio Code extension from the `Visual Studio Marketplace `_. The default key-binding is Alt-Shift-F.
 
+Git integration
+===
+
+The script `clang/tools/clang-format/git-clang-format` can be used to
+format just the lines touched in git commits:
+
+.. code-block:: console
+
+  % git clang-format -h
+  usage: git clang-format [OPTIONS] [] [|--staged] [--] [...]
+
+  If zero or one commits are given, run clang-format on all lines that differ
+  between the working directory and , which defaults to HEAD.  Changes are
+  only applied to the working directory, or in the stage/index.
+
+  Examples:
+To format staged changes, i.e everything that's been `git add`ed:
+  git clang-format
+
+To also format everything touched in the most recent commit:
+  git clang-format HEAD~1
+
+If you're on a branch off main, to format everything touched on your branch:
+  git clang-format main
+
+  If two commits are given (requires --diff), run clang-format on all lines in the
+  second  that differ from the first .
+
+  The following git-config settings set the default of the corresponding option:
+clangFormat.binary
+clangFormat.commit
+clangFormat.extensions
+clangFormat.style
+
+  positional arguments:
+  revision from which to compute the diff
+... if specified, only consider differences in these files
+
+  optional arguments:
+-h, --helpshow this help message and exit
+--binary BINARY   path to clang-format
+--commit COMMIT   default commit to use if none is specified
+--diffprint a diff instead of applying the changes
+--diffstatprint a diffstat instead of applying the changes
+

[clang] 422e6e7 - [docs] Document git-clang-format

2022-07-13 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2022-07-13T21:06:00-04:00
New Revision: 422e6e762935b4466c2ef1871df6917ab1c31262

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

LOG: [docs] Document git-clang-format

clang-format's documentation documented the more general clang-format-diff.py
script. Add documentation for the less general but arguably easier-to-use
git integration as well.

Differential Revision: https://reviews.llvm.org/D129563

Added: 


Modified: 
clang/docs/ClangFormat.rst

Removed: 




diff  --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index 150f0aa009e9..3059355c03b1 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -229,6 +229,59 @@ Visual Studio Code Integration
 
 Get the latest Visual Studio Code extension from the `Visual Studio 
Marketplace 
`_. The 
default key-binding is Alt-Shift-F.
 
+Git integration
+===
+
+The script `clang/tools/clang-format/git-clang-format` can be used to
+format just the lines touched in git commits:
+
+.. code-block:: console
+
+  % git clang-format -h
+  usage: git clang-format [OPTIONS] [] [|--staged] [--] 
[...]
+
+  If zero or one commits are given, run clang-format on all lines that 
diff er
+  between the working directory and , which defaults to HEAD.  Changes 
are
+  only applied to the working directory, or in the stage/index.
+
+  Examples:
+To format staged changes, i.e everything that's been `git add`ed:
+  git clang-format
+
+To also format everything touched in the most recent commit:
+  git clang-format HEAD~1
+
+If you're on a branch off main, to format everything touched on your 
branch:
+  git clang-format main
+
+  If two commits are given (requires --
diff ), run clang-format on all lines in the
+  second  that 
diff er from the first .
+
+  The following git-config settings set the default of the corresponding 
option:
+clangFormat.binary
+clangFormat.commit
+clangFormat.extensions
+clangFormat.style
+
+  positional arguments:
+  revision from which to compute the 
diff 
+... if specified, only consider 
diff erences in these files
+
+  optional arguments:
+-h, --helpshow this help message and exit
+--binary BINARY   path to clang-format
+--commit COMMIT   default commit to use if none is specified
+--
diff print a 
diff  instead of applying the changes
+--
diff statprint a 
diff stat instead of applying the changes
+--extensions EXTENSIONS
+  comma-separated list of file extensions to format, 
excluding the period and case-insensitive
+-f, --force   allow changes to unstaged files
+-p, --patch   select hunks interactively
+-q, --quiet   print less information
+--staged, --cachedformat lines in the stage instead of the working dir
+--style STYLE passed to clang-format
+-v, --verbose print extra information
+
 
 Script for patch reformatting
 =



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


[PATCH] D129694: [OPENMP] Make declare target static global externally visible

2022-07-13 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:3284-3286
   // Hidden or internal symbols on the device are not externally visible. 
We
   // should not attempt to register them by creating an offloading entry.
   if (auto *GV = dyn_cast(CE->getAddress()))

This comment needs to be adjusted accordingly



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:10790
 Flags = OffloadEntriesInfoManagerTy::OMPTargetGlobalVarEntryTo;
-VarName = CGM.getMangledName(VD);
+// We don't need to mangle the host side of declare target global 
variables but we
+// need to create offload entry that matches the device side which gets 
mangled.

ssquare08 wrote:
> jhuber6 wrote:
> > It might be easier to just mangle the original definition, that would 
> > reduce a lot of churn here adding `origName` everywhere. Any reason that's 
> > not desirable?
> You are right, it'd have made the code cleaner but we didn't want to mangle 
> the host side if we could avoid it.
Others may want to comment, but personally I'm not too worried about mangling a 
name that wouldn't have been placed in the symbol table to begin with and it 
would make the code a lot cleaner.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:10797
+Out< jhuber6 wrote:
> > `CGM.printPostfixForExternalizedDecl` should ideally give the same output 
> > on the host and device, but it's somewhat limited since it just checks the 
> > file ID and environment, which is technically possible to change. The 
> > kernels use `getTargetEntryUniqueInfo`, which might make sense to re-use 
> > for this case.
> That was the point I had raised in one of the Clang meeting but someone had 
> mentioned that kernels names are created on the host side and the device side 
> reads the information though the Host IR. Seems like kernels name could  also 
> run into mismatch issue for some corner cases then?
So the problem here is that the host and device need to agree on what the name 
is so that we can register the correct variable. The CUDA / HIP toolchains 
solved this by either performing a mangling that is stable between the host and 
device, or by having the driver generate a random hash that gets used on both. 
OpenMP instead solves this by writing the variable to the host IR first and 
then reading it on the device to see what the name needs to be. Since we have 
that dependency we can use any mangling we want, though it's still best for it 
to be somewhat stable unless we want tests to change every time we run them. It 
probably won't hurt anything to just use `printPostfixForExternalizedDecl` but 
it's not as strong of a mangling as what we can do with the OpenMP method since 
it needs to be common between the host and device.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:9439
 const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule ) const {
+  // Make sure any variable with OpenMP declare target is visible to runtime
+  // except for those with hidden visibility

ssquare08 wrote:
> jhuber6 wrote:
> > Just spitballing, is it possible to do this when we make the global instead?
> This is something I was wondering as well.  In 
> CodeGenModule::GetOrCreateLLVMGlobal, when it creates a new global variable, 
> it always uses the llvm::GlobalValue::ExternalLinkage. Seems like this 
> changes somewhere later to internal for static globals. Do you know where 
> that would be?
I'm not exactly sure, I remember deleting some code in D117806 that did 
something like that, albeit incorrectly. But I'm not sure if you'd have the 
necessary information to check whether or not there are updates attached to it. 
We don't want to externalize things if we don't need to, otherwise we'd get a 
lot of our device runtime variables with external visibility that now can't be 
optimized out.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129694/new/

https://reviews.llvm.org/D129694

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


[PATCH] D129709: [clang][CodeGen] add fn_ret_thunk_extern to synthetic fns

2022-07-13 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/test/CodeGen/attr-function-return.c:107
+// CHECK-GCOV: @__llvm_gcov_init() unnamed_addr [[EXTERNGCOV]]
+// CHECK-ASAN: @asan.module_ctor() [[EXTERNASAN:#[0-9]+]]
+// CHECK-TSAN: @tsan.module_ctor() [[EXTERNTSAN:#[0-9]+]]

https://lore.kernel.org/llvm/Ys7pLq+tQk5xEa%2FB@dev-arch.thelio-3990X/ also 
mentions `asan.module_dtor()`.  I wonder what flags produce that?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129709/new/

https://reviews.llvm.org/D129709

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


[PATCH] D129709: [clang][CodeGen] add fn_ret_thunk_extern to synthetic fns

2022-07-13 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers created this revision.
nickdesaulniers added reviewers: MaskRay, void.
Herald added subscribers: jsji, StephenFan, jdoerfert, pengfei, hiraditya.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Follow up fix to
commit 2240d72f15f3 
 ("[X86] 
initial -mfunction-return=thunk-extern
support")
https://reviews.llvm.org/D129572

@nathanchance reported that -mfunction-return=thunk-extern was failing
to annotate the asan and tsan contructors.
https://lore.kernel.org/llvm/Ys7pLq+tQk5xEa%2FB@dev-arch.thelio-3990X/

I then noticed the same occurring for gcov synthetic functions.

Similar to
commit 2786e67 
 
("[IR][sanitizer] Add module flag "frame-pointer" and set
it for cc1 -mframe-pointer={non-leaf,all}")
define a new module level MetaData, "fn_ret_thunk_extern", then when set
adds the fn_ret_thunk_extern IR Fn Attr to synthetically created
Functions.

https://github.com/llvm/llvm-project/issues/56514

Fixes #56514


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129709

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/attr-function-return.c
  llvm/docs/LangRef.rst
  llvm/lib/IR/Function.cpp


Index: llvm/lib/IR/Function.cpp
===
--- llvm/lib/IR/Function.cpp
+++ llvm/lib/IR/Function.cpp
@@ -354,6 +354,8 @@
 B.addAttribute("frame-pointer", "all");
 break;
   }
+  if (M->getModuleFlag("fn_return_thunk_extern"))
+B.addAttribute(Attribute::FnRetThunkExtern);
   F->addFnAttrs(B);
   return F;
 }
Index: llvm/docs/LangRef.rst
===
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -7367,6 +7367,8 @@
 - "uwtable": **Max**. The value can be 0, 1, or 2. If the value is 1, a 
synthesized
   function will get the ``uwtable(sync)`` function attribute, if the value is 
2,
   a synthesized function will get the ``uwtable(async)`` function attribute.
+- "fn_return_thunk_extern": The synthesized function will get the
+  ``fn_return_thunk_extern`` function attribute.
 
 Objective-C Garbage Collection Module Flags Metadata
 
Index: clang/test/CodeGen/attr-function-return.c
===
--- clang/test/CodeGen/attr-function-return.c
+++ clang/test/CodeGen/attr-function-return.c
@@ -6,6 +6,15 @@
 // RUN: %clang_cc1 -std=gnu2x -triple x86_64-linux-gnu %s -emit-llvm -o - \
 // RUN:  -mfunction-return=thunk-extern | FileCheck %s \
 // RUN:  --check-prefixes=CHECK,CHECK-EXTERN
+// RUN: %clang_cc1 -std=gnu2x -triple x86_64-linux-gnu %s -emit-llvm -o - \
+// RUN:  -mfunction-return=thunk-extern -fprofile-arcs \
+// RUN:   | FileCheck %s --check-prefix=CHECK-GCOV
+// RUN: %clang_cc1 -std=gnu2x -triple x86_64-linux-gnu %s -emit-llvm -o - \
+// RUN:  -mfunction-return=thunk-extern -fsanitize=address \
+// RUN:   | FileCheck %s --check-prefix=CHECK-ASAN
+// RUN: %clang_cc1 -std=gnu2x -triple x86_64-linux-gnu %s -emit-llvm -o - \
+// RUN:  -mfunction-return=thunk-extern -fsanitize=thread \
+// RUN:   | FileCheck %s --check-prefix=CHECK-TSAN
 
 #if !__has_attribute(function_return)
 #error "missing attribute support for function_return"
@@ -91,6 +100,16 @@
 // CHECK-EXTERN: @no_attrs() [[EXTERN]]
 void no_attrs(void) {}
 
+// Test synthetic functions.
+// CHECK-GCOV: @__llvm_gcov_writeout() unnamed_addr [[EXTERNGCOV:#[0-9]+]]
+// CHECK-GCOV: @__llvm_gcov_reset() unnamed_addr [[EXTERNGCOV]]
+// CHECK-GCOV: @__llvm_gcov_init() unnamed_addr [[EXTERNGCOV]]
+// CHECK-ASAN: @asan.module_ctor() [[EXTERNASAN:#[0-9]+]]
+// CHECK-TSAN: @tsan.module_ctor() [[EXTERNTSAN:#[0-9]+]]
+
 // CHECK-NOM-NOT:  [[NOATTR]] = {{.*}}fn_ret_thunk_extern
 // CHECK-KEEP-NOT: [[NOATTR]] = {{.*}}fn_ret_thunk_extern
 // CHECK: [[EXTERN]] = {{.*}}fn_ret_thunk_extern
+// CHECK-GCOV: [[EXTERNGCOV]] = {{.*}}fn_ret_thunk_extern
+// CHECK-ASAN: [[EXTERNASAN]] = {{.*}}fn_ret_thunk_extern
+// CHECK-TSAN: [[EXTERNTSAN]] = {{.*}}fn_ret_thunk_extern
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -756,6 +756,9 @@
   if (CodeGenOpts.IBTSeal)
 getModule().addModuleFlag(llvm::Module::Override, "ibt-seal", 1);
 
+  if (CodeGenOpts.FunctionReturnThunks)
+getModule().addModuleFlag(llvm::Module::Override, 
"fn_return_thunk_extern", 1);
+
   // Add module metadata for return address signing (ignoring
   // non-leaf/all) and stack tagging. These are actually turned on by function
   // attributes, but we use module metadata to emit build attributes. This is


Index: llvm/lib/IR/Function.cpp

[PATCH] D129694: [OPENMP] Make declare target static global externally visible

2022-07-13 Thread Sunil Shrestha via Phabricator via cfe-commits
ssquare08 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:10790
 Flags = OffloadEntriesInfoManagerTy::OMPTargetGlobalVarEntryTo;
-VarName = CGM.getMangledName(VD);
+// We don't need to mangle the host side of declare target global 
variables but we
+// need to create offload entry that matches the device side which gets 
mangled.

jhuber6 wrote:
> It might be easier to just mangle the original definition, that would reduce 
> a lot of churn here adding `origName` everywhere. Any reason that's not 
> desirable?
You are right, it'd have made the code cleaner but we didn't want to mangle the 
host side if we could avoid it.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:10797
+Out< `CGM.printPostfixForExternalizedDecl` should ideally give the same output on 
> the host and device, but it's somewhat limited since it just checks the file 
> ID and environment, which is technically possible to change. The kernels use 
> `getTargetEntryUniqueInfo`, which might make sense to re-use for this case.
That was the point I had raised in one of the Clang meeting but someone had 
mentioned that kernels names are created on the host side and the device side 
reads the information though the Host IR. Seems like kernels name could  also 
run into mismatch issue for some corner cases then?



Comment at: clang/lib/CodeGen/TargetInfo.cpp:7292
 const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule ) const {
+  // Make sure any variable with OpenMP declare target is visible to runtime
+  // except for those with hidden visibility

jhuber6 wrote:
> Formatting looks weird, did you do `git clang-format HEAD~1`?
Looks like I didn't run git clang-format correctly, I'll fix it. Thanks



Comment at: clang/lib/CodeGen/TargetInfo.cpp:9439
 const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule ) const {
+  // Make sure any variable with OpenMP declare target is visible to runtime
+  // except for those with hidden visibility

jhuber6 wrote:
> Just spitballing, is it possible to do this when we make the global instead?
This is something I was wondering as well.  In 
CodeGenModule::GetOrCreateLLVMGlobal, when it creates a new global variable, it 
always uses the llvm::GlobalValue::ExternalLinkage. Seems like this changes 
somewhere later to internal for static globals. Do you know where that would be?



Comment at: clang/test/OpenMP/declare_target_visibility_codegen.cpp:11-12
 // HOST: @z = global i32 0
-// HOST-NOT: @.omp_offloading.entry.c
-// HOST-NOT: @.omp_offloading.entry.x
+// HOST: @.omp_offloading.entry.c__static__{{[0-9a-z]+_[0-9a-z]+}}
+// HOST: @.omp_offloading.entry.x__static__{{[0-9a-z]+_[0-9a-z]+}}
 // HOST-NOT: @.omp_offloading.entry.y

jhuber6 wrote:
> If there are no updates between the host and device we can keep these static 
> without emitting an offloading entry.
That 's a good point. I'll fix that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129694/new/

https://reviews.llvm.org/D129694

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


[PATCH] D128465: [llvm] add zstd to `llvm::compression` namespace

2022-07-13 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added inline comments.
This revision is now accepted and ready to land.



Comment at: llvm/include/llvm/Support/Compression.h:54
+
+void compress(StringRef InputBuffer, SmallVectorImpl ,
+  int Level = DefaultCompression);

I changed the zlib functions to use uint8_t * and ArrayRef instead. 
This patch needs to switch to uint8_t too.



Comment at: llvm/lib/Support/Compression.cpp:155
+bool zstd::isAvailable() { return false; }
+void zstd::compress(StringRef InputBuffer,
+SmallVectorImpl , int Level) {

uint8_t


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128465/new/

https://reviews.llvm.org/D128465

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


[PATCH] D129269: [analyzer] Fix use of length in CStringChecker

2022-07-13 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1d7e58cfade1: [analyzer] Fix use of length in CStringChecker 
(authored by einvbri vince.a.bridg...@ericsson.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129269/new/

https://reviews.llvm.org/D129269

Files:
  clang/docs/analyzer/checkers.rst
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/test/Analysis/string.c


Index: clang/test/Analysis/string.c
===
--- clang/test/Analysis/string.c
+++ clang/test/Analysis/string.c
@@ -1652,3 +1652,18 @@
   __builtin___memset_chk(, 0, sizeof(x), __builtin_object_size(, 0));
   clang_analyzer_eval(x == 0); // expected-warning{{TRUE}}
 }
+
+#ifndef SUPPRESS_OUT_OF_BOUND
+void strcpy_no_overflow_2(char *y) {
+  char x[3];
+  // FIXME: string literal modeling does not account for embedded NULLs.
+  //This case should not elicit a warning, but does.
+  //See discussion at https://reviews.llvm.org/D129269
+  strcpy(x, "12\0"); // expected-warning{{String copy function overflows the 
destination buffer}}
+}
+#else
+void strcpy_no_overflow_2(char *y) {
+  char x[3];
+  strcpy(x, "12\0");
+}
+#endif
Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -848,7 +848,7 @@
 SValBuilder  = C.getSValBuilder();
 QualType sizeTy = svalBuilder.getContext().getSizeType();
 const StringLiteral *strLit = cast(MR)->getStringLiteral();
-return svalBuilder.makeIntVal(strLit->getByteLength(), sizeTy);
+return svalBuilder.makeIntVal(strLit->getLength(), sizeTy);
   }
   case MemRegion::SymbolicRegionKind:
   case MemRegion::AllocaRegionKind:
Index: clang/docs/analyzer/checkers.rst
===
--- clang/docs/analyzer/checkers.rst
+++ clang/docs/analyzer/checkers.rst
@@ -2726,6 +2726,9 @@
 ""
 Check for out-of-bounds access in string functions; applies to:`` strncopy, 
strncat``.
 
+This check also applies to string literals, except there is a known bug in that
+the analyzer cannot detect embedded NULL characters.
+
 .. code-block:: c
 
  void test() {


Index: clang/test/Analysis/string.c
===
--- clang/test/Analysis/string.c
+++ clang/test/Analysis/string.c
@@ -1652,3 +1652,18 @@
   __builtin___memset_chk(, 0, sizeof(x), __builtin_object_size(, 0));
   clang_analyzer_eval(x == 0); // expected-warning{{TRUE}}
 }
+
+#ifndef SUPPRESS_OUT_OF_BOUND
+void strcpy_no_overflow_2(char *y) {
+  char x[3];
+  // FIXME: string literal modeling does not account for embedded NULLs.
+  //This case should not elicit a warning, but does.
+  //See discussion at https://reviews.llvm.org/D129269
+  strcpy(x, "12\0"); // expected-warning{{String copy function overflows the destination buffer}}
+}
+#else
+void strcpy_no_overflow_2(char *y) {
+  char x[3];
+  strcpy(x, "12\0");
+}
+#endif
Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -848,7 +848,7 @@
 SValBuilder  = C.getSValBuilder();
 QualType sizeTy = svalBuilder.getContext().getSizeType();
 const StringLiteral *strLit = cast(MR)->getStringLiteral();
-return svalBuilder.makeIntVal(strLit->getByteLength(), sizeTy);
+return svalBuilder.makeIntVal(strLit->getLength(), sizeTy);
   }
   case MemRegion::SymbolicRegionKind:
   case MemRegion::AllocaRegionKind:
Index: clang/docs/analyzer/checkers.rst
===
--- clang/docs/analyzer/checkers.rst
+++ clang/docs/analyzer/checkers.rst
@@ -2726,6 +2726,9 @@
 ""
 Check for out-of-bounds access in string functions; applies to:`` strncopy, strncat``.
 
+This check also applies to string literals, except there is a known bug in that
+the analyzer cannot detect embedded NULL characters.
+
 .. code-block:: c
 
  void test() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1d7e58c - [analyzer] Fix use of length in CStringChecker

2022-07-13 Thread via cfe-commits

Author: einvbri
Date: 2022-07-13T19:19:23-05:00
New Revision: 1d7e58cfade1dd4236efba59ce969698bb05a039

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

LOG: [analyzer] Fix use of length in CStringChecker

CStringChecker is using getByteLength to get the length of a string
literal. For targets where a "char" is 8-bits, getByteLength() and
getLength() will be equal for a C string, but for targets where a "char"
is 16-bits getByteLength() returns the size in octets.

This is verified in our downstream target, but we have no way to add a
test case for this case since there is no target supporting 16-bit
"char" upstream. Since this cannot have a test case, I'm asserted this
change is "correct by construction", and visually inspected to be
correct by way of the following example where this was found.

The case that shows this fails using a target with 16-bit chars is here.
getByteLength() for the string literal returns 4, which fails when
checked against "char x[4]". With the change, the string literal is
evaluated to a size of 2 which is a correct number of "char"'s for a
16-bit target.

```
void strcpy_no_overflow_2(char *y) {
  char x[4];
  strcpy(x, "12"); // with getByteLength(), returns 4 using 16-bit chars
}
```

This change exposed that embedded nulls within the string are not
handled. This is documented as a FIXME for a future fix.

```
void strcpy_no_overflow_3(char *y) {
  char x[3];
  strcpy(x, "12\0");
}

```

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D129269

Added: 


Modified: 
clang/docs/analyzer/checkers.rst
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
clang/test/Analysis/string.c

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index 6f2486fb49dfc..da53fad14bc57 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2726,6 +2726,9 @@ alpha.unix.cstring.OutOfBounds (C)
 ""
 Check for out-of-bounds access in string functions; applies to:`` strncopy, 
strncat``.
 
+This check also applies to string literals, except there is a known bug in that
+the analyzer cannot detect embedded NULL characters.
+
 .. code-block:: c
 
  void test() {

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index 2e4c8e6436988..987cf65d6fec6 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -848,7 +848,7 @@ SVal CStringChecker::getCStringLength(CheckerContext , 
ProgramStateRef ,
 SValBuilder  = C.getSValBuilder();
 QualType sizeTy = svalBuilder.getContext().getSizeType();
 const StringLiteral *strLit = cast(MR)->getStringLiteral();
-return svalBuilder.makeIntVal(strLit->getByteLength(), sizeTy);
+return svalBuilder.makeIntVal(strLit->getLength(), sizeTy);
   }
   case MemRegion::SymbolicRegionKind:
   case MemRegion::AllocaRegionKind:

diff  --git a/clang/test/Analysis/string.c b/clang/test/Analysis/string.c
index d1fcd92e73270..6bdf59c56f63b 100644
--- a/clang/test/Analysis/string.c
+++ b/clang/test/Analysis/string.c
@@ -1652,3 +1652,18 @@ void test_memset_chk(void) {
   __builtin___memset_chk(, 0, sizeof(x), __builtin_object_size(, 0));
   clang_analyzer_eval(x == 0); // expected-warning{{TRUE}}
 }
+
+#ifndef SUPPRESS_OUT_OF_BOUND
+void strcpy_no_overflow_2(char *y) {
+  char x[3];
+  // FIXME: string literal modeling does not account for embedded NULLs.
+  //This case should not elicit a warning, but does.
+  //See discussion at https://reviews.llvm.org/D129269
+  strcpy(x, "12\0"); // expected-warning{{String copy function overflows the 
destination buffer}}
+}
+#else
+void strcpy_no_overflow_2(char *y) {
+  char x[3];
+  strcpy(x, "12\0");
+}
+#endif



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


[PATCH] D129691: [clang][test] fix typo in fn attr

2022-07-13 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/test/CodeGen/attr-function-return.c:18
 
 // CHECK: @keep2() [[KEEP:#[0-9]+]]
 [[gnu::function_return("keep")]] void keep2(void) {}

probably don't want to reset `KEEP`



Comment at: clang/test/CodeGen/attr-function-return.c:24
 
 // CHECK: @thunk_extern2() [[EXTERN:#[0-9]+]]
 [[gnu::function_return("thunk-extern")]] void thunk_extern2(void) {}

probably don't want to reset `EXTERN`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129691/new/

https://reviews.llvm.org/D129691

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


[PATCH] D129456: [lldb] Add image dump pcm-info command

2022-07-13 Thread Dave Lee via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb5ccfeb6bfbb: [lldb] Add image dump pcm-info command 
(authored by kastiglione).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129456/new/

https://reviews.llvm.org/D129456

Files:
  clang/include/clang/Frontend/FrontendActions.h
  clang/lib/Frontend/FrontendActions.cpp
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/test/API/commands/target/dump-pcm-info/Makefile
  lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py
  lldb/test/API/commands/target/dump-pcm-info/main.m

Index: lldb/test/API/commands/target/dump-pcm-info/main.m
===
--- /dev/null
+++ lldb/test/API/commands/target/dump-pcm-info/main.m
@@ -0,0 +1 @@
+int main() { return 0; }
Index: lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py
===
--- /dev/null
+++ lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py
@@ -0,0 +1,40 @@
+"""
+Test 'target modules dump pcm-info'.
+"""
+
+import os
+import shutil
+import glob
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestCase(TestBase):
+@no_debug_info_test
+@skipUnlessDarwin
+def test(self):
+self.build()
+
+lldbutil.run_to_source_breakpoint(
+self, "return", lldb.SBFileSpec("main.m"))
+
+mod_cache = self.getBuildArtifact("private-module-cache")
+if os.path.isdir(mod_cache):
+shutil.rmtree(mod_cache)
+
+self.runCmd(f"settings set symbols.clang-modules-cache-path '{mod_cache}'")
+
+# Cause lldb to generate a Darwin-*.pcm
+self.runCmd("p @import Darwin")
+
+# root//-.pcm
+pcm_paths = glob.glob(os.path.join(mod_cache, '*', 'Darwin-*.pcm'))
+self.assertEqual(len(pcm_paths), 1, "Expected one Darwin pcm")
+pcm_path = pcm_paths[0]
+
+self.expect(
+f"target modules dump pcm-info '{pcm_path}'",
+startstr=f"Information for module file '{pcm_path}'",
+substrs=["Module name: Darwin"])
Index: lldb/test/API/commands/target/dump-pcm-info/Makefile
===
--- /dev/null
+++ lldb/test/API/commands/target/dump-pcm-info/Makefile
@@ -0,0 +1,4 @@
+OBJC_SOURCES := main.m
+USE_PRIVATE_MODULE_CACHE = YES
+include Makefile.rules
+
Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -47,12 +47,18 @@
 #include "lldb/Target/Thread.h"
 #include "lldb/Target/ThreadSpec.h"
 #include "lldb/Utility/Args.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/State.h"
 #include "lldb/Utility/Timer.h"
 #include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-private-enumerations.h"
 
+#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormatAdapters.h"
@@ -2155,6 +2161,59 @@
   }
 };
 
+class CommandObjectTargetModulesDumpClangPCMInfo : public CommandObjectParsed {
+public:
+  CommandObjectTargetModulesDumpClangPCMInfo(CommandInterpreter )
+  : CommandObjectParsed(
+interpreter, "target modules dump pcm-info",
+"Dump information about the given clang module (pcm).") {
+// Take a single file argument.
+CommandArgumentData arg{eArgTypeFilename, eArgRepeatPlain};
+m_arguments.push_back({arg});
+  }
+
+  ~CommandObjectTargetModulesDumpClangPCMInfo() override = default;
+
+protected:
+  bool DoExecute(Args , CommandReturnObject ) override {
+if (command.GetArgumentCount() != 1) {
+  result.AppendErrorWithFormat("'%s' takes exactly one pcm path argument.",
+   m_cmd_name.c_str());
+  return false;
+}
+
+const char *pcm_path = command.GetArgumentAtIndex(0);
+FileSpec pcm_file{pcm_path};
+
+if (pcm_file.GetFileNameExtension().GetStringRef() != ".pcm") {
+  result.AppendError("file must have a .pcm extension");
+  return false;
+}
+
+if (!FileSystem::Instance().Exists(pcm_file)) {
+  result.AppendError("pcm file does not exist");
+  return false;
+}
+
+clang::CompilerInstance compiler;
+compiler.createDiagnostics();
+
+const char *clang_args[] = {"clang", pcm_path};
+compiler.setInvocation(clang::createInvocation(clang_args));
+
+clang::DumpModuleInfoAction 

[clang] b5ccfeb - [lldb] Add image dump pcm-info command

2022-07-13 Thread Dave Lee via cfe-commits

Author: Dave Lee
Date: 2022-07-13T16:56:53-07:00
New Revision: b5ccfeb6bfbbc5436b91a1e317f88e2c499c9306

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

LOG: [lldb] Add image dump pcm-info command

Add `pcm-info` to the `target module dump` subcommands.

This dump command shows information about clang .pcm files. This command
effectively runs `clang -module-file-info` and produces identical output.

The .pcm file format is tightly coupled to the clang version. The clang
embedded in lldb is not guaranteed to match the version of the clang executable
available on the local system.

There have been times when I've needed to view the details about a .pcm file
produced by lldb's embedded clang, but because the clang executable was a
slightly different version, the `-module-file-info` invocation failed. With
this command, users can inspect .pcm files generated by lldb too.

Differential Revision: https://reviews.llvm.org/D129456

Added: 
lldb/test/API/commands/target/dump-pcm-info/Makefile
lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py
lldb/test/API/commands/target/dump-pcm-info/main.m

Modified: 
clang/include/clang/Frontend/FrontendActions.h
clang/lib/Frontend/FrontendActions.cpp
lldb/source/Commands/CommandObjectTarget.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/FrontendActions.h 
b/clang/include/clang/Frontend/FrontendActions.h
index ae829d741152a..fe399850bd447 100644
--- a/clang/include/clang/Frontend/FrontendActions.h
+++ b/clang/include/clang/Frontend/FrontendActions.h
@@ -190,6 +190,10 @@ class SyntaxOnlyAction : public ASTFrontendAction {
 /// Dump information about the given module file, to be used for
 /// basic debugging and discovery.
 class DumpModuleInfoAction : public ASTFrontendAction {
+public:
+  // Allow other tools (ex lldb) to direct output for their use.
+  llvm::raw_ostream *OutputStream = nullptr;
+
 protected:
   std::unique_ptr CreateASTConsumer(CompilerInstance ,
  StringRef InFile) override;

diff  --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index f61c83a2a465e..f833541caa25c 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -854,8 +854,9 @@ void DumpModuleInfoAction::ExecuteAction() {
 std::error_code EC;
 OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
llvm::sys::fs::OF_TextWithCRLF));
+OutputStream = OutFile.get();
   }
-  llvm::raw_ostream  = OutFile.get()? *OutFile.get() : llvm::outs();
+  llvm::raw_ostream  = OutputStream ? *OutputStream : llvm::outs();
 
   Out << "Information for module file '" << getCurrentFile() << "':\n";
   auto  = getCompilerInstance().getFileManager();

diff  --git a/lldb/source/Commands/CommandObjectTarget.cpp 
b/lldb/source/Commands/CommandObjectTarget.cpp
index 2b71f1bc7bc86..51978878c8b9d 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -47,12 +47,18 @@
 #include "lldb/Target/Thread.h"
 #include "lldb/Target/ThreadSpec.h"
 #include "lldb/Utility/Args.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/State.h"
 #include "lldb/Utility/Timer.h"
 #include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-private-enumerations.h"
 
+#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormatAdapters.h"
@@ -2155,6 +2161,59 @@ class CommandObjectTargetModulesDumpSections
   }
 };
 
+class CommandObjectTargetModulesDumpClangPCMInfo : public CommandObjectParsed {
+public:
+  CommandObjectTargetModulesDumpClangPCMInfo(CommandInterpreter )
+  : CommandObjectParsed(
+interpreter, "target modules dump pcm-info",
+"Dump information about the given clang module (pcm).") {
+// Take a single file argument.
+CommandArgumentData arg{eArgTypeFilename, eArgRepeatPlain};
+m_arguments.push_back({arg});
+  }
+
+  ~CommandObjectTargetModulesDumpClangPCMInfo() override = default;
+
+protected:
+  bool DoExecute(Args , CommandReturnObject ) override {
+if (command.GetArgumentCount() != 1) {
+  result.AppendErrorWithFormat("'%s' takes exactly one pcm path argument.",
+   m_cmd_name.c_str());
+  return false;
+}
+
+const char *pcm_path = command.GetArgumentAtIndex(0);
+FileSpec pcm_file{pcm_path};
+
+if 

[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2022-07-13 Thread Kees Cook via Phabricator via cfe-commits
kees added a comment.

Example of the bug I want to block:

  struct foo {
  int stuff;
  u32 data[0];
  };
  
  struct foo *deserialize(u8 *str, int len)
  {
  struct foo *instance;
  size_t bytes;
  
  bytes = sizeof(*instance) + sizeof(instance->data) * (len / sizeof(u32));
  instance = kmalloc(bytes, GFP_KERNEL);
  if (!instance)
  return NULL;
  memcpy(instance->data, str, len)
  }

This contains a catastrophic 1 character bug (should be 
`sizeof(*instance->data)`) that will only be encountered at runtime when the 
memcpy runs past the end of the the allocation. It could have been caught at 
build-time if the flex-array extensions were disabled; without 
`-fstrict-flex-arrays=3` I have no way to block these (or similar) sneaking 
back into the kernel by way of old (or new) userspace APIs. :( So actually, 
even with `#pragma`, we could still trip over this. Please leave the `=3` mode.

https://godbolt.org/z/dexd3a4Y8


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126864/new/

https://reviews.llvm.org/D126864

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


[PATCH] D129706: [NFCI][clang-tidy] Reimplement GlobList without relying on Regex.

2022-07-13 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 57.
njames93 added a comment.

Fix comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129706/new/

https://reviews.llvm.org/D129706

Files:
  clang-tools-extra/clang-tidy/GlobList.cpp
  clang-tools-extra/clang-tidy/GlobList.h
  clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp
@@ -16,6 +16,13 @@
   EXPECT_FALSE(Filter.contains("aaa"));
 }
 
+TYPED_TEST(GlobListTest, NotEmpty) {
+  TypeParam Filter("*,-");
+
+  EXPECT_FALSE(Filter.contains(""));
+  EXPECT_TRUE(Filter.contains("aaa"));
+}
+
 TYPED_TEST(GlobListTest, Nothing) {
   TypeParam Filter("-*");
 
@@ -57,6 +64,42 @@
   EXPECT_FALSE(Filter.contains(""));
 }
 
+TYPED_TEST(GlobListTest, PreAndPostFixPattern) {
+  TypeParam Filter("a*b");
+
+  EXPECT_TRUE(Filter.contains("ab"));
+  EXPECT_TRUE(Filter.contains("aMiddleb"));
+  EXPECT_FALSE(Filter.contains("aba"));
+  EXPECT_FALSE(Filter.contains("bab"));
+}
+
+TYPED_TEST(GlobListTest, DoubleWildcard) {
+  {
+TypeParam Filter("a**b");
+
+EXPECT_TRUE(Filter.contains("ab"));
+EXPECT_TRUE(Filter.contains("aMiddleb"));
+EXPECT_FALSE(Filter.contains("aba"));
+EXPECT_FALSE(Filter.contains("bab"));
+  }
+  {
+TypeParam Filter("a**");
+
+EXPECT_TRUE(Filter.contains("ab"));
+EXPECT_TRUE(Filter.contains("aMiddleb"));
+EXPECT_TRUE(Filter.contains("aba"));
+EXPECT_FALSE(Filter.contains("bab"));
+  }
+  {
+TypeParam Filter("**b");
+
+EXPECT_TRUE(Filter.contains("ab"));
+EXPECT_TRUE(Filter.contains("aMiddleb"));
+EXPECT_FALSE(Filter.contains("aba"));
+EXPECT_TRUE(Filter.contains("bab"));
+  }
+}
+
 TYPED_TEST(GlobListTest, PatternPriority) {
   // The last glob that matches the string decides whether that string is
   // included or excluded.
@@ -107,6 +150,9 @@
 TYPED_TEST(GlobListTest, NewlineCharactersAsSeparators) {
   TypeParam Filter("a*  \n b,\n-c*,dd");
 
+  // FIXME: Define this behaviour, There are 2 seperator characters next to each
+  // other (,\n), Technically that should be represented as containing an empty
+  // item.
   EXPECT_FALSE(Filter.contains(""));
   EXPECT_TRUE(Filter.contains("aaa"));
   EXPECT_TRUE(Filter.contains("b"));
@@ -117,5 +163,14 @@
   EXPECT_FALSE(Filter.contains("ddd"));
 }
 
+TYPED_TEST(GlobListTest, IgnoreNegativeMatches) {
+  TypeParam Filter("a,-a,b*,-b*,-*", false);
+
+  EXPECT_FALSE(Filter.contains(""));
+  EXPECT_TRUE(Filter.contains("a"));
+  EXPECT_TRUE(Filter.contains("b"));
+  EXPECT_TRUE(Filter.contains("bar"));
+}
+
 } // namespace tidy
 } // namespace clang
Index: clang-tools-extra/clang-tidy/GlobList.h
===
--- clang-tools-extra/clang-tidy/GlobList.h
+++ clang-tools-extra/clang-tidy/GlobList.h
@@ -10,10 +10,10 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H
 
 #include "clang/Basic/LLVM.h"
-#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Regex.h"
+#include 
+#include 
 
 namespace clang {
 namespace tidy {
@@ -25,7 +25,9 @@
 /// them in the order of appearance in the list.
 class GlobList {
 public:
-  virtual ~GlobList() = default;
+  virtual ~GlobList();
+
+  GlobList(const GlobList &) = delete;
 
   /// \p Globs is a comma-separated list of globs (only the '*' metacharacter is
   /// supported) with an optional '-' prefix to denote exclusion.
@@ -41,12 +43,33 @@
   /// matching glob's Positive flag.
   virtual bool contains(StringRef S) const;
 
+  bool isEquivalentTo(const GlobList );
+
 private:
-  struct GlobListItem {
-bool IsPositive;
-llvm::Regex Regex;
+  static constexpr size_t ItemBits = 15;
+  // Pretty arbitrary choice here.
+  static constexpr size_t NumInlineElements = 24;
+  struct GlobStartInfo {
+uint16_t Items : ItemBits;
+uint16_t IsPositive : 1;
+  };
+
+  union DataItem {
+GlobStartInfo StartInfo;
+uint16_t Size;
+  };
+
+  /// Tirst item we encounter is a \c GlobStartInfo object. The next \c
+  /// StartInfo.Items items in here will be a raw uint16_t. After that, if there
+  /// are more items, the next will be another \c GlobStartInfo object.
+  std::vector Data;
+  union {
+char Inline[NumInlineElements];
+char *Ptr;
   };
-  SmallVector Items;
+  size_t RawStringSize : sizeof(size_t) * CHAR_BIT - 1;
+  // The fallback value if we don't match anything.
+  size_t UnmatchedResult : 1;
 };
 
 /// A \p GlobList that caches search results, so that search is performed only
Index: clang-tools-extra/clang-tidy/GlobList.cpp
===
--- clang-tools-extra/clang-tidy/GlobList.cpp
+++ 

[PATCH] D129466: [clang-format][NFC] Replace most of std::vector with SmallVector

2022-07-13 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG36229fa3886b: [clang-format][NFC] Replace most of 
std::vector with SmallVector (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129466/new/

https://reviews.llvm.org/D129466

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/ContinuationIndenter.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.cpp
  clang/lib/Format/Macros.h
  clang/lib/Format/UnwrappedLineFormatter.cpp


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1132,7 +1132,7 @@
   typedef std::pair QueueItem;
 
   /// The BFS queue type.
-  typedef std::priority_queue,
+  typedef std::priority_queue,
   std::greater>
   QueueType;
 
Index: clang/lib/Format/Macros.h
===
--- clang/lib/Format/Macros.h
+++ clang/lib/Format/Macros.h
@@ -128,7 +128,7 @@
   const FormatStyle 
   llvm::SpecificBumpPtrAllocator 
   IdentifierTable 
-  std::vector> Buffers;
+  SmallVector> Buffers;
   llvm::StringMap Definitions;
 };
 
Index: clang/lib/Format/FormatToken.cpp
===
--- clang/lib/Format/FormatToken.cpp
+++ clang/lib/Format/FormatToken.cpp
@@ -264,7 +264,7 @@
   // We can never place more than ColumnLimit / 3 items in a row (because of 
the
   // spaces and the comma).
   unsigned MaxItems = Style.ColumnLimit / 3;
-  std::vector MinSizeInColumn;
+  SmallVector MinSizeInColumn;
   MinSizeInColumn.reserve(MaxItems);
   for (unsigned Columns = 1; Columns <= MaxItems; ++Columns) {
 ColumnFormat Format;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2386,7 +2386,7 @@
 
   tooling::Replacements generateFixes() {
 tooling::Replacements Fixes;
-std::vector Tokens;
+SmallVector Tokens;
 std::copy(DeletedTokens.begin(), DeletedTokens.end(),
   std::back_inserter(Tokens));
 
@@ -2580,7 +2580,7 @@
   StringRef Identifier;
   StringRef Text;
   unsigned Offset;
-  std::vector AssociatedCommentLines;
+  SmallVector AssociatedCommentLines;
   bool IsStatic;
 };
 
@@ -2983,7 +2983,7 @@
   llvm::Regex ImportRegex(JavaImportRegexPattern);
   SmallVector Matches;
   SmallVector ImportsInBlock;
-  std::vector AssociatedCommentLines;
+  SmallVector AssociatedCommentLines;
 
   bool FormattingOff = false;
 
Index: clang/lib/Format/ContinuationIndenter.h
===
--- clang/lib/Format/ContinuationIndenter.h
+++ clang/lib/Format/ContinuationIndenter.h
@@ -434,7 +434,7 @@
 
   /// A stack keeping track of properties applying to parenthesis
   /// levels.
-  std::vector Stack;
+  SmallVector Stack;
 
   /// Ignore the stack of \c ParenStates for state comparison.
   ///
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -37,7 +37,7 @@
 // Returns the length of everything up to the first possible line break after
 // the ), ], } or > matching \c Tok.
 static unsigned getLengthToMatchingParen(const FormatToken ,
- const std::vector ) 
{
+ const SmallVector ) 
{
   // Normally whether or not a break before T is possible is calculated and
   // stored in T.CanBreakBefore. Braces, array initializers and text proto
   // messages like `key: < ... >` are an exception: a break is possible


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1132,7 +1132,7 @@
   typedef std::pair QueueItem;
 
   /// The BFS queue type.
-  typedef std::priority_queue,
+  typedef std::priority_queue,
   std::greater>
   QueueType;
 
Index: clang/lib/Format/Macros.h
===
--- clang/lib/Format/Macros.h
+++ clang/lib/Format/Macros.h
@@ -128,7 +128,7 @@
   const FormatStyle 
   llvm::SpecificBumpPtrAllocator 
   IdentifierTable 
-  std::vector> Buffers;
+  SmallVector> Buffers;
   llvm::StringMap Definitions;
 };
 
Index: clang/lib/Format/FormatToken.cpp
===
--- clang/lib/Format/FormatToken.cpp
+++ clang/lib/Format/FormatToken.cpp
@@ -264,7 +264,7 @@
   // We can never place more than ColumnLimit / 3 items in a row (because of the
   

[clang] 36229fa - [clang-format][NFC] Replace most of std::vector with SmallVector

2022-07-13 Thread via cfe-commits

Author: owenca
Date: 2022-07-13T16:45:22-07:00
New Revision: 36229fa3886be7d3c864642fad021c9fe4afda38

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

LOG: [clang-format][NFC] Replace most of std::vector with SmallVector

Differential Revision: https://reviews.llvm.org/D129466

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/ContinuationIndenter.h
clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.cpp
clang/lib/Format/Macros.h
clang/lib/Format/UnwrappedLineFormatter.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index e957852ba9859..1cd28ab073da4 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -37,7 +37,7 @@ static bool shouldIndentWrappedSelectorName(const FormatStyle 
,
 // Returns the length of everything up to the first possible line break after
 // the ), ], } or > matching \c Tok.
 static unsigned getLengthToMatchingParen(const FormatToken ,
- const std::vector ) 
{
+ const SmallVector ) 
{
   // Normally whether or not a break before T is possible is calculated and
   // stored in T.CanBreakBefore. Braces, array initializers and text proto
   // messages like `key: < ... >` are an exception: a break is possible

diff  --git a/clang/lib/Format/ContinuationIndenter.h 
b/clang/lib/Format/ContinuationIndenter.h
index 494a9727d5edc..620060e688614 100644
--- a/clang/lib/Format/ContinuationIndenter.h
+++ b/clang/lib/Format/ContinuationIndenter.h
@@ -434,7 +434,7 @@ struct LineState {
 
   /// A stack keeping track of properties applying to parenthesis
   /// levels.
-  std::vector Stack;
+  SmallVector Stack;
 
   /// Ignore the stack of \c ParenStates for state comparison.
   ///

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 9ce75b66bdc93..d13907faca43f 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -2386,7 +2386,7 @@ class Cleaner : public TokenAnalyzer {
 
   tooling::Replacements generateFixes() {
 tooling::Replacements Fixes;
-std::vector Tokens;
+SmallVector Tokens;
 std::copy(DeletedTokens.begin(), DeletedTokens.end(),
   std::back_inserter(Tokens));
 
@@ -2580,7 +2580,7 @@ struct JavaImportDirective {
   StringRef Identifier;
   StringRef Text;
   unsigned Offset;
-  std::vector AssociatedCommentLines;
+  SmallVector AssociatedCommentLines;
   bool IsStatic;
 };
 
@@ -2983,7 +2983,7 @@ tooling::Replacements sortJavaImports(const FormatStyle 
, StringRef Code,
   llvm::Regex ImportRegex(JavaImportRegexPattern);
   SmallVector Matches;
   SmallVector ImportsInBlock;
-  std::vector AssociatedCommentLines;
+  SmallVector AssociatedCommentLines;
 
   bool FormattingOff = false;
 

diff  --git a/clang/lib/Format/FormatToken.cpp 
b/clang/lib/Format/FormatToken.cpp
index 2c0fee6975c2b..832af463206c8 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -264,7 +264,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const 
FormatToken *Token) {
   // We can never place more than ColumnLimit / 3 items in a row (because of 
the
   // spaces and the comma).
   unsigned MaxItems = Style.ColumnLimit / 3;
-  std::vector MinSizeInColumn;
+  SmallVector MinSizeInColumn;
   MinSizeInColumn.reserve(MaxItems);
   for (unsigned Columns = 1; Columns <= MaxItems; ++Columns) {
 ColumnFormat Format;

diff  --git a/clang/lib/Format/Macros.h b/clang/lib/Format/Macros.h
index ded792c628701..b26799c20f8c4 100644
--- a/clang/lib/Format/Macros.h
+++ b/clang/lib/Format/Macros.h
@@ -128,7 +128,7 @@ class MacroExpander {
   const FormatStyle 
   llvm::SpecificBumpPtrAllocator 
   IdentifierTable 
-  std::vector> Buffers;
+  SmallVector> Buffers;
   llvm::StringMap Definitions;
 };
 

diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 55a97addb3b1d..abeb93d237767 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1132,7 +1132,7 @@ class OptimizingLineFormatter : public LineFormatter {
   typedef std::pair QueueItem;
 
   /// The BFS queue type.
-  typedef std::priority_queue,
+  typedef std::priority_queue,
   std::greater>
   QueueType;
 



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


[PATCH] D129706: [NFCI][clang-tidy] Reimplement GlobList without relying on Regex.

2022-07-13 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: alexfh, aaron.ballman.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a project: All.
njames93 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Regex is a little cumbersome for the limited syntax GlobList supports and its 
implementation is a bit of a hack.
This implementation supports exactly what we require and nothing more.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129706

Files:
  clang-tools-extra/clang-tidy/GlobList.cpp
  clang-tools-extra/clang-tidy/GlobList.h
  clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp
@@ -16,6 +16,13 @@
   EXPECT_FALSE(Filter.contains("aaa"));
 }
 
+TYPED_TEST(GlobListTest, NotEmpty) {
+  TypeParam Filter("*,-");
+
+  EXPECT_FALSE(Filter.contains(""));
+  EXPECT_TRUE(Filter.contains("aaa"));
+}
+
 TYPED_TEST(GlobListTest, Nothing) {
   TypeParam Filter("-*");
 
@@ -57,6 +64,42 @@
   EXPECT_FALSE(Filter.contains(""));
 }
 
+TYPED_TEST(GlobListTest, PreAndPostFixPattern) {
+  TypeParam Filter("a*b");
+
+  EXPECT_TRUE(Filter.contains("ab"));
+  EXPECT_TRUE(Filter.contains("aMiddleb"));
+  EXPECT_FALSE(Filter.contains("aba"));
+  EXPECT_FALSE(Filter.contains("bab"));
+}
+
+TYPED_TEST(GlobListTest, DoubleWildcard) {
+  {
+TypeParam Filter("a**b");
+
+EXPECT_TRUE(Filter.contains("ab"));
+EXPECT_TRUE(Filter.contains("aMiddleb"));
+EXPECT_FALSE(Filter.contains("aba"));
+EXPECT_FALSE(Filter.contains("bab"));
+  }
+  {
+TypeParam Filter("a**");
+
+EXPECT_TRUE(Filter.contains("ab"));
+EXPECT_TRUE(Filter.contains("aMiddleb"));
+EXPECT_TRUE(Filter.contains("aba"));
+EXPECT_FALSE(Filter.contains("bab"));
+  }
+  {
+TypeParam Filter("**b");
+
+EXPECT_TRUE(Filter.contains("ab"));
+EXPECT_TRUE(Filter.contains("aMiddleb"));
+EXPECT_FALSE(Filter.contains("aba"));
+EXPECT_TRUE(Filter.contains("bab"));
+  }
+}
+
 TYPED_TEST(GlobListTest, PatternPriority) {
   // The last glob that matches the string decides whether that string is
   // included or excluded.
@@ -107,6 +150,9 @@
 TYPED_TEST(GlobListTest, NewlineCharactersAsSeparators) {
   TypeParam Filter("a*  \n b,\n-c*,dd");
 
+  // FIXME: Define this behaviour, There are 2 seperator characters next to each
+  // other (,\n), Technically that should be represented as containing an empty
+  // item.
   EXPECT_FALSE(Filter.contains(""));
   EXPECT_TRUE(Filter.contains("aaa"));
   EXPECT_TRUE(Filter.contains("b"));
@@ -117,5 +163,14 @@
   EXPECT_FALSE(Filter.contains("ddd"));
 }
 
+TYPED_TEST(GlobListTest, IgnoreNegativeMatches) {
+  TypeParam Filter("a,-a,b*,-b*,-*", false);
+
+  EXPECT_FALSE(Filter.contains(""));
+  EXPECT_TRUE(Filter.contains("a"));
+  EXPECT_TRUE(Filter.contains("b"));
+  EXPECT_TRUE(Filter.contains("bar"));
+}
+
 } // namespace tidy
 } // namespace clang
Index: clang-tools-extra/clang-tidy/GlobList.h
===
--- clang-tools-extra/clang-tidy/GlobList.h
+++ clang-tools-extra/clang-tidy/GlobList.h
@@ -10,10 +10,10 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H
 
 #include "clang/Basic/LLVM.h"
-#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Regex.h"
+#include 
+#include 
 
 namespace clang {
 namespace tidy {
@@ -25,7 +25,9 @@
 /// them in the order of appearance in the list.
 class GlobList {
 public:
-  virtual ~GlobList() = default;
+  virtual ~GlobList();
+
+  GlobList(const GlobList &) = delete;
 
   /// \p Globs is a comma-separated list of globs (only the '*' metacharacter is
   /// supported) with an optional '-' prefix to denote exclusion.
@@ -41,12 +43,32 @@
   /// matching glob's Positive flag.
   virtual bool contains(StringRef S) const;
 
+  bool isEquivalentTo(const GlobList );
+
 private:
-  struct GlobListItem {
-bool IsPositive;
-llvm::Regex Regex;
+  static constexpr size_t ItemBits = 15;
+  // Pretty arbitrary choice here, but should
+  static constexpr size_t NumInlineElements = 24;
+  struct GlobStartInfo {
+uint16_t Items : ItemBits;
+uint16_t IsPositive : 1;
+  };
+  union DataItem {
+GlobStartInfo StartInfo;
+uint16_t Size;
+  };
+  /// We traverse this vector backwards, and the first item we encounter is a \c
+  /// GlobStart object. The next \c GlobStart.Items items in here will be a raw
+  /// uint16_t. After that, if there are more items, the next will be another \c
+  /// GlobStart object.
+  std::vector Data;
+  union {
+char Inline[NumInlineElements];
+char *Ptr;
   };
-  SmallVector Items;
+  size_t RawStringSize : sizeof(size_t) * 

[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2022-07-13 Thread Kees Cook via Phabricator via cfe-commits
kees added a comment.

In D126864#3646854 , @jyknight wrote:

> In D126864#3645994 , @kees wrote:
>
>> I should clarify: I still need the =3 mode. Since sizeof([0]) == 0 and 
>> sizeof([]) == error, they are being treated differently already by the 
>> compiler causing bugs in Linux. The kernel must still have a way to reject 
>> the _use_ of a [0] array. We cannot reject _declaration_ of them due to 
>> userspace API.
>
> Looks like the linux kernel is currently chock-full of zero-length-arrays 
> which are actually intended/required to work as flexible array members. Do 
> you have a pending patch to convert all of them to [] which should be?

Well, yes and no. It's been a multi-year on-going effort. Though it's actually 
complete for the kernel now as of v5.18:
https://github.com/KSPP/linux/issues/78

What remains is the userspace headers. The _real_ pain has been the 1-element 
arrays. Ugh. The master bug is here:
https://github.com/KSPP/linux/issues/21

> If you're saying you absolutely need this mode -- which I still believe would 
> be nonsensical to provide -- I'd like to see the set of concrete examples you 
> cannot otherwise deal with.

I have several goals. The most important is making all the fixed-sized trailing 
arrays are NOT treated as flexible arrays so that `__builtin_object_size` will 
work as expected for Linux's FORTIFY implementation and 
`-fstrict-flex-arrays=2` certainly solves that. However, then we're left with 
all the 0-element arrays, which need to be cleaned up because they don't behave 
the same as true flexible arrays. For example, with `sizeof`; the kernel has 
dealt with allocation size bugs relating to `sizeof` being used against 
0-element arrays (which _should_ have caused a build failure if it were a true 
flexible array and the bug would have been immediately found), and I would like 
to make sure those can never happen again.

If this were any other code base, I could just use `-Wzero-length-array`, but 
the scattered ancient userspace APIs need to live on until $forever.

And if this were any other code base, I could use `#pragma`, but it's frown on 
in general, and is going to be met with even greater resistance in userspace 
API headers, especially given that it will need to be `#ifdef`ed for clang vs 
gcc, and then tweaked again once GCC gains the option, which would then need to 
be version checked. (This is why `#pragma` is strongly discouraged: Linux has a 
whole system for doing compiler behavior detection for its internal headers and 
build system, but such things don't exist for the userspace headers.)

So given the behavioral differences that already existed between true flexible 
arrays and 0-element arrays, I'd wanted to have a way to turn off _all_ the 
flexible array "extensions". I never wanted these different levels for 
`-fstrict-flex-arrays`. :) I want the complete disabling of all the extensions 
that were creating inconsistent behaviors. But to lose the ability to disable 
the 0-is-flexible would be disappointing, but if I absolutely have no choice, I 
can live with it. Given Linux will be the first user of this option, and the 
reason for this option being created, I'd _much_ rather have it doing what's 
needed, though. :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126864/new/

https://reviews.llvm.org/D126864

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


[PATCH] D129398: [ASTMatchers] Add a new matcher for callee declarations of Obj-C message expressions

2022-07-13 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 updated this revision to Diff 49.
ziqingluo-90 added a comment.

Added a test to `unittests/ASTMatchers/Dynamic/RegistryTest.cpp` and confirms 
that the overloaded `callee` still works with dynamic matchers


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129398/new/

https://reviews.llvm.org/D129398

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp

Index: clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
===
--- clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
+++ clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
@@ -198,13 +198,32 @@
constructMatcher("hasName", StringRef("x")
   .getTypedMatcher();
 
+  Matcher ObjCMsgExpr =
+  constructMatcher(
+  "objcMessageExpr",
+  constructMatcher(
+  "callee",
+  constructMatcher("objcMethodDecl",
+   constructMatcher("hasName", StringRef("x")
+  .getTypedMatcher();
+
   std::string Code = "class Y { public: void x(); }; void z() { Y y; y.x(); }";
   EXPECT_FALSE(matches(Code, CallExpr0));
   EXPECT_TRUE(matches(Code, CallExpr1));
+  EXPECT_FALSE(matches(Code, ObjCMsgExpr));
 
   Code = "class Z { public: void z() { this->z(); } };";
   EXPECT_TRUE(matches(Code, CallExpr0));
   EXPECT_FALSE(matches(Code, CallExpr1));
+  EXPECT_FALSE(matches(Code, ObjCMsgExpr));
+
+  Code = "@interface I "
+ "+ (void)x; "
+ "@end\n"
+ "int main() { [I x]; }";
+  EXPECT_FALSE(matchesObjC(Code, CallExpr0));
+  EXPECT_FALSE(matchesObjC(Code, CallExpr1));
+  EXPECT_TRUE(matchesObjC(Code, ObjCMsgExpr));
 
   Matcher DeclDecl = declaratorDecl(hasTypeLoc(
   constructMatcher(
Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2307,6 +2307,45 @@
   hasName("cc"), hasInitializer(integerLiteral(equals(1));
 }
 
+TEST(ASTMatchersTestObjC, ObjCMessageCalees) {
+  StatementMatcher MessagingFoo =
+  objcMessageExpr(callee(objcMethodDecl(hasName("foo";
+
+  EXPECT_TRUE(matchesObjC("@interface I"
+  "+ (void)foo;"
+  "@end\n"
+  "int main() {"
+  "  [I foo];"
+  "}",
+  MessagingFoo));
+  EXPECT_TRUE(notMatchesObjC("@interface I"
+ "+ (void)foo;"
+ "+ (void)bar;"
+ "@end\n"
+ "int main() {"
+ "  [I bar];"
+ "}",
+ MessagingFoo));
+  EXPECT_TRUE(matchesObjC("@interface I"
+  "- (void)foo;"
+  "- (void)bar;"
+  "@end\n"
+  "int main() {"
+  "  I *i;"
+  "  [i foo];"
+  "}",
+  MessagingFoo));
+  EXPECT_TRUE(notMatchesObjC("@interface I"
+ "- (void)foo;"
+ "- (void)bar;"
+ "@end\n"
+ "int main() {"
+ "  I *i;"
+ "  [i bar];"
+ "}",
+ MessagingFoo));
+}
+
 TEST(ASTMatchersTestObjC, ObjCMessageExpr) {
   // Don't find ObjCMessageExpr where none are present.
   EXPECT_TRUE(notMatchesObjC("", objcMessageExpr(anything(;
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3838,8 +3838,9 @@
   InnerMatcher.matches(*ExprNode, Finder, Builder));
 }
 
-/// Matches if the call expression's callee's declaration matches the
-/// given matcher.
+/// Matches 1) if the call expression's callee's declaration matches the
+/// given matcher; or 2) if the Obj-C message expression's callee's method
+/// declaration matches the given matcher.
 ///
 /// Example matches y.x() (matcher = callExpr(callee(
 ///cxxMethodDecl(hasName("x")
@@ -3847,9 +3848,31 @@
 ///   class Y { public: void x(); };
 ///   void z() { Y y; y.x(); }
 /// \endcode
-AST_MATCHER_P_OVERLOAD(CallExpr, callee, internal::Matcher, InnerMatcher,
-   1) {
-  return callExpr(hasDeclaration(InnerMatcher)).matches(Node, Finder, Builder);
+///
+/// Example 2. Matches [I 

[clang-tools-extra] e690137 - [Support] Change compression::zlib::{compress,uncompress} to use uint8_t *

2022-07-13 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-07-13T16:26:54-07:00
New Revision: e690137dde1c9b037e0c987d393da054d86eeeab

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

LOG: [Support] Change compression::zlib::{compress,uncompress} to use uint8_t *

It's more natural to use uint8_t * (std::byte needs C++17 and llvm has
too much uint8_t *) and most callers use uint8_t * instead of char *.
The functions are recently moved into `llvm::compression::zlib::`, so
downstream projects need to make adaption anyway.

Added: 


Modified: 
clang-tools-extra/clangd/index/Serialization.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
lld/ELF/InputSection.cpp
lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
llvm/include/llvm/Object/Decompressor.h
llvm/include/llvm/Support/Compression.h
llvm/lib/MC/ELFObjectWriter.cpp
llvm/lib/ObjCopy/ELF/ELFObject.cpp
llvm/lib/ObjCopy/ELF/ELFObject.h
llvm/lib/Object/Decompressor.cpp
llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
llvm/lib/ProfileData/InstrProf.cpp
llvm/lib/ProfileData/SampleProfReader.cpp
llvm/lib/ProfileData/SampleProfWriter.cpp
llvm/lib/Support/Compression.cpp
llvm/unittests/Support/CompressionTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/Serialization.cpp 
b/clang-tools-extra/clangd/index/Serialization.cpp
index ee86ed5714ec..9fc1567ad919 100644
--- a/clang-tools-extra/clangd/index/Serialization.cpp
+++ b/clang-tools-extra/clangd/index/Serialization.cpp
@@ -191,10 +191,11 @@ class StringTableOut {
   RawTable.push_back(0);
 }
 if (llvm::compression::zlib::isAvailable()) {
-  llvm::SmallString<1> Compressed;
-  llvm::compression::zlib::compress(RawTable, Compressed);
+  llvm::SmallVector Compressed;
+  llvm::compression::zlib::compress(llvm::arrayRefFromStringRef(RawTable),
+Compressed);
   write32(RawTable.size(), OS);
-  OS << Compressed;
+  OS << llvm::toStringRef(Compressed);
 } else {
   write32(0, OS); // No compression.
   OS << RawTable;
@@ -220,7 +221,7 @@ llvm::Expected 
readStringTable(llvm::StringRef Data) {
 return error("Truncated string table");
 
   llvm::StringRef Uncompressed;
-  llvm::SmallString<1> UncompressedStorage;
+  llvm::SmallVector UncompressedStorage;
   if (UncompressedSize == 0) // No compression
 Uncompressed = R.rest();
   else if (llvm::compression::zlib::isAvailable()) {
@@ -234,9 +235,10 @@ llvm::Expected 
readStringTable(llvm::StringRef Data) {
R.rest().size(), UncompressedSize);
 
 if (llvm::Error E = llvm::compression::zlib::uncompress(
-R.rest(), UncompressedStorage, UncompressedSize))
+llvm::arrayRefFromStringRef(R.rest()), UncompressedStorage,
+UncompressedSize))
   return std::move(E);
-Uncompressed = UncompressedStorage;
+Uncompressed = toStringRef(UncompressedStorage);
   } else
 return error("Compressed string table, but zlib is unavailable");
 

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index bb98660717e7..04ade0a3b9d0 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -1466,14 +1466,15 @@ bool ASTReader::ReadSLocEntry(int ID) {
 Error("zlib is not available");
 return nullptr;
   }
-  SmallString<0> Uncompressed;
+  SmallVector Uncompressed;
   if (llvm::Error E = llvm::compression::zlib::uncompress(
-  Blob, Uncompressed, Record[0])) {
+  llvm::arrayRefFromStringRef(Blob), Uncompressed, Record[0])) {
 Error("could not decompress embedded file contents: " +
   llvm::toString(std::move(E)));
 return nullptr;
   }
-  return llvm::MemoryBuffer::getMemBufferCopy(Uncompressed, Name);
+  return llvm::MemoryBuffer::getMemBufferCopy(
+  llvm::toStringRef(Uncompressed), Name);
 } else if (RecCode == SM_SLOC_BUFFER_BLOB) {
   return llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), Name, true);
 } else {

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 678105360431..fac8fc141d2c 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -2000,12 +2000,13 @@ static void emitBlob(llvm::BitstreamWriter , 
StringRef Blob,
 
   // Compress the buffer if possible. We expect that almost all PCM
   // consumers will not want its contents.
-  SmallString<0> CompressedBuffer;
+  SmallVector CompressedBuffer;
   if (llvm::compression::zlib::isAvailable()) {
-

[PATCH] D112374: [clang] Implement ElaboratedType sugaring for types written bare

2022-07-13 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D112374#3648624 , @JDevlieghere 
wrote:

> This breaks all the LLDB tests that import the std module:
>
> Given that the bot has been red for 14 hours I went ahead and reverted this 
> change. Please keep an eye on this bot when relanding.

OK, this seems like the simple breakage where the test expected the type to be 
printed fully qualified, just because it was written without any qualifications.

I am not sure what lldb really wants here.
I think usually the two sane choices you want are:

1. Always print the type as written, which this patch makes it easier and 
consistent.
2. Always print the types fully qualified as if ignoring the existence of 
ElaboratedType nodes, which the type printer never really supported, but you 
would usually get this effect usually if the type was canonicalized, as that 
would remove all sugar.

So if lldb wants 1), that's great this patch fixes a bug in lldb and we just 
need to change the test expectation.
If it wants 2, then we just exposed a bug in lldb, because this would never 
have worked consistently. If libc++ devs had written any name qualifiers in 
that size_type typedef, then the type printer would suddenly switch to printing 
the type as-written.

As a side note, it's unfortunate that this test is not supported on Windows, as 
that is what I primarily develop clang on. In fact, the lldb test suite is 
poorly supported there, as running the whole thing says half the tests are 
unsupported, and creates an unholly mess on my desktop with a bunch of frozen 
terminal windows created!

@JDevlieghere can you identify what lldb wants here, 1, 2 or some other option 
I missed? Or otherwise subscribe someone who can?

In D112374#3649525 , @kimgr wrote:

> This patch also broke IWYU, not exactly sure how or why yet. We run around 
> the AST quite a bit, so structural changes like this often bite us.
>
> Can you expand on what happened here? Before/after kind-of thing? Thanks!

Thanks for the report!

So this patch makes (name-qualifiable) types that come from the parser 
consistently carry an ElaboratedType node, which otherwise would be absent when 
the type represents some parsed entity which was written without any name 
qualifiers.

So if you take a look at the many fixes around in this patch, and without any 
further idea from what is going on at IWYU, then the churn this patch causes is 
usually:

1. What I explained to @JDevlieghere above, a change in how the type printer 
prints a type.
2. Exposed a bug in some AST matcher. Matching types is harder to get right 
when there is sugar involved. For example, if you want to match a type against 
being a pointer to some type `A`, then you have to account for getting a type 
that is sugar for a pointer to A, or being a pointer to sugar to A, or both! 
Usually you would get the second part wrong, and this would work for a very 
simple test where you don't use any name qualifiers when you write `A`, but you 
would discover is broken when someone reports that it doesn't work when you do. 
The usual fix is to either use the matcher which strips sugar, which is 
annoying to use as for example if you match an N level pointer, you have to put 
N+1 such matchers in there, beginning to end and between all those levels. But 
in a lot of cases, if the property you want to match is present in the 
canonical type, it's easier and faster to just match on that...
3. Exposed a bug in how you get the source range of some TypeLoc. For some 
reason, a lot of code is using `getLocalSourceRange()`, which only looks at the 
given TypeLoc node. This patch introduces a new, and more common TypeLoc node 
which contains no source locations on itself. This is not new and some other, 
more rare TypeLoc nodes could also have this property, but if you use 
getLocalSourceRange on them, it's not going to return any valid locations, 
because it doesn't have any. The right fix here is to always use 
`getSourceRange()` or `getBeginLoc`/`getEndLoc` which will dive into the inner 
TypeLoc to get the source range if it doesn't find it on the top level one. You 
can use `getLocalSourceRange` if you are really into micro-optimizations and 
you have some outside knowledge that the TypeLocs you are dealing with will 
always include some source location.
4. Exposed a bug somewhere in the use of the normal clang type class API, where 
you have some type, you want to see if that type is some particular kind, you 
try a `dyn_cast` such as `dyn_cast` and that fails because now you 
have an ElaboratedType which has a TypeDefType inside of it, which is what you 
wanted to match. Again, like 2 this would usually have been tested poorly with 
some simple tests with no qualifications, and would have been broken had there 
been any other kind of sugar to what you wanted at all, be it an ElaboratedType 
or a TemplateSpecializationType or a 

[PATCH] D129700: [clang] Don't emit type tests for dllexport/import classes

2022-07-13 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks created this revision.
aeubanks added reviewers: pcc, tejohnson.
Herald added subscribers: ormris, steven_wu, hiraditya.
Herald added a project: All.
aeubanks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

According to https://clang.llvm.org/docs/LTOVisibility.html, classes on
Windows with dllimport/export receive public LTO visibility and
therefore should not participate in WPD.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129700

Files:
  clang/lib/CodeGen/CGVTables.cpp
  clang/test/CodeGenCXX/lto-visibility-inference.cpp


Index: clang/test/CodeGenCXX/lto-visibility-inference.cpp
===
--- clang/test/CodeGenCXX/lto-visibility-inference.cpp
+++ clang/test/CodeGenCXX/lto-visibility-inference.cpp
@@ -74,10 +74,10 @@
   // MS: type.test{{.*}}!"?AUC2@@"
   c2->f();
   // ITANIUM: type.test{{.*}}!"_ZTS2C3"
-  // MS: type.test{{.*}}!"?AUC3@@"
+  // MS-NOT: type.test{{.*}}!"?AUC3@@"
   c3->f();
   // ITANIUM: type.test{{.*}}!"_ZTS2C4"
-  // MS: type.test{{.*}}!"?AUC4@@"
+  // MS-NOT: type.test{{.*}}!"?AUC4@@"
   c4->f();
   // ITANIUM-NOT: type.test{{.*}}!"_ZTS2C5"
   // MS-NOT: type.test{{.*}}!"?AUC5@@"
Index: clang/lib/CodeGen/CGVTables.cpp
===
--- clang/lib/CodeGen/CGVTables.cpp
+++ clang/lib/CodeGen/CGVTables.cpp
@@ -1176,7 +1176,8 @@
 }
 
 bool CodeGenModule::AlwaysHasLTOVisibilityPublic(const CXXRecordDecl *RD) {
-  if (RD->hasAttr() || RD->hasAttr())
+  if (RD->hasAttr() || RD->hasAttr() ||
+  RD->hasAttr() || RD->hasAttr())
 return true;
 
   if (!getCodeGenOpts().LTOVisibilityPublicStd)


Index: clang/test/CodeGenCXX/lto-visibility-inference.cpp
===
--- clang/test/CodeGenCXX/lto-visibility-inference.cpp
+++ clang/test/CodeGenCXX/lto-visibility-inference.cpp
@@ -74,10 +74,10 @@
   // MS: type.test{{.*}}!"?AUC2@@"
   c2->f();
   // ITANIUM: type.test{{.*}}!"_ZTS2C3"
-  // MS: type.test{{.*}}!"?AUC3@@"
+  // MS-NOT: type.test{{.*}}!"?AUC3@@"
   c3->f();
   // ITANIUM: type.test{{.*}}!"_ZTS2C4"
-  // MS: type.test{{.*}}!"?AUC4@@"
+  // MS-NOT: type.test{{.*}}!"?AUC4@@"
   c4->f();
   // ITANIUM-NOT: type.test{{.*}}!"_ZTS2C5"
   // MS-NOT: type.test{{.*}}!"?AUC5@@"
Index: clang/lib/CodeGen/CGVTables.cpp
===
--- clang/lib/CodeGen/CGVTables.cpp
+++ clang/lib/CodeGen/CGVTables.cpp
@@ -1176,7 +1176,8 @@
 }
 
 bool CodeGenModule::AlwaysHasLTOVisibilityPublic(const CXXRecordDecl *RD) {
-  if (RD->hasAttr() || RD->hasAttr())
+  if (RD->hasAttr() || RD->hasAttr() ||
+  RD->hasAttr() || RD->hasAttr())
 return true;
 
   if (!getCodeGenOpts().LTOVisibilityPublicStd)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109701: [clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface

2022-07-13 Thread Abraham Corea Diaz via Phabricator via cfe-commits
abrahamcd added a comment.

In D109701#3648168 , @vaibhav.y wrote:

> In D109701#3646856 , @abrahamcd 
> wrote:
>
>> Hi! I'm interning with @cjdb and @denik this summer and I was working on 
>> adding a `-fdiagnostics-format=sarif` option to start off my project, but I 
>> just found that a previous abandoned version of this change (D109697 
>> ) was intending to add it. Seeing as the 
>> flag is no longer included in this version of the change, is it okay for me 
>> to go on and add it myself, or are you still planning on adding it here? 
>> Thanks!
>
> Sure, feel free to use D109697  as you see 
> fit!

Great, thank you!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109701/new/

https://reviews.llvm.org/D109701

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


[PATCH] D128465: [llvm] add zstd to `llvm::compression` namespace

2022-07-13 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 32.
ckissane added a comment.

- Merge branch main


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128465/new/

https://reviews.llvm.org/D128465

Files:
  llvm/CMakeLists.txt
  llvm/cmake/config-ix.cmake
  llvm/cmake/modules/FindZSTD.cmake
  llvm/cmake/modules/LLVMConfig.cmake.in
  llvm/include/llvm/Config/llvm-config.h.cmake
  llvm/include/llvm/Support/Compression.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/Compression.cpp
  llvm/test/lit.site.cfg.py.in
  llvm/unittests/Support/CompressionTest.cpp
  utils/bazel/llvm_configs/llvm-config.h.cmake

Index: utils/bazel/llvm_configs/llvm-config.h.cmake
===
--- utils/bazel/llvm_configs/llvm-config.h.cmake
+++ utils/bazel/llvm_configs/llvm-config.h.cmake
@@ -95,6 +95,9 @@
 /* Define if zlib compression is available */
 #cmakedefine01 LLVM_ENABLE_ZLIB
 
+/* Define if zstd compression is available */
+#cmakedefine01 LLVM_ENABLE_ZSTD
+
 /* Define if LLVM was built with a dependency to the libtensorflow dynamic library */
 #cmakedefine LLVM_HAVE_TF_API
 
Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -61,4 +61,43 @@
 }
 #endif
 
+#if LLVM_ENABLE_ZSTD
+static void testZstdCompression(StringRef Input, int Level) {
+  SmallString<32> Compressed;
+  SmallString<32> Uncompressed;
+  zstd::compress(Input, Compressed, Level);
+
+  // Check that uncompressed buffer is the same as original.
+  Error E = zstd::uncompress(Compressed, Uncompressed, Input.size());
+  consumeError(std::move(E));
+
+  EXPECT_EQ(Input, Uncompressed);
+  if (Input.size() > 0) {
+// Uncompression fails if expected length is too short.
+E = zstd::uncompress(Compressed, Uncompressed, Input.size() - 1);
+EXPECT_EQ("Destination buffer is too small", llvm::toString(std::move(E)));
+  }
+}
+
+TEST(CompressionTest, Zstd) {
+  testZstdCompression("", zstd::DefaultCompression);
+
+  testZstdCompression("hello, world!", zstd::NoCompression);
+  testZstdCompression("hello, world!", zstd::BestSizeCompression);
+  testZstdCompression("hello, world!", zstd::BestSpeedCompression);
+  testZstdCompression("hello, world!", zstd::DefaultCompression);
+
+  const size_t kSize = 1024;
+  char BinaryData[kSize];
+  for (size_t i = 0; i < kSize; ++i)
+BinaryData[i] = i & 255;
+  StringRef BinaryDataStr(BinaryData, kSize);
+
+  testZstdCompression(BinaryDataStr, zstd::NoCompression);
+  testZstdCompression(BinaryDataStr, zstd::BestSizeCompression);
+  testZstdCompression(BinaryDataStr, zstd::BestSpeedCompression);
+  testZstdCompression(BinaryDataStr, zstd::DefaultCompression);
+}
+#endif
+
 }
Index: llvm/test/lit.site.cfg.py.in
===
--- llvm/test/lit.site.cfg.py.in
+++ llvm/test/lit.site.cfg.py.in
@@ -37,6 +37,7 @@
 config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.have_zstd = @LLVM_ENABLE_ZSTD@
 config.have_libxar = @LLVM_HAVE_LIBXAR@
 config.have_libxml2 = @LLVM_ENABLE_LIBXML2@
 config.have_curl = @LLVM_ENABLE_CURL@
Index: llvm/lib/Support/Compression.cpp
===
--- llvm/lib/Support/Compression.cpp
+++ llvm/lib/Support/Compression.cpp
@@ -20,6 +20,9 @@
 #if LLVM_ENABLE_ZLIB
 #include 
 #endif
+#if LLVM_ENABLE_ZSTD
+#include 
+#endif
 
 using namespace llvm;
 using namespace llvm::compression;
@@ -101,3 +104,65 @@
   llvm_unreachable("zlib::uncompress is unavailable");
 }
 #endif
+
+#if LLVM_ENABLE_ZSTD
+
+bool zstd::isAvailable() { return true; }
+
+void zstd::compress(StringRef InputBuffer,
+SmallVectorImpl , int Level) {
+  unsigned long CompressedBufferSize = ::ZSTD_compressBound(InputBuffer.size());
+  CompressedBuffer.resize_for_overwrite(CompressedBufferSize);
+  unsigned long CompressedSize = ::ZSTD_compress(
+  (char *)CompressedBuffer.data(), CompressedBufferSize,
+  (const char *)InputBuffer.data(), InputBuffer.size(), Level);
+  if (ZSTD_isError(CompressedSize))
+report_bad_alloc_error("Allocation failed");
+  // Tell MemorySanitizer that zstd output buffer is fully initialized.
+  // This avoids a false report when running LLVM with uninstrumented ZLib.
+  __msan_unpoison(CompressedBuffer.data(), CompressedSize);
+  if (CompressedSize < CompressedBuffer.size())
+CompressedBuffer.truncate(CompressedSize);
+}
+
+Error zstd::uncompress(StringRef InputBuffer, char *UncompressedBuffer,
+   size_t ) {
+  const size_t Res =
+  ::ZSTD_decompress((char *)UncompressedBuffer, UncompressedSize,
+(const char *)InputBuffer.data(), InputBuffer.size());
+  UncompressedSize 

[PATCH] D128465: [llvm] add zstd to `llvm::compression` namespace

2022-07-13 Thread Cole Kissane via Phabricator via cfe-commits
ckissane added inline comments.



Comment at: llvm/lib/Support/Compression.cpp:63
   __msan_unpoison(CompressedBuffer.data(), CompressedSize);
-  CompressedBuffer.truncate(CompressedSize);
+  if (CompressedSize < CompressedBuffer.size())
+CompressedBuffer.truncate(CompressedSize);

phosek wrote:
> I'd make changes to zlib separately.
Here https://reviews.llvm.org/D129698


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128465/new/

https://reviews.llvm.org/D128465

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


[PATCH] D129583: [DOC] Add DR1734 and DR1496 Clang's cxx_dr_status as not implemented

2022-07-13 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

Thanks for the suggestions and for the quick review! @aaron.ballman


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129583/new/

https://reviews.llvm.org/D129583

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


[PATCH] D129583: [DOC] Add DR1734 and DR1496 Clang's cxx_dr_status as not implemented

2022-07-13 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG202b327f5d29: [DOC] Add DR1734 and DR1496 Clangs 
cxx_dr_status as not implemented (authored by royjacobson).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129583/new/

https://reviews.llvm.org/D129583

Files:
  clang/test/CXX/drs/dr14xx.cpp
  clang/test/CXX/drs/dr17xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -8790,7 +8790,7 @@
 https://wg21.link/cwg1496;>1496
 CD4
 Triviality with deleted and missing default constructors
-Unknown
+No
   
   
 https://wg21.link/cwg1497;>1497
@@ -10218,7 +10218,7 @@
 https://wg21.link/cwg1734;>1734
 CD4
 Nontrivial deleted copy functions
-Unknown
+No
   
   
 https://wg21.link/cwg1735;>1735
Index: clang/test/CXX/drs/dr17xx.cpp
===
--- clang/test/CXX/drs/dr17xx.cpp
+++ clang/test/CXX/drs/dr17xx.cpp
@@ -27,6 +27,18 @@
 #endif
 }
 
+namespace dr1734 { // dr1734: no
+#if __cplusplus >= 201103L
+struct A {
+A(const A&) = delete;
+};
+// FIXME: 'A' should not be trivially copyable because the class lacks at least
+// one non-deleted copy constructor, move constructor, copy assignment
+// operator, or move assignment operator.
+static_assert(__is_trivially_copyable(A), "");
+#endif
+}
+
 namespace dr1736 { // dr1736: 3.9
 #if __cplusplus >= 201103L
 struct S {
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -501,4 +501,16 @@
   template int c<0, Ts...>; // expected-error {{not more 
specialized}}
 #endif
 }
+
+namespace dr1496 { // dr1496: no
+#if __cplusplus >= 201103L
+struct A {
+A() = delete;
+};
+// FIXME: 'A' should not be trivial because the class lacks at least one
+// default constructor which is not deleted.
+static_assert(__is_trivial(A), "");
+#endif
+}
+
 #endif


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -8790,7 +8790,7 @@
 https://wg21.link/cwg1496;>1496
 CD4
 Triviality with deleted and missing default constructors
-Unknown
+No
   
   
 https://wg21.link/cwg1497;>1497
@@ -10218,7 +10218,7 @@
 https://wg21.link/cwg1734;>1734
 CD4
 Nontrivial deleted copy functions
-Unknown
+No
   
   
 https://wg21.link/cwg1735;>1735
Index: clang/test/CXX/drs/dr17xx.cpp
===
--- clang/test/CXX/drs/dr17xx.cpp
+++ clang/test/CXX/drs/dr17xx.cpp
@@ -27,6 +27,18 @@
 #endif
 }
 
+namespace dr1734 { // dr1734: no
+#if __cplusplus >= 201103L
+struct A {
+A(const A&) = delete;
+};
+// FIXME: 'A' should not be trivially copyable because the class lacks at least
+// one non-deleted copy constructor, move constructor, copy assignment
+// operator, or move assignment operator.
+static_assert(__is_trivially_copyable(A), "");
+#endif
+}
+
 namespace dr1736 { // dr1736: 3.9
 #if __cplusplus >= 201103L
 struct S {
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -501,4 +501,16 @@
   template int c<0, Ts...>; // expected-error {{not more specialized}}
 #endif
 }
+
+namespace dr1496 { // dr1496: no
+#if __cplusplus >= 201103L
+struct A {
+A() = delete;
+};
+// FIXME: 'A' should not be trivial because the class lacks at least one
+// default constructor which is not deleted.
+static_assert(__is_trivial(A), "");
+#endif
+}
+
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 202b327 - [DOC] Add DR1734 and DR1496 Clang's cxx_dr_status as not implemented

2022-07-13 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-07-14T00:48:35+03:00
New Revision: 202b327f5d293a6f795a01933835b5ad53d8ed42

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

LOG: [DOC] Add DR1734 and DR1496 Clang's cxx_dr_status as not implemented

Those two DRs about the (copy) triviality of types with deleted special member 
functions are not implemented in Clang.
Document them as such.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D129583

Added: 


Modified: 
clang/test/CXX/drs/dr14xx.cpp
clang/test/CXX/drs/dr17xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr14xx.cpp b/clang/test/CXX/drs/dr14xx.cpp
index 06fcc190784d9..526211c0e0062 100644
--- a/clang/test/CXX/drs/dr14xx.cpp
+++ b/clang/test/CXX/drs/dr14xx.cpp
@@ -501,4 +501,16 @@ namespace dr1495 { // dr1495: 4
   template int c<0, Ts...>; // expected-error {{not more 
specialized}}
 #endif
 }
+
+namespace dr1496 { // dr1496: no
+#if __cplusplus >= 201103L
+struct A {
+A() = delete;
+};
+// FIXME: 'A' should not be trivial because the class lacks at least one
+// default constructor which is not deleted.
+static_assert(__is_trivial(A), "");
+#endif
+}
+
 #endif

diff  --git a/clang/test/CXX/drs/dr17xx.cpp b/clang/test/CXX/drs/dr17xx.cpp
index c8648908ebda9..addf1d274e91b 100644
--- a/clang/test/CXX/drs/dr17xx.cpp
+++ b/clang/test/CXX/drs/dr17xx.cpp
@@ -27,6 +27,18 @@ namespace dr1715 { // dr1715: 3.9
 #endif
 }
 
+namespace dr1734 { // dr1734: no
+#if __cplusplus >= 201103L
+struct A {
+A(const A&) = delete;
+};
+// FIXME: 'A' should not be trivially copyable because the class lacks at least
+// one non-deleted copy constructor, move constructor, copy assignment
+// operator, or move assignment operator.
+static_assert(__is_trivially_copyable(A), "");
+#endif
+}
+
 namespace dr1736 { // dr1736: 3.9
 #if __cplusplus >= 201103L
 struct S {

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index e437da1bfda99..466f287c75d90 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -8790,7 +8790,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg1496;>1496
 CD4
 Triviality with deleted and missing default constructors
-Unknown
+No
   
   
 https://wg21.link/cwg1497;>1497
@@ -10218,7 +10218,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg1734;>1734
 CD4
 Nontrivial deleted copy functions
-Unknown
+No
   
   
 https://wg21.link/cwg1735;>1735



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


[PATCH] D129583: [DOC] Add DR1734 and DR1496 Clang's cxx_dr_status as not implemented

2022-07-13 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 22.
royjacobson added a comment.

Update comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129583/new/

https://reviews.llvm.org/D129583

Files:
  clang/test/CXX/drs/dr14xx.cpp
  clang/test/CXX/drs/dr17xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -8790,7 +8790,7 @@
 https://wg21.link/cwg1496;>1496
 CD4
 Triviality with deleted and missing default constructors
-Unknown
+No
   
   
 https://wg21.link/cwg1497;>1497
@@ -10218,7 +10218,7 @@
 https://wg21.link/cwg1734;>1734
 CD4
 Nontrivial deleted copy functions
-Unknown
+No
   
   
 https://wg21.link/cwg1735;>1735
Index: clang/test/CXX/drs/dr17xx.cpp
===
--- clang/test/CXX/drs/dr17xx.cpp
+++ clang/test/CXX/drs/dr17xx.cpp
@@ -27,6 +27,18 @@
 #endif
 }
 
+namespace dr1734 { // dr1734: no
+#if __cplusplus >= 201103L
+struct A {
+A(const A&) = delete;
+};
+// FIXME: 'A' should not be trivially copyable because the class lacks at least
+// one non-deleted copy constructor, move constructor, copy assignment
+// operator, or move assignment operator.
+static_assert(__is_trivially_copyable(A), "");
+#endif
+}
+
 namespace dr1736 { // dr1736: 3.9
 #if __cplusplus >= 201103L
 struct S {
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -501,4 +501,16 @@
   template int c<0, Ts...>; // expected-error {{not more 
specialized}}
 #endif
 }
+
+namespace dr1496 { // dr1496: no
+#if __cplusplus >= 201103L
+struct A {
+A() = delete;
+};
+// FIXME: 'A' should not be trivial because the class lacks at least one
+// default constructor which is not deleted.
+static_assert(__is_trivial(A), "");
+#endif
+}
+
 #endif


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -8790,7 +8790,7 @@
 https://wg21.link/cwg1496;>1496
 CD4
 Triviality with deleted and missing default constructors
-Unknown
+No
   
   
 https://wg21.link/cwg1497;>1497
@@ -10218,7 +10218,7 @@
 https://wg21.link/cwg1734;>1734
 CD4
 Nontrivial deleted copy functions
-Unknown
+No
   
   
 https://wg21.link/cwg1735;>1735
Index: clang/test/CXX/drs/dr17xx.cpp
===
--- clang/test/CXX/drs/dr17xx.cpp
+++ clang/test/CXX/drs/dr17xx.cpp
@@ -27,6 +27,18 @@
 #endif
 }
 
+namespace dr1734 { // dr1734: no
+#if __cplusplus >= 201103L
+struct A {
+A(const A&) = delete;
+};
+// FIXME: 'A' should not be trivially copyable because the class lacks at least
+// one non-deleted copy constructor, move constructor, copy assignment
+// operator, or move assignment operator.
+static_assert(__is_trivially_copyable(A), "");
+#endif
+}
+
 namespace dr1736 { // dr1736: 3.9
 #if __cplusplus >= 201103L
 struct S {
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -501,4 +501,16 @@
   template int c<0, Ts...>; // expected-error {{not more specialized}}
 #endif
 }
+
+namespace dr1496 { // dr1496: no
+#if __cplusplus >= 201103L
+struct A {
+A() = delete;
+};
+// FIXME: 'A' should not be trivial because the class lacks at least one
+// default constructor which is not deleted.
+static_assert(__is_trivial(A), "");
+#endif
+}
+
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129694: [OPENMP] Make declare target static global externally visible

2022-07-13 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

Thanks for the patch. I still think this is a silly feature to support, but 
users will probably expect it. See comments.




Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:10790
 Flags = OffloadEntriesInfoManagerTy::OMPTargetGlobalVarEntryTo;
-VarName = CGM.getMangledName(VD);
+// We don't need to mangle the host side of declare target global 
variables but we
+// need to create offload entry that matches the device side which gets 
mangled.

It might be easier to just mangle the original definition, that would reduce a 
lot of churn here adding `origName` everywhere. Any reason that's not desirable?



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:10797
+Out

[PATCH] D128462: [HLSL] add -I option for dxc mode.

2022-07-13 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: clang/include/clang/Driver/Options.td:6824
+class DXCJoinedOrSeparateConflict : Option<["--", "/", "-"], name,
+  KIND_JOINED_OR_SEPARATE>, Group, Flags<[DXCOption, 
NoXarchOption]>;
 

python3kgae wrote:
> beanz wrote:
> > python3kgae wrote:
> > > pow2clk wrote:
> > > > I'm not sure why this has the suffix "Conflict" In addition, you can't 
> > > > currently specify the "I" option with "--" in DXC.
> > > The conflict happened with clang-cl which use same prefix ("/", "-") as 
> > > dxc.
> > > 
> > > def _SLASH_I : CLJoinedOrSeparate<"I">,
> > >   HelpText<"Add directory to include search path">, MetaVarName<"">,
> > >   Alias;
> > Our option’s behavior is the same as _SLASH_I, so why can’t we reuse it 
> > instead of re-implementing it.
> You mean add DXCOption flag for _SLASH_I?
> Is it OK to modify options for cl mode?
It is preferable to add DXCOption to existing options rather than declaring new 
options for everything.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128462/new/

https://reviews.llvm.org/D128462

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


[PATCH] D128465: [llvm] add zstd to `llvm::compression` namespace

2022-07-13 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: llvm/lib/Support/Compression.cpp:63
   __msan_unpoison(CompressedBuffer.data(), CompressedSize);
-  CompressedBuffer.truncate(CompressedSize);
+  if (CompressedSize < CompressedBuffer.size())
+CompressedBuffer.truncate(CompressedSize);

I'd make changes to zlib separately.



Comment at: llvm/lib/Support/Compression.cpp:86
  UncompressedSize);
-  UncompressedBuffer.truncate(UncompressedSize);
+  if (UncompressedSize < UncompressedBuffer.size())
+UncompressedBuffer.truncate(UncompressedSize);

Ditto here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128465/new/

https://reviews.llvm.org/D128465

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


[PATCH] D128462: [HLSL] add -I option for dxc mode.

2022-07-13 Thread Xiang Li via Phabricator via cfe-commits
python3kgae marked an inline comment as done.
python3kgae added inline comments.



Comment at: clang/include/clang/Driver/Options.td:6824
+class DXCJoinedOrSeparateConflict : Option<["--", "/", "-"], name,
+  KIND_JOINED_OR_SEPARATE>, Group, Flags<[DXCOption, 
NoXarchOption]>;
 

beanz wrote:
> python3kgae wrote:
> > pow2clk wrote:
> > > I'm not sure why this has the suffix "Conflict" In addition, you can't 
> > > currently specify the "I" option with "--" in DXC.
> > The conflict happened with clang-cl which use same prefix ("/", "-") as dxc.
> > 
> > def _SLASH_I : CLJoinedOrSeparate<"I">,
> >   HelpText<"Add directory to include search path">, MetaVarName<"">,
> >   Alias;
> Our option’s behavior is the same as _SLASH_I, so why can’t we reuse it 
> instead of re-implementing it.
You mean add DXCOption flag for _SLASH_I?
Is it OK to modify options for cl mode?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128462/new/

https://reviews.llvm.org/D128462

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


[PATCH] D128462: [HLSL] add -I option for dxc mode.

2022-07-13 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: clang/include/clang/Driver/Options.td:6824
+class DXCJoinedOrSeparateConflict : Option<["--", "/", "-"], name,
+  KIND_JOINED_OR_SEPARATE>, Group, Flags<[DXCOption, 
NoXarchOption]>;
 

python3kgae wrote:
> pow2clk wrote:
> > I'm not sure why this has the suffix "Conflict" In addition, you can't 
> > currently specify the "I" option with "--" in DXC.
> The conflict happened with clang-cl which use same prefix ("/", "-") as dxc.
> 
> def _SLASH_I : CLJoinedOrSeparate<"I">,
>   HelpText<"Add directory to include search path">, MetaVarName<"">,
>   Alias;
Our option’s behavior is the same as _SLASH_I, so why can’t we reuse it instead 
of re-implementing it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128462/new/

https://reviews.llvm.org/D128462

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


[PATCH] D129694: [OPENMP] Make declare target static global externally visible

2022-07-13 Thread Sunil Shrestha via Phabricator via cfe-commits
ssquare08 created this revision.
ssquare08 added a reviewer: jhuber6.
Herald added subscribers: mattd, asavonic, guansong, yaxunl.
Herald added a project: All.
ssquare08 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

This is to support cases where static globals are marked declare
target. By default these file static globals are not externally
visible but in order for OpenMP runtime to access these symbols,
this changes here makes them externally visisble unless they
have "hidden" visibility attribute.
Making them externally visible, however, leads to symbol conflict
when two files have variables with the same name. Thus, these
symbols needs to be mangled on the device side of the compilation.
In order to do so, the host side mangles the symbol names and
passes that metadata information to the device side. It also uses
these mangled names if offload entry table so that the OPenMP
runtime can find these symbols during registration.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129694

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/declare_target_codegen.cpp
  clang/test/OpenMP/declare_target_link_codegen.cpp
  clang/test/OpenMP/declare_target_visibility_codegen.cpp
  clang/test/OpenMP/nvptx_allocate_codegen.cpp
  clang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp
  clang/test/OpenMP/target_update_messages.cpp

Index: clang/test/OpenMP/target_update_messages.cpp
===
--- clang/test/OpenMP/target_update_messages.cpp
+++ clang/test/OpenMP/target_update_messages.cpp
@@ -14,13 +14,6 @@
   argc = x; // expected-warning {{variable 'x' is uninitialized when used here}}
 }
 
-static int y;
-#pragma omp declare target(y)
-
-void yyy() {
-#pragma omp target update to(y) // expected-error {{the host cannot update a declare target variable that is not externally visible.}}
-}
-
 int __attribute__((visibility("hidden"))) z;
 #pragma omp declare target(z)
 
Index: clang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp
===
--- clang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp
+++ clang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp
@@ -15,7 +15,7 @@
 
 // SIMD-ONLY-NOT: {{__kmpc|__tgt}}
 
-// DEVICE-DAG: [[C_ADDR:.+]] = internal global i32 0,
+// DEVICE-DAG: [[C_ADDR:.+]] = global i32 0,
 // DEVICE-DAG: [[CD_ADDR:@.+]] ={{ protected | }}global %struct.S zeroinitializer,
 // HOST-DAG: @[[C_ADDR:.+]] = internal global i32 0,
 // HOST-DAG: @[[CD_ADDR:.+]] ={{( protected | dso_local)?}} global %struct.S zeroinitializer,
@@ -72,6 +72,8 @@
 // DEVICE-DAG: call void
 // DEVICE-DAG: ret void
 
+// HOST-DAG: @.omp_offloading.entry_name = internal unnamed_addr constant [{{[0-9]+}} x i8] c"[[C_ENTRY_NAME:c__static__.+]]\00"
+// HOST-DAG: @.omp_offloading.entry.[[C_ENTRY_NAME]] = weak{{.*}} constant %struct.__tgt_offload_entry { i8* bitcast (i32* @[[C_ADDR]] to i8*), i8* getelementptr inbounds ([{{[0-9]+}} x i8], [{{[0-9]+}} x i8]* @.omp_offloading.entry_name, i32 0, i32 0), i64 4, i32 0, i32 0 }, section "omp_offloading_entries", align 1
 // HOST-DAG: @.omp_offloading.entry_name{{.*}} = internal unnamed_addr constant [{{[0-9]+}} x i8] c"[[CD_ADDR]]\00"
 // HOST-DAG: @.omp_offloading.entry.[[CD_ADDR]] = weak{{.*}} constant %struct.__tgt_offload_entry { i8* bitcast (%struct.S* @[[CD_ADDR]] to i8*), i8* getelementptr inbounds ([{{[0-9]+}} x i8], [{{[0-9]+}} x i8]* @.omp_offloading.entry_name{{.*}}, i32 0, i32 0), i64 4, i32 0, i32 0 }, section "omp_offloading_entries", align 1
 // HOST-DAG: @.omp_offloading.entry_name{{.*}} = internal unnamed_addr constant [{{[0-9]+}} x i8] c"[[C_CTOR]]\00"
@@ -97,8 +99,8 @@
 // HOST: [[C:%.*]] = load i32, i32* @[[C_ADDR]],
 // HOST: store i32 [[C]], i32* %
 
-// HOST-DAG: !{i32 1, !"[[CD_ADDR]]", i32 0, i32 {{[0-9]+}}}
-// HOST-DAG: !{i32 1, !"[[C_ADDR]]", i32 0, i32 {{[0-9]+}}}
+// HOST-DAG: !{i32 1, !"[[CD_ADDR]]", i32 0, i32 {{[0-9]+}}, !"cd"}
+// HOST-DAG: !{i32 1, !"[[C_ENTRY_NAME]]", i32 0, i32 {{[0-9]+}}, !"c"}
 
 // DEVICE: !nvvm.annotations
 // DEVICE-DAG: !{void ()* [[C_CTOR]], !"kernel", i32 1}
Index: clang/test/OpenMP/nvptx_allocate_codegen.cpp
===
--- clang/test/OpenMP/nvptx_allocate_codegen.cpp
+++ clang/test/OpenMP/nvptx_allocate_codegen.cpp
@@ -89,7 +89,7 @@
 // CHECK1-NEXT:[[RETVAL:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:[[B:%.*]] = alloca double, align 8
 // CHECK1-NEXT:store i32 0, i32* [[RETVAL]], align 4
-// CHECK1-NEXT:store i32 2, i32* @_ZZ4mainE1a, align 

[clang] 779ba43 - [clang][deps] Silence a GCC warning about missing returns after a fully covered switch. NFC.

2022-07-13 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2022-07-13T23:57:01+03:00
New Revision: 779ba43234cc9eb747018d2fe86d7d4a16d283d9

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

LOG: [clang][deps] Silence a GCC warning about missing returns after a fully 
covered switch. NFC.

Added: 


Modified: 
clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 




diff  --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index 46166d8903a75..aea9b913609f2 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -378,6 +378,7 @@ class FullDeps {
 case ModuleOutputKind::DiagnosticSerializationFile:
   return PCMPath.first->second + ".diag";
 }
+llvm_unreachable("Fully covered switch above!");
   }
 
   /// Construct a path for the explicitly built PCM.



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


[PATCH] D128462: [HLSL] add -I option for dxc mode.

2022-07-13 Thread Xiang Li via Phabricator via cfe-commits
python3kgae marked an inline comment as done.
python3kgae added inline comments.



Comment at: clang/include/clang/Driver/Options.td:6824
+class DXCJoinedOrSeparateConflict : Option<["--", "/", "-"], name,
+  KIND_JOINED_OR_SEPARATE>, Group, Flags<[DXCOption, 
NoXarchOption]>;
 

pow2clk wrote:
> I'm not sure why this has the suffix "Conflict" In addition, you can't 
> currently specify the "I" option with "--" in DXC.
The conflict happened with clang-cl which use same prefix ("/", "-") as dxc.

def _SLASH_I : CLJoinedOrSeparate<"I">,
  HelpText<"Add directory to include search path">, MetaVarName<"">,
  Alias;



Comment at: clang/include/clang/Driver/Options.td:6851
   Group, Flags<[DXCOption, NoXarchOption]>, Alias;
+def dxc_I : DXCJoinedOrSeparateConflict<"I">,
+  HelpText<"Add directory to include search path">,

beanz wrote:
> beanz wrote:
> > This option has the same behavior between DXC and clang, is there a reason 
> > we need to define a new option value instead of reusing the existing one?
> As a note, the `I_Group` only has the `-I` flag, so we probably can just make 
> `I_Group` valid for DXC.
clang -I is CC1Option,CC1AsOption,FlangOption,FC1Option. We need one for dxc 
mode with prefix "/", "-". But it conflict with _SLASH_I for clang-cl.
So have to add dxc_I.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128462/new/

https://reviews.llvm.org/D128462

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


[PATCH] D128462: [HLSL] add -I option for dxc mode.

2022-07-13 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 13.
python3kgae marked 3 inline comments as done.
python3kgae added a comment.

Update test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128462/new/

https://reviews.llvm.org/D128462

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/dxc_I.hlsl


Index: clang/test/Driver/dxc_I.hlsl
===
--- /dev/null
+++ clang/test/Driver/dxc_I.hlsl
@@ -0,0 +1,4 @@
+// RUN: %clang_dxc -I test  -### %s 2>&1 | FileCheck %s
+
+// Make sure -I send to cc1.
+// CHECK:"-I" "test"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3481,6 +3481,7 @@
   types::ID InputType) {
   const unsigned ForwardedArguments[] = {options::OPT_dxil_validator_version,
  options::OPT_D,
+ options::OPT_I,
  options::OPT_S,
  options::OPT_emit_llvm,
  options::OPT_disable_llvm_passes,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -6820,6 +6820,8 @@
   Group, Flags<[DXCOption, NoXarchOption]>;
 class DXCJoinedOrSeparate : Option<["/", "-"], name,
   KIND_JOINED_OR_SEPARATE>, Group, Flags<[DXCOption, 
NoXarchOption]>;
+class DXCJoinedOrSeparateConflict : Option<["--", "/", "-"], name,
+  KIND_JOINED_OR_SEPARATE>, Group, Flags<[DXCOption, 
NoXarchOption]>;
 
 def dxc_help : Option<["/", "-", "--"], "help", KIND_JOINED>,
   Group, Flags<[DXCOption, NoXarchOption]>, Alias,
@@ -6846,6 +6848,9 @@
  "as_6_5, as_6_6, as_6_7">;
 def dxc_D : Option<["--", "/", "-"], "D", KIND_JOINED_OR_SEPARATE>,
   Group, Flags<[DXCOption, NoXarchOption]>, Alias;
+def dxc_I : DXCJoinedOrSeparateConflict<"I">,
+  HelpText<"Add directory to include search path">,
+  Alias;
 def emit_pristine_llvm : DXCFlag<"emit-pristine-llvm">,
   HelpText<"Emit pristine LLVM IR from the frontend by not running any LLVM 
passes at all."
"Same as -S + -emit-llvm + -disable-llvm-passes.">;


Index: clang/test/Driver/dxc_I.hlsl
===
--- /dev/null
+++ clang/test/Driver/dxc_I.hlsl
@@ -0,0 +1,4 @@
+// RUN: %clang_dxc -I test  -### %s 2>&1 | FileCheck %s
+
+// Make sure -I send to cc1.
+// CHECK:"-I" "test"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3481,6 +3481,7 @@
   types::ID InputType) {
   const unsigned ForwardedArguments[] = {options::OPT_dxil_validator_version,
  options::OPT_D,
+ options::OPT_I,
  options::OPT_S,
  options::OPT_emit_llvm,
  options::OPT_disable_llvm_passes,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -6820,6 +6820,8 @@
   Group, Flags<[DXCOption, NoXarchOption]>;
 class DXCJoinedOrSeparate : Option<["/", "-"], name,
   KIND_JOINED_OR_SEPARATE>, Group, Flags<[DXCOption, NoXarchOption]>;
+class DXCJoinedOrSeparateConflict : Option<["--", "/", "-"], name,
+  KIND_JOINED_OR_SEPARATE>, Group, Flags<[DXCOption, NoXarchOption]>;
 
 def dxc_help : Option<["/", "-", "--"], "help", KIND_JOINED>,
   Group, Flags<[DXCOption, NoXarchOption]>, Alias,
@@ -6846,6 +6848,9 @@
  "as_6_5, as_6_6, as_6_7">;
 def dxc_D : Option<["--", "/", "-"], "D", KIND_JOINED_OR_SEPARATE>,
   Group, Flags<[DXCOption, NoXarchOption]>, Alias;
+def dxc_I : DXCJoinedOrSeparateConflict<"I">,
+  HelpText<"Add directory to include search path">,
+  Alias;
 def emit_pristine_llvm : DXCFlag<"emit-pristine-llvm">,
   HelpText<"Emit pristine LLVM IR from the frontend by not running any LLVM passes at all."
"Same as -S + -emit-llvm + -disable-llvm-passes.">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129691: [clang][test] fix typo in fn attr

2022-07-13 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers created this revision.
nickdesaulniers added reviewers: aaron.ballman, erichkeane, MaskRay.
Herald added subscribers: jsji, StephenFan, pengfei.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

While testing backports of
https://reviews.llvm.org/D129572#inline-1245936
commit 2240d72f15f3 
 ("[X86] 
initial -mfunction-return=thunk-extern support")
I noticed that one of my unit tests mistyped a function attribute. The
unit test was intended to test fn attr merging behavior, but with the
typo it was not.  Small fixup.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129691

Files:
  clang/test/CodeGen/attr-function-return.c
  clang/test/CodeGen/attr-function-return.cpp


Index: clang/test/CodeGen/attr-function-return.cpp
===
--- clang/test/CodeGen/attr-function-return.cpp
+++ clang/test/CodeGen/attr-function-return.cpp
@@ -1,11 +1,12 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu %s -emit-llvm -o - \
+// RUN:   -Werror=unknown-attributes \
 // RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-NOM
 // RUN: %clang_cc1 -triple x86_64-linux-gnu %s -emit-llvm -o - \
-// RUN:   -mfunction-return=keep | FileCheck %s \
-// RUN:   --check-prefixes=CHECK,CHECK-KEEP
+// RUN:   -Werror=unknown-attributes -mfunction-return=keep \
+// RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-KEEP
 // RUN: %clang_cc1 -triple x86_64-linux-gnu %s -emit-llvm -o - \
-// RUN:  -mfunction-return=thunk-extern | FileCheck %s \
-// RUN:  --check-prefixes=CHECK,CHECK-EXTERN
+// RUN:   -Werror=unknown-attributes -mfunction-return=thunk-extern \
+// RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-EXTERN
 
 int foo(void) {
   // CHECK: @"_ZZ3foovENK3$_0clEv"({{.*}}) [[NOATTR:#[0-9]+]]
Index: clang/test/CodeGen/attr-function-return.c
===
--- clang/test/CodeGen/attr-function-return.c
+++ clang/test/CodeGen/attr-function-return.c
@@ -1,11 +1,12 @@
 // RUN: %clang_cc1 -std=gnu2x -triple x86_64-linux-gnu %s -emit-llvm -o - \
+// RUN:   -Werror=ignored-attributes \
 // RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-NOM
 // RUN: %clang_cc1 -std=gnu2x -triple x86_64-linux-gnu %s -emit-llvm -o - \
-// RUN:   -mfunction-return=keep | FileCheck %s \
-// RUN:   --check-prefixes=CHECK,CHECK-KEEP
+// RUN:   -Werror=ignored-attributes -mfunction-return=keep \
+// RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-KEEP
 // RUN: %clang_cc1 -std=gnu2x -triple x86_64-linux-gnu %s -emit-llvm -o - \
-// RUN:  -mfunction-return=thunk-extern | FileCheck %s \
-// RUN:  --check-prefixes=CHECK,CHECK-EXTERN
+// RUN:   -Werror=ignored-attributes -mfunction-return=thunk-extern \
+// RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-EXTERN
 
 #if !__has_attribute(function_return)
 #error "missing attribute support for function_return"
@@ -39,7 +40,7 @@
 void double_keep_thunk(void) {}
 
 // CHECK: @double_keep_thunk2() [[EXTERN]]
-[[gnu::function_return("thunk-keep")]][[gnu::function_return("thunk-extern")]]
+[[gnu::function_return("keep")]][[gnu::function_return("thunk-extern")]]
 void double_keep_thunk2(void) {}
 
 // CHECK: @thunk_keep() [[KEEP]]


Index: clang/test/CodeGen/attr-function-return.cpp
===
--- clang/test/CodeGen/attr-function-return.cpp
+++ clang/test/CodeGen/attr-function-return.cpp
@@ -1,11 +1,12 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu %s -emit-llvm -o - \
+// RUN:   -Werror=unknown-attributes \
 // RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-NOM
 // RUN: %clang_cc1 -triple x86_64-linux-gnu %s -emit-llvm -o - \
-// RUN:   -mfunction-return=keep | FileCheck %s \
-// RUN:   --check-prefixes=CHECK,CHECK-KEEP
+// RUN:   -Werror=unknown-attributes -mfunction-return=keep \
+// RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-KEEP
 // RUN: %clang_cc1 -triple x86_64-linux-gnu %s -emit-llvm -o - \
-// RUN:  -mfunction-return=thunk-extern | FileCheck %s \
-// RUN:  --check-prefixes=CHECK,CHECK-EXTERN
+// RUN:   -Werror=unknown-attributes -mfunction-return=thunk-extern \
+// RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-EXTERN
 
 int foo(void) {
   // CHECK: @"_ZZ3foovENK3$_0clEv"({{.*}}) [[NOATTR:#[0-9]+]]
Index: clang/test/CodeGen/attr-function-return.c
===
--- clang/test/CodeGen/attr-function-return.c
+++ clang/test/CodeGen/attr-function-return.c
@@ -1,11 +1,12 @@
 // RUN: %clang_cc1 -std=gnu2x -triple x86_64-linux-gnu %s -emit-llvm -o - \
+// RUN:   -Werror=ignored-attributes \
 // RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-NOM
 // RUN: %clang_cc1 -std=gnu2x -triple x86_64-linux-gnu %s -emit-llvm -o - \
-// RUN:   -mfunction-return=keep | FileCheck %s \
-// RUN:   

[PATCH] D129607: [clang][deps] Fix handling of -MT in module command-line

2022-07-13 Thread Ben Langmuir via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3ce78cbd2392: [clang][deps] Fix handling of -MT in module 
command-line (authored by benlangmuir).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129607/new/

https://reviews.llvm.org/D129607

Files:
  clang/include/clang/Basic/MakeSupport.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/MakeSupport.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/generate-modules-path-args.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -196,6 +196,12 @@
 llvm::cl::desc("the module of which the dependencies are to be computed"),
 llvm::cl::cat(DependencyScannerCategory));
 
+llvm::cl::list ModuleDepTargets(
+"dependency-target",
+llvm::cl::desc("With '-generate-modules-path-args', the names of "
+   "dependency targets for the dependency file"),
+llvm::cl::cat(DependencyScannerCategory));
+
 enum ResourceDirRecipeKind {
   RDRK_ModifyCompilerPath,
   RDRK_InvokeCompiler,
@@ -367,7 +373,8 @@
 case ModuleOutputKind::DependencyFile:
   return PCMPath.first->second + ".d";
 case ModuleOutputKind::DependencyTargets:
-  return ""; // Will get the default target name.
+  // Null-separate the list of targets.
+  return join(ModuleDepTargets, StringRef("\0", 1));
 case ModuleOutputKind::DiagnosticSerializationFile:
   return PCMPath.first->second + ".diag";
 }
Index: clang/test/ClangScanDeps/generate-modules-path-args.c
===
--- clang/test/ClangScanDeps/generate-modules-path-args.c
+++ clang/test/ClangScanDeps/generate-modules-path-args.c
@@ -5,6 +5,12 @@
 // RUN: clang-scan-deps -compilation-database %t/cdb.json \
 // RUN:   -format experimental-full -generate-modules-path-args > %t/deps.json
 // RUN: cat %t/deps.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s
+// RUN: clang-scan-deps -compilation-database %t/cdb.json \
+// RUN:   -format experimental-full -generate-modules-path-args -dependency-target foo > %t/deps_mt1.json
+// RUN: cat %t/deps_mt1.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s -check-prefix=DEPS_MT1
+// RUN: clang-scan-deps -compilation-database %t/cdb.json \
+// RUN:   -format experimental-full -generate-modules-path-args -dependency-target foo -dependency-target bar > %t/deps_mt2.json
+// RUN: cat %t/deps_mt2.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s -check-prefix=DEPS_MT2
 // RUN: clang-scan-deps -compilation-database %t/cdb_without.json \
 // RUN:   -format experimental-full -generate-modules-path-args > %t/deps_without.json
 // RUN: cat %t/deps_without.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t -check-prefix=WITHOUT %s
@@ -16,10 +22,20 @@
 // CHECK-NEXT: "-cc1"
 // CHECK:  "-serialize-diagnostic-file"
 // CHECK-NEXT: "[[PREFIX]]{{.*}}Mod{{.*}}.diag"
+// CHECK:  "-MT"
+// CHECK-NEXT: "[[PREFIX]]{{.*}}Mod{{.*}}.pcm"
 // CHECK:  "-dependency-file"
 // CHECK-NEXT: "[[PREFIX]]{{.*}}Mod{{.*}}.d"
 // CHECK:],
 
+// DEPS_MT1:  "-MT"
+// DEPS_MT1-NEXT: "foo"
+
+// DEPS_MT2:  "-MT"
+// DEPS_MT2-NEXT: "foo"
+// DEPS_MT2-NEXT: "-MT"
+// DEPS_MT2-NEXT: "bar"
+
 // WITHOUT:  {
 // WITHOUT-NEXT:   "modules": [
 // WITHOUT-NEXT: {
@@ -27,6 +43,7 @@
 // WITHOUT-NEXT: "-cc1"
 // WITHOUT-NOT:  "-serialize-diagnostic-file"
 // WITHOUT-NOT:  "-dependency-file"
+// WITHOUT-NOT:  "-MT"
 // WITHOUT:],
 
 //--- cdb.json.template
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Tooling/DependencyScanning/ModuleDepCollector.h"
 
+#include "clang/Basic/MakeSupport.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h"
@@ -112,7 +113,7 @@
 
 static std::vector splitString(std::string S, char Separator) {
   SmallVector Segments;
-  StringRef(S).split(Segments, Separator);
+  StringRef(S).split(Segments, Separator, /*MaxSplit=*/-1, /*KeepEmpty=*/false);
   std::vector Result;
   Result.reserve(Segments.size());
   for (StringRef Segment : Segments)
@@ -135,10 +136,17 @@
 CI.getDiagnosticOpts().DiagnosticSerializationFile =
 LookupModuleOutput(ID, 

[clang] 3ce78cb - [clang][deps] Fix handling of -MT in module command-line

2022-07-13 Thread Ben Langmuir via cfe-commits

Author: Ben Langmuir
Date: 2022-07-13T13:36:15-07:00
New Revision: 3ce78cbd2392d7c98f97d1d424cd7ff582fc28f8

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

LOG: [clang][deps] Fix handling of -MT in module command-line

Follow-up to 6626f6fec3d3, this fixes the handling of -MT
* If no targets are provided, we need to invent one since cc1 expects
  the driver to have handled it. The default is to use -o, quoting as
  necessary for a make target.
* Fix the splitting for empty string, which was incorrectly treated as
  {""} instead of {}.
* Add a way to test this behaviour in clang-scan-deps.

Differential Revision: https://reviews.llvm.org/D129607

Added: 
clang/include/clang/Basic/MakeSupport.h
clang/lib/Basic/MakeSupport.cpp

Modified: 
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
clang/lib/Basic/CMakeLists.txt
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
clang/test/ClangScanDeps/generate-modules-path-args.c
clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/MakeSupport.h 
b/clang/include/clang/Basic/MakeSupport.h
new file mode 100644
index 0..c663014ba7bcf
--- /dev/null
+++ b/clang/include/clang/Basic/MakeSupport.h
@@ -0,0 +1,23 @@
+//===- MakeSupport.h - Make Utilities ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_BASIC_MAKESUPPORT_H
+#define LLVM_CLANG_BASIC_MAKESUPPORT_H
+
+#include "clang/Basic/LLVM.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace clang {
+
+/// Quote target names for inclusion in GNU Make dependency files.
+/// Only the characters '$', '#', ' ', '\t' are quoted.
+void quoteMakeTarget(StringRef Target, SmallVectorImpl );
+
+} // namespace clang
+
+#endif // LLVM_CLANG_BASIC_MAKESUPPORT_H

diff  --git 
a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h 
b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index cb68df8314da1..05c9f56b4cf63 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -72,7 +72,7 @@ enum class ModuleOutputKind {
   /// The path of the dependency file (.d), if any.
   DependencyFile,
   /// The null-separated list of names to use as the targets in the dependency
-  /// file, if any.
+  /// file, if any. Defaults to the value of \c ModuleFile, as in the driver.
   DependencyTargets,
   /// The path of the serialized diagnostic file (.dia), if any.
   DiagnosticSerializationFile,

diff  --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index c815b571bc9c0..89dd33260b29c 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -54,6 +54,7 @@ add_clang_library(clangBasic
   IdentifierTable.cpp
   LangOptions.cpp
   LangStandards.cpp
+  MakeSupport.cpp
   Module.cpp
   ObjCRuntime.cpp
   OpenCLOptions.cpp

diff  --git a/clang/lib/Basic/MakeSupport.cpp b/clang/lib/Basic/MakeSupport.cpp
new file mode 100644
index 0..37838f7bbc7bc
--- /dev/null
+++ b/clang/lib/Basic/MakeSupport.cpp
@@ -0,0 +1,35 @@
+//===-- MakeSuport.cpp 
--*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/MakeSupport.h"
+
+void clang::quoteMakeTarget(StringRef Target, SmallVectorImpl ) {
+  for (unsigned i = 0, e = Target.size(); i != e; ++i) {
+switch (Target[i]) {
+case ' ':
+case '\t':
+  // Escape the preceding backslashes
+  for (int j = i - 1; j >= 0 && Target[j] == '\\'; --j)
+Res.push_back('\\');
+
+  // Escape the space/tab
+  Res.push_back('\\');
+  break;
+case '$':
+  Res.push_back('$');
+  break;
+case '#':
+  Res.push_back('\\');
+  break;
+default:
+  break;
+}
+
+Res.push_back(Target[i]);
+  }
+}
\ No newline at end of file

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 0081426e698ec..e16f017dd5229 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -27,6 +27,7 @@
 #include 

[PATCH] D127270: [clang-format] Add space in placement new expression

2022-07-13 Thread omar ahmed via Phabricator via cfe-commits
omarahmed added a comment.

I don't have push credentials so If everything is okay with the patch, can you 
push it for me. My email is omarpiratee2...@gmail.com




Comment at: clang/include/clang/Format/Format.h:3555
   AfterFunctionDefinitionName(false), AfterIfMacros(false),
-  AfterOverloadedOperator(false), AfterRequiresInClause(false),
-  AfterRequiresInExpression(false), BeforeNonEmptyParentheses(false) {}
+  AfterOverloadedOperator(false), AfterPlacementOperator(APO_Leave),
+  AfterRequiresInClause(false), AfterRequiresInExpression(false),

HazardyKnusperkeks wrote:
> We change the behavior here, I'm still not convinced we should do that. 
> Although I'm a big supporter of the `Leave` option.
I am neutral to both cases, so I leave the choice to you as I am not 
experienced with clang-format users. Let me know which choice you think would 
be better.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127270/new/

https://reviews.llvm.org/D127270

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


[PATCH] D129594: [InstrProf] Add options to profile function groups

2022-07-13 Thread Ian Levesque via Phabricator via cfe-commits
ianlevesque accepted this revision.
ianlevesque added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129594/new/

https://reviews.llvm.org/D129594

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


[PATCH] D128465: [llvm] add zstd to `llvm::compression` namespace

2022-07-13 Thread Cole Kissane via Phabricator via cfe-commits
ckissane marked 6 inline comments as done.
ckissane added a comment.

Mark handled comments from @MaskRay as done


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128465/new/

https://reviews.llvm.org/D128465

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


[PATCH] D129607: [clang][deps] Fix handling of -MT in module command-line

2022-07-13 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129607/new/

https://reviews.llvm.org/D129607

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


[PATCH] D128090: [Clang][OpenMP] Process multi-arch compilation options given via -march

2022-07-13 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D128090#3649579 , @tra wrote:

> In D128090#3649235 , @jhuber6 wrote:
>
>> Interesting, may be worthwhile to query that if it exists, though AMD does 
>> this with `amdgpu-arch` which has led to problems for me in the past. But 
>> even if it could be wrong it will still spit out an architecture that would 
>> run on at least one local card rather than zero.
>
> We do have existing precedent of `-march=native`, so it may make sense to 
> introduce `--offload-arch=native`, though it may be a bit too ambiguous, 
> considering that there may be more than one likely choice -- multiple GPUs, 
> possibly a mix from different vendors. Perhaps we would need something more 
> specific, like `--offload-arch=native-nvidia`.

That's an interesting idea, we could put that functionality in OpenMP using 
this method as well.

  -Xopenmp-target=nvptx64 -march=native

For CUDA / HIP we could also potentially just make users specify which 
toolchain the native applies to somewhat like `-Xopenmp-target`. Might be a 
more general solution than attaching it to the architecture string.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128090/new/

https://reviews.llvm.org/D128090

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


[PATCH] D129655: [CUDA] Allow the new driver to compile CUDA in non-RDC mode

2022-07-13 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 marked an inline comment as done.
jhuber6 added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:7009
+  // Host-side offloading compilation receives all device-side outputs. Include
+  // them in the host compilation depending on the target.
   if ((IsCuda || IsHIP) && CudaDeviceInput) {

tra wrote:
> I think more details/history would be helpful here. Unlike you and me, the 
> future readers will have little to no context to understand why we do things 
> three different ways here.
I'd like a future with only one way of doing it, but I'll add a comment 
mentioning the new and old drivers to make it clearer.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129655/new/

https://reviews.llvm.org/D129655

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


[PATCH] D129655: [CUDA] Allow the new driver to compile CUDA in non-RDC mode

2022-07-13 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:7009
+  // Host-side offloading compilation receives all device-side outputs. Include
+  // them in the host compilation depending on the target.
   if ((IsCuda || IsHIP) && CudaDeviceInput) {

I think more details/history would be helpful here. Unlike you and me, the 
future readers will have little to no context to understand why we do things 
three different ways here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129655/new/

https://reviews.llvm.org/D129655

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


[PATCH] D128465: [llvm] cmake config groundwork to have ZSTD in LLVM and add ZSTD compression namespace

2022-07-13 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 00.
ckissane added a comment.

tidy some code


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128465/new/

https://reviews.llvm.org/D128465

Files:
  llvm/CMakeLists.txt
  llvm/cmake/config-ix.cmake
  llvm/cmake/modules/FindZSTD.cmake
  llvm/cmake/modules/LLVMConfig.cmake.in
  llvm/include/llvm/Config/llvm-config.h.cmake
  llvm/include/llvm/Support/Compression.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/Compression.cpp
  llvm/test/lit.site.cfg.py.in
  llvm/unittests/Support/CompressionTest.cpp
  utils/bazel/llvm_configs/llvm-config.h.cmake

Index: utils/bazel/llvm_configs/llvm-config.h.cmake
===
--- utils/bazel/llvm_configs/llvm-config.h.cmake
+++ utils/bazel/llvm_configs/llvm-config.h.cmake
@@ -95,6 +95,9 @@
 /* Define if zlib compression is available */
 #cmakedefine01 LLVM_ENABLE_ZLIB
 
+/* Define if zstd compression is available */
+#cmakedefine01 LLVM_ENABLE_ZSTD
+
 /* Define if LLVM was built with a dependency to the libtensorflow dynamic library */
 #cmakedefine LLVM_HAVE_TF_API
 
Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -23,11 +23,9 @@
 namespace {
 
 #if LLVM_ENABLE_ZLIB
-
-void TestZlibCompression(StringRef Input, int Level) {
+static void testZlibCompression(StringRef Input, int Level) {
   SmallString<32> Compressed;
   SmallString<32> Uncompressed;
-
   zlib::compress(Input, Compressed, Level);
 
   // Check that uncompressed buffer is the same as original.
@@ -43,26 +41,63 @@
 }
 
 TEST(CompressionTest, Zlib) {
-  TestZlibCompression("", zlib::DefaultCompression);
+  testZlibCompression("", zlib::DefaultCompression);
 
-  TestZlibCompression("hello, world!", zlib::NoCompression);
-  TestZlibCompression("hello, world!", zlib::BestSizeCompression);
-  TestZlibCompression("hello, world!", zlib::BestSpeedCompression);
-  TestZlibCompression("hello, world!", zlib::DefaultCompression);
+  testZlibCompression("hello, world!", zlib::NoCompression);
+  testZlibCompression("hello, world!", zlib::BestSizeCompression);
+  testZlibCompression("hello, world!", zlib::BestSpeedCompression);
+  testZlibCompression("hello, world!", zlib::DefaultCompression);
 
   const size_t kSize = 1024;
   char BinaryData[kSize];
-  for (size_t i = 0; i < kSize; ++i) {
+  for (size_t i = 0; i < kSize; ++i)
 BinaryData[i] = i & 255;
-  }
   StringRef BinaryDataStr(BinaryData, kSize);
 
-  TestZlibCompression(BinaryDataStr, zlib::NoCompression);
-  TestZlibCompression(BinaryDataStr, zlib::BestSizeCompression);
-  TestZlibCompression(BinaryDataStr, zlib::BestSpeedCompression);
-  TestZlibCompression(BinaryDataStr, zlib::DefaultCompression);
+  testZlibCompression(BinaryDataStr, zlib::NoCompression);
+  testZlibCompression(BinaryDataStr, zlib::BestSizeCompression);
+  testZlibCompression(BinaryDataStr, zlib::BestSpeedCompression);
+  testZlibCompression(BinaryDataStr, zlib::DefaultCompression);
+}
+#endif
+
+#if LLVM_ENABLE_ZSTD
+static void testZstdCompression(StringRef Input, int Level) {
+  SmallString<32> Compressed;
+  SmallString<32> Uncompressed;
+  zstd::compress(Input, Compressed, Level);
+
+  // Check that uncompressed buffer is the same as original.
+  Error E = zstd::uncompress(Compressed, Uncompressed, Input.size());
+  consumeError(std::move(E));
+
+  EXPECT_EQ(Input, Uncompressed);
+  if (Input.size() > 0) {
+// Uncompression fails if expected length is too short.
+E = zstd::uncompress(Compressed, Uncompressed, Input.size() - 1);
+EXPECT_EQ("Destination buffer is too small", llvm::toString(std::move(E)));
+  }
 }
 
+TEST(CompressionTest, Zstd) {
+  testZstdCompression("", zstd::DefaultCompression);
+
+  testZstdCompression("hello, world!", zstd::NoCompression);
+  testZstdCompression("hello, world!", zstd::BestSizeCompression);
+  testZstdCompression("hello, world!", zstd::BestSpeedCompression);
+  testZstdCompression("hello, world!", zstd::DefaultCompression);
+
+  const size_t kSize = 1024;
+  char BinaryData[kSize];
+  for (size_t i = 0; i < kSize; ++i)
+BinaryData[i] = i & 255;
+  StringRef BinaryDataStr(BinaryData, kSize);
+
+  testZstdCompression(BinaryDataStr, zstd::NoCompression);
+  testZstdCompression(BinaryDataStr, zstd::BestSizeCompression);
+  testZstdCompression(BinaryDataStr, zstd::BestSpeedCompression);
+  testZstdCompression(BinaryDataStr, zstd::DefaultCompression);
+}
 #endif
 
 }
Index: llvm/test/lit.site.cfg.py.in
===
--- llvm/test/lit.site.cfg.py.in
+++ llvm/test/lit.site.cfg.py.in
@@ -37,6 +37,7 @@
 config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.have_zstd = 

[PATCH] D128090: [Clang][OpenMP] Process multi-arch compilation options given via -march

2022-07-13 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D128090#3649235 , @jhuber6 wrote:

> Interesting, may be worthwhile to query that if it exists, though AMD does 
> this with `amdgpu-arch` which has led to problems for me in the past. But 
> even if it could be wrong it will still spit out an architecture that would 
> run on at least one local card rather than zero.

We do have existing precedent of `-march=native`, so it may make sense to 
introduce `--offload-arch=native`, though it may be a bit too ambiguous, 
considering that there may be more than one likely chouce -- multiple GPUs, 
possibly a mix from different vendors. Perhaps we would need something more 
specific, like `--offload-arch=native-nvidia`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128090/new/

https://reviews.llvm.org/D128090

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


[PATCH] D129655: [CUDA] Allow the new driver to compile CUDA in non-RDC mode

2022-07-13 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 444398.
jhuber6 marked an inline comment as done.
jhuber6 added a comment.

Updating and making suggested changes. I removed the old `fgpu-rdc` in 
rG6abaa8e2103760025cee76528f555de7cf6698e6 
 since I 
considered it to be reviewed already from the discussion here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129655/new/

https://reviews.llvm.org/D129655

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenCUDA/offloading-entries.cu
  clang/test/Driver/cuda-omp-unsupported-debug-options.cu
  clang/test/Driver/cuda-openmp-driver.cu
  clang/test/Driver/cuda-phases.cu

Index: clang/test/Driver/cuda-phases.cu
===
--- clang/test/Driver/cuda-phases.cu
+++ clang/test/Driver/cuda-phases.cu
@@ -221,25 +221,48 @@
 //
 // Test the phases generated when using the new offloading driver.
 //
-// RUN: %clang -### -target powerpc64le-ibm-linux-gnu -ccc-print-phases --offload-new-driver \
-// RUN: --offload-arch=sm_52 --offload-arch=sm_70 %s 2>&1 | FileCheck --check-prefix=NEW_DRIVER %s
-// NEW_DRIVER: 0: input, "[[INPUT:.+]]", cuda
-// NEW_DRIVER: 1: preprocessor, {0}, cuda-cpp-output
-// NEW_DRIVER: 2: compiler, {1}, ir
-// NEW_DRIVER: 3: input, "[[INPUT]]", cuda, (device-cuda, sm_52)
-// NEW_DRIVER: 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_52)
-// NEW_DRIVER: 5: compiler, {4}, ir, (device-cuda, sm_52)
-// NEW_DRIVER: 6: backend, {5}, assembler, (device-cuda, sm_52)
-// NEW_DRIVER: 7: assembler, {6}, object, (device-cuda, sm_52)
-// NEW_DRIVER: 8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_52)" {7}, object
-// NEW_DRIVER: 9: input, "[[INPUT]]", cuda, (device-cuda, sm_70)
-// NEW_DRIVER: 10: preprocessor, {9}, cuda-cpp-output, (device-cuda, sm_70)
-// NEW_DRIVER: 11: compiler, {10}, ir, (device-cuda, sm_70)
-// NEW_DRIVER: 12: backend, {11}, assembler, (device-cuda, sm_70)
-// NEW_DRIVER: 13: assembler, {12}, object, (device-cuda, sm_70)
-// NEW_DRIVER: 14: offload, "device-cuda (nvptx64-nvidia-cuda:sm_70)" {13}, object
-// NEW_DRIVER: 15: clang-offload-packager, {8, 14}, image
-// NEW_DRIVER: 16: offload, " (powerpc64le-ibm-linux-gnu)" {2}, " (powerpc64le-ibm-linux-gnu)" {15}, ir
-// NEW_DRIVER: 17: backend, {16}, assembler, (host-cuda)
-// NEW_DRIVER: 18: assembler, {17}, object, (host-cuda)
-// NEW_DRIVER: 19: clang-linker-wrapper, {18}, image, (host-cuda)
+// RUN: %clang -### -target powerpc64le-ibm-linux-gnu -ccc-print-phases --offload-new-driver -fgpu-rdc \
+// RUN: --offload-arch=sm_52 --offload-arch=sm_70 %s 2>&1 | FileCheck --check-prefix=NEW-DRIVER-RDC %s
+// NEW-DRIVER-RDC: 0: input, "[[INPUT:.+]]", cuda
+// NEW-DRIVER-RDC: 1: preprocessor, {0}, cuda-cpp-output
+// NEW-DRIVER-RDC: 2: compiler, {1}, ir
+// NEW-DRIVER-RDC: 3: input, "[[INPUT]]", cuda, (device-cuda, sm_52)
+// NEW-DRIVER-RDC: 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_52)
+// NEW-DRIVER-RDC: 5: compiler, {4}, ir, (device-cuda, sm_52)
+// NEW-DRIVER-RDC: 6: backend, {5}, assembler, (device-cuda, sm_52)
+// NEW-DRIVER-RDC: 7: assembler, {6}, object, (device-cuda, sm_52)
+// NEW-DRIVER-RDC: 8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_52)" {7}, object
+// NEW-DRIVER-RDC: 9: input, "[[INPUT]]", cuda, (device-cuda, sm_70)
+// NEW-DRIVER-RDC: 10: preprocessor, {9}, cuda-cpp-output, (device-cuda, sm_70)
+// NEW-DRIVER-RDC: 11: compiler, {10}, ir, (device-cuda, sm_70)
+// NEW-DRIVER-RDC: 12: backend, {11}, assembler, (device-cuda, sm_70)
+// NEW-DRIVER-RDC: 13: assembler, {12}, object, (device-cuda, sm_70)
+// NEW-DRIVER-RDC: 14: offload, "device-cuda (nvptx64-nvidia-cuda:sm_70)" {13}, object
+// NEW-DRIVER-RDC: 15: clang-offload-packager, {8, 14}, image
+// NEW-DRIVER-RDC: 16: offload, " (powerpc64le-ibm-linux-gnu)" {2}, " (powerpc64le-ibm-linux-gnu)" {15}, ir
+// NEW-DRIVER-RDC: 17: backend, {16}, assembler, (host-cuda)
+// NEW-DRIVER-RDC: 18: assembler, {17}, object, (host-cuda)
+// NEW-DRIVER-RDC: 19: clang-linker-wrapper, {18}, image, (host-cuda)
+
+// RUN: %clang -### -target powerpc64le-ibm-linux-gnu -ccc-print-phases --offload-new-driver -fgpu-rdc \
+// RUN: --offload-arch=sm_52 --offload-arch=sm_70 %s 2>&1 | FileCheck --check-prefix=NEW-DRIVER %s
+// NEW-DRIVER: 0: input, "[[INPUT:.+]]", cuda
+// NEW-DRIVER: 1: preprocessor, {0}, cuda-cpp-output
+// NEW-DRIVER: 2: compiler, {1}, ir
+// NEW-DRIVER: 3: input, "[[INPUT]]", cuda, (device-cuda, sm_52)
+// NEW-DRIVER: 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_52)
+// NEW-DRIVER: 5: compiler, {4}, ir, (device-cuda, sm_52)
+// NEW-DRIVER: 6: backend, {5}, assembler, (device-cuda, sm_52)
+// NEW-DRIVER: 7: assembler, {6}, object, (device-cuda, sm_52)
+// NEW-DRIVER: 8: offload, "device-cuda 

[clang] 6abaa8e - [CUDA][HIP][NFC] Do not add `-fgpu-rdc` flag twice

2022-07-13 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-07-13T15:57:53-04:00
New Revision: 6abaa8e2103760025cee76528f555de7cf6698e6

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

LOG: [CUDA][HIP][NFC] Do not add `-fgpu-rdc` flag twice

Summary:
We currently add the `-fgpu-rdc` flag twice. Once unconditionally for
both the host and device phases of compilation, and a second time only
for the host. When we moved to an unconditional addition of this flag it
the old one was most likely not removed. This patch simply removes the
redundant flag and changes no functionality.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cuda-external-tools.cu

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index e187fcec75e2a..0081426e698ec 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7011,8 +7011,6 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   if ((IsCuda || IsHIP) && CudaDeviceInput) {
   CmdArgs.push_back("-fcuda-include-gpubinary");
   CmdArgs.push_back(CudaDeviceInput->getFilename());
-  if (Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false))
-CmdArgs.push_back("-fgpu-rdc");
   }
 
   if (IsCuda) {

diff  --git a/clang/test/Driver/cuda-external-tools.cu 
b/clang/test/Driver/cuda-external-tools.cu
index 198443e475bf9..1aa87cc09982c 100644
--- a/clang/test/Driver/cuda-external-tools.cu
+++ b/clang/test/Driver/cuda-external-tools.cu
@@ -160,7 +160,5 @@
 // ARCH64-SAME: "-triple" "x86_64-
 // ARCH32-SAME: "-triple" "i386-
 // CHECK-SAME: "-fcuda-include-gpubinary" "[[FATBINARY]]"
-// RDC-SAME: "-fgpu-rdc"
-// CHECK-NOT: "-fgpu-rdc"
 
 // CHK-PTXAS-VERBOSE: ptxas{{.*}}" "-v"



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


[PATCH] D126735: [clang-tidy] Silence modernize-redundant-void-arg in the case of vexing parses

2022-07-13 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv updated this revision to Diff 444397.
george.burgess.iv added a comment.

Rebased on top of 891319f654c102572cf7028ed04bbaf6c59e7bff 
 as 
requested; `ninja check-clang-extra docs-clang-tools-html` passes


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126735/new/

https://reviews.llvm.org/D126735

Files:
  clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp
@@ -592,3 +592,9 @@
   (void)a;
 }
 #undef return_t
+
+// Explicitly specifying `(void)` is a way to sidestep -Wvexing-parse, so we
+// should not warn about it here.
+void most_vexing_parse() {
+  int foo(void);
+}
Index: clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -109,9 +109,13 @@
 }
 removeVoidArgumentTokens(Result, SourceRange(Start, End),
  "function definition");
-  } else
+  } else if (!Function->getLexicalDeclContext()->isFunctionOrMethod()) {
+// Only do this if our decl context is outside of a function or method;
+// otherwise, the user may have explicitly written `(void)` to avoid Most
+// Vexing Parse warnings.
 removeVoidArgumentTokens(Result, SourceRange(Start, End),
  "function declaration");
+  }
 }
 
 bool isMacroIdentifier(const IdentifierTable , const Token ) 
{


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp
@@ -592,3 +592,9 @@
   (void)a;
 }
 #undef return_t
+
+// Explicitly specifying `(void)` is a way to sidestep -Wvexing-parse, so we
+// should not warn about it here.
+void most_vexing_parse() {
+  int foo(void);
+}
Index: clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -109,9 +109,13 @@
 }
 removeVoidArgumentTokens(Result, SourceRange(Start, End),
  "function definition");
-  } else
+  } else if (!Function->getLexicalDeclContext()->isFunctionOrMethod()) {
+// Only do this if our decl context is outside of a function or method;
+// otherwise, the user may have explicitly written `(void)` to avoid Most
+// Vexing Parse warnings.
 removeVoidArgumentTokens(Result, SourceRange(Start, End),
  "function declaration");
+  }
 }
 
 bool isMacroIdentifier(const IdentifierTable , const Token ) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129655: [CUDA] Allow the new driver to compile CUDA in non-RDC mode

2022-07-13 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 marked an inline comment as done.
jhuber6 added a comment.

It's also worth noting that this doesn't include the `PTX` output for JIT in 
the fatbinary, it would be relatively easy to include that but I wanted to ask 
how we should handle that.




Comment at: clang/lib/Driver/ToolChains/Clang.cpp:6999
+if (IsRDCMode)
+  CmdArgs.push_back("-fgpu-rdc");
+  } else if (IsCuda && !HostOffloadingInputs.empty() && !IsRDCMode) {

tra wrote:
> This should not be necessary -- we've already added it for all CUDA/HIP 
> compilations above.
What I figured, I think I'm just going to prune it in a separate commit to 
clean this up.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:7003
+CmdArgs.push_back(HostOffloadingInputs.front().getFilename());
+  } else {
+for (const InputInfo Input : HostOffloadingInputs)

tra wrote:
> I'm not sure I understand when we'd end up in this "else" branch.
> Perhaps the whole sequence could be restructured this way:
> 
> ```
> if ((IsCuda || IsHIP) && CudaDeviceInput) { // old-style embedding
> CmdArgs.push_back("-fcuda-include-gpubinary");
> CmdArgs.push_back(CudaDeviceInput->getFilename());
> } else if (!HostOffloadingInputs.empty()) { // new-driver offloading mode
>   if (Cuda && !IsRDCMode) {
> assert(HostOffloadingInputs.size() == 1); // We should have only one GPU 
> fatbinary to embed. Uses old-style embedding.
> CmdArgs.push_back("-fcuda-include-gpubinary");
> CmdArgs.push_back(HostOffloadingInputs.front().getFilename());
>   } else { // new driver embedding of GPU object files.
>  for (const InputInfo Input : HostOffloadingInputs)
> CmdArgs.push_back(Args.MakeArgString("-fembed-offload-object=" +
>  TC.getInputFilename(Input)));
>   }
> }
> ```
> 
This is clearer, I'll change it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129655/new/

https://reviews.llvm.org/D129655

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


[PATCH] D112374: [clang] Implement ElaboratedType sugaring for types written bare

2022-07-13 Thread Kim Gräsman via Phabricator via cfe-commits
kimgr added a comment.

This patch also broke IWYU, not exactly sure how or why yet. We run around the 
AST quite a bit, so structural changes like this often bite us.

Can you expand on what happened here? Before/after kind-of thing? Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112374/new/

https://reviews.llvm.org/D112374

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


[PATCH] D119296: KCFI sanitizer

2022-07-13 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Worth waiting a bit and checking whether @pcc has more comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119296/new/

https://reviews.llvm.org/D119296

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


[PATCH] D119296: KCFI sanitizer

2022-07-13 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp:332
+
+  Register AddrReg = MI.getOperand(0).getReg();
+

MaskRay wrote:
> Add const. Delete blank line after the declaration.
Deleted the blank line, but this can't be `const` because it's assigned to in 
the `if` statement below.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119296/new/

https://reviews.llvm.org/D119296

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


[clang] 1a5c1ee - [LinkerWrapper] Fix deleted constructor error on older compilers

2022-07-13 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-07-13T15:45:35-04:00
New Revision: 1a5c1ee5b8bb580ce35e660f9ea907148c6bf627

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

LOG: [LinkerWrapper] Fix deleted constructor error on older compilers

Summary:
The previous patch moved some functoinality into a new function and
returned it. The vector contained move-only members. Newer compilers
should figure this out and I didn't notice any problems, but other ones
have problems. Explicitly move this vector to hopefully solve the issue.

Added: 


Modified: 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index a3ff6fba3748..cf1a9d39ee16 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -1474,7 +1474,7 @@ Expected> getDeviceInput(const 
ArgList ) {
 if (IsTargetUsed.contains(LazyFile))
   InputFiles.emplace_back(std::move(LazyFile));
 
-  return InputFiles;
+  return std::move(InputFiles);
 }
 
 } // namespace



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


[PATCH] D129373: [NFC] Minor cleanup of usage of FloatModeKind with bitmask enums

2022-07-13 Thread Jolanta Jensen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG07df9e918e3f: [NFC] Minor cleanup of usage of FloatModeKind 
with bitmask enums (authored by jolanta.jensen).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129373/new/

https://reviews.llvm.org/D129373

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/X86.h


Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -421,8 +421,8 @@
 
 // Use fpret for all types.
 RealTypeUsesObjCFPRetMask =
-(int)(FloatModeKind::Float | FloatModeKind::Double |
-  FloatModeKind::LongDouble);
+(unsigned)(FloatModeKind::Float | FloatModeKind::Double |
+   FloatModeKind::LongDouble);
 
 // x86-32 has atomics up to 8 bytes
 MaxAtomicPromoteWidth = 64;
@@ -701,7 +701,7 @@
 "64-i64:64-f80:128-n8:16:32:64-S128");
 
 // Use fpret only for long double.
-RealTypeUsesObjCFPRetMask = (int)FloatModeKind::LongDouble;
+RealTypeUsesObjCFPRetMask = (unsigned)FloatModeKind::LongDouble;
 
 // Use fp2ret for _Complex long double.
 ComplexLongDoubleUsesFP2Ret = true;
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -222,9 +222,7 @@
   mutable VersionTuple PlatformMinVersion;
 
   unsigned HasAlignMac68kSupport : 1;
-  unsigned RealTypeUsesObjCFPRetMask
-  : llvm::BitmaskEnumDetail::bitWidth(
-(int)FloatModeKind::LLVM_BITMASK_LARGEST_ENUMERATOR);
+  unsigned RealTypeUsesObjCFPRetMask : llvm::BitWidth;
   unsigned ComplexLongDoubleUsesFP2Ret : 1;
 
   unsigned HasBuiltinMSVaList : 1;
@@ -893,7 +891,7 @@
   /// Check whether the given real type should use the "fpret" flavor of
   /// Objective-C message passing on this target.
   bool useObjCFPRetForRealType(FloatModeKind T) const {
-return RealTypeUsesObjCFPRetMask & llvm::BitmaskEnumDetail::Underlying(T);
+return (int)((FloatModeKind)RealTypeUsesObjCFPRetMask & T);
   }
 
   /// Check whether _Complex long double should use the "fp2ret" flavor


Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -421,8 +421,8 @@
 
 // Use fpret for all types.
 RealTypeUsesObjCFPRetMask =
-(int)(FloatModeKind::Float | FloatModeKind::Double |
-  FloatModeKind::LongDouble);
+(unsigned)(FloatModeKind::Float | FloatModeKind::Double |
+   FloatModeKind::LongDouble);
 
 // x86-32 has atomics up to 8 bytes
 MaxAtomicPromoteWidth = 64;
@@ -701,7 +701,7 @@
 "64-i64:64-f80:128-n8:16:32:64-S128");
 
 // Use fpret only for long double.
-RealTypeUsesObjCFPRetMask = (int)FloatModeKind::LongDouble;
+RealTypeUsesObjCFPRetMask = (unsigned)FloatModeKind::LongDouble;
 
 // Use fp2ret for _Complex long double.
 ComplexLongDoubleUsesFP2Ret = true;
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -222,9 +222,7 @@
   mutable VersionTuple PlatformMinVersion;
 
   unsigned HasAlignMac68kSupport : 1;
-  unsigned RealTypeUsesObjCFPRetMask
-  : llvm::BitmaskEnumDetail::bitWidth(
-(int)FloatModeKind::LLVM_BITMASK_LARGEST_ENUMERATOR);
+  unsigned RealTypeUsesObjCFPRetMask : llvm::BitWidth;
   unsigned ComplexLongDoubleUsesFP2Ret : 1;
 
   unsigned HasBuiltinMSVaList : 1;
@@ -893,7 +891,7 @@
   /// Check whether the given real type should use the "fpret" flavor of
   /// Objective-C message passing on this target.
   bool useObjCFPRetForRealType(FloatModeKind T) const {
-return RealTypeUsesObjCFPRetMask & llvm::BitmaskEnumDetail::Underlying(T);
+return (int)((FloatModeKind)RealTypeUsesObjCFPRetMask & T);
   }
 
   /// Check whether _Complex long double should use the "fp2ret" flavor
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 07df9e9 - [NFC] Minor cleanup of usage of FloatModeKind with bitmask enums

2022-07-13 Thread Jolanta Jensen via cfe-commits

Author: Jolanta Jensen
Date: 2022-07-13T20:44:06+01:00
New Revision: 07df9e918e3f6b8d99eaae0243a17e18a7bdd860

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

LOG: [NFC] Minor cleanup of usage of FloatModeKind with bitmask enums

Differential Revision: https://reviews.llvm.org/D129373

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/Targets/X86.h

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 0ab3e9b67dfe8..b4f3a69259fad 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -222,9 +222,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   mutable VersionTuple PlatformMinVersion;
 
   unsigned HasAlignMac68kSupport : 1;
-  unsigned RealTypeUsesObjCFPRetMask
-  : llvm::BitmaskEnumDetail::bitWidth(
-(int)FloatModeKind::LLVM_BITMASK_LARGEST_ENUMERATOR);
+  unsigned RealTypeUsesObjCFPRetMask : llvm::BitWidth;
   unsigned ComplexLongDoubleUsesFP2Ret : 1;
 
   unsigned HasBuiltinMSVaList : 1;
@@ -893,7 +891,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   /// Check whether the given real type should use the "fpret" flavor of
   /// Objective-C message passing on this target.
   bool useObjCFPRetForRealType(FloatModeKind T) const {
-return RealTypeUsesObjCFPRetMask & llvm::BitmaskEnumDetail::Underlying(T);
+return (int)((FloatModeKind)RealTypeUsesObjCFPRetMask & T);
   }
 
   /// Check whether _Complex long double should use the "fp2ret" flavor

diff  --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 00662517ae37c..ea98dcf42de65 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -421,8 +421,8 @@ class LLVM_LIBRARY_VISIBILITY X86_32TargetInfo : public 
X86TargetInfo {
 
 // Use fpret for all types.
 RealTypeUsesObjCFPRetMask =
-(int)(FloatModeKind::Float | FloatModeKind::Double |
-  FloatModeKind::LongDouble);
+(unsigned)(FloatModeKind::Float | FloatModeKind::Double |
+   FloatModeKind::LongDouble);
 
 // x86-32 has atomics up to 8 bytes
 MaxAtomicPromoteWidth = 64;
@@ -701,7 +701,7 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public 
X86TargetInfo {
 "64-i64:64-f80:128-n8:16:32:64-S128");
 
 // Use fpret only for long double.
-RealTypeUsesObjCFPRetMask = (int)FloatModeKind::LongDouble;
+RealTypeUsesObjCFPRetMask = (unsigned)FloatModeKind::LongDouble;
 
 // Use fp2ret for _Complex long double.
 ComplexLongDoubleUsesFP2Ret = true;



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


[PATCH] D128465: [llvm] cmake config groundwork to have ZSTD in LLVM and add ZSTD compression namespace

2022-07-13 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

The patch looks mostly good but please fix the subject and the summary.

Note: if you fix the local commit message, you can use ` arc diff --head=HEAD 
'HEAD^' --verbatim` to update the subject and the summary.




Comment at: llvm/lib/Support/Compression.cpp:87
  UncompressedSize);
-  UncompressedBuffer.truncate(UncompressedSize);
+  if (UncompressedSize < UncompressedBuffer.size()) {
+UncompressedBuffer.truncate(UncompressedSize);

https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements

ditto below



Comment at: llvm/lib/Support/Compression.cpp:133
+   size_t ) {
+  size_t const Res =
+  ::ZSTD_decompress((char *)UncompressedBuffer, UncompressedSize,

`const size_t`



Comment at: llvm/unittests/Support/CompressionTest.cpp:69
+#if LLVM_ENABLE_ZSTD
+
+void TestZstdCompression(StringRef Input, int Level) {

delete blank line



Comment at: llvm/unittests/Support/CompressionTest.cpp:70
+
+void TestZstdCompression(StringRef Input, int Level) {
+  SmallString<32> Compressed;

`static void testZstd...`



Comment at: llvm/unittests/Support/CompressionTest.cpp:73
+  SmallString<32> Uncompressed;
+
+  zstd::compress(Input, Compressed, Level);

delete blank line 



Comment at: llvm/unittests/Support/CompressionTest.cpp:99
+  for (size_t i = 0; i < kSize; ++i) {
+BinaryData[i] = i & 255;
+  }

https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128465/new/

https://reviews.llvm.org/D128465

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


[clang] c70db40 - [LinkerWrapper] Support time tracing in the linker wrapper

2022-07-13 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-07-13T15:38:39-04:00
New Revision: c70db40ceb65ef5ad4549a0ad4665ed88a5e2224

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

LOG: [LinkerWrapper] Support time tracing in the linker wrapper

Summary:
This patch adds the new `--wrapper-time-trace=` option to write a time
tracing JSON file indicating where time was spent in the linker wrapper.
We also reformat and group some of the existing code to make
constraining the scope easier for time tracing.  We use the `--wrapper`
prefix to set this apart from the time tracing that lld may use.

Added: 


Modified: 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td

Removed: 




diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 898fa71d30e3..a3ff6fba3748 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -262,11 +262,29 @@ Expected findProgram(StringRef Name, 
ArrayRef Paths) {
   return *Path;
 }
 
-Error runLinker(StringRef LinkerPath, ArgStringList LinkerArgs) {
-  SmallVector Args({LinkerPath});
-  for (StringRef Arg : LinkerArgs)
-Args.push_back(Arg);
-  if (Error Err = executeCommands(LinkerPath, Args))
+/// Runs the wrapped linker job with the newly created input.
+Error runLinker(ArrayRef Files, const ArgList ) {
+  llvm::TimeTraceScope TimeScope("Execute host linker");
+
+  // Render the linker arguments and add the newly created image. We add it
+  // after the output file to ensure it is linked with the correct libraries.
+  StringRef LinkerPath = Args.getLastArgValue(OPT_linker_path_EQ);
+  ArgStringList NewLinkerArgs;
+  for (const opt::Arg *Arg : Args) {
+// Do not forward arguments only intended for the linker wrapper.
+if (Arg->getOption().hasFlag(WrapperOnlyOption))
+  continue;
+
+Arg->render(Args, NewLinkerArgs);
+if (Arg->getOption().matches(OPT_o))
+  llvm::transform(Files, std::back_inserter(NewLinkerArgs),
+  [&](StringRef Arg) { return Args.MakeArgString(Arg); });
+  }
+
+  SmallVector LinkerArgs({LinkerPath});
+  for (StringRef Arg : NewLinkerArgs)
+LinkerArgs.push_back(Arg);
+  if (Error Err = executeCommands(LinkerPath, LinkerArgs))
 return Err;
   return Error::success();
 }
@@ -422,6 +440,7 @@ Error extractFromBuffer(std::unique_ptr 
Buffer,
 namespace nvptx {
 Expected assemble(StringRef InputFile, const ArgList ,
  bool RDC = true) {
+  llvm::TimeTraceScope TimeScope("NVPTX Assembler");
   // NVPTX uses the ptxas binary to create device object files.
   Expected PtxasPath = findProgram("ptxas", {CudaBinaryPath});
   if (!PtxasPath)
@@ -462,6 +481,7 @@ Expected assemble(StringRef InputFile, const 
ArgList ,
 }
 
 Expected link(ArrayRef InputFiles, const ArgList ) {
+  llvm::TimeTraceScope TimeScope("NVPTX linker");
   // NVPTX uses the nvlink binary to link device object files.
   Expected NvlinkPath = findProgram("nvlink", {CudaBinaryPath});
   if (!NvlinkPath)
@@ -505,6 +525,7 @@ Expected link(ArrayRef InputFiles, 
const ArgList ) {
 Expected
 fatbinary(ArrayRef> InputFiles,
   const ArgList ) {
+  llvm::TimeTraceScope TimeScope("NVPTX fatbinary");
   // NVPTX uses the fatbinary program to bundle the linked images.
   Expected FatBinaryPath =
   findProgram("fatbinary", {CudaBinaryPath});
@@ -539,6 +560,7 @@ fatbinary(ArrayRef> 
InputFiles,
 
 namespace amdgcn {
 Expected link(ArrayRef InputFiles, const ArgList ) {
+  llvm::TimeTraceScope TimeScope("AMDGPU linker");
   // AMDGPU uses lld to link device object files.
   Expected LLDPath =
   findProgram("lld", {getMainExecutable("lld")});
@@ -583,6 +605,8 @@ Expected link(ArrayRef InputFiles, 
const ArgList ) {
 Expected
 fatbinary(ArrayRef> InputFiles,
   const ArgList ) {
+  llvm::TimeTraceScope TimeScope("AMDGPU Fatbinary");
+
   // AMDGPU uses the clang-offload-bundler to bundle the linked images.
   Expected OffloadBundlerPath = findProgram(
   "clang-offload-bundler", {getMainExecutable("clang-offload-bundler")});
@@ -654,6 +678,7 @@ const char *getLDMOption(const llvm::Triple ) {
 }
 
 Expected link(ArrayRef InputFiles, const ArgList ) {
+  llvm::TimeTraceScope TimeScope("Generic linker");
   const llvm::Triple Triple(Args.getLastArgValue(OPT_triple_EQ));
   StringRef Arch = Args.getLastArgValue(OPT_arch_EQ);
 
@@ -846,6 +871,7 @@ bool isValidCIdentifier(StringRef S) {
 Error linkBitcodeFiles(SmallVectorImpl ,
SmallVectorImpl ,
const ArgList ) {
+  llvm::TimeTraceScope TimeScope("Link bitcode files");
   const llvm::Triple 

[clang] 96f16a6 - [LinkerWrapper] Add support for timescope tracing

2022-07-13 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-07-13T15:38:39-04:00
New Revision: 96f16a6867f78e42e67807cbd357546a95b2a9b6

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

LOG: [LinkerWrapper] Add support for timescope tracing

Added: 


Modified: 
clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td

Removed: 




diff  --git a/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td 
b/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
index 4449ac897bc91..f197082a9afa6 100644
--- a/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
+++ b/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
@@ -52,6 +52,10 @@ def print_wrapped_module : Flag<["--"], 
"print-wrapped-module">,
 def save_temps : Flag<["--"], "save-temps">,
   Flags<[WrapperOnlyOption]>, HelpText<"Save intermediate results">;
 
+def wrapper_time_trace_eq : Joined<["--"], "wrapper-time-trace=">,
+  Flags<[WrapperOnlyOption]>, MetaVarName<"">,
+  HelpText<"Enable time-trace and write the output to ">;
+
 // Flags passed to the device linker.
 def arch_EQ : Joined<["--"], "arch=">,
   Flags<[DeviceOnlyOption, HelpHidden]>, MetaVarName<"">,



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


[PATCH] D129655: [CUDA] Allow the new driver to compile CUDA in non-RDC mode

2022-07-13 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

Nice.




Comment at: clang/lib/Driver/ToolChains/Clang.cpp:6999
+if (IsRDCMode)
+  CmdArgs.push_back("-fgpu-rdc");
+  } else if (IsCuda && !HostOffloadingInputs.empty() && !IsRDCMode) {

This should not be necessary -- we've already added it for all CUDA/HIP 
compilations above.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:7003
+CmdArgs.push_back(HostOffloadingInputs.front().getFilename());
+  } else {
+for (const InputInfo Input : HostOffloadingInputs)

I'm not sure I understand when we'd end up in this "else" branch.
Perhaps the whole sequence could be restructured this way:

```
if ((IsCuda || IsHIP) && CudaDeviceInput) { // old-style embedding
CmdArgs.push_back("-fcuda-include-gpubinary");
CmdArgs.push_back(CudaDeviceInput->getFilename());
} else if (!HostOffloadingInputs.empty()) { // new-driver offloading mode
  if (Cuda && !IsRDCMode) {
assert(HostOffloadingInputs.size() == 1); // We should have only one GPU 
fatbinary to embed. Uses old-style embedding.
CmdArgs.push_back("-fcuda-include-gpubinary");
CmdArgs.push_back(HostOffloadingInputs.front().getFilename());
  } else { // new driver embedding of GPU object files.
 for (const InputInfo Input : HostOffloadingInputs)
CmdArgs.push_back(Args.MakeArgString("-fembed-offload-object=" +
 TC.getInputFilename(Input)));
  }
}
```



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129655/new/

https://reviews.llvm.org/D129655

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


[PATCH] D118350: [Clang][Sema][AIX][PowerPC] Emit byval alignment warning only when struct is passed to a function

2022-07-13 Thread Zarko Todorovski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa61b202d4e3b: [Clang][Sema][AIX][PowerPC] Emit byval 
alignment warning only when struct is… (authored by ZarkoCA).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118350/new/

https://reviews.llvm.org/D118350

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Analysis/padding_c.c
  clang/test/Analysis/padding_cpp.cpp
  clang/test/CXX/drs/dr6xx.cpp
  clang/test/Sema/aix-attr-align.c
  clang/test/SemaTemplate/instantiate-attr.cpp

Index: clang/test/SemaTemplate/instantiate-attr.cpp
===
--- clang/test/SemaTemplate/instantiate-attr.cpp
+++ clang/test/SemaTemplate/instantiate-attr.cpp
@@ -1,7 +1,4 @@
-// FIXME -Wno-aix-compat added temporarily while the diagnostic is being
-// refined.
-
-// RUN: %clang_cc1 -fsyntax-only -verify -Wno-aix-compat %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s
 // expected-no-diagnostics
 template 
 struct A {
Index: clang/test/Sema/aix-attr-align.c
===
--- clang/test/Sema/aix-attr-align.c
+++ clang/test/Sema/aix-attr-align.c
@@ -5,18 +5,37 @@
 // RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -verify=off -Wno-aix-compat -fsyntax-only %s
 // RUN: %clang_cc1 -triple powerpc64le-unknown-linux -verify=off -fsyntax-only %s
 
-struct S {
-  int a[8] __attribute__((aligned(8))); // no-warning
+// We do not warn on any declaration with a member aligned 16. Only when the struct is passed byval.
+struct R {
+  int b[8] __attribute__((aligned(16))); // no-warning
 };
 
-struct T {
-  int a[4] __attribute__((aligned(16))); // expected-warning {{requesting an alignment of 16 bytes or greater for struct members is not binary compatible with IBM XL C/C++ for AIX 16.1.0 and older}}
+struct S {
+  int a[8] __attribute__((aligned(8)));  // no-warning
+  int b[8] __attribute__((aligned(16))); // expected-warning {{alignment of 16 bytes for a struct member is not binary compatible with IBM XL C/C++ for AIX 16.1.0 or older}}
 };
 
-struct U {
-  int a[2] __attribute__((aligned(32))); // expected-warning {{requesting an alignment of 16 bytes or greater for struct members is not binary compatible with IBM XL C/C++ for AIX 16.1.0 and older}}
+struct T {
+  int a[8] __attribute__((aligned(8))); // no-warning
+  int b[8] __attribute__((aligned(4))); // no-warning
 };
 
 int a[8] __attribute__((aligned(8)));  // no-warning
 int b[4] __attribute__((aligned(16))); // no-warning
-int c[2] __attribute__((aligned(32))); // no-warning
+
+void baz(int a, int b, int *c, int d, int *e, int f, struct S);
+void jaz(int a, int b, int *c, int d, int *e, int f, struct T);
+void vararg_baz(int a,...);
+static void static_baz(int a, int b, int *c, int d, int *e, int f, struct S sp2) {
+  a = *sp2.b + *c + *e;
+}
+
+void foo(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8,
+ struct S s, struct T t) {
+
+  baz(p1, p2, s.b, p3, b, p5, s);// expected-note {{passing byval argument 's' with potentially incompatible alignment here}}
+  jaz(p1, p2, a, p3, s.a, p5, t);// no-note
+  jaz(p1, p2, s.b, p3, b, p5, t);// no-note
+  vararg_baz(p1, p2, s.b, p3, b, p5, s); // no-note
+  static_baz(p1, p2, s.b, p3, b, p5, s); // no-note
+}
Index: clang/test/CXX/drs/dr6xx.cpp
===
--- clang/test/CXX/drs/dr6xx.cpp
+++ clang/test/CXX/drs/dr6xx.cpp
@@ -1,10 +1,8 @@
-// FIXME -Wno-aix-compat added temporarily while the diagnostic is being
-// refined.
-// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking -Wno-aix-compat
-// RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking -Wno-aix-compat
-// RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking -Wno-aix-compat
-// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking -Wno-aix-compat
-// RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking -Wno-aix-compat
+// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
+// RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
+// RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
+// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
+// RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
 
 namespace std {
   struct type_info {};
Index: 

[clang] a61b202 - [Clang][Sema][AIX][PowerPC] Emit byval alignment warning only when struct is passed to a function

2022-07-13 Thread Zarko Todorovski via cfe-commits

Author: Zarko Todorovski
Date: 2022-07-13T15:32:29-04:00
New Revision: a61b202d4e3b00bf6bfd71dc1ea354d37f73b791

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

LOG: [Clang][Sema][AIX][PowerPC] Emit byval alignment warning only when struct 
is passed to a function

Previous warning went on whenever a struct with a struct member with alignment 
=> 16
was declared. This led to too many false positives and led to diagnostic lit 
failures
due to it being emitted too frequently. Only emit the warning when such a 
struct and
that struct contains a member that has an alignment of 16 bytes is passed to a 
caller
function since this is where the potential binary compatibility issue with XL 
16.1.0
and older exists.

Reviewed By: sfertile, aaron.ballman

Differential Revision: https://reviews.llvm.org/D118350

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Analysis/padding_c.c
clang/test/Analysis/padding_cpp.cpp
clang/test/CXX/drs/dr6xx.cpp
clang/test/Sema/aix-attr-align.c
clang/test/SemaTemplate/instantiate-attr.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index ca6390a02ce82..550029f58b546 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3341,10 +3341,11 @@ def warn_assume_aligned_too_great
   "alignment assumed">,
   InGroup>;
 def warn_not_xl_compatible
-: Warning<"requesting an alignment of 16 bytes or greater for struct"
-  " members is not binary compatible with IBM XL C/C++ for AIX"
-  " 16.1.0 and older">,
+: Warning<"alignment of 16 bytes for a struct member is not binary "
+  "compatible with IBM XL C/C++ for AIX 16.1.0 or older">,
   InGroup;
+def note_misaligned_member_used_here : Note<
+"passing byval argument %0 with potentially incompatible alignment here">;
 def warn_redeclaration_without_attribute_prev_attribute_ignored : Warning<
   "%q0 redeclared without %1 attribute: previous %1 ignored">,
   InGroup;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 75a2e7eb31d19..e51b9daef7d3e 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13039,6 +13039,8 @@ class Sema final {
 ArrayRef Args,
 const FunctionProtoType *Proto, SourceLocation 
Loc);
 
+  void checkAIXMemberAlignment(SourceLocation Loc, const Expr *Arg);
+
   void CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl,
  StringRef ParamName, QualType ArgTy, QualType 
ParamTy);
 

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index d3929361213ad..df602f168dbc6 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5626,6 +5626,40 @@ static void CheckNonNullArguments(Sema ,
   }
 }
 
+// 16 byte ByVal alignment not due to a vector member is not honoured by XL
+// on AIX. Emit a warning here that users are generating binary incompatible
+// code to be safe.
+// Here we try to get information about the alignment of the struct member
+// from the struct passed to the caller function. We only warn when the struct
+// is passed byval, hence the series of checks and early returns if we are a 
not
+// passing a struct byval.
+void Sema::checkAIXMemberAlignment(SourceLocation Loc, const Expr *Arg) {
+  const auto *ICE = dyn_cast(Arg->IgnoreParens());
+  if (!ICE)
+return;
+
+  const auto *DR = dyn_cast(ICE->getSubExpr());
+  if (!DR)
+return;
+
+  const auto *PD = dyn_cast(DR->getDecl());
+  if (!PD || !PD->getType()->isRecordType())
+return;
+
+  QualType ArgType = Arg->getType();
+  for (const FieldDecl *FD :
+   ArgType->castAs()->getDecl()->fields()) {
+if (const auto *AA = FD->getAttr()) {
+  CharUnits Alignment =
+  Context.toCharUnitsFromBits(AA->getAlignment(Context));
+  if (Alignment.getQuantity() == 16) {
+Diag(FD->getLocation(), diag::warn_not_xl_compatible) << FD;
+Diag(Loc, diag::note_misaligned_member_used_here) << PD;
+  }
+}
+  }
+}
+
 /// Warn if a pointer or reference argument passed to a function points to an
 /// object that is less aligned than the parameter. This can happen when
 /// creating a typedef with a lower alignment than the original type and then
@@ -5736,6 +5770,12 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 if (Arg->containsErrors())
   continue;
 
+if 

[PATCH] D129664: [Clang] Adjust extension warnings for delimited sequences

2022-07-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM! If for some very surprising reason either of these papers fail in 
plenary, we can easily revert this as necessary.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129664/new/

https://reviews.llvm.org/D129664

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


[PATCH] D129655: [CUDA] Allow the new driver to compile CUDA in non-RDC mode

2022-07-13 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:6998-6999
+CmdArgs.push_back(CudaDeviceInput->getFilename());
+if (IsRDCMode)
+  CmdArgs.push_back("-fgpu-rdc");
+  } else if (IsCuda && !HostOffloadingInputs.empty() && !IsRDCMode) {

Why do we add `-fgpu-rdc` here when it's already added on line 6322 above?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129655/new/

https://reviews.llvm.org/D129655

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


[PATCH] D127363: [Lex] Fix for char32_t literal truncation on 16 bit architectures

2022-07-13 Thread Sebastian Perta via Phabricator via cfe-commits
SebastianPerta added a comment.

>> Additionally, the type of a character constant in C is int.

This means that char32_t c4 = U'\U00064321'; is invalid in C. I know that is 
clang more strict with the standard than GCC, however I would like to mention 
that in GCC the value is not truncated to 16 bit which is I found this problem 
originally. I suppose we want to stick with the standard in clang.

>> My reading of https://eel.is/c++draft/lex.ccon#2 is that a multi-char char 
>> literal with a L/u8/u/U prefix is not int but the respective character types

As explained by @tahonermann is just in case of C in case of C++ literals have 
their respective character types:
I checked char8_t, char16_t and char32_t with u8,u and U respectively and the 
following line of code by @tahonermann works in all 3 cases.
unsigned BitWidth = getCharWidth(Kind, PP.getTargetInfo());
Since Kind will be utf8_char_constant, utf16_char_constant and 
utf32_char_constant respectively.
And since L is not supported I think all cases are accounted for. 
Or am I missing something?
In case not, should I continue to put another patch together with suggested 
changes?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127363/new/

https://reviews.llvm.org/D127363

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


[PATCH] D129683: [Sema] Move Diags.isIgnored() checks off hot paths, it's not free. NFC

2022-07-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added a subscriber: usaxena95.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added a project: clang.

This speeds up clangd's buildAST() (i.e. parsing with a preamble) by 5% on
clangd/AST.cpp, by avoiding filling up the diagnostic state map with entries for
all the files where templates are being instantiated from.

(I would assume it has a similar effect on PCH and modules compiles).

This approach is obviously pretty fragile, and we should find ways to make
isIgnored() cheaper instead. But these changes in particular don't seem to make
the code worse in any case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129683

Files:
  clang/lib/Sema/Sema.cpp


Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -582,9 +582,6 @@
 }
 
 void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr* E) {
-  if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
-  E->getBeginLoc()))
-return;
   // nullptr only exists from C++11 on, so don't warn on its absence earlier.
   if (!getLangOpts().CPlusPlus11)
 return;
@@ -594,6 +591,10 @@
   if (E->IgnoreParenImpCasts()->getType()->isNullPtrType())
 return;
 
+  if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
+  E->getBeginLoc()))
+return;
+
   // Don't diagnose the conversion from a 0 literal to a null pointer argument
   // in a synthesized call to operator<=>.
   if (!CodeSynthesisContexts.empty() &&


Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -582,9 +582,6 @@
 }
 
 void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr* E) {
-  if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
-  E->getBeginLoc()))
-return;
   // nullptr only exists from C++11 on, so don't warn on its absence earlier.
   if (!getLangOpts().CPlusPlus11)
 return;
@@ -594,6 +591,10 @@
   if (E->IgnoreParenImpCasts()->getType()->isNullPtrType())
 return;
 
+  if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
+  E->getBeginLoc()))
+return;
+
   // Don't diagnose the conversion from a 0 literal to a null pointer argument
   // in a synthesized call to operator<=>.
   if (!CodeSynthesisContexts.empty() &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129048: Rewording the "static_assert" to static assertion

2022-07-13 Thread Muhammad Usman Shahid via Phabricator via cfe-commits
Codesbyusman added a comment.

ok. I will take care of this next time. Thank you.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129048/new/

https://reviews.llvm.org/D129048

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


[PATCH] D128465: [llvm] cmake config groundwork to have ZSTD in LLVM and add ZSTD compression namespace

2022-07-13 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 444374.
ckissane added a comment.

- Trim CMAKE modifications to minimum needed


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128465/new/

https://reviews.llvm.org/D128465

Files:
  llvm/CMakeLists.txt
  llvm/cmake/config-ix.cmake
  llvm/cmake/modules/FindZSTD.cmake
  llvm/cmake/modules/LLVMConfig.cmake.in
  llvm/include/llvm/Config/llvm-config.h.cmake
  llvm/include/llvm/Support/Compression.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/Compression.cpp
  llvm/test/lit.site.cfg.py.in
  llvm/unittests/Support/CompressionTest.cpp
  utils/bazel/llvm_configs/llvm-config.h.cmake

Index: utils/bazel/llvm_configs/llvm-config.h.cmake
===
--- utils/bazel/llvm_configs/llvm-config.h.cmake
+++ utils/bazel/llvm_configs/llvm-config.h.cmake
@@ -95,6 +95,9 @@
 /* Define if zlib compression is available */
 #cmakedefine01 LLVM_ENABLE_ZLIB
 
+/* Define if zstd compression is available */
+#cmakedefine01 LLVM_ENABLE_ZSTD
+
 /* Define if LLVM was built with a dependency to the libtensorflow dynamic library */
 #cmakedefine LLVM_HAVE_TF_API
 
Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -65,4 +65,46 @@
 
 #endif
 
+#if LLVM_ENABLE_ZSTD
+
+void TestZstdCompression(StringRef Input, int Level) {
+  SmallString<32> Compressed;
+  SmallString<32> Uncompressed;
+
+  zstd::compress(Input, Compressed, Level);
+
+  // Check that uncompressed buffer is the same as original.
+  Error E = zstd::uncompress(Compressed, Uncompressed, Input.size());
+  consumeError(std::move(E));
+
+  EXPECT_EQ(Input, Uncompressed);
+  if (Input.size() > 0) {
+// Uncompression fails if expected length is too short.
+E = zstd::uncompress(Compressed, Uncompressed, Input.size() - 1);
+EXPECT_EQ("Destination buffer is too small", llvm::toString(std::move(E)));
+  }
+}
+
+TEST(CompressionTest, Zstd) {
+  TestZstdCompression("", zstd::DefaultCompression);
+
+  TestZstdCompression("hello, world!", zstd::NoCompression);
+  TestZstdCompression("hello, world!", zstd::BestSizeCompression);
+  TestZstdCompression("hello, world!", zstd::BestSpeedCompression);
+  TestZstdCompression("hello, world!", zstd::DefaultCompression);
+
+  const size_t kSize = 1024;
+  char BinaryData[kSize];
+  for (size_t i = 0; i < kSize; ++i) {
+BinaryData[i] = i & 255;
+  }
+  StringRef BinaryDataStr(BinaryData, kSize);
+
+  TestZstdCompression(BinaryDataStr, zstd::NoCompression);
+  TestZstdCompression(BinaryDataStr, zstd::BestSizeCompression);
+  TestZstdCompression(BinaryDataStr, zstd::BestSpeedCompression);
+  TestZstdCompression(BinaryDataStr, zstd::DefaultCompression);
+}
+
+#endif
 }
Index: llvm/test/lit.site.cfg.py.in
===
--- llvm/test/lit.site.cfg.py.in
+++ llvm/test/lit.site.cfg.py.in
@@ -37,6 +37,7 @@
 config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.have_zstd = @LLVM_ENABLE_ZSTD@
 config.have_libxar = @LLVM_HAVE_LIBXAR@
 config.have_libxml2 = @LLVM_ENABLE_LIBXML2@
 config.have_curl = @LLVM_ENABLE_CURL@
Index: llvm/lib/Support/Compression.cpp
===
--- llvm/lib/Support/Compression.cpp
+++ llvm/lib/Support/Compression.cpp
@@ -20,6 +20,9 @@
 #if LLVM_ENABLE_ZLIB
 #include 
 #endif
+#if LLVM_ENABLE_ZSTD
+#include 
+#endif
 
 using namespace llvm;
 using namespace llvm::compression;
@@ -57,7 +60,9 @@
   // Tell MemorySanitizer that zlib output buffer is fully initialized.
   // This avoids a false report when running LLVM with uninstrumented ZLib.
   __msan_unpoison(CompressedBuffer.data(), CompressedSize);
-  CompressedBuffer.truncate(CompressedSize);
+  if (CompressedSize < CompressedBuffer.size()) {
+CompressedBuffer.truncate(CompressedSize);
+  }
 }
 
 Error zlib::uncompress(StringRef InputBuffer, char *UncompressedBuffer,
@@ -79,7 +84,9 @@
   UncompressedBuffer.resize_for_overwrite(UncompressedSize);
   Error E = zlib::uncompress(InputBuffer, UncompressedBuffer.data(),
  UncompressedSize);
-  UncompressedBuffer.truncate(UncompressedSize);
+  if (UncompressedSize < UncompressedBuffer.size()) {
+UncompressedBuffer.truncate(UncompressedSize);
+  }
   return E;
 }
 
@@ -99,3 +106,67 @@
   llvm_unreachable("zlib::uncompress is unavailable");
 }
 #endif
+
+#if LLVM_ENABLE_ZSTD
+
+bool zstd::isAvailable() { return true; }
+
+void zstd::compress(StringRef InputBuffer,
+SmallVectorImpl , int Level) {
+  unsigned long CompressedBufferSize = ::ZSTD_compressBound(InputBuffer.size());
+  CompressedBuffer.resize_for_overwrite(CompressedBufferSize);
+  unsigned long 

[PATCH] D129048: Rewording the "static_assert" to static assertion

2022-07-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

The changes here LGTM aside from one thing (which I'll take care of when I land 
the changes on your behalf). ParseDeclCXX.cpp still has a bunch of unrelated 
whitespace changes in it which should be backed out. We don't want unrelated 
changes sneaking in to a commit because that makes a future `git blame` that 
much harder on folks. But, rather than have you fiddle with it, I can strip 
them easily enough on my end, so this is just something to keep in mind for 
next time.

Thank you for the cleanup here!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129048/new/

https://reviews.llvm.org/D129048

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


[PATCH] D128745: [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template

2022-07-13 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added inline comments.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:5444
+  if (Better1 && Better2) {
+bool ClangABICompat14 = S.Context.getLangOpts().getClangABICompat() <=
+LangOptions::ClangABI::Ver14;

aaron.ballman wrote:
> Can you add CodeGen test coverage for both ABI modes (new RUN line with 
> `-fclang-abi-compat=14`)
Some test cases could reach the CodeGen phase *with* 
`-fclang-abi-compat=14`(i.e without this patch), some test cases could reach 
the CodeGen phase *without* `-fclang-abi-compat=14`(i.e with this patch). 
Please let me know if the added CodeGen tests are what you expected.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128745/new/

https://reviews.llvm.org/D128745

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


[PATCH] D128090: [Clang][OpenMP] Process multi-arch compilation options given via -march

2022-07-13 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D128090#3649202 , @tra wrote:

> In D128090#3649125 , @jhuber6 wrote:
>
>> It just defaults to `sm_35` if CUDA isn't present on the system IIRC. 
>> Alternatively we could ship a tool to derive it at compile time.
>
> As it happens, recent CUDA releases ship with `bin/__nvcc_device_query` which 
> prints out the list of SM capabilities of the GPUs it sees.
>
> Even that may not be the right value. E.g. only some of the GPUs on the 
> machine may be intended for compute. It's not that uncommon to have a puny 
> card to drive the display and one or more compute cards we actually want to 
> compile for. There's no point compiling for a GPU variant which will never do 
> any compute.

Interesting, may be worthwhile to query that if it exists, though AMD does this 
with `amdgpu-arch` which has led to problems for me in the past. But even if it 
could be wrong it will still spit out an architecture that would run on at 
least one local card rather than zero.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128090/new/

https://reviews.llvm.org/D128090

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


[PATCH] D129377: [lldb/Fuzzer] Add fuzzer for expression evaluator

2022-07-13 Thread Chelsea Cassanova via Phabricator via cfe-commits
cassanova updated this revision to Diff 444361.
cassanova added a comment.

Updated the ProtobufMutator CMake module and expression fuzzer CMakeLists file 
so that the expression fuzzer will create its own target name in its CMake 
file, and the ProtobufMutator will not attempt to create another target if one 
already exists

Also updated the expression fuzzer's CMake file to create a directory to store 
expression fuzzer artifacts.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129377/new/

https://reviews.llvm.org/D129377

Files:
  clang/cmake/modules/ProtobufMutator.cmake
  clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
  clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
  lldb/tools/lldb-fuzzer/CMakeLists.txt
  lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
  lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/cxx_proto.proto
  lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/lldb-expression-fuzzer.cpp

Index: lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/lldb-expression-fuzzer.cpp
===
--- /dev/null
+++ lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/lldb-expression-fuzzer.cpp
@@ -0,0 +1,73 @@
+//===-- lldb-expression-fuzzer.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===-===//
+//
+// \file
+// This file is a fuzzer for LLDB's expression evaluator. It uses protobufs
+// and the libprotobuf-mutator to create valid C-like inputs for the
+// expression evaluator.
+//
+//===-===//
+
+#include 
+
+#include "cxx_proto.pb.h"
+#include "handle_cxx.h"
+#include "lldb/API/SBBreakpoint.h"
+#include "lldb/API/SBDebugger.h"
+#include "lldb/API/SBError.h"
+#include "lldb/API/SBLaunchInfo.h"
+#include "lldb/API/SBProcess.h"
+#include "lldb/API/SBTarget.h"
+#include "proto_to_cxx.h"
+#include "src/libfuzzer/libfuzzer_macro.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+
+using namespace lldb;
+using namespace llvm;
+using namespace clang_fuzzer;
+
+char **originalargv;
+
+extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
+  SBDebugger::Initialize();
+
+  // The path for a simple compiled program is needed to create a
+  // target for the debugger and that path is passed in through argv
+  originalargv = *argv;
+  return 0;
+}
+
+DEFINE_BINARY_PROTO_FUZZER(const clang_fuzzer::Function ) {
+  auto S = clang_fuzzer::FunctionToString(input);
+
+  // Get the second argument from argv and strip the '--' from it.
+  // This will be used as the path for the object file to create a target from
+  std::string rawpath = originalargv[2];
+  StringRef objpath = rawpath.erase(0, 2);
+
+  // Create a debugger and a target
+  SBDebugger debugger = SBDebugger::Create(false);
+  SBTarget target = debugger.CreateTarget(objpath.str().c_str());
+
+  // Create a breakpoint on the only line in the program
+  SBBreakpoint bp = target.BreakpointCreateByLocation(objpath.str().c_str(), 1);
+
+  // Create launch info and error for launching the process
+  SBLaunchInfo li = target.GetLaunchInfo();
+  SBError error;
+
+  // Launch the process and evaluate the fuzzer's input data
+  // as an expression
+  SBProcess process = target.Launch(li, error);
+  target.EvaluateExpression(S.c_str());
+
+  debugger.DeleteTarget(target);
+  SBDebugger::Destroy(debugger);
+  SBModule::GarbageCollectAllocatedModules();
+}
Index: lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/cxx_proto.proto
===
--- /dev/null
+++ lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/cxx_proto.proto
@@ -0,0 +1,92 @@
+//===-- cxx_proto.proto - Protobuf description of C++ -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// This file describes a subset of C++ as a protobuf.  It is used to
+///  more easily find interesting inputs for fuzzing Clang.
+///
+//===--===//
+
+syntax = "proto2";
+
+message VarRef {
+  required int32 varnum = 1;
+}
+
+message Lvalue {
+  required VarRef varref = 1;
+}
+
+message Const {
+  required int32 val = 1;
+}
+
+message BinaryOp {
+  enum Op {
+PLUS = 0;
+MINUS = 1;
+MUL = 2;
+DIV = 3;
+MOD = 4;
+XOR = 5;
+AND = 6;
+OR = 7;
+EQ = 8;
+NE = 9;
+LE = 10;
+GE = 11;
+LT = 12;
+GT = 13;
+  };
+  required Op op = 1;
+  required 

  1   2   3   >