[PATCH] D128439: [Clang][WIP] Don't call distributeTypeAttrsFromDeclarator() on empty list.

2022-06-26 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added a comment.

Thanks for the pointer -- I wasn't aware of that document yet!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128439

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


[PATCH] D128329: [clangd] Also mark output arguments of operator call expressions

2022-06-26 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Thanks for the patch!

nit: please make the commit message a bit more specific, e.g. "Also apply the 
'mutable' semantic token modifier to arguments of overloaded call operators"




Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:540
 
 // FIXME ...here it would make sense though.
+Expr **args = nullptr;

Please update the FIXME to something like:

```
// FIXME: consider highlighting parameters of some other overloaded operators 
as well
```

(There's some discussion 
[here](https://reviews.llvm.org/D108320?id=367302#inline-1031934) about which 
other cases would make sense to highlight, and which wouldn't.)



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:541
 // FIXME ...here it would make sense though.
-if (isa(E))
-  return true;
+Expr **args = nullptr;
+unsigned numArgs = 0;

I think this could be expressed a bit more cleanly with the `ArrayRef` API:

(Please note also the convention in this codebase to capitalize local variable 
names.)

```
llvm::ArrayRef Args = {E->getArgs(), E->getNumArgs()};
if (const auto CallOp = ...) {
  if (CallOp->getOperator() != OO_Call)
return true;
  
  Args = Args.drop_front();  // Drop object parameter
}

highlightMutableReferenceArguments(..., Args);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128329

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


[PATCH] D128621: [clangd] Do not try to use $0 as a placeholder in completion snippets

2022-06-26 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
nridge added reviewers: hokein, ilya-biryukov, sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: All.
nridge requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang-tools-extra.

$0 can only be used as a tab stop, not as a placeholder (e.g.
`${0:expression}` is not valid)

Fixes https://github.com/clangd/clangd/issues/1190


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128621

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeCompletionStrings.cpp
  clang-tools-extra/clangd/CodeCompletionStrings.h
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp

Index: clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
@@ -23,12 +23,10 @@
 CCTUInfo(Allocator), Builder(*Allocator, CCTUInfo) {}
 
 protected:
-  void computeSignature(const CodeCompletionString ,
-bool CompletingPattern = false) {
+  void computeSignature(const CodeCompletionString ) {
 Signature.clear();
 Snippet.clear();
-getSignature(CCS, , , /*RequiredQualifier=*/nullptr,
- CompletingPattern);
+getSignature(CCS, , , /*RequiredQualifier=*/nullptr);
   }
 
   std::shared_ptr Allocator;
@@ -145,12 +143,8 @@
 Builder.AddChunk(CodeCompletionString::CK_SemiColon);
 return *Builder.TakeString();
   };
-  computeSignature(MakeCCS(), /*CompletingPattern=*/false);
+  computeSignature(MakeCCS());
   EXPECT_EQ(Snippet, " ${1:name} = ${2:target};");
-
-  // When completing a pattern, the last placeholder holds the cursor position.
-  computeSignature(MakeCCS(), /*CompletingPattern=*/true);
-  EXPECT_EQ(Snippet, " ${1:name} = ${0:target};");
 }
 
 TEST_F(CompletionStringTest, IgnoreInformativeQualifier) {
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3135,12 +3135,10 @@
 })cpp",
   /*IndexSymbols=*/{}, Options);
 
-  // Last placeholder in code patterns should be $0 to put the cursor there.
   EXPECT_THAT(Results.Completions,
   Contains(AllOf(
   named("while"),
-  snippetSuffix(" (${1:condition}) {\n${0:statements}\n}";
-  // However, snippets for functions must *not* end with $0.
+  snippetSuffix(" (${1:condition}) {\n${2:statements}\n}";
   EXPECT_THAT(Results.Completions,
   Contains(AllOf(named("while_foo"),
  snippetSuffix("(${1:int a}, ${2:int b})";
Index: clang-tools-extra/clangd/CodeCompletionStrings.h
===
--- clang-tools-extra/clangd/CodeCompletionStrings.h
+++ clang-tools-extra/clangd/CodeCompletionStrings.h
@@ -41,13 +41,9 @@
 ///   *Snippet = "(${1:size_type})"
 /// If set, RequiredQualifiers is the text that must be typed before the name.
 /// e.g "Base::" when calling a base class member function that's hidden.
-///
-/// When \p CompletingPattern is true, the last placeholder will be of the form
-/// ${0:…}, indicating the cursor should stay there.
 void getSignature(const CodeCompletionString , std::string *Signature,
   std::string *Snippet,
-  std::string *RequiredQualifiers = nullptr,
-  bool CompletingPattern = false);
+  std::string *RequiredQualifiers = nullptr);
 
 /// Assembles formatted documentation for a completion result. This includes
 /// documentation comments and other relevant information like annotations.
Index: clang-tools-extra/clangd/CodeCompletionStrings.cpp
===
--- clang-tools-extra/clangd/CodeCompletionStrings.cpp
+++ clang-tools-extra/clangd/CodeCompletionStrings.cpp
@@ -95,22 +95,7 @@
 }
 
 void getSignature(const CodeCompletionString , std::string *Signature,
-  std::string *Snippet, std::string *RequiredQualifiers,
-  bool CompletingPattern) {
-  // Placeholder with this index will be ${0:…} to mark final cursor position.
-  // Usually we do not add $0, so the cursor is placed at end of completed text.
-  unsigned CursorSnippetArg = std::numeric_limits::max();
-  if (CompletingPattern) {
-// In patterns, it's best to place the cursor at the last placeholder, to
-// handle cases like
-//namespace ${1:name} {
-//  ${0:decls}
-//}
-CursorSnippetArg =
-llvm::count_if(CCS, [](const 

[PATCH] D128328: [C++20][Modules] Improve handing of Private Module Fragment diagnostics.

2022-06-26 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

From the discussion, it looks like the 'export' part is not necessary here and 
we don't need to care about linkage in this revision.

In D128328#3609827 , @vsapsai wrote:

> Sorry for changing my mind. I've thought about the errors more and especially 
> about the case mentioned by Chuanqi
>
>   export module A;
>   [export] inline void func();
>
> I'm afraid it can complicate the implementation but we can achieve some 
> consistency with errors like
>
>   export module A;
>   export inline void func(); // error: no definition for exported inline 
> function 'func' in module 'A'
>
> and
>
>   export module A;
>   export inline void func(); // error: no definition for exported inline 
> function 'func' in module 'A'
>   //...
>   module :private;
>   void func() {}  // note: definition here is not reachable as it is private
>
> I think it is useful to have connection between declaration and definition 
> and to explain why the definition is no good.
>
> Specific wording around "no definition | missing definition | definition 
> required" is flexible.

It makes sense to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128328

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


[clang] ca05cc2 - [clang] Don't use Optional::hasValue (NFC)

2022-06-26 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-06-26T18:51:54-07:00
New Revision: ca05cc206478245292cb769f826dbe12f59605be

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

LOG: [clang] Don't use Optional::hasValue (NFC)

This patch replaces x.hasValue() with x where x is contextually
convertible to bool.

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
clang/include/clang/Support/RISCVVIntrinsicUtils.h
clang/lib/Driver/Driver.cpp
clang/lib/Lex/MacroInfo.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
index 11c60b6895627..4b6cbd516628a 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
@@ -53,14 +53,10 @@ class ConditionTruthVal {
   }
 
   /// Return true if the constraint is perfectly constrained to 'true'.
-  bool isConstrainedTrue() const {
-return Val.hasValue() && Val.getValue();
-  }
+  bool isConstrainedTrue() const { return Val && Val.getValue(); }
 
   /// Return true if the constraint is perfectly constrained to 'false'.
-  bool isConstrainedFalse() const {
-return Val.hasValue() && !Val.getValue();
-  }
+  bool isConstrainedFalse() const { return Val && !Val.getValue(); }
 
   /// Return true if the constrained is perfectly constrained.
   bool isConstrained() const {

diff  --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h 
b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index 0e9fe97ab735e..3b6f205f9f220 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -209,8 +209,8 @@ class RVVType {
   }
 
   bool isValid() const { return Valid; }
-  bool isScalar() const { return Scale.hasValue() && Scale.getValue() == 0; }
-  bool isVector() const { return Scale.hasValue() && Scale.getValue() != 0; }
+  bool isScalar() const { return Scale && Scale.getValue() == 0; }
+  bool isVector() const { return Scale && Scale.getValue() != 0; }
   bool isVector(unsigned Width) const {
 return isVector() && ElementBitwidth == Width;
   }

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index d83142286e7d6..c34da3a67a2e0 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3325,8 +3325,8 @@ class OffloadingActionBuilder final {
 A = C.getDriver().ConstructPhaseAction(C, Args, CurPhase, A,
AssociatedOffloadKind);
 
-  if (CompileDeviceOnly && CurPhase == FinalPhase &&
-  BundleOutput.hasValue() && BundleOutput.getValue()) {
+  if (CompileDeviceOnly && CurPhase == FinalPhase && BundleOutput &&
+  BundleOutput.getValue()) {
 for (unsigned I = 0, E = GpuArchList.size(); I != E; ++I) {
   OffloadAction::DeviceDependences DDep;
   DDep.add(*CudaDeviceActions[I], *ToolChains.front(), GpuArchList[I],

diff  --git a/clang/lib/Lex/MacroInfo.cpp b/clang/lib/Lex/MacroInfo.cpp
index 19ab9bcb972dd..310b95f36771d 100644
--- a/clang/lib/Lex/MacroInfo.cpp
+++ b/clang/lib/Lex/MacroInfo.cpp
@@ -213,8 +213,7 @@ MacroDirective::DefInfo MacroDirective::getDefinition() {
   isPublic = VisMD->isPublic();
   }
 
-  return DefInfo(nullptr, UndefLoc,
- !isPublic.hasValue() || isPublic.getValue());
+  return DefInfo(nullptr, UndefLoc, !isPublic || isPublic.getValue());
 }
 
 const MacroDirective::DefInfo

diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index dbb0ca66f4976..43a69a8e94e14 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2313,9 +2313,9 @@ Parser::DeclGroupPtrTy 
Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
 Sema::DeclareTargetContextInfo DTCI(DKind, DTLoc);
 if (HasClauses)
   ParseOMPDeclareTargetClauses(DTCI);
-bool HasImplicitMappings =
-DKind == OMPD_begin_declare_target || !HasClauses ||
-(DTCI.ExplicitlyMapped.empty() && DTCI.Indirect.hasValue());
+bool HasImplicitMappings = DKind == OMPD_begin_declare_target ||
+   !HasClauses ||
+   (DTCI.ExplicitlyMapped.empty() && 
DTCI.Indirect);
 
 // Skip the last annot_pragma_openmp_end.
 ConsumeAnyToken();

diff  --git a/clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp 
b/clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp
index 4c5efa7504048..7c50453abe509 100644
--- 

[PATCH] D128620: [Driver][test] Add libclang_rt.profile{{.*}}.a tests for NetBSD

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

It's best to switch to LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on layout at some 
point.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128620

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


[PATCH] D128620: [Driver][test] Add libclang_rt.profile{{.*}}.a tests for NetBSD

2022-06-26 Thread Frederic Cambus via Phabricator via cfe-commits
fcambus created this revision.
fcambus added a reviewer: MaskRay.
Herald added a subscriber: StephenFan.
Herald added a project: All.
fcambus requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Similar to D128512 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128620

Files:
  clang/test/Driver/coverage-ld.c
  clang/test/Driver/instrprof-ld.c


Index: clang/test/Driver/instrprof-ld.c
===
--- clang/test/Driver/instrprof-ld.c
+++ clang/test/Driver/instrprof-ld.c
@@ -36,6 +36,15 @@
 // CHECK-FREEBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-FREEBSD-X86-64: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
 //
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-unknown-netbsd -fprofile-instr-generate 
-fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_netbsd_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-NETBSD-X86-64 %s
+
+// CHECK-NETBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-NETBSD-X86-64: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}netbsd{{/|}}libclang_rt.profile-x86_64.a"
+
 // RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-unknown-openbsd -fprofile-instr-generate 
-fuse-ld=ld \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
@@ -75,6 +84,16 @@
 // CHECK-FREEBSD-X86-64-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-FREEBSD-X86-64-SHARED: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
 //
+// RUN: %clang -### %s 2>&1 \
+// RUN: -shared \
+// RUN: --target=x86_64-unknown-netbsd -fprofile-instr-generate 
-fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_netbsd_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-NETBSD-X86-64-SHARED %s
+
+// CHECK-NETBSD-X86-64-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-NETBSD-X86-64-SHARED: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}netbsd{{/|}}libclang_rt.profile-x86_64.a"
+
 // RUN: %clang -### %s 2>&1 \
 // RUN: -shared \
 // RUN: --target=x86_64-unknown-openbsd -fprofile-instr-generate 
-fuse-ld=ld \
Index: clang/test/Driver/coverage-ld.c
===
--- clang/test/Driver/coverage-ld.c
+++ clang/test/Driver/coverage-ld.c
@@ -35,6 +35,15 @@
 // CHECK-FREEBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-FREEBSD-X86-64: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
 //
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-unknown-netbsd --coverage -fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_netbsd_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-NETBSD-X86-64 %s
+
+// CHECK-NETBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-NETBSD-X86-64: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}netbsd{{/|}}libclang_rt.profile-x86_64.a"
+
 // RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-unknown-openbsd --coverage -fuse-ld=ld \
 // RUN: -resource-dir=%S/Inputs/resource_dir \


Index: clang/test/Driver/instrprof-ld.c
===
--- clang/test/Driver/instrprof-ld.c
+++ clang/test/Driver/instrprof-ld.c
@@ -36,6 +36,15 @@
 // CHECK-FREEBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-FREEBSD-X86-64: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
 //
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-unknown-netbsd -fprofile-instr-generate -fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_netbsd_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-NETBSD-X86-64 %s
+
+// CHECK-NETBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-NETBSD-X86-64: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}netbsd{{/|}}libclang_rt.profile-x86_64.a"
+
 // RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-unknown-openbsd -fprofile-instr-generate -fuse-ld=ld \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
@@ -75,6 +84,16 @@
 // CHECK-FREEBSD-X86-64-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-FREEBSD-X86-64-SHARED: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
 //
+// RUN: %clang -### %s 2>&1 \
+// RUN: -shared \
+// RUN: --target=x86_64-unknown-netbsd -fprofile-instr-generate -fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_netbsd_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-NETBSD-X86-64-SHARED %s
+
+// CHECK-NETBSD-X86-64-SHARED: 

[PATCH] D128607: [clang-format] NFC Fix uninitialized memory problem

2022-06-26 Thread sstwcw via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG141ad3ba0571: [clang-format] Fix uninitialized memory 
problem (authored by sstwcw).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128607

Files:
  clang/lib/Format/FormatTokenLexer.cpp


Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -1128,11 +1128,12 @@
 return false;
   size_t Len = Matches[0].size();
 
-  Tok.setLength(Len);
-  Tok.setLocation(Lex->getSourceLocation(Start, Len));
   // The kind has to be an identifier so we can match it against those defined
-  // in Keywords.
+  // in Keywords. The kind has to be set before the length because the 
setLength
+  // function checks that the kind is not an annotation.
   Tok.setKind(tok::raw_identifier);
+  Tok.setLength(Len);
+  Tok.setLocation(Lex->getSourceLocation(Start, Len));
   Tok.setRawIdentifierData(Start);
   Lex->seek(Lex->getCurrentBufferOffset() + Len, /*IsAtStartofline=*/false);
   return true;


Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -1128,11 +1128,12 @@
 return false;
   size_t Len = Matches[0].size();
 
-  Tok.setLength(Len);
-  Tok.setLocation(Lex->getSourceLocation(Start, Len));
   // The kind has to be an identifier so we can match it against those defined
-  // in Keywords.
+  // in Keywords. The kind has to be set before the length because the setLength
+  // function checks that the kind is not an annotation.
   Tok.setKind(tok::raw_identifier);
+  Tok.setLength(Len);
+  Tok.setLocation(Lex->getSourceLocation(Start, Len));
   Tok.setRawIdentifierData(Start);
   Lex->seek(Lex->getCurrentBufferOffset() + Len, /*IsAtStartofline=*/false);
   return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 141ad3b - [clang-format] Fix uninitialized memory problem

2022-06-26 Thread via cfe-commits

Author: sstwcw
Date: 2022-06-26T22:23:50Z
New Revision: 141ad3ba05711cc8396a34fce6b26648d216eb8e

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

LOG: [clang-format] Fix uninitialized memory problem

The setLength function checks for the token kind which could be
uninitialized in the previous version.

The problem was introduced in 2e32ff106e.

Reviewed By: MyDeveloperDay, owenpan

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

Added: 


Modified: 
clang/lib/Format/FormatTokenLexer.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index e3af9548b015..88b0d3b1970f 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -1128,11 +1128,12 @@ bool 
FormatTokenLexer::readRawTokenVerilogSpecific(Token ) {
 return false;
   size_t Len = Matches[0].size();
 
-  Tok.setLength(Len);
-  Tok.setLocation(Lex->getSourceLocation(Start, Len));
   // The kind has to be an identifier so we can match it against those defined
-  // in Keywords.
+  // in Keywords. The kind has to be set before the length because the 
setLength
+  // function checks that the kind is not an annotation.
   Tok.setKind(tok::raw_identifier);
+  Tok.setLength(Len);
+  Tok.setLocation(Lex->getSourceLocation(Start, Len));
   Tok.setRawIdentifierData(Start);
   Lex->seek(Lex->getCurrentBufferOffset() + Len, /*IsAtStartofline=*/false);
   return true;



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


[clang] 016342e - [RISCV] Evaluate ICE operands to builtins using getIntegerConstantExpr.

2022-06-26 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2022-06-26T13:51:17-07:00
New Revision: 016342e319fd31e41cf5ed16a6140a8ea2de74dd

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

LOG: [RISCV] Evaluate ICE operands to builtins using getIntegerConstantExpr.

Some RISC-V builtins requires ICE operands. We should call
getIntegerConstantExpr instead of EmitScalarExpr to match other
targets.

This was made a little trickier by the vector intrinsics not having
a valid type string, but there are two that have ICE operands so
I specified them manually.

Added: 
clang/test/CodeGen/RISCV/rvv-intrinsics/vget-vset-ice.cpp

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 019fe4e7f0fb4..b22d1f76c1a1d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19009,8 +19009,34 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned 
BuiltinID,
   SmallVector Ops;
   llvm::Type *ResultType = ConvertType(E->getType());
 
-  for (unsigned i = 0, e = E->getNumArgs(); i != e; i++)
-Ops.push_back(EmitScalarExpr(E->getArg(i)));
+  // Find out if any arguments are required to be integer constant expressions.
+  unsigned ICEArguments = 0;
+  ASTContext::GetBuiltinTypeError Error;
+  getContext().GetBuiltinType(BuiltinID, Error, );
+  if (Error == ASTContext::GE_Missing_type) {
+// Vector intrinsics don't have a type string.
+assert(BuiltinID >= clang::RISCV::FirstRVVBuiltin &&
+   BuiltinID <= clang::RISCV::LastRVVBuiltin);
+ICEArguments = 0;
+if (BuiltinID == RISCVVector::BI__builtin_rvv_vget_v ||
+BuiltinID == RISCVVector::BI__builtin_rvv_vset_v)
+  ICEArguments = 1 << 1;
+  } else {
+assert(Error == ASTContext::GE_None && "Unexpected error");
+  }
+
+  for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) {
+// If this is a normal argument, just emit it as a scalar.
+if ((ICEArguments & (1 << i)) == 0) {
+  Ops.push_back(EmitScalarExpr(E->getArg(i)));
+  continue;
+}
+
+// If this is required to be a constant, constant fold it so that we know
+// that the generated intrinsic gets a ConstantInt.
+Ops.push_back(llvm::ConstantInt::get(
+getLLVMContext(), 
*E->getArg(i)->getIntegerConstantExpr(getContext(;
+  }
 
   Intrinsic::ID ID = Intrinsic::not_intrinsic;
   unsigned NF = 1;

diff  --git a/clang/test/CodeGen/RISCV/rvv-intrinsics/vget-vset-ice.cpp 
b/clang/test/CodeGen/RISCV/rvv-intrinsics/vget-vset-ice.cpp
new file mode 100644
index 0..bb43b4018ee2d
--- /dev/null
+++ b/clang/test/CodeGen/RISCV/rvv-intrinsics/vget-vset-ice.cpp
@@ -0,0 +1,29 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh -target-feature 
+experimental-zvfh \
+// RUN:   -disable-O0-optnone -emit-llvm %s -o - | opt -S -mem2reg | FileCheck 
--check-prefix=CHECK-RV64 %s
+
+#include 
+
+// Use constexpr function to make sure we correctly evaluate it as a constant
+// when emitting IR for the vget/vset builtins.
+constexpr int foo() { return 1; }
+
+// CHECK-RV64-LABEL: @_Z21test_vget_v_i8m2_i8m1u14__rvv_int8m2_t
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.experimental.vector.extract.nxv8i8.nxv16i8( 
[[SRC:%.*]], i64 8)
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vint8m1_t test_vget_v_i8m2_i8m1(vint8m2_t src) {
+  return vget_v_i8m2_i8m1(src, foo());
+}
+
+// CHECK-RV64-LABEL: 
@_Z21test_vset_v_i8m1_i8m2u14__rvv_int8m2_tu14__rvv_int8m1_t
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.experimental.vector.insert.nxv16i8.nxv8i8( 
[[DEST:%.*]],  [[VAL:%.*]], i64 8)
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vint8m2_t test_vset_v_i8m1_i8m2(vint8m2_t dest, vint8m1_t val) {
+  return vset_v_i8m1_i8m2(dest, foo(), val);
+}



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


[PATCH] D128512: [Driver][test] Add libclang_rt.profile{{.*}}.a tests for OpenBSD

2022-06-26 Thread Frederic Cambus 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 rG2ff4fb6573c1: [Driver][test] Add libclang_rt.profile{{.*}}.a 
tests for OpenBSD (authored by fcambus).

Changed prior to commit:
  https://reviews.llvm.org/D128512?vs=439684=440088#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128512

Files:
  clang/test/Driver/coverage-ld.c
  clang/test/Driver/instrprof-ld.c


Index: clang/test/Driver/instrprof-ld.c
===
--- clang/test/Driver/instrprof-ld.c
+++ clang/test/Driver/instrprof-ld.c
@@ -36,6 +36,15 @@
 // CHECK-FREEBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-FREEBSD-X86-64: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
 //
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-unknown-openbsd -fprofile-instr-generate 
-fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_openbsd_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-OPENBSD-X86-64 %s
+
+// CHECK-OPENBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-OPENBSD-X86-64: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}openbsd{{/|}}libclang_rt.profile-x86_64.a"
+
 // RUN: %clang -### %s 2>&1 \
 // RUN: -shared \
 // RUN: --target=i386-unknown-linux -fprofile-instr-generate -fuse-ld=ld \
@@ -66,6 +75,16 @@
 // CHECK-FREEBSD-X86-64-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-FREEBSD-X86-64-SHARED: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
 //
+// RUN: %clang -### %s 2>&1 \
+// RUN: -shared \
+// RUN: --target=x86_64-unknown-openbsd -fprofile-instr-generate 
-fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_openbsd_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-OPENBSD-X86-64-SHARED %s
+
+// CHECK-OPENBSD-X86-64-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-OPENBSD-X86-64-SHARED: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}openbsd{{/|}}libclang_rt.profile-x86_64.a"
+
 // RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-apple-darwin14 -fprofile-instr-generate 
-fuse-ld=ld \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
Index: clang/test/Driver/coverage-ld.c
===
--- clang/test/Driver/coverage-ld.c
+++ clang/test/Driver/coverage-ld.c
@@ -35,6 +35,15 @@
 // CHECK-FREEBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-FREEBSD-X86-64: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
 //
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-unknown-openbsd --coverage -fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_openbsd_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-OPENBSD-X86-64 %s
+
+// CHECK-OPENBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-OPENBSD-X86-64: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}openbsd{{/|}}libclang_rt.profile-x86_64.a"
+
 // RUN: %clang -### %s 2>&1 \
 // RUN: --target=arm-linux-androideabi --coverage -fuse-ld=ld \
 // RUN: -resource-dir=%S/Inputs/resource_dir \


Index: clang/test/Driver/instrprof-ld.c
===
--- clang/test/Driver/instrprof-ld.c
+++ clang/test/Driver/instrprof-ld.c
@@ -36,6 +36,15 @@
 // CHECK-FREEBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-FREEBSD-X86-64: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
 //
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-unknown-openbsd -fprofile-instr-generate -fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_openbsd_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-OPENBSD-X86-64 %s
+
+// CHECK-OPENBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-OPENBSD-X86-64: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}openbsd{{/|}}libclang_rt.profile-x86_64.a"
+
 // RUN: %clang -### %s 2>&1 \
 // RUN: -shared \
 // RUN: --target=i386-unknown-linux -fprofile-instr-generate -fuse-ld=ld \
@@ -66,6 +75,16 @@
 // CHECK-FREEBSD-X86-64-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-FREEBSD-X86-64-SHARED: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
 //
+// RUN: %clang -### %s 2>&1 \
+// RUN: -shared \
+// RUN: --target=x86_64-unknown-openbsd -fprofile-instr-generate -fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_openbsd_tree \
+// RUN:   | FileCheck 

[clang] 2ff4fb6 - [Driver][test] Add libclang_rt.profile{{.*}}.a tests for OpenBSD

2022-06-26 Thread Frederic Cambus via cfe-commits

Author: Frederic Cambus
Date: 2022-06-26T22:18:13+02:00
New Revision: 2ff4fb6573c111265a9d4d445f5cf43b659e71eb

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

LOG: [Driver][test] Add libclang_rt.profile{{.*}}.a tests for OpenBSD

This was requested in D109244.

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

Added: 


Modified: 
clang/test/Driver/coverage-ld.c
clang/test/Driver/instrprof-ld.c

Removed: 




diff  --git a/clang/test/Driver/coverage-ld.c b/clang/test/Driver/coverage-ld.c
index 7d6a48be8b085..edfe272fbb525 100644
--- a/clang/test/Driver/coverage-ld.c
+++ b/clang/test/Driver/coverage-ld.c
@@ -35,6 +35,15 @@
 // CHECK-FREEBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-FREEBSD-X86-64: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
 //
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-unknown-openbsd --coverage -fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_openbsd_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-OPENBSD-X86-64 %s
+
+// CHECK-OPENBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-OPENBSD-X86-64: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}openbsd{{/|}}libclang_rt.profile-x86_64.a"
+
 // RUN: %clang -### %s 2>&1 \
 // RUN: --target=arm-linux-androideabi --coverage -fuse-ld=ld \
 // RUN: -resource-dir=%S/Inputs/resource_dir \

diff  --git a/clang/test/Driver/instrprof-ld.c 
b/clang/test/Driver/instrprof-ld.c
index d1b070ed59c3f..fefc648d610e2 100644
--- a/clang/test/Driver/instrprof-ld.c
+++ b/clang/test/Driver/instrprof-ld.c
@@ -36,6 +36,15 @@
 // CHECK-FREEBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-FREEBSD-X86-64: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
 //
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-unknown-openbsd -fprofile-instr-generate 
-fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_openbsd_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-OPENBSD-X86-64 %s
+
+// CHECK-OPENBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-OPENBSD-X86-64: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}openbsd{{/|}}libclang_rt.profile-x86_64.a"
+
 // RUN: %clang -### %s 2>&1 \
 // RUN: -shared \
 // RUN: --target=i386-unknown-linux -fprofile-instr-generate -fuse-ld=ld \
@@ -66,6 +75,16 @@
 // CHECK-FREEBSD-X86-64-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-FREEBSD-X86-64-SHARED: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
 //
+// RUN: %clang -### %s 2>&1 \
+// RUN: -shared \
+// RUN: --target=x86_64-unknown-openbsd -fprofile-instr-generate 
-fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_openbsd_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-OPENBSD-X86-64-SHARED %s
+
+// CHECK-OPENBSD-X86-64-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-OPENBSD-X86-64-SHARED: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}openbsd{{/|}}libclang_rt.profile-x86_64.a"
+
 // RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-apple-darwin14 -fprofile-instr-generate 
-fuse-ld=ld \
 // RUN: -resource-dir=%S/Inputs/resource_dir \



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


[PATCH] D128574: [clang-format] Quit analyzing solution space for large state count

2022-06-26 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG664ce34e81d9: [clang-format] Quit analyzing solution space 
for large state count (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128574

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1163,6 +1163,10 @@
 
 // While not empty, take first element and follow edges.
 while (!Queue.empty()) {
+  // Quit if we still haven't found a solution by now.
+  if (Count > 2500)
+return 0;
+
   Penalty = Queue.top().first.first;
   StateNode *Node = Queue.top().second;
   if (!Node->State.NextToken) {


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1163,6 +1163,10 @@
 
 // While not empty, take first element and follow edges.
 while (!Queue.empty()) {
+  // Quit if we still haven't found a solution by now.
+  if (Count > 2500)
+return 0;
+
   Penalty = Queue.top().first.first;
   StateNode *Node = Queue.top().second;
   if (!Node->State.NextToken) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 664ce34 - [clang-format] Quit analyzing solution space for large state count

2022-06-26 Thread via cfe-commits

Author: owenca
Date: 2022-06-26T13:15:07-07:00
New Revision: 664ce34e81d98af7859754f127b28030b45c8893

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

LOG: [clang-format] Quit analyzing solution space for large state count

Fixes #56043.

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineFormatter.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index b8a535b8d527f..22509a5042465 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1163,6 +1163,10 @@ class OptimizingLineFormatter : public LineFormatter {
 
 // While not empty, take first element and follow edges.
 while (!Queue.empty()) {
+  // Quit if we still haven't found a solution by now.
+  if (Count > 2500)
+return 0;
+
   Penalty = Queue.top().first.first;
   StateNode *Node = Queue.top().second;
   if (!Node->State.NextToken) {



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


[PATCH] D128613: Add explicit index type for llvm.vector.extract

2022-06-26 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Can we just add the missing zext to the RISC-V vget implementation?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128613

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


[PATCH] D128607: [clang-format] NFC Fix uninitialized memory problem

2022-06-26 Thread Owen Pan via Phabricator via cfe-commits
owenpan accepted this revision.
owenpan added a comment.

Can you remove NFC? IMO, fixing a memory error is not NFC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128607

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


[PATCH] D109051: Use Component in OpenBSD::getCompilerRT to find libraries

2022-06-26 Thread Frederic Cambus 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 rG3caa32b26f5a: [Driver] Use Component in 
OpenBSD::getCompilerRT to find libraries (authored by blackgnezdo, committed by 
fcambus).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109051

Files:
  clang/lib/Driver/ToolChains/OpenBSD.cpp


Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -17,6 +17,7 @@
 #include "clang/Driver/SanitizerArgs.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/VirtualFileSystem.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -334,12 +335,21 @@
   CmdArgs.push_back(Profiling ? "-lpthread_p" : "-lpthread");
 }
 
-std::string OpenBSD::getCompilerRT(const ArgList ,
-   StringRef Component,
+std::string OpenBSD::getCompilerRT(const ArgList , StringRef Component,
FileType Type) const {
-  SmallString<128> Path(getDriver().SysRoot);
-  llvm::sys::path::append(Path, "/usr/lib/libcompiler_rt.a");
-  return std::string(Path.str());
+  if (Component == "builtins") {
+SmallString<128> Path(getDriver().SysRoot);
+llvm::sys::path::append(Path, "/usr/lib/libcompiler_rt.a");
+return std::string(Path.str());
+  }
+  SmallString<128> P(getDriver().ResourceDir);
+  std::string CRTBasename =
+  buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
+  llvm::sys::path::append(P, "lib", CRTBasename);
+  // Checks if this is the base system case which uses a different location.
+  if (getVFS().exists(P))
+return std::string(P.str());
+  return ToolChain::getCompilerRT(Args, Component, Type);
 }
 
 Tool *OpenBSD::buildAssembler() const {


Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -17,6 +17,7 @@
 #include "clang/Driver/SanitizerArgs.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/VirtualFileSystem.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -334,12 +335,21 @@
   CmdArgs.push_back(Profiling ? "-lpthread_p" : "-lpthread");
 }
 
-std::string OpenBSD::getCompilerRT(const ArgList ,
-   StringRef Component,
+std::string OpenBSD::getCompilerRT(const ArgList , StringRef Component,
FileType Type) const {
-  SmallString<128> Path(getDriver().SysRoot);
-  llvm::sys::path::append(Path, "/usr/lib/libcompiler_rt.a");
-  return std::string(Path.str());
+  if (Component == "builtins") {
+SmallString<128> Path(getDriver().SysRoot);
+llvm::sys::path::append(Path, "/usr/lib/libcompiler_rt.a");
+return std::string(Path.str());
+  }
+  SmallString<128> P(getDriver().ResourceDir);
+  std::string CRTBasename =
+  buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
+  llvm::sys::path::append(P, "lib", CRTBasename);
+  // Checks if this is the base system case which uses a different location.
+  if (getVFS().exists(P))
+return std::string(P.str());
+  return ToolChain::getCompilerRT(Args, Component, Type);
 }
 
 Tool *OpenBSD::buildAssembler() const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3caa32b - [Driver] Use Component in OpenBSD::getCompilerRT to find libraries

2022-06-26 Thread Frederic Cambus via cfe-commits

Author: Greg Steuck
Date: 2022-06-26T21:05:39+02:00
New Revision: 3caa32b26f5a1d4f2e3c9c3f1540a30fe06abe38

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

LOG: [Driver] Use Component in OpenBSD::getCompilerRT to find libraries

Clang uses runtime libraries for some advanced features like
sanitizers. Different systems have different preferences about file
placement. OpenBSD with this change will use this name for ASan:
/usr/lib/clang/15.0.0/lib/libclang_rt.asan.a

Already committed to OpenBSD repository then amended to cover the
case of development tree.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/OpenBSD.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp 
b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index 62c430b66e5f7..54cf3cc89caf7 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -17,6 +17,7 @@
 #include "clang/Driver/SanitizerArgs.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/VirtualFileSystem.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -334,12 +335,21 @@ void OpenBSD::AddCXXStdlibLibArgs(const ArgList ,
   CmdArgs.push_back(Profiling ? "-lpthread_p" : "-lpthread");
 }
 
-std::string OpenBSD::getCompilerRT(const ArgList ,
-   StringRef Component,
+std::string OpenBSD::getCompilerRT(const ArgList , StringRef Component,
FileType Type) const {
-  SmallString<128> Path(getDriver().SysRoot);
-  llvm::sys::path::append(Path, "/usr/lib/libcompiler_rt.a");
-  return std::string(Path.str());
+  if (Component == "builtins") {
+SmallString<128> Path(getDriver().SysRoot);
+llvm::sys::path::append(Path, "/usr/lib/libcompiler_rt.a");
+return std::string(Path.str());
+  }
+  SmallString<128> P(getDriver().ResourceDir);
+  std::string CRTBasename =
+  buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
+  llvm::sys::path::append(P, "lib", CRTBasename);
+  // Checks if this is the base system case which uses a 
diff erent location.
+  if (getVFS().exists(P))
+return std::string(P.str());
+  return ToolChain::getCompilerRT(Args, Component, Type);
 }
 
 Tool *OpenBSD::buildAssembler() const {



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


[PATCH] D128612: RISC-V big-endian support implementation

2022-06-26 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Basic/Targets/RISCV.h:111
 SizeType = UnsignedInt;
-resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
   }

Instead of creating new classes, could we have a branch on the Arch or 
isLittleEndian portion of the triple to decide what to pass to resetDataLayout? 
That's what PPC32TargetInfo does for example.



Comment at: lld/ELF/Arch/RISCV.cpp:160
+  if (config->is64) {
+if (config->isLE)
+  write64le(buf, mainPart->dynamic->getVA());

Is it possible to use write64 instead of write64le/be? It looks like it checks 
the endianness internally.



Comment at: llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp:628
+  // For big endian cores, data fixup should be swapped.
+  bool swapValue = (Endian == support::big) && isDataFixup(Kind);
   for (unsigned i = 0; i != NumBytes; ++i) {

Capitalize `swapValue`



Comment at: llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h:34
   const MCTargetOptions )
-  : MCAsmBackend(support::little), STI(STI), OSABI(OSABI), 
Is64Bit(Is64Bit),
+  : MCAsmBackend(IsLittleEndian ? support::little : support::big), 
STI(STI), OSABI(OSABI), Is64Bit(Is64Bit),
 TargetOptions(Options) {

Is this longer than 80 columns?



Comment at: llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp:24
+  if (TT.getArch() == Triple::riscv32be || TT.getArch() == Triple::riscv64be)
+IsLittleEndian = false;
+

Could we do IsLittleEndian = TT.isLittleEndian()?



Comment at: llvm/lib/Target/RISCV/RISCVTargetMachine.cpp:64
+  return "e-m:e-p:64:64-i64:64-i128:128-n64-S128";
+else
+  return "E-m:e-p:64:64-i64:64-i128:128-n64-S128";

No else after return


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128612

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


[PATCH] D116280: [clang] adds unary type trait checks as compiler built-ins

2022-06-26 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 440079.
cjdb added a comment.

rebases


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116280

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/type-traits.cpp

Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -345,11 +345,19 @@
 }
 
 typedef Enum EnumType;
+typedef EnumClass EnumClassType;
 
 void is_enum()
 {
   { int arr[T(__is_enum(Enum))]; }
   { int arr[T(__is_enum(EnumType))]; }
+  { int arr[T(__is_enum(SignedEnum))]; }
+  { int arr[T(__is_enum(UnsignedEnum))]; }
+
+  { int arr[T(__is_enum(EnumClass))]; }
+  { int arr[T(__is_enum(EnumClassType))]; }
+  { int arr[T(__is_enum(SignedEnumClass))]; }
+  { int arr[T(__is_enum(UnsignedEnumClass))]; }
 
   { int arr[F(__is_enum(int))]; }
   { int arr[F(__is_enum(Union))]; }
@@ -363,6 +371,29 @@
   { int arr[F(__is_enum(HasAnonymousUnion))]; }
 }
 
+void is_scoped_enum() {
+  { int arr[F(__is_scoped_enum(Enum))]; }
+  { int arr[F(__is_scoped_enum(EnumType))]; }
+  { int arr[F(__is_scoped_enum(SignedEnum))]; }
+  { int arr[F(__is_scoped_enum(UnsignedEnum))]; }
+
+  { int arr[T(__is_scoped_enum(EnumClass))]; }
+  { int arr[T(__is_scoped_enum(EnumClassType))]; }
+  { int arr[T(__is_scoped_enum(SignedEnumClass))]; }
+  { int arr[T(__is_scoped_enum(UnsignedEnumClass))]; }
+
+  { int arr[F(__is_scoped_enum(int))]; }
+  { int arr[F(__is_scoped_enum(Union))]; }
+  { int arr[F(__is_scoped_enum(Int))]; }
+  { int arr[F(__is_scoped_enum(IntAr))]; }
+  { int arr[F(__is_scoped_enum(UnionAr))]; }
+  { int arr[F(__is_scoped_enum(Derives))]; }
+  { int arr[F(__is_scoped_enum(ClassType))]; }
+  { int arr[F(__is_scoped_enum(cvoid))]; }
+  { int arr[F(__is_scoped_enum(IntArNB))]; }
+  { int arr[F(__is_scoped_enum(HasAnonymousUnion))]; }
+}
+
 struct FinalClass final {
 };
 
@@ -702,6 +733,106 @@
   int t31[F(__is_array(cvoid*))];
 }
 
+void is_bounded_array(int n) {
+  int t01[T(__is_bounded_array(IntAr))];
+  int t02[F(__is_bounded_array(IntArNB))];
+  int t03[T(__is_bounded_array(UnionAr))];
+
+  int t10[F(__is_bounded_array(void))];
+  int t11[F(__is_bounded_array(cvoid))];
+  int t12[F(__is_bounded_array(float))];
+  int t13[F(__is_bounded_array(double))];
+  int t14[F(__is_bounded_array(long double))];
+  int t15[F(__is_bounded_array(bool))];
+  int t16[F(__is_bounded_array(char))];
+  int t17[F(__is_bounded_array(signed char))];
+  int t18[F(__is_bounded_array(unsigned char))];
+  int t19[F(__is_bounded_array(wchar_t))];
+  int t20[F(__is_bounded_array(short))];
+  int t21[F(__is_bounded_array(unsigned short))];
+  int t22[F(__is_bounded_array(int))];
+  int t23[F(__is_bounded_array(unsigned int))];
+  int t24[F(__is_bounded_array(long))];
+  int t25[F(__is_bounded_array(unsigned long))];
+  int t26[F(__is_bounded_array(Union))];
+  int t27[F(__is_bounded_array(Derives))];
+  int t28[F(__is_bounded_array(ClassType))];
+  int t29[F(__is_bounded_array(Enum))];
+  int t30[F(__is_bounded_array(void *))];
+  int t31[F(__is_bounded_array(cvoid *))];
+
+  int t32[n];
+  (void)__is_bounded_array(decltype(t32)); // expected-error{{variable length arrays are not supported for '__is_bounded_array'}}
+}
+
+void is_unbounded_array(int n) {
+  int t01[F(__is_unbounded_array(IntAr))];
+  int t02[T(__is_unbounded_array(IntArNB))];
+  int t03[F(__is_unbounded_array(UnionAr))];
+
+  int t10[F(__is_unbounded_array(void))];
+  int t11[F(__is_unbounded_array(cvoid))];
+  int t12[F(__is_unbounded_array(float))];
+  int t13[F(__is_unbounded_array(double))];
+  int t14[F(__is_unbounded_array(long double))];
+  int t15[F(__is_unbounded_array(bool))];
+  int t16[F(__is_unbounded_array(char))];
+  int t17[F(__is_unbounded_array(signed char))];
+  int t18[F(__is_unbounded_array(unsigned char))];
+  int t19[F(__is_unbounded_array(wchar_t))];
+  int t20[F(__is_unbounded_array(short))];
+  int t21[F(__is_unbounded_array(unsigned short))];
+  int t22[F(__is_unbounded_array(int))];
+  int t23[F(__is_unbounded_array(unsigned int))];
+  int t24[F(__is_unbounded_array(long))];
+  int t25[F(__is_unbounded_array(unsigned long))];
+  int t26[F(__is_unbounded_array(Union))];
+  int t27[F(__is_unbounded_array(Derives))];
+  int t28[F(__is_unbounded_array(ClassType))];
+  int t29[F(__is_unbounded_array(Enum))];
+  int t30[F(__is_unbounded_array(void *))];
+  int t31[F(__is_unbounded_array(cvoid *))];
+
+  int t32[n];
+  (void)__is_unbounded_array(decltype(t32)); // expected-error{{variable length arrays are not supported for '__is_unbounded_array'}}
+}
+
+void is_referenceable() {
+  { int a[T(__is_referenceable(int))]; 

[PATCH] D103313: [RISCV][Clang] Add support for Zmmul extension

2022-06-26 Thread ksyx via Phabricator via cfe-commits
ksyx updated this revision to Diff 440075.
ksyx marked an inline comment as done.
ksyx added a comment.

Make Zmmul extension independent instead of implied by M extension for backward 
ELF attribute compatibility.


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

https://reviews.llvm.org/D103313

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfoM.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/CodeGen/RISCV/zmmul.ll
  llvm/test/MC/RISCV/rv32i-invalid.s
  llvm/test/MC/RISCV/rv32zmmul-invaild.s
  llvm/test/MC/RISCV/rv32zmmul-valid.s
  llvm/test/MC/RISCV/rv64zmmul-invalid.s
  llvm/test/MC/RISCV/rv64zmmul-valid.s

Index: llvm/test/MC/RISCV/rv64zmmul-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zmmul-valid.s
@@ -0,0 +1,5 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+zmmul -riscv-no-aliases 2>&1 \
+# RUN:  | FileCheck -check-prefixes=CHECK-INST %s
+
+# CHECK-INST: mulw ra, sp, gp
+mulw ra, sp, gp
Index: llvm/test/MC/RISCV/rv64zmmul-invalid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zmmul-invalid.s
@@ -0,0 +1,14 @@
+# RUN: not llvm-mc %s -triple=riscv64 -mattr=+zmmul -riscv-no-aliases 2>&1 \
+# RUN:  | FileCheck -check-prefixes=CHECK-ERROR %s
+
+# CHECK-ERROR: 5:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+divw tp, t0, t1
+
+# CHECK-ERROR: 8:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+divuw t2, s0, s2
+
+# CHECK-ERROR: 11:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+remw a0, a1, a2
+
+# CHECK-ERROR: 14:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+remuw a3, a4, a5
Index: llvm/test/MC/RISCV/rv32zmmul-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zmmul-valid.s
@@ -0,0 +1,14 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+zmmul -riscv-no-aliases 2>&1 \
+# RUN:  | FileCheck -check-prefixes=CHECK-INST %s
+
+# CHECK-INST: mul a4, ra, s0
+mul a4, ra, s0
+
+# CHECK-INST: mulh ra, zero, zero
+mulh x1, x0, x0
+
+# CHECK-INST: mulhsu t0, t2, t1
+mulhsu t0, t2, t1
+
+# CHECK-INST: mulhu a5, a4, a3
+mulhu a5, a4, a3
Index: llvm/test/MC/RISCV/rv32zmmul-invaild.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zmmul-invaild.s
@@ -0,0 +1,14 @@
+# RUN: not llvm-mc %s -triple=riscv32 -mattr=+zmmul -riscv-no-aliases 2>&1 \
+# RUN:  | FileCheck -check-prefixes=CHECK-ERROR %s
+
+# CHECK-ERROR: 5:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+div s0, s0, s0
+
+# CHECK-ERROR: 8:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+divu gp, a0, a1
+
+# CHECK-ERROR: 11:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+rem s2, s2, s8
+
+# CHECK-ERROR: 14:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+remu x18, x18, x24
Index: llvm/test/MC/RISCV/rv32i-invalid.s
===
--- llvm/test/MC/RISCV/rv32i-invalid.s
+++ llvm/test/MC/RISCV/rv32i-invalid.s
@@ -169,7 +169,7 @@
 xor s2, s2 # CHECK: :[[@LINE]]:1: error: too few operands for instruction
 
 # Instruction not in the base ISA
-mul a4, ra, s0 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
+div a4, ra, s0 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'M' (Integer Multiplication and Division)
 amomaxu.w s5, s4, (s3) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'A' (Atomic Instructions)
 fadd.s ft0, ft1, ft2 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'F' (Single-Precision Floating-Point){{$}}
 fadd.h ft0, ft1, ft2 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point)
Index: llvm/test/CodeGen/RISCV/zmmul.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/zmmul.ll
@@ -0,0 +1,41 @@
+; RUN: llc -mtriple=riscv32 -mattr=+zmmul -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-DIV %s
+; RUN: llc -mtriple=riscv64 -mattr=+zmmul -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-DIV %s
+; RUN: llc -mtriple=riscv32 -mattr=+zmmul -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-REM %s
+; RUN: llc -mtriple=riscv64 -mattr=+zmmul -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-REM %s
+

[PATCH] D128402: [clang-tidy] Don't treat invalid branches as identical

2022-06-26 Thread Ishaan Gandhi via Phabricator via cfe-commits
ishaangandhi updated this revision to Diff 440071.

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

https://reviews.llvm.org/D128402

Files:
  clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-unknown-expr.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-unknown-expr.cpp
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-unknown-expr.cpp
@@ -0,0 +1,9 @@
+// RUN: %check_clang_tidy -fix-errors %s bugprone-branch-clone %t
+
+int test_unknown_expression() {
+  if (unknown_expression_1) {// CHECK-MESSAGES: :[[@LINE]]:7: error: 
use of undeclared identifier 'unknown_expression_1' [clang-diagnostic-error]
+function1(unknown_expression_2); // CHECK-MESSAGES: :[[@LINE]]:15: error: 
use of undeclared identifier 'unknown_expression_2' [clang-diagnostic-error]
+  } else {
+function2(unknown_expression_3); // CHECK-MESSAGES: :[[@LINE]]:15: error: 
use of undeclared identifier 'unknown_expression_3' [clang-diagnostic-error]
+  }
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -158,6 +158,10 @@
 - Fixed nonsensical suggestion of :doc:`altera-struct-pack-align
   ` check for empty structs.
 
+- Fixed a false positive in :doc:`bugprone-branch-clone
+  ` when the branches
+  involve unknown expressions.
+
 - Fixed some false positives in :doc:`bugprone-infinite-loop
   ` involving dependent expressions.
 
Index: clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
@@ -19,6 +19,17 @@
 /// Returns true when the statements are Type I clones of each other.
 static bool areStatementsIdentical(const Stmt *LHS, const Stmt *RHS,
const ASTContext ) {
+  if (isa(LHS) && isa(RHS)) {
+// If we have errors in expressions, we will be unable
+// to accurately profile and compute hashes for each
+// of the left and right statements.
+const auto *LHSExpr = llvm::cast(LHS);
+const auto *RHSExpr = llvm::cast(RHS);
+if (LHSExpr->containsErrors() && RHSExpr->containsErrors()) {
+  return false;
+}
+  }
+
   llvm::FoldingSetNodeID DataLHS, DataRHS;
   LHS->Profile(DataLHS, Context, false);
   RHS->Profile(DataRHS, Context, false);


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-unknown-expr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-unknown-expr.cpp
@@ -0,0 +1,9 @@
+// RUN: %check_clang_tidy -fix-errors %s bugprone-branch-clone %t
+
+int test_unknown_expression() {
+  if (unknown_expression_1) {// CHECK-MESSAGES: :[[@LINE]]:7: error: use of undeclared identifier 'unknown_expression_1' [clang-diagnostic-error]
+function1(unknown_expression_2); // CHECK-MESSAGES: :[[@LINE]]:15: error: use of undeclared identifier 'unknown_expression_2' [clang-diagnostic-error]
+  } else {
+function2(unknown_expression_3); // CHECK-MESSAGES: :[[@LINE]]:15: error: use of undeclared identifier 'unknown_expression_3' [clang-diagnostic-error]
+  }
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -158,6 +158,10 @@
 - Fixed nonsensical suggestion of :doc:`altera-struct-pack-align
   ` check for empty structs.
 
+- Fixed a false positive in :doc:`bugprone-branch-clone
+  ` when the branches
+  involve unknown expressions.
+
 - Fixed some false positives in :doc:`bugprone-infinite-loop
   ` involving dependent expressions.
 
Index: clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
@@ -19,6 +19,17 @@
 /// Returns true when the statements are Type I clones of each other.
 static bool areStatementsIdentical(const Stmt *LHS, const Stmt *RHS,
const ASTContext ) {
+  if (isa(LHS) && isa(RHS)) {
+// If we have errors in expressions, we will be unable
+// to accurately profile and compute hashes for each
+// of the left and right statements.
+const auto *LHSExpr = llvm::cast(LHS);
+const auto *RHSExpr = llvm::cast(RHS);
+if (LHSExpr->containsErrors() && RHSExpr->containsErrors()) {
+  return false;
+}
+  }

[PATCH] D128613: Add explicit index type for llvm.vector.extract

2022-06-26 Thread Liao Chunyu via Phabricator via cfe-commits
liaolucy added a comment.

The patch : fix crash for rv32 vget intrinsics


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128613

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


[PATCH] D128613: Add explicit index type for llvm.vector.extract

2022-06-26 Thread Liao Chunyu via Phabricator via cfe-commits
liaolucy created this revision.
liaolucy added reviewers: craig.topper, joechrisellis, khchen.
Herald added subscribers: StephenFan, frasercrmck, luismarques, apazos, 
sameer.abuasal, s.egerton, Jim, jocewei, PkmX, arphaman, the_o, brucehoult, 
MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, 
simoncook, johnrusso, rbar, asb.
Herald added a project: All.
liaolucy requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, jdoerfert, 
MaskRay.
Herald added projects: clang, LLVM.

Without this patch, we get:  llvm.experimental.vector.extract.nxv.nxv

Whereas with the patch we get:
RV32, the intrinsic name is: llvm.experimental.vector.extract.nxv.nxv.i32
RV64, the intrinsic name is: llvm.experimental.vector.extract.nxv.nxv.i64


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128613

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vget.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vlmul.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vget.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vlmul.c
  clang/test/CodeGen/aarch64-sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c
  clang/test/CodeGen/aarch64-sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp
  clang/test/CodeGen/aarch64-sve-vls-arith-ops.c
  clang/test/CodeGen/aarch64-sve-vls-bitwise-ops.c
  clang/test/CodeGen/aarch64-sve-vls-compare-ops.c
  clang/test/CodeGen/aarch64-sve-vls-shift-ops.c
  clang/test/CodeGen/aarch64-sve-vls-subscript-ops.c
  
clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_get_neonq.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-bitcast.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-codegen.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/test/Analysis/CostModel/AArch64/sve-intrinsics.ll
  llvm/test/Analysis/CostModel/RISCV/rvv-shuffle.ll
  llvm/test/Transforms/InstCombine/canonicalize-vector-extract.ll
  llvm/test/Transforms/InstSimplify/extract-vector.ll
  llvm/test/Transforms/InstSimplify/insert-vector.ll
  llvm/test/Transforms/InterleavedAccess/AArch64/sve-interleaved-accesses.ll

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


[PATCH] D128612: RISC-V big-endian support implementation

2022-06-26 Thread Guy Benyei via Phabricator via cfe-commits
gbenyei created this revision.
gbenyei added a reviewer: asb.
gbenyei added projects: clang, LLVM, lld.
Herald added subscribers: Enna1, sunshaoce, VincentWu, luke957, StephenFan, 
vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, ormris, 
jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, 
zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, 
rbar, hiraditya, arichardson, mgorny, emaste.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a reviewer: rupprecht.
Herald added a reviewer: jhenderson.
Herald added a reviewer: MaskRay.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
gbenyei requested review of this revision.
Herald added subscribers: lldb-commits, cfe-commits, pcwang-thead.
Herald added a project: LLDB.

Implement riscv32be and riscv64be targets.
The RISC-V big- and bi-endian targets are discussed in the RISC-V spec  Version 
20191213, but some aspects, like ABI are still unclear.
The instruction encoding is little endian in both big- and little-endian modes. 
ISA spec Volume 1 1.15: "Instructions are stored in memory as a sequence
of 16-bit little-endian parcels, regardless of memory system endianness".

RISC-V Big-endian cores are already supported by GCC. Where spec is unclear, we 
aim to be compatible with GCC.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128612

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  lld/ELF/Arch/RISCV.cpp
  lld/ELF/InputFiles.cpp
  lldb/source/Utility/ArchSpec.cpp
  llvm/cmake/config-ix.cmake
  llvm/cmake/config.guess
  llvm/include/llvm/ADT/Triple.h
  llvm/include/llvm/Object/ELFObjectFile.h
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/ExecutionEngine/JITLink/ELF.cpp
  llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
  llvm/lib/ExecutionEngine/Orc/EPCIndirectionUtils.cpp
  llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp
  llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp
  llvm/lib/Object/RelocationResolver.cpp
  llvm/lib/Support/Triple.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.cpp
  llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
  llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
  llvm/lib/Target/RISCV/TargetInfo/RISCVTargetInfo.cpp
  llvm/lib/Target/RISCV/TargetInfo/RISCVTargetInfo.h
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
  llvm/unittests/Object/ELFObjectFileTest.cpp

Index: llvm/unittests/Object/ELFObjectFileTest.cpp
===
--- llvm/unittests/Object/ELFObjectFileTest.cpp
+++ llvm/unittests/Object/ELFObjectFileTest.cpp
@@ -186,10 +186,10 @@
 }
 
 TEST(ELFObjectFileTest, MachineTestForRISCV) {
-  std::array Formats = {"elf32-littleriscv", "elf32-littleriscv",
-  "elf64-littleriscv", "elf64-littleriscv"};
-  std::array Archs = {Triple::riscv32, Triple::riscv32,
-   Triple::riscv64, Triple::riscv64};
+  std::array Formats = {"elf32-littleriscv", "elf32-bigriscv",
+  "elf64-littleriscv", "elf64-bigriscv"};
+  std::array Archs = {Triple::riscv32, Triple::riscv32be,
+   Triple::riscv64, Triple::riscv64be};
   size_t I = 0;
   for (const DataForTest  : generateData(ELF::EM_RISCV)) {
 checkFormatAndArch(D, Formats[I], Archs[I]);
Index: llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
===
--- llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -301,6 +301,8 @@
 // RISC-V
 {"elf32-littleriscv", {ELF::EM_RISCV, false, true}},
 {"elf64-littleriscv", {ELF::EM_RISCV, true, true}},
+{"elf32-bigriscv", {ELF::EM_RISCV, false, false}},
+{"elf64-bigriscv", {ELF::EM_RISCV, true, false}},
 // PowerPC
 {"elf32-powerpc", {ELF::EM_PPC, false, false}},
 {"elf32-powerpcle", {ELF::EM_PPC, 

[PATCH] D127873: [clang-format] Fix misplacement of `*` in declaration of pointer to struct

2022-06-26 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D127873

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


[PATCH] D108469: Improve handling of static assert messages.

2022-06-26 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 440064.
cor3ntin added a comment.

Formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108469

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Diagnostic.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
  clang/test/C/drs/dr0xx.c
  clang/test/CXX/dcl.dcl/p4-0x.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp
  clang/test/Lexer/null-character-in-literal.c
  clang/test/Misc/diag-special-chars.c
  clang/test/Misc/wrong-encoding.c
  clang/test/PCH/cxx-static_assert.cpp
  clang/test/Sema/static-assert.c
  clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp
  clang/test/SemaCXX/static-assert.cpp
  llvm/include/llvm/Support/Unicode.h
  llvm/lib/Support/Unicode.cpp

Index: llvm/lib/Support/Unicode.cpp
===
--- llvm/lib/Support/Unicode.cpp
+++ llvm/lib/Support/Unicode.cpp
@@ -19,197 +19,271 @@
 namespace sys {
 namespace unicode {
 
+/// Unicode code points of the categories L, M, N, P, S and Zs are considered
+/// printable.
+/// In addition, U+00AD SOFT HYPHEN is also considered printable, as
+/// it's actually displayed on most terminals. \return true if the character is
+/// considered printable.
 bool isPrintable(int UCS) {
-  // Sorted list of non-overlapping intervals of code points that are not
-  // supposed to be printable.
-  static const UnicodeCharRange NonPrintableRanges[] = {
-{ 0x, 0x001F }, { 0x007F, 0x009F }, { 0x034F, 0x034F },
-{ 0x0378, 0x0379 }, { 0x037F, 0x0383 }, { 0x038B, 0x038B },
-{ 0x038D, 0x038D }, { 0x03A2, 0x03A2 }, { 0x0528, 0x0530 },
-{ 0x0557, 0x0558 }, { 0x0560, 0x0560 }, { 0x0588, 0x0588 },
-{ 0x058B, 0x058E }, { 0x0590, 0x0590 }, { 0x05C8, 0x05CF },
-{ 0x05EB, 0x05EF }, { 0x05F5, 0x0605 }, { 0x061C, 0x061D },
-{ 0x06DD, 0x06DD }, { 0x070E, 0x070F }, { 0x074B, 0x074C },
-{ 0x07B2, 0x07BF }, { 0x07FB, 0x07FF }, { 0x082E, 0x082F },
-{ 0x083F, 0x083F }, { 0x085C, 0x085D }, { 0x085F, 0x089F },
-{ 0x08A1, 0x08A1 }, { 0x08AD, 0x08E3 }, { 0x08FF, 0x08FF },
-{ 0x0978, 0x0978 }, { 0x0980, 0x0980 }, { 0x0984, 0x0984 },
-{ 0x098D, 0x098E }, { 0x0991, 0x0992 }, { 0x09A9, 0x09A9 },
-{ 0x09B1, 0x09B1 }, { 0x09B3, 0x09B5 }, { 0x09BA, 0x09BB },
-{ 0x09C5, 0x09C6 }, { 0x09C9, 0x09CA }, { 0x09CF, 0x09D6 },
-{ 0x09D8, 0x09DB }, { 0x09DE, 0x09DE }, { 0x09E4, 0x09E5 },
-{ 0x09FC, 0x0A00 }, { 0x0A04, 0x0A04 }, { 0x0A0B, 0x0A0E },
-{ 0x0A11, 0x0A12 }, { 0x0A29, 0x0A29 }, { 0x0A31, 0x0A31 },
-{ 0x0A34, 0x0A34 }, { 0x0A37, 0x0A37 }, { 0x0A3A, 0x0A3B },
-{ 0x0A3D, 0x0A3D }, { 0x0A43, 0x0A46 }, { 0x0A49, 0x0A4A },
-{ 0x0A4E, 0x0A50 }, { 0x0A52, 0x0A58 }, { 0x0A5D, 0x0A5D },
-{ 0x0A5F, 0x0A65 }, { 0x0A76, 0x0A80 }, { 0x0A84, 0x0A84 },
-{ 0x0A8E, 0x0A8E }, { 0x0A92, 0x0A92 }, { 0x0AA9, 0x0AA9 },
-{ 0x0AB1, 0x0AB1 }, { 0x0AB4, 0x0AB4 }, { 0x0ABA, 0x0ABB },
-{ 0x0AC6, 0x0AC6 }, { 0x0ACA, 0x0ACA }, { 0x0ACE, 0x0ACF },
-{ 0x0AD1, 0x0ADF }, { 0x0AE4, 0x0AE5 }, { 0x0AF2, 0x0B00 },
-{ 0x0B04, 0x0B04 }, { 0x0B0D, 0x0B0E }, { 0x0B11, 0x0B12 },
-{ 0x0B29, 0x0B29 }, { 0x0B31, 0x0B31 }, { 0x0B34, 0x0B34 },
-{ 0x0B3A, 0x0B3B }, { 0x0B45, 0x0B46 }, { 0x0B49, 0x0B4A },
-{ 0x0B4E, 0x0B55 }, { 0x0B58, 0x0B5B }, { 0x0B5E, 0x0B5E },
-{ 0x0B64, 0x0B65 }, { 0x0B78, 0x0B81 }, { 0x0B84, 0x0B84 },
-{ 0x0B8B, 0x0B8D }, { 0x0B91, 0x0B91 }, { 0x0B96, 0x0B98 },
-{ 0x0B9B, 0x0B9B }, { 0x0B9D, 0x0B9D }, { 0x0BA0, 0x0BA2 },
-{ 0x0BA5, 0x0BA7 }, { 0x0BAB, 0x0BAD }, { 0x0BBA, 0x0BBD },
-{ 0x0BC3, 0x0BC5 }, { 0x0BC9, 0x0BC9 }, { 0x0BCE, 0x0BCF },
-{ 0x0BD1, 0x0BD6 }, { 0x0BD8, 0x0BE5 }, { 0x0BFB, 0x0C00 },
-{ 0x0C04, 0x0C04 }, { 0x0C0D, 0x0C0D }, { 0x0C11, 0x0C11 },
-{ 0x0C29, 0x0C29 }, { 0x0C34, 0x0C34 }, { 0x0C3A, 0x0C3C },
-{ 0x0C45, 0x0C45 }, { 0x0C49, 0x0C49 }, { 0x0C4E, 0x0C54 },
-{ 0x0C57, 0x0C57 }, { 0x0C5A, 0x0C5F }, { 0x0C64, 0x0C65 },
-{ 0x0C70, 0x0C77 }, { 0x0C80, 0x0C81 }, { 0x0C84, 0x0C84 },
-{ 0x0C8D, 0x0C8D }, { 0x0C91, 0x0C91 }, { 0x0CA9, 0x0CA9 },
-{ 0x0CB4, 0x0CB4 }, { 0x0CBA, 0x0CBB }, { 0x0CC5, 0x0CC5 },
-{ 0x0CC9, 0x0CC9 }, { 0x0CCE, 0x0CD4 }, { 0x0CD7, 0x0CDD },
-{ 0x0CDF, 0x0CDF }, { 0x0CE4, 0x0CE5 }, { 0x0CF0, 0x0CF0 },
-{ 0x0CF3, 0x0D01 }, { 0x0D04, 0x0D04 }, { 0x0D0D, 0x0D0D },
-{ 0x0D11, 0x0D11 }, { 0x0D3B, 0x0D3C }, { 0x0D45, 0x0D45 },
-{ 0x0D49, 0x0D49 }, { 0x0D4F, 0x0D56 }, { 0x0D58, 0x0D5F },
-{ 0x0D64, 0x0D65 }, { 0x0D76, 0x0D78 }, { 0x0D80, 0x0D81 },
-{ 0x0D84, 0x0D84 }, { 0x0D97, 0x0D99 }, { 0x0DB2, 0x0DB2 },
-{ 0x0DBC, 0x0DBC }, { 0x0DBE, 0x0DBF }, { 0x0DC7, 0x0DC9 },
-{ 0x0DCB, 0x0DCE }, { 0x0DD5, 0x0DD5 }, { 0x0DD7, 0x0DD7 },
-{ 0x0DE0, 0x0DF1 }, { 0x0DF5, 0x0E00 }, { 0x0E3B, 0x0E3E },
-{ 0x0E5C, 0x0E80 }, { 0x0E83, 0x0E83 }, { 

[clang] 282059b - Update LibASTImporter.rst

2022-06-26 Thread via cfe-commits

Author: Shivam
Date: 2022-06-26T19:22:52+05:30
New Revision: 282059b44d003a3e044bdc5c8884797f92bf2eab

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

LOG: Update LibASTImporter.rst

As my last commit changed the name of ImportError to ASTImportError , this 
section also needs to be updated so changed it.

Added: 


Modified: 
clang/docs/LibASTImporter.rst

Removed: 




diff  --git a/clang/docs/LibASTImporter.rst b/clang/docs/LibASTImporter.rst
index bedaf527f5e9..515eff7ebe33 100644
--- a/clang/docs/LibASTImporter.rst
+++ b/clang/docs/LibASTImporter.rst
@@ -468,7 +468,7 @@ Note, there may be several 
diff erent ASTImporter objects which import into the s
 cxxRecordDecl(hasName("Y"), isDefinition()), ToUnit);
 ToYDef->dump();
 // An error is set for "ToYDef" in the shared state.
-Optional OptErr =
+Optional OptErr =
 ImporterState->getImportDeclErrorIfAny(ToYDef);
 assert(OptErr);
 



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


[PATCH] D108469: Improve handling of static assert messages.

2022-06-26 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 440063.
cor3ntin marked 4 inline comments as done.
cor3ntin added a comment.
Herald added a subscriber: steakhal.
Herald added a project: All.

- Rebase
- Address Aaron's comments.
- Fix tests
- Keep dumping wide/utf16/utf32 strings escaped until we can ensure these 
things cannot appear in static_assert and other compile time constructs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108469

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Diagnostic.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
  clang/test/C/drs/dr0xx.c
  clang/test/CXX/dcl.dcl/p4-0x.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp
  clang/test/Lexer/null-character-in-literal.c
  clang/test/Misc/diag-special-chars.c
  clang/test/Misc/wrong-encoding.c
  clang/test/PCH/cxx-static_assert.cpp
  clang/test/Sema/static-assert.c
  clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp
  clang/test/SemaCXX/static-assert.cpp
  llvm/include/llvm/Support/Unicode.h
  llvm/lib/Support/Unicode.cpp

Index: llvm/lib/Support/Unicode.cpp
===
--- llvm/lib/Support/Unicode.cpp
+++ llvm/lib/Support/Unicode.cpp
@@ -19,197 +19,271 @@
 namespace sys {
 namespace unicode {
 
+/// Unicode code points of the categories L, M, N, P, S and Zs are considered
+/// printable.
+/// In addition, U+00AD SOFT HYPHEN is also considered printable, as
+/// it's actually displayed on most terminals. \return true if the character is
+/// considered printable.
 bool isPrintable(int UCS) {
-  // Sorted list of non-overlapping intervals of code points that are not
-  // supposed to be printable.
-  static const UnicodeCharRange NonPrintableRanges[] = {
-{ 0x, 0x001F }, { 0x007F, 0x009F }, { 0x034F, 0x034F },
-{ 0x0378, 0x0379 }, { 0x037F, 0x0383 }, { 0x038B, 0x038B },
-{ 0x038D, 0x038D }, { 0x03A2, 0x03A2 }, { 0x0528, 0x0530 },
-{ 0x0557, 0x0558 }, { 0x0560, 0x0560 }, { 0x0588, 0x0588 },
-{ 0x058B, 0x058E }, { 0x0590, 0x0590 }, { 0x05C8, 0x05CF },
-{ 0x05EB, 0x05EF }, { 0x05F5, 0x0605 }, { 0x061C, 0x061D },
-{ 0x06DD, 0x06DD }, { 0x070E, 0x070F }, { 0x074B, 0x074C },
-{ 0x07B2, 0x07BF }, { 0x07FB, 0x07FF }, { 0x082E, 0x082F },
-{ 0x083F, 0x083F }, { 0x085C, 0x085D }, { 0x085F, 0x089F },
-{ 0x08A1, 0x08A1 }, { 0x08AD, 0x08E3 }, { 0x08FF, 0x08FF },
-{ 0x0978, 0x0978 }, { 0x0980, 0x0980 }, { 0x0984, 0x0984 },
-{ 0x098D, 0x098E }, { 0x0991, 0x0992 }, { 0x09A9, 0x09A9 },
-{ 0x09B1, 0x09B1 }, { 0x09B3, 0x09B5 }, { 0x09BA, 0x09BB },
-{ 0x09C5, 0x09C6 }, { 0x09C9, 0x09CA }, { 0x09CF, 0x09D6 },
-{ 0x09D8, 0x09DB }, { 0x09DE, 0x09DE }, { 0x09E4, 0x09E5 },
-{ 0x09FC, 0x0A00 }, { 0x0A04, 0x0A04 }, { 0x0A0B, 0x0A0E },
-{ 0x0A11, 0x0A12 }, { 0x0A29, 0x0A29 }, { 0x0A31, 0x0A31 },
-{ 0x0A34, 0x0A34 }, { 0x0A37, 0x0A37 }, { 0x0A3A, 0x0A3B },
-{ 0x0A3D, 0x0A3D }, { 0x0A43, 0x0A46 }, { 0x0A49, 0x0A4A },
-{ 0x0A4E, 0x0A50 }, { 0x0A52, 0x0A58 }, { 0x0A5D, 0x0A5D },
-{ 0x0A5F, 0x0A65 }, { 0x0A76, 0x0A80 }, { 0x0A84, 0x0A84 },
-{ 0x0A8E, 0x0A8E }, { 0x0A92, 0x0A92 }, { 0x0AA9, 0x0AA9 },
-{ 0x0AB1, 0x0AB1 }, { 0x0AB4, 0x0AB4 }, { 0x0ABA, 0x0ABB },
-{ 0x0AC6, 0x0AC6 }, { 0x0ACA, 0x0ACA }, { 0x0ACE, 0x0ACF },
-{ 0x0AD1, 0x0ADF }, { 0x0AE4, 0x0AE5 }, { 0x0AF2, 0x0B00 },
-{ 0x0B04, 0x0B04 }, { 0x0B0D, 0x0B0E }, { 0x0B11, 0x0B12 },
-{ 0x0B29, 0x0B29 }, { 0x0B31, 0x0B31 }, { 0x0B34, 0x0B34 },
-{ 0x0B3A, 0x0B3B }, { 0x0B45, 0x0B46 }, { 0x0B49, 0x0B4A },
-{ 0x0B4E, 0x0B55 }, { 0x0B58, 0x0B5B }, { 0x0B5E, 0x0B5E },
-{ 0x0B64, 0x0B65 }, { 0x0B78, 0x0B81 }, { 0x0B84, 0x0B84 },
-{ 0x0B8B, 0x0B8D }, { 0x0B91, 0x0B91 }, { 0x0B96, 0x0B98 },
-{ 0x0B9B, 0x0B9B }, { 0x0B9D, 0x0B9D }, { 0x0BA0, 0x0BA2 },
-{ 0x0BA5, 0x0BA7 }, { 0x0BAB, 0x0BAD }, { 0x0BBA, 0x0BBD },
-{ 0x0BC3, 0x0BC5 }, { 0x0BC9, 0x0BC9 }, { 0x0BCE, 0x0BCF },
-{ 0x0BD1, 0x0BD6 }, { 0x0BD8, 0x0BE5 }, { 0x0BFB, 0x0C00 },
-{ 0x0C04, 0x0C04 }, { 0x0C0D, 0x0C0D }, { 0x0C11, 0x0C11 },
-{ 0x0C29, 0x0C29 }, { 0x0C34, 0x0C34 }, { 0x0C3A, 0x0C3C },
-{ 0x0C45, 0x0C45 }, { 0x0C49, 0x0C49 }, { 0x0C4E, 0x0C54 },
-{ 0x0C57, 0x0C57 }, { 0x0C5A, 0x0C5F }, { 0x0C64, 0x0C65 },
-{ 0x0C70, 0x0C77 }, { 0x0C80, 0x0C81 }, { 0x0C84, 0x0C84 },
-{ 0x0C8D, 0x0C8D }, { 0x0C91, 0x0C91 }, { 0x0CA9, 0x0CA9 },
-{ 0x0CB4, 0x0CB4 }, { 0x0CBA, 0x0CBB }, { 0x0CC5, 0x0CC5 },
-{ 0x0CC9, 0x0CC9 }, { 0x0CCE, 0x0CD4 }, { 0x0CD7, 0x0CDD },
-{ 0x0CDF, 0x0CDF }, { 0x0CE4, 0x0CE5 }, { 0x0CF0, 0x0CF0 },
-{ 0x0CF3, 0x0D01 }, { 0x0D04, 0x0D04 }, { 0x0D0D, 0x0D0D },
-{ 0x0D11, 0x0D11 }, { 0x0D3B, 0x0D3C }, { 0x0D45, 0x0D45 },
-{ 0x0D49, 0x0D49 }, { 0x0D4F, 0x0D56 }, { 0x0D58, 0x0D5F },
-{ 0x0D64, 0x0D65 }, { 0x0D76, 0x0D78 }, { 0x0D80, 0x0D81 },
-{ 0x0D84, 

[PATCH] D115827: [clang]: add missing Interpreter -> ClangDriverOptions dependency

2022-06-26 Thread Vassil Vassilev 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 rGb5eaf500f244: [clang] Add missing Interpreter - 
ClangDriverOptions dependency (authored by v.g.vassilev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115827

Files:
  clang/lib/Interpreter/CMakeLists.txt


Index: clang/lib/Interpreter/CMakeLists.txt
===
--- clang/lib/Interpreter/CMakeLists.txt
+++ clang/lib/Interpreter/CMakeLists.txt
@@ -14,6 +14,7 @@
 
   DEPENDS
   intrinsics_gen
+  ClangDriverOptions
 
   LINK_LIBS
   clangAST


Index: clang/lib/Interpreter/CMakeLists.txt
===
--- clang/lib/Interpreter/CMakeLists.txt
+++ clang/lib/Interpreter/CMakeLists.txt
@@ -14,6 +14,7 @@
 
   DEPENDS
   intrinsics_gen
+  ClangDriverOptions
 
   LINK_LIBS
   clangAST
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b5eaf50 - [clang] Add missing Interpreter -> ClangDriverOptions dependency

2022-06-26 Thread Vassil Vassilev via cfe-commits

Author: Vassil Vassilev
Date: 2022-06-26T13:51:21Z
New Revision: b5eaf500f2441eff2277ea2973878fb1f171fd0a

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

LOG: [clang] Add missing Interpreter -> ClangDriverOptions dependency

Without this, it is possible that Interpreter.cpp is being built before
clang/Driver/Options.inc is generated.

Observed only infrequently, serial builds and ext4 manifest the problem
much more often than parallel builds and btrfs.

https://reviews.llvm.org/rG06487b010d48c36c7714ee083ed38dff65711812
is a very similar case.

Patch by t184256!

Differential revision: https://reviews.llvm.org/D115827

Added: 


Modified: 
clang/lib/Interpreter/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index 88a0a716e126..df359329d08b 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -14,6 +14,7 @@ add_clang_library(clangInterpreter
 
   DEPENDS
   intrinsics_gen
+  ClangDriverOptions
 
   LINK_LIBS
   clangAST



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


[PATCH] D88780: Allow interfaces to operate on in-memory buffers with no source location info.

2022-06-26 Thread Vassil Vassilev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe881d85371bf: Allow interfaces to operate on in-memory 
buffers with no source location info. (authored by tapaswenipathak, committed 
by v.g.vassilev).

Changed prior to commit:
  https://reviews.llvm.org/D88780?vs=432746=440061#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88780

Files:
  clang/include/clang/Basic/SourceManager.h
  clang/unittests/Basic/SourceManagerTest.cpp

Index: clang/unittests/Basic/SourceManagerTest.cpp
===
--- clang/unittests/Basic/SourceManagerTest.cpp
+++ clang/unittests/Basic/SourceManagerTest.cpp
@@ -51,6 +51,73 @@
   IntrusiveRefCntPtr Target;
 };
 
+TEST_F(SourceManagerTest, isInMemoryBuffersNoSourceLocationInfo) {
+  // Check for invalid source location for each method
+  SourceLocation LocEmpty;
+  bool isWrittenInBuiltInFileFalse = SourceMgr.isWrittenInBuiltinFile(LocEmpty);
+  bool isWrittenInCommandLineFileFalse =
+  SourceMgr.isWrittenInCommandLineFile(LocEmpty);
+  bool isWrittenInScratchSpaceFalse =
+  SourceMgr.isWrittenInScratchSpace(LocEmpty);
+
+  EXPECT_FALSE(isWrittenInBuiltInFileFalse);
+  EXPECT_FALSE(isWrittenInCommandLineFileFalse);
+  EXPECT_FALSE(isWrittenInScratchSpaceFalse);
+
+  // Check for valid source location per filename for each method
+  const char *Source = "int x";
+
+  std::unique_ptr BuiltInBuf =
+  llvm::MemoryBuffer::getMemBuffer(Source);
+  const FileEntry *BuiltInFile =
+  FileMgr.getVirtualFile("", BuiltInBuf->getBufferSize(), 0);
+  SourceMgr.overrideFileContents(BuiltInFile, std::move(BuiltInBuf));
+  FileID BuiltInFileID =
+  SourceMgr.getOrCreateFileID(BuiltInFile, SrcMgr::C_User);
+  SourceMgr.setMainFileID(BuiltInFileID);
+  SourceLocation LocBuiltIn =
+  SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
+  bool isWrittenInBuiltInFileTrue =
+  SourceMgr.isWrittenInBuiltinFile(LocBuiltIn);
+
+  std::unique_ptr CommandLineBuf =
+  llvm::MemoryBuffer::getMemBuffer(Source);
+  const FileEntry *CommandLineFile = FileMgr.getVirtualFile(
+  "", CommandLineBuf->getBufferSize(), 0);
+  SourceMgr.overrideFileContents(CommandLineFile, std::move(CommandLineBuf));
+  FileID CommandLineFileID =
+  SourceMgr.getOrCreateFileID(CommandLineFile, SrcMgr::C_User);
+  SourceMgr.setMainFileID(CommandLineFileID);
+  SourceLocation LocCommandLine =
+  SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
+  bool isWrittenInCommandLineFileTrue =
+  SourceMgr.isWrittenInCommandLineFile(LocCommandLine);
+
+  std::unique_ptr ScratchSpaceBuf =
+  llvm::MemoryBuffer::getMemBuffer(Source);
+  const FileEntry *ScratchSpaceFile = FileMgr.getVirtualFile(
+  "", ScratchSpaceBuf->getBufferSize(), 0);
+  SourceMgr.overrideFileContents(ScratchSpaceFile, std::move(ScratchSpaceBuf));
+  FileID ScratchSpaceFileID =
+  SourceMgr.getOrCreateFileID(ScratchSpaceFile, SrcMgr::C_User);
+  SourceMgr.setMainFileID(ScratchSpaceFileID);
+  SourceLocation LocScratchSpace =
+  SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
+  bool isWrittenInScratchSpaceTrue =
+  SourceMgr.isWrittenInScratchSpace(LocScratchSpace);
+
+  EXPECT_TRUE(isWrittenInBuiltInFileTrue);
+  EXPECT_TRUE(isWrittenInCommandLineFileTrue);
+  EXPECT_TRUE(isWrittenInScratchSpaceTrue);
+}
+
+TEST_F(SourceManagerTest, isInSystemHeader) {
+  // Check for invalid source location
+  SourceLocation LocEmpty;
+  bool isInSystemHeaderFalse = SourceMgr.isInSystemHeader(LocEmpty);
+  ASSERT_FALSE(isInSystemHeaderFalse);
+}
+
 TEST_F(SourceManagerTest, isBeforeInTranslationUnit) {
   const char *source =
 "#define M(x) [x]\n"
Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -1473,24 +1473,35 @@
 
   /// Returns whether \p Loc is located in a  file.
   bool isWrittenInBuiltinFile(SourceLocation Loc) const {
-StringRef Filename(getPresumedLoc(Loc).getFilename());
+PresumedLoc Presumed = getPresumedLoc(Loc);
+if (Presumed.isInvalid())
+  return false;
+StringRef Filename(Presumed.getFilename());
 return Filename.equals("");
   }
 
   /// Returns whether \p Loc is located in a  file.
   bool isWrittenInCommandLineFile(SourceLocation Loc) const {
-StringRef Filename(getPresumedLoc(Loc).getFilename());
+PresumedLoc Presumed = getPresumedLoc(Loc);
+if (Presumed.isInvalid())
+  return false;
+StringRef Filename(Presumed.getFilename());
 return Filename.equals("");
   }
 
   /// Returns whether \p Loc is located in a  file.
   bool isWrittenInScratchSpace(SourceLocation Loc) const {
-StringRef Filename(getPresumedLoc(Loc).getFilename());
+PresumedLoc Presumed = getPresumedLoc(Loc);

[clang] e881d85 - Allow interfaces to operate on in-memory buffers with no source location info.

2022-06-26 Thread Vassil Vassilev via cfe-commits

Author: Tapasweni Pathak
Date: 2022-06-26T13:21:23Z
New Revision: e881d85371bf9b024e0668f1667fefde4df05711

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

LOG: Allow interfaces to operate on in-memory buffers with no source location 
info.

This patch is a part of the upstreaming efforts. Cling has the ability to spawn
child interpreters (mainly for auto completions). The child interpreter import
Decls using the ASTImporter which casuses the assertion here
https://github.com/llvm/llvm-project/blob/65eb74e94b414fcde6bfa810d1c30c7fcb136b77/clang/include/clang/Basic/SourceLocation.h#L322

The patch is co-developed with V. Vassilev.

Differential revision: https://reviews.llvm.org/D88780

Added: 


Modified: 
clang/include/clang/Basic/SourceManager.h
clang/unittests/Basic/SourceManagerTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 73e6353109d92..5bdeecb07cd9e 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -1473,24 +1473,35 @@ class SourceManager : public 
RefCountedBase {
 
   /// Returns whether \p Loc is located in a  file.
   bool isWrittenInBuiltinFile(SourceLocation Loc) const {
-StringRef Filename(getPresumedLoc(Loc).getFilename());
+PresumedLoc Presumed = getPresumedLoc(Loc);
+if (Presumed.isInvalid())
+  return false;
+StringRef Filename(Presumed.getFilename());
 return Filename.equals("");
   }
 
   /// Returns whether \p Loc is located in a  file.
   bool isWrittenInCommandLineFile(SourceLocation Loc) const {
-StringRef Filename(getPresumedLoc(Loc).getFilename());
+PresumedLoc Presumed = getPresumedLoc(Loc);
+if (Presumed.isInvalid())
+  return false;
+StringRef Filename(Presumed.getFilename());
 return Filename.equals("");
   }
 
   /// Returns whether \p Loc is located in a  file.
   bool isWrittenInScratchSpace(SourceLocation Loc) const {
-StringRef Filename(getPresumedLoc(Loc).getFilename());
+PresumedLoc Presumed = getPresumedLoc(Loc);
+if (Presumed.isInvalid())
+  return false;
+StringRef Filename(Presumed.getFilename());
 return Filename.equals("");
   }
 
   /// Returns if a SourceLocation is in a system header.
   bool isInSystemHeader(SourceLocation Loc) const {
+if (Loc.isInvalid())
+  return false;
 return isSystem(getFileCharacteristic(Loc));
   }
 

diff  --git a/clang/unittests/Basic/SourceManagerTest.cpp 
b/clang/unittests/Basic/SourceManagerTest.cpp
index dadfcc94ac0d3..e98100faedbe2 100644
--- a/clang/unittests/Basic/SourceManagerTest.cpp
+++ b/clang/unittests/Basic/SourceManagerTest.cpp
@@ -51,6 +51,73 @@ class SourceManagerTest : public ::testing::Test {
   IntrusiveRefCntPtr Target;
 };
 
+TEST_F(SourceManagerTest, isInMemoryBuffersNoSourceLocationInfo) {
+  // Check for invalid source location for each method
+  SourceLocation LocEmpty;
+  bool isWrittenInBuiltInFileFalse = 
SourceMgr.isWrittenInBuiltinFile(LocEmpty);
+  bool isWrittenInCommandLineFileFalse =
+  SourceMgr.isWrittenInCommandLineFile(LocEmpty);
+  bool isWrittenInScratchSpaceFalse =
+  SourceMgr.isWrittenInScratchSpace(LocEmpty);
+
+  EXPECT_FALSE(isWrittenInBuiltInFileFalse);
+  EXPECT_FALSE(isWrittenInCommandLineFileFalse);
+  EXPECT_FALSE(isWrittenInScratchSpaceFalse);
+
+  // Check for valid source location per filename for each method
+  const char *Source = "int x";
+
+  std::unique_ptr BuiltInBuf =
+  llvm::MemoryBuffer::getMemBuffer(Source);
+  const FileEntry *BuiltInFile =
+  FileMgr.getVirtualFile("", BuiltInBuf->getBufferSize(), 0);
+  SourceMgr.overrideFileContents(BuiltInFile, std::move(BuiltInBuf));
+  FileID BuiltInFileID =
+  SourceMgr.getOrCreateFileID(BuiltInFile, SrcMgr::C_User);
+  SourceMgr.setMainFileID(BuiltInFileID);
+  SourceLocation LocBuiltIn =
+  SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
+  bool isWrittenInBuiltInFileTrue =
+  SourceMgr.isWrittenInBuiltinFile(LocBuiltIn);
+
+  std::unique_ptr CommandLineBuf =
+  llvm::MemoryBuffer::getMemBuffer(Source);
+  const FileEntry *CommandLineFile = FileMgr.getVirtualFile(
+  "", CommandLineBuf->getBufferSize(), 0);
+  SourceMgr.overrideFileContents(CommandLineFile, std::move(CommandLineBuf));
+  FileID CommandLineFileID =
+  SourceMgr.getOrCreateFileID(CommandLineFile, SrcMgr::C_User);
+  SourceMgr.setMainFileID(CommandLineFileID);
+  SourceLocation LocCommandLine =
+  SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
+  bool isWrittenInCommandLineFileTrue =
+  SourceMgr.isWrittenInCommandLineFile(LocCommandLine);
+
+  std::unique_ptr ScratchSpaceBuf =
+  llvm::MemoryBuffer::getMemBuffer(Source);
+  const 

[PATCH] D128608: [NFC][AST] remove the unnecessary condition checks in ASTImporter.cpp

2022-06-26 Thread Shivam Rajput via Phabricator via cfe-commits
phyBrackets created this revision.
Herald added a subscriber: martong.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
phyBrackets requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I think that these conditions are unnecessary because in VisitClassTemplateDecl 
we import the definition via the templated CXXRecordDecl and in 
VisitVarTemplateDecl via the templated VarDecl. These are named ToTemplted and 
DTemplated respectively.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128608

Files:
  clang/lib/AST/ASTImporter.cpp


Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -5667,11 +5667,6 @@
 D2->setPreviousDecl(Recent);
   }
 
-  if (FromTemplated->isCompleteDefinition() &&
-  !ToTemplated->isCompleteDefinition()) {
-// FIXME: Import definition!
-  }
-
   return D2;
 }
 
@@ -5950,11 +5945,6 @@
 ToVarTD->setPreviousDecl(Recent);
   }
 
-  if (DTemplated->isThisDeclarationADefinition() &&
-  !ToTemplated->isThisDeclarationADefinition()) {
-// FIXME: Import definition!
-  }
-
   return ToVarTD;
 }
 


Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -5667,11 +5667,6 @@
 D2->setPreviousDecl(Recent);
   }
 
-  if (FromTemplated->isCompleteDefinition() &&
-  !ToTemplated->isCompleteDefinition()) {
-// FIXME: Import definition!
-  }
-
   return D2;
 }
 
@@ -5950,11 +5945,6 @@
 ToVarTD->setPreviousDecl(Recent);
   }
 
-  if (DTemplated->isThisDeclarationADefinition() &&
-  !ToTemplated->isThisDeclarationADefinition()) {
-// FIXME: Import definition!
-  }
-
   return ToVarTD;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128589: [clang-repl] Support destructors of global objects.

2022-06-26 Thread Sunho Kim via Phabricator via cfe-commits
sunho added a comment.

This seems to be breaking builds in ppc bots. Invastigating right now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128589

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


[clang] 45b6c38 - Revert "[clang-repl] Support destructors of global objects."

2022-06-26 Thread Sunho Kim via cfe-commits

Author: Sunho Kim
Date: 2022-06-26T22:10:28+09:00
New Revision: 45b6c38145e72d8a2593f9637c01015122b0b28c

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

LOG: Revert "[clang-repl] Support destructors of global objects."

This reverts commit 9de8b05bfe0de2915d2443d06159396c5f9d389f.

Added: 


Modified: 
clang/lib/Interpreter/IncrementalExecutor.cpp
clang/lib/Interpreter/IncrementalExecutor.h
clang/lib/Interpreter/Interpreter.cpp
clang/test/Interpreter/execute.cpp
clang/tools/clang-repl/ClangRepl.cpp
clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/IncrementalExecutor.cpp 
b/clang/lib/Interpreter/IncrementalExecutor.cpp
index 2445ba906a4c2..c055827281b4f 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -53,12 +53,6 @@ 
IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext ,
 
 IncrementalExecutor::~IncrementalExecutor() {}
 
-// Clean up the JIT instance.
-llvm::Error IncrementalExecutor::cleanUp() {
-  // This calls the global dtors of registered modules.
-  return Jit->deinitialize(Jit->getMainJITDylib());
-}
-
 llvm::Error IncrementalExecutor::addModule(PartialTranslationUnit ) {
   llvm::orc::ResourceTrackerSP RT =
   Jit->getMainJITDylib().createResourceTracker();

diff  --git a/clang/lib/Interpreter/IncrementalExecutor.h 
b/clang/lib/Interpreter/IncrementalExecutor.h
index fd93b1d390357..580724e1e24e2 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.h
+++ b/clang/lib/Interpreter/IncrementalExecutor.h
@@ -51,7 +51,6 @@ class IncrementalExecutor {
   llvm::Error addModule(PartialTranslationUnit );
   llvm::Error removeModule(PartialTranslationUnit );
   llvm::Error runCtors() const;
-  llvm::Error cleanUp();
   llvm::Expected
   getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
   llvm::orc::LLJIT *getExecutionEngine() const { return Jit.get(); }

diff  --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 0ffb40c217cd9..a10eb79b413b3 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -183,14 +183,7 @@ Interpreter::Interpreter(std::unique_ptr 
CI,
*TSCtx->getContext(), Err);
 }
 
-Interpreter::~Interpreter() {
-  if (IncrExecutor) {
-if (llvm::Error Err = IncrExecutor->cleanUp())
-  llvm::report_fatal_error(
-  llvm::Twine("Failed to clean up IncrementalExecutor: ") +
-  toString(std::move(Err)));
-  }
-}
+Interpreter::~Interpreter() {}
 
 llvm::Expected>
 Interpreter::create(std::unique_ptr CI) {

diff  --git a/clang/test/Interpreter/execute.cpp 
b/clang/test/Interpreter/execute.cpp
index 914a9285117e0..f5c70c21ac507 100644
--- a/clang/test/Interpreter/execute.cpp
+++ b/clang/test/Interpreter/execute.cpp
@@ -1,4 +1,3 @@
-// clang-format off
 // RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
@@ -19,7 +18,4 @@ auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, 
reinterpret_cast(m)); }} d;
-// CHECK: D[f=1.00, m=0x0]
-
 %quit

diff  --git a/clang/tools/clang-repl/ClangRepl.cpp 
b/clang/tools/clang-repl/ClangRepl.cpp
index d3253738c6da1..4f673bdcb7cc5 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -70,8 +70,6 @@ int main(int argc, const char **argv) {
   ExitOnErr.setBanner("clang-repl: ");
   llvm::cl::ParseCommandLineOptions(argc, argv);
 
-  llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
-
   std::vector ClangArgv(ClangArgs.size());
   std::transform(ClangArgs.begin(), ClangArgs.end(), ClangArgv.begin(),
  [](const std::string ) -> const char * { return s.data(); 
});
@@ -129,5 +127,7 @@ int main(int argc, const char **argv) {
   // later errors use the default handling behavior instead.
   llvm::remove_fatal_error_handler();
 
+  llvm::llvm_shutdown();
+
   return checkDiagErrors(Interp->getCompilerInstance());
 }

diff  --git 
a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp 
b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
index 73f7a01a20bf0..75928d912dd47 100644
--- a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
+++ b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
@@ -48,7 +48,6 @@ createInterpreter(const Args  = {},
 TEST(InterpreterTest, CatchException) {
   llvm::InitializeNativeTarget();
   llvm::InitializeNativeTargetAsmPrinter();
-  

[PATCH] D128607: [clang-format] NFC Fix uninitialized memory problem

2022-06-26 Thread sstwcw via Phabricator via cfe-commits
sstwcw added a comment.

This problem was found by the build bot after I pushed the buggy code.
https://lab.llvm.org/buildbot#builders/5/builds/25268
It looks like uninitialized memory was not checked when I ran `ninja 
check-clang-format` locally.  Am I missing some configuration?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128607

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


[PATCH] D128607: [clang-format] NFC Fix uninitialized memory problem

2022-06-26 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
sstwcw added reviewers: HazardyKnusperkeks, MyDeveloperDay, curdeius, owenpan.
Herald added a project: All.
sstwcw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The setLength function checks for the token kind which could be
uninitialized in the previous version.

The problem was introduced in 2e32ff106e 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128607

Files:
  clang/lib/Format/FormatTokenLexer.cpp


Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -1128,11 +1128,12 @@
 return false;
   size_t Len = Matches[0].size();
 
-  Tok.setLength(Len);
-  Tok.setLocation(Lex->getSourceLocation(Start, Len));
   // The kind has to be an identifier so we can match it against those defined
-  // in Keywords.
+  // in Keywords. The kind has to be set before the length because the 
setLength
+  // function checks that the kind is not an annotation.
   Tok.setKind(tok::raw_identifier);
+  Tok.setLength(Len);
+  Tok.setLocation(Lex->getSourceLocation(Start, Len));
   Tok.setRawIdentifierData(Start);
   Lex->seek(Lex->getCurrentBufferOffset() + Len, /*IsAtStartofline=*/false);
   return true;


Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -1128,11 +1128,12 @@
 return false;
   size_t Len = Matches[0].size();
 
-  Tok.setLength(Len);
-  Tok.setLocation(Lex->getSourceLocation(Start, Len));
   // The kind has to be an identifier so we can match it against those defined
-  // in Keywords.
+  // in Keywords. The kind has to be set before the length because the setLength
+  // function checks that the kind is not an annotation.
   Tok.setKind(tok::raw_identifier);
+  Tok.setLength(Len);
+  Tok.setLocation(Lex->getSourceLocation(Start, Len));
   Tok.setRawIdentifierData(Start);
   Lex->seek(Lex->getCurrentBufferOffset() + Len, /*IsAtStartofline=*/false);
   return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126682: [clang-repl] Implement code undo

2022-06-26 Thread Jun Zhang via Phabricator via cfe-commits
junaire closed this revision.
junaire added a comment.

land in https://reviews.llvm.org/rGdea5a9cc929048be261a4c030407e4d7e1e70fec


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126682

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


[clang] dea5a9c - [clang-repl] Implement code undo.

2022-06-26 Thread Jun Zhang via cfe-commits

Author: Jun Zhang
Date: 2022-06-26T18:32:18+08:00
New Revision: dea5a9cc929048be261a4c030407e4d7e1e70fec

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

LOG: [clang-repl] Implement code undo.

In interactive C++ it is convenient to roll back to a previous state of the
compiler. For example:
clang-repl> int x = 42;
clang-repl> %undo
clang-repl> float x = 24 // not an error

To support this, the patch extends the functionality used to recover from
errors and adds functionality to recover the low-level execution infrastructure.

The current implementation is based on watermarks. It exploits the fact that
at each incremental input the underlying compiler infrastructure is in a valid
state. We can only go N incremental inputs back to a previous valid state. We do
not need and do not do any further dependency tracking.

This patch was co-developed with V. Vassilev, relies on the past work of Purva
Chaudhari in clang-repl and is inspired by the past work on the same feature
in the Cling interpreter.

Co-authored-by: Purva-Chaudhari 
Co-authored-by: Vassil Vassilev 
Signed-off-by: Jun Zhang 

Added: 
clang/test/Interpreter/code-undo.cpp

Modified: 
clang/include/clang/Interpreter/Interpreter.h
clang/lib/Interpreter/IncrementalExecutor.cpp
clang/lib/Interpreter/IncrementalExecutor.h
clang/lib/Interpreter/IncrementalParser.cpp
clang/lib/Interpreter/IncrementalParser.h
clang/lib/Interpreter/Interpreter.cpp
clang/test/Interpreter/execute.cpp
clang/test/Interpreter/plugins.cpp
clang/test/Interpreter/sanity.c
clang/tools/clang-repl/ClangRepl.cpp
clang/unittests/Interpreter/InterpreterTest.cpp

Removed: 




diff  --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index f2fdb90f5ba48..fd22af9766135 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -69,6 +69,9 @@ class Interpreter {
 return llvm::Error::success();
   }
 
+  /// Undo N previous incremental inputs.
+  llvm::Error Undo(unsigned N = 1);
+
   /// \returns the \c JITTargetAddress of a \c GlobalDecl. This interface uses
   /// the CodeGenModule's internal mangling cache to avoid recomputing the
   /// mangled name.

diff  --git a/clang/lib/Interpreter/IncrementalExecutor.cpp 
b/clang/lib/Interpreter/IncrementalExecutor.cpp
index c5ed9b0fb4571..2445ba906a4c2 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -12,6 +12,7 @@
 
 #include "IncrementalExecutor.h"
 
+#include "clang/Interpreter/PartialTranslationUnit.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
 #include "llvm/ExecutionEngine/Orc/CompileUtils.h"
 #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
@@ -58,8 +59,24 @@ llvm::Error IncrementalExecutor::cleanUp() {
   return Jit->deinitialize(Jit->getMainJITDylib());
 }
 
-llvm::Error IncrementalExecutor::addModule(std::unique_ptr M) {
-  return Jit->addIRModule(llvm::orc::ThreadSafeModule(std::move(M), TSCtx));
+llvm::Error IncrementalExecutor::addModule(PartialTranslationUnit ) {
+  llvm::orc::ResourceTrackerSP RT =
+  Jit->getMainJITDylib().createResourceTracker();
+  ResourceTrackers[] = RT;
+
+  return Jit->addIRModule(RT, {std::move(PTU.TheModule), TSCtx});
+}
+
+llvm::Error IncrementalExecutor::removeModule(PartialTranslationUnit ) {
+
+  llvm::orc::ResourceTrackerSP RT = std::move(ResourceTrackers[]);
+  if (!RT)
+return llvm::Error::success();
+
+  ResourceTrackers.erase();
+  if (llvm::Error Err = RT->remove())
+return Err;
+  return llvm::Error::success();
 }
 
 llvm::Error IncrementalExecutor::runCtors() const {

diff  --git a/clang/lib/Interpreter/IncrementalExecutor.h 
b/clang/lib/Interpreter/IncrementalExecutor.h
index 75c181d76302a..fd93b1d390357 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.h
+++ b/clang/lib/Interpreter/IncrementalExecutor.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_CLANG_LIB_INTERPRETER_INCREMENTALEXECUTOR_H
 #define LLVM_CLANG_LIB_INTERPRETER_INCREMENTALEXECUTOR_H
 
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
@@ -29,11 +30,17 @@ class ThreadSafeContext;
 } // namespace llvm
 
 namespace clang {
+
+struct PartialTranslationUnit;
+
 class IncrementalExecutor {
   using CtorDtorIterator = llvm::orc::CtorDtorIterator;
   std::unique_ptr Jit;
   llvm::orc::ThreadSafeContext 
 
+  llvm::DenseMap
+  ResourceTrackers;
+
 public:
   enum SymbolNameKind { IRName, LinkerName };
 
@@ -41,7 +48,8 @@ class IncrementalExecutor {
   const llvm::Triple );
   ~IncrementalExecutor();
 
-  llvm::Error addModule(std::unique_ptr M);
+  

[PATCH] D128604: [WIP][RISCV] Support Zbpbo extension

2022-06-26 Thread Shao-Ce SUN via Phabricator via cfe-commits
sunshaoce created this revision.
sunshaoce added reviewers: asb, craig.topper, jrtc27, Jim, luismarques, 
kito-cheng, frasercrmck.
Herald added subscribers: VincentWu, luke957, StephenFan, vkmr, evandro, 
apazos, sameer.abuasal, s.egerton, benna, psnobl, jocewei, PkmX, the_o, 
brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, shiva0217, niosHD, 
sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
sunshaoce requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, eopXD, 
MaskRay.
Herald added projects: clang, LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128604

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/test/CodeGen/RISCV/rvp-intrinsics/riscv32-zbpbo.c
  clang/test/CodeGen/RISCV/rvp-intrinsics/riscv64-zbpbo.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/rv32zbpbo.ll
  llvm/test/CodeGen/RISCV/rv64zbpbo.ll
  llvm/test/MC/RISCV/rv32zbpbo-valid.s
  llvm/test/MC/RISCV/rv64zbpbo-valid.s

Index: llvm/test/MC/RISCV/rv64zbpbo-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zbpbo-valid.s
@@ -0,0 +1,35 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zbpbo -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zbpbo < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zbpbo -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: pack t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x08]
+pack t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: packu t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x48]
+packu t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: fsrw t0, t1, t2, t3
+# CHECK-ASM: encoding: [0xbb,0x52,0xc3,0x3d]
+fsrw t0, t1, t2, t3
+
+# CHECK-ASM-AND-OBJ: max t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x62,0x73,0x0a]
+max t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: min t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x0a]
+min t0, t1, t2
+
+# CHECK-S-OBJ: rev8.h t0, t1
+rev8.h x5, x6
+
+# CHECK-ASM-AND-OBJ: cmix t0, t1, t2, t3
+# CHECK-ASM: encoding: [0xb3,0x92,0x63,0xe6]
+cmix t0, t1, t2, t3
+
+# CHECK-ASM: encoding: [0x93,0x52,0xf3,0x6b]
+rev t0, t1
Index: llvm/test/MC/RISCV/rv32zbpbo-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zbpbo-valid.s
@@ -0,0 +1,43 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zbpbo -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zbpbo < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zbpbo -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: clz t0, t1
+# CHECK-ASM: encoding: [0x93,0x12,0x03,0x60]
+clz t0, t1
+
+# CHECK-ASM-AND-OBJ: pack t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x08]
+pack t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: packu t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x48]
+packu t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: fsr t0, t1, t2, t3
+# CHECK-ASM: encoding: [0xb3,0x52,0xc3,0x3d]
+fsr t0, t1, t2, t3
+
+# CHECK-ASM-AND-OBJ: fsri t0, t1, t2, 0
+# CHECK-ASM: encoding: [0x93,0x52,0x03,0x3c]
+fsri t0, t1, t2, 0
+
+# CHECK-ASM-AND-OBJ: max t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x62,0x73,0x0a]
+max t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: min t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x0a]
+min t0, t1, t2
+
+# CHECK-S-OBJ: rev8.h t0, t1
+rev8.h x5, x6
+
+# CHECK-ASM-AND-OBJ: cmix t0, t1, t2, t3
+# CHECK-ASM: encoding: [0xb3,0x92,0x63,0xe6]
+cmix t0, t1, t2, t3
+
+# CHECK-ASM: encoding: [0x93,0x52,0xf3,0x69]
+rev t0, t1
Index: llvm/test/CodeGen/RISCV/rv64zbpbo.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/rv64zbpbo.ll
@@ -0,0 +1,103 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s -check-prefix=RV64I
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-zbpbo -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s -check-prefix=RV64ZBPBO
+
+define i64 @pack_i64(i64 %a, i64 %b) nounwind {
+; RV64I-LABEL: pack_i64:
+; RV64I:   # %bb.0:
+; RV64I-NEXT:slli a0, a0, 32
+; RV64I-NEXT:srli a0, a0, 32
+; RV64I-NEXT:slli a1, a1, 32
+; RV64I-NEXT:or a0, a1, a0
+; RV64I-NEXT:ret
+;
+; RV64ZBPBO-LABEL: pack_i64:
+; RV64ZBPBO:   # %bb.0:
+; RV64ZBPBO-NEXT:pack a0, a0, a1
+; RV64ZBPBO-NEXT:ret
+  %shl = and i64 %a, 4294967295
+  %shl1 = shl i64 %b, 32
+  %or = or i64 

[PATCH] D126682: [clang-repl] Implement code undo

2022-06-26 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev accepted this revision.
v.g.vassilev 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/D126682/new/

https://reviews.llvm.org/D126682

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


[PATCH] D128589: [clang-repl] Support destructors of global objects.

2022-06-26 Thread Sunho Kim via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9de8b05bfe0d: [clang-repl] Support destructors of global 
objects. (authored by sunho).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128589

Files:
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/test/Interpreter/execute.cpp
  clang/tools/clang-repl/ClangRepl.cpp
  clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp

Index: clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
===
--- clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
+++ clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
@@ -48,6 +48,7 @@
 TEST(InterpreterTest, CatchException) {
   llvm::InitializeNativeTarget();
   llvm::InitializeNativeTargetAsmPrinter();
+  llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
 
   {
 auto J = llvm::orc::LLJITBuilder().create();
@@ -131,8 +132,6 @@
   EXPECT_ANY_THROW(ThrowException());
   std::string CapturedStdOut = testing::internal::GetCapturedStdout();
   EXPECT_EQ(CapturedStdOut, "Caught: 'To be caught in JIT'\n");
-
-  llvm::llvm_shutdown();
 }
 
 } // end anonymous namespace
Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -70,6 +70,8 @@
   ExitOnErr.setBanner("clang-repl: ");
   llvm::cl::ParseCommandLineOptions(argc, argv);
 
+  llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+
   std::vector ClangArgv(ClangArgs.size());
   std::transform(ClangArgs.begin(), ClangArgs.end(), ClangArgv.begin(),
  [](const std::string ) -> const char * { return s.data(); });
@@ -121,7 +123,5 @@
   // later errors use the default handling behavior instead.
   llvm::remove_fatal_error_handler();
 
-  llvm::llvm_shutdown();
-
   return checkDiagErrors(Interp->getCompilerInstance());
 }
Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -1,3 +1,4 @@
+// clang-format off
 // RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
@@ -18,4 +19,7 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
+struct D { float f = 1.0; D *m = nullptr; D(){} ~D() { printf("D[f=%f, m=0x%llx]\n", f, reinterpret_cast(m)); }} d;
+// CHECK: D[f=1.00, m=0x0]
+
 quit
Index: clang/lib/Interpreter/Interpreter.cpp
===
--- clang/lib/Interpreter/Interpreter.cpp
+++ clang/lib/Interpreter/Interpreter.cpp
@@ -183,7 +183,14 @@
*TSCtx->getContext(), Err);
 }
 
-Interpreter::~Interpreter() {}
+Interpreter::~Interpreter() {
+  if (IncrExecutor) {
+if (llvm::Error Err = IncrExecutor->cleanUp())
+  llvm::report_fatal_error(
+  llvm::Twine("Failed to clean up IncrementalExecutor: ") +
+  toString(std::move(Err)));
+  }
+}
 
 llvm::Expected>
 Interpreter::create(std::unique_ptr CI) {
Index: clang/lib/Interpreter/IncrementalExecutor.h
===
--- clang/lib/Interpreter/IncrementalExecutor.h
+++ clang/lib/Interpreter/IncrementalExecutor.h
@@ -43,6 +43,7 @@
 
   llvm::Error addModule(std::unique_ptr M);
   llvm::Error runCtors() const;
+  llvm::Error cleanUp();
   llvm::Expected
   getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
   llvm::orc::LLJIT *getExecutionEngine() const { return Jit.get(); }
Index: clang/lib/Interpreter/IncrementalExecutor.cpp
===
--- clang/lib/Interpreter/IncrementalExecutor.cpp
+++ clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -52,6 +52,12 @@
 
 IncrementalExecutor::~IncrementalExecutor() {}
 
+// Clean up the JIT instance.
+llvm::Error IncrementalExecutor::cleanUp() {
+  // This calls the global dtors of registered modules.
+  return Jit->deinitialize(Jit->getMainJITDylib());
+}
+
 llvm::Error IncrementalExecutor::addModule(std::unique_ptr M) {
   return Jit->addIRModule(llvm::orc::ThreadSafeModule(std::move(M), TSCtx));
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 9de8b05 - [clang-repl] Support destructors of global objects.

2022-06-26 Thread Sunho Kim via cfe-commits

Author: Sunho Kim
Date: 2022-06-26T19:02:19+09:00
New Revision: 9de8b05bfe0de2915d2443d06159396c5f9d389f

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

LOG: [clang-repl] Support destructors of global objects.

Supports destructors of global objects by properly calling jitdylib 
deinitialize which calls the global dtors of ir modules.

This supersedes https://reviews.llvm.org/D127945. There was an issue when 
calling deinitialize on windows but it got fixed by 
https://reviews.llvm.org/D128037.

Reviewed By: v.g.vassilev

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

Added: 


Modified: 
clang/lib/Interpreter/IncrementalExecutor.cpp
clang/lib/Interpreter/IncrementalExecutor.h
clang/lib/Interpreter/Interpreter.cpp
clang/test/Interpreter/execute.cpp
clang/tools/clang-repl/ClangRepl.cpp
clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/IncrementalExecutor.cpp 
b/clang/lib/Interpreter/IncrementalExecutor.cpp
index 75c385aa409f3..c5ed9b0fb4571 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -52,6 +52,12 @@ 
IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext ,
 
 IncrementalExecutor::~IncrementalExecutor() {}
 
+// Clean up the JIT instance.
+llvm::Error IncrementalExecutor::cleanUp() {
+  // This calls the global dtors of registered modules.
+  return Jit->deinitialize(Jit->getMainJITDylib());
+}
+
 llvm::Error IncrementalExecutor::addModule(std::unique_ptr M) {
   return Jit->addIRModule(llvm::orc::ThreadSafeModule(std::move(M), TSCtx));
 }

diff  --git a/clang/lib/Interpreter/IncrementalExecutor.h 
b/clang/lib/Interpreter/IncrementalExecutor.h
index 51b4d83d10b1c..75c181d76302a 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.h
+++ b/clang/lib/Interpreter/IncrementalExecutor.h
@@ -43,6 +43,7 @@ class IncrementalExecutor {
 
   llvm::Error addModule(std::unique_ptr M);
   llvm::Error runCtors() const;
+  llvm::Error cleanUp();
   llvm::Expected
   getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
   llvm::orc::LLJIT *getExecutionEngine() const { return Jit.get(); }

diff  --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 564b24efebdd0..c3bbfcfec8cbe 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -183,7 +183,14 @@ Interpreter::Interpreter(std::unique_ptr 
CI,
*TSCtx->getContext(), Err);
 }
 
-Interpreter::~Interpreter() {}
+Interpreter::~Interpreter() {
+  if (IncrExecutor) {
+if (llvm::Error Err = IncrExecutor->cleanUp())
+  llvm::report_fatal_error(
+  llvm::Twine("Failed to clean up IncrementalExecutor: ") +
+  toString(std::move(Err)));
+  }
+}
 
 llvm::Expected>
 Interpreter::create(std::unique_ptr CI) {

diff  --git a/clang/test/Interpreter/execute.cpp 
b/clang/test/Interpreter/execute.cpp
index f5d75074947d4..4f01f8349be2f 100644
--- a/clang/test/Interpreter/execute.cpp
+++ b/clang/test/Interpreter/execute.cpp
@@ -1,3 +1,4 @@
+// clang-format off
 // RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
@@ -18,4 +19,7 @@ auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, 
reinterpret_cast(m)); }} d;
+// CHECK: D[f=1.00, m=0x0]
+
 quit

diff  --git a/clang/tools/clang-repl/ClangRepl.cpp 
b/clang/tools/clang-repl/ClangRepl.cpp
index ca784ad0c07de..271ec2695789e 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -70,6 +70,8 @@ int main(int argc, const char **argv) {
   ExitOnErr.setBanner("clang-repl: ");
   llvm::cl::ParseCommandLineOptions(argc, argv);
 
+  llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+
   std::vector ClangArgv(ClangArgs.size());
   std::transform(ClangArgs.begin(), ClangArgs.end(), ClangArgv.begin(),
  [](const std::string ) -> const char * { return s.data(); 
});
@@ -121,7 +123,5 @@ int main(int argc, const char **argv) {
   // later errors use the default handling behavior instead.
   llvm::remove_fatal_error_handler();
 
-  llvm::llvm_shutdown();
-
   return checkDiagErrors(Interp->getCompilerInstance());
 }

diff  --git 
a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp 
b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
index 75928d912dd47..73f7a01a20bf0 100644
--- a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
+++ 

[PATCH] D126682: [clang-repl] Implement code undo

2022-06-26 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 440050.
junaire added a comment.

Try to fix the failing permerge test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126682

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/test/Interpreter/code-undo.cpp
  clang/test/Interpreter/execute.cpp
  clang/test/Interpreter/plugins.cpp
  clang/test/Interpreter/sanity.c
  clang/tools/clang-repl/ClangRepl.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -128,6 +128,51 @@
   EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
 }
 
+TEST(InterpreterTest, UndoCommand) {
+  Args ExtraArgs = {"-Xclang", "-diagnostic-log-file", "-Xclang", "-"};
+
+  // Create the diagnostic engine with unowned consumer.
+  std::string DiagnosticOutput;
+  llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
+  auto DiagPrinter = std::make_unique(
+  DiagnosticsOS, new DiagnosticOptions());
+
+  auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
+
+  // Fail to undo.
+  auto Err1 = Interp->Undo();
+  EXPECT_EQ("Operation failed. Too many undos",
+llvm::toString(std::move(Err1)));
+  auto Err2 = Interp->Parse("int foo = 42;");
+  EXPECT_TRUE(!!Err2);
+  auto Err3 = Interp->Undo(2);
+  EXPECT_EQ("Operation failed. Too many undos",
+llvm::toString(std::move(Err3)));
+
+  // Succeed to undo.
+  auto Err4 = Interp->Parse("int x = 42;");
+  EXPECT_TRUE(!!Err4);
+  auto Err5 = Interp->Undo();
+  EXPECT_FALSE(Err5);
+  auto Err6 = Interp->Parse("int x = 24;");
+  EXPECT_TRUE(!!Err6);
+  auto Err7 = Interp->Parse("#define X 42");
+  EXPECT_TRUE(!!Err7);
+  auto Err8 = Interp->Undo();
+  EXPECT_FALSE(Err8);
+  auto Err9 = Interp->Parse("#define X 24");
+  EXPECT_TRUE(!!Err9);
+
+  // Undo input contains errors.
+  auto Err10 = Interp->Parse("int y = ;");
+  EXPECT_FALSE(!!Err10);
+  EXPECT_EQ("Parsing failed.", llvm::toString(Err10.takeError()));
+  auto Err11 = Interp->Parse("int y = 42;");
+  EXPECT_TRUE(!!Err11);
+  auto Err12 = Interp->Undo();
+  EXPECT_FALSE(Err12);
+}
+
 static std::string MangleName(NamedDecl *ND) {
   ASTContext  = ND->getASTContext();
   std::unique_ptr MangleC(C.createMangleContext());
Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -92,8 +92,14 @@
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
 while (llvm::Optional Line = LE.readLine()) {
-  if (*Line == "quit")
+  if (*Line == R"(%quit)")
 break;
+  if (*Line == R"(%undo)") {
+if (auto Err = Interp->Undo())
+  llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+continue;
+  }
+
   if (auto Err = Interp->ParseAndExecute(*Line))
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
 }
Index: clang/test/Interpreter/sanity.c
===
--- clang/test/Interpreter/sanity.c
+++ clang/test/Interpreter/sanity.c
@@ -15,4 +15,4 @@
 // CHECK-NEXT: UnaryOperator{{.*}} 'int' lvalue prefix '++'
 // CHECK-NEXT:   DeclRefExpr{{.*}} 'int' lvalue Var [[var_ptr]] 'TestVar' 'int'
 
-quit
+%quit
Index: clang/test/Interpreter/plugins.cpp
===
--- clang/test/Interpreter/plugins.cpp
+++ clang/test/Interpreter/plugins.cpp
@@ -6,8 +6,7 @@
 int i = 10;
 extern "C" int printf(const char*,...);
 auto r1 = printf("i = %d\n", i);
-quit
-
+%quit
 
 // CHECK: top-level-decl: "i"
 // CHECK-NEXT: top-level-decl: "r1"
Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -18,4 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-quit
+%quit
Index: clang/test/Interpreter/code-undo.cpp
===
--- clang/test/Interpreter/code-undo.cpp
+++ clang/test/Interpreter/code-undo.cpp
@@ -1,4 +1,3 @@
-// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
@@ -6,16 +5,19 @@
 // CHECK-DRIVER: i = 10
 // RUN: 

[PATCH] D128589: [clang-repl] Support destructors of global objects.

2022-06-26 Thread Sunho Kim via Phabricator via cfe-commits
sunho updated this revision to Diff 440047.

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

https://reviews.llvm.org/D128589

Files:
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/test/Interpreter/execute.cpp
  clang/tools/clang-repl/ClangRepl.cpp
  clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp

Index: clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
===
--- clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
+++ clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
@@ -48,6 +48,7 @@
 TEST(InterpreterTest, CatchException) {
   llvm::InitializeNativeTarget();
   llvm::InitializeNativeTargetAsmPrinter();
+  llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
 
   {
 auto J = llvm::orc::LLJITBuilder().create();
@@ -131,8 +132,6 @@
   EXPECT_ANY_THROW(ThrowException());
   std::string CapturedStdOut = testing::internal::GetCapturedStdout();
   EXPECT_EQ(CapturedStdOut, "Caught: 'To be caught in JIT'\n");
-
-  llvm::llvm_shutdown();
 }
 
 } // end anonymous namespace
Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -70,6 +70,8 @@
   ExitOnErr.setBanner("clang-repl: ");
   llvm::cl::ParseCommandLineOptions(argc, argv);
 
+  llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+
   std::vector ClangArgv(ClangArgs.size());
   std::transform(ClangArgs.begin(), ClangArgs.end(), ClangArgv.begin(),
  [](const std::string ) -> const char * { return s.data(); });
@@ -121,7 +123,5 @@
   // later errors use the default handling behavior instead.
   llvm::remove_fatal_error_handler();
 
-  llvm::llvm_shutdown();
-
   return checkDiagErrors(Interp->getCompilerInstance());
 }
Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -1,3 +1,4 @@
+// clang-format off
 // RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
@@ -18,4 +19,7 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
+struct D { float f = 1.0; D *m = nullptr; D(){} ~D() { printf("D[f=%f, m=0x%llx]\n", f, reinterpret_cast(m)); }} d;
+// CHECK: D[f=1.00, m=0x0]
+
 quit
Index: clang/lib/Interpreter/Interpreter.cpp
===
--- clang/lib/Interpreter/Interpreter.cpp
+++ clang/lib/Interpreter/Interpreter.cpp
@@ -183,7 +183,14 @@
*TSCtx->getContext(), Err);
 }
 
-Interpreter::~Interpreter() {}
+Interpreter::~Interpreter() {
+  if (IncrExecutor) {
+if (llvm::Error Err = IncrExecutor->cleanUp())
+  llvm::report_fatal_error(
+  llvm::Twine("Failed to clean up IncrementalExecutor: ") +
+  toString(std::move(Err)));
+  }
+}
 
 llvm::Expected>
 Interpreter::create(std::unique_ptr CI) {
Index: clang/lib/Interpreter/IncrementalExecutor.h
===
--- clang/lib/Interpreter/IncrementalExecutor.h
+++ clang/lib/Interpreter/IncrementalExecutor.h
@@ -43,6 +43,7 @@
 
   llvm::Error addModule(std::unique_ptr M);
   llvm::Error runCtors() const;
+  llvm::Error cleanUp();
   llvm::Expected
   getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
   llvm::orc::LLJIT *getExecutionEngine() const { return Jit.get(); }
Index: clang/lib/Interpreter/IncrementalExecutor.cpp
===
--- clang/lib/Interpreter/IncrementalExecutor.cpp
+++ clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -52,6 +52,12 @@
 
 IncrementalExecutor::~IncrementalExecutor() {}
 
+// Clean up the JIT instance.
+llvm::Error IncrementalExecutor::cleanUp() {
+  // This calls the global dtors of registered modules.
+  return Jit->deinitialize(Jit->getMainJITDylib());
+}
+
 llvm::Error IncrementalExecutor::addModule(std::unique_ptr M) {
   return Jit->addIRModule(llvm::orc::ThreadSafeModule(std::move(M), TSCtx));
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126682: [clang-repl] Implement code undo

2022-06-26 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 440043.
junaire edited the summary of this revision.
junaire added a comment.

Rename CleanupPTU => CleanUpPTU


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126682

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/test/Interpreter/code-undo.cpp
  clang/test/Interpreter/execute.cpp
  clang/test/Interpreter/plugins.cpp
  clang/test/Interpreter/sanity.c
  clang/tools/clang-repl/ClangRepl.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -128,6 +128,50 @@
   EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
 }
 
+TEST(InterpreterTest, UndoCommand) {
+  Args ExtraArgs = {"-Xclang", "-diagnostic-log-file", "-Xclang", "-"};
+
+  // Create the diagnostic engine with unowned consumer.
+  std::string DiagnosticOutput;
+  llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
+  auto DiagPrinter = std::make_unique(
+  DiagnosticsOS, new DiagnosticOptions());
+
+  auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
+
+  // Fail to undo.
+  auto Err1 = Interp->Undo();
+  EXPECT_EQ("Operation failed. Too many undos",
+llvm::toString(std::move(Err1)));
+  auto Err2 = Interp->Parse("int foo = 42;");
+  EXPECT_TRUE(!!Err2);
+  auto Err3 = Interp->Undo(2);
+  EXPECT_EQ("Operation failed. Too many undos",
+llvm::toString(std::move(Err3)));
+
+  // Succeed to undo.
+  auto Err4 = Interp->Parse("int x = 42;");
+  EXPECT_TRUE(!!Err4);
+  auto Err5 = Interp->Undo();
+  EXPECT_FALSE(!!Err5);
+  auto Err6 = Interp->Parse("int x = 24;");
+  EXPECT_TRUE(!!Err6);
+  auto Err7 = Interp->Parse("#define X 42");
+  EXPECT_TRUE(!!Err7);
+  auto Err8 = Interp->Undo();
+  EXPECT_FALSE(!!Err8);
+  auto Err9 = Interp->Parse("#define X 24");
+  EXPECT_TRUE(!!Err9);
+
+  // Undo input contains errors.
+  auto Err10 = Interp->Parse("int y = ;");
+  EXPECT_FALSE(!!Err10);
+  auto Err11 = Interp->Parse("int y = 42;");
+  EXPECT_TRUE(!!Err11);
+  auto Err12 = Interp->Undo();
+  EXPECT_FALSE(!!Err12);
+}
+
 static std::string MangleName(NamedDecl *ND) {
   ASTContext  = ND->getASTContext();
   std::unique_ptr MangleC(C.createMangleContext());
Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -92,8 +92,14 @@
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
 while (llvm::Optional Line = LE.readLine()) {
-  if (*Line == "quit")
+  if (*Line == R"(%quit)")
 break;
+  if (*Line == R"(%undo)") {
+if (auto Err = Interp->Undo())
+  llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+continue;
+  }
+
   if (auto Err = Interp->ParseAndExecute(*Line))
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
 }
Index: clang/test/Interpreter/sanity.c
===
--- clang/test/Interpreter/sanity.c
+++ clang/test/Interpreter/sanity.c
@@ -15,4 +15,4 @@
 // CHECK-NEXT: UnaryOperator{{.*}} 'int' lvalue prefix '++'
 // CHECK-NEXT:   DeclRefExpr{{.*}} 'int' lvalue Var [[var_ptr]] 'TestVar' 'int'
 
-quit
+%quit
Index: clang/test/Interpreter/plugins.cpp
===
--- clang/test/Interpreter/plugins.cpp
+++ clang/test/Interpreter/plugins.cpp
@@ -6,8 +6,7 @@
 int i = 10;
 extern "C" int printf(const char*,...);
 auto r1 = printf("i = %d\n", i);
-quit
-
+%quit
 
 // CHECK: top-level-decl: "i"
 // CHECK-NEXT: top-level-decl: "r1"
Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -18,4 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-quit
+%quit
Index: clang/test/Interpreter/code-undo.cpp
===
--- clang/test/Interpreter/code-undo.cpp
+++ clang/test/Interpreter/code-undo.cpp
@@ -1,4 +1,3 @@
-// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
@@ -6,16 +5,19 @@
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | 

[PATCH] D127873: [clang-format] Fix misplacement of `*` in declaration of pointer to struct

2022-06-26 Thread Jack Huang via Phabricator via cfe-commits
jackhong12 added a comment.

Got it. Thanks for your reply!


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

https://reviews.llvm.org/D127873

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


[PATCH] D126682: [clang-repl] Implement undo command

2022-06-26 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 440042.
junaire added a comment.

Update commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126682

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/test/Interpreter/code-undo.cpp
  clang/test/Interpreter/execute.cpp
  clang/test/Interpreter/plugins.cpp
  clang/test/Interpreter/sanity.c
  clang/tools/clang-repl/ClangRepl.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -128,6 +128,50 @@
   EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
 }
 
+TEST(InterpreterTest, UndoCommand) {
+  Args ExtraArgs = {"-Xclang", "-diagnostic-log-file", "-Xclang", "-"};
+
+  // Create the diagnostic engine with unowned consumer.
+  std::string DiagnosticOutput;
+  llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
+  auto DiagPrinter = std::make_unique(
+  DiagnosticsOS, new DiagnosticOptions());
+
+  auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
+
+  // Fail to undo.
+  auto Err1 = Interp->Undo();
+  EXPECT_EQ("Operation failed. Too many undos",
+llvm::toString(std::move(Err1)));
+  auto Err2 = Interp->Parse("int foo = 42;");
+  EXPECT_TRUE(!!Err2);
+  auto Err3 = Interp->Undo(2);
+  EXPECT_EQ("Operation failed. Too many undos",
+llvm::toString(std::move(Err3)));
+
+  // Succeed to undo.
+  auto Err4 = Interp->Parse("int x = 42;");
+  EXPECT_TRUE(!!Err4);
+  auto Err5 = Interp->Undo();
+  EXPECT_FALSE(!!Err5);
+  auto Err6 = Interp->Parse("int x = 24;");
+  EXPECT_TRUE(!!Err6);
+  auto Err7 = Interp->Parse("#define X 42");
+  EXPECT_TRUE(!!Err7);
+  auto Err8 = Interp->Undo();
+  EXPECT_FALSE(!!Err8);
+  auto Err9 = Interp->Parse("#define X 24");
+  EXPECT_TRUE(!!Err9);
+
+  // Undo input contains errors.
+  auto Err10 = Interp->Parse("int y = ;");
+  EXPECT_FALSE(!!Err10);
+  auto Err11 = Interp->Parse("int y = 42;");
+  EXPECT_TRUE(!!Err11);
+  auto Err12 = Interp->Undo();
+  EXPECT_FALSE(!!Err12);
+}
+
 static std::string MangleName(NamedDecl *ND) {
   ASTContext  = ND->getASTContext();
   std::unique_ptr MangleC(C.createMangleContext());
Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -92,8 +92,14 @@
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
 while (llvm::Optional Line = LE.readLine()) {
-  if (*Line == "quit")
+  if (*Line == R"(%quit)")
 break;
+  if (*Line == R"(%undo)") {
+if (auto Err = Interp->Undo())
+  llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+continue;
+  }
+
   if (auto Err = Interp->ParseAndExecute(*Line))
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
 }
Index: clang/test/Interpreter/sanity.c
===
--- clang/test/Interpreter/sanity.c
+++ clang/test/Interpreter/sanity.c
@@ -15,4 +15,4 @@
 // CHECK-NEXT: UnaryOperator{{.*}} 'int' lvalue prefix '++'
 // CHECK-NEXT:   DeclRefExpr{{.*}} 'int' lvalue Var [[var_ptr]] 'TestVar' 'int'
 
-quit
+%quit
Index: clang/test/Interpreter/plugins.cpp
===
--- clang/test/Interpreter/plugins.cpp
+++ clang/test/Interpreter/plugins.cpp
@@ -6,8 +6,7 @@
 int i = 10;
 extern "C" int printf(const char*,...);
 auto r1 = printf("i = %d\n", i);
-quit
-
+%quit
 
 // CHECK: top-level-decl: "i"
 // CHECK-NEXT: top-level-decl: "r1"
Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -18,4 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-quit
+%quit
Index: clang/test/Interpreter/code-undo.cpp
===
--- clang/test/Interpreter/code-undo.cpp
+++ clang/test/Interpreter/code-undo.cpp
@@ -1,4 +1,3 @@
-// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
@@ -6,16 +5,19 @@
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);

[PATCH] D126682: [clang-repl] Implement undo command

2022-06-26 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 440038.
junaire added a comment.

- Update a comment
- Add a FIXME back


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126682

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/test/Interpreter/code-undo.cpp
  clang/test/Interpreter/execute.cpp
  clang/test/Interpreter/plugins.cpp
  clang/test/Interpreter/sanity.c
  clang/tools/clang-repl/ClangRepl.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -128,6 +128,50 @@
   EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
 }
 
+TEST(InterpreterTest, UndoCommand) {
+  Args ExtraArgs = {"-Xclang", "-diagnostic-log-file", "-Xclang", "-"};
+
+  // Create the diagnostic engine with unowned consumer.
+  std::string DiagnosticOutput;
+  llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
+  auto DiagPrinter = std::make_unique(
+  DiagnosticsOS, new DiagnosticOptions());
+
+  auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
+
+  // Fail to undo.
+  auto Err1 = Interp->Undo();
+  EXPECT_EQ("Operation failed. Too many undos",
+llvm::toString(std::move(Err1)));
+  auto Err2 = Interp->Parse("int foo = 42;");
+  EXPECT_TRUE(!!Err2);
+  auto Err3 = Interp->Undo(2);
+  EXPECT_EQ("Operation failed. Too many undos",
+llvm::toString(std::move(Err3)));
+
+  // Succeed to undo.
+  auto Err4 = Interp->Parse("int x = 42;");
+  EXPECT_TRUE(!!Err4);
+  auto Err5 = Interp->Undo();
+  EXPECT_FALSE(!!Err5);
+  auto Err6 = Interp->Parse("int x = 24;");
+  EXPECT_TRUE(!!Err6);
+  auto Err7 = Interp->Parse("#define X 42");
+  EXPECT_TRUE(!!Err7);
+  auto Err8 = Interp->Undo();
+  EXPECT_FALSE(!!Err8);
+  auto Err9 = Interp->Parse("#define X 24");
+  EXPECT_TRUE(!!Err9);
+
+  // Undo input contains errors.
+  auto Err10 = Interp->Parse("int y = ;");
+  EXPECT_FALSE(!!Err10);
+  auto Err11 = Interp->Parse("int y = 42;");
+  EXPECT_TRUE(!!Err11);
+  auto Err12 = Interp->Undo();
+  EXPECT_FALSE(!!Err12);
+}
+
 static std::string MangleName(NamedDecl *ND) {
   ASTContext  = ND->getASTContext();
   std::unique_ptr MangleC(C.createMangleContext());
Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -92,8 +92,14 @@
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
 while (llvm::Optional Line = LE.readLine()) {
-  if (*Line == "quit")
+  if (*Line == R"(%quit)")
 break;
+  if (*Line == R"(%undo)") {
+if (auto Err = Interp->Undo())
+  llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+continue;
+  }
+
   if (auto Err = Interp->ParseAndExecute(*Line))
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
 }
Index: clang/test/Interpreter/sanity.c
===
--- clang/test/Interpreter/sanity.c
+++ clang/test/Interpreter/sanity.c
@@ -15,4 +15,4 @@
 // CHECK-NEXT: UnaryOperator{{.*}} 'int' lvalue prefix '++'
 // CHECK-NEXT:   DeclRefExpr{{.*}} 'int' lvalue Var [[var_ptr]] 'TestVar' 'int'
 
-quit
+%quit
Index: clang/test/Interpreter/plugins.cpp
===
--- clang/test/Interpreter/plugins.cpp
+++ clang/test/Interpreter/plugins.cpp
@@ -6,8 +6,7 @@
 int i = 10;
 extern "C" int printf(const char*,...);
 auto r1 = printf("i = %d\n", i);
-quit
-
+%quit
 
 // CHECK: top-level-decl: "i"
 // CHECK-NEXT: top-level-decl: "r1"
Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -18,4 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-quit
+%quit
Index: clang/test/Interpreter/code-undo.cpp
===
--- clang/test/Interpreter/code-undo.cpp
+++ clang/test/Interpreter/code-undo.cpp
@@ -1,4 +1,3 @@
-// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
@@ -6,16 +5,19 @@
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int 

[PATCH] D126682: [Interpreter][clang-repl] Implement undo command

2022-06-26 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 440036.
junaire added a comment.

- Rename IncrementalParser::Restore to IncrementalParser::CleanupPTU
- Drop unused code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126682

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/test/Interpreter/code-undo.cpp
  clang/test/Interpreter/execute.cpp
  clang/test/Interpreter/plugins.cpp
  clang/test/Interpreter/sanity.c
  clang/tools/clang-repl/ClangRepl.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -128,6 +128,50 @@
   EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
 }
 
+TEST(InterpreterTest, UndoCommand) {
+  Args ExtraArgs = {"-Xclang", "-diagnostic-log-file", "-Xclang", "-"};
+
+  // Create the diagnostic engine with unowned consumer.
+  std::string DiagnosticOutput;
+  llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
+  auto DiagPrinter = std::make_unique(
+  DiagnosticsOS, new DiagnosticOptions());
+
+  auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
+
+  // Fail to undo.
+  auto Err1 = Interp->Undo();
+  EXPECT_EQ("Operation failed. Too many undos",
+llvm::toString(std::move(Err1)));
+  auto Err2 = Interp->Parse("int foo = 42;");
+  EXPECT_TRUE(!!Err2);
+  auto Err3 = Interp->Undo(2);
+  EXPECT_EQ("Operation failed. Too many undos",
+llvm::toString(std::move(Err3)));
+
+  // Succeed to undo.
+  auto Err4 = Interp->Parse("int x = 42;");
+  EXPECT_TRUE(!!Err4);
+  auto Err5 = Interp->Undo();
+  EXPECT_FALSE(!!Err5);
+  auto Err6 = Interp->Parse("int x = 24;");
+  EXPECT_TRUE(!!Err6);
+  auto Err7 = Interp->Parse("#define X 42");
+  EXPECT_TRUE(!!Err7);
+  auto Err8 = Interp->Undo();
+  EXPECT_FALSE(!!Err8);
+  auto Err9 = Interp->Parse("#define X 24");
+  EXPECT_TRUE(!!Err9);
+
+  // Undo input contains errors.
+  auto Err10 = Interp->Parse("int y = ;");
+  EXPECT_FALSE(!!Err10);
+  auto Err11 = Interp->Parse("int y = 42;");
+  EXPECT_TRUE(!!Err11);
+  auto Err12 = Interp->Undo();
+  EXPECT_FALSE(!!Err12);
+}
+
 static std::string MangleName(NamedDecl *ND) {
   ASTContext  = ND->getASTContext();
   std::unique_ptr MangleC(C.createMangleContext());
Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -92,8 +92,14 @@
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
 while (llvm::Optional Line = LE.readLine()) {
-  if (*Line == "quit")
+  if (*Line == R"(%quit)")
 break;
+  if (*Line == R"(%undo)") {
+if (auto Err = Interp->Undo())
+  llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+continue;
+  }
+
   if (auto Err = Interp->ParseAndExecute(*Line))
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
 }
Index: clang/test/Interpreter/sanity.c
===
--- clang/test/Interpreter/sanity.c
+++ clang/test/Interpreter/sanity.c
@@ -15,4 +15,4 @@
 // CHECK-NEXT: UnaryOperator{{.*}} 'int' lvalue prefix '++'
 // CHECK-NEXT:   DeclRefExpr{{.*}} 'int' lvalue Var [[var_ptr]] 'TestVar' 'int'
 
-quit
+%quit
Index: clang/test/Interpreter/plugins.cpp
===
--- clang/test/Interpreter/plugins.cpp
+++ clang/test/Interpreter/plugins.cpp
@@ -6,8 +6,7 @@
 int i = 10;
 extern "C" int printf(const char*,...);
 auto r1 = printf("i = %d\n", i);
-quit
-
+%quit
 
 // CHECK: top-level-decl: "i"
 // CHECK-NEXT: top-level-decl: "r1"
Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -18,4 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-quit
+%quit
Index: clang/test/Interpreter/code-undo.cpp
===
--- clang/test/Interpreter/code-undo.cpp
+++ clang/test/Interpreter/code-undo.cpp
@@ -1,4 +1,3 @@
-// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
@@ -6,16 +5,19 @@
 // CHECK-DRIVER: i = 10
 // RUN: cat %s |