[clang] 168d4e2 - Handles failing driver tests of clang

2022-08-02 Thread via cfe-commits

Author: Purva-Chaudhari
Date: 2022-08-02T12:29:26+05:30
New Revision: 168d4e2945a9d3ba2aa88aad65e0a15bddcf7e58

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

LOG: Handles failing driver tests of clang

Added support for incremental mode 8 and 28 ie. `frontend::EmitBC:` and 
`frontend::PrintPreprocessedInput:`
Added supporting clang tests to test in clang-repl mode

Reviewed By: v.g.vassilev

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

Added: 
clang/test/Interpreter/incremental-mode.cpp

Modified: 
clang/lib/Interpreter/IncrementalParser.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index db854c4161b4f..32eeb1be788a2 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -69,8 +69,12 @@ class IncrementalAction : public WrapperFrontendAction {
 LLVM_FALLTHROUGH;
   case frontend::EmitAssembly:
 LLVM_FALLTHROUGH;
+  case frontend::EmitBC:
+LLVM_FALLTHROUGH;
   case frontend::EmitObj:
 LLVM_FALLTHROUGH;
+  case frontend::PrintPreprocessedInput:
+LLVM_FALLTHROUGH;
   case frontend::EmitLLVMOnly:
 Act.reset(new EmitLLVMOnlyAction(&LLVMCtx));
 break;

diff  --git a/clang/test/Interpreter/incremental-mode.cpp 
b/clang/test/Interpreter/incremental-mode.cpp
new file mode 100644
index 0..e6350d237ef57
--- /dev/null
+++ b/clang/test/Interpreter/incremental-mode.cpp
@@ -0,0 +1,3 @@
+// RUN: clang-repl -Xcc -E
+// RUN: clang-repl -Xcc -emit-llvm 
+// expected-no-diagnostics



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


[PATCH] D125946: Handles failing driver tests of clang

2022-08-02 Thread Purva Chaudhari via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG168d4e2945a9: Handles failing driver tests of clang 
(authored by Purva-Chaudhari).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125946

Files:
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/test/Interpreter/incremental-mode.cpp


Index: clang/test/Interpreter/incremental-mode.cpp
===
--- /dev/null
+++ clang/test/Interpreter/incremental-mode.cpp
@@ -0,0 +1,3 @@
+// RUN: clang-repl -Xcc -E
+// RUN: clang-repl -Xcc -emit-llvm 
+// expected-no-diagnostics
Index: clang/lib/Interpreter/IncrementalParser.cpp
===
--- clang/lib/Interpreter/IncrementalParser.cpp
+++ clang/lib/Interpreter/IncrementalParser.cpp
@@ -69,8 +69,12 @@
 LLVM_FALLTHROUGH;
   case frontend::EmitAssembly:
 LLVM_FALLTHROUGH;
+  case frontend::EmitBC:
+LLVM_FALLTHROUGH;
   case frontend::EmitObj:
 LLVM_FALLTHROUGH;
+  case frontend::PrintPreprocessedInput:
+LLVM_FALLTHROUGH;
   case frontend::EmitLLVMOnly:
 Act.reset(new EmitLLVMOnlyAction(&LLVMCtx));
 break;


Index: clang/test/Interpreter/incremental-mode.cpp
===
--- /dev/null
+++ clang/test/Interpreter/incremental-mode.cpp
@@ -0,0 +1,3 @@
+// RUN: clang-repl -Xcc -E
+// RUN: clang-repl -Xcc -emit-llvm 
+// expected-no-diagnostics
Index: clang/lib/Interpreter/IncrementalParser.cpp
===
--- clang/lib/Interpreter/IncrementalParser.cpp
+++ clang/lib/Interpreter/IncrementalParser.cpp
@@ -69,8 +69,12 @@
 LLVM_FALLTHROUGH;
   case frontend::EmitAssembly:
 LLVM_FALLTHROUGH;
+  case frontend::EmitBC:
+LLVM_FALLTHROUGH;
   case frontend::EmitObj:
 LLVM_FALLTHROUGH;
+  case frontend::PrintPreprocessedInput:
+LLVM_FALLTHROUGH;
   case frontend::EmitLLVMOnly:
 Act.reset(new EmitLLVMOnlyAction(&LLVMCtx));
 break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130894: [clang] Print more information about failed static assertions

2022-08-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 449199.

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

https://reviews.llvm.org/D130894

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/p3.cpp
  clang/test/CXX/drs/dr7xx.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/init-capture.cpp
  clang/test/PCH/cxx-templates.cpp
  clang/test/Parser/objc-static-assert.mm
  clang/test/SemaCXX/static-assert-cxx17.cpp
  clang/test/SemaTemplate/instantiate-var-template.cpp
  clang/test/SemaTemplate/instantiation-dependence.cpp

Index: clang/test/SemaTemplate/instantiation-dependence.cpp
===
--- clang/test/SemaTemplate/instantiation-dependence.cpp
+++ clang/test/SemaTemplate/instantiation-dependence.cpp
@@ -68,8 +68,10 @@
   struct D : B, C {};
 
   static_assert(trait::specialization == 0);
-  static_assert(trait::specialization == 1); // FIXME expected-error {{failed}}
-  static_assert(trait::specialization == 2); // FIXME expected-error {{failed}}
+  static_assert(trait::specialization == 1); // FIXME expected-error {{failed}} \
+// expected-note {{evaluates to '0'}}
+  static_assert(trait::specialization == 2); // FIXME expected-error {{failed}} \
+// expected-note {{evaluates to '0'}}
   static_assert(trait::specialization == 0); // FIXME-error {{ambiguous partial specialization}}
 }
 
Index: clang/test/SemaTemplate/instantiate-var-template.cpp
===
--- clang/test/SemaTemplate/instantiate-var-template.cpp
+++ clang/test/SemaTemplate/instantiate-var-template.cpp
@@ -31,7 +31,8 @@
   static_assert(b == 1, ""); // expected-note {{in instantiation of}} expected-error {{not an integral constant}}
 
   template void f() {
-static_assert(a == 0, ""); // expected-error {{static assertion failed due to requirement 'a == 0'}}
+static_assert(a == 0, ""); // expected-error {{static assertion failed due to requirement 'a == 0'}} \
+   // expected-note {{evaluates to '1'}}
   }
 }
 
Index: clang/test/SemaCXX/static-assert-cxx17.cpp
===
--- clang/test/SemaCXX/static-assert-cxx17.cpp
+++ clang/test/SemaCXX/static-assert-cxx17.cpp
@@ -88,7 +88,8 @@
   static_assert(typename T::T(0));
   // expected-error@-1{{static assertion failed due to requirement 'int(0)'}}
   static_assert(sizeof(X) == 0);
-  // expected-error@-1{{static assertion failed due to requirement 'sizeof(X) == 0'}}
+  // expected-error@-1{{static assertion failed due to requirement 'sizeof(X) == 0'}} \
+  // expected-note@-1 {{evaluates to '8'}}
   static_assert((const X *)nullptr);
   // expected-error@-1{{static assertion failed due to requirement '(const X *)nullptr'}}
   static_assert(static_cast *>(nullptr));
@@ -96,7 +97,8 @@
   static_assert((const X[]){} == nullptr);
   // expected-error@-1{{static assertion failed due to requirement '(const X[0]){} == nullptr'}}
   static_assert(sizeof(X().X::~X())>) == 0);
-  // expected-error@-1{{static assertion failed due to requirement 'sizeof(X) == 0'}}
+  // expected-error@-1{{static assertion failed due to requirement 'sizeof(X) == 0'}} \
+  // expected-note@-1 {{evaluates to '8'}}
   static_assert(constexpr_return_false());
   // expected-error@-1{{static assertion failed due to requirement 'constexpr_return_false()'}}
 }
Index: clang/test/Parser/objc-static-assert.mm
===
--- clang/test/Parser/objc-static-assert.mm
+++ clang/test/Parser/objc-static-assert.mm
@@ -26,7 +26,8 @@
 
   static_assert(a, ""); // expected-error {{static assertion expression is not an integral constant expression}}
   static_assert(sizeof(a) == 4, "");
-  static_assert(sizeof(a) == 3, ""); // expected-error {{static assertion failed}}
+  static_assert(sizeof(a) == 3, ""); // expected-error {{static assertion failed}} \
+ // expected-note {{evaluates to '4'}}
 }
 
 static_assert(1, "");
@@ -40,7 +41,8 @@
   static_assert(1, "");
   _Static_assert(1, "");
   static_assert(sizeof(b) == 4, "");
-  static_assert(sizeof(b) == 3, ""); // expected-error {{static assertion failed}}
+  static_assert(sizeof(b) == 3, ""); // expected-error {{static assertion failed}} \
+ // expected-note {{evaluates to '4'}}
 }
 
 static_assert(1, "");
@@ -56,7 +58,8 @@
 @interface B () {
   int b;
   static_assert(sizeof(b) == 4, "");
-  static_assert(sizeof(b) == 3, ""); // expected-error {{static assertion failed}}
+  static_assert(sizeof(b) == 3, ""); // expected-error {{static assertion failed}} \
+ // expected-note {{evalu

[PATCH] D130754: [X86] Support ``-mindirect-branch-cs-prefix`` for call and jmp to indirect thunk

2022-08-02 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

When a module with `"indirect_branch_cs_prefix"` and another without the module 
flag are merged, what the result should be? If 0, we should use `Min` instead 
of `Override`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130754

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


[PATCH] D130754: [X86] Support ``-mindirect-branch-cs-prefix`` for call and jmp to indirect thunk

2022-08-02 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay requested changes to this revision.
MaskRay added inline comments.
This revision now requires changes to proceed.
Herald added a subscriber: StephenFan.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:6350
 
+  if (Args.hasArg(options::OPT_mindirect_branch_cs_prefix))
+CmdArgs.push_back("-mindirect-branch-cs-prefix");

Check CC1Option uses in `clang/include/clang/Driver/Options.td`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130754

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


[clang] afb785f - [Driver] Remove Separate form for XRay options

2022-08-02 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-08-02T00:47:37-07:00
New Revision: afb785f51161b78b9af7d9ecd3ce7632160efee9

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

LOG: [Driver] Remove Separate form for XRay options

Supporting something like `-fxray-instruction-threshold= 1` is not intended.

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/XRayArgs.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e37b461c95cb4..709dbfd12cdb9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2032,31 +2032,28 @@ defm xray_instrument : BoolFOption<"xray-instrument",
   NegFlag>;
 
 def fxray_instruction_threshold_EQ :
-  JoinedOrSeparate<["-"], "fxray-instruction-threshold=">,
+  Joined<["-"], "fxray-instruction-threshold=">,
   Group, Flags<[CC1Option]>,
   HelpText<"Sets the minimum function size to instrument with XRay">,
   MarshallingInfoInt, "200">;
-def fxray_instruction_threshold_ :
-  JoinedOrSeparate<["-"], "fxray-instruction-threshold">,
-  Group, Flags<[CC1Option]>;
 
 def fxray_always_instrument :
-  JoinedOrSeparate<["-"], "fxray-always-instrument=">,
+  Joined<["-"], "fxray-always-instrument=">,
   Group, Flags<[CC1Option]>,
   HelpText<"DEPRECATED: Filename defining the whitelist for imbuing the 
'always instrument' XRay attribute.">,
   MarshallingInfoStringVector>;
 def fxray_never_instrument :
-  JoinedOrSeparate<["-"], "fxray-never-instrument=">,
+  Joined<["-"], "fxray-never-instrument=">,
   Group, Flags<[CC1Option]>,
   HelpText<"DEPRECATED: Filename defining the whitelist for imbuing the 'never 
instrument' XRay attribute.">,
   MarshallingInfoStringVector>;
 def fxray_attr_list :
-  JoinedOrSeparate<["-"], "fxray-attr-list=">,
+  Joined<["-"], "fxray-attr-list=">,
   Group, Flags<[CC1Option]>,
   HelpText<"Filename defining the list of functions/types for imbuing XRay 
attributes.">,
   MarshallingInfoStringVector>;
 def fxray_modes :
-  JoinedOrSeparate<["-"], "fxray-modes=">,
+  Joined<["-"], "fxray-modes=">,
   Group, Flags<[CC1Option]>,
   HelpText<"List of modes to link in by default into XRay instrumented 
binaries.">;
 
@@ -2091,7 +2088,7 @@ def fnoxray_link_deps : Flag<["-"], "fnoxray-link-deps">, 
Group,
   Flags<[CC1Option]>;
 
 def fxray_instrumentation_bundle :
-  JoinedOrSeparate<["-"], "fxray-instrumentation-bundle=">,
+  Joined<["-"], "fxray-instrumentation-bundle=">,
   Group, Flags<[CC1Option]>,
   HelpText<"Select which XRay instrumentation points to emit. Options: all, 
none, function-entry, function-exit, function, custom. Default is 'all'.  
'function' includes both 'function-entry' and 'function-exit'.">;
 

diff  --git a/clang/lib/Driver/XRayArgs.cpp b/clang/lib/Driver/XRayArgs.cpp
index 63b575178bd12..cf9b5780c4555 100644
--- a/clang/lib/Driver/XRayArgs.cpp
+++ b/clang/lib/Driver/XRayArgs.cpp
@@ -79,8 +79,7 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
 
   XRayInstrument = true;
   if (const Arg *A =
-  Args.getLastArg(options::OPT_fxray_instruction_threshold_,
-  options::OPT_fxray_instruction_threshold_EQ)) {
+  Args.getLastArg(options::OPT_fxray_instruction_threshold_EQ)) {
 StringRef S = A->getValue();
 if (S.getAsInteger(0, InstructionThreshold) || InstructionThreshold < 0)
   D.Diag(clang::diag::err_drv_invalid_value) << A->getAsString(Args) << S;



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


[PATCH] D130969: [clang] [HLSL] Fix GCC warnings about virtual methods that are hidden

2022-08-02 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
mstorsjo added a reviewer: beanz.
Herald added a subscriber: Anastasia.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a project: clang.

This fixes the following warnings produced by GCC 9:

[...] Building CXX object tools/clan...gSema.dir/HLSLExternalSemaSource.cpp.o
In file included from ../tools/clang/include/clang/Sema/ExternalSemaSource.h:15,

  from ../tools/clang/include/clang/Sema/HLSLExternalSemaSource.h:17,
  from ../tools/clang/lib/Sema/HLSLExternalSemaSource.cpp:12:

../tools/clang/include/clang/AST/ExternalASTSource.h:211:16: warning: ‘virtual 
void clang::ExternalASTSource::CompleteType(clang::ObjCInterfaceDecl*)’ was 
hidden [-Woverloaded-virtual]

  211 |   virtual void CompleteType(ObjCInterfaceDecl *Class);
  |^~~~

In file included from ../tools/clang/lib/Sema/HLSLExternalSemaSource.cpp:12:
../tools/clang/include/clang/Sema/HLSLExternalSemaSource.h:49:8: warning:   by  
virtual void clang::HLSLExternalSemaSource::CompleteType(clang::TagDecl*)’ 
[-Woverloaded-virtual]

  49 |   void CompleteType(TagDecl *Tag) override;
 |^~~~


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130969

Files:
  clang/include/clang/Sema/HLSLExternalSemaSource.h


Index: clang/include/clang/Sema/HLSLExternalSemaSource.h
===
--- clang/include/clang/Sema/HLSLExternalSemaSource.h
+++ clang/include/clang/Sema/HLSLExternalSemaSource.h
@@ -45,6 +45,7 @@
   /// Inform the semantic consumer that Sema is no longer available.
   void ForgetSema() override { SemaPtr = nullptr; }
 
+  using ExternalASTSource::CompleteType;
   /// Complete an incomplete HLSL builtin type
   void CompleteType(TagDecl *Tag) override;
 };


Index: clang/include/clang/Sema/HLSLExternalSemaSource.h
===
--- clang/include/clang/Sema/HLSLExternalSemaSource.h
+++ clang/include/clang/Sema/HLSLExternalSemaSource.h
@@ -45,6 +45,7 @@
   /// Inform the semantic consumer that Sema is no longer available.
   void ForgetSema() override { SemaPtr = nullptr; }
 
+  using ExternalASTSource::CompleteType;
   /// Complete an incomplete HLSL builtin type
   void CompleteType(TagDecl *Tag) override;
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130311: [RISCV] Enable strict FP in clang as long as Zve* or V are not enabled.

2022-08-02 Thread Alex Bradbury via Phabricator via cfe-commits
asb added inline comments.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:232
+bool RISCVISAInfo::hasVInstructions() const {
+  return hasExtension("zve32x");
+}

Given the other sub-thread showed that hasExtennsion("zve32x") == 
hasVInstructions isn't completely obvious, perhaps worth a comment like "zve32x 
is the root of the V extension inheritance tree. i.e. enabling any of the 
vector extensions will implicitly enable zve32x."


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130311

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


[PATCH] D130894: [clang] Print more information about failed static assertions

2022-08-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 449226.

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

https://reviews.llvm.org/D130894

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/p3.cpp
  clang/test/CXX/drs/dr7xx.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/init-capture.cpp
  clang/test/PCH/cxx-templates.cpp
  clang/test/Parser/objc-static-assert.mm
  clang/test/SemaCXX/static-assert-cxx17.cpp
  clang/test/SemaTemplate/instantiate-var-template.cpp
  clang/test/SemaTemplate/instantiation-dependence.cpp

Index: clang/test/SemaTemplate/instantiation-dependence.cpp
===
--- clang/test/SemaTemplate/instantiation-dependence.cpp
+++ clang/test/SemaTemplate/instantiation-dependence.cpp
@@ -68,8 +68,10 @@
   struct D : B, C {};
 
   static_assert(trait::specialization == 0);
-  static_assert(trait::specialization == 1); // FIXME expected-error {{failed}}
-  static_assert(trait::specialization == 2); // FIXME expected-error {{failed}}
+  static_assert(trait::specialization == 1); // FIXME expected-error {{failed}} \
+// expected-note {{evaluates to '0'}}
+  static_assert(trait::specialization == 2); // FIXME expected-error {{failed}} \
+// expected-note {{evaluates to '0'}}
   static_assert(trait::specialization == 0); // FIXME-error {{ambiguous partial specialization}}
 }
 
Index: clang/test/SemaTemplate/instantiate-var-template.cpp
===
--- clang/test/SemaTemplate/instantiate-var-template.cpp
+++ clang/test/SemaTemplate/instantiate-var-template.cpp
@@ -31,7 +31,8 @@
   static_assert(b == 1, ""); // expected-note {{in instantiation of}} expected-error {{not an integral constant}}
 
   template void f() {
-static_assert(a == 0, ""); // expected-error {{static assertion failed due to requirement 'a == 0'}}
+static_assert(a == 0, ""); // expected-error {{static assertion failed due to requirement 'a == 0'}} \
+   // expected-note {{evaluates to '1'}}
   }
 }
 
Index: clang/test/SemaCXX/static-assert-cxx17.cpp
===
--- clang/test/SemaCXX/static-assert-cxx17.cpp
+++ clang/test/SemaCXX/static-assert-cxx17.cpp
@@ -88,7 +88,8 @@
   static_assert(typename T::T(0));
   // expected-error@-1{{static assertion failed due to requirement 'int(0)'}}
   static_assert(sizeof(X) == 0);
-  // expected-error@-1{{static assertion failed due to requirement 'sizeof(X) == 0'}}
+  // expected-error@-1{{static assertion failed due to requirement 'sizeof(X) == 0'}} \
+  // expected-note@-1 {{evaluates to '8'}}
   static_assert((const X *)nullptr);
   // expected-error@-1{{static assertion failed due to requirement '(const X *)nullptr'}}
   static_assert(static_cast *>(nullptr));
@@ -96,7 +97,8 @@
   static_assert((const X[]){} == nullptr);
   // expected-error@-1{{static assertion failed due to requirement '(const X[0]){} == nullptr'}}
   static_assert(sizeof(X().X::~X())>) == 0);
-  // expected-error@-1{{static assertion failed due to requirement 'sizeof(X) == 0'}}
+  // expected-error@-1{{static assertion failed due to requirement 'sizeof(X) == 0'}} \
+  // expected-note@-1 {{evaluates to '8'}}
   static_assert(constexpr_return_false());
   // expected-error@-1{{static assertion failed due to requirement 'constexpr_return_false()'}}
 }
Index: clang/test/Parser/objc-static-assert.mm
===
--- clang/test/Parser/objc-static-assert.mm
+++ clang/test/Parser/objc-static-assert.mm
@@ -26,7 +26,8 @@
 
   static_assert(a, ""); // expected-error {{static assertion expression is not an integral constant expression}}
   static_assert(sizeof(a) == 4, "");
-  static_assert(sizeof(a) == 3, ""); // expected-error {{static assertion failed}}
+  static_assert(sizeof(a) == 3, ""); // expected-error {{static assertion failed}} \
+ // expected-note {{evaluates to '4'}}
 }
 
 static_assert(1, "");
@@ -40,7 +41,8 @@
   static_assert(1, "");
   _Static_assert(1, "");
   static_assert(sizeof(b) == 4, "");
-  static_assert(sizeof(b) == 3, ""); // expected-error {{static assertion failed}}
+  static_assert(sizeof(b) == 3, ""); // expected-error {{static assertion failed}} \
+ // expected-note {{evaluates to '4'}}
 }
 
 static_assert(1, "");
@@ -56,7 +58,8 @@
 @interface B () {
   int b;
   static_assert(sizeof(b) == 4, "");
-  static_assert(sizeof(b) == 3, ""); // expected-error {{static assertion failed}}
+  static_assert(sizeof(b) == 3, ""); // expected-error {{static assertion failed}} \
+ // expected-note {{evalu

[PATCH] D130918: [clang][ExtractAPI] Record availability information on all platforms

2022-08-02 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 449228.
dang added a comment.

Remove doc comments in test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130918

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/AvailabilityInfo.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/AvailabilityInfo.cpp
  clang/lib/ExtractAPI/CMakeLists.txt
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/availability.c

Index: clang/test/ExtractAPI/availability.c
===
--- /dev/null
+++ clang/test/ExtractAPI/availability.c
@@ -0,0 +1,459 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api --product-name=Availability -triple arm64-apple-macosx -x c-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+void a(void);
+
+void b(void) __attribute__((availability(macos, introduced=12.0)));
+
+void c(void) __attribute__((availability(macos, introduced=11.0, deprecated=12.0, obsoleted=20.0)));
+
+void d(void) __attribute__((availability(macos, introduced=11.0, deprecated=12.0, obsoleted=20.0))) __attribute__((availability(ios, introduced=13.0)));
+
+void e(void) __attribute__((deprecated)) __attribute__((availability(macos, introduced=11.0)));
+
+void f(void) __attribute__((unavailable)) __attribute__((availability(macos, introduced=11.0)));
+
+void d(void) __attribute__((availability(tvos, introduced=15.0)));
+///expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "Availability",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:v",
+  "spelling": "void"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "a"
+},
+{
+  "kind": "text",
+  "spelling": "()"
+}
+  ],
+  "functionSignature": {
+"returns": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:v",
+"spelling": "void"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@F@a"
+  },
+  "kind": {
+"displayName": "Function",
+"identifier": "c.func"
+  },
+  "location": {
+"position": {
+  "character": 6,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "a"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "a"
+  }
+],
+"title": "a"
+  },
+  "pathComponents": [
+"a"
+  ]
+},
+{
+  "accessLevel": "public",
+  "availability": [
+{
+  "domain": "macos",
+  "introducedVersion": {
+"major": 12,
+"minor": 0,
+"patch": 0
+  }
+}
+  ],
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:v",
+  "spelling": "void"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "b"
+},
+{
+  "kind": "text",
+  "spelling": "()"
+}
+  ],
+  "functionSignature": {
+"returns": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:v",
+"spelling": "void"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@F@b"
+  },
+  "kind": {
+"displayName": "Function",
+"identifier": "c.func"
+  },
+

[PATCH] D130906: [clang] format string checking for conpile-time evaluated str literal

2022-08-02 Thread YingChi Long via Phabricator via cfe-commits
inclyc added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130906

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


[PATCH] D130906: [clang] format string checking for conpile-time evaluated str literal

2022-08-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Getting a review usually takes far longer than just a few hours, so don't ping 
too early. I also want an opinion from at least one other reviewer.




Comment at: clang/lib/Sema/SemaChecking.cpp:8505
 
+  // maybe this expression can be evaluated at compile-time
+  // checks if E can be evaluated to some StringLiteral and retry

The comment should be full sentences, start with an upper-case character and 
end in a period:

```
// If this expression can be evaluated at compile-time,
// check if the result is a StringLiteral and retry
```
(just a suggestion)



Comment at: clang/lib/Sema/SemaChecking.cpp:8507
+if (Result.Val.isLValue()) {
+  auto *LVE = Result.Val.getLValueBase().dyn_cast();
+  if (LVE && LVE->getStmtClass() == Stmt::StringLiteralClass) {

tbaeder wrote:
> inclyc wrote:
> > tbaeder wrote:
> > > I think you should be able to unify the two `if` statements.
> > > 
> > > Can you not `dyn_cast_or_null(Result.Val.getLValueBase())` 
> > > here instead of casting to `Expr*` and checking the `StmtClass`?
> > `LValueBase` seems to be a wrapper of a pointer that has its own dyn_cast 
> > method.
> > 
> > I have changed code here like this, but it cannot compile
> > ```
> > auto *MaybeStringLiteral =
> > dyn_cast_or_null(Result.Val.getLValueBase());
> > if (MaybeStringLiteral) {
> >   return checkFormatStringExpr(S, MaybeStringLiteral, Args, APK, 
> > format_idx,
> >firstDataArg, Type, CallType,
> >/*InFunctionCall*/ false, CheckedVarArgs,
> >UncoveredArg, Offset);
> > }
> > ```
> > 
> > ```
> > /llvm-project/llvm/include/llvm/Support/Casting.h:64:53: error: 
> > type 'clang::StringLiteral *' cannot be used prior to '::' because it has 
> > no members
> >   static inline bool doit(const From &Val) { return To::classof(&Val); }
> > ```
> Ah, shame. This ends up calling `dyn_cast` on a `llvm::Pointerunion` as far 
> as I can see, which seems to return `nullptr` in case the cast is 
> unsuccessful anyway, so you could try just exploiting that: 
> https://llvm.org/doxygen/classllvm_1_1PointerUnion.html#a9147352f78d98ee246f25d3300e0aaba
What about this? I.e. usong `StringLiteral*` directly in the `dyn_cast` call?



Comment at: clang/test/Sema/format-strings-scanf.c:236
+  scanf(1 ? "%s" : "%d", i); // expected-warning{{format specifies type 'char 
*'}} \
+ // expected-note{{format string is defined here}}
   scanf(0 ? "%d %d" : "%d", i); // no warning

inclyc wrote:
> ```
> // long macro
> #include 
> 
> #define SOME_STRANGE_MACRO(a, b) ((0) ? (a) : (b))
> 
> int main() {
>   int *i;
>   scanf(SOME_STRANGE_MACRO("%d", "%d %s"), i);
> }
> ```
> 
> previous:
> ```
> sample.cpp:7:39: warning: more '%' conversions than data arguments 
> [-Wformat-insufficient-args]
>   scanf(SOME_STRANGE_MACRO("%d", "%d %s"), i);
>  ~^
> sample.cpp:3:48: note: expanded from macro 'SOME_STRANGE_MACRO'
> #define SOME_STRANGE_MACRO(a, b) ((0) ? (a) : (b))
>^
> 1 warning generated.
> ```
> 
> now:
> 
> ```
> sample.cpp:7:9: warning: more '%' conversions than data arguments 
> [-Wformat-insufficient-args]
>   scanf(SOME_STRANGE_MACRO("%d", "%d %s"), i);
> ^
> sample.cpp:3:34: note: expanded from macro 'SOME_STRANGE_MACRO'
> #define SOME_STRANGE_MACRO(a, b) ((0) ? (a) : (b))
>  ^
> sample.cpp:7:39: note: format string is defined here
>   scanf(SOME_STRANGE_MACRO("%d", "%d %s"), i);
>  ~^
> sample.cpp:3:48: note: expanded from macro 'SOME_STRANGE_MACRO'
> #define SOME_STRANGE_MACRO(a, b) ((0) ? (a) : (b))
>^
> 1 warning generated.
> ```
> 
> I think it is better to underline the buggy expression, if this sucks maybe 
> we can check if this is constexpr **after** checking conditional operator ` ? 
> :`  or somehow other statement classes ?
I think the output is fine as-is for this patch, but could be improved later. 
Looking at this as a human, I feel as if both of the "expanded from macro" 
notes are redundant. But I guess they can provide useful information in other 
cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130906

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


[PATCH] D124435: [X86] Always extend the integer parameters in callee

2022-08-02 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 updated this revision to Diff 449230.
LiuChen3 added a comment.

rebase and address rjmccall's comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124435

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/CodeGen/CGFunctionInfo.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/2007-06-18-SextAttrAggregate.c
  clang/test/CodeGen/X86/integer_argument_passing.c
  clang/test/CodeGen/X86/x86_32-arguments-darwin.c
  clang/test/CodeGen/X86/x86_32-arguments-linux.c
  clang/test/CodeGen/X86/x86_64-arguments-nacl.c
  clang/test/CodeGen/X86/x86_64-arguments.c
  clang/test/CodeGen/attr-noundef.cpp
  clang/test/CodeGen/builtin-align.c
  clang/test/CodeGen/builtins-memset-inline.c
  clang/test/CodeGen/catch-implicit-integer-sign-changes.c
  clang/test/CodeGen/ext-int-cc.c
  clang/test/CodeGen/function-attributes.c
  clang/test/CodeGen/mangle-windows.c
  clang/test/CodeGen/matrix-type-builtins.c
  clang/test/CodeGen/matrix-type-operators.c
  clang/test/CodeGen/ms-inline-asm.c
  clang/test/CodeGen/regcall.c
  clang/test/CodeGen/vectorcall.c
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/ext-int.cpp
  clang/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp
  clang/test/CodeGenCXX/new-overflow.cpp
  clang/test/CodeGenCXX/virtual-bases.cpp
  clang/test/CodeGenObjC/property-atomic-bool.m
  clang/test/OpenMP/target_codegen_global_capture.cpp

Index: clang/test/OpenMP/target_codegen_global_capture.cpp
===
--- clang/test/OpenMP/target_codegen_global_capture.cpp
+++ clang/test/OpenMP/target_codegen_global_capture.cpp
@@ -1166,7 +1166,7 @@
 //
 //
 // CHECK3-LABEL: define {{[^@]+}}@_Z3foo
-// CHECK3-SAME: (i16 noundef signext [[A:%.*]], i16 noundef signext [[B:%.*]], i16 noundef signext [[C:%.*]], i16 noundef signext [[D:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK3-SAME: (i16 noundef [[A:%.*]], i16 noundef [[B:%.*]], i16 noundef [[C:%.*]], i16 noundef [[D:%.*]]) #[[ATTR0:[0-9]+]] {
 // CHECK3-NEXT:  entry:
 // CHECK3-NEXT:[[A_ADDR:%.*]] = alloca i16, align 2
 // CHECK3-NEXT:[[B_ADDR:%.*]] = alloca i16, align 2
@@ -1469,7 +1469,7 @@
 //
 //
 // CHECK3-LABEL: define {{[^@]+}}@_Z3bar
-// CHECK3-SAME: (i16 noundef signext [[A:%.*]], i16 noundef signext [[B:%.*]], i16 noundef signext [[C:%.*]], i16 noundef signext [[D:%.*]]) #[[ATTR0]] {
+// CHECK3-SAME: (i16 noundef [[A:%.*]], i16 noundef [[B:%.*]], i16 noundef [[C:%.*]], i16 noundef [[D:%.*]]) #[[ATTR0]] {
 // CHECK3-NEXT:  entry:
 // CHECK3-NEXT:[[A_ADDR:%.*]] = alloca i16, align 2
 // CHECK3-NEXT:[[B_ADDR:%.*]] = alloca i16, align 2
@@ -1795,7 +1795,7 @@
 //
 //
 // CHECK3-LABEL: define {{[^@]+}}@_Z5tbar2
-// CHECK3-SAME: (i16 noundef signext [[A:%.*]], i16 noundef signext [[B:%.*]], i16 noundef signext [[C:%.*]], i16 noundef signext [[D:%.*]]) #[[ATTR0]] {
+// CHECK3-SAME: (i16 noundef [[A:%.*]], i16 noundef [[B:%.*]], i16 noundef [[C:%.*]], i16 noundef [[D:%.*]]) #[[ATTR0]] {
 // CHECK3-NEXT:  entry:
 // CHECK3-NEXT:[[A_ADDR:%.*]] = alloca i16, align 2
 // CHECK3-NEXT:[[B_ADDR:%.*]] = alloca i16, align 2
@@ -1814,7 +1814,7 @@
 //
 //
 // CHECK3-LABEL: define {{[^@]+}}@_Z4tbarIsEiT_S0_S0_S0_
-// CHECK3-SAME: (i16 noundef signext [[A:%.*]], i16 noundef signext [[B:%.*]], i16 noundef signext [[C:%.*]], i16 noundef signext [[D:%.*]]) #[[ATTR0]] comdat {
+// CHECK3-SAME: (i16 noundef [[A:%.*]], i16 noundef [[B:%.*]], i16 noundef [[C:%.*]], i16 noundef [[D:%.*]]) #[[ATTR0]] comdat {
 // CHECK3-NEXT:  entry:
 // CHECK3-NEXT:[[A_ADDR:%.*]] = alloca i16, align 2
 // CHECK3-NEXT:[[B_ADDR:%.*]] = alloca i16, align 2
Index: clang/test/CodeGenObjC/property-atomic-bool.m
===
--- clang/test/CodeGenObjC/property-atomic-bool.m
+++ clang/test/CodeGenObjC/property-atomic-bool.m
@@ -5,7 +5,7 @@
 // CHECK:   %[[TOBOOL:.*]] = trunc i8 %[[ATOMIC_LOAD]] to i1
 // CHECK:   ret i1 %[[TOBOOL]]
 
-// CHECK: define internal void @"\01-[A0 setP:]"({{.*}} i1 noundef zeroext {{.*}})
+// CHECK: define internal void @"\01-[A0 setP:]"({{.*}} i1 noundef {{.*}})
 // CHECK:   store atomic i8 %{{.*}}, i8* %{{.*}} seq_cst, align 1
 // CHECK:   ret void
 
@@ -14,7 +14,7 @@
 // CHECK:   %[[TOBOOL:.*]] = trunc i8 %load to i1
 // CHECK:   ret i1 %[[TOBOOL]]
 
-// CHECK: define internal void @"\01-[A1 setP:]"({{.*}} i1 noundef zeroext %p)
+// CHECK: define internal void @"\01-[A1 setP:]"({{.*}} i1 noundef %p)
 // CHECK:   store atomic i8 %{{.*}}, i8* %{{.*}} unordered, align 1
 // CHECK:   ret void
 
Index: clang/test/CodeGenCXX/virtual-bases.cpp
===
--- clang/

[PATCH] D124435: [X86] Always extend the integer parameters in callee

2022-08-02 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 added a comment.

Sorry for the late update. I hope you can take the time to continue reviewing, 
@rjmccall . 
I'm not sure if I understand you correctly. Now if the 
`-mextend-small-integers=default` is used, compiler will report error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124435

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


[PATCH] D124435: [X86] Always extend the integer parameters in callee

2022-08-02 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 added a comment.

In D124435#3515541 , @jyknight wrote:

> I find the option names you have a bit confusing. I'd like to suggest calling 
> them, instead:
>
> caller: Extend a small integer parameter in the caller; callee will assume it 
> has already been extended.
> callee : Pass a small integer parameter directly in caller, extend in callee 
> when converting to full-width.
> both: Extend a small integer parameter in the caller; callee ALSO extends 
> when converting to full-width.
> default: Use the default rule for the target.
>
> I think that gets more to the point of what's going on here, even though it's 
> not exactly the case that "callee" always extends.

rjmccall's comment convinced me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124435

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


[PATCH] D130864: [NFC] Introduce ASTContext::isInSameModule()

2022-08-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Thanks for working on this. I have a few major concerns here:

- Do we know that it's a bottleneck in practice? E.g. if the module name have 
different sizes, comparing strings is actually fast. If the module names are 
short, we are also in a pretty good situation. Having some benchmarks numbers 
would help to quantify whether the change is needed.
- `llvm::hash_value` is not a crypto hash, so we should expect collisions from 
it. OTOH, doing an extra string comparison when hashes match defeats the 
purpose of this optimization. Collisions are rare, but if someone hits one 
after the compiler is released there are literally no workarounds.  Instead we 
can use `llvm::SHA1` or `llvm::SHA256`. (possibly truncated to 128 bits? it's 
hard to tell how much this is needed without benchmarks.)
- Why not store the hash directly inside `Module` and compute it on 
construction after setting name? If we want these comparisons to be fast, we 
probably want to avoid even the overhead of hash table access.


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

https://reviews.llvm.org/D130864

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


[PATCH] D130864: [NFC] Introduce ASTContext::isInSameModule()

2022-08-02 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu planned changes to this revision.
ChuanqiXu marked an inline comment as done.
ChuanqiXu added a comment.

In D130864#3693019 , @ilya-biryukov 
wrote:

> Thanks for working on this. I have a few major concerns here:
>
> - Do we know that it's a bottleneck in practice? E.g. if the module name have 
> different sizes, comparing strings is actually fast. If the module names are 
> short, we are also in a pretty good situation. Having some benchmarks numbers 
> would help to quantify whether the change is needed.

No, we don't know it is a bottleneck in practice. (Currently there shouldn't be 
many users for C++20 Modules). The reason to do this is that we (Iain and me) 
feel bad to compare string frequently. Benchmarks would be good but I am afraid 
I can't. Since there are not enough existing benchmarks and it looks costful to 
construct the meaningful benchmarks. Let's not make the perfect to be the enemy 
of better.

> - `llvm::hash_value` is not a crypto hash, so we should expect collisions 
> from it. OTOH, doing an extra string comparison when hashes match defeats the 
> purpose of this optimization. Collisions are rare, but if someone hits one 
> after the compiler is released there are literally no workarounds.  Instead 
> we can use `llvm::SHA1` or `llvm::SHA256`. (possibly truncated to 128 bits? 
> it's hard to tell how much this is needed without benchmarks.)
> - Why not store the hash directly inside `Module` and compute it on 
> construction after setting name? If we want these comparisons to be fast, we 
> probably want to avoid even the overhead of hash table access.

Good idea. Will try to do.


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

https://reviews.llvm.org/D130864

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


[PATCH] D130906: [clang] format string checking for conpile-time evaluated str literal

2022-08-02 Thread YingChi Long via Phabricator via cfe-commits
inclyc added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:8507
+if (Result.Val.isLValue()) {
+  auto *LVE = Result.Val.getLValueBase().dyn_cast();
+  if (LVE && LVE->getStmtClass() == Stmt::StringLiteralClass) {

tbaeder wrote:
> tbaeder wrote:
> > inclyc wrote:
> > > tbaeder wrote:
> > > > I think you should be able to unify the two `if` statements.
> > > > 
> > > > Can you not 
> > > > `dyn_cast_or_null(Result.Val.getLValueBase())` here 
> > > > instead of casting to `Expr*` and checking the `StmtClass`?
> > > `LValueBase` seems to be a wrapper of a pointer that has its own dyn_cast 
> > > method.
> > > 
> > > I have changed code here like this, but it cannot compile
> > > ```
> > > auto *MaybeStringLiteral =
> > > dyn_cast_or_null(Result.Val.getLValueBase());
> > > if (MaybeStringLiteral) {
> > >   return checkFormatStringExpr(S, MaybeStringLiteral, Args, APK, 
> > > format_idx,
> > >firstDataArg, Type, CallType,
> > >/*InFunctionCall*/ false, 
> > > CheckedVarArgs,
> > >UncoveredArg, Offset);
> > > }
> > > ```
> > > 
> > > ```
> > > /llvm-project/llvm/include/llvm/Support/Casting.h:64:53: 
> > > error: type 'clang::StringLiteral *' cannot be used prior to '::' because 
> > > it has no members
> > >   static inline bool doit(const From &Val) { return To::classof(&Val); }
> > > ```
> > Ah, shame. This ends up calling `dyn_cast` on a `llvm::Pointerunion` as far 
> > as I can see, which seems to return `nullptr` in case the cast is 
> > unsuccessful anyway, so you could try just exploiting that: 
> > https://llvm.org/doxygen/classllvm_1_1PointerUnion.html#a9147352f78d98ee246f25d3300e0aaba
> What about this? I.e. usong `StringLiteral*` directly in the `dyn_cast` call?
```
FAILED: tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaChecking.cpp.o 
/usr/lib/llvm/14/bin/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/build/tools/clang/lib/Sema -I/clang/lib/Sema 
-I/clang/include -I/build/tools/clang/include 
-I/build/include -I/llvm/include -fPIC 
-fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -fdiagnostics-color -fno-common -Woverloaded-virtual 
-Wno-nested-anon-types -g  -fno-exceptions -fno-rtti -std=c++14 -MD -MT 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaChecking.cpp.o -MF 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaChecking.cpp.o.d -o 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaChecking.cpp.o -c 
/clang/lib/Sema/SemaChecking.cpp
In file included from /clang/lib/Sema/SemaChecking.cpp:14:
In file included from /clang/include/clang/AST/APValue.h:18:
In file included from /llvm/include/llvm/ADT/APFloat.h:19:
In file included from /llvm/include/llvm/ADT/ArrayRef.h:15:
/llvm/include/llvm/ADT/STLExtras.h:199:42: error: implicit 
instantiation of undefined template 'llvm::FirstIndexOfType'
: std::integral_constant::value> {};
 ^
/llvm/include/llvm/ADT/STLExtras.h:199:42: note: in instantiation 
of template class 'llvm::FirstIndexOfType' requested here
/llvm/include/llvm/ADT/STLExtras.h:199:42: note: in instantiation 
of template class 'llvm::FirstIndexOfType' requested here
/llvm/include/llvm/ADT/STLExtras.h:199:42: note: in instantiation 
of template class 'llvm::FirstIndexOfType' requested here
/llvm/include/llvm/ADT/PointerUnion.h:230:30: note: in 
instantiation of template class 'llvm::FirstIndexOfType' requested here
return F.Val.getInt() == FirstIndexOfType::value;
 ^
/llvm/include/llvm/ADT/PointerUnion.h:248:27: note: in 
instantiation of function template specialization 
'llvm::CastInfoPointerUnionImpl::isPossible' requested here
return Impl::template isPossible(f);
  ^
/llvm/include/llvm/Support/Casting.h:312:19: note: in 
instantiation of member function 'llvm::CastInfo>::isPossible' requested here
if (!Derived::isPossible(f))
  ^
/llvm/include/llvm/Support/Casting.h:407:23: note: in 
instantiation of member function 'llvm::DefaultDoCastIfPossible, 
llvm::CastInfo>>::doCastIfPossible' requested here
return ForwardTo::doCastIfPossible(const_cast(f));
  ^
/clang/include/clang/AST/APValue.h:167:37: note: in instantiation 
of function template specialization 'llvm::PointerUnion::dyn_cast' requested 
here
T dyn_cast() const { return Ptr.dyn_cast(); }
 

[PATCH] D130864: [NFC] Introduce ASTContext::isInSameModule()

2022-08-02 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

In D130864#3693022 , @ChuanqiXu wrote:

> In D130864#3693019 , @ilya-biryukov 
> wrote:
>
>> Thanks for working on this. I have a few major concerns here:
>>
>> - Do we know that it's a bottleneck in practice? E.g. if the module name 
>> have different sizes, comparing strings is actually fast. If the module 
>> names are short, we are also in a pretty good situation. Having some 
>> benchmarks numbers would help to quantify whether the change is needed.
>
> No, we don't know it is a bottleneck in practice. (Currently there shouldn't 
> be many users for C++20 Modules). The reason to do this is that we (Iain and 
> me) feel bad to compare string frequently. Benchmarks would be good but I am 
> afraid I can't. Since there are not enough existing benchmarks and it looks 
> costful to construct the meaningful benchmarks. Let's not make the perfect to 
> be the enemy of better.

We do not have benchmarks, it is true - initially, it seemed that the problem 
would be confined to the case of checking for the parent of a module partition 
which would be no concern - since it is one check per TU).   However, in later 
parts of the implementation it has become necessary to check when merging or 
comparing individual decls - and that is a concern.

>> - `llvm::hash_value` is not a crypto hash, so we should expect collisions 
>> from it. OTOH, doing an extra string comparison when hashes match defeats 
>> the purpose of this optimization. Collisions are rare, but if someone hits 
>> one after the compiler is released there are literally no workarounds.  
>> Instead we can use `llvm::SHA1` or `llvm::SHA256`. (possibly truncated to 
>> 128 bits? it's hard to tell how much this is needed without benchmarks.)
>> - Why not store the hash directly inside `Module` and compute it on 
>> construction after setting name? If we want these comparisons to be fast, we 
>> probably want to avoid even the overhead of hash table access.
>
> Good idea. Will try to do.

+1.
if the string is stored locally to the Module, then would it not be sufficient 
to compare the address?


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

https://reviews.llvm.org/D130864

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


[PATCH] D130906: [clang] format string checking for conpile-time evaluated str literal

2022-08-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:8507
+if (Result.Val.isLValue()) {
+  auto *LVE = Result.Val.getLValueBase().dyn_cast();
+  if (LVE && LVE->getStmtClass() == Stmt::StringLiteralClass) {

inclyc wrote:
> tbaeder wrote:
> > tbaeder wrote:
> > > inclyc wrote:
> > > > tbaeder wrote:
> > > > > I think you should be able to unify the two `if` statements.
> > > > > 
> > > > > Can you not 
> > > > > `dyn_cast_or_null(Result.Val.getLValueBase())` here 
> > > > > instead of casting to `Expr*` and checking the `StmtClass`?
> > > > `LValueBase` seems to be a wrapper of a pointer that has its own 
> > > > dyn_cast method.
> > > > 
> > > > I have changed code here like this, but it cannot compile
> > > > ```
> > > > auto *MaybeStringLiteral =
> > > > dyn_cast_or_null(Result.Val.getLValueBase());
> > > > if (MaybeStringLiteral) {
> > > >   return checkFormatStringExpr(S, MaybeStringLiteral, Args, APK, 
> > > > format_idx,
> > > >firstDataArg, Type, CallType,
> > > >/*InFunctionCall*/ false, 
> > > > CheckedVarArgs,
> > > >UncoveredArg, Offset);
> > > > }
> > > > ```
> > > > 
> > > > ```
> > > > /llvm-project/llvm/include/llvm/Support/Casting.h:64:53: 
> > > > error: type 'clang::StringLiteral *' cannot be used prior to '::' 
> > > > because it has no members
> > > >   static inline bool doit(const From &Val) { return To::classof(&Val); }
> > > > ```
> > > Ah, shame. This ends up calling `dyn_cast` on a `llvm::Pointerunion` as 
> > > far as I can see, which seems to return `nullptr` in case the cast is 
> > > unsuccessful anyway, so you could try just exploiting that: 
> > > https://llvm.org/doxygen/classllvm_1_1PointerUnion.html#a9147352f78d98ee246f25d3300e0aaba
> > What about this? I.e. usong `StringLiteral*` directly in the `dyn_cast` 
> > call?
> ```
> FAILED: tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaChecking.cpp.o 
> /usr/lib/llvm/14/bin/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE 
> -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
> -I/build/tools/clang/lib/Sema -I/clang/lib/Sema 
> -I/clang/include -I/build/tools/clang/include 
> -I/build/include -I/llvm/include -fPIC 
> -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time 
> -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
> -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
> -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
> -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
> -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
> -Wmisleading-indentation -fdiagnostics-color -fno-common -Woverloaded-virtual 
> -Wno-nested-anon-types -g  -fno-exceptions -fno-rtti -std=c++14 -MD -MT 
> tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaChecking.cpp.o -MF 
> tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaChecking.cpp.o.d -o 
> tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaChecking.cpp.o -c 
> /clang/lib/Sema/SemaChecking.cpp
> In file included from /clang/lib/Sema/SemaChecking.cpp:14:
> In file included from /clang/include/clang/AST/APValue.h:18:
> In file included from /llvm/include/llvm/ADT/APFloat.h:19:
> In file included from /llvm/include/llvm/ADT/ArrayRef.h:15:
> /llvm/include/llvm/ADT/STLExtras.h:199:42: error: implicit 
> instantiation of undefined template 'llvm::FirstIndexOfType clang::StringLiteral *>'
> : std::integral_constant::value> 
> {};
>  ^
> /llvm/include/llvm/ADT/STLExtras.h:199:42: note: in 
> instantiation of template class 'llvm::FirstIndexOfType clang::StringLiteral *, clang::DynamicAllocLValue>' requested here
> /llvm/include/llvm/ADT/STLExtras.h:199:42: note: in 
> instantiation of template class 'llvm::FirstIndexOfType clang::StringLiteral *, clang::TypeInfoLValue, clang::DynamicAllocLValue>' 
> requested here
> /llvm/include/llvm/ADT/STLExtras.h:199:42: note: in 
> instantiation of template class 'llvm::FirstIndexOfType clang::StringLiteral *, const clang::Expr *, clang::TypeInfoLValue, 
> clang::DynamicAllocLValue>' requested here
> /llvm/include/llvm/ADT/PointerUnion.h:230:30: note: in 
> instantiation of template class 'llvm::FirstIndexOfType clang::StringLiteral *, const clang::ValueDecl *, const clang::Expr *, 
> clang::TypeInfoLValue, clang::DynamicAllocLValue>' requested here
> return F.Val.getInt() == FirstIndexOfType::value;
>  ^
> /llvm/include/llvm/ADT/PointerUnion.h:248:27: note: in 
> instantiation of function template specialization 
> 'llvm::CastInfoPointerUnionImpl *, clang::TypeInfoLValue, clang::DynamicAllocLValue>::isPossible clang::StringLiteral *>' requested here
> return Impl::template isPossible(f);
>   ^
> /llvm/include/llvm/Support/Casti

[PATCH] D130906: [clang] format string checking for conpile-time evaluated str literal

2022-08-02 Thread YingChi Long via Phabricator via cfe-commits
inclyc updated this revision to Diff 449236.
inclyc added a comment.

update comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130906

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/format-strings-scanf.c
  clang/test/Sema/format-strings.c
  clang/test/SemaCXX/format-strings.cpp

Index: clang/test/SemaCXX/format-strings.cpp
===
--- clang/test/SemaCXX/format-strings.cpp
+++ clang/test/SemaCXX/format-strings.cpp
@@ -163,3 +163,48 @@
   t::func4("Hello %s"); // expected-warning {{more '%' conversions than data arguments}}
 }
 }
+#if __cplusplus >= 201103L
+namespace evaluated {
+
+constexpr const char *basic() { 
+  return 
+"%s %d"; // expected-note {{format string is defined here}}
+}
+
+constexpr const char *correct_fmt() { 
+  return 
+"%d %d";
+}
+
+constexpr const char *string_linebreak() { 
+  return 
+"%d %d"
+"%d %s"; // expected-note {{format string is defined here}}
+}
+
+/*non-constexpr*/ const char *not_literal() { 
+  return 
+"%d %d"
+"%d %s";
+}
+
+constexpr const char *inner_call() {
+  return "%d %s"; // expected-note {{format string is defined here}}
+}
+
+constexpr const char *wrap_constexpr() {
+  return inner_call();
+}
+
+
+void f() {
+  printf(basic(), 1, 2); // expected-warning {{format specifies type 'char *' but the argument has type 'int'}}
+  printf(correct_fmt(), 1, 2);
+  printf(string_linebreak(), 1, 2, 3, 4); // expected-warning {{format specifies type 'char *' but the argument has type 'int'}}
+  printf(not_literal(), 1, 2, 3, 4); // expected-warning {{format string is not a string literal}}
+  printf(wrap_constexpr(), 1, 2); // expected-warning {{format specifies type 'char *' but the argument has type 'int'}}
+}
+
+
+}
+#endif
Index: clang/test/Sema/format-strings.c
===
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -105,7 +105,8 @@
   // expected-note@-1{{treat the string as an argument to avoid this}}
   printf("yes" ?: "no %d", 1); // expected-warning{{data argument not used by format string}}
   printf(0 ? "yes %s" : "no %d", 1); // no-warning
-  printf(0 ? "yes %d" : "no %s", 1); // expected-warning{{format specifies type 'char *'}}
+  printf(0 ? "yes %d" : "no %s", 1); // expected-warning{{format specifies type 'char *'}} \
+ // expected-note{{format string is defined here}}
 
   printf(0 ? "yes" : "no %d", 1); // no-warning
   printf(0 ? "yes %d" : "no", 1); // expected-warning{{data argument not used by format string}}
@@ -259,8 +260,7 @@
   printf(s2); // no-warning
   printf(s3); // expected-warning{{not a string literal}}
   // expected-note@-1{{treat the string as an argument to avoid this}}
-  printf(s4); // expected-warning{{not a string literal}}
-  // expected-note@-1{{treat the string as an argument to avoid this}}
+  printf(s4);
   printf(s5); // expected-warning{{not a string literal}}
   // expected-note@-1{{treat the string as an argument to avoid this}}
 }
@@ -621,7 +621,8 @@
 
   // Make sure that the "format string is defined here" note is not emitted
   // when the original string is within the argument expression.
-  printf(1 ? "yes %d" : "no %d"); // expected-warning{{more '%' conversions than data arguments}}
+  printf(1 ? "yes %d" : "no %d"); // expected-warning{{more '%' conversions than data arguments}} \
+  // expected-note {{format string is defined here}}
 
   const char kFormat17[] = "%hu"; // expected-note{{format string is defined here}}}
   printf(kFormat17, (int[]){0}); // expected-warning{{format specifies type 'unsigned short' but the argument}}
Index: clang/test/Sema/format-strings-scanf.c
===
--- clang/test/Sema/format-strings-scanf.c
+++ clang/test/Sema/format-strings-scanf.c
@@ -232,9 +232,11 @@
 
 void check_conditional_literal(char *s, int *i) {
   scanf(0 ? "%s" : "%d", i); // no warning
-  scanf(1 ? "%s" : "%d", i); // expected-warning{{format specifies type 'char *'}}
+  scanf(1 ? "%s" : "%d", i); // expected-warning{{format specifies type 'char *'}} \
+ // expected-note{{format string is defined here}}
   scanf(0 ? "%d %d" : "%d", i); // no warning
-  scanf(1 ? "%d %d" : "%d", i); // expected-warning{{more '%' conversions than data arguments}}
+  scanf(1 ? "%d %d" : "%d", i); // expected-warning{{more '%' conversions than data arguments}} \
+// expected-note{{format string is defined here}}
   scanf(0 ? "%d %d" : "%d", i, s); // expected-warning{{data argument not used}}
   scanf(1 ? "%d %s" : "%d", i, s); // no warning
   scanf(i ? "%d %s" : "%d", i, s); // no warning
Index: clang/lib/Sema/SemaChecking.cpp
===
---

[PATCH] D130041: [clangd] Add decl/def support to SymbolDetails

2022-08-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

no worries, as discussed offline this LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130041

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


[PATCH] D111521: [DebugInfo] Mark OpenMP generated functions as artificial

2022-08-02 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok updated this revision to Diff 449239.
alok added a comment.

Re-based and updated to incorporate comments from @dblaikie


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

https://reviews.llvm.org/D111521

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/OpenMP/outlined_artificial.c


Index: clang/test/OpenMP/outlined_artificial.c
===
--- /dev/null
+++ clang/test/OpenMP/outlined_artificial.c
@@ -0,0 +1,67 @@
+// This testcase checks emission of DIFlagArtificial flag for outlined
+// subroutines generated by compiler.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#if defined(_WIN32)
+#define __KAI_KMPC_CONVENTION __cdecl
+#else
+#define __KAI_KMPC_CONVENTION
+#endif
+
+extern int printf(const char *, ...);
+extern void __KAI_KMPC_CONVENTION omp_set_num_threads(int);
+extern int __KAI_KMPC_CONVENTION omp_get_thread_num(void);
+
+#define N 10
+
+float f[10];
+void foo_simd(int low, int up) {
+  for (int i = low; i < up; ++i) {
+f[i] = 0.0;
+#pragma omp ordered simd
+f[i] = 1.0;
+  }
+}
+
+int main() {
+  int arr[10];
+  int i;
+  omp_set_num_threads(2);
+#pragma omp parallel
+#pragma omp single
+#pragma omp taskloop num_tasks(10)
+  for (i = 0; i < N; i++) {
+arr[i] = i * i;
+  }
+
+  for (int j = 0; j < N; j++) {
+printf("%d\n", arr[j]);
+  }
+  return 0;
+}
+
+// foo_simd is not artificial.
+// CHECK-DAG: !DISubprogram(name: "foo_simd"
+// CHECK-DAG-SAME: flags: DIFlagPrototyped,
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt_debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined._debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(linkageName: ".omp_task_entry."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined..1"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4097,8 +4097,12 @@
   if (Name.startswith("\01"))
 Name = Name.substr(1);
 
+  assert((!D || !isa(D) ||
+  GD.getDynamicInitKind() != DynamicInitKind::NoStub) &&
+ "Unexpected DynamicInitKind !");
+
   if (!HasDecl || D->isImplicit() || D->hasAttr() ||
-  (isa(D) && GD.getDynamicInitKind() != DynamicInitKind::NoStub)) 
{
+  isa(D) || isa(D)) {
 Flags |= llvm::DINode::FlagArtificial;
 // Artificial functions should not silently reuse CurLoc.
 CurLoc = SourceLocation();


Index: clang/test/OpenMP/outlined_artificial.c
===
--- /dev/null
+++ clang/test/OpenMP/outlined_artificial.c
@@ -0,0 +1,67 @@
+// This testcase checks emission of DIFlagArtificial flag for outlined
+// subroutines generated by compiler.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#if defined(_WIN32)
+#define __KAI_KMPC_CONVENTION __cdecl
+#else
+#define __KAI_KMPC_CONVENTION
+#endif
+
+extern int printf(const char *, ...);
+extern void __KAI_KMPC_CONVENTION omp_set_num_threads(int);
+extern int __KAI_KMPC_CONVENTION omp_get_thread_num(void);
+
+#define N 10
+
+float f[10];
+void foo_simd(int low, int up) {
+  for (int i = low; i < up; ++i) {
+f[i] = 0.0;
+#pragma omp ordered simd
+f[i] = 1.0;
+  }
+}
+
+int main() {
+  int arr[10];
+  int i;
+  omp_set_num_threads(2);
+#pragma omp parallel
+#pragma omp single
+#pragma omp taskloop num_tasks(10)
+  for (i = 0; i < N; i++) {
+arr[i] = i * i;
+  }
+
+  for (int j = 0; j < N; j++) {
+printf("%d\n", arr[j]);
+  }
+  return 0;
+}
+
+// foo_simd is not artificial.
+// CHECK-DAG: !DISubprogram(name: "foo_simd"
+// CHECK-DAG-SAME: flags: DIFlagPrototyped,
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt_debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined._debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(linkageName: ".omp_task_entry."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined..1"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
Index: clang/lib/CodeGen/CGDebugInfo.cpp
=

[PATCH] D130863: [clangd] Make git ignore index directories

2022-08-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

I'm with Kadir on this one, but maybe I'm too attached to my 
`.git/info/exclude`s. I somehow don't feel it's a big burden specific to 
clangd. I have to configure `.gitignore` for my projects and 
`.git/info/excludes` for other projects I work on because of many tools I 
personally use (editors, etc).

If this lands, I feel we should say `*` in the added `.gitignore` and put it 
into `.cache/clangd`.
That way the `.cache` folder does not appear in the git status at all and this 
improves the workflow for people who use git, i.e. they don't see anything 
related to clangd's internal storage in their VCS by default.

Otherwise, I would personally still put `.cache/clangd` into the global 
`.gitignore` or `.git/info/exclude`. IMO `.cache/clangd` should not be in the 
VCS history at all, even if only for the `.gitignore` files.
So landing this as is wouldn't really improve the situation for me personally.
Maybe my workflow is different from what others do, but hopefully this can be 
helpful.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130863

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


[PATCH] D130863: [clangd] Make git ignore index directories

2022-08-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D130863#3693135 , @ilya-biryukov 
wrote:

> Otherwise, I would personally still put `.cache/clangd` into the global 
> `.gitignore` or `.git/info/exclude`. IMO `.cache/clangd` should not be in the 
> VCS history at all, even if only for the `.gitignore` files.
> So landing this as is wouldn't really improve the situation for me personally.

Oh, i was under the impression that git didn't track empty directories and this 
was recursive: if .cache/clangd/index/* are ignored then index/ doesn't exist, 
so nor does clangd/ or .cache/.

If this is not the case i agree the value is less... (Can't check, don't have a 
real computer this week)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130863

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


[PATCH] D127803: Generate the capture for field when the field is used in openmp region with implicit default in the member function.

2022-08-02 Thread mgabka via Phabricator via cfe-commits
mgabka added a comment.

I noticed that this patch is causing now an assertion failure for cases like :

class A{

  void a() {
#pragma omp parallel
a(b);
  }

};

The failed assertion is: "const clang::ValueDecl* getCanonicalDecl(const 
clang::ValueDecl*): Assertion `FD' failed."

while before it clang was correctly  reporting error:
error: use of undeclared identifier 'b'

is it the same assertion you were trying to fix here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127803

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


[PATCH] D130847: [clang] SourceManager: fix isOffsetInFileID for the case of a fake SLocEntry

2022-08-02 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko updated this revision to Diff 449261.
ivanmurashko added a comment.

Fix for wrong LastFileIDLookup assignment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130847

Files:
  clang/lib/Basic/SourceManager.cpp


Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -880,7 +880,7 @@
   for (NumProbes = 0; NumProbes < 8; ++NumProbes, ++I) {
 // Make sure the entry is loaded!
 const SrcMgr::SLocEntry &E = getLoadedSLocEntry(I);
-if (E.getOffset() <= SLocOffset) {
+if (E.getOffset() != 0 && E.getOffset() <= SLocOffset) {
   FileID Res = FileID::get(-int(I) - 2);
   LastFileIDLookup = Res;
   NumLinearScans += NumProbes + 1;


Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -880,7 +880,7 @@
   for (NumProbes = 0; NumProbes < 8; ++NumProbes, ++I) {
 // Make sure the entry is loaded!
 const SrcMgr::SLocEntry &E = getLoadedSLocEntry(I);
-if (E.getOffset() <= SLocOffset) {
+if (E.getOffset() != 0 && E.getOffset() <= SLocOffset) {
   FileID Res = FileID::get(-int(I) - 2);
   LastFileIDLookup = Res;
   NumLinearScans += NumProbes + 1;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130847: [clang] SourceManager: fix isOffsetInFileID for the case of a fake SLocEntry

2022-08-02 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko added a comment.

In D130847#3690977 , @aaron.ballman 
wrote:

> 



> Given that this code is on the hot path, should it be the caller's 
> responsibility to have already validated the `FileID` that's passed in so 
> that the fake entry can never be returned?

That is a good point. The crash that I am trying to fix uses incorrectly 
assigned `SourceManager::LastFileIDLookup`, see SourceManager::getFileID 
.
 It's worth avoiding the incorrect cache value assignment. I could determine 
the place at the code where the assignment was made and updated the patch 
accordingly.

@aaron.ballman, could you look at the update. Is it reasonable?

Note: the change introduces a check that similar to one made previously 
 for the 
rest of the search procedure




Comment at: clang/include/clang/Basic/SourceManager.h:1112-1113
 // If our one-entry cache covers this offset, just return it.
 if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
   return LastFileIDLookup;
 

nit: There is the place when `isOffsetInFileID` produces a wrong result at my 
case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130847

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


[PATCH] D130847: [clang] SourceManager: fix isOffsetInFileID for the case of a fake SLocEntry

2022-08-02 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko added inline comments.



Comment at: clang/lib/Basic/SourceManager.cpp:901
 const SrcMgr::SLocEntry &E = getLoadedSLocEntry(MiddleIndex);
 if (E.getOffset() == 0)
   return FileID(); // invalid entry.

FYI: the same check is used for the rest of the search procedure


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130847

___
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-08-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D129048#3692394 , @thakis wrote:

> This change caused a ton of churn, for what I understand fix the diag in C 
> mode when assert.h is not included.

Which is not that uncommon of a scenario: 
https://sourcegraph.com/search?q=context:global+file:.*%5C.c+_Static_assert&patternType=literal&case=yes

> IMHO, it would've been better to change the diag to say either 
> `static_assert` as before in c++ mode or when assert.h is included (i.e. 
> almost always), and `_Static_assert` else. You can use 
> PP.getLastMacroWithSpelling() to (effectively) detect if assert.h was 
> included.
>
> Is this something y'all had considered?

Yes, and that approach is actually more complicated to get correct. Part of the 
trouble is MSVC compatibility where `static_assert` is allowed in C mode even 
without including `assert.h` and that kind of thing. Ultimately, we decided the 
principle is: if the diagnostic is about parsing the syntax we'll use the 
actual token name, otherwise we'll use "static assertion" as a prose term 
instead to avoid having the diagnostic be wrong in edge cases.


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] D130964: [X86][BF16] Enable __bf16 for x86 targets.

2022-08-02 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

Add to `ReleaseNotes.rst` as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130964

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


[PATCH] D130984: [clang][AArch64][SVE] Add unary +/- operators for SVE types

2022-08-02 Thread David Truby via Phabricator via cfe-commits
DavidTruby created this revision.
Herald added subscribers: ctetreau, psnobl, kristof.beyls, tschuett.
Herald added a reviewer: efriedma.
Herald added a project: All.
DavidTruby requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch enables the unary promotion and negation operators on
SVE types.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130984

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGen/aarch64-sve-vector-arith-ops.c

Index: clang/test/CodeGen/aarch64-sve-vector-arith-ops.c
===
--- clang/test/CodeGen/aarch64-sve-vector-arith-ops.c
+++ clang/test/CodeGen/aarch64-sve-vector-arith-ops.c
@@ -1650,3 +1650,143 @@
 svuint64_t rem_scalar_u64(svuint64_t a, uint64_t b) {
   return a % b;
 }
+
+// UNARY PROMOTION
+
+// CHECK-LABEL: @prom_i8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret  [[A:%.*]]
+//
+svint8_t prom_i8(svint8_t a) {
+  return +a;
+}
+
+// CHECK-LABEL: @prom_i16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret  [[A:%.*]]
+//
+svint16_t prom_i16(svint16_t a) {
+  return +a;
+}
+
+// CHECK-LABEL: @prom_i32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret  [[A:%.*]]
+//
+svint32_t prom_i32(svint32_t a) {
+  return +a;
+}
+
+// CHECK-LABEL: @prom_i64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret  [[A:%.*]]
+//
+svint64_t prom_i64(svint64_t a) {
+  return +a;
+}
+
+// CHECK-LABEL: @prom_u8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret  [[A:%.*]]
+//
+svuint8_t prom_u8(svuint8_t a) {
+  return +a;
+}
+
+// CHECK-LABEL: @prom_u16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret  [[A:%.*]]
+//
+svuint16_t prom_u16(svuint16_t a) {
+  return +a;
+}
+
+// CHECK-LABEL: @prom_u32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret  [[A:%.*]]
+//
+svuint32_t prom_u32(svuint32_t a) {
+  return +a;
+}
+
+// CHECK-LABEL: @prom_u64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret  [[A:%.*]]
+//
+svuint64_t prom_u64(svuint64_t a) {
+  return +a;
+}
+
+// UNARY NEGATION
+
+// CHECK-LABEL: @neg_i8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SUB:%.*]] = sub  zeroinitializer, [[A:%.*]]
+// CHECK-NEXT:ret  [[SUB]]
+//
+svint8_t neg_i8(svint8_t a) {
+  return -a;
+}
+
+// CHECK-LABEL: @neg_i16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SUB:%.*]] = sub  zeroinitializer, [[A:%.*]]
+// CHECK-NEXT:ret  [[SUB]]
+//
+svint16_t neg_i16(svint16_t a) {
+  return -a;
+}
+
+// CHECK-LABEL: @neg_i32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SUB:%.*]] = sub  zeroinitializer, [[A:%.*]]
+// CHECK-NEXT:ret  [[SUB]]
+//
+svint32_t neg_i32(svint32_t a) {
+  return -a;
+}
+
+// CHECK-LABEL: @neg_i64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SUB:%.*]] = sub  zeroinitializer, [[A:%.*]]
+// CHECK-NEXT:ret  [[SUB]]
+//
+svint64_t neg_i64(svint64_t a) {
+  return -a;
+}
+
+// CHECK-LABEL: @neg_u8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SUB:%.*]] = sub  zeroinitializer, [[A:%.*]]
+// CHECK-NEXT:ret  [[SUB]]
+//
+svuint8_t neg_u8(svuint8_t a) {
+  return -a;
+}
+
+// CHECK-LABEL: @neg_u16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SUB:%.*]] = sub  zeroinitializer, [[A:%.*]]
+// CHECK-NEXT:ret  [[SUB]]
+//
+svuint16_t neg_u16(svuint16_t a) {
+  return -a;
+}
+
+// CHECK-LABEL: @neg_u32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SUB:%.*]] = sub  zeroinitializer, [[A:%.*]]
+// CHECK-NEXT:ret  [[SUB]]
+//
+svuint32_t neg_u32(svuint32_t a) {
+  return -a;
+}
+
+// CHECK-LABEL: @neg_u64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SUB:%.*]] = sub  zeroinitializer, [[A:%.*]]
+// CHECK-NEXT:ret  [[SUB]]
+//
+svuint64_t neg_u64(svuint64_t a) {
+  return -a;
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15605,6 +15605,8 @@
   resultType->castAs()->getVectorKind() !=
   VectorType::AltiVecBool))
   break;
+else if (resultType->isVLSTBuiltinType()) // SVE vectors allow + and -
+  break;
 else if (getLangOpts().CPlusPlus && // C++ [expr.unary.op]p6
  Opc == UO_Plus &&
  resultType->isPointerType())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130863: [clangd] Make git ignore index directories

2022-08-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D130863#3693293 , @sammccall wrote:

> In D130863#3693135 , @ilya-biryukov 
> wrote:
>
>> Otherwise, I would personally still put `.cache/clangd` into the global 
>> `.gitignore` or `.git/info/exclude`. IMO `.cache/clangd` should not be in 
>> the VCS history at all, even if only for the `.gitignore` files.
>> So landing this as is wouldn't really improve the situation for me 
>> personally.
>
> Oh, i was under the impression that git didn't track empty directories and 
> this was recursive: if .cache/clangd/index/* are ignored then index/ doesn't 
> exist, so nor does clangd/ or .cache/.
>
> If this is not the case i agree the value is less... (Can't check, don't have 
> a real computer this week)

No, you're right. I was mistaken about what the patch is doing.
Forget what I said, this change is fine. No `.gitignore` files are in the `git 
status` output.

I'm still think that I need to ignore files for other tools I use anyway, so 
not doing this for clangd is not a big improvement.
But that's just my opinion, please disregard other concerns.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130863

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


[PATCH] D120175: [Driver] Re-run lld with --reproduce when it crashes

2022-08-02 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

> lld has tests for --reproduce already. Even if I added an environment 
> variable to crash lld, the test would depend on lld being built, adding a big 
> dependency to clang's tests. Do we think that's worth it?

There is now cross-project-tests which would seem to be the appropriate place 
for a test that wants to run both clang and lld.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120175

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


[PATCH] D130754: [X86] Support ``-mindirect-branch-cs-prefix`` for call and jmp to indirect thunk

2022-08-02 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 449275.
pengfei marked an inline comment as done.
pengfei added a comment.

Add CC1 option test.

> When a module with "`indirect_branch_cs_prefix`" and another without the 
> module flag are merged, what the result should be? If 0, we should use `Min` 
> instead of `Override`.

I think `Override` is correct. This option is used for Linux Kernel build. When 
merged, all should be set to 1.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130754

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/X86/indirect-branch-cs-prefix.c
  clang/test/Driver/x86_features.c
  llvm/lib/Target/X86/X86MCInstLower.cpp
  llvm/lib/Target/X86/X86ReturnThunks.cpp
  llvm/test/CodeGen/X86/attr-function-return.ll
  llvm/test/CodeGen/X86/lvi-hardening-indirectbr.ll

Index: llvm/test/CodeGen/X86/lvi-hardening-indirectbr.ll
===
--- llvm/test/CodeGen/X86/lvi-hardening-indirectbr.ll
+++ llvm/test/CodeGen/X86/lvi-hardening-indirectbr.ll
@@ -22,18 +22,22 @@
 ; X64:   callq bar
 ; X64-DAG:   movl %[[x]], %edi
 ; X64-DAG:   movq %[[fp]], %r11
-; X64:   callq __llvm_lvi_thunk_r11
+; X64:   cs
+; X64-NEXT:  callq __llvm_lvi_thunk_r11
 ; X64:   movl %[[x]], %edi
 ; X64:   callq bar
 ; X64-DAG:   movl %[[x]], %edi
 ; X64-DAG:   movq %[[fp]], %r11
-; X64:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+; X64:   cs
+; X64-NEXT:  jmp __llvm_lvi_thunk_r11 # TAILCALL
 
 ; X64FAST-LABEL: icall_reg:
 ; X64FAST:   callq bar
-; X64FAST:   callq __llvm_lvi_thunk_r11
+; X64FAST:   cs
+; X64FAST-NEXT:  callq __llvm_lvi_thunk_r11
 ; X64FAST:   callq bar
-; X64FAST:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+; X64FAST:   cs
+; X64FAST-NEXT:  jmp __llvm_lvi_thunk_r11 # TAILCALL
 
 
 @global_fp = external dso_local global ptr
@@ -50,16 +54,20 @@
 ; X64-LABEL: icall_global_fp:
 ; X64-DAG:   movl %edi, %[[x:[^ ]*]]
 ; X64-DAG:   movq global_fp(%rip), %r11
-; X64:   callq __llvm_lvi_thunk_r11
+; X64:   cs
+; X64-NEXT:  callq __llvm_lvi_thunk_r11
 ; X64-DAG:   movl %[[x]], %edi
 ; X64-DAG:   movq global_fp(%rip), %r11
-; X64:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+; X64:   cs
+; X64-NEXT:  jmp __llvm_lvi_thunk_r11 # TAILCALL
 
 ; X64FAST-LABEL: icall_global_fp:
 ; X64FAST:   movq global_fp(%rip), %r11
-; X64FAST:   callq __llvm_lvi_thunk_r11
+; X64FAST:   cs
+; X64FAST-NEXT:  callq __llvm_lvi_thunk_r11
 ; X64FAST:   movq global_fp(%rip), %r11
-; X64FAST:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+; X64FAST:   cs
+; X64FAST-NEXT:  jmp __llvm_lvi_thunk_r11 # TAILCALL
 
 
 %struct.Foo = type { ptr }
@@ -79,14 +87,18 @@
 ; X64:   movq (%rdi), %[[vptr:[^ ]*]]
 ; X64:   movq 8(%[[vptr]]), %[[fp:[^ ]*]]
 ; X64:   movq %[[fp]], %r11
-; X64:   callq __llvm_lvi_thunk_r11
+; X64:   cs
+; X64-NEXT:  callq __llvm_lvi_thunk_r11
 ; X64-DAG:   movq %[[obj]], %rdi
 ; X64-DAG:   movq %[[fp]], %r11
-; X64:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+; X64:   cs
+; X64-NEXT:  jmp __llvm_lvi_thunk_r11 # TAILCALL
 
 ; X64FAST-LABEL: vcall:
-; X64FAST:   callq __llvm_lvi_thunk_r11
-; X64FAST:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+; X64FAST:   cs
+; X64FAST-NEXT:  callq __llvm_lvi_thunk_r11
+; X64FAST:   cs
+; X64FAST-NEXT:  jmp __llvm_lvi_thunk_r11 # TAILCALL
 
 
 declare dso_local void @direct_callee()
@@ -113,14 +125,18 @@
 ; X64-LABEL: nonlazybind_caller:
 ; X64:   movq nonlazybind_callee@GOTPCREL(%rip), %[[REG:.*]]
 ; X64:   movq %[[REG]], %r11
-; X64:   callq __llvm_lvi_thunk_r11
+; X64:   cs
+; X64-NEXT:  callq __llvm_lvi_thunk_r11
 ; X64:   movq %[[REG]], %r11
-; X64:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+; X64:   cs
+; X64-NEXT:  jmp __llvm_lvi_thunk_r11 # TAILCALL
 ; X64FAST-LABEL: nonlazybind_caller:
 ; X64FAST:   movq nonlazybind_callee@GOTPCREL(%rip), %r11
-; X64FAST:   callq __llvm_lvi_thunk_r11
+; X64FAST:   cs
+; X64FAST-NEXT:  callq __llvm_lvi_thunk_r11
 ; X64FAST:   movq nonlazybind_callee@GOTPCREL(%rip), %r11
-; X64FAST:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+; X64FAST:   cs
+; X64FAST-NEXT:  jmp __llvm_lvi_thunk_r11 # TAILCALL
 
 
 ; Check that a switch gets lowered using a jump table
@@ -278,3 +294,7 @@
 ; X64-NEXT:  jmpq *%r11
 
 attributes #1 = { nonlazybind }
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 4, !"indirect_branch_cs_prefix", i32 1}
Index: llvm/test/CodeGen/X86/attr-function-return.ll
===
--- llvm/test/CodeGen/X86/attr-function-return.ll
+++ llvm/test/CodeGen/X86/attr-function-return.ll
@@ -6,6 +6,11 @@
 define void @x() fn_ret_thunk_extern {
 ; CHECK-LABEL: x:
 ; CHECK:   # %bb.0:

[PATCH] D130510: Missing tautological compare warnings due to unary operators

2022-08-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D130510#3692654 , @rtrieu wrote:

> This warning is now flagging some code which I believe is a false positive.  
> In particular, when template arguments are involved, their values can be 
> calculated during template instantiation, but they should be treated as 
> variables instead of constants.  For example:
>
>   template 
>   void foo(int x) {
>   bool b1 = (x & sizeof(T)) == 8;
>   bool b2 = (x & I) == 8;
>   bool b3 = (x & 4) == 8;
>   }
>   
>   void run(int x) {
>   foo<4, int>(8);
>   }
>
> In this instantiation, x is and'ed with the value 4 in different ways.  
> `sizeof(T)` is type-dependent, `I` is value-dependent, and `4` is an integer 
> literal.  With your code, each of them would produce a warning.  However, the 
> first two values of 4 will change in different template instantiations, so 
> the warning is not useful when it is okay for some instantiations to have 
> constant values.

Yeah, this is definitely a false positive we need to avoid, thank you for 
bringing it up!

> Because of this, warnings should treat dependent expressions as non-constant 
> even when they can be evaluated, so only `b3` should get a warning.  This is 
> causing the warning to be emitted on code heavy in template meta-programming, 
> such as array libraries.  Please revert or fix.

Yeah, I agree. Unfortunately, the CFG makes this exceptionally difficult 
because it walks over the instantiated code, so we've lost that the original 
expression was dependent by the time we get to checking the binary expressions. 
The original code worked by virtue of overfitting to *just* integer literals.

> I believe that evaluating the expression would make this warning too broad 
> and would need more testing that what was included here.  Only handling 
> UnaryOperator with IntegerLiteral sub-expression makes more sense for the 
> warning, and adding in any new cases if we find them.

I agree that the warning is too broad right now and that's unintentional. 
However, manually handling every single case in the CFG as something special is 
fragile and what got us this bug in the first place. We have a constant 
expression evaluator (two, actually) and we shouldn't have to reimplement it a 
third time in the CFG. However, asking a GSoC mentee to address that is well 
beyond the scope of what they should be working on. So for now I'm going to 
revert this change, reopen the issue, and we'll discuss the next steps off-list 
with Usman.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130510

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


[clang] c783ca0 - Revert "Missing tautological compare warnings due to unary operators"

2022-08-02 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-08-02T09:39:36-04:00
New Revision: c783ca0de1e1e00f364cf4745b8444a020ddd29b

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

LOG: Revert "Missing tautological compare warnings due to unary operators"

This reverts commit 0cc3c184c784d5f0d55de8ad0a9876acd149.

The changes did not account for templated code where one instantiation
may trigger the diagnostic but other instantiations will not, as in:
```
template 
void foo(int x) {
bool b1 = (x & sizeof(T)) == 8;
bool b2 = (x & I) == 8;
bool b3 = (x & 4) == 8;
}

void run(int x) {
foo<4, int>(8);
}
```

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Analysis/CFG.cpp
clang/test/Sema/warn-bitwise-compare.c
clang/test/SemaCXX/warn-unreachable.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f3d8200c0d1a8..782659346e52e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -49,9 +49,6 @@ Major New Features
 
 Bug Fixes
 -
-- ``-Wtautological-compare`` missed warnings for tautological comparisons
-  involving a negative integer literal. This fixes
-  `Issue 42918 `_.
 - Fixes an accepts-invalid bug in C when using a ``_Noreturn`` function
   specifier on something other than a function declaration. This fixes
   `Issue 56800 `_.

diff  --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 282e0066642b6..5c45264896027 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -964,44 +964,43 @@ class CFGBuilder {
 const Expr *LHSExpr = B->getLHS()->IgnoreParens();
 const Expr *RHSExpr = B->getRHS()->IgnoreParens();
 
-const Expr *BoolExpr = nullptr; // To store the expression.
-Expr::EvalResult IntExprResult; // If integer literal then will save value.
+const IntegerLiteral *IntLiteral = dyn_cast(LHSExpr);
+const Expr *BoolExpr = RHSExpr;
 
-if (LHSExpr->EvaluateAsInt(IntExprResult, *Context))
-  BoolExpr = RHSExpr;
-else if (RHSExpr->EvaluateAsInt(IntExprResult, *Context))
+if (!IntLiteral) {
+  IntLiteral = dyn_cast(RHSExpr);
   BoolExpr = LHSExpr;
-else
-  return TryResult();
+}
 
-llvm::APInt L1 = IntExprResult.Val.getInt();
+if (!IntLiteral)
+  return TryResult();
 
 const BinaryOperator *BitOp = dyn_cast(BoolExpr);
-if (BitOp &&
-(BitOp->getOpcode() == BO_And || BitOp->getOpcode() == BO_Or)) {
+if (BitOp && (BitOp->getOpcode() == BO_And ||
+  BitOp->getOpcode() == BO_Or)) {
+  const Expr *LHSExpr2 = BitOp->getLHS()->IgnoreParens();
+  const Expr *RHSExpr2 = BitOp->getRHS()->IgnoreParens();
 
-  // If integer literal in expression identified then will save value.
-  Expr::EvalResult IntExprResult2;
+  const IntegerLiteral *IntLiteral2 = dyn_cast(LHSExpr2);
 
-  if (BitOp->getLHS()->EvaluateAsInt(IntExprResult2, *Context))
-; // LHS is a constant expression.
-  else if (BitOp->getRHS()->EvaluateAsInt(IntExprResult2, *Context))
-; // RHS is a constant expression.
-  else
-return TryResult(); // Neither is a constant expression, bail out.
+  if (!IntLiteral2)
+IntLiteral2 = dyn_cast(RHSExpr2);
 
-  llvm::APInt L2 = IntExprResult2.Val.getInt();
+  if (!IntLiteral2)
+return TryResult();
 
+  llvm::APInt L1 = IntLiteral->getValue();
+  llvm::APInt L2 = IntLiteral2->getValue();
   if ((BitOp->getOpcode() == BO_And && (L2 & L1) != L1) ||
-  (BitOp->getOpcode() == BO_Or && (L2 | L1) != L1)) {
+  (BitOp->getOpcode() == BO_Or  && (L2 | L1) != L1)) {
 if (BuildOpts.Observer)
   BuildOpts.Observer->compareBitwiseEquality(B,
  B->getOpcode() != BO_EQ);
 TryResult(B->getOpcode() != BO_EQ);
   }
 } else if (BoolExpr->isKnownToHaveBooleanValue()) {
-  llvm::APInt IntValue = IntExprResult.Val.getInt(); // Getting the value.
-  if ((L1 == 1) || (L1 == 0)) {
+  llvm::APInt IntValue = IntLiteral->getValue();
+  if ((IntValue == 1) || (IntValue == 0)) {
 return TryResult();
   }
   return TryResult(B->getOpcode() != BO_EQ);

diff  --git a/clang/test/Sema/warn-bitwise-compare.c 
b/clang/test/Sema/warn-bitwise-compare.c
index b96881fe296e2..08a8b084fe795 100644
--- a/clang/test/Sema/warn-bitwise-compare.c
+++ b/clang/test/Sema/warn-bitwise-compare.c
@@ -2,7 +2,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wall -Wno-unused %s
 
 #define mydefine 2
-#define mydefine2 -2
 
 enum {
   ZERO,
@@ -12,67 +11,29 @@ enum {
 void f(int x) {
   if (

[PATCH] D130510: Missing tautological compare warnings due to unary operators

2022-08-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

I've reverted in c783ca0de1e1e00f364cf4745b8444a020ddd29b 
. Marking 
as requesting changes to make it clear more work needs to be done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130510

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


[PATCH] D130936: [SemaCXX] Validate destructor is valid for dependent classes

2022-08-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

Hmm... I'm a little shocked that didn't error before, while we did the 2nd pass 
through the destructor.  A little shocking this made it this far...

The fix looks fine to me, I wish I knew why we had that check there, but I got 
lost in the subversion history.

Anyway, LGTM with 1 nit..  ALSO needs a release note.




Comment at: clang/test/SemaCXX/member-class-11.cpp:30
+}
\ No newline at end of file


Nit: Need newline at end of file (C++98 rule).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130936

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


[PATCH] D130705: [clang][ASTImporter] Improve import of functions with auto return type.

2022-08-02 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D130705#3685299 , @balazske wrote:

> It is still not perfect, analysis of qtbase is not better than before and 
> some of the unreachable assertions were encountered.

Does it mean you plan some updates on this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130705

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


[PATCH] D127803: Generate the capture for field when the field is used in openmp region with implicit default in the member function.

2022-08-02 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

In D127803#3693301 , @mgabka wrote:

> I noticed that this patch is causing now an assertion failure for cases like :
>
> class A{
>
>   void a() {
> #pragma omp parallel
> a(b);
>   }
>
> };
>
> The failed assertion is: "const clang::ValueDecl* getCanonicalDecl(const 
> clang::ValueDecl*): Assertion `FD' failed."
>
> while before it clang was correctly  reporting error:
> error: use of undeclared identifier 'b'
>
> is it the same assertion you were trying to fix here?

No, the assert I am fixing is when default(firstprivate) is used inside member 
function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127803

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


[PATCH] D127803: Generate the capture for field when the field is used in openmp region with implicit default in the member function.

2022-08-02 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D127803#3693655 , @jyu2 wrote:

> In D127803#3693301 , @mgabka wrote:
>
>> I noticed that this patch is causing now an assertion failure for cases like 
>> :
>>
>> class A{
>>
>>   void a() {
>> #pragma omp parallel
>> a(b);
>>   }
>>
>> };
>>
>> The failed assertion is: "const clang::ValueDecl* getCanonicalDecl(const 
>> clang::ValueDecl*): Assertion `FD' failed."
>>
>> while before it clang was correctly  reporting error:
>> error: use of undeclared identifier 'b'
>>
>> is it the same assertion you were trying to fix here?
>
> No, the assert I am fixing is when default(firstprivate) is used inside 
> member function.

Could you please investigate and fix it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127803

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


[PATCH] D130847: [clang] SourceManager: fix isOffsetInFileID for the case of a fake SLocEntry

2022-08-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

These changes look reasonable, but I verified that the precommit CI failures 
are valid -- it looks like this change broke a test somehow; perhaps a caller 
was relying on the old behavior and needs to be reworked?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130847

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


[PATCH] D130394: [clang][CodeGen] Factor out Swift ABI hooks (NFCI)

2022-08-02 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130394

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


[PATCH] D127803: Generate the capture for field when the field is used in openmp region with implicit default in the member function.

2022-08-02 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

In D127803#3693660 , @ABataev wrote:

> In D127803#3693655 , @jyu2 wrote:
>
>> In D127803#3693301 , @mgabka wrote:
>>
>>> I noticed that this patch is causing now an assertion failure for cases 
>>> like :
>>>
>>> class A{
>>>
>>>   void a() {
>>> #pragma omp parallel
>>> a(b);
>>>   }
>>>
>>> };
>>>
>>> The failed assertion is: "const clang::ValueDecl* getCanonicalDecl(const 
>>> clang::ValueDecl*): Assertion `FD' failed."
>>>
>>> while before it clang was correctly  reporting error:
>>> error: use of undeclared identifier 'b'
>>>
>>> is it the same assertion you were trying to fix here?
>>
>> No, the assert I am fixing is when default(firstprivate) is used inside 
>> member function.
>
> Could you please investigate and fix it?

Yes, I will fix this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127803

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


[PATCH] D129016: [PowerPC] implemented @llvm.ppc.kill.canary to corrupt stack guard

2022-08-02 Thread Paul Scoropan via Phabricator via cfe-commits
pscoro updated this revision to Diff 449299.
pscoro marked 3 inline comments as done.
pscoro added a comment.

Fixed test cases and AIX implementation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129016

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Basic/Targets/PPC.cpp
  clang/test/CodeGen/PowerPC/builtins-ppc-stackprotect.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/test/CodeGen/PowerPC/kill-canary-intrinsic.ll

Index: llvm/test/CodeGen/PowerPC/kill-canary-intrinsic.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/kill-canary-intrinsic.ll
@@ -0,0 +1,142 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-aix -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr7 --ppc-asm-full-reg-names < %s | FileCheck %s -check-prefix=CHECK-AIX
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr7 --ppc-asm-full-reg-names < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr7 --ppc-asm-full-reg-names < %s | FileCheck %s -check-prefix=CHECK-AIX64
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr7 --ppc-asm-full-reg-names < %s | FileCheck %s -check-prefix=CHECK-LINUX-LE
+
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-aix -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr8 --ppc-asm-full-reg-names < %s | FileCheck %s -check-prefix=CHECK-AIX
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr8 --ppc-asm-full-reg-names < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr8 --ppc-asm-full-reg-names < %s | FileCheck %s -check-prefix=CHECK-AIX64
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr8 --ppc-asm-full-reg-names < %s | FileCheck %s -check-prefix=CHECK-LINUX-LE
+
+attributes #1 = { nounwind }
+declare void @llvm.ppc.kill.canary()
+define dso_local void @test_kill_canary() #1 {
+; CHECK-AIX-LABEL: test_kill_canary:
+; CHECK-AIX:   # %bb.0: # %entry
+; CHECK-AIX-NEXT:blr
+;
+; CHECK-LABEL: test_kill_canary:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:blr
+;
+; CHECK-AIX64-LABEL: test_kill_canary:
+; CHECK-AIX64:   # %bb.0: # %entry
+; CHECK-AIX64-NEXT:blr
+;
+; CHECK-LINUX-LE-LABEL: test_kill_canary:
+; CHECK-LINUX-LE:   # %bb.0: # %entry
+; CHECK-LINUX-LE-NEXT:blr
+entry:
+  call void @llvm.ppc.kill.canary()
+  ret void
+}
+
+attributes #0 = { sspreq }
+; Function Attrs: sspreq
+define dso_local void @test_kill_canary_ssp() #0 #1 {
+; CHECK-AIX-LABEL: test_kill_canary_ssp:
+; CHECK-AIX:   # %bb.0: # %entry
+; CHECK-AIX-NEXT:mflr r0
+; CHECK-AIX-NEXT:stw r0, 8(r1)
+; CHECK-AIX-NEXT:stwu r1, -64(r1)
+; CHECK-AIX-NEXT:lwz r3, L..C0(r2) # @__ssp_canary_word
+; CHECK-AIX-NEXT:lwz r4, 0(r3)
+; CHECK-AIX-NEXT:stw r4, 60(r1)
+; CHECK-AIX-NEXT:lwz r4, 0(r3)
+; CHECK-AIX-NEXT:not r4, r4
+; CHECK-AIX-NEXT:stw r4, 60(r1)
+; CHECK-AIX-NEXT:lwz r3, 0(r3)
+; CHECK-AIX-NEXT:lwz r4, 60(r1)
+; CHECK-AIX-NEXT:cmplw r3, r4
+; CHECK-AIX-NEXT:bne cr0, L..BB1_2
+; CHECK-AIX-NEXT:  # %bb.1: # %entry
+; CHECK-AIX-NEXT:addi r1, r1, 64
+; CHECK-AIX-NEXT:lwz r0, 8(r1)
+; CHECK-AIX-NEXT:mtlr r0
+; CHECK-AIX-NEXT:blr
+; CHECK-AIX-NEXT:  L..BB1_2: # %entry
+; CHECK-AIX-NEXT:bl .__stack_chk_fail[PR]
+; CHECK-AIX-NEXT:nop
+;
+; CHECK-LABEL: test_kill_canary_ssp:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:mflr r0
+; CHECK-NEXT:std r0, 16(r1)
+; CHECK-NEXT:stdu r1, -128(r1)
+; CHECK-NEXT:ld r3, -28688(r13)
+; CHECK-NEXT:std r3, 120(r1)
+; CHECK-NEXT:ld r3, -28688(r13)
+; CHECK-NEXT:not r3, r3
+; CHECK-NEXT:std r3, 120(r1)
+; CHECK-NEXT:ld r3, 120(r1)
+; CHECK-NEXT:ld r4, -28688(r13)
+; CHECK-NEXT:cmpld r4, r3
+; CHECK-NEXT:bne cr0, .LBB1_2
+; CHECK-NEXT:  # %bb.1: # %entry
+; CHECK-NEXT:addi r1, r1, 128
+; CHECK-NEXT:ld r0, 16(r1)
+; CHECK-NEXT:mtlr r0
+; CHECK-NEXT:blr
+; CHECK-NEXT:  .LBB1_2: # %entry
+; CHECK-NEXT:bl __stack_chk_fail
+; CHECK-NEXT:nop
+;
+; CHECK-AIX64-LABEL: test_kill_canary_ssp:
+; CHECK-AIX64:   # %bb.0: # %entry
+; CHECK-AIX64-NEXT:mflr r0
+; CHECK-AIX64-NEXT:std r0, 16(r1)
+; CHECK-AIX64-NEXT:stdu r1, -128(r1)
+; CHECK-AIX64-NEXT:ld r3, L..C0(r2) # @__ssp_canary_word
+; CHECK-AIX64-NEXT:ld r4, 0(r3)
+; CHECK-AIX64-NEXT:std r4, 120(r1)
+; CHECK-AIX64-NEXT:ld r4, 0(r3)
+; CHECK-AIX64-NEXT:not r4, r4
+; CHECK-AIX64-NEXT: 

[PATCH] D129016: [PowerPC] implemented @llvm.ppc.kill.canary to corrupt stack guard

2022-08-02 Thread Paul Scoropan via Phabricator via cfe-commits
pscoro marked 8 inline comments as done.
pscoro added inline comments.



Comment at: llvm/test/CodeGen/PowerPC/kill-canary-intrinsic.ll:11
+
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-aix 
-ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr8 --ppc-asm-full-reg-names < %s | FileCheck %s 
-check-prefix=CHECK-AIX

How many test cases should I include? I tested all these machine triples on 
Power 7-10, bought I thought having 16 run lines may be too much, so I only 
included the power 7 and 8 run lines in the review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129016

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


[PATCH] D130847: [clang] SourceManager: fix isOffsetInFileID for the case of a fake SLocEntry

2022-08-02 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko added a comment.

In D130847#3693668 , @aaron.ballman 
wrote:

> These changes look reasonable, but I verified that the precommit CI failures 
> are valid -- it looks like this change broke a test somehow; perhaps a caller 
> was relying on the old behavior and needs to be reworked?

Ah, I have to verify and fix it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130847

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


[PATCH] D130705: [clang][ASTImporter] Improve import of functions with auto return type.

2022-08-02 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Yes, I plan to add improvements but the current code remains mostly. I found 
other type of error (in project //qtbase//) that are not directly related, too 
(infinite import loop of deduction guide without auto return value, one of the 
function arguments is involved), these will remain for future work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130705

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


[PATCH] D111521: [DebugInfo] Mark OpenMP generated functions as artificial

2022-08-02 Thread Alok Kumar Sharma 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 rG5ec6ea3dfded: [clang][OpenMP][DebugInfo] Mark OpenMP 
generated functions as artificial (authored by alok).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111521

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/OpenMP/outlined_artificial.c


Index: clang/test/OpenMP/outlined_artificial.c
===
--- /dev/null
+++ clang/test/OpenMP/outlined_artificial.c
@@ -0,0 +1,67 @@
+// This testcase checks emission of DIFlagArtificial flag for outlined
+// subroutines generated by compiler.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#if defined(_WIN32)
+#define __KAI_KMPC_CONVENTION __cdecl
+#else
+#define __KAI_KMPC_CONVENTION
+#endif
+
+extern int printf(const char *, ...);
+extern void __KAI_KMPC_CONVENTION omp_set_num_threads(int);
+extern int __KAI_KMPC_CONVENTION omp_get_thread_num(void);
+
+#define N 10
+
+float f[10];
+void foo_simd(int low, int up) {
+  for (int i = low; i < up; ++i) {
+f[i] = 0.0;
+#pragma omp ordered simd
+f[i] = 1.0;
+  }
+}
+
+int main() {
+  int arr[10];
+  int i;
+  omp_set_num_threads(2);
+#pragma omp parallel
+#pragma omp single
+#pragma omp taskloop num_tasks(10)
+  for (i = 0; i < N; i++) {
+arr[i] = i * i;
+  }
+
+  for (int j = 0; j < N; j++) {
+printf("%d\n", arr[j]);
+  }
+  return 0;
+}
+
+// foo_simd is not artificial.
+// CHECK-DAG: !DISubprogram(name: "foo_simd"
+// CHECK-DAG-SAME: flags: DIFlagPrototyped,
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt_debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined._debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(linkageName: ".omp_task_entry."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined..1"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4097,8 +4097,12 @@
   if (Name.startswith("\01"))
 Name = Name.substr(1);
 
+  assert((!D || !isa(D) ||
+  GD.getDynamicInitKind() != DynamicInitKind::NoStub) &&
+ "Unexpected DynamicInitKind !");
+
   if (!HasDecl || D->isImplicit() || D->hasAttr() ||
-  (isa(D) && GD.getDynamicInitKind() != DynamicInitKind::NoStub)) 
{
+  isa(D) || isa(D)) {
 Flags |= llvm::DINode::FlagArtificial;
 // Artificial functions should not silently reuse CurLoc.
 CurLoc = SourceLocation();


Index: clang/test/OpenMP/outlined_artificial.c
===
--- /dev/null
+++ clang/test/OpenMP/outlined_artificial.c
@@ -0,0 +1,67 @@
+// This testcase checks emission of DIFlagArtificial flag for outlined
+// subroutines generated by compiler.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#if defined(_WIN32)
+#define __KAI_KMPC_CONVENTION __cdecl
+#else
+#define __KAI_KMPC_CONVENTION
+#endif
+
+extern int printf(const char *, ...);
+extern void __KAI_KMPC_CONVENTION omp_set_num_threads(int);
+extern int __KAI_KMPC_CONVENTION omp_get_thread_num(void);
+
+#define N 10
+
+float f[10];
+void foo_simd(int low, int up) {
+  for (int i = low; i < up; ++i) {
+f[i] = 0.0;
+#pragma omp ordered simd
+f[i] = 1.0;
+  }
+}
+
+int main() {
+  int arr[10];
+  int i;
+  omp_set_num_threads(2);
+#pragma omp parallel
+#pragma omp single
+#pragma omp taskloop num_tasks(10)
+  for (i = 0; i < N; i++) {
+arr[i] = i * i;
+  }
+
+  for (int j = 0; j < N; j++) {
+printf("%d\n", arr[j]);
+  }
+  return 0;
+}
+
+// foo_simd is not artificial.
+// CHECK-DAG: !DISubprogram(name: "foo_simd"
+// CHECK-DAG-SAME: flags: DIFlagPrototyped,
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt_debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined._debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(linkageName: ".omp_task_entry."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined."
+// CHECK-DAG-SAME: flags: DI

[clang] 5ec6ea3 - [clang][OpenMP][DebugInfo] Mark OpenMP generated functions as artificial

2022-08-02 Thread Alok Kumar Sharma via cfe-commits

Author: Alok Kumar Sharma
Date: 2022-08-02T21:24:46+05:30
New Revision: 5ec6ea3dfded028de775eb165ce0bae6f1e6c2bf

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

LOG: [clang][OpenMP][DebugInfo] Mark OpenMP generated functions as artificial

The Clang compiler generates internal functions for OpenMP. Current
patch marks these functions as artificial.

Reviewed By: aprantl

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

Added: 
clang/test/OpenMP/outlined_artificial.c

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 6821fc97e5047..522ed7ae8b144 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4097,8 +4097,12 @@ void CGDebugInfo::emitFunctionStart(GlobalDecl GD, 
SourceLocation Loc,
   if (Name.startswith("\01"))
 Name = Name.substr(1);
 
+  assert((!D || !isa(D) ||
+  GD.getDynamicInitKind() != DynamicInitKind::NoStub) &&
+ "Unexpected DynamicInitKind !");
+
   if (!HasDecl || D->isImplicit() || D->hasAttr() ||
-  (isa(D) && GD.getDynamicInitKind() != DynamicInitKind::NoStub)) 
{
+  isa(D) || isa(D)) {
 Flags |= llvm::DINode::FlagArtificial;
 // Artificial functions should not silently reuse CurLoc.
 CurLoc = SourceLocation();

diff  --git a/clang/test/OpenMP/outlined_artificial.c 
b/clang/test/OpenMP/outlined_artificial.c
new file mode 100644
index 0..4c997ef2e68f5
--- /dev/null
+++ b/clang/test/OpenMP/outlined_artificial.c
@@ -0,0 +1,67 @@
+// This testcase checks emission of DIFlagArtificial flag for outlined
+// subroutines generated by compiler.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#if defined(_WIN32)
+#define __KAI_KMPC_CONVENTION __cdecl
+#else
+#define __KAI_KMPC_CONVENTION
+#endif
+
+extern int printf(const char *, ...);
+extern void __KAI_KMPC_CONVENTION omp_set_num_threads(int);
+extern int __KAI_KMPC_CONVENTION omp_get_thread_num(void);
+
+#define N 10
+
+float f[10];
+void foo_simd(int low, int up) {
+  for (int i = low; i < up; ++i) {
+f[i] = 0.0;
+#pragma omp ordered simd
+f[i] = 1.0;
+  }
+}
+
+int main() {
+  int arr[10];
+  int i;
+  omp_set_num_threads(2);
+#pragma omp parallel
+#pragma omp single
+#pragma omp taskloop num_tasks(10)
+  for (i = 0; i < N; i++) {
+arr[i] = i * i;
+  }
+
+  for (int j = 0; j < N; j++) {
+printf("%d\n", arr[j]);
+  }
+  return 0;
+}
+
+// foo_simd is not artificial.
+// CHECK-DAG: !DISubprogram(name: "foo_simd"
+// CHECK-DAG-SAME: flags: DIFlagPrototyped,
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt_debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined._debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(linkageName: ".omp_task_entry."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined..1"
+// CHECK-DAG-SAME: flags: DIFlagArtificial



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


[PATCH] D130894: [clang] Print more information about failed static assertions

2022-08-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Oh, I noticed that g++ already does this:

  test.cpp:27:21: error: static assertion failed
 27 | static_assert(foo() < 4);
|   ~~^~~
  test.cpp:27:21: note: the comparison reduces to ‘(10 < 4)’


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

https://reviews.llvm.org/D130894

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


[PATCH] D127641: [clang-cl][MSVC] Enable /Zc:alignedNew for C++17 and /Zc:sizedDealloc by default

2022-08-02 Thread Stephen Long via Phabricator via cfe-commits
steplong updated this revision to Diff 449303.
steplong added a comment.

- Add necessary includes to use EXPECT_THAT and MatchesRegex


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127641

Files:
  clang-tools-extra/test/clang-tidy/checkers/misc-new-delete-overloads.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cl-zc.cpp
  clang/unittests/StaticAnalyzer/CallEventTest.cpp

Index: clang/unittests/StaticAnalyzer/CallEventTest.cpp
===
--- clang/unittests/StaticAnalyzer/CallEventTest.cpp
+++ clang/unittests/StaticAnalyzer/CallEventTest.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "CheckerRegistration.h"
+#include "gmock/gmock.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
@@ -22,6 +23,8 @@
 #include "clang/Tooling/Tooling.h"
 #include "gtest/gtest.h"
 
+using testing::MatchesRegex;
+
 namespace clang {
 namespace ento {
 namespace {
@@ -81,7 +84,7 @@
 }
   )",
  Diags));
-  EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 1\n");
+  EXPECT_THAT(Diags, MatchesRegex("test.CXXDeallocator: NumArgs: (1|2)\n"));
 }
 
 } // namespace
Index: clang/test/Driver/cl-zc.cpp
===
--- clang/test/Driver/cl-zc.cpp
+++ clang/test/Driver/cl-zc.cpp
@@ -1,6 +1,19 @@
 // Note: %s must be preceded by --, otherwise it may be interpreted as a
 // command-line option, e.g. on Mac where %s is commonly under /Users.
 
+// RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=SIZED-DEALLOC %s
+// RUN: %clang_cl /c -### -fms-compatibility-version=18 -- %s 2>&1 | FileCheck -check-prefix=SIZED-DEALLOC-OFF %s
+// SIZED-DEALLOC: "-fsized-deallocation"
+// SIZED-DEALLOC-OFF-NOT: "-fsized-deallocation"
+
+// RUN: %clang_cl /c /std:c++11 -### -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-BEFORE-CPP17 %s
+// RUN: %clang_cl /c /std:c++14 -### -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-BEFORE-CPP17 %s
+// RUN: %clang_cl /c /std:c++17 -### -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-CPP17ONWARDS %s
+// RUN: %clang_cl /c /std:c++20 -### -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-CPP17ONWARDS %s
+// RUN: %clang_cl /c /std:c++latest -### -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-CPP17ONWARDS %s
+// ALIGNED-NEW-BEFORE-CPP17-NOT: "-faligned-allocation"
+// ALIGNED-NEW-CPP17ONWARDS: "-faligned-allocation"
+
 // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=TRIGRAPHS-DEFAULT %s
 // cc1 will disable trigraphs for -fms-compatibility as long as -ftrigraphs
 // isn't explicitly passed.
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6470,6 +6470,7 @@
 }
 CmdArgs.push_back(LanguageStandard.data());
   }
+  bool IsCPP17Onwards = false;
   if (ImplyVCPPCXXVer) {
 StringRef LanguageStandard;
 if (const Arg *StdArg = Args.getLastArg(options::OPT__SLASH_std)) {
@@ -6493,6 +6494,9 @@
 }
 
 CmdArgs.push_back(LanguageStandard.data());
+
+IsCPP17Onwards =
+LanguageStandard != "-std=c++11" && LanguageStandard != "-std=c++14";
   }
 
   Args.addOptInFlag(CmdArgs, options::OPT_fborland_extensions,
@@ -6622,9 +6626,15 @@
 options::OPT_fno_relaxed_template_template_args);
 
   // -fsized-deallocation is off by default, as it is an ABI-breaking change for
-  // most platforms.
-  Args.addOptInFlag(CmdArgs, options::OPT_fsized_deallocation,
-options::OPT_fno_sized_deallocation);
+  // most platforms. MSVC turns on /Zc:sizedDealloc by default, starting in
+  // MSVC 2015.
+  if (IsWindowsMSVC && IsMSVC2015Compatible &&
+  !Args.getLastArg(options::OPT_fsized_deallocation,
+   options::OPT_fno_sized_deallocation))
+CmdArgs.push_back("-fsized-deallocation");
+  else
+Args.addOptInFlag(CmdArgs, options::OPT_fsized_deallocation,
+  options::OPT_fno_sized_deallocation);
 
   // -faligned-allocation is on by default in C++17 onwards and otherwise off
   // by default.
@@ -6635,6 +6645,8 @@
   CmdArgs.push_back("-fno-aligned-allocation");
 else
   CmdArgs.push_back("-faligned-allocation");
+  } else if (IsCPP17Onwards) {
+CmdArgs.push_back("-faligned-allocation");
   }
 
   // The default new alignment can be specified using a dedicated option or via
Index: clang-tools-extra/test/clang-tidy/checkers/misc-new-delete-overloads.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc-new-delete-overloads.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/m

[PATCH] D126745: [RISCV][Clang] Support policy functions for vmerge, vfmerge and vcompress.

2022-08-02 Thread Zakk Chen via Phabricator via cfe-commits
khchen added a comment.

@nlopes we will update all undef to poison in follow up patches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126745

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


[PATCH] D127803: Generate the capture for field when the field is used in openmp region with implicit default in the member function.

2022-08-02 Thread mgabka via Phabricator via cfe-commits
mgabka added a comment.

In D127803#3693700 , @jyu2 wrote:

> In D127803#3693660 , @ABataev wrote:
>
>> In D127803#3693655 , @jyu2 wrote:
>>
>>> In D127803#3693301 , @mgabka 
>>> wrote:
>>>
 I noticed that this patch is causing now an assertion failure for cases 
 like :

 class A{

   void a() {
 #pragma omp parallel
 a(b);
   }

 };

 The failed assertion is: "const clang::ValueDecl* getCanonicalDecl(const 
 clang::ValueDecl*): Assertion `FD' failed."

 while before it clang was correctly  reporting error:
 error: use of undeclared identifier 'b'

 is it the same assertion you were trying to fix here?
>>>
>>> No, the assert I am fixing is when default(firstprivate) is used inside 
>>> member function.
>>
>> Could you please investigate and fix it?
>
> Yes, I will fix this.

Thanks a lot, I raised an upstream bug for it 
https://github.com/llvm/llvm-project/issues/56884


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127803

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


[PATCH] D130918: [clang][ExtractAPI] Record availability information on all platforms

2022-08-02 Thread Zixu Wang via Phabricator via cfe-commits
zixuw accepted this revision.
zixuw 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/D130918/new/

https://reviews.llvm.org/D130918

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


[PATCH] D35379: Add documentation for @available

2022-08-02 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis marked an inline comment as done.
thakis added a comment.
This revision is now accepted and ready to land.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.

landed long ago in 11cafc82b72a80fb9a7266bbda7fc7a0cc1b51a0 / 
564004ae78c61a9292a15f8ed0500016b93ea74e


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

https://reviews.llvm.org/D35379

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


[PATCH] D130791: [clang] Short-circuit trivial constexpr array constructors

2022-08-02 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! I agree that test coverage for the performance issue is basically 
impossible with our testing system. I was thinking "well good, add a test with 
a huge initializer to make sure it doesn't crash" but then I realized that will 
slow down running the tests significantly and will always be susceptible to a 
slightly larger array than the test uses being a problem. So I think it's fine 
to land this without tests.


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

https://reviews.llvm.org/D130791

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


[PATCH] D120175: [Driver] Re-run lld with --reproduce when it crashes

2022-08-02 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:1638
+llvm::opt::ArgStringList ArgList = NewLLDInvocation.getArguments();
+ArgList.push_back(Saver.save(Twine{"--reproduce="} + TmpName).data());
+NewLLDInvocation.replaceArguments(std::move(ArgList));

This does the wrong thing on Windows, I think (the flag is spelled 
/reproduce:path there I think?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120175

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


[PATCH] D130894: [clang] Print more information about failed static assertions

2022-08-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Wow, I *really* like this improvement, thank you for working on it! This is 
going to be especially helpful for things like `static_assert(foo() == 12, "oh 
no, foo wasn't 12!");`. Can you also add a release note for this improvement?




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:1536
+def note_bin_op_evaluates : Note<
+  "%select{left-hand|right-hand}0 side of operator '%1' evaluates to '%2'">;
 

Should probably add at least one test that shows the "right-hand" version of 
the diagnostic.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16564-16571
+if (isa(Op->getRHS()->IgnoreParenImpCasts())) {
+  ExprIsRHS = false;
+  ExprSide = Op->getLHS();
+} else if (isa(Op->getLHS()->IgnoreParenImpCasts())) {
+  ExprIsRHS = true;
+  ExprSide = Op->getRHS();
+} else

I think we want a little bit more smarts here -- `-2` is not an 
`IntegerLiteral`, it's a unary expression whose subexpression is an integer 
literal. I think we need to handle unary expressions because it'd be weird for 
`foo() == 12` to get helpful information but `foo() == -12` not to.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16579-16580
+
+if (isa(ExprSide))
+  return;
+

Similar issue here for unary expressions; we probably don't want `1 == -12` to 
get past this check.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16587-16590
+if (EvalResult.Val.isInt())
+  EvalResult.Val.getInt().toString(ValueString);
+else
+  return;

This same logic seems correct for float, fixed point, and complex (though this 
one may need some extra work because of the real and imaginary parts). Any 
reason not to handle those as well?


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

https://reviews.llvm.org/D130894

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


[clang] 7eddeb9 - [RISCV][Clang] Support policy functions for vmerge, vfmerge and

2022-08-02 Thread Zakk Chen via cfe-commits

Author: Zakk Chen
Date: 2022-08-02T17:27:55Z
New Revision: 7eddeb9e99f36d907295a2ed75244d39e1e41e33

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

LOG: [RISCV][Clang] Support policy functions for vmerge, vfmerge and
vcompress.

We will switch all UndefValue to PoisonValue in follow up patches.

Reviewed By: kito-cheng

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

Added: 


Modified: 
clang/include/clang/Basic/riscv_vector.td
clang/include/clang/Support/RISCVVIntrinsicUtils.h
clang/lib/Support/RISCVVIntrinsicUtils.cpp
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vcompress.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfmerge.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmerge.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vcompress.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vfmerge.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vmerge.c

Removed: 




diff  --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index a36ff62231581..75d2f607b1cff 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -137,6 +137,8 @@ class PolicyScheme{
 def NonePolicy : PolicyScheme<0>;
 def HasPassthruOperand : PolicyScheme<1>;
 def HasPolicyOperand : PolicyScheme<2>;
+// Specail case for passthru operand which is not a first opeand.
+def HasPassthruOperandAtIdx1 : PolicyScheme<3>;
 
 class RVVBuiltin {
@@ -1819,13 +1821,16 @@ defm vwmaccus : RVVOutOp1Op2BuiltinSet<"vwmaccus", 
"csi",
 }
 
 // 12.15. Vector Integer Merge Instructions
-// C/C++ Operand: (mask, op1, op2, vl), Intrinsic: (op1, op2, mask, vl)
-let HasMasked = false, MaskedPolicyScheme = NonePolicy,
+// C/C++ Operand: (mask, op1, op2, vl), Intrinsic: (passthru, op1, op2, mask, 
vl)
+let HasMasked = false,
+UnMaskedPolicyScheme = HasPassthruOperandAtIdx1,
+MaskedPolicyScheme = NonePolicy,
 ManualCodegen = [{
-  std::rotate(Ops.begin(), Ops.begin() + 1, Ops.begin() + 3);
-  IntrinsicTypes = {ResultType, Ops[1]->getType(), Ops[3]->getType()};
+  std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
   // insert undef passthru
-  Ops.insert(Ops.begin(), llvm::UndefValue::get(ResultType));
+  if (DefaultPolicy == TAIL_AGNOSTIC)
+Ops.insert(Ops.begin(), llvm::UndefValue::get(ResultType));
+  IntrinsicTypes = {ResultType, Ops[2]->getType(), Ops.back()->getType()};
 }] in {
   defm vmerge : RVVOutOp1BuiltinSet<"vmerge", "csil",
 [["vvm", "v", "vmvv"],
@@ -1960,12 +1965,15 @@ let Name = "vfclass_v", UnMaskedPolicyScheme = 
HasPassthruOperand in
 
 // 14.15. Vector Floating-Point Merge Instructio
 // C/C++ Operand: (mask, op1, op2, vl), Builtin: (op1, op2, mask, vl)
-let HasMasked = false, MaskedPolicyScheme = NonePolicy,
+let HasMasked = false,
+UnMaskedPolicyScheme = HasPassthruOperandAtIdx1,
+MaskedPolicyScheme = NonePolicy,
 ManualCodegen = [{
-  std::rotate(Ops.begin(), Ops.begin() + 1, Ops.begin() + 3);
-  IntrinsicTypes = {ResultType, Ops[1]->getType(), Ops[3]->getType()};
+  std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
   // insert undef passthru
-  Ops.insert(Ops.begin(), llvm::UndefValue::get(ResultType));
+  if (DefaultPolicy == TAIL_AGNOSTIC)
+Ops.insert(Ops.begin(), llvm::UndefValue::get(ResultType));
+  IntrinsicTypes = {ResultType, Ops[2]->getType(), Ops.back()->getType()};
 }] in {
   defm vmerge : RVVOutOp1BuiltinSet<"vmerge", "xfd",
 [["vvm", "v", "vmvv"]]>;
@@ -2152,10 +2160,16 @@ defm vrgatherei16 : RVVOutBuiltinSet<"vrgatherei16_vv", 
"csil",
 }
 
 // 17.5. Vector Compress Instruction
-let HasMasked = false, MaskedPolicyScheme = NonePolicy,
+let IsPrototypeDefaultTU = true,
+HasMasked = false,
+UnMaskedPolicyScheme = HasPassthruOperandAtIdx1,
+MaskedPolicyScheme = NonePolicy,
 ManualCodegen = [{
-  std::rotate(Ops.begin(), Ops.begin() + 1, Ops.begin() + 3);
-  IntrinsicTypes = {ResultType, Ops[3]->getType()};
+  std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
+  // insert undef passthru
+  if (DefaultPolicy == TAIL_AGNOSTIC)
+Ops.insert(Ops.begin(), llvm::UndefValue::get(ResultType));
+  IntrinsicTypes = {ResultType, Ops.back()->getType()};
 }] in {
   // signed and floating type
   defm vcompress : RVVOutBuiltinSet<"vcompress", "csilxfd",

diff  --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h 
b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index 756d8d13d6986..4a8bbc78cdee3 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -290,8 +290,1

[clang] 9caf2cc - [RISCV][Clang] Support policy functions for Vector Comparison

2022-08-02 Thread Zakk Chen via cfe-commits

Author: Zakk Chen
Date: 2022-08-02T17:27:56Z
New Revision: 9caf2cc05c02300c06e2405ff3606d5aa8cf773d

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

LOG: [RISCV][Clang] Support policy functions for Vector Comparison
Instructions.

We will switch all UndefValue to PoisonValue in follow up patches.

Reviewed By: kito-cheng

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

Added: 


Modified: 
clang/include/clang/Basic/riscv_vector.td
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfeq.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfge.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfgt.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfle.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmflt.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfne.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmseq.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsge.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsgt.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsle.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmslt.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsne.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vmfeq.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vmfge.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vmfgt.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vmfle.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vmflt.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vmfne.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vmseq.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vmsge.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vmsgt.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vmsle.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vmslt.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vmsne.c

Removed: 




diff  --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index 75d2f607b1cf..4b0c48fb91d4 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -1745,7 +1745,8 @@ defm vncvt_x_x_w : RVVPseudoVNCVTBuiltin<"vnsrl", 
"vncvt_x", "csi",
   ["Uv", "UvUw"]]>;
 
 // 12.8. Vector Integer Comparison Instructions
-let MaskedPolicyScheme = NonePolicy in {
+let MaskedPolicyScheme = HasPassthruOperand,
+HasTailPolicy = false in {
 defm vmseq : RVVIntMaskOutBuiltinSet;
 defm vmsne : RVVIntMaskOutBuiltinSet;
 defm vmsltu : RVVUnsignedMaskOutBuiltinSet;
@@ -1950,7 +1951,8 @@ defm vfneg_v : RVVPseudoVFUnaryBuiltin<"vfsgnjn", "xfd">;
 defm vfabs_v : RVVPseudoVFUnaryBuiltin<"vfsgnjx", "xfd">;
 
 // 14.13. Vector Floating-Point Compare Instructions
-let MaskedPolicyScheme = NonePolicy in {
+let MaskedPolicyScheme = HasPassthruOperand,
+HasTailPolicy = false in {
 defm vmfeq : RVVFloatingMaskOutBuiltinSet;
 defm vmfne : RVVFloatingMaskOutBuiltinSet;
 defm vmflt : RVVFloatingMaskOutBuiltinSet;

diff  --git a/clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfeq.c 
b/clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfeq.c
index 1d1b50e60dd5..bc92ec407ea7 100644
--- a/clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfeq.c
+++ b/clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfeq.c
@@ -361,3 +361,39 @@ vbool8_t test_vmfeq_vf_f64m8_b8_m(vbool8_t mask, vbool8_t 
maskedoff,
   vfloat64m8_t op1, double op2, size_t vl) {
   return vmfeq(mask, maskedoff, op1, op2, vl);
 }
+
+// CHECK-RV64-LABEL: @test_vmfeq_vv_f32mf2_b64_ma(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.riscv.vmfeq.mask.nxv1f32.nxv1f32.i64( undef,  [[OP1:%.*]],  [[OP2:%.*]],  
[[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vbool64_t test_vmfeq_vv_f32mf2_b64_ma (vbool64_t mask, vfloat32mf2_t op1, 
vfloat32mf2_t op2, size_t vl) {
+  return vmfeq_ma(mask, op1, op2, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vmfeq_vf_f32mf2_b64_ma(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.riscv.vmfeq.mask.nxv1f32.f32.i64( undef,  [[OP1:%.*]], float [[OP2:%.*]],  [[MASK:%.*]], i64 
[[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vbool64_t test_vmfeq_vf_f32mf2_b64_ma (vbool64_t mask, vfloat32mf2_t op1, 
float op2, size_t vl) {
+  return vmfeq_ma(mask, op1, op2, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vmfeq_vv_f32mf2_b64_mu(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.riscv.vmfeq.mask.nxv1f32.nxv1f32.i64( [[MERGE:%.*]], 
 [[OP1:%.*]],  [[OP2:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vbool64_t test_vmfeq_vv_f32mf2_b64_mu (vbool64_t mask, vbool64_t merge, 
vfloat32mf2_t op1, vfloat32mf2_t op2, size_t vl

[clang] dffdca8 - [RISCV][Clang] Support policy functions for Vector Reduction

2022-08-02 Thread Zakk Chen via cfe-commits

Author: Zakk Chen
Date: 2022-08-02T17:27:56Z
New Revision: dffdca85ec2d17ce751adca1a851bc4458973e57

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

LOG: [RISCV][Clang] Support policy functions for Vector Reduction
Instructions.

We will switch all UndefValue to PoisonValue in follow up patches.

Thanks for Kito to help on verification with their interanl testsuite.

Reviewed By: kito-cheng

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

Added: 


Modified: 
clang/include/clang/Basic/riscv_vector.td
clang/lib/Support/RISCVVIntrinsicUtils.cpp
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfredmax.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfredmin.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfredsum.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfwredsum.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vredand.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vredmax.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vredmin.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vredor.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vredsum.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vredxor.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vwredsum.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vfredmax.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vfredmin.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vfredsum.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vfwredsum.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vredand.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vredmax.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vredmin.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vredor.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vredsum.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vredxor.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vwredsum.c
clang/utils/TableGen/RISCVVEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index 4b0c48fb91d4c..f724dee49aeaa 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -2027,7 +2027,8 @@ let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
 
 // 15. Vector Reduction Operations
 // 15.1. Vector Single-Width Integer Reduction Instructions
-let MaskedPolicyScheme = NonePolicy,
+let UnMaskedPolicyScheme = HasPassthruOperand,
+MaskedPolicyScheme = HasPassthruOperand,
 IsPrototypeDefaultTU = true,
 HasMaskPolicy = false in {
 defm vredsum : RVVIntReductionBuiltinSet;

diff  --git a/clang/lib/Support/RISCVVIntrinsicUtils.cpp 
b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
index bf81ac60dae3e..f57d21bd5c295 100644
--- a/clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -937,6 +937,7 @@ llvm::SmallVector 
RVVIntrinsic::computeBuiltinTypes(
   default:
 break;
   }
+  bool HasPassthruOp = DefaultScheme == PolicyScheme::HasPassthruOperand;
   if (IsMasked) {
 // If HasMaskedOffOperand, insert result type as first input operand if
 // need.
@@ -954,6 +955,10 @@ llvm::SmallVector 
RVVIntrinsic::computeBuiltinTypes(
   NewPrototype.insert(NewPrototype.begin() + NF + 1, MaskoffType);
   }
 }
+// Erase passthru operand for TAM
+if (NF == 1 && IsPrototypeDefaultTU && DefaultPolicy == Policy::TAMA &&
+HasPassthruOp && !HasMaskedOffOperand)
+  NewPrototype.erase(NewPrototype.begin() + 1);
 if (HasMaskedOffOperand && NF > 1) {
   // Convert
   // (void, op0 address, op1 address, ..., maskedoff0, maskedoff1, ...)
@@ -967,7 +972,6 @@ llvm::SmallVector 
RVVIntrinsic::computeBuiltinTypes(
   NewPrototype.insert(NewPrototype.begin() + 1, PrototypeDescriptor::Mask);
 }
   } else if (NF == 1) {
-bool HasPassthruOp = DefaultScheme == PolicyScheme::HasPassthruOperand;
 if (DefaultPolicy == Policy::TU && HasPassthruOp && !IsPrototypeDefaultTU)
   NewPrototype.insert(NewPrototype.begin(), NewPrototype[0]);
 else if (DefaultPolicy == Policy::TA && HasPassthruOp &&

diff  --git a/clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfredmax.c 
b/clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfredmax.c
index c61e6ade90eb8..f4a784a4efd93 100644
--- a/clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfredmax.c
+++ b/clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfredmax.c
@@ -194,3 +194,39 @@ vfloat64m1_t test_vfredmax_vs_f64m8_f64m1_m(vbool8_t mask, 
vfloat64m1_t dst,
 vfloat64m1_t scalar, size_t vl) {
   return vfredmax(mask, dst, vector, scalar, vl);
 }
+
+// CHECK-RV64-LABEL: @test_vfredmax_vs_f32mf2_f32m1_tu(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NE

[clang] bb99d4b - [RISCV][Clang] Support policy functions for Vector Mask Instructions.

2022-08-02 Thread Zakk Chen via cfe-commits

Author: Zakk Chen
Date: 2022-08-02T17:27:57Z
New Revision: bb99d4b11d84ae178d9ea3ea2c9da4d4c2e1eafc

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

LOG: [RISCV][Clang] Support policy functions for Vector Mask Instructions.

We will switch all UndefValue to PoisonValue in follow up patches.

Reviewed By: kito-cheng

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

Added: 


Modified: 
clang/include/clang/Basic/riscv_vector.td
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vid.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/viota.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsbf.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsif.c
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsof.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vid.c
clang/test/CodeGen/RISCV/rvv-intrinsics/viota.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vmsbf.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vmsif.c
clang/test/CodeGen/RISCV/rvv-intrinsics/vmsof.c

Removed: 




diff  --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index f724dee49aea..c20600e4f2a0 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -2082,7 +2082,10 @@ def vcpop : RVVMaskOp0Builtin<"um">;
 
 // 16.3. vfirst find-first-set mask bit
 def vfirst : RVVMaskOp0Builtin<"lm">;
+}
 
+let MaskedPolicyScheme = HasPassthruOperand,
+HasTailPolicy = false in {
 // 16.4. vmsbf.m set-before-first mask bit
 def vmsbf : RVVMaskUnaryBuiltin;
 

diff  --git a/clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vid.c 
b/clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vid.c
index ddf3bb2a12d2..7111f495513b 100644
--- a/clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vid.c
+++ b/clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vid.c
@@ -219,3 +219,39 @@ vuint64m8_t test_vid_v_u64m8_m(vbool8_t mask, vuint64m8_t 
maskedoff,
size_t vl) {
   return vid(mask, maskedoff, vl);
 }
+
+// CHECK-RV64-LABEL: @test_vid_v_u32mf2_tu(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.riscv.vid.nxv1i32.i64( [[MERGE:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vuint32mf2_t test_vid_v_u32mf2_tu(vuint32mf2_t merge, size_t vl) {
+  return vid_tu(merge, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vid_v_u32mf2_tuma(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.riscv.vid.mask.nxv1i32.i64( [[MERGE:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vuint32mf2_t test_vid_v_u32mf2_tuma(vbool64_t mask, vuint32mf2_t merge, size_t 
vl) {
+  return vid_tuma(mask, merge, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vid_v_u32mf2_tumu(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.riscv.vid.mask.nxv1i32.i64( [[MERGE:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vuint32mf2_t test_vid_v_u32mf2_tumu(vbool64_t mask, vuint32mf2_t merge, size_t 
vl) {
+  return vid_tumu(mask, merge, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vid_v_u32mf2_tamu(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.riscv.vid.mask.nxv1i32.i64( [[MERGE:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vuint32mf2_t test_vid_v_u32mf2_tamu(vbool64_t mask, vuint32mf2_t merge, size_t 
vl) {
+  return vid_tamu(mask, merge, vl);
+}

diff  --git a/clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/viota.c 
b/clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/viota.c
index ff2acb39fd91..7cc7b1fb0a2b 100644
--- a/clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/viota.c
+++ b/clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/viota.c
@@ -6,7 +6,7 @@
 
 // CHECK-RV64-LABEL: @test_viota_m_u8mf8_m(
 // CHECK-RV64-NEXT:  entry:
-// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.riscv.viota.mask.nxv1i8.i64( [[MASKEDOFF:%.*]],  [[OP1:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.riscv.viota.mask.nxv1i8.i64( [[MASKEDOFF:%.*]],  [[OP1:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
 // CHECK-RV64-NEXT:ret  [[TMP0]]
 //
 vuint8mf8_t test_viota_m_u8mf8_m(vbool64_t mask, vuint8mf8_t maskedoff,
@@ -16,7 +16,7 @@ vuint8mf8_t test_viota_m_u8mf8_m(vbool64_t mask, vuint8mf8_t 
maskedoff,
 
 // CHECK-RV64-LABEL: @test_viota_m_u8mf4_m(
 // CHECK-RV64-NEXT:  entry:
-// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.riscv.viota.mask.nxv2i8.i64( [[MASKEDOFF:%.*]],  [[OP1:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.riscv.viota.mask.nxv2i8.i64( [[MASKEDOFF:%.*]],  [[OP1:%.*]],  [[MASK:%.*]], i64 [[VL:%.

[PATCH] D126745: [RISCV][Clang] Support policy functions for vmerge, vfmerge and vcompress.

2022-08-02 Thread Zakk Chen 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 rG7eddeb9e99f3: [RISCV][Clang] Support policy functions for 
vmerge, vfmerge and (authored by khchen).

Changed prior to commit:
  https://reviews.llvm.org/D126745?vs=433263&id=449336#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126745

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/Support/RISCVVIntrinsicUtils.cpp
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vcompress.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfmerge.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmerge.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vcompress.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfmerge.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmerge.c

Index: clang/test/CodeGen/RISCV/rvv-intrinsics/vmerge.c
===
--- clang/test/CodeGen/RISCV/rvv-intrinsics/vmerge.c
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/vmerge.c
@@ -981,7 +981,7 @@
 // CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmerge.nxv1f16.nxv1f16.i64( undef,  [[OP1:%.*]],  [[OP2:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
 // CHECK-RV64-NEXT:ret  [[TMP0]]
 //
-vfloat16mf4_t test_vmerge_vvm_f16mf4 (vbool64_t mask, vfloat16mf4_t op1, vfloat16mf4_t op2, size_t vl) {
+vfloat16mf4_t test_vmerge_vvm_f16mf4(vbool64_t mask, vfloat16mf4_t op1, vfloat16mf4_t op2, size_t vl) {
   return vmerge_vvm_f16mf4(mask, op1, op2, vl);
 }
 
@@ -990,7 +990,7 @@
 // CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmerge.nxv2f16.nxv2f16.i64( undef,  [[OP1:%.*]],  [[OP2:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
 // CHECK-RV64-NEXT:ret  [[TMP0]]
 //
-vfloat16mf2_t test_vmerge_vvm_f16mf2 (vbool32_t mask, vfloat16mf2_t op1, vfloat16mf2_t op2, size_t vl) {
+vfloat16mf2_t test_vmerge_vvm_f16mf2(vbool32_t mask, vfloat16mf2_t op1, vfloat16mf2_t op2, size_t vl) {
   return vmerge_vvm_f16mf2(mask, op1, op2, vl);
 }
 
@@ -999,7 +999,7 @@
 // CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmerge.nxv4f16.nxv4f16.i64( undef,  [[OP1:%.*]],  [[OP2:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
 // CHECK-RV64-NEXT:ret  [[TMP0]]
 //
-vfloat16m1_t test_vmerge_vvm_f16m1 (vbool16_t mask, vfloat16m1_t op1, vfloat16m1_t op2, size_t vl) {
+vfloat16m1_t test_vmerge_vvm_f16m1(vbool16_t mask, vfloat16m1_t op1, vfloat16m1_t op2, size_t vl) {
   return vmerge_vvm_f16m1(mask, op1, op2, vl);
 }
 
@@ -1008,7 +1008,7 @@
 // CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmerge.nxv8f16.nxv8f16.i64( undef,  [[OP1:%.*]],  [[OP2:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
 // CHECK-RV64-NEXT:ret  [[TMP0]]
 //
-vfloat16m2_t test_vmerge_vvm_f16m2 (vbool8_t mask, vfloat16m2_t op1, vfloat16m2_t op2, size_t vl) {
+vfloat16m2_t test_vmerge_vvm_f16m2(vbool8_t mask, vfloat16m2_t op1, vfloat16m2_t op2, size_t vl) {
   return vmerge_vvm_f16m2(mask, op1, op2, vl);
 }
 
@@ -1017,7 +1017,7 @@
 // CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmerge.nxv16f16.nxv16f16.i64( undef,  [[OP1:%.*]],  [[OP2:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
 // CHECK-RV64-NEXT:ret  [[TMP0]]
 //
-vfloat16m4_t test_vmerge_vvm_f16m4 (vbool4_t mask, vfloat16m4_t op1, vfloat16m4_t op2, size_t vl) {
+vfloat16m4_t test_vmerge_vvm_f16m4(vbool4_t mask, vfloat16m4_t op1, vfloat16m4_t op2, size_t vl) {
   return vmerge_vvm_f16m4(mask, op1, op2, vl);
 }
 
@@ -1026,6 +1026,96 @@
 // CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmerge.nxv32f16.nxv32f16.i64( undef,  [[OP1:%.*]],  [[OP2:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
 // CHECK-RV64-NEXT:ret  [[TMP0]]
 //
-vfloat16m8_t test_vmerge_vvm_f16m8 (vbool2_t mask, vfloat16m8_t op1, vfloat16m8_t op2, size_t vl) {
+vfloat16m8_t test_vmerge_vvm_f16m8(vbool2_t mask, vfloat16m8_t op1, vfloat16m8_t op2, size_t vl) {
   return vmerge_vvm_f16m8(mask, op1, op2, vl);
 }
+
+// CHECK-RV64-LABEL: @test_vmerge_vvm_i32mf2_tu(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmerge.nxv1i32.nxv1i32.i64( [[MERGE:%.*]],  [[OP1:%.*]],  [[OP2:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vint32mf2_t test_vmerge_vvm_i32mf2_tu(vbool64_t mask, vint32mf2_t merge, vint32mf2_t op1, vint32mf2_t op2, size_t vl) {
+  return vmerge_vvm_i32mf2_tu(mask, merge, op1, op2, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vmerge_vxm_i32mf2_tu(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmerge.nxv1i32.i32.i64( [[MERGE:%.*]],  [[OP1:%.*]], i32 [[OP2:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vint32mf2_t test_vmerge_vxm_i32mf2_tu(vbool64_t mask, vint32mf2_t merge, vint32mf2_t op1, int32_t op2, size_t vl) {
+  return vmerge_vxm_i32mf2_tu(mask, merge, op1, op2, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vmerge

[PATCH] D126746: [RISCV][Clang] Support policy functions for Vector Comparison Instructions.

2022-08-02 Thread Zakk Chen 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 rG9caf2cc05c02: [RISCV][Clang] Support policy functions for 
Vector Comparison (authored by khchen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126746

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfeq.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfge.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfgt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfle.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmflt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfne.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmseq.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsge.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsgt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsle.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmslt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsne.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmfeq.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmfge.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmfgt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmfle.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmflt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmfne.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmseq.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmsge.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmsgt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmsle.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmslt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmsne.c

Index: clang/test/CodeGen/RISCV/rvv-intrinsics/vmsne.c
===
--- clang/test/CodeGen/RISCV/rvv-intrinsics/vmsne.c
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/vmsne.c
@@ -1699,3 +1699,75 @@
   vuint64m8_t op1, uint64_t op2, size_t vl) {
   return vmsne_vx_u64m8_b8_m(mask, maskedoff, op1, op2, vl);
 }
+
+// CHECK-RV64-LABEL: @test_vmsne_vv_i32mf2_b64_ma(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmsne.mask.nxv1i32.nxv1i32.i64( undef,  [[OP1:%.*]],  [[OP2:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vbool64_t test_vmsne_vv_i32mf2_b64_ma (vbool64_t mask, vint32mf2_t op1, vint32mf2_t op2, size_t vl) {
+  return vmsne_vv_i32mf2_b64_ma(mask, op1, op2, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vmsne_vx_i32mf2_b64_ma(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmsne.mask.nxv1i32.i32.i64( undef,  [[OP1:%.*]], i32 [[OP2:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vbool64_t test_vmsne_vx_i32mf2_b64_ma (vbool64_t mask, vint32mf2_t op1, int32_t op2, size_t vl) {
+  return vmsne_vx_i32mf2_b64_ma(mask, op1, op2, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vmsne_vv_u32mf2_b64_ma(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmsne.mask.nxv1i32.nxv1i32.i64( undef,  [[OP1:%.*]],  [[OP2:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vbool64_t test_vmsne_vv_u32mf2_b64_ma (vbool64_t mask, vuint32mf2_t op1, vuint32mf2_t op2, size_t vl) {
+  return vmsne_vv_u32mf2_b64_ma(mask, op1, op2, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vmsne_vx_u32mf2_b64_ma(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmsne.mask.nxv1i32.i32.i64( undef,  [[OP1:%.*]], i32 [[OP2:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vbool64_t test_vmsne_vx_u32mf2_b64_ma (vbool64_t mask, vuint32mf2_t op1, uint32_t op2, size_t vl) {
+  return vmsne_vx_u32mf2_b64_ma(mask, op1, op2, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vmsne_vv_i32mf2_b64_mu(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmsne.mask.nxv1i32.nxv1i32.i64( [[MERGE:%.*]],  [[OP1:%.*]],  [[OP2:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vbool64_t test_vmsne_vv_i32mf2_b64_mu (vbool64_t mask, vbool64_t merge, vint32mf2_t op1, vint32mf2_t op2, size_t vl) {
+  return vmsne_vv_i32mf2_b64_mu(mask, merge, op1, op2, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vmsne_vx_i32mf2_b64_mu(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmsne.mask.nxv1i32.i32.i64( [[MERGE:%.*]],  [[OP1:%.*]], i32 [[OP2:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vbool64_t test_vmsne_vx_i32mf2_b64_mu (vbool64_t mask, vbool64_t merge, vint32mf2_t op1, int32_t op2, size_t vl) {
+  return vmsne_vx_i32mf2_b64_mu(mask, merge, op1, op2, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vmsne_vv_u32mf2_b64_mu(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv

[PATCH] D126748: [RISCV][Clang] Support policy functions for Vector Reduction Instructions.

2022-08-02 Thread Zakk Chen 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 rGdffdca85ec2d: [RISCV][Clang] Support policy functions for 
Vector Reduction (authored by khchen).

Changed prior to commit:
  https://reviews.llvm.org/D126748?vs=433267&id=449338#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126748

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/lib/Support/RISCVVIntrinsicUtils.cpp
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfredmax.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfredmin.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfredsum.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfwredsum.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vredand.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vredmax.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vredmin.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vredor.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vredsum.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vredxor.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vwredsum.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfredmax.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfredmin.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfredsum.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfwredsum.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vredand.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vredmax.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vredmin.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vredor.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vredsum.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vredxor.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vwredsum.c
  clang/utils/TableGen/RISCVVEmitter.cpp

Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -194,6 +194,10 @@
   if (RVVI->hasMaskedOffOperand() &&
   RVVI->getDefaultPolicy() == Policy::TAMA)
 OS << "  Ops.insert(Ops.begin(), llvm::UndefValue::get(ResultType));\n";
+  // Masked reduction cases.
+  if (!RVVI->hasMaskedOffOperand() && RVVI->hasPassthruOperand() &&
+  RVVI->getDefaultPolicy() == Policy::TAMA)
+OS << "  Ops.insert(Ops.begin(), llvm::UndefValue::get(ResultType));\n";
 } else {
   OS << "  std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end());\n";
 }
@@ -201,7 +205,8 @@
 if (RVVI->hasPolicyOperand())
   OS << "  Ops.push_back(ConstantInt::get(Ops.back()->getType(), "
 "DefaultPolicy));\n";
-else if (RVVI->hasPassthruOperand() && RVVI->getDefaultPolicy() == Policy::TA)
+else if (RVVI->hasPassthruOperand() &&
+ RVVI->getDefaultPolicy() == Policy::TA)
   OS << "  Ops.insert(Ops.begin(), llvm::UndefValue::get(ResultType));\n";
   }
 
Index: clang/test/CodeGen/RISCV/rvv-intrinsics/vwredsum.c
===
--- clang/test/CodeGen/RISCV/rvv-intrinsics/vwredsum.c
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/vwredsum.c
@@ -759,3 +759,75 @@
 vuint64m1_t scalar, size_t vl) {
   return vwredsumu_vs_u32m8_u64m1_m(mask, dst, vector, scalar, vl);
 }
+
+// CHECK-RV64-LABEL: @test_vwredsum_vs_i32mf2_i64m1_tu(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vwredsum.nxv1i64.nxv1i32.i64( [[MERGE:%.*]],  [[VECTOR:%.*]],  [[SCALAR:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vint64m1_t test_vwredsum_vs_i32mf2_i64m1_tu(vint64m1_t merge, vint32mf2_t vector, vint64m1_t scalar, size_t vl) {
+  return vwredsum_vs_i32mf2_i64m1_tu(merge, vector, scalar, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vwredsumu_vs_u32mf2_u64m1_tu(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vwredsumu.nxv1i64.nxv1i32.i64( [[MERGE:%.*]],  [[VECTOR:%.*]],  [[SCALAR:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vuint64m1_t test_vwredsumu_vs_u32mf2_u64m1_tu(vuint64m1_t merge, vuint32mf2_t vector, vuint64m1_t scalar, size_t vl) {
+  return vwredsumu_vs_u32mf2_u64m1_tu(merge, vector, scalar, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vwredsum_vs_i32mf2_i64m1_ta(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vwredsum.nxv1i64.nxv1i32.i64( undef,  [[VECTOR:%.*]],  [[SCALAR:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vint64m1_t test_vwredsum_vs_i32mf2_i64m1_ta(vint32mf2_t vector, vint64m1_t scalar, size_t vl) {
+  return vwredsum_vs_i32mf2_i64m1_ta(vector, scalar, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vwredsumu_vs_u32mf2_u64m1_ta(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vwredsumu.nxv1i64.nxv

[PATCH] D126749: [RISCV][Clang] Support policy functions for Vector Mask Instructions.

2022-08-02 Thread Zakk Chen 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 rGbb99d4b11d84: [RISCV][Clang] Support policy functions for 
Vector Mask Instructions. (authored by khchen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126749

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vid.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/viota.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsbf.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsif.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsof.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vid.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/viota.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmsbf.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmsif.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmsof.c

Index: clang/test/CodeGen/RISCV/rvv-intrinsics/vmsof.c
===
--- clang/test/CodeGen/RISCV/rvv-intrinsics/vmsof.c
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/vmsof.c
@@ -136,3 +136,21 @@
  size_t vl) {
   return vmsof_m_b64_m(mask, maskedoff, op1, vl);
 }
+
+// CHECK-RV64-LABEL: @test_vmsof_m_b4_ma(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmsof.mask.nxv16i1.i64( undef,  [[OP1:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vbool4_t test_vmsof_m_b4_ma(vbool4_t mask, vbool4_t op1, size_t vl) {
+  return vmsof_m_b4_ma(mask, op1, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vmsof_m_b4_mu(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmsof.mask.nxv16i1.i64( [[MERGE:%.*]],  [[OP1:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vbool4_t test_vmsof_m_b4_mu(vbool4_t mask, vbool4_t merge, vbool4_t op1, size_t vl) {
+  return vmsof_m_b4_mu(mask, merge, op1, vl);
+}
Index: clang/test/CodeGen/RISCV/rvv-intrinsics/vmsif.c
===
--- clang/test/CodeGen/RISCV/rvv-intrinsics/vmsif.c
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/vmsif.c
@@ -136,3 +136,21 @@
  size_t vl) {
   return vmsif_m_b64_m(mask, maskedoff, op1, vl);
 }
+
+// CHECK-RV64-LABEL: @test_vmsif_m_b4_ma(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmsif.mask.nxv16i1.i64( undef,  [[OP1:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vbool4_t test_vmsif_m_b4_ma(vbool4_t mask, vbool4_t op1, size_t vl) {
+  return vmsif_m_b4_ma(mask, op1, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vmsif_m_b4_mu(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmsif.mask.nxv16i1.i64( [[MERGE:%.*]],  [[OP1:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vbool4_t test_vmsif_m_b4_mu(vbool4_t mask, vbool4_t merge, vbool4_t op1, size_t vl) {
+  return vmsif_m_b4_mu(mask, merge, op1, vl);
+}
Index: clang/test/CodeGen/RISCV/rvv-intrinsics/vmsbf.c
===
--- clang/test/CodeGen/RISCV/rvv-intrinsics/vmsbf.c
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/vmsbf.c
@@ -136,3 +136,21 @@
  size_t vl) {
   return vmsbf_m_b64_m(mask, maskedoff, op1, vl);
 }
+
+// CHECK-RV64-LABEL: @test_vmsbf_m_b4_ma(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmsbf.mask.nxv16i1.i64( undef,  [[OP1:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vbool4_t test_vmsbf_m_b4_ma(vbool4_t mask, vbool4_t op1, size_t vl) {
+  return vmsbf_m_b4_ma(mask, op1, vl);
+}
+
+// CHECK-RV64-LABEL: @test_vmsbf_m_b4_mu(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmsbf.mask.nxv16i1.i64( [[MERGE:%.*]],  [[OP1:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vbool4_t test_vmsbf_m_b4_mu(vbool4_t mask, vbool4_t merge, vbool4_t op1, size_t vl) {
+  return vmsbf_m_b4_mu(mask, merge, op1, vl);
+}
Index: clang/test/CodeGen/RISCV/rvv-intrinsics/viota.c
===
--- clang/test/CodeGen/RISCV/rvv-intrinsics/viota.c
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/viota.c
@@ -204,7 +204,7 @@
 
 // CHECK-RV64-LABEL: @test_viota_m_u8mf8_m(
 // CHECK-RV64-NEXT:  entry:
-// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.viota.mask.nxv1i8.i64( [[MASKEDOFF:%.*]],  [[OP1:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.viota.mask.nxv1i8.i64( [[MASKEDOFF:%.*]],  [[OP1:%.*]],  [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
 // CHECK-RV64-NEXT:ret  [[TMP0]]
 //
 vuint8mf8_t test_viota_m_u8mf8_m

[PATCH] D130936: [SemaCXX] Validate destructor is valid for dependent classes

2022-08-02 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 449344.
royjacobson edited the summary of this revision.
royjacobson added a comment.

Add newline and release notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130936

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/member-class-11.cpp


Index: clang/test/SemaCXX/member-class-11.cpp
===
--- clang/test/SemaCXX/member-class-11.cpp
+++ clang/test/SemaCXX/member-class-11.cpp
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
 struct rdar9677163 {
   struct Y { ~Y(); };
@@ -6,3 +8,22 @@
   Y::~Y() { } // expected-error{{non-friend class member '~Y' cannot have a 
qualified name}}
   ~Z(); // expected-error{{expected the class name after '~' to name the 
enclosing class}}
 };
+
+namespace GH56772 {
+
+template
+struct A {
+  ~A();
+};
+#if __cplusplus >= 202002L
+// FIXME: This isn't valid in C++20 and later.
+#endif
+
+struct B;
+
+template
+struct C {
+  ~B(); // expected-error {{expected the class name after '~' to name the 
enclosing class}}
+};
+
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -11496,17 +11496,12 @@
   CXXRecordDecl *Record = Destructor->getParent();
   QualType ClassType = Context.getTypeDeclType(Record);
 
-  // FIXME: Shouldn't we be able to perform this check even when the class
-  // type is dependent? Both gcc and edg can handle that.
-  if (!ClassType->isDependentType()) {
-DeclarationName Name
-  = Context.DeclarationNames.getCXXDestructorName(
-Context.getCanonicalType(ClassType));
-if (NewFD->getDeclName() != Name) {
-  Diag(NewFD->getLocation(), diag::err_destructor_name);
-  NewFD->setInvalidDecl();
-  return Redeclaration;
-}
+  DeclarationName Name = Context.DeclarationNames.getCXXDestructorName(
+  Context.getCanonicalType(ClassType));
+  if (NewFD->getDeclName() != Name) {
+Diag(NewFD->getLocation(), diag::err_destructor_name);
+NewFD->setInvalidDecl();
+return Redeclaration;
   }
 } else if (auto *Guide = dyn_cast(NewFD)) {
   if (auto *TD = Guide->getDescribedFunctionTemplate())
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -52,6 +52,8 @@
 - Fixes an accepts-invalid bug in C when using a ``_Noreturn`` function
   specifier on something other than a function declaration. This fixes
   `Issue 56800 `_.
+- Fix `#56772 `_ - invalid
+  destructor names were incorrectly accepted on template classes.
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/SemaCXX/member-class-11.cpp
===
--- clang/test/SemaCXX/member-class-11.cpp
+++ clang/test/SemaCXX/member-class-11.cpp
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
 struct rdar9677163 {
   struct Y { ~Y(); };
@@ -6,3 +8,22 @@
   Y::~Y() { } // expected-error{{non-friend class member '~Y' cannot have a qualified name}}
   ~Z(); // expected-error{{expected the class name after '~' to name the enclosing class}}
 };
+
+namespace GH56772 {
+
+template
+struct A {
+  ~A();
+};
+#if __cplusplus >= 202002L
+// FIXME: This isn't valid in C++20 and later.
+#endif
+
+struct B;
+
+template
+struct C {
+  ~B(); // expected-error {{expected the class name after '~' to name the enclosing class}}
+};
+
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -11496,17 +11496,12 @@
   CXXRecordDecl *Record = Destructor->getParent();
   QualType ClassType = Context.getTypeDeclType(Record);
 
-  // FIXME: Shouldn't we be able to perform this check even when the class
-  // type is dependent? Both gcc and edg can handle that.
-  if (!ClassType->isDependentType()) {
-DeclarationName Name
-  = Context.DeclarationNames.getCXXDestructorName(
-Context.getCanonicalType(ClassType));
-if (NewFD->getDeclName() != Name) {
-  Diag(NewFD->getLocation(), diag::err_destructor_name);
-  NewFD->setInvalidDecl();
-  return Redeclar

[PATCH] D130516: [llvm] compression classes

2022-08-02 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 449346.
ckissane added a comment.

- feat compression "enum" with methods


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130516

Files:
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/unittests/SerializationTests.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  lld/ELF/Driver.cpp
  lld/ELF/InputSection.cpp
  llvm/include/llvm/Object/Decompressor.h
  llvm/include/llvm/ProfileData/InstrProf.h
  llvm/include/llvm/Support/Compression.h
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/ObjCopy/ELF/ELFObject.cpp
  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/InstrProfCorrelator.cpp
  llvm/lib/ProfileData/SampleProfReader.cpp
  llvm/lib/ProfileData/SampleProfWriter.cpp
  llvm/lib/Support/Compression.cpp
  llvm/tools/llvm-mc/llvm-mc.cpp
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
  llvm/unittests/ProfileData/InstrProfTest.cpp
  llvm/unittests/Support/CompressionTest.cpp

Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -22,31 +22,41 @@
 
 namespace {
 
-#if LLVM_ENABLE_ZLIB
-static void testZlibCompression(StringRef Input, int Level) {
+static void testCompressionAlgorithm(
+StringRef Input, int Level, compression::CompressionKind CompressionScheme,
+std::string ExpectedDestinationBufferTooSmallErrorMessage) {
   SmallVector Compressed;
   SmallVector Uncompressed;
-  zlib::compress(arrayRefFromStringRef(Input), Compressed, Level);
+  CompressionScheme->compress(arrayRefFromStringRef(Input), Compressed, Level);
 
   // Check that uncompressed buffer is the same as original.
-  Error E = zlib::uncompress(Compressed, Uncompressed, Input.size());
+  Error E =
+  CompressionScheme->decompress(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 = zlib::uncompress(Compressed, Uncompressed, Input.size() - 1);
-EXPECT_EQ("zlib error: Z_BUF_ERROR", llvm::toString(std::move(E)));
+E = CompressionScheme->decompress(Compressed, Uncompressed,
+  Input.size() - 1);
+EXPECT_EQ(ExpectedDestinationBufferTooSmallErrorMessage,
+  llvm::toString(std::move(E)));
   }
 }
 
+#if LLVM_ENABLE_ZLIB
+static void testZlibCompression(StringRef Input, int Level) {
+  testCompressionAlgorithm(Input, Level, CompressionKind::Zlib,
+   "zlib error: Z_BUF_ERROR");
+}
+
 TEST(CompressionTest, Zlib) {
-  testZlibCompression("", zlib::DefaultCompression);
+  compression::CompressionKind CompressionScheme = CompressionKind::Zlib;
+  testZlibCompression("", CompressionScheme->getDefaultLevel());
 
-  testZlibCompression("hello, world!", zlib::NoCompression);
-  testZlibCompression("hello, world!", zlib::BestSizeCompression);
-  testZlibCompression("hello, world!", zlib::BestSpeedCompression);
-  testZlibCompression("hello, world!", zlib::DefaultCompression);
+  testZlibCompression("hello, world!", CompressionScheme->getBestSizeLevel());
+  testZlibCompression("hello, world!", CompressionScheme->getBestSpeedLevel());
+  testZlibCompression("hello, world!", CompressionScheme->getDefaultLevel());
 
   const size_t kSize = 1024;
   char BinaryData[kSize];
@@ -54,38 +64,26 @@
 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, CompressionScheme->getBestSizeLevel());
+  testZlibCompression(BinaryDataStr, CompressionScheme->getBestSpeedLevel());
+  testZlibCompression(BinaryDataStr, CompressionScheme->getDefaultLevel());
 }
 #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 buffe

[PATCH] D130516: [llvm] compression classes

2022-08-02 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D130516#3688236 , @dblaikie wrote:

> In D130516#3688123 , @MaskRay wrote:
>
>> I'd like to make a few arguments for the current namespace+free function 
>> design, as opposed to the class+member function design as explored in this 
>> patch (but thanks for the exploration!).
>> Let's discuss several use cases.
>>
>> (a) if a use case just calls compress/uncompress. The class design has 
>> slightly more boilerplate as it needs to get the algorithm class, a new 
>> instance, or a singleton instance.
>> For each new use, the number of lines may not differ, but the involvement of 
>> a a static class member or an instance make the reader wonder whether the 
>> object will be reused or thrown away.
>> There is some slight cognitive burden.
>> The class design has a non-trivial one-shot cost to have a function 
>> returning the singleton instance.
>
> Though there must've been a condition that dominates this use somewhere - I'd 
> suggest that condition could be where the algorithm is retrieved, and then 
> passed to this code to use unconditionally.
>
> If the algorithm object is const and raw pointers/references are used, I 
> think it makes it clear to the reader that there's no ownership here, and 
> it's not stateful when compressing/decompressing.

Singleton compression classes are isomorphic to an `enum CompressionType` 
variable.
Using an enum variable doesn't lose any usage pattern we can do with a pointer 
to a singleton compression class.

Say, we do

  auto *algo = !compression::ZlibCompression;
  if (!algo)
...
  
  
  algo->compress(...);

either together or apart, the result is similar to the following but with (IMO) 
slightly larger cognitive burden:

  if (!compression::isAvailable(format))
...
  
  compression::compress(format);



>> (b) zlib compress/uncompress immediately following an availability check.
>>
>>   // free function
>>   if (!compression::zlib::isAvailable())
>> errs() << "cannot compress: " << 
>> compression::zlib::buildConfigurationHint();
>>   
>>   // class
>>   auto *algo = !compression::ZlibCompression;
>>   if (!algo->isAvailable()) {
>> errs() << "cannot compress: " << algo->buildConfigurationHint();
>>   }
>
> I think maybe this code might end up looking like:
>
>   Algo *algo = getAlgo(Zlib)
>   if (!algo)
> errs() ...
>
> It's possible that this function would return non-null even for a 
> non-available algorithm if we wanted to communicate other things (like the 
> cmake macro name to enable to add the functionality)

I think this is similarly achieved with an enum variable.
With the class based approach, a pointer has a static type of the ancestor 
compression class and a dynamic type of any possible algorithm.
This is not different from that: the enum variable may have a value the enum 
class supports.

>> (c) zlib/zstd compress/uncompress immediately following an availability 
>> check.
>>
>>   // free function
>>   if (!compression::isAvailable(format))
>> errs() << "cannot compress: " << 
>> compression::buildConfigurationHint(format);
>>   
>>   // class
>>   std::unique_ptr algo = make_compression(format);
>>   if (!algo->isAvailable()) {
>> errs() << "cannot compress: " << algo->buildConfigurationHint();
>>   }
>
> I don't think there's a need for unique_ptr here - algorithms can be constant 
> singletons, referenced via raw const pointers/references without ownership.
>
> & this example doesn't include the code that does the 
> compression/decompression,  which seems part of the discussion & part I find 
> nice in that the type of compression used matches the type used in the check 
> necessarily rather than being passed into two APIs independently.

Thanks for clarification. Then this fits my "singleton compression classes are 
isomorphic to an `enum CompressionType` variable" argument :)

>> (d) compress/uncompress and an availability check are apart.
>>
>>   // free function
>>   no change
>>   
>>   // class
>>   Store (the pointer to the) the algorithm object somewhere, or construct 
>> the pointer/object twice.
>
> The benefit here is that it's harder for the test to become separated from 
> the usage - for the usage to end up becoming unconditional/incorrectly 
> guarded.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130516

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


[PATCH] D130516: [llvm] compression classes

2022-08-02 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 449355.
ckissane added a comment.

- make a zlib corruption check specific


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130516

Files:
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/unittests/SerializationTests.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  lld/ELF/Driver.cpp
  lld/ELF/InputSection.cpp
  llvm/include/llvm/Object/Decompressor.h
  llvm/include/llvm/ProfileData/InstrProf.h
  llvm/include/llvm/Support/Compression.h
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/ObjCopy/ELF/ELFObject.cpp
  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/InstrProfCorrelator.cpp
  llvm/lib/ProfileData/SampleProfReader.cpp
  llvm/lib/ProfileData/SampleProfWriter.cpp
  llvm/lib/Support/Compression.cpp
  llvm/tools/llvm-mc/llvm-mc.cpp
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
  llvm/unittests/ProfileData/InstrProfTest.cpp
  llvm/unittests/Support/CompressionTest.cpp

Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -22,31 +22,41 @@
 
 namespace {
 
-#if LLVM_ENABLE_ZLIB
-static void testZlibCompression(StringRef Input, int Level) {
+static void testCompressionAlgorithm(
+StringRef Input, int Level, compression::CompressionKind CompressionScheme,
+std::string ExpectedDestinationBufferTooSmallErrorMessage) {
   SmallVector Compressed;
   SmallVector Uncompressed;
-  zlib::compress(arrayRefFromStringRef(Input), Compressed, Level);
+  CompressionScheme->compress(arrayRefFromStringRef(Input), Compressed, Level);
 
   // Check that uncompressed buffer is the same as original.
-  Error E = zlib::uncompress(Compressed, Uncompressed, Input.size());
+  Error E =
+  CompressionScheme->decompress(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 = zlib::uncompress(Compressed, Uncompressed, Input.size() - 1);
-EXPECT_EQ("zlib error: Z_BUF_ERROR", llvm::toString(std::move(E)));
+E = CompressionScheme->decompress(Compressed, Uncompressed,
+  Input.size() - 1);
+EXPECT_EQ(ExpectedDestinationBufferTooSmallErrorMessage,
+  llvm::toString(std::move(E)));
   }
 }
 
+#if LLVM_ENABLE_ZLIB
+static void testZlibCompression(StringRef Input, int Level) {
+  testCompressionAlgorithm(Input, Level, CompressionKind::Zlib,
+   "zlib error: Z_BUF_ERROR");
+}
+
 TEST(CompressionTest, Zlib) {
-  testZlibCompression("", zlib::DefaultCompression);
+  compression::CompressionKind CompressionScheme = CompressionKind::Zlib;
+  testZlibCompression("", CompressionScheme->getDefaultLevel());
 
-  testZlibCompression("hello, world!", zlib::NoCompression);
-  testZlibCompression("hello, world!", zlib::BestSizeCompression);
-  testZlibCompression("hello, world!", zlib::BestSpeedCompression);
-  testZlibCompression("hello, world!", zlib::DefaultCompression);
+  testZlibCompression("hello, world!", CompressionScheme->getBestSizeLevel());
+  testZlibCompression("hello, world!", CompressionScheme->getBestSpeedLevel());
+  testZlibCompression("hello, world!", CompressionScheme->getDefaultLevel());
 
   const size_t kSize = 1024;
   char BinaryData[kSize];
@@ -54,38 +64,26 @@
 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, CompressionScheme->getBestSizeLevel());
+  testZlibCompression(BinaryDataStr, CompressionScheme->getBestSpeedLevel());
+  testZlibCompression(BinaryDataStr, CompressionScheme->getDefaultLevel());
 }
 #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 buff

[PATCH] D130811: [Clang] Fix handling of Max from getValueRange(...) in IntExprEvaluator::VisitCastExpr(...)

2022-08-02 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:13540
 ED->getValueRange(Max, Min);
+--Max;
 

erichkeane wrote:
> I don't think this is the correct answer.  Even though the other use of this 
> seems to 'work', `getValueRange` is still returning wrapped values here.  The 
> fix is to figure out how to fix the math in getValueRange, and change the 
> sanitizer's IR generation if necessary.
So the other user of these values is `getRangeForLoadFromType(...)` through 
`getRangeForType(...)` which is used to generate the [range 
metadata](https://llvm.org/docs/LangRef.html#range-metadata) and in this case 
the range is exclusive on the right side:

> The pair a,b represents the range [a,b).

and it is allowed to wrap:

> The range is allowed to wrap.

So I believe the behavior will be correct. 

Even though the range looks off in this example: https://godbolt.org/z/z7d9PKoMn

```
!{i32 0, i32 -2147483648}
```

I think it does the right thing.

Note the language ref also says:

> The type must match the type loaded by the instruction.

and a quick experiment to use `i33` confirms this breaks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130811

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


[PATCH] D131004: [clang] Add FileEntryRef::getNameAsRequested()

2022-08-02 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir created this revision.
benlangmuir added a reviewer: bnbarham.
Herald added a project: All.
benlangmuir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As progress towards having FileManager::getFileRef() return the path 
as-requested by default, return a FileEntryRef that can use 
getNameAsRequested() to retrieve this path, with the ultimate goal that this 
should be the behaviour of getName() and clients should explicitly request the 
"external" name if they need to (see comment in FileManager::getFileRef). For 
now, getName() continues to return the external path by looking through the 
redirects.

For now, the new function is only used in unit tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131004

Files:
  clang/include/clang/Basic/FileEntry.h
  clang/lib/Basic/FileManager.cpp
  clang/unittests/Basic/FileEntryTest.cpp
  clang/unittests/Basic/FileManagerTest.cpp

Index: clang/unittests/Basic/FileManagerTest.cpp
===
--- clang/unittests/Basic/FileManagerTest.cpp
+++ clang/unittests/Basic/FileManagerTest.cpp
@@ -356,9 +356,13 @@
   EXPECT_EQ("dir/f1.cpp", F1Redirect->getName());
   EXPECT_EQ("dir/f2.cpp", F2->getName());
 
+  EXPECT_EQ("dir/f1.cpp", F1->getNameAsRequested());
+  EXPECT_EQ("dir/f1-redirect.cpp", F1Redirect->getNameAsRequested());
+
   // Compare against FileEntry*.
   EXPECT_EQ(&F1->getFileEntry(), *F1);
   EXPECT_EQ(*F1, &F1->getFileEntry());
+  EXPECT_EQ(&F1->getFileEntry(), &F1Redirect->getFileEntry());
   EXPECT_NE(&F2->getFileEntry(), *F1);
   EXPECT_NE(*F1, &F2->getFileEntry());
 
@@ -374,7 +378,7 @@
 
   // Compare using isSameRef.
   EXPECT_TRUE(F1->isSameRef(*F1Again));
-  EXPECT_TRUE(F1->isSameRef(*F1Redirect));
+  EXPECT_FALSE(F1->isSameRef(*F1Redirect));
   EXPECT_FALSE(F1->isSameRef(*F1Also));
   EXPECT_FALSE(F1->isSameRef(*F2));
 }
Index: clang/unittests/Basic/FileEntryTest.cpp
===
--- clang/unittests/Basic/FileEntryTest.cpp
+++ clang/unittests/Basic/FileEntryTest.cpp
@@ -50,6 +50,14 @@
 const_cast(Base.getFileEntry()), DR)})
  .first);
   }
+  FileEntryRef addFileRedirect(StringRef Name, FileEntryRef Base) {
+return FileEntryRef(
+*Files
+ .insert({Name, FileEntryRef::MapValue(
+const_cast(
+Base.getMapEntry()))})
+ .first);
+  }
 };
 
 namespace {
@@ -58,13 +66,23 @@
   FileEntryRef R1 = Refs.addFile("1");
   FileEntryRef R2 = Refs.addFile("2");
   FileEntryRef R1Also = Refs.addFileAlias("1-also", R1);
+  FileEntryRef R1Redirect = Refs.addFileRedirect("1-redirect", R1);
+  FileEntryRef R1Redirect2 = Refs.addFileRedirect("1-redirect2", R1Redirect);
 
   EXPECT_EQ("1", R1.getName());
   EXPECT_EQ("2", R2.getName());
   EXPECT_EQ("1-also", R1Also.getName());
+  EXPECT_EQ("1", R1Redirect.getName());
+  EXPECT_EQ("1", R1Redirect2.getName());
+
+  EXPECT_EQ("1", R1.getNameAsRequested());
+  EXPECT_EQ("1-redirect", R1Redirect.getNameAsRequested());
+  EXPECT_EQ("1-redirect2", R1Redirect2.getNameAsRequested());
 
   EXPECT_NE(&R1.getFileEntry(), &R2.getFileEntry());
   EXPECT_EQ(&R1.getFileEntry(), &R1Also.getFileEntry());
+  EXPECT_EQ(&R1.getFileEntry(), &R1Redirect.getFileEntry());
+  EXPECT_EQ(&R1Redirect.getFileEntry(), &R1Redirect2.getFileEntry());
 
   const FileEntry *CE1 = R1;
   EXPECT_EQ(CE1, &R1.getFileEntry());
@@ -93,6 +111,8 @@
   FileEntryRef R1 = Refs.addFile("1");
   FileEntryRef R2 = Refs.addFile("2");
   FileEntryRef R1Also = Refs.addFileAlias("1-also", R1);
+  FileEntryRef R1Redirect = Refs.addFileRedirect("1-redirect", R1);
+  FileEntryRef R1Redirect2 = Refs.addFileRedirect("1-redirect2", R1Redirect);
 
   EXPECT_EQ(R1, &R1.getFileEntry());
   EXPECT_EQ(&R1.getFileEntry(), R1);
@@ -100,6 +120,8 @@
   EXPECT_NE(R1, &R2.getFileEntry());
   EXPECT_NE(&R2.getFileEntry(), R1);
   EXPECT_NE(R1, R2);
+  EXPECT_EQ(R1, R1Redirect);
+  EXPECT_EQ(R1, R1Redirect2);
 
   OptionalFileEntryRefDegradesToFileEntryPtr M1 = R1;
 
@@ -114,11 +136,16 @@
   FileEntryRef R1 = Refs.addFile("1");
   FileEntryRef R2 = Refs.addFile("2");
   FileEntryRef R1Also = Refs.addFileAlias("1-also", R1);
+  FileEntryRef R1Redirect = Refs.addFileRedirect("1-redirect", R1);
+  FileEntryRef R1Redirect2 = Refs.addFileRedirect("1-redirect2", R1Redirect);
 
   EXPECT_TRUE(R1.isSameRef(FileEntryRef(R1)));
   EXPECT_TRUE(R1.isSameRef(FileEntryRef(R1.getMapEntry(;
   EXPECT_FALSE(R1.isSameRef(R2));
   EXPECT_FALSE(R1.isSameRef(R1Also));
+  EXPECT_FALSE(R1.isSameRef(R1Redirect));
+  EXPECT_FALSE(R1.isSameRef(R1Redirect2));
+  EXPECT_FALSE(R1Redirect.isSameRef(R1Redirect2));
 }
 
 TEST(FileEntryTest, DenseMapInfo) {
Index: clang/lib/Basic/FileManager.cpp
===
--- clang/lib/Basic/F

[PATCH] D130811: [Clang] Fix handling of Max from getValueRange(...) in IntExprEvaluator::VisitCastExpr(...)

2022-08-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:13540
 ED->getValueRange(Max, Min);
+--Max;
 

shafik wrote:
> erichkeane wrote:
> > I don't think this is the correct answer.  Even though the other use of 
> > this seems to 'work', `getValueRange` is still returning wrapped values 
> > here.  The fix is to figure out how to fix the math in getValueRange, and 
> > change the sanitizer's IR generation if necessary.
> So the other user of these values is `getRangeForLoadFromType(...)` through 
> `getRangeForType(...)` which is used to generate the [range 
> metadata](https://llvm.org/docs/LangRef.html#range-metadata) and in this case 
> the range is exclusive on the right side:
> 
> > The pair a,b represents the range [a,b).
> 
> and it is allowed to wrap:
> 
> > The range is allowed to wrap.
> 
> So I believe the behavior will be correct. 
> 
> Even though the range looks off in this example: 
> https://godbolt.org/z/z7d9PKoMn
> 
> ```
> !{i32 0, i32 -2147483648}
> ```
> 
> I think it does the right thing.
> 
> Note the language ref also says:
> 
> > The type must match the type loaded by the instruction.
> 
> and a quick experiment to use `i33` confirms this breaks.
Hmm... ok.  Well, its quite unfortunate that 2 of our 3 uses of this are having 
to hack around this behavior a bit, but I guess this will have to be acceptable 
short-term then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130811

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


[PATCH] D130516: [llvm] compression classes

2022-08-02 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 449365.
ckissane added a comment.

- trim down compression api: remove supported()


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130516

Files:
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/unittests/SerializationTests.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  lld/ELF/Driver.cpp
  lld/ELF/InputSection.cpp
  llvm/include/llvm/Object/Decompressor.h
  llvm/include/llvm/ProfileData/InstrProf.h
  llvm/include/llvm/Support/Compression.h
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/ObjCopy/ELF/ELFObject.cpp
  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/InstrProfCorrelator.cpp
  llvm/lib/ProfileData/SampleProfReader.cpp
  llvm/lib/ProfileData/SampleProfWriter.cpp
  llvm/lib/Support/Compression.cpp
  llvm/tools/llvm-mc/llvm-mc.cpp
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
  llvm/unittests/ProfileData/InstrProfTest.cpp
  llvm/unittests/Support/CompressionTest.cpp

Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -22,31 +22,41 @@
 
 namespace {
 
-#if LLVM_ENABLE_ZLIB
-static void testZlibCompression(StringRef Input, int Level) {
+static void testCompressionAlgorithm(
+StringRef Input, int Level, compression::CompressionKind CompressionScheme,
+std::string ExpectedDestinationBufferTooSmallErrorMessage) {
   SmallVector Compressed;
   SmallVector Uncompressed;
-  zlib::compress(arrayRefFromStringRef(Input), Compressed, Level);
+  CompressionScheme->compress(arrayRefFromStringRef(Input), Compressed, Level);
 
   // Check that uncompressed buffer is the same as original.
-  Error E = zlib::uncompress(Compressed, Uncompressed, Input.size());
+  Error E =
+  CompressionScheme->decompress(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 = zlib::uncompress(Compressed, Uncompressed, Input.size() - 1);
-EXPECT_EQ("zlib error: Z_BUF_ERROR", llvm::toString(std::move(E)));
+E = CompressionScheme->decompress(Compressed, Uncompressed,
+  Input.size() - 1);
+EXPECT_EQ(ExpectedDestinationBufferTooSmallErrorMessage,
+  llvm::toString(std::move(E)));
   }
 }
 
+#if LLVM_ENABLE_ZLIB
+static void testZlibCompression(StringRef Input, int Level) {
+  testCompressionAlgorithm(Input, Level, CompressionKind::Zlib,
+   "zlib error: Z_BUF_ERROR");
+}
+
 TEST(CompressionTest, Zlib) {
-  testZlibCompression("", zlib::DefaultCompression);
+  compression::CompressionKind CompressionScheme = CompressionKind::Zlib;
+  testZlibCompression("", CompressionScheme->getDefaultLevel());
 
-  testZlibCompression("hello, world!", zlib::NoCompression);
-  testZlibCompression("hello, world!", zlib::BestSizeCompression);
-  testZlibCompression("hello, world!", zlib::BestSpeedCompression);
-  testZlibCompression("hello, world!", zlib::DefaultCompression);
+  testZlibCompression("hello, world!", CompressionScheme->getBestSizeLevel());
+  testZlibCompression("hello, world!", CompressionScheme->getBestSpeedLevel());
+  testZlibCompression("hello, world!", CompressionScheme->getDefaultLevel());
 
   const size_t kSize = 1024;
   char BinaryData[kSize];
@@ -54,38 +64,26 @@
 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, CompressionScheme->getBestSizeLevel());
+  testZlibCompression(BinaryDataStr, CompressionScheme->getBestSpeedLevel());
+  testZlibCompression(BinaryDataStr, CompressionScheme->getDefaultLevel());
 }
 #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("Destinat

[PATCH] D131006: [analyzer] Use DisequalityMap while inferring constraints

2022-08-02 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov created this revision.
ASDenysPetrov added reviewers: martong, steakhal, NoQ.
ASDenysPetrov added a project: clang.
Herald added subscribers: manas, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: All.
ASDenysPetrov requested review of this revision.
Herald added a subscriber: cfe-commits.

Infer range using associated unequal symbols from DisequalityMap.
Example:

  if(x == 42)
if(x != y)
  y; // [-2147483648, 41]U[43, 2147483647]

NOTE: Currently, this revision causes test failure due to assertion in related 
to `IteratorModeling.cpp` in `relateSymbols` on line
`assert(isa(CompSym) && "Symbol comparison must be a 
`SymIntExpr`");`. It needs to be fixed in some way before loading. The revision 
is exposed to show the motivation for D130372 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131006

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/range-inferring-from-disequality-map.cpp

Index: clang/test/Analysis/range-inferring-from-disequality-map.cpp
===
--- /dev/null
+++ clang/test/Analysis/range-inferring-from-disequality-map.cpp
@@ -0,0 +1,57 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection -verify %s
+
+template
+void clang_analyzer_value(T x);
+
+void test1(int x, int tmp) {
+  if(tmp != 0)
+if(x != tmp)
+ clang_analyzer_value(x); // expected-warning {{32s:{ [0, 0] }}}
+  // TODO:  TODO: Keep x range correct even if associated disequalities are
+  // already dead.
+  (void)tmp; // Keep alive.
+}
+
+void test2(int x, int tmp) {
+  if(x != tmp)
+if(tmp < 0)
+  clang_analyzer_value(x); // expected-warning {{32s:{ [0, 2147483647] }}}
+  // TODO:  TODO: Keep x range correct even if associated disequalities are
+  // already dead.
+  (void)tmp; // Keep alive.
+}
+
+void test3(int x, int tmp) {
+  if(x != tmp)
+if(tmp > 42 && tmp < 87)
+  clang_analyzer_value(x); // expected-warning {{32s:{ [-2147483648, 42], [87, 2147483647] }}}
+  // TODO:  TODO: Keep x range correct even if associated disequalities are
+  // already dead.
+  (void)tmp; // Keep alive.
+}
+
+void test4(int x, int tmp1, int tmp2) {
+  if(x != tmp1) {
+if (tmp1 < 0 && tmp2 > 0) {
+  clang_analyzer_value(x); // expected-warning {{32s:{ [0, 2147483647] }}}
+  if(x != tmp2)
+clang_analyzer_value(x); // expected-warning {{32s:{ [0, 0] }}}
+}
+  }
+  // TODO:  TODO: Keep x range correct even if associated disequalities are
+  // already dead.
+  (void)tmp1; // Keep alive.
+  (void)tmp2; // Keep alive.
+}
+
+void test5(int x, int tmp1, int tmp2) {
+  if (tmp1 < 42 && tmp2 >= 42) 
+if(x != tmp1 && x != tmp2)
+  // TODO: This condition should be infeasible.
+  //   Thus, the branch should be unreachable.
+  clang_analyzer_value(x); // expected-warning {{{ empty }}}
+  // TODO:  TODO: Keep x range correct even if associated disequalities are
+  // already dead.
+  (void)tmp1; // Keep alive.
+  (void)tmp2; // Keep alive.
+}
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1327,6 +1327,8 @@
  // Of course, we should take the constraint directly
  // associated with this symbol into consideration.
  getConstraint(State, Sym),
+ // Use inverted ranges from DisequalityMap.
+ getInvertedRangeFromDisequalityMap(State, Sym),
  // Apart from the Sym itself, we can infer quite a lot if
  // we look into subexpressions of Sym.
  Visit(Sym));
@@ -1490,6 +1492,39 @@
 return RangeFactory.deletePoint(Domain, IntType.getZeroValue());
   }
 
+  Optional getInvertedRangeFromDisequalityMap(ProgramStateRef State,
+SymbolRef Sym) {
+QualType T = Sym->getType();
+// We only support integral types.
+if (!T->isIntegralOrEnumerationType())
+  return llvm::None;
+
+EquivalenceClass EC = EquivalenceClass::find(State, Sym);
+const ClassSet *CS = State->get(EC);
+
+if (!CS)
+  return llvm::None;
+
+bool IsFirst = true;
+RangeSet RS = RangeFactory.getEmptySet();
+for (EquivalenceClass EC : *CS) {
+  if (const RangeSet *RSPtr = getConstraint(State, EC)) {
+if (IsFirst) {
+  IsFirst = false;
+  RS = *RSPtr;
+} else
+  RS = RangeFactory.unite(RS, *RSPtr);
+  }
+}
+
+if (IsFirst)
+  return llvm::None;
+
+RS = RangeFactory.castTo(RS, T);
+RS = RangeFactory.invert(RS);
+return RS;
+  }
+
   template 
  

[PATCH] D131007: [NFCI] Refactor how KeywordStatus is calculated

2022-08-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: aaron.ballman, tahonermann, shafik, Codesbyusman.
Herald added a project: All.
erichkeane requested review of this revision.

The getKeywordStatus function is a horrible mess of inter-dependent 'if'
 statements that depend significantly on the ORDER of the checks.  This
 patch removes the dependency on order by checking each set-flag only
 once.

It does this by looping through each of the set bits, and checks each
 individual flag for its effect, then combines them at the end.

This might slow down startup performance slightly, as there are only a
few hundred keywords, and a vast majority will only get checked 1x
still.

This patch ALSO removes the KEYWORD_CONCEPTS flag, because it has since
become synonymous with C++20.


https://reviews.llvm.org/D131007

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Basic/IdentifierTable.cpp
  clang/test/Lexer/keywords_test.cpp

Index: clang/test/Lexer/keywords_test.cpp
===
--- clang/test/Lexer/keywords_test.cpp
+++ clang/test/Lexer/keywords_test.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -std=c++03 -fsyntax-only %s
 // RUN: %clang_cc1 -std=c++11 -DCXX11 -fsyntax-only %s
-// RUN: %clang_cc1 -std=c++2a -DCXX11 -DCXX2A -fsyntax-only %s
+// RUN: %clang_cc1 -std=c++20 -DCXX11 -DCXX20 -fsyntax-only %s
 // RUN: %clang_cc1 -std=c++03 -fdeclspec -DDECLSPEC -fsyntax-only %s
 // RUN: %clang_cc1 -std=c++03 -fms-extensions -DDECLSPEC -fsyntax-only %s
 // RUN: %clang_cc1 -std=c++03 -fborland-extensions -DDECLSPEC -fsyntax-only %s
@@ -19,10 +19,10 @@
 #define NOT_KEYWORD(NAME) _Static_assert(__is_identifier(NAME), #NAME)
 #define IS_TYPE(NAME) void is_##NAME##_type() { int f(NAME); }
 
-#if defined(CXX2A)
-#define CONCEPTS_KEYWORD(NAME)  IS_KEYWORD(NAME)
+#if defined(CXX20)
+#define CXX20_KEYWORD(NAME)  IS_KEYWORD(NAME)
 #else
-#define CONCEPTS_KEYWORD(NAME)  NOT_KEYWORD(NAME)
+#define CXX20_KEYWORD(NAME)  NOT_KEYWORD(NAME)
 #endif
 
 #ifdef DECLSPEC
@@ -59,8 +59,8 @@
 CXX11_KEYWORD(thread_local);
 
 // Concepts keywords
-CONCEPTS_KEYWORD(concept);
-CONCEPTS_KEYWORD(requires);
+CXX20_KEYWORD(concept);
+CXX20_KEYWORD(requires);
 
 // __declspec extension
 DECLSPEC_KEYWORD(__declspec);
Index: clang/lib/Basic/IdentifierTable.cpp
===
--- clang/lib/Basic/IdentifierTable.cpp
+++ clang/lib/Basic/IdentifierTable.cpp
@@ -82,7 +82,7 @@
 // Constants for TokenKinds.def
 namespace {
 
-  enum {
+  enum TokenKey {
 KEYC99= 0x1,
 KEYCXX= 0x2,
 KEYCXX11  = 0x4,
@@ -99,70 +99,146 @@
 WCHARSUPPORT  = 0x2000,
 HALFSUPPORT   = 0x4000,
 CHAR8SUPPORT  = 0x8000,
-KEYCONCEPTS   = 0x1,
-KEYOBJC   = 0x2,
-KEYZVECTOR= 0x4,
-KEYCOROUTINES = 0x8,
-KEYMODULES= 0x10,
-KEYCXX20  = 0x20,
-KEYOPENCLCXX  = 0x40,
-KEYMSCOMPAT   = 0x80,
-KEYSYCL   = 0x100,
-KEYCUDA   = 0x200,
+KEYOBJC   = 0x1,
+KEYZVECTOR= 0x2,
+KEYCOROUTINES = 0x4,
+KEYMODULES= 0x8,
+KEYCXX20  = 0x10,
+KEYOPENCLCXX  = 0x20,
+KEYMSCOMPAT   = 0x40,
+KEYSYCL   = 0x80,
+KEYCUDA   = 0x100,
 KEYMAX= KEYCUDA, // The maximum key
 KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX20,
 KEYALL = (KEYMAX | (KEYMAX-1)) & ~KEYNOMS18 &
  ~KEYNOOPENCL // KEYNOMS18 and KEYNOOPENCL are used to exclude.
   };
 
-  /// How a keyword is treated in the selected standard.
+  /// How a keyword is treated in the selected standard. This enum is ordered
+  /// intentionally so that the value that 'wins' is the most 'permissive'.
   enum KeywordStatus {
+KS_Unknown, // Not yet calculated. Used when figuring out the status.
 KS_Disabled,// Disabled
+KS_Future,  // Is a keyword in future standard
 KS_Extension,   // Is an extension
 KS_Enabled, // Enabled
-KS_Future   // Is a keyword in future standard
   };
 
 } // namespace
 
+// This works on a single TokenKey flag and checks the LangOpts to get the
+// KeywordStatus based exclusively on this flag, so that it can be merged in
+// getKeywordStatus. Most should be enabled/disabled, but some might imply
+// 'future' versions, or extensions. Returns 'unknown' unless this is KNOWN to
+// be disabled, and the calling function makes it 'disabled' if no other flag
+// changes it. This is necessary for the KEYNOCXX and KEYNOOPENCL flags.
+static KeywordStatus getKeywordStatusHelper(const LangOptions &LangOpts,
+TokenKey Flag) {
+  // Flag is a single bit version of TokenKey (that is, not
+  // KEYALL/KEYALLCXX/etc), so we can check with == throughout this function.
+
+  assert ((Flag &-Flag) == Flag && "Multiple bits set?");
+  switch (Flag) {
+  case KEYC99:
+// FIXME: This should have K

[clang] 92c1bc6 - [CodeGen][inlineasm] assume the flag output of inline asm is boolean value

2022-08-02 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-08-02T11:49:01-07:00
New Revision: 92c1bc61586c9d6c7bf0c36b1005fe00b4f48cc0

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

LOG: [CodeGen][inlineasm] assume the flag output of inline asm is boolean value

GCC inline asm document says that
"... the general rule is that the output variable must be a scalar
integer, and the value is boolean."

Commit e5c37958f901cc9bec50624dbee85d40143e4bca lowers flag output of
inline asm on X86 with setcc, hence it is guaranteed that the flag
is of boolean value. Clang does not support ARM inline asm flag output
yet so nothing need to be worried about ARM.

See "Flag Output" section at
https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#OutputOperands

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

Reviewed By: nikic

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

Added: 


Modified: 
clang/lib/CodeGen/CGStmt.cpp
clang/test/CodeGen/inline-asm-x86-flag-output.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 05ab16668743b..481438de0e53a 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -2343,6 +2343,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
   std::vector ArgElemTypes;
   std::vector Args;
   llvm::BitVector ResultTypeRequiresCast;
+  llvm::BitVector ResultRegIsFlagReg;
 
   // Keep track of inout constraints.
   std::string InOutConstraints;
@@ -2400,6 +2401,9 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
   ResultRegQualTys.push_back(QTy);
   ResultRegDests.push_back(Dest);
 
+  bool IsFlagReg = llvm::StringRef(OutputConstraint).startswith("{@cc");
+  ResultRegIsFlagReg.push_back(IsFlagReg);
+
   llvm::Type *Ty = ConvertTypeForMem(QTy);
   const bool RequiresCast = Info.allowsRegister() &&
   (getTargetHooks().isScalarizableAsmOperand(*this, Ty) ||
@@ -2717,10 +2721,21 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
   // ResultRegDests can be also populated by addReturnRegisterOutputs() above,
   // in which case its size may grow.
   assert(ResultTypeRequiresCast.size() <= ResultRegDests.size());
+  assert(ResultRegIsFlagReg.size() <= ResultRegDests.size());
   for (unsigned i = 0, e = RegResults.size(); i != e; ++i) {
 llvm::Value *Tmp = RegResults[i];
 llvm::Type *TruncTy = ResultTruncRegTypes[i];
 
+if ((i < ResultRegIsFlagReg.size()) && ResultRegIsFlagReg[i]) {
+  // Target must guarantee the Value `Tmp` here is lowered to a boolean
+  // value.
+  llvm::Constant *Two = llvm::ConstantInt::get(Tmp->getType(), 2);
+  llvm::Value *IsBooleanValue =
+  Builder.CreateCmp(llvm::CmpInst::ICMP_ULT, Tmp, Two);
+  llvm::Function *FnAssume = CGM.getIntrinsic(llvm::Intrinsic::assume);
+  Builder.CreateCall(FnAssume, IsBooleanValue);
+}
+
 // If the result type of the LLVM IR asm doesn't match the result type of
 // the expression, do the conversion.
 if (ResultRegTypes[i] != ResultTruncRegTypes[i]) {

diff  --git a/clang/test/CodeGen/inline-asm-x86-flag-output.c 
b/clang/test/CodeGen/inline-asm-x86-flag-output.c
index 4c7e750e6d939..732714388c195 100644
--- a/clang/test/CodeGen/inline-asm-x86-flag-output.c
+++ b/clang/test/CodeGen/inline-asm-x86-flag-output.c
@@ -374,3 +374,22 @@ _Bool check_no_clobber_conflicts(void) {
   : "cx");
   return b;
 }
+
+int test_assume_boolean_flag(long nr, volatile long *addr) {
+  //CHECK-LABEL: @test_assume_boolean_flag
+  //CHECK: %0 = tail call { i32, i32 } asm "cmp $2,$1", 
"={@cca},={@ccae},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(i64* 
elementtype(i64) %addr, i64 %nr)
+  //CHECK: [[RES1:%.*]] = extractvalue { i32, i32 } %0, 0
+  //CHECK: [[RES2:%.*]] = extractvalue { i32, i32 } %0, 1
+  //CHECK: %1 = icmp ult i32 [[RES1]], 2
+  //CHECK: tail call void @llvm.assume(i1 %1)
+  //CHECK: %2 = icmp ult i32 [[RES2]], 2
+  //CHECK: tail call void @llvm.assume(i1 %2)
+  int x,y;
+  asm("cmp %2,%1"
+  : "=@cca"(x), "=@ccae"(y), "=m"(*(volatile long *)(addr))
+  : "r"(nr)
+  : "cc");
+  if (x)
+return 0;
+  return 1;
+}



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


[PATCH] D129954: [CodeGen][inlineasm] assume the flag output of inline asm is boolean value

2022-08-02 Thread Yuanfang Chen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
ychen marked an inline comment as done.
Closed by commit rG92c1bc61586c: [CodeGen][inlineasm] assume the flag output of 
inline asm is boolean value (authored by ychen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129954

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/inline-asm-x86-flag-output.c


Index: clang/test/CodeGen/inline-asm-x86-flag-output.c
===
--- clang/test/CodeGen/inline-asm-x86-flag-output.c
+++ clang/test/CodeGen/inline-asm-x86-flag-output.c
@@ -374,3 +374,22 @@
   : "cx");
   return b;
 }
+
+int test_assume_boolean_flag(long nr, volatile long *addr) {
+  //CHECK-LABEL: @test_assume_boolean_flag
+  //CHECK: %0 = tail call { i32, i32 } asm "cmp $2,$1", 
"={@cca},={@ccae},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(i64* 
elementtype(i64) %addr, i64 %nr)
+  //CHECK: [[RES1:%.*]] = extractvalue { i32, i32 } %0, 0
+  //CHECK: [[RES2:%.*]] = extractvalue { i32, i32 } %0, 1
+  //CHECK: %1 = icmp ult i32 [[RES1]], 2
+  //CHECK: tail call void @llvm.assume(i1 %1)
+  //CHECK: %2 = icmp ult i32 [[RES2]], 2
+  //CHECK: tail call void @llvm.assume(i1 %2)
+  int x,y;
+  asm("cmp %2,%1"
+  : "=@cca"(x), "=@ccae"(y), "=m"(*(volatile long *)(addr))
+  : "r"(nr)
+  : "cc");
+  if (x)
+return 0;
+  return 1;
+}
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -2343,6 +2343,7 @@
   std::vector ArgElemTypes;
   std::vector Args;
   llvm::BitVector ResultTypeRequiresCast;
+  llvm::BitVector ResultRegIsFlagReg;
 
   // Keep track of inout constraints.
   std::string InOutConstraints;
@@ -2400,6 +2401,9 @@
   ResultRegQualTys.push_back(QTy);
   ResultRegDests.push_back(Dest);
 
+  bool IsFlagReg = llvm::StringRef(OutputConstraint).startswith("{@cc");
+  ResultRegIsFlagReg.push_back(IsFlagReg);
+
   llvm::Type *Ty = ConvertTypeForMem(QTy);
   const bool RequiresCast = Info.allowsRegister() &&
   (getTargetHooks().isScalarizableAsmOperand(*this, Ty) ||
@@ -2717,10 +2721,21 @@
   // ResultRegDests can be also populated by addReturnRegisterOutputs() above,
   // in which case its size may grow.
   assert(ResultTypeRequiresCast.size() <= ResultRegDests.size());
+  assert(ResultRegIsFlagReg.size() <= ResultRegDests.size());
   for (unsigned i = 0, e = RegResults.size(); i != e; ++i) {
 llvm::Value *Tmp = RegResults[i];
 llvm::Type *TruncTy = ResultTruncRegTypes[i];
 
+if ((i < ResultRegIsFlagReg.size()) && ResultRegIsFlagReg[i]) {
+  // Target must guarantee the Value `Tmp` here is lowered to a boolean
+  // value.
+  llvm::Constant *Two = llvm::ConstantInt::get(Tmp->getType(), 2);
+  llvm::Value *IsBooleanValue =
+  Builder.CreateCmp(llvm::CmpInst::ICMP_ULT, Tmp, Two);
+  llvm::Function *FnAssume = CGM.getIntrinsic(llvm::Intrinsic::assume);
+  Builder.CreateCall(FnAssume, IsBooleanValue);
+}
+
 // If the result type of the LLVM IR asm doesn't match the result type of
 // the expression, do the conversion.
 if (ResultRegTypes[i] != ResultTruncRegTypes[i]) {


Index: clang/test/CodeGen/inline-asm-x86-flag-output.c
===
--- clang/test/CodeGen/inline-asm-x86-flag-output.c
+++ clang/test/CodeGen/inline-asm-x86-flag-output.c
@@ -374,3 +374,22 @@
   : "cx");
   return b;
 }
+
+int test_assume_boolean_flag(long nr, volatile long *addr) {
+  //CHECK-LABEL: @test_assume_boolean_flag
+  //CHECK: %0 = tail call { i32, i32 } asm "cmp $2,$1", "={@cca},={@ccae},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(i64* elementtype(i64) %addr, i64 %nr)
+  //CHECK: [[RES1:%.*]] = extractvalue { i32, i32 } %0, 0
+  //CHECK: [[RES2:%.*]] = extractvalue { i32, i32 } %0, 1
+  //CHECK: %1 = icmp ult i32 [[RES1]], 2
+  //CHECK: tail call void @llvm.assume(i1 %1)
+  //CHECK: %2 = icmp ult i32 [[RES2]], 2
+  //CHECK: tail call void @llvm.assume(i1 %2)
+  int x,y;
+  asm("cmp %2,%1"
+  : "=@cca"(x), "=@ccae"(y), "=m"(*(volatile long *)(addr))
+  : "r"(nr)
+  : "cc");
+  if (x)
+return 0;
+  return 1;
+}
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -2343,6 +2343,7 @@
   std::vector ArgElemTypes;
   std::vector Args;
   llvm::BitVector ResultTypeRequiresCast;
+  llvm::BitVector ResultRegIsFlagReg;
 
   // Keep track of inout constraints.
   std::string InOutConstraints;
@@ -2400,6 +2401,9 @@
   ResultRegQualTys.push_back(QTy);
   ResultRegDests.push_back(Dest);
 
+  bool IsFlagReg = llvm::StringRef(OutputConstraint).startswith("{@cc");
+  ResultRegIsFlagReg.push_back(IsFla

[clang] 508c431 - [SemaCXX] Validate destructor is valid for dependent classes

2022-08-02 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-08-02T21:50:54+03:00
New Revision: 508c431ed9ab6d2074f1c68e3ee6b245ece57d5a

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

LOG: [SemaCXX] Validate destructor is valid for dependent classes

We didn't check that a destructor's name matches the directly enclosing class 
if the class was dependent.
I enabled the check we already had for non-dependent types, which seems to 
work. Added appropriate tests.

Fixes GitHub issue #56772

Reviewed By: erichkeane

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/member-class-11.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 782659346e52e..9dc08639dafb4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -52,6 +52,8 @@ Bug Fixes
 - Fixes an accepts-invalid bug in C when using a ``_Noreturn`` function
   specifier on something other than a function declaration. This fixes
   `Issue 56800 `_.
+- Fix `#56772 `_ - invalid
+  destructor names were incorrectly accepted on template classes.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0557120949a9b..eca20002b30da 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11496,17 +11496,12 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
   CXXRecordDecl *Record = Destructor->getParent();
   QualType ClassType = Context.getTypeDeclType(Record);
 
-  // FIXME: Shouldn't we be able to perform this check even when the class
-  // type is dependent? Both gcc and edg can handle that.
-  if (!ClassType->isDependentType()) {
-DeclarationName Name
-  = Context.DeclarationNames.getCXXDestructorName(
-Context.getCanonicalType(ClassType));
-if (NewFD->getDeclName() != Name) {
-  Diag(NewFD->getLocation(), diag::err_destructor_name);
-  NewFD->setInvalidDecl();
-  return Redeclaration;
-}
+  DeclarationName Name = Context.DeclarationNames.getCXXDestructorName(
+  Context.getCanonicalType(ClassType));
+  if (NewFD->getDeclName() != Name) {
+Diag(NewFD->getLocation(), diag::err_destructor_name);
+NewFD->setInvalidDecl();
+return Redeclaration;
   }
 } else if (auto *Guide = dyn_cast(NewFD)) {
   if (auto *TD = Guide->getDescribedFunctionTemplate())

diff  --git a/clang/test/SemaCXX/member-class-11.cpp 
b/clang/test/SemaCXX/member-class-11.cpp
index c230c5305e7a8..68873ebad9d1d 100644
--- a/clang/test/SemaCXX/member-class-11.cpp
+++ b/clang/test/SemaCXX/member-class-11.cpp
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
 struct rdar9677163 {
   struct Y { ~Y(); };
@@ -6,3 +8,22 @@ struct rdar9677163 {
   Y::~Y() { } // expected-error{{non-friend class member '~Y' cannot have a 
qualified name}}
   ~Z(); // expected-error{{expected the class name after '~' to name the 
enclosing class}}
 };
+
+namespace GH56772 {
+
+template
+struct A {
+  ~A();
+};
+#if __cplusplus >= 202002L
+// FIXME: This isn't valid in C++20 and later.
+#endif
+
+struct B;
+
+template
+struct C {
+  ~B(); // expected-error {{expected the class name after '~' to name the 
enclosing class}}
+};
+
+}



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


[PATCH] D130936: [SemaCXX] Validate destructor is valid for dependent classes

2022-08-02 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG508c431ed9ab: [SemaCXX] Validate destructor is valid for 
dependent classes (authored by royjacobson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130936

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/member-class-11.cpp


Index: clang/test/SemaCXX/member-class-11.cpp
===
--- clang/test/SemaCXX/member-class-11.cpp
+++ clang/test/SemaCXX/member-class-11.cpp
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
 struct rdar9677163 {
   struct Y { ~Y(); };
@@ -6,3 +8,22 @@
   Y::~Y() { } // expected-error{{non-friend class member '~Y' cannot have a 
qualified name}}
   ~Z(); // expected-error{{expected the class name after '~' to name the 
enclosing class}}
 };
+
+namespace GH56772 {
+
+template
+struct A {
+  ~A();
+};
+#if __cplusplus >= 202002L
+// FIXME: This isn't valid in C++20 and later.
+#endif
+
+struct B;
+
+template
+struct C {
+  ~B(); // expected-error {{expected the class name after '~' to name the 
enclosing class}}
+};
+
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -11496,17 +11496,12 @@
   CXXRecordDecl *Record = Destructor->getParent();
   QualType ClassType = Context.getTypeDeclType(Record);
 
-  // FIXME: Shouldn't we be able to perform this check even when the class
-  // type is dependent? Both gcc and edg can handle that.
-  if (!ClassType->isDependentType()) {
-DeclarationName Name
-  = Context.DeclarationNames.getCXXDestructorName(
-Context.getCanonicalType(ClassType));
-if (NewFD->getDeclName() != Name) {
-  Diag(NewFD->getLocation(), diag::err_destructor_name);
-  NewFD->setInvalidDecl();
-  return Redeclaration;
-}
+  DeclarationName Name = Context.DeclarationNames.getCXXDestructorName(
+  Context.getCanonicalType(ClassType));
+  if (NewFD->getDeclName() != Name) {
+Diag(NewFD->getLocation(), diag::err_destructor_name);
+NewFD->setInvalidDecl();
+return Redeclaration;
   }
 } else if (auto *Guide = dyn_cast(NewFD)) {
   if (auto *TD = Guide->getDescribedFunctionTemplate())
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -52,6 +52,8 @@
 - Fixes an accepts-invalid bug in C when using a ``_Noreturn`` function
   specifier on something other than a function declaration. This fixes
   `Issue 56800 `_.
+- Fix `#56772 `_ - invalid
+  destructor names were incorrectly accepted on template classes.
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/SemaCXX/member-class-11.cpp
===
--- clang/test/SemaCXX/member-class-11.cpp
+++ clang/test/SemaCXX/member-class-11.cpp
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
 struct rdar9677163 {
   struct Y { ~Y(); };
@@ -6,3 +8,22 @@
   Y::~Y() { } // expected-error{{non-friend class member '~Y' cannot have a qualified name}}
   ~Z(); // expected-error{{expected the class name after '~' to name the enclosing class}}
 };
+
+namespace GH56772 {
+
+template
+struct A {
+  ~A();
+};
+#if __cplusplus >= 202002L
+// FIXME: This isn't valid in C++20 and later.
+#endif
+
+struct B;
+
+template
+struct C {
+  ~B(); // expected-error {{expected the class name after '~' to name the enclosing class}}
+};
+
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -11496,17 +11496,12 @@
   CXXRecordDecl *Record = Destructor->getParent();
   QualType ClassType = Context.getTypeDeclType(Record);
 
-  // FIXME: Shouldn't we be able to perform this check even when the class
-  // type is dependent? Both gcc and edg can handle that.
-  if (!ClassType->isDependentType()) {
-DeclarationName Name
-  = Context.DeclarationNames.getCXXDestructorName(
-Context.getCanonicalType(ClassType));
-if (NewFD->getDeclName() != Name) {
-  Diag(NewFD->getLocation(), diag::err_destructor_name);
-  NewFD->setInvali

[PATCH] D130372: [analyzer] Add a new factory function RangeSet::Factory::invert

2022-08-02 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@martong

> Now I'm working on the next patch and you'll see a motivation soon.

Here is the motivation but it still causes some tests failure D131006 
.


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

https://reviews.llvm.org/D130372

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


[PATCH] D130516: [llvm] compression classes

2022-08-02 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D130516#3694151 , @MaskRay wrote:

> In D130516#3688236 , @dblaikie 
> wrote:
>
>> In D130516#3688123 , @MaskRay 
>> wrote:
>>
>>> I'd like to make a few arguments for the current namespace+free function 
>>> design, as opposed to the class+member function design as explored in this 
>>> patch (but thanks for the exploration!).
>>> Let's discuss several use cases.
>>>
>>> (a) if a use case just calls compress/uncompress. The class design has 
>>> slightly more boilerplate as it needs to get the algorithm class, a new 
>>> instance, or a singleton instance.
>>> For each new use, the number of lines may not differ, but the involvement 
>>> of a a static class member or an instance make the reader wonder whether 
>>> the object will be reused or thrown away.
>>> There is some slight cognitive burden.
>>> The class design has a non-trivial one-shot cost to have a function 
>>> returning the singleton instance.
>>
>> Though there must've been a condition that dominates this use somewhere - 
>> I'd suggest that condition could be where the algorithm is retrieved, and 
>> then passed to this code to use unconditionally.
>>
>> If the algorithm object is const and raw pointers/references are used, I 
>> think it makes it clear to the reader that there's no ownership here, and 
>> it's not stateful when compressing/decompressing.
>
> A pointer to a singleton compression class is isomorphic to an `enum class 
> CompressionType` variable.

I don't mean to suggest that either design is fundamentally more or less 
functional - I'm totally OK with/agree that both design directions allow the 
implementation of all the desired final/end-user-visible functionality.

I'm trying to make a point about which, I think, achieves that goal in a 
"better" way - that's the space of design discussions, I think - what kinds of 
(developer, maintenance, etc) costs different designs incur.

> Using an enum variable doesn't lose any usage pattern we can do with a 
> pointer to a singleton compression class.

I agree that either design doesn't change what's possible - I do, though, think 
that the "usage patterns" are meaningfully different between the two designs.

> An enum variable allows more patterns, as the allowed values are enumerable 
> (we don't need to worry about -Wswitch for the uses).
>
> Say, we do
>
>   auto *algo = !compression::ZlibCompression;
>   if (!algo)
> ...
>   
>   
>   algo->compress(...);
>
> either together or apart, the result is similar to the following but with 
> (IMO) slightly larger cognitive burden:
>
>   if (!compression::isAvailable(format))
> ...
>   
>   compression::compress(format);

Specifically two APIs that are related (it's important/necessary to check for 
availability before calling compress or decompress) in their contracts but 
unrelated in their API use makes it easier to misuse the APIs and have a 
situation where the availability check doesn't cover the usage. That's what I 
think is important/important to discuss here.

>>> (b) zlib compress/uncompress immediately following an availability check.
>>>
>>>   // free function
>>>   if (!compression::zlib::isAvailable())
>>> errs() << "cannot compress: " << 
>>> compression::zlib::buildConfigurationHint();
>>>   
>>>   // class
>>>   auto *algo = !compression::ZlibCompression;
>>>   if (!algo->isAvailable()) {
>>> errs() << "cannot compress: " << algo->buildConfigurationHint();
>>>   }
>>
>> I think maybe this code might end up looking like:
>>
>>   Algo *algo = getAlgo(Zlib)
>>   if (!algo)
>> errs() ...
>>
>> It's possible that this function would return non-null even for a 
>> non-available algorithm if we wanted to communicate other things (like the 
>> cmake macro name to enable to add the functionality)
>
> I think this is similarly achieved with an enum variable.
> With the class based approach, a pointer has a static type of the ancestor 
> compression class and a dynamic type of any possible algorithm.
> This is not different from that: the enum variable may have a value the enum 
> class supports.

I agree that the code is similar in either case, but with a small difference 
that is important to me - that accessing the algorithm necessarily (to some 
degree - you could still have code that doesn't test the condition/dereferences 
null, the same way that code can dereference an empty Optional without checking 
first - but at least the API I'm suggesting makes clear there's a connection 
between availability and usage).

>>> (c) zlib/zstd compress/uncompress immediately following an availability 
>>> check.
>>>
>>>   // free function
>>>   if (!compression::isAvailable(format))
>>> errs() << "cannot compress: " << 
>>> compression::buildConfigurationHint(format);
>>>   
>>>   // class
>>>   std::unique_ptr algo = make_compression(format);
>>>   if (!algo

[PATCH] D130516: [llvm] compression classes

2022-08-02 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 449375.
ckissane added a comment.

- CompressionKind: clean up param names to == op


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130516

Files:
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/unittests/SerializationTests.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  lld/ELF/Driver.cpp
  lld/ELF/InputSection.cpp
  llvm/include/llvm/Object/Decompressor.h
  llvm/include/llvm/ProfileData/InstrProf.h
  llvm/include/llvm/Support/Compression.h
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/ObjCopy/ELF/ELFObject.cpp
  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/InstrProfCorrelator.cpp
  llvm/lib/ProfileData/SampleProfReader.cpp
  llvm/lib/ProfileData/SampleProfWriter.cpp
  llvm/lib/Support/Compression.cpp
  llvm/tools/llvm-mc/llvm-mc.cpp
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
  llvm/unittests/ProfileData/InstrProfTest.cpp
  llvm/unittests/Support/CompressionTest.cpp

Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -22,31 +22,41 @@
 
 namespace {
 
-#if LLVM_ENABLE_ZLIB
-static void testZlibCompression(StringRef Input, int Level) {
+static void testCompressionAlgorithm(
+StringRef Input, int Level, compression::CompressionKind CompressionScheme,
+std::string ExpectedDestinationBufferTooSmallErrorMessage) {
   SmallVector Compressed;
   SmallVector Uncompressed;
-  zlib::compress(arrayRefFromStringRef(Input), Compressed, Level);
+  CompressionScheme->compress(arrayRefFromStringRef(Input), Compressed, Level);
 
   // Check that uncompressed buffer is the same as original.
-  Error E = zlib::uncompress(Compressed, Uncompressed, Input.size());
+  Error E =
+  CompressionScheme->decompress(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 = zlib::uncompress(Compressed, Uncompressed, Input.size() - 1);
-EXPECT_EQ("zlib error: Z_BUF_ERROR", llvm::toString(std::move(E)));
+E = CompressionScheme->decompress(Compressed, Uncompressed,
+  Input.size() - 1);
+EXPECT_EQ(ExpectedDestinationBufferTooSmallErrorMessage,
+  llvm::toString(std::move(E)));
   }
 }
 
+#if LLVM_ENABLE_ZLIB
+static void testZlibCompression(StringRef Input, int Level) {
+  testCompressionAlgorithm(Input, Level, CompressionKind::Zlib,
+   "zlib error: Z_BUF_ERROR");
+}
+
 TEST(CompressionTest, Zlib) {
-  testZlibCompression("", zlib::DefaultCompression);
+  compression::CompressionKind CompressionScheme = CompressionKind::Zlib;
+  testZlibCompression("", CompressionScheme->getDefaultLevel());
 
-  testZlibCompression("hello, world!", zlib::NoCompression);
-  testZlibCompression("hello, world!", zlib::BestSizeCompression);
-  testZlibCompression("hello, world!", zlib::BestSpeedCompression);
-  testZlibCompression("hello, world!", zlib::DefaultCompression);
+  testZlibCompression("hello, world!", CompressionScheme->getBestSizeLevel());
+  testZlibCompression("hello, world!", CompressionScheme->getBestSpeedLevel());
+  testZlibCompression("hello, world!", CompressionScheme->getDefaultLevel());
 
   const size_t kSize = 1024;
   char BinaryData[kSize];
@@ -54,38 +64,26 @@
 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, CompressionScheme->getBestSizeLevel());
+  testZlibCompression(BinaryDataStr, CompressionScheme->getBestSpeedLevel());
+  testZlibCompression(BinaryDataStr, CompressionScheme->getDefaultLevel());
 }
 #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("Destina

[PATCH] D130516: [llvm] compression classes

2022-08-02 Thread Cole Kissane via Phabricator via cfe-commits
ckissane added a comment.

In D130516#3694366 , @dblaikie wrote:

> In D130516#3694151 , @MaskRay wrote:
>
>> In D130516#3688236 , @dblaikie 
>> wrote:
>>
>>> In D130516#3688123 , @MaskRay 
>>> wrote:
>>>
 I'd like to make a few arguments for the current namespace+free function 
 design, as opposed to the class+member function design as explored in this 
 patch (but thanks for the exploration!).
 Let's discuss several use cases.

 (a) if a use case just calls compress/uncompress. The class design has 
 slightly more boilerplate as it needs to get the algorithm class, a new 
 instance, or a singleton instance.
 For each new use, the number of lines may not differ, but the involvement 
 of a a static class member or an instance make the reader wonder whether 
 the object will be reused or thrown away.
 There is some slight cognitive burden.
 The class design has a non-trivial one-shot cost to have a function 
 returning the singleton instance.
>>>
>>> Though there must've been a condition that dominates this use somewhere - 
>>> I'd suggest that condition could be where the algorithm is retrieved, and 
>>> then passed to this code to use unconditionally.
>>>
>>> If the algorithm object is const and raw pointers/references are used, I 
>>> think it makes it clear to the reader that there's no ownership here, and 
>>> it's not stateful when compressing/decompressing.
>>
>> A pointer to a singleton compression class is isomorphic to an `enum class 
>> CompressionType` variable.
>
> I don't mean to suggest that either design is fundamentally more or less 
> functional - I'm totally OK with/agree that both design directions allow the 
> implementation of all the desired final/end-user-visible functionality.
>
> I'm trying to make a point about which, I think, achieves that goal in a 
> "better" way - that's the space of design discussions, I think - what kinds 
> of (developer, maintenance, etc) costs different designs incur.
>
>> Using an enum variable doesn't lose any usage pattern we can do with a 
>> pointer to a singleton compression class.
>
> I agree that either design doesn't change what's possible - I do, though, 
> think that the "usage patterns" are meaningfully different between the two 
> designs.
>
>> An enum variable allows more patterns, as the allowed values are enumerable 
>> (we don't need to worry about -Wswitch for the uses).
>>
>> Say, we do
>>
>>   auto *algo = !compression::ZlibCompression;
>>   if (!algo)
>> ...
>>   
>>   
>>   algo->compress(...);
>>
>> either together or apart, the result is similar to the following but with 
>> (IMO) slightly larger cognitive burden:
>>
>>   if (!compression::isAvailable(format))
>> ...
>>   
>>   compression::compress(format);
>
> Specifically two APIs that are related (it's important/necessary to check for 
> availability before calling compress or decompress) in their contracts but 
> unrelated in their API use makes it easier to misuse the APIs and have a 
> situation where the availability check doesn't cover the usage. That's what I 
> think is important/important to discuss here.
>
 (b) zlib compress/uncompress immediately following an availability check.

   // free function
   if (!compression::zlib::isAvailable())
 errs() << "cannot compress: " << 
 compression::zlib::buildConfigurationHint();
   
   // class
   auto *algo = !compression::ZlibCompression;
   if (!algo->isAvailable()) {
 errs() << "cannot compress: " << algo->buildConfigurationHint();
   }
>>>
>>> I think maybe this code might end up looking like:
>>>
>>>   Algo *algo = getAlgo(Zlib)
>>>   if (!algo)
>>> errs() ...
>>>
>>> It's possible that this function would return non-null even for a 
>>> non-available algorithm if we wanted to communicate other things (like the 
>>> cmake macro name to enable to add the functionality)
>>
>> I think this is similarly achieved with an enum variable.
>> With the class based approach, a pointer has a static type of the ancestor 
>> compression class and a dynamic type of any possible algorithm.
>> This is not different from that: the enum variable may have a value the enum 
>> class supports.
>
> I agree that the code is similar in either case, but with a small difference 
> that is important to me - that accessing the algorithm necessarily (to some 
> degree - you could still have code that doesn't test the 
> condition/dereferences null, the same way that code can dereference an empty 
> Optional without checking first - but at least the API I'm suggesting makes 
> clear there's a connection between availability and usage).
>
 (c) zlib/zstd compress/uncompress immediately following an availability 
 check.

   // free function
   if 

[PATCH] D131009: [analyzer] Fixing a bug raising false positives of stack block object leaking under ARC

2022-08-02 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 created this revision.
ziqingluo-90 added reviewers: NoQ, t-rasmud, usama54321, steakhal, vsavchenko, 
martong, Szelethus.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: All.
ziqingluo-90 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When ARC is enabled, (objective-c) block objects are automatically retained and 
released thus they do not leak.  
Without ARC, they still can leak from an expiring stack frame like other stack 
variables.

This patch simply adds the ARC checking condition onto the changes made in 
https://reviews.llvm.org/D107078 .   The 
checker already checks the same condition for global variables.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131009

Files:
  clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
  clang/test/Analysis/stack-capture-leak-arc.mm
  clang/test/Analysis/stack-capture-leak-no-arc.mm

Index: clang/test/Analysis/stack-capture-leak-no-arc.mm
===
--- clang/test/Analysis/stack-capture-leak-no-arc.mm
+++ clang/test/Analysis/stack-capture-leak-no-arc.mm
@@ -4,6 +4,7 @@
 typedef void (^dispatch_block_t)(void);
 void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
 extern dispatch_queue_t queue;
+void f(int);
 
 void test_block_inside_block_async_no_leak() {
   int x = 123;
@@ -35,3 +36,46 @@
   return outer; // expected-warning-re{{Address of stack-allocated block declared on line {{.+}} is captured by a returned block}}
 }
 
+// The block literal defined in this function could leak once being
+// called.
+void output_block(dispatch_block_t * blk) {
+  int x = 0;
+  *blk = ^{ f(x); }; // expected-warning {{Address of stack-allocated block declared on line 43 is still referred to by the stack variable 'blk' upon returning to the caller.  This will be a dangling reference [core.StackAddressEscape]}}
+}
+
+// The block literal captures nothing thus is treated as a constant.
+void output_constant_block(dispatch_block_t * blk) {
+  *blk = ^{ };
+}
+
+// A block can leak if it captures at least one variable and is not
+// under ARC when its' stack frame expires.
+void test_block_leak() {
+  __block dispatch_block_t blk;
+  int x = 0;
+  dispatch_block_t p = ^{
+blk = ^{ // expected-warning {{Address of stack-allocated block declared on line 57 is still referred to by the stack variable 'blk' upon returning to the caller.  This will be a dangling reference [core.StackAddressEscape]}}
+  f(x);
+};
+  };
+
+  p();
+  blk();
+  output_block(&blk);
+  blk();
+}
+
+// A block captures nothing is a constant thus never leaks.
+void test_constant_block_no_leak() {
+  __block dispatch_block_t blk;
+  dispatch_block_t p = ^{
+blk = ^{
+  f(0);
+};
+  };
+  
+  p();
+  blk();
+  output_constant_block(&blk);
+  blk();
+}
Index: clang/test/Analysis/stack-capture-leak-arc.mm
===
--- clang/test/Analysis/stack-capture-leak-arc.mm
+++ clang/test/Analysis/stack-capture-leak-arc.mm
@@ -8,6 +8,7 @@
 typedef long dispatch_time_t;
 void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block);
 void dispatch_barrier_sync(dispatch_queue_t queue, dispatch_block_t block);
+void f(int);
 
 extern dispatch_queue_t queue;
 extern dispatch_once_t *predicate;
@@ -187,3 +188,40 @@
   }
   dispatch_barrier_sync(queue, ^{});
 }
+
+void output_block(dispatch_block_t * blk) {
+  int x = 0;
+  *blk = ^{ f(x); };
+}
+
+// Block objects themselves can never leak under ARC.
+void test_no_block_leak() {
+  __block dispatch_block_t blk;
+  int x = 0;
+  dispatch_block_t p = ^{
+blk = ^{
+  f(x);
+};
+  };
+  p();
+  blk();
+  output_block(&blk);
+  blk();
+}
+
+// Block objects do not leak under ARC but stack variables of
+// non-object kind indirectly referred by a block can leak.
+dispatch_block_t test_block_referencing_variable_leak() {
+  int x = 0;
+  __block int * p = &x;
+  __block int * q = &x;
+  
+  dispatch_async(queue, ^{// expected-warning {{Address of stack memory associated with local variable 'x' is captured by an asynchronously-executed block \
+[alpha.core.StackAddressAsyncEscape]}}
+  ++(*p);
+});
+  return (dispatch_block_t) ^{// expected-warning {{Address of stack memory associated with local variable 'x' is captured by a returned block \
+[core.StackAddressEscape]}}
+++(*q);
+  };
+}
Index: clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
@@ -310,6 +310,9 @@
 /// referred by an other stack variable from different st

[PATCH] D130516: [llvm] compression classes

2022-08-02 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

The current code here still seems more complicated than I'd prefer - looks like 
currently the size/speed/default levels are currently unused, so maybe we can 
omit those for now, knowing they will be added?
And the CompressionKind with all its operator overloads seems like a lot of 
surface area that is pretty non-obvious for usage - boolean testable, logical 
operator overloads, etc.
Could we have only one decompress/compress function each, for now?
& maybe leave out the name/enum from the base class for now, add it in later (& 
I think I mentionted in another comment those properties can be non-virtual, 
maybe even direct const members - passed into the base through the ctor from 
the derived class)

Maybe it's easier if I either post a patch, or at least more explicitly flesh 
out what I'm picturing/proposing/suggesting:
Header:

  struct CompressionAlgorithm {
virtual void Compress(...);
virtual void Decompress(...);
  };
  enum class CompressionType {
Zlib, Zstd
  };
  CompressionAlgorithm *getCompressionAlgorithm(CompressionType);

Implementation:

  #if LLVM_ENABLE_ZLIB
  struct ZlibCompressionAlgorthim : CompressionAlgorithm {
void Compress(...) { ... }
void Decompress(...) { ...}
  }
  #endif
  ...
  CompressionAlgorithm *getCompressionAlgorithm(CompressionType T) {
switch (T) {
case CompressionType::Zlib: {
  #if LLVM_ENABLE_ZLIB
  static ZlibCompressionAlgorithm A;
  return &A;
  #else
  break;
  #endif
}
  ...
}
return nullptr;
  }

Usage:

  if (CompressionAlgorithm *C = getCompressionAlgorithm(CompressionType::Zlib) {
C->compress(...);
  }

And, yeah, I think it'd be suitable to eventually add name, type, 
size/speed/default levels:

  struct CompressionAlgorithm {
const StringRef Name;
const CompressionType Type;
const int DefaultLevel;
const int BestSizeLevel;
const int BestSpeedLevel;
virtual void Compress(...);
virtual void Decompress(...);
  protected:
CompressionAlgorithm(StringRef Name, CompressionType Type, ...) : 
Name(Name), Type(Type), ... {}
  }

  struct ZlibCompressionAlgorithm : CompressionAlgorithm {
ZlibCompressionAlgorithm() : CompressionAlgorithm("zlib", 
CompressionType::Zlib, 5, 10, 1) { }
/* as before */
  };
  ...

Though those can be added as needed - good to keep in mind that they're a 
useful direction to go, but might simplify the review/discussion to omit them 
for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130516

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


[PATCH] D130516: [llvm] compression classes

2022-08-02 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

> I think I have worked out something that is the best of both worlds:

I think @MaskRay's main concern, which I share to a degree, is that there's a 
lot of code/complexity here that doesn't currently seem warranted by the size 
of the problem. So adding more implementation complexity to this patch, even if 
it does provide some of the benefits (though I don't think the ability to do 
boolean logic, etc, is the main concern either myself or @maskray have - either 
way we'll have the enum) it's adding a lot more implementation complexity, 
which is something we're trying to address/reduce.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130516

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


[PATCH] D130516: [llvm] compression classes

2022-08-02 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D130516#3694366 , @dblaikie wrote:

> In D130516#3694151 , @MaskRay wrote:
>
>> In D130516#3688236 , @dblaikie 
>> wrote:
>>
>>> In D130516#3688123 , @MaskRay 
>>> wrote:
>>>
 I'd like to make a few arguments for the current namespace+free function 
 design, as opposed to the class+member function design as explored in this 
 patch (but thanks for the exploration!).
 Let's discuss several use cases.

 (a) if a use case just calls compress/uncompress. The class design has 
 slightly more boilerplate as it needs to get the algorithm class, a new 
 instance, or a singleton instance.
 For each new use, the number of lines may not differ, but the involvement 
 of a a static class member or an instance make the reader wonder whether 
 the object will be reused or thrown away.
 There is some slight cognitive burden.
 The class design has a non-trivial one-shot cost to have a function 
 returning the singleton instance.
>>>
>>> Though there must've been a condition that dominates this use somewhere - 
>>> I'd suggest that condition could be where the algorithm is retrieved, and 
>>> then passed to this code to use unconditionally.
>>>
>>> If the algorithm object is const and raw pointers/references are used, I 
>>> think it makes it clear to the reader that there's no ownership here, and 
>>> it's not stateful when compressing/decompressing.
>>
>> A pointer to a singleton compression class is isomorphic to an `enum class 
>> CompressionType` variable.
>
> I don't mean to suggest that either design is fundamentally more or less 
> functional - I'm totally OK with/agree that both design directions allow the 
> implementation of all the desired final/end-user-visible functionality.
>
> I'm trying to make a point about which, I think, achieves that goal in a 
> "better" way - that's the space of design discussions, I think - what kinds 
> of (developer, maintenance, etc) costs different designs incur.
>
> [...]
>
> I don't understand what you're saying here. Could you rephrase/expand a bit?
>
> Maybe it's easier if I either post a patch, or at least more explicitly flesh 
> out what I'm picturing/proposing/suggesting:

I agree that it is easier if you post a patch so that we can have discussion on 
concrete code. I think we are now at the "a picture is worth a thousand words"  
stage:)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130516

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


[PATCH] D131004: [clang] Add FileEntryRef::getNameAsRequested()

2022-08-02 Thread Ben Barham via Phabricator via cfe-commits
bnbarham accepted this revision.
bnbarham added a comment.
This revision is now accepted and ready to land.

Thanks 🙇




Comment at: clang/unittests/Basic/FileManagerTest.cpp:381
   EXPECT_TRUE(F1->isSameRef(*F1Again));
-  EXPECT_TRUE(F1->isSameRef(*F1Redirect));
+  EXPECT_FALSE(F1->isSameRef(*F1Redirect));
   EXPECT_FALSE(F1->isSameRef(*F1Also));

Bit weird that this test was checking for true 🤔. Seems like it isn't used 
outside of tests except for `isEqual` in `DenseMapInfo` though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131004

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


[PATCH] D130516: [llvm] compression classes

2022-08-02 Thread Cole Kissane via Phabricator via cfe-commits
ckissane added a comment.

In D130516#3694422 , @dblaikie wrote:

> The current code here still seems more complicated than I'd prefer - looks 
> like currently the size/speed/default levels are currently unused, so maybe 
> we can omit those for now, knowing they will be added?
> And the CompressionKind with all its operator overloads seems like a lot of 
> surface area that is pretty non-obvious for usage - boolean testable, logical 
> operator overloads, etc.
> Could we have only one decompress/compress function each, for now?
> & maybe leave out the name/enum from the base class for now, add it in later 
> (& I think I mentionted in another comment those properties can be 
> non-virtual, maybe even direct const members - passed into the base through 
> the ctor from the derived class)

Yes, I can continue to trim down the implementation! I agree with your 
sentiment.

> Maybe it's easier if I either post a patch, or at least more explicitly flesh 
> out what I'm picturing/proposing/suggesting:
> Header:
>
>   struct CompressionAlgorithm {
> virtual void Compress(...);
> virtual void Decompress(...);
>   };
>   enum class CompressionType {
> Zlib, Zstd
>   };
>   CompressionAlgorithm *getCompressionAlgorithm(CompressionType);
>
> Implementation:
>
>   #if LLVM_ENABLE_ZLIB
>   struct ZlibCompressionAlgorthim : CompressionAlgorithm {
> void Compress(...) { ... }
> void Decompress(...) { ...}
>   }
>   #endif
>   ...
>   CompressionAlgorithm *getCompressionAlgorithm(CompressionType T) {
> switch (T) {
> case CompressionType::Zlib: {
>   #if LLVM_ENABLE_ZLIB
>   static ZlibCompressionAlgorithm A;
>   return &A;
>   #else
>   break;
>   #endif
> }
>   ...
> }
> return nullptr;
>   }

I agree with some of this, I have some strong thoughts I would like to work out 
about the whole nullptr being none or unsupported a little preemptively IMO.

>   Usage:
>
> if (CompressionAlgorithm *C = getCompressionAlgorithm(CompressionType::Zlib) {
>
>   C->compress(...);
>
> }
>
>   

currently, you can do

  if (CompressionKind C = CompressionKind::Zlib) {
C->compress(...);
  }



> And, yeah, I think it'd be suitable to eventually add name, type, 
> size/speed/default levels:
>
>   struct CompressionAlgorithm {
> const StringRef Name;
> const CompressionType Type;
> const int DefaultLevel;
> const int BestSizeLevel;
> const int BestSpeedLevel;
> virtual void Compress(...);
> virtual void Decompress(...);
>   protected:
> CompressionAlgorithm(StringRef Name, CompressionType Type, ...) : 
> Name(Name), Type(Type), ... {}
>   }
>
>   struct ZlibCompressionAlgorithm : CompressionAlgorithm {
> ZlibCompressionAlgorithm() : CompressionAlgorithm("zlib", 
> CompressionType::Zlib, 5, 10, 1) { }
> /* as before */
>   };
>   ...
>
> Though those can be added as needed - good to keep in mind that they're a 
> useful direction to go, but might simplify the review/discussion to omit them 
> for now.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130516

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


[PATCH] D124435: [X86] Always extend the integer parameters in callee

2022-08-02 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

It looks like you haven't implemented the target-specific logic for this yet.  
I cannot let you commit until you do that, because you will be breaking the ABI 
on Apple platforms.




Comment at: clang/include/clang/Basic/CodeGenOptions.h:150
+Assumed,  // Force the use of Extend.
+Default, // Use the default rule for the target, which is Extend for now.
+  };

This comment is incorrect.



Comment at: clang/include/clang/Driver/Options.td:3435
+   "'assumed' (Assume the small integer parameter has been extened in 
the caller) | "
+   "'default' (Use the default rule for the target, this value is not 
yet supported)">,
+  Values<"none,conservative,assumed,default">,

We're not usually this verbose in the inline help text; this is basically an 
attempt to document the whole feature, which is excessive,   We should do like 
we do for `-mthread-model` or similar enum options and just quickly describe 
the option and list the possible values.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:1948
+case CodeGenOptions::ExtendIntegerArgsKind::Direct:
+// ExtendIntegerArgsKind::Direct will be handled at the last.
+  break;





Comment at: clang/lib/CodeGen/TargetInfo.cpp:3828
+  isPromotableIntegerTypeForABI(Ty)) {
+  // ExtendIntegerArgsKind::Direct will be handled at the last.
+  if (Kind == CodeGenOptions::ExtendIntegerArgsKind::Conservative)




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124435

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


[PATCH] D130964: [X86][BF16] Enable __bf16 for x86 targets.

2022-08-02 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

How are you actually implementing `__bf16` on these targets?  There isn't even 
hardware support for conversions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130964

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


[PATCH] D131012: No longer place const volatile global variables in a read only section

2022-08-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: nickdesaulniers, erichkeane, rjmccall, efriedma.
Herald added a project: All.
aaron.ballman requested review of this revision.
Herald added a project: clang.

The C standard hints in a footnote attached to C17 6.7.3p5 that `const` objects 
which are not `volatile` can be placed in read-only memory, which implies that 
`volatile` objects can never be placed there. GCC appears to be following that 
behavior: https://godbolt.org/z/9WEq18TWz and this changes Clang to behave the 
same.

Fixes #56468


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131012

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCXX/const-global-linkage.cpp


Index: clang/test/CodeGenCXX/const-global-linkage.cpp
===
--- clang/test/CodeGenCXX/const-global-linkage.cpp
+++ clang/test/CodeGenCXX/const-global-linkage.cpp
@@ -4,7 +4,7 @@
 const int y = 20;
 const volatile int z = 30;
 // CHECK-NOT: @x
-// CHECK: @z = {{(dso_local )?}}constant i32 30
+// CHECK: @z = {{(dso_local )?}}global i32 30
 // CHECK: @_ZL1y = internal constant i32 20
 const int& b() { return y; }
 
@@ -12,6 +12,6 @@
 const char z2[] = "zxcv";
 const volatile char z3[] = "zxcv";
 // CHECK-NOT: @z1
-// CHECK: @z3 = {{(dso_local )?}}constant
+// CHECK: @z3 = {{(dso_local )?}}global
 // CHECK: @_ZL2z2 = internal constant
 const char* b2() { return z2; }
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4165,6 +4165,15 @@
   if (!Ty.isConstant(Context) && !Ty->isReferenceType())
 return false;
 
+  // If the type is also marked as volatile, it should not be treated as a
+  // constant according to C17 6.7.3p5 and footnote 133, though there does not
+  // appear to be a normative requirement. That said, GCC does not put the
+  // object into a read only section, and we're following suit. C++ says even
+  // less about this situation, but [decl.type.cv]p6 implies that when it comes
+  // to volatile, C++ follows C's lead, so we'll do the same here.
+  if (Ty.isVolatileQualified())
+return false;
+
   if (Context.getLangOpts().CPlusPlus) {
 if (const CXXRecordDecl *Record
   = Context.getBaseElementType(Ty)->getAsCXXRecordDecl())
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -52,6 +52,9 @@
 - Fixes an accepts-invalid bug in C when using a ``_Noreturn`` function
   specifier on something other than a function declaration. This fixes
   `Issue 56800 `_.
+- ``const volatile`` global variables are no longer placed in a read-only
+  section, but are instead treated as a non-const global. This fixes
+  `Issue 56468 `_.
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/CodeGenCXX/const-global-linkage.cpp
===
--- clang/test/CodeGenCXX/const-global-linkage.cpp
+++ clang/test/CodeGenCXX/const-global-linkage.cpp
@@ -4,7 +4,7 @@
 const int y = 20;
 const volatile int z = 30;
 // CHECK-NOT: @x
-// CHECK: @z = {{(dso_local )?}}constant i32 30
+// CHECK: @z = {{(dso_local )?}}global i32 30
 // CHECK: @_ZL1y = internal constant i32 20
 const int& b() { return y; }
 
@@ -12,6 +12,6 @@
 const char z2[] = "zxcv";
 const volatile char z3[] = "zxcv";
 // CHECK-NOT: @z1
-// CHECK: @z3 = {{(dso_local )?}}constant
+// CHECK: @z3 = {{(dso_local )?}}global
 // CHECK: @_ZL2z2 = internal constant
 const char* b2() { return z2; }
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4165,6 +4165,15 @@
   if (!Ty.isConstant(Context) && !Ty->isReferenceType())
 return false;
 
+  // If the type is also marked as volatile, it should not be treated as a
+  // constant according to C17 6.7.3p5 and footnote 133, though there does not
+  // appear to be a normative requirement. That said, GCC does not put the
+  // object into a read only section, and we're following suit. C++ says even
+  // less about this situation, but [decl.type.cv]p6 implies that when it comes
+  // to volatile, C++ follows C's lead, so we'll do the same here.
+  if (Ty.isVolatileQualified())
+return false;
+
   if (Context.getLangOpts().CPlusPlus) {
 if (const CXXRecordDecl *Record
   = Context.getBaseElementType(Ty)->getAsCXXRecordDecl())
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNote

[PATCH] D131012: No longer place const volatile global variables in a read only section

2022-08-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

The code changes look perfectly fine to me, but I'm hopeful someone else has 
something to say about how acceptable/ABI related this is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131012

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


[PATCH] D130510: Missing tautological compare warnings due to unary operators

2022-08-02 Thread Richard Trieu via Phabricator via cfe-commits
rtrieu added a comment.

In D130510#3693494 , @aaron.ballman 
wrote:

> In D130510#3692654 , @rtrieu wrote:
>
>> Because of this, warnings should treat dependent expressions as non-constant 
>> even when they can be evaluated, so only `b3` should get a warning.  This is 
>> causing the warning to be emitted on code heavy in template 
>> meta-programming, such as array libraries.  Please revert or fix.
>
> Yeah, I agree. Unfortunately, the CFG makes this exceptionally difficult 
> because it walks over the instantiated code, so we've lost that the original 
> expression was dependent by the time we get to checking the binary 
> expressions. The original code worked by virtue of overfitting to *just* 
> integer literals.

Not being able to detect when expressions are dependent inside template 
instantiations has been a pain for warnings since forever.

>> I believe that evaluating the expression would make this warning too broad 
>> and would need more testing that what was included here.  Only handling 
>> UnaryOperator with IntegerLiteral sub-expression makes more sense for the 
>> warning, and adding in any new cases if we find them.
>
> I agree that the warning is too broad right now and that's unintentional. 
> However, manually handling every single case in the CFG as something special 
> is fragile and what got us this bug in the first place. We have a constant 
> expression evaluator (two, actually) and we shouldn't have to reimplement it 
> a third time in the CFG. However, asking a GSoC mentee to address that is 
> well beyond the scope of what they should be working on. So for now I'm going 
> to revert this change, reopen the issue, and we'll discuss the next steps 
> off-list with Usman.

I agree, the CFG should be as broadly applicable as possible, so using an 
evaluator there is fine.  Manually handling every single case may be needed to 
keep the warning under control.  It's possible to put that handling to the Sema 
side of things, right before the warning is emitted.  There's already a filter 
for macros, so maybe adding the filtering logic there would be a good fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130510

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


[PATCH] D131012: No longer place const volatile global variables in a read only section

2022-08-02 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I think this is fine for the ABI; the section is generally a 
definition-specific property and doesn't affect use sites.

Do we also need to check for volatile fields of records?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131012

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


[PATCH] D131014: [clang][dataflow] Make the type of the post visit callback consistent

2022-08-02 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev created this revision.
sgatev added reviewers: ymandel, xazax.hun, gribozavr2, samestep.
Herald added subscribers: martong, tschuett, rnkovacs.
Herald added a reviewer: NoQ.
Herald added a project: All.
sgatev requested review of this revision.
Herald added a project: clang.

Make the type of the post visit callback consistent.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131014

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -1245,9 +1245,10 @@
   return UncheckedOptionalAccessModel(Ctx, Options);
 },
 [&Diagnostics, Diagnoser = UncheckedOptionalAccessDiagnoser(Options)](
-ASTContext &Ctx, const Stmt *Stmt,
+ASTContext &Ctx, const CFGStmt &Stmt,
 const TypeErasedDataflowAnalysisState &State) mutable {
-  auto StmtDiagnostics = Diagnoser.diagnose(Ctx, Stmt, State.Env);
+  auto StmtDiagnostics =
+  Diagnoser.diagnose(Ctx, Stmt.getStmt(), State.Env);
   llvm::move(StmtDiagnostics, std::back_inserter(Diagnostics));
 },
 [&Diagnostics](AnalysisData AnalysisData) {
Index: clang/unittests/Analysis/FlowSensitive/TestingSupport.h
===
--- clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -76,7 +76,7 @@
 llvm::StringRef Code,
 ast_matchers::internal::Matcher TargetFuncMatcher,
 std::function MakeAnalysis,
-std::function
 PostVisitStmt,
 std::function VerifyResults, ArrayRef Args,
@@ -112,11 +112,11 @@
   Environment Env(DACtx, *F);
   auto Analysis = MakeAnalysis(Context, Env);
 
-  std::function
+  std::function
   PostVisitStmtClosure = nullptr;
   if (PostVisitStmt != nullptr) {
 PostVisitStmtClosure = [&PostVisitStmt, &Context](
-   const Stmt *Stmt,
+   const CFGStmt &Stmt,
const TypeErasedDataflowAnalysisState &State) {
   PostVisitStmt(Context, Stmt, State);
 };
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -333,7 +333,8 @@
 runTypeErasedDataflowAnalysis(
 const ControlFlowContext &CFCtx, TypeErasedDataflowAnalysis &Analysis,
 const Environment &InitEnv,
-std::function
+std::function
 PostVisitStmt) {
   PostOrderCFGView POV(&CFCtx.getCFG());
   ForwardDataflowWorklist Worklist(CFCtx.getCFG(), &POV);
@@ -398,12 +399,9 @@
   // Skip blocks that were not evaluated.
   if (!BlockStates[Block->getBlockID()])
 continue;
-  transferBlock(
-  CFCtx, BlockStates, *Block, InitEnv, Analysis,
-  [&PostVisitStmt](const clang::CFGStmt &Stmt,
-   const TypeErasedDataflowAnalysisState &State) {
-PostVisitStmt(Stmt.getStmt(), State);
-  });
+
+  transferBlock(CFCtx, BlockStates, *Block, InitEnv, Analysis,
+PostVisitStmt);
 }
   }
 
Index: clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
===
--- clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
+++ clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
@@ -138,7 +138,8 @@
 runTypeErasedDataflowAnalysis(
 const ControlFlowContext &CFCtx, TypeErasedDataflowAnalysis &Analysis,
 const Environment &InitEnv,
-std::function
+std::function
 PostVisitStmt = nullptr);
 
 } // namespace dataflow
Index: clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
@@ -125,14 +125,14 @@
 runDataflowAnalysis(
 const ControlFlowContext &CFCtx, AnalysisT &Analysis,
 const Environment &InitEnv,
-std::function &)>
+std::function &)>
 PostVisitStmt = nullptr) {
-  std::function
+  std::function
   PostVisitStmtClosure = nullptr;
   if (PostVisitStmt != nullptr) {
  

[PATCH] D131014: [clang][dataflow] Make the type of the post visit callback consistent

2022-08-02 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 449398.
sgatev added a comment.

Update commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131014

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -1245,9 +1245,10 @@
   return UncheckedOptionalAccessModel(Ctx, Options);
 },
 [&Diagnostics, Diagnoser = UncheckedOptionalAccessDiagnoser(Options)](
-ASTContext &Ctx, const Stmt *Stmt,
+ASTContext &Ctx, const CFGStmt &Stmt,
 const TypeErasedDataflowAnalysisState &State) mutable {
-  auto StmtDiagnostics = Diagnoser.diagnose(Ctx, Stmt, State.Env);
+  auto StmtDiagnostics =
+  Diagnoser.diagnose(Ctx, Stmt.getStmt(), State.Env);
   llvm::move(StmtDiagnostics, std::back_inserter(Diagnostics));
 },
 [&Diagnostics](AnalysisData AnalysisData) {
Index: clang/unittests/Analysis/FlowSensitive/TestingSupport.h
===
--- clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -76,7 +76,7 @@
 llvm::StringRef Code,
 ast_matchers::internal::Matcher TargetFuncMatcher,
 std::function MakeAnalysis,
-std::function
 PostVisitStmt,
 std::function VerifyResults, ArrayRef Args,
@@ -112,11 +112,11 @@
   Environment Env(DACtx, *F);
   auto Analysis = MakeAnalysis(Context, Env);
 
-  std::function
+  std::function
   PostVisitStmtClosure = nullptr;
   if (PostVisitStmt != nullptr) {
 PostVisitStmtClosure = [&PostVisitStmt, &Context](
-   const Stmt *Stmt,
+   const CFGStmt &Stmt,
const TypeErasedDataflowAnalysisState &State) {
   PostVisitStmt(Context, Stmt, State);
 };
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -333,7 +333,8 @@
 runTypeErasedDataflowAnalysis(
 const ControlFlowContext &CFCtx, TypeErasedDataflowAnalysis &Analysis,
 const Environment &InitEnv,
-std::function
+std::function
 PostVisitStmt) {
   PostOrderCFGView POV(&CFCtx.getCFG());
   ForwardDataflowWorklist Worklist(CFCtx.getCFG(), &POV);
@@ -398,12 +399,9 @@
   // Skip blocks that were not evaluated.
   if (!BlockStates[Block->getBlockID()])
 continue;
-  transferBlock(
-  CFCtx, BlockStates, *Block, InitEnv, Analysis,
-  [&PostVisitStmt](const clang::CFGStmt &Stmt,
-   const TypeErasedDataflowAnalysisState &State) {
-PostVisitStmt(Stmt.getStmt(), State);
-  });
+
+  transferBlock(CFCtx, BlockStates, *Block, InitEnv, Analysis,
+PostVisitStmt);
 }
   }
 
Index: clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
===
--- clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
+++ clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
@@ -138,7 +138,8 @@
 runTypeErasedDataflowAnalysis(
 const ControlFlowContext &CFCtx, TypeErasedDataflowAnalysis &Analysis,
 const Environment &InitEnv,
-std::function
+std::function
 PostVisitStmt = nullptr);
 
 } // namespace dataflow
Index: clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
@@ -125,14 +125,14 @@
 runDataflowAnalysis(
 const ControlFlowContext &CFCtx, AnalysisT &Analysis,
 const Environment &InitEnv,
-std::function &)>
+std::function &)>
 PostVisitStmt = nullptr) {
-  std::function
+  std::function
   PostVisitStmtClosure = nullptr;
   if (PostVisitStmt != nullptr) {
 PostVisitStmtClosure = [&PostVisitStmt](
-   const Stmt *Stmt,
+   const CFGStmt &Stmt,
   

  1   2   >