[clang] fad6e37 - [Lex] Fix crash during dependency scanning while skipping an unmatched `#if`

2022-05-28 Thread Argyrios Kyrtzidis via cfe-commits

Author: Argyrios Kyrtzidis
Date: 2022-05-27T23:59:30-07:00
New Revision: fad6e37995b461a7750bdc203aad37eca9532fd5

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

LOG: [Lex] Fix crash during dependency scanning while skipping an unmatched 
`#if`

Added: 
clang/test/ClangScanDeps/skipping-unmatched-if.c

Modified: 
clang/lib/Lex/Lexer.cpp

Removed: 




diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index a0a7a6ae789b..d4601261b58b 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -4223,6 +4223,7 @@ bool 
Lexer::LexDependencyDirectiveTokenWhileSkipping(Token &Result) {
   }
   break;
 case pp_eof:
+  NextDepDirectiveTokenIndex = 0;
   return LexEndOfFile(Result, BufferEnd);
 }
   } while (!Stop);

diff  --git a/clang/test/ClangScanDeps/skipping-unmatched-if.c 
b/clang/test/ClangScanDeps/skipping-unmatched-if.c
new file mode 100644
index ..fec7857d6bfd
--- /dev/null
+++ b/clang/test/ClangScanDeps/skipping-unmatched-if.c
@@ -0,0 +1,27 @@
+// Check dependency scanning when skipping an unmatched #if
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: not clang-scan-deps -compilation-database %t/cdb.json 2>&1 | FileCheck 
%s
+// CHECK: header1.h:1:2: error: unterminated conditional directive
+
+//--- cdb.json.template
+[{
+  "directory" : "DIR",
+  "command" : "clang -target x86_64-apple-macosx10.7 -c DIR/test.cpp -o 
DIR/test.o",
+  "file" : "DIR/test.o"
+}]
+
+//--- test.cpp
+#include "header1.h"
+#include "header2.h"
+
+//--- header1.h
+#if 0
+
+//--- header2.h
+#ifndef _HEADER2_H_
+#define _HEADER2_H_
+#endif



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


[PATCH] D126183: Implement soft reset of the diagnostics engine.

2022-05-28 Thread Tapasweni Pathak via Phabricator via cfe-commits
tapaswenipathak updated this revision to Diff 432711.
tapaswenipathak added a comment.

Addresses review comment by @rsmith: https://reviews.llvm.org/D126183#3534846.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126183

Files:
  include/clang/Basic/Diagnostic.h
  lib/Basic/Diagnostic.cpp
  test/Interpreter/error-recovery-pragmas.cpp
  tools/clang-repl/ClangRepl.cpp
  unittests/Basic/DiagnosticTest.cpp

Index: unittests/Basic/DiagnosticTest.cpp
===
--- unittests/Basic/DiagnosticTest.cpp
+++ unittests/Basic/DiagnosticTest.cpp
@@ -14,8 +14,18 @@
 using namespace llvm;
 using namespace clang;
 
+
 namespace {
 
+void DiagnosticsEngine::DiagnosticTestHelper() {
+  unsigned delayedDiagID = 0U;
+
+  EXPECT_EQ(this.DelayedDiagID, delayedDiagID);
+  EXPECT_FALSE(this.DiagStates.empty());
+  EXPECT_FALSE(this.DiagStatesByLoc.empty());
+  EXPECT_FALSE(this.DiagStateOnPushStack.empty());
+}
+
 // Check that DiagnosticErrorTrap works with SuppressAllDiagnostics.
 TEST(DiagnosticTest, suppressAndTrap) {
   DiagnosticsEngine Diags(new DiagnosticIDs(),
@@ -71,6 +81,32 @@
 EXPECT_EQ(Diags.getNumWarnings(), FatalsAsError);
   }
 }
+
+// Check that soft RESET works as intended
+TEST(DiagnosticTest, softReset) {
+  DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
+  new IgnoringDiagConsumer());
+
+  unsigned numWarnings = 0U, numErrors = 0U;
+
+  Diags.Reset(true);
+  // Check For ErrorOccurred and TrapNumErrorsOccurred
+  EXPECT_FALSE(Diags.hasErrorOccurred());
+  EXPECT_FALSE(Diags.hasFatalErrorOccurred());
+  EXPECT_FALSE(Diags.hasUncompilableErrorOccurred());
+  // Check for UnrecoverableErrorOccurred and TrapNumUnrecoverableErrorsOccurred
+  EXPECT_FALSE(Diags.hasUnrecoverableErrorOccurred());
+
+  EXPECT_EQ(Diags.getNumWarnings(), numWarnings);
+  EXPECT_EQ(Diags.getNumErrors(), numErrors);
+
+  // Check for private variables of DiagnosticsEngine differentiating soft reset
+  Diags.DiagnosticTestHelper();
+
+  EXPECT_FALSE(Diags.isDiagnosticInFlight());
+  EXPECT_TRUE(Diags.isLastDiagnosticIgnored());
+}
+
 TEST(DiagnosticTest, diagnosticError) {
   DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
   new IgnoringDiagConsumer());
Index: tools/clang-repl/ClangRepl.cpp
===
--- tools/clang-repl/ClangRepl.cpp
+++ tools/clang-repl/ClangRepl.cpp
@@ -86,14 +86,17 @@
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  bool hadErrors = false;
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
 while (llvm::Optional Line = LE.readLine()) {
   if (*Line == "quit")
 break;
-  if (auto Err = Interp->ParseAndExecute(*Line))
+  if (auto Err = Interp->ParseAndExecute(*Line)) {
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+hadErrors = true;
+  }
 }
   }
 
@@ -104,5 +107,5 @@
 
   llvm::llvm_shutdown();
 
-  return 0;
+  return hadErrors;
 }
Index: test/Interpreter/error-recovery-pragmas.cpp
===
--- /dev/null
+++ test/Interpreter/error-recovery-pragmas.cpp
@@ -0,0 +1,6 @@
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wmultichar"
+// Reset should not delete #pragmas
+error; // expected-error {{use of undeclared identifier}}
+void no_diag_multichar(void) { char c = (char)'ab'; }
Index: lib/Basic/Diagnostic.cpp
===
--- lib/Basic/Diagnostic.cpp
+++ lib/Basic/Diagnostic.cpp
@@ -130,7 +130,7 @@
   return true;
 }
 
-void DiagnosticsEngine::Reset() {
+void DiagnosticsEngine::Reset(bool soft /*=false*/) {
   ErrorOccurred = false;
   UncompilableErrorOccurred = false;
   FatalErrorOccurred = false;
@@ -145,15 +145,17 @@
   LastDiagLevel = DiagnosticIDs::Ignored;
   DelayedDiagID = 0;
 
-  // Clear state related to #pragma diagnostic.
-  DiagStates.clear();
-  DiagStatesByLoc.clear();
-  DiagStateOnPushStack.clear();
+  if (!soft) {
+// Clear state related to #pragma diagnostic.
+DiagStates.clear();
+DiagStatesByLoc.clear();
+DiagStateOnPushStack.clear();
 
-  // Create a DiagState and DiagStatePoint representing diagnostic changes
-  // through command-line.
-  DiagStates.emplace_back();
-  DiagStatesByLoc.appendFirst(&DiagStates.back());
+// Create a DiagState and DiagStatePoint representing diagnostic changes
+// through command-line.
+DiagStates.emplace_back();
+DiagStatesByLoc.appendFirst(&DiagStates.back());
+  }
 }
 
 void DiagnosticsEngine::SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1,
Index: include/clang/Basic/Diagnostic.h

[PATCH] D126183: Implement soft reset of the diagnostics engine.

2022-05-28 Thread Tapasweni Pathak via Phabricator via cfe-commits
tapaswenipathak updated this revision to Diff 432712.
tapaswenipathak added a comment.

runs clang-format on the diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126183

Files:
  include/clang/Basic/Diagnostic.h
  lib/Basic/Diagnostic.cpp
  test/Interpreter/error-recovery-pragmas.cpp
  tools/clang-repl/ClangRepl.cpp
  unittests/Basic/DiagnosticTest.cpp

Index: unittests/Basic/DiagnosticTest.cpp
===
--- unittests/Basic/DiagnosticTest.cpp
+++ unittests/Basic/DiagnosticTest.cpp
@@ -16,6 +16,15 @@
 
 namespace {
 
+void DiagnosticsEngine::DiagnosticTestHelper() {
+  unsigned delayedDiagID = 0U;
+
+  EXPECT_EQ(this.DelayedDiagID, delayedDiagID);
+  EXPECT_FALSE(this.DiagStates.empty());
+  EXPECT_FALSE(this.DiagStatesByLoc.empty());
+  EXPECT_FALSE(this.DiagStateOnPushStack.empty());
+}
+
 // Check that DiagnosticErrorTrap works with SuppressAllDiagnostics.
 TEST(DiagnosticTest, suppressAndTrap) {
   DiagnosticsEngine Diags(new DiagnosticIDs(),
@@ -71,6 +80,32 @@
 EXPECT_EQ(Diags.getNumWarnings(), FatalsAsError);
   }
 }
+
+// Check that soft RESET works as intended
+TEST(DiagnosticTest, softReset) {
+  DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
+  new IgnoringDiagConsumer());
+
+  unsigned numWarnings = 0U, numErrors = 0U;
+
+  Diags.Reset(true);
+  // Check For ErrorOccurred and TrapNumErrorsOccurred
+  EXPECT_FALSE(Diags.hasErrorOccurred());
+  EXPECT_FALSE(Diags.hasFatalErrorOccurred());
+  EXPECT_FALSE(Diags.hasUncompilableErrorOccurred());
+  // Check for UnrecoverableErrorOccurred and TrapNumUnrecoverableErrorsOccurred
+  EXPECT_FALSE(Diags.hasUnrecoverableErrorOccurred());
+
+  EXPECT_EQ(Diags.getNumWarnings(), numWarnings);
+  EXPECT_EQ(Diags.getNumErrors(), numErrors);
+
+  // Check for private variables of DiagnosticsEngine differentiating soft reset
+  Diags.DiagnosticTestHelper();
+
+  EXPECT_FALSE(Diags.isDiagnosticInFlight());
+  EXPECT_TRUE(Diags.isLastDiagnosticIgnored());
+}
+
 TEST(DiagnosticTest, diagnosticError) {
   DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
   new IgnoringDiagConsumer());
Index: tools/clang-repl/ClangRepl.cpp
===
--- tools/clang-repl/ClangRepl.cpp
+++ tools/clang-repl/ClangRepl.cpp
@@ -86,14 +86,17 @@
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  bool hadErrors = false;
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
 while (llvm::Optional Line = LE.readLine()) {
   if (*Line == "quit")
 break;
-  if (auto Err = Interp->ParseAndExecute(*Line))
+  if (auto Err = Interp->ParseAndExecute(*Line)) {
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+hadErrors = true;
+  }
 }
   }
 
@@ -104,5 +107,5 @@
 
   llvm::llvm_shutdown();
 
-  return 0;
+  return hadErrors;
 }
Index: test/Interpreter/error-recovery-pragmas.cpp
===
--- /dev/null
+++ test/Interpreter/error-recovery-pragmas.cpp
@@ -0,0 +1,6 @@
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wmultichar"
+// Reset should not delete #pragmas
+error; // expected-error {{use of undeclared identifier}}
+void no_diag_multichar(void) { char c = (char)'ab'; }
Index: lib/Basic/Diagnostic.cpp
===
--- lib/Basic/Diagnostic.cpp
+++ lib/Basic/Diagnostic.cpp
@@ -130,7 +130,7 @@
   return true;
 }
 
-void DiagnosticsEngine::Reset() {
+void DiagnosticsEngine::Reset(bool soft /*=false*/) {
   ErrorOccurred = false;
   UncompilableErrorOccurred = false;
   FatalErrorOccurred = false;
@@ -145,15 +145,17 @@
   LastDiagLevel = DiagnosticIDs::Ignored;
   DelayedDiagID = 0;
 
-  // Clear state related to #pragma diagnostic.
-  DiagStates.clear();
-  DiagStatesByLoc.clear();
-  DiagStateOnPushStack.clear();
+  if (!soft) {
+// Clear state related to #pragma diagnostic.
+DiagStates.clear();
+DiagStatesByLoc.clear();
+DiagStateOnPushStack.clear();
 
-  // Create a DiagState and DiagStatePoint representing diagnostic changes
-  // through command-line.
-  DiagStates.emplace_back();
-  DiagStatesByLoc.appendFirst(&DiagStates.back());
+// Create a DiagState and DiagStatePoint representing diagnostic changes
+// through command-line.
+DiagStates.emplace_back();
+DiagStatesByLoc.appendFirst(&DiagStates.back());
+  }
 }
 
 void DiagnosticsEngine::SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1,
Index: include/clang/Basic/Diagnostic.h
===
--- include/clang/Basic/Diagnostic.h
+++ 

[PATCH] D116593: Fix `performance-unnecessary-value-param` for template specialization

2022-05-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM aside from a very minor nit that can be corrected when landing.




Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp:143
   isReferencedOutsideOfCallExpr(*Function, *Result.Context) ||
-  isExplicitTemplateSpecialization(*Function))
+  (Function->getTemplatedKind() != FunctionDecl::TK_NonTemplate))
 return;

No need for the extra parens.


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

https://reviews.llvm.org/D116593

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


[PATCH] D125802: Fix std::has_unique_object_representations for _BitInt types with padding bits

2022-05-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM as well -- do you need someone to commit on your behalf? If so, what name 
and email address would you like used for patch attribution?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125802

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


[PATCH] D126084: [Sema] Reject implicit conversions between different scoped enum types in list initialization

2022-05-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:4506
 !S.Context.hasSameUnqualifiedType(E->getType(), DestType) &&
-(E->getType()->isIntegralOrEnumerationType() ||
+(E->getType()->isIntegralOrUnscopedEnumerationType() ||
  E->getType()->isFloatingType())) {

ahatanak wrote:
> ahatanak wrote:
> > aaron.ballman wrote:
> > > ahatanak wrote:
> > > > aaron.ballman wrote:
> > > > > This doesn't match the comments immediately above here and I don't 
> > > > > think is the correct fix.
> > > > > 
> > > > > We're handling this case: http://eel.is/c++draft/dcl.init.list#3.8
> > > > > 
> > > > > A scoped enumeration has a fixed underlying type 
> > > > > (https://eel.is/c++draft/dcl.enum#5.sentence-5). The initializer list 
> > > > > has a single element and that element can be implicitly converted to 
> > > > > the underlying type (`int` in all of the test cases changed in this 
> > > > > patch). And this is a direct initialization case, so I think we 
> > > > > should be performing the conversion here rather than skipping to the 
> > > > > next bullet.
> > > > Can scoped enums be implicitly converted to integer types? Unscoped 
> > > > enums can be converted to an integer type, but I don't see any mention 
> > > > of scoped enums here: https://eel.is/c++draft/conv.integral
> > > > 
> > > > It seems that the original paper was trying to change the rules about 
> > > > conversions from the underlying type to a scoped enum. It doesn't look 
> > > > like it's allowing conversion from a scope enum to another scope enum.
> > > > 
> > > > https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0138r2.pdf
> > > > Can scoped enums be implicitly converted to integer types? Unscoped 
> > > > enums can be converted to an integer type, but I don't see any mention 
> > > > of scoped enums here: https://eel.is/c++draft/conv.integral
> > > 
> > > Correct, they cannot be implicitly converted to an integer.
> > > 
> > > > It seems that the original paper was trying to change the rules about 
> > > > conversions from the underlying type to a scoped enum. It doesn't look 
> > > > like it's allowing conversion from a scope enum to another scope enum.
> > > 
> > > Agreed, however, I think where we want this to fail is below in the 
> > > attempt at conversion. "v can be implicitly converted to U" is the part 
> > > that should be failing here, and we're now skipping over the bit of code 
> > > that's checking whether the implicit conversion is valid.
> > Is the code below checking whether the implicit conversion is valid? It 
> > looks like it's assuming the implicit conversion is valid and adding an 
> > implicit conversion sequence based on that assumption. If the source is an 
> > integer, unscoped enum, or floating type, the implicit conversion that is 
> > performed later should succeed except when there is narrowing.
> > 
> > Or are you suggesting we should add a check to 
> > `Sema::PerformImplicitConversion` that rejects conversions from scoped 
> > enums to other types? It seems to me that it's better to detect the error 
> > earlier.
> Alternatively, we can emit a diagnostic in the code below that specifically 
> calls out conversion from scoped enums to integer types.
> Is the code below checking whether the implicit conversion is valid? 

It's forming the conversion sequence as-if it must be valid, but that causes us 
to get the right diagnostics. We do the same for narrowing float conversions: 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaInit.cpp#L4521
 and I would expect us to then need changes so we get to here: 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaInit.cpp#L8478


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126084

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


[PATCH] D126183: Implement soft reset of the diagnostics engine.

2022-05-28 Thread Tapasweni Pathak via Phabricator via cfe-commits
tapaswenipathak updated this revision to Diff 432723.
tapaswenipathak added a comment.

Fixes F23230194: Screenshot 2022-05-28 at 7.18.51 PM.png 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126183

Files:
  clang/include/clang/Basic/Diagnostic.h
  clang/lib/Basic/Diagnostic.cpp
  clang/test/Interpreter/error-recovery-pragmas.cpp
  clang/tools/clang-repl/ClangRepl.cpp
  clang/unittests/Basic/DiagnosticTest.cpp

Index: clang/unittests/Basic/DiagnosticTest.cpp
===
--- clang/unittests/Basic/DiagnosticTest.cpp
+++ clang/unittests/Basic/DiagnosticTest.cpp
@@ -14,6 +14,15 @@
 using namespace llvm;
 using namespace clang;
 
+void clang::DiagnosticsTestHelper(DiagnosticsEngine &diag) {
+  unsigned delayedDiagID = 0U;
+
+  EXPECT_EQ(diag.DelayedDiagID, delayedDiagID);
+  EXPECT_FALSE(diag.DiagStates.empty());
+  EXPECT_TRUE(diag.DiagStatesByLoc.empty());
+  EXPECT_TRUE(diag.DiagStateOnPushStack.empty());
+}
+
 namespace {
 
 // Check that DiagnosticErrorTrap works with SuppressAllDiagnostics.
@@ -71,6 +80,32 @@
 EXPECT_EQ(Diags.getNumWarnings(), FatalsAsError);
   }
 }
+
+// Check that soft RESET works as intended
+TEST(DiagnosticTest, softReset) {
+  DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
+  new IgnoringDiagConsumer());
+
+  unsigned numWarnings = 0U, numErrors = 0U;
+
+  Diags.Reset(true);
+  // Check For ErrorOccurred and TrapNumErrorsOccurred
+  EXPECT_FALSE(Diags.hasErrorOccurred());
+  EXPECT_FALSE(Diags.hasFatalErrorOccurred());
+  EXPECT_FALSE(Diags.hasUncompilableErrorOccurred());
+  // Check for UnrecoverableErrorOccurred and TrapNumUnrecoverableErrorsOccurred
+  EXPECT_FALSE(Diags.hasUnrecoverableErrorOccurred());
+
+  EXPECT_EQ(Diags.getNumWarnings(), numWarnings);
+  EXPECT_EQ(Diags.getNumErrors(), numErrors);
+
+  // Check for private variables of DiagnosticsEngine differentiating soft reset
+  DiagnosticTestHelper(Diags);
+
+  EXPECT_FALSE(Diags.isDiagnosticInFlight());
+  EXPECT_TRUE(Diags.isLastDiagnosticIgnored());
+}
+
 TEST(DiagnosticTest, diagnosticError) {
   DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
   new IgnoringDiagConsumer());
Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -86,14 +86,17 @@
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  bool hadErrors = false;
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
 while (llvm::Optional Line = LE.readLine()) {
   if (*Line == "quit")
 break;
-  if (auto Err = Interp->ParseAndExecute(*Line))
+  if (auto Err = Interp->ParseAndExecute(*Line)) {
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+hadErrors = true;
+  }
 }
   }
 
@@ -104,5 +107,5 @@
 
   llvm::llvm_shutdown();
 
-  return 0;
+  return hadErrors;
 }
Index: clang/test/Interpreter/error-recovery-pragmas.cpp
===
--- /dev/null
+++ clang/test/Interpreter/error-recovery-pragmas.cpp
@@ -0,0 +1,6 @@
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wmultichar"
+// Reset should not delete #pragmas
+error; // expected-error {{use of undeclared identifier}}
+void no_diag_multichar(void) { char c = (char)'ab'; }
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -130,7 +130,7 @@
   return true;
 }
 
-void DiagnosticsEngine::Reset() {
+void DiagnosticsEngine::Reset(bool soft /*=false*/) {
   ErrorOccurred = false;
   UncompilableErrorOccurred = false;
   FatalErrorOccurred = false;
@@ -145,15 +145,17 @@
   LastDiagLevel = DiagnosticIDs::Ignored;
   DelayedDiagID = 0;
 
-  // Clear state related to #pragma diagnostic.
-  DiagStates.clear();
-  DiagStatesByLoc.clear();
-  DiagStateOnPushStack.clear();
+  if (!soft) {
+// Clear state related to #pragma diagnostic.
+DiagStates.clear();
+DiagStatesByLoc.clear();
+DiagStateOnPushStack.clear();
 
-  // Create a DiagState and DiagStatePoint representing diagnostic changes
-  // through command-line.
-  DiagStates.emplace_back();
-  DiagStatesByLoc.appendFirst(&DiagStates.back());
+// Create a DiagState and DiagStatePoint representing diagnostic changes
+// through command-line.
+DiagStates.emplace_back();
+DiagStatesByLoc.appendFirst(&DiagStates.back());
+  }
 }
 
 void DiagnosticsEngine::SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1,
Index: clang/include/

[PATCH] D120495: [clang][dataflow] Add transfer functions for structured bindings

2022-05-28 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 432728.
sgatev added a comment.

Rebase main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120495

Files:
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3369,4 +3369,192 @@
   LangStandard::lang_cxx17, /*ApplyBuiltinTransfer=*/true, "operator=");
 }
 
+TEST_F(TransferTest, StructuredBindingAssignFromStructIntMembersToRefs) {
+  std::string Code = R"(
+struct A {
+  int Foo;
+  int Bar;
+};
+
+void target() {
+  int Qux;
+  A Baz;
+  Baz.Foo = Qux;
+  auto &FooRef = Baz.Foo;
+  auto &BarRef = Baz.Bar;
+  auto &[BoundFooRef, BoundBarRef] = Baz;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooRefDecl = findValueDecl(ASTCtx, "FooRef");
+ASSERT_THAT(FooRefDecl, NotNull());
+
+const ValueDecl *BarRefDecl = findValueDecl(ASTCtx, "BarRef");
+ASSERT_THAT(BarRefDecl, NotNull());
+
+const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ASSERT_THAT(QuxDecl, NotNull());
+
+const ValueDecl *BoundFooRefDecl = findValueDecl(ASTCtx, "BoundFooRef");
+ASSERT_THAT(BoundFooRefDecl, NotNull());
+
+const ValueDecl *BoundBarRefDecl = findValueDecl(ASTCtx, "BoundBarRef");
+ASSERT_THAT(BoundBarRefDecl, NotNull());
+
+const StorageLocation *FooRefLoc =
+Env.getStorageLocation(*FooRefDecl, SkipPast::Reference);
+ASSERT_THAT(FooRefLoc, NotNull());
+
+const StorageLocation *BarRefLoc =
+Env.getStorageLocation(*BarRefDecl, SkipPast::Reference);
+ASSERT_THAT(BarRefLoc, NotNull());
+
+const Value *QuxVal = Env.getValue(*QuxDecl, SkipPast::None);
+ASSERT_THAT(QuxVal, NotNull());
+
+const StorageLocation *BoundFooRefLoc =
+Env.getStorageLocation(*BoundFooRefDecl, SkipPast::Reference);
+EXPECT_EQ(BoundFooRefLoc, FooRefLoc);
+
+const StorageLocation *BoundBarRefLoc =
+Env.getStorageLocation(*BoundBarRefDecl, SkipPast::Reference);
+EXPECT_EQ(BoundBarRefLoc, BarRefLoc);
+
+EXPECT_EQ(Env.getValue(*BoundFooRefDecl, SkipPast::Reference), QuxVal);
+  });
+}
+
+TEST_F(TransferTest, StructuredBindingAssignFromStructRefMembersToRefs) {
+  std::string Code = R"(
+struct A {
+  int &Foo;
+  int &Bar;
+};
+
+void target(A Baz) {
+  int Qux;
+  Baz.Foo = Qux;
+  auto &FooRef = Baz.Foo;
+  auto &BarRef = Baz.Bar;
+  auto &[BoundFooRef, BoundBarRef] = Baz;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooRefDecl = findValueDecl(ASTCtx, "FooRef");
+ASSERT_THAT(FooRefDecl, NotNull());
+
+const ValueDecl *BarRefDecl = findValueDecl(ASTCtx, "BarRef");
+ASSERT_THAT(BarRefDecl, NotNull());
+
+const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ASSERT_THAT(QuxDecl, NotNull());
+
+const ValueDecl *BoundFooRefDecl = findValueDecl(ASTCtx, "BoundFooRef");
+ASSERT_THAT(BoundFooRefDecl, NotNull());
+
+const ValueDecl *BoundBarRefDecl = findValueDecl(ASTCtx, "BoundBarRef");
+ASSERT_THAT(BoundBarRefDecl, NotNull());
+
+const StorageLocation *FooRefLoc =
+Env.getStorageLocation(*FooRefDecl, SkipPast::Reference);
+ASSERT_THAT(FooRefLoc, NotNull());
+
+const StorageLocation *BarRefLoc =
+Env.getStorageLocation(*BarRefDecl, SkipPast::Reference);
+ASSERT_THAT(BarRefLoc, NotNull());
+
+const Value *QuxVal = Env.getValue(*QuxDecl, SkipPast::None);
+ASSERT_THAT(QuxVal, NotNull());
+
+const StorageLocation *BoundFooRefLoc =
+Env.getStorageLocation(*BoundFooRefDecl, SkipPast::Reference);
+EXPECT_EQ(BoundFooRefLoc, FooRefLoc);
+
+const StorageLocation *BoundBarRefLoc =
+Env.getStorageLocation(*BoundBarRefDecl, SkipPast::Reference);
+EXPECT_EQ(BoundBarRefLoc, BarRefLoc);
+
+EXPECT_EQ(Env.getValue(*BoundFooRefDecl, SkipPast::Reference), QuxVal);
+  });
+}
+
+TEST_F(TransferTest, StructuredBindingAssign

[PATCH] D120495: [clang][dataflow] Add transfer functions for structured bindings

2022-05-28 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 432731.
sgatev added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120495

Files:
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3369,4 +3369,192 @@
   LangStandard::lang_cxx17, /*ApplyBuiltinTransfer=*/true, "operator=");
 }
 
+TEST_F(TransferTest, StructuredBindingAssignFromStructIntMembersToRefs) {
+  std::string Code = R"(
+struct A {
+  int Foo;
+  int Bar;
+};
+
+void target() {
+  int Qux;
+  A Baz;
+  Baz.Foo = Qux;
+  auto &FooRef = Baz.Foo;
+  auto &BarRef = Baz.Bar;
+  auto &[BoundFooRef, BoundBarRef] = Baz;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooRefDecl = findValueDecl(ASTCtx, "FooRef");
+ASSERT_THAT(FooRefDecl, NotNull());
+
+const ValueDecl *BarRefDecl = findValueDecl(ASTCtx, "BarRef");
+ASSERT_THAT(BarRefDecl, NotNull());
+
+const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ASSERT_THAT(QuxDecl, NotNull());
+
+const ValueDecl *BoundFooRefDecl = findValueDecl(ASTCtx, "BoundFooRef");
+ASSERT_THAT(BoundFooRefDecl, NotNull());
+
+const ValueDecl *BoundBarRefDecl = findValueDecl(ASTCtx, "BoundBarRef");
+ASSERT_THAT(BoundBarRefDecl, NotNull());
+
+const StorageLocation *FooRefLoc =
+Env.getStorageLocation(*FooRefDecl, SkipPast::Reference);
+ASSERT_THAT(FooRefLoc, NotNull());
+
+const StorageLocation *BarRefLoc =
+Env.getStorageLocation(*BarRefDecl, SkipPast::Reference);
+ASSERT_THAT(BarRefLoc, NotNull());
+
+const Value *QuxVal = Env.getValue(*QuxDecl, SkipPast::None);
+ASSERT_THAT(QuxVal, NotNull());
+
+const StorageLocation *BoundFooRefLoc =
+Env.getStorageLocation(*BoundFooRefDecl, SkipPast::Reference);
+EXPECT_EQ(BoundFooRefLoc, FooRefLoc);
+
+const StorageLocation *BoundBarRefLoc =
+Env.getStorageLocation(*BoundBarRefDecl, SkipPast::Reference);
+EXPECT_EQ(BoundBarRefLoc, BarRefLoc);
+
+EXPECT_EQ(Env.getValue(*BoundFooRefDecl, SkipPast::Reference), QuxVal);
+  });
+}
+
+TEST_F(TransferTest, StructuredBindingAssignFromStructRefMembersToRefs) {
+  std::string Code = R"(
+struct A {
+  int &Foo;
+  int &Bar;
+};
+
+void target(A Baz) {
+  int Qux;
+  Baz.Foo = Qux;
+  auto &FooRef = Baz.Foo;
+  auto &BarRef = Baz.Bar;
+  auto &[BoundFooRef, BoundBarRef] = Baz;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooRefDecl = findValueDecl(ASTCtx, "FooRef");
+ASSERT_THAT(FooRefDecl, NotNull());
+
+const ValueDecl *BarRefDecl = findValueDecl(ASTCtx, "BarRef");
+ASSERT_THAT(BarRefDecl, NotNull());
+
+const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ASSERT_THAT(QuxDecl, NotNull());
+
+const ValueDecl *BoundFooRefDecl = findValueDecl(ASTCtx, "BoundFooRef");
+ASSERT_THAT(BoundFooRefDecl, NotNull());
+
+const ValueDecl *BoundBarRefDecl = findValueDecl(ASTCtx, "BoundBarRef");
+ASSERT_THAT(BoundBarRefDecl, NotNull());
+
+const StorageLocation *FooRefLoc =
+Env.getStorageLocation(*FooRefDecl, SkipPast::Reference);
+ASSERT_THAT(FooRefLoc, NotNull());
+
+const StorageLocation *BarRefLoc =
+Env.getStorageLocation(*BarRefDecl, SkipPast::Reference);
+ASSERT_THAT(BarRefLoc, NotNull());
+
+const Value *QuxVal = Env.getValue(*QuxDecl, SkipPast::None);
+ASSERT_THAT(QuxVal, NotNull());
+
+const StorageLocation *BoundFooRefLoc =
+Env.getStorageLocation(*BoundFooRefDecl, SkipPast::Reference);
+EXPECT_EQ(BoundFooRefLoc, FooRefLoc);
+
+const StorageLocation *BoundBarRefLoc =
+Env.getStorageLocation(*BoundBarRefDecl, SkipPast::Reference);
+EXPECT_EQ(BoundBarRefLoc, BarRefLoc);
+
+EXPECT_EQ(Env.getValue(*BoundFooRefDecl, SkipPast::Reference), QuxVal);
+  });
+}
+
+TEST_F(TransferTest, StructuredBindingA

[PATCH] D120495: [clang][dataflow] Add transfer functions for structured bindings

2022-05-28 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev marked 2 inline comments as done.
sgatev added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:80
+///
+/// FIXME: Consider adding support for structured bindings to the CFG builder.
+class DecompositionVisitor : public ConstStmtVisitor {

xazax.hun wrote:
> sgatev wrote:
> > xazax.hun wrote:
> > > Did you look into how hard would it be to add structured bindings to the 
> > > CFG builder? If the effort is comparable to this patch (and not 
> > > significantly bigger), it might be better to do that work instead of 
> > > spending effort on some temporary workaround. What do you think?
> > Circling back to this after a while. I believe we explored changing the CFG 
> > briefly, but don't have a fully fleshed out proposal for it. I recently 
> > noticed 
> > https://discourse.llvm.org/t/implement-support-for-c-17-structured-bindings-in-the-clang-static-analyzer/60588.
> >  It seems that part of the project is exploring necessary changes to the 
> > CFG. What do you think about submitting this patch with local pattern 
> > matching and revisiting that once the GSoC project completes?
> Officially, there is no candidate accepted for that project yet, so there is 
> no guarantee that we will have someone working on this. That being said, the 
> CSA devs started to discuss what would be the best way to represent 
> structured bindings in the CFG, and it is possible that for many of the cases 
> we do not actually need to change the CFG, because the AST nodes have rich 
> information. But of course, none of this is final, but we do not need to 
> block this patch on that. So I'm fine adding this for now.
> 
> The AST for the supported case looks like:
> ```
>`-DeclStmt 0x5599ad9de6b0 
>   `-DecompositionDecl 0x5599ad9de310  col:13 used 'A &' 
> cinit
> |-DeclRefExpr 0x5599ad9de388  'A' lvalue Var 0x5599ad9ddb80 
> 'Baz' 'A'
> |-BindingDecl 0x5599ad9de280  col:14 BoundFooRef 'int'
> | `-MemberExpr 0x5599ad9de630  'int' lvalue .Foo 
> 0x5599ad9dd970
> |   `-DeclRefExpr 0x5599ad9de610  'A':'A' lvalue 
> Decomposition 0x5599ad9de310 '' 'A &'
> `-BindingDecl 0x5599ad9de2c8  col:27 BoundBarRef 'int'
>   `-MemberExpr 0x5599ad9de680  'int' lvalue .Bar 
> 0x5599ad9dd9d8
> `-DeclRefExpr 0x5599ad9de660  'A':'A' lvalue 
> Decomposition 0x5599ad9de310 '' 'A &'
> ``` 
> 
> So each `BindingDecl` is like:
> ```
> `-BindingDecl 0x5599ad9de2c8  col:27 BoundBarRef 'int'
>   `-MemberExpr 0x5599ad9de680  'int' lvalue .Bar 
> 0x5599ad9dd9d8
> `-DeclRefExpr 0x5599ad9de660  'A':'A' lvalue 
> Decomposition 0x5599ad9de310 '' 'A &'
> ```
> 
> Is there a case where the `BindingDecl` would have a different shape? If we 
> do not expect that happening, I feel like an `StmtVisitor` is a bit of an 
> overkill for this and we could handle the supported case more directly. What 
> do you think?
Agreed. I simplified the patch. Please take a look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120495

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


[PATCH] D126183: Implement soft reset of the diagnostics engine.

2022-05-28 Thread Tapasweni Pathak via Phabricator via cfe-commits
tapaswenipathak updated this revision to Diff 432730.
tapaswenipathak added a comment.

Fixes: 
https://buildkite.com/llvm-project/premerge-checks/builds/95001#01810b0b-6313-400f-aaf0-35855916ec93

I pasted the wrong diff. sorry!

(have multiple build repository in local)

F23230857: Screenshot 2022-05-28 at 9.19.48 PM.png 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126183

Files:
  clang/include/clang/Basic/Diagnostic.h
  clang/lib/Basic/Diagnostic.cpp
  clang/test/Interpreter/error-recovery-pragmas.cpp
  clang/tools/clang-repl/ClangRepl.cpp
  clang/unittests/Basic/DiagnosticTest.cpp

Index: clang/unittests/Basic/DiagnosticTest.cpp
===
--- clang/unittests/Basic/DiagnosticTest.cpp
+++ clang/unittests/Basic/DiagnosticTest.cpp
@@ -14,6 +14,15 @@
 using namespace llvm;
 using namespace clang;
 
+void clang::DiagnosticsTestHelper(DiagnosticsEngine &diag) {
+  unsigned delayedDiagID = 0U;
+
+  EXPECT_EQ(diag.DelayedDiagID, delayedDiagID);
+  EXPECT_FALSE(diag.DiagStates.empty());
+  EXPECT_TRUE(diag.DiagStatesByLoc.empty());
+  EXPECT_TRUE(diag.DiagStateOnPushStack.empty());
+}
+
 namespace {
 
 // Check that DiagnosticErrorTrap works with SuppressAllDiagnostics.
@@ -71,6 +80,32 @@
 EXPECT_EQ(Diags.getNumWarnings(), FatalsAsError);
   }
 }
+
+// Check that soft RESET works as intended
+TEST(DiagnosticTest, softReset) {
+  DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
+  new IgnoringDiagConsumer());
+
+  unsigned numWarnings = 0U, numErrors = 0U;
+
+  Diags.Reset(true);
+  // Check For ErrorOccurred and TrapNumErrorsOccurred
+  EXPECT_FALSE(Diags.hasErrorOccurred());
+  EXPECT_FALSE(Diags.hasFatalErrorOccurred());
+  EXPECT_FALSE(Diags.hasUncompilableErrorOccurred());
+  // Check for UnrecoverableErrorOccurred and TrapNumUnrecoverableErrorsOccurred
+  EXPECT_FALSE(Diags.hasUnrecoverableErrorOccurred());
+
+  EXPECT_EQ(Diags.getNumWarnings(), numWarnings);
+  EXPECT_EQ(Diags.getNumErrors(), numErrors);
+
+  // Check for private variables of DiagnosticsEngine differentiating soft reset
+  DiagnosticsTestHelper(Diags);
+
+  EXPECT_FALSE(Diags.isDiagnosticInFlight());
+  EXPECT_TRUE(Diags.isLastDiagnosticIgnored());
+}
+
 TEST(DiagnosticTest, diagnosticError) {
   DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
   new IgnoringDiagConsumer());
Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -86,14 +86,17 @@
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  bool hadErrors = false;
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
 while (llvm::Optional Line = LE.readLine()) {
   if (*Line == "quit")
 break;
-  if (auto Err = Interp->ParseAndExecute(*Line))
+  if (auto Err = Interp->ParseAndExecute(*Line)) {
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+hadErrors = true;
+  }
 }
   }
 
@@ -104,5 +107,5 @@
 
   llvm::llvm_shutdown();
 
-  return 0;
+  return hadErrors;
 }
Index: clang/test/Interpreter/error-recovery-pragmas.cpp
===
--- /dev/null
+++ clang/test/Interpreter/error-recovery-pragmas.cpp
@@ -0,0 +1,6 @@
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wmultichar"
+// Reset should not delete #pragmas
+error; // expected-error {{use of undeclared identifier}}
+void no_diag_multichar(void) { char c = (char)'ab'; }
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -130,7 +130,7 @@
   return true;
 }
 
-void DiagnosticsEngine::Reset() {
+void DiagnosticsEngine::Reset(bool soft /*=false*/) {
   ErrorOccurred = false;
   UncompilableErrorOccurred = false;
   FatalErrorOccurred = false;
@@ -145,15 +145,17 @@
   LastDiagLevel = DiagnosticIDs::Ignored;
   DelayedDiagID = 0;
 
-  // Clear state related to #pragma diagnostic.
-  DiagStates.clear();
-  DiagStatesByLoc.clear();
-  DiagStateOnPushStack.clear();
+  if (!soft) {
+// Clear state related to #pragma diagnostic.
+DiagStates.clear();
+DiagStatesByLoc.clear();
+DiagStateOnPushStack.clear();
 
-  // Create a DiagState and DiagStatePoint representing diagnostic changes
-  // through command-line.
-  DiagStates.emplace_back();
-  DiagStatesByLoc.appendFirst(&DiagStates.back());
+// Create a DiagState and DiagStatePoint representing diagnostic changes
+// through command-line.
+DiagStates.

[PATCH] D126578: [clang] Add tests for (const) weak variables

2022-05-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thanks for looking to improve our test coverage here! However, precommit CI 
looks to be failing:

  
  Failed Tests (1):
Clang :: CodeGenCXX/weak-init.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126578

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


[PATCH] D126597: [clang] Remove `rm` script which is no longer necessary

2022-05-28 Thread Yuki Okushi via Phabricator via cfe-commits
JohnTitor created this revision.
Herald added a project: All.
JohnTitor requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

8b4fa2c98e07997469f53bee30c0d24a61dc7c8c 
 added 
this to remove left-over files on January.
Now we could assume they're cleaned up and this `rm` script is no longer 
necessary as FIXME states.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126597

Files:
  clang/test/Sema/test-wunaligned-access.c


Index: clang/test/Sema/test-wunaligned-access.c
===
--- clang/test/Sema/test-wunaligned-access.c
+++ clang/test/Sema/test-wunaligned-access.c
@@ -1,6 +1,3 @@
-// FIXME: Remove rm after a few days.
-// RUN: rm -f %S/test-wunaligned-access.ll
-
 // RUN: %clang_cc1 %s -triple=armv7-none-none-eabi -verify -Wunaligned-access 
-S -emit-llvm -o %t
 // REQUIRES: arm-registered-target
 //


Index: clang/test/Sema/test-wunaligned-access.c
===
--- clang/test/Sema/test-wunaligned-access.c
+++ clang/test/Sema/test-wunaligned-access.c
@@ -1,6 +1,3 @@
-// FIXME: Remove rm after a few days.
-// RUN: rm -f %S/test-wunaligned-access.ll
-
 // RUN: %clang_cc1 %s -triple=armv7-none-none-eabi -verify -Wunaligned-access -S -emit-llvm -o %t
 // REQUIRES: arm-registered-target
 //
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126598: # Enter a commit message. # # Changes: # # clang/utils/hmaptool/CMakeLists.txt Fixed typo in hmaptool CMakeLists.txt

2022-05-28 Thread Daniel Hannon via Phabricator via cfe-commits
danielh2942 created this revision.
Herald added a subscriber: mgorny.
Herald added a project: All.
danielh2942 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

There was a typo in the CMakeLists.txt for hmap tool that installed it to the 
wrong directory


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126598

Files:
  clang/utils/hmaptool/CMakeLists.txt


Index: clang/utils/hmaptool/CMakeLists.txt
===
--- clang/utils/hmaptool/CMakeLists.txt
+++ clang/utils/hmaptool/CMakeLists.txt
@@ -2,7 +2,7 @@
COMMAND "${CMAKE_COMMAND}" -E copy 
"${CMAKE_CURRENT_SOURCE_DIR}/hmaptool" "${LLVM_TOOLS_BINARY_DIR}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool")
 
-install(PROGRAMS hmaptool DESTINATION "${LLVM_UTILS_INSTALL_DIR}}" COMPONENT 
hmaptool)
+install(PROGRAMS hmaptool DESTINATION "${LLVM_UTILS_INSTALL_DIR}" COMPONENT 
hmaptool)
 add_custom_target(hmaptool ALL DEPENDS "${LLVM_TOOLS_BINARY_DIR}/hmaptool")
 set_target_properties(hmaptool PROPERTIES FOLDER "Utils")
 


Index: clang/utils/hmaptool/CMakeLists.txt
===
--- clang/utils/hmaptool/CMakeLists.txt
+++ clang/utils/hmaptool/CMakeLists.txt
@@ -2,7 +2,7 @@
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool" "${LLVM_TOOLS_BINARY_DIR}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool")
 
-install(PROGRAMS hmaptool DESTINATION "${LLVM_UTILS_INSTALL_DIR}}" COMPONENT hmaptool)
+install(PROGRAMS hmaptool DESTINATION "${LLVM_UTILS_INSTALL_DIR}" COMPONENT hmaptool)
 add_custom_target(hmaptool ALL DEPENDS "${LLVM_TOOLS_BINARY_DIR}/hmaptool")
 set_target_properties(hmaptool PROPERTIES FOLDER "Utils")
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126599: [docs][clang] Fix a broken link on the APINotes doc

2022-05-28 Thread Yuki Okushi via Phabricator via cfe-commits
JohnTitor created this revision.
Herald added a project: All.
JohnTitor requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch replaces a link with a GitHub one.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126599

Files:
  clang/docs/APINotes.rst


Index: clang/docs/APINotes.rst
===
--- clang/docs/APINotes.rst
+++ clang/docs/APINotes.rst
@@ -22,11 +22,11 @@
 That's API notes.
 
 API notes use a YAML-based file format. YAML is a format best explained by
-example, so here is a `small example`__ from the compiler test suite of API
+example, so here is a `small example
+`_
+from the compiler test suite of API
 notes for a hypothetical "SomeKit" framework.
 
-__ test/APINotes/Inputs/Frameworks/SomeKit.framework/Headers/SomeKit.apinotes
-
 
 Usage
 =


Index: clang/docs/APINotes.rst
===
--- clang/docs/APINotes.rst
+++ clang/docs/APINotes.rst
@@ -22,11 +22,11 @@
 That's API notes.
 
 API notes use a YAML-based file format. YAML is a format best explained by
-example, so here is a `small example`__ from the compiler test suite of API
+example, so here is a `small example
+`_
+from the compiler test suite of API
 notes for a hypothetical "SomeKit" framework.
 
-__ test/APINotes/Inputs/Frameworks/SomeKit.framework/Headers/SomeKit.apinotes
-
 
 Usage
 =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126598: Fixed typo in hmaptool CMakeLists.txt

2022-05-28 Thread Keith Smiley via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG50f2e4992456: [clang][cmake] Fixed typo in hmaptool 
CMakeLists.txt (authored by danielh2942, committed by keith).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126598

Files:
  clang/utils/hmaptool/CMakeLists.txt


Index: clang/utils/hmaptool/CMakeLists.txt
===
--- clang/utils/hmaptool/CMakeLists.txt
+++ clang/utils/hmaptool/CMakeLists.txt
@@ -2,7 +2,7 @@
COMMAND "${CMAKE_COMMAND}" -E copy 
"${CMAKE_CURRENT_SOURCE_DIR}/hmaptool" "${LLVM_TOOLS_BINARY_DIR}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool")
 
-install(PROGRAMS hmaptool DESTINATION "${LLVM_UTILS_INSTALL_DIR}}" COMPONENT 
hmaptool)
+install(PROGRAMS hmaptool DESTINATION "${LLVM_UTILS_INSTALL_DIR}" COMPONENT 
hmaptool)
 add_custom_target(hmaptool ALL DEPENDS "${LLVM_TOOLS_BINARY_DIR}/hmaptool")
 set_target_properties(hmaptool PROPERTIES FOLDER "Utils")
 


Index: clang/utils/hmaptool/CMakeLists.txt
===
--- clang/utils/hmaptool/CMakeLists.txt
+++ clang/utils/hmaptool/CMakeLists.txt
@@ -2,7 +2,7 @@
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool" "${LLVM_TOOLS_BINARY_DIR}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool")
 
-install(PROGRAMS hmaptool DESTINATION "${LLVM_UTILS_INSTALL_DIR}}" COMPONENT hmaptool)
+install(PROGRAMS hmaptool DESTINATION "${LLVM_UTILS_INSTALL_DIR}" COMPONENT hmaptool)
 add_custom_target(hmaptool ALL DEPENDS "${LLVM_TOOLS_BINARY_DIR}/hmaptool")
 set_target_properties(hmaptool PROPERTIES FOLDER "Utils")
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 50f2e49 - [clang][cmake] Fixed typo in hmaptool CMakeLists.txt

2022-05-28 Thread Keith Smiley via cfe-commits

Author: Daniel Hannon
Date: 2022-05-28T10:10:57-07:00
New Revision: 50f2e49924566330ea9aa731908f2864603bf4fb

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

LOG: [clang][cmake] Fixed typo in hmaptool CMakeLists.txt

There was a typo in the CMakeLists.txt for hmap tool that installed it to the 
wrong directory

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

Reviewed By: keith

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

Added: 


Modified: 
clang/utils/hmaptool/CMakeLists.txt

Removed: 




diff  --git a/clang/utils/hmaptool/CMakeLists.txt 
b/clang/utils/hmaptool/CMakeLists.txt
index 320a24da346d6..375d7b0448829 100644
--- a/clang/utils/hmaptool/CMakeLists.txt
+++ b/clang/utils/hmaptool/CMakeLists.txt
@@ -2,7 +2,7 @@ add_custom_command(OUTPUT "${LLVM_TOOLS_BINARY_DIR}/hmaptool"
COMMAND "${CMAKE_COMMAND}" -E copy 
"${CMAKE_CURRENT_SOURCE_DIR}/hmaptool" "${LLVM_TOOLS_BINARY_DIR}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool")
 
-install(PROGRAMS hmaptool DESTINATION "${LLVM_UTILS_INSTALL_DIR}}" COMPONENT 
hmaptool)
+install(PROGRAMS hmaptool DESTINATION "${LLVM_UTILS_INSTALL_DIR}" COMPONENT 
hmaptool)
 add_custom_target(hmaptool ALL DEPENDS "${LLVM_TOOLS_BINARY_DIR}/hmaptool")
 set_target_properties(hmaptool PROPERTIES FOLDER "Utils")
 



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


[PATCH] D125802: Fix std::has_unique_object_representations for _BitInt types with padding bits

2022-05-28 Thread Mital Ashok via Phabricator via cfe-commits
MitalAshok added a comment.

@aaron.ballman yes, with the author "Mital Ashok 
". (replacing the [AT]) Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125802

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


[PATCH] D126597: [clang] Remove `rm` script which is no longer necessary

2022-05-28 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126597

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


[PATCH] D126578: [clang] Add tests for (const) weak variables

2022-05-28 Thread Anders Waldenborg via Phabricator via cfe-commits
wanders updated this revision to Diff 432742.
wanders added a comment.

Added explicit triple to hopefully make it pass on win.
Made the new files clang-format clean.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126578

Files:
  clang/test/CodeGenCXX/weak-init.cpp
  clang/test/SemaCXX/weak-init.cpp


Index: clang/test/SemaCXX/weak-init.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/weak-init.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+extern const int W1 __attribute__((weak)) = 10; // expected-note {{declared 
here}}
+
+static_assert(W1 == 10, ""); // expected-error   {{static_assert expression is 
not an integral constant expression}}
+ // expected-note@-1 {{initializer of weak 
variable 'W1' is not considered constant because it may be different at 
runtime}}
+
+extern const int W2 __attribute__((weak)) = 20;
+
+int S2[W2]; // expected-error {{variable length array declaration not allowed 
at file scope}}
+
+extern const int W3 __attribute__((weak)) = 30; // expected-note {{declared 
here}}
+
+constexpr int S3 = W3; // expected-error   {{constexpr variable 'S3' must be 
initialized by a constant expression}}
+   // expected-note@-1 {{initializer of weak variable 'W3' 
is not considered constant because it may be different at runtime}}
Index: clang/test/CodeGenCXX/weak-init.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/weak-init.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -emit-llvm %s -o - | FileCheck 
%s
+
+extern const int W __attribute__((weak)) = 99;
+const int S = 77;
+
+// CHECK: @C1 = {{.*}} 77
+extern const int C1 = S;
+
+// CHECK: %0 = load {{.*}} @W
+// CHECK-NEXT: store {{.*}} %0, {{.*}} @C2
+extern const int C2 = W;


Index: clang/test/SemaCXX/weak-init.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/weak-init.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+extern const int W1 __attribute__((weak)) = 10; // expected-note {{declared here}}
+
+static_assert(W1 == 10, ""); // expected-error   {{static_assert expression is not an integral constant expression}}
+ // expected-note@-1 {{initializer of weak variable 'W1' is not considered constant because it may be different at runtime}}
+
+extern const int W2 __attribute__((weak)) = 20;
+
+int S2[W2]; // expected-error {{variable length array declaration not allowed at file scope}}
+
+extern const int W3 __attribute__((weak)) = 30; // expected-note {{declared here}}
+
+constexpr int S3 = W3; // expected-error   {{constexpr variable 'S3' must be initialized by a constant expression}}
+   // expected-note@-1 {{initializer of weak variable 'W3' is not considered constant because it may be different at runtime}}
Index: clang/test/CodeGenCXX/weak-init.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/weak-init.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+extern const int W __attribute__((weak)) = 99;
+const int S = 77;
+
+// CHECK: @C1 = {{.*}} 77
+extern const int C1 = S;
+
+// CHECK: %0 = load {{.*}} @W
+// CHECK-NEXT: store {{.*}} %0, {{.*}} @C2
+extern const int C2 = W;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2022-05-28 Thread Tapasweni Pathak via Phabricator via cfe-commits
tapaswenipathak created this revision.
tapaswenipathak added a reviewer: v.g.vassilev.
tapaswenipathak added a project: clang.
Herald added a project: All.
tapaswenipathak requested review of this revision.
Herald added a subscriber: cfe-commits.

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

  

This patch avoids an assert PresumedLoc::getFilename if it is invalid.

  

Add unit tests for allowing the interface to operate on in-memory buffers with 
no
source location info.

It addresses all review comments of https://reviews.llvm.org/D88780.

Ref: https://reviews.llvm.org/D126271.

  

Co-authored-by: Vassil Vassilev 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126600

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"
@@ -84,11 +151,11 @@
   ASSERT_EQ(tok::l_square, toks[0].getKind());
   ASSERT_EQ(tok::identifier, toks[1].getKind());
   ASSERT_EQ(tok::r_square, toks[2].getKind());
-  
+
   SourceLocation lsqrLoc = toks[0].getLocation();
   SourceLocation idLoc = toks[1].getLocation();
   SourceLocation rsqrLoc = toks[2].getLocation();
-  
+
   SourceLocation macroExpStartLoc = SourceMgr.translateLineCol(mainFileID, 2, 1);
   SourceLocation macroExpEndLoc = SourceMgr.translateLineCol(mainFileID, 2, 6);
   ASSERT_TRUE(macroExpStartLoc.isFileID());
Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -1470,24 +1470,35 @@
 
   /// Returns whether \p Loc is located in a  file.
   bool isWrittenInBuiltinFile(SourceLocation Loc) const {
-StringRef Fil

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

2022-05-28 Thread Tapasweni Pathak via Phabricator via cfe-commits
tapaswenipathak commandeered this revision.
tapaswenipathak added a reviewer: reikdas.
tapaswenipathak added a comment.
Herald added a project: All.

Ref: https://reviews.llvm.org/D126600.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88780

___
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-05-28 Thread Tapasweni Pathak via Phabricator via cfe-commits
tapaswenipathak updated this revision to Diff 432746.
tapaswenipathak added a comment.

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

  

This patch avoids an assert PresumedLoc::getFilename if it is invalid.

  

Add unit tests for allowing the interface to operate on in-memory buffers with 
no
source location info.

It addresses all review comments of https://reviews.llvm.org/D88780.

Ref: https://reviews.llvm.org/D126271.

  

Co-authored-by: Vassil Vassilev 


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"
@@ -84,11 +151,11 @@
   ASSERT_EQ(tok::l_square, toks[0].getKind());
   ASSERT_EQ(tok::identifier, toks[1].getKind());
   ASSERT_EQ(tok::r_square, toks[2].getKind());
-  
+
   SourceLocation lsqrLoc = toks[0].getLocation();
   SourceLocation idLoc = toks[1].getLocation();
   SourceLocation rsqrLoc = toks[2].getLocation();
-  
+
   SourceLocation macroExpStartLoc = SourceMgr.translateLineCol(mainFileID, 2, 1);
   SourceLocation macroExpEndLoc = SourceMgr.translateLineCol(mainFileID, 2, 6);
   ASSERT_TRUE(macroExpStartLoc.isFileID());
Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -1470,24 +1470,35 @@
 
   /// Returns whether \p Loc is located in a  file.
   bool isWrittenInBuiltinFile(SourceLocation Loc) const {
-StringRef Filename(getPresumedLoc(Loc).getFilename());
+PresumedLoc Presumed = getPresumedLoc(Loc);
+   

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

2022-05-28 Thread Tapasweni Pathak via Phabricator via cfe-commits
tapaswenipathak abandoned this revision.
tapaswenipathak added a comment.

Ref: dup: https://reviews.llvm.org/D88780.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126600

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


[PATCH] D126183: Implement soft reset of the diagnostics engine.

2022-05-28 Thread Tapasweni Pathak via Phabricator via cfe-commits
tapaswenipathak updated this revision to Diff 432747.
tapaswenipathak added a comment.

runs `make check-clang`, `check-clang-tools`, `check-all`.

prev ran: `make check-clang-unit`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126183

Files:
  clang/include/clang/Basic/Diagnostic.h
  clang/lib/Basic/Diagnostic.cpp
  clang/test/Interpreter/error-recovery-pragmas.cpp
  clang/tools/clang-repl/ClangRepl.cpp
  clang/unittests/Basic/DiagnosticTest.cpp

Index: clang/unittests/Basic/DiagnosticTest.cpp
===
--- clang/unittests/Basic/DiagnosticTest.cpp
+++ clang/unittests/Basic/DiagnosticTest.cpp
@@ -14,6 +14,15 @@
 using namespace llvm;
 using namespace clang;
 
+void clang::DiagnosticsTestHelper(DiagnosticsEngine &diag) {
+  unsigned delayedDiagID = 0U;
+
+  EXPECT_EQ(diag.DelayedDiagID, delayedDiagID);
+  EXPECT_FALSE(diag.DiagStates.empty());
+  EXPECT_TRUE(diag.DiagStatesByLoc.empty());
+  EXPECT_TRUE(diag.DiagStateOnPushStack.empty());
+}
+
 namespace {
 
 // Check that DiagnosticErrorTrap works with SuppressAllDiagnostics.
@@ -71,6 +80,32 @@
 EXPECT_EQ(Diags.getNumWarnings(), FatalsAsError);
   }
 }
+
+// Check that soft RESET works as intended
+TEST(DiagnosticTest, softReset) {
+  DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
+  new IgnoringDiagConsumer());
+
+  unsigned numWarnings = 0U, numErrors = 0U;
+
+  Diags.Reset(true);
+  // Check For ErrorOccurred and TrapNumErrorsOccurred
+  EXPECT_FALSE(Diags.hasErrorOccurred());
+  EXPECT_FALSE(Diags.hasFatalErrorOccurred());
+  EXPECT_FALSE(Diags.hasUncompilableErrorOccurred());
+  // Check for UnrecoverableErrorOccurred and TrapNumUnrecoverableErrorsOccurred
+  EXPECT_FALSE(Diags.hasUnrecoverableErrorOccurred());
+
+  EXPECT_EQ(Diags.getNumWarnings(), numWarnings);
+  EXPECT_EQ(Diags.getNumErrors(), numErrors);
+
+  // Check for private variables of DiagnosticsEngine differentiating soft reset
+  DiagnosticsTestHelper(Diags);
+
+  EXPECT_FALSE(Diags.isDiagnosticInFlight());
+  EXPECT_TRUE(Diags.isLastDiagnosticIgnored());
+}
+
 TEST(DiagnosticTest, diagnosticError) {
   DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
   new IgnoringDiagConsumer());
Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -86,14 +86,17 @@
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  bool hadErrors = false;
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
 while (llvm::Optional Line = LE.readLine()) {
   if (*Line == "quit")
 break;
-  if (auto Err = Interp->ParseAndExecute(*Line))
+  if (auto Err = Interp->ParseAndExecute(*Line)) {
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+hadErrors = true;
+  }
 }
   }
 
@@ -104,5 +107,5 @@
 
   llvm::llvm_shutdown();
 
-  return 0;
+  return hadErrors;
 }
Index: clang/test/Interpreter/error-recovery-pragmas.cpp
===
--- /dev/null
+++ clang/test/Interpreter/error-recovery-pragmas.cpp
@@ -0,0 +1,7 @@
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wmultichar"
+// Reset should not delete #pragmas
+error; // expected-error {{use of undeclared identifier}}
+void no_diag_multichar(void) { char c = (char)'ab'; }
+quit
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -130,7 +130,7 @@
   return true;
 }
 
-void DiagnosticsEngine::Reset() {
+void DiagnosticsEngine::Reset(bool soft /*=false*/) {
   ErrorOccurred = false;
   UncompilableErrorOccurred = false;
   FatalErrorOccurred = false;
@@ -145,15 +145,17 @@
   LastDiagLevel = DiagnosticIDs::Ignored;
   DelayedDiagID = 0;
 
-  // Clear state related to #pragma diagnostic.
-  DiagStates.clear();
-  DiagStatesByLoc.clear();
-  DiagStateOnPushStack.clear();
+  if (!soft) {
+// Clear state related to #pragma diagnostic.
+DiagStates.clear();
+DiagStatesByLoc.clear();
+DiagStateOnPushStack.clear();
 
-  // Create a DiagState and DiagStatePoint representing diagnostic changes
-  // through command-line.
-  DiagStates.emplace_back();
-  DiagStatesByLoc.appendFirst(&DiagStates.back());
+// Create a DiagState and DiagStatePoint representing diagnostic changes
+// through command-line.
+DiagStates.emplace_back();
+DiagStatesByLoc.appendFirst(&DiagStates.back());
+  }
 }
 
 void DiagnosticsEngine::SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1,
Index: clang/in

[PATCH] D126578: [clang] Add tests for (const) weak variables

2022-05-28 Thread Anders Waldenborg via Phabricator via cfe-commits
wanders added a comment.

In D126578#3543994 , @aaron.ballman 
wrote:

> Thanks for looking to improve our test coverage here! However, precommit CI 
> looks to be failing:

Thanks for notifying me.  It should be green now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126578

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


[PATCH] D123674: Clang-Repl Error Recovery Bug Fix

2022-05-28 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! Apologies for the delay.


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

https://reviews.llvm.org/D123674

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


[PATCH] D126602: [Clang][OpenMP] Replace IgnoreImpCasts with IgnoreImplicitAsWritten in atomic compare

2022-05-28 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, ABataev.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
tianshilei1992 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

This patch replaces all `IgnoreImpCasts` with `IgnoreImplicitAsWritten`
to avoid potential ignore of necessary casts.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126602

Files:
  clang/lib/Sema/SemaOpenMP.cpp


Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -11429,11 +11429,11 @@
   switch (Cond->getOpcode()) {
   case BO_EQ: {
 C = Cond;
-D = BO->getRHS()->IgnoreImpCasts();
+D = BO->getRHS()->IgnoreImplicitAsWritten();
 if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS())) {
-  E = Cond->getRHS()->IgnoreImpCasts();
+  E = Cond->getRHS()->IgnoreImplicitAsWritten();
 } else if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getRHS())) {
-  E = Cond->getLHS()->IgnoreImpCasts();
+  E = Cond->getLHS()->IgnoreImplicitAsWritten();
 } else {
   ErrorInfo.Error = ErrorTy::InvalidComparison;
   ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Cond->getExprLoc();
@@ -11444,7 +11444,7 @@
   }
   case BO_LT:
   case BO_GT: {
-E = BO->getRHS()->IgnoreImpCasts();
+E = BO->getRHS()->IgnoreImplicitAsWritten();
 if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS()) &&
 checkIfTwoExprsAreSame(ContextRef, E, Cond->getRHS())) {
   C = Cond;
@@ -11524,11 +11524,11 @@
   switch (Cond->getOpcode()) {
   case BO_EQ: {
 C = Cond;
-D = CO->getTrueExpr()->IgnoreImpCasts();
+D = CO->getTrueExpr()->IgnoreImplicitAsWritten();
 if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS())) {
-  E = Cond->getRHS()->IgnoreImpCasts();
+  E = Cond->getRHS()->IgnoreImplicitAsWritten();
 } else if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getRHS())) {
-  E = Cond->getLHS()->IgnoreImpCasts();
+  E = Cond->getLHS()->IgnoreImplicitAsWritten();
 } else {
   ErrorInfo.Error = ErrorTy::InvalidComparison;
   ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Cond->getExprLoc();
@@ -11539,7 +11539,7 @@
   }
   case BO_LT:
   case BO_GT: {
-E = CO->getTrueExpr()->IgnoreImpCasts();
+E = CO->getTrueExpr()->IgnoreImplicitAsWritten();
 if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS()) &&
 checkIfTwoExprsAreSame(ContextRef, E, Cond->getRHS())) {
   C = Cond;


Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -11429,11 +11429,11 @@
   switch (Cond->getOpcode()) {
   case BO_EQ: {
 C = Cond;
-D = BO->getRHS()->IgnoreImpCasts();
+D = BO->getRHS()->IgnoreImplicitAsWritten();
 if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS())) {
-  E = Cond->getRHS()->IgnoreImpCasts();
+  E = Cond->getRHS()->IgnoreImplicitAsWritten();
 } else if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getRHS())) {
-  E = Cond->getLHS()->IgnoreImpCasts();
+  E = Cond->getLHS()->IgnoreImplicitAsWritten();
 } else {
   ErrorInfo.Error = ErrorTy::InvalidComparison;
   ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Cond->getExprLoc();
@@ -11444,7 +11444,7 @@
   }
   case BO_LT:
   case BO_GT: {
-E = BO->getRHS()->IgnoreImpCasts();
+E = BO->getRHS()->IgnoreImplicitAsWritten();
 if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS()) &&
 checkIfTwoExprsAreSame(ContextRef, E, Cond->getRHS())) {
   C = Cond;
@@ -11524,11 +11524,11 @@
   switch (Cond->getOpcode()) {
   case BO_EQ: {
 C = Cond;
-D = CO->getTrueExpr()->IgnoreImpCasts();
+D = CO->getTrueExpr()->IgnoreImplicitAsWritten();
 if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS())) {
-  E = Cond->getRHS()->IgnoreImpCasts();
+  E = Cond->getRHS()->IgnoreImplicitAsWritten();
 } else if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getRHS())) {
-  E = Cond->getLHS()->IgnoreImpCasts();
+  E = Cond->getLHS()->IgnoreImplicitAsWritten();
 } else {
   ErrorInfo.Error = ErrorTy::InvalidComparison;
   ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Cond->getExprLoc();
@@ -11539,7 +11539,7 @@
   }
   case BO_LT:
   case BO_GT: {
-E = CO->getTrueExpr()->IgnoreImpCasts();
+E = CO->getTrueExpr()->IgnoreImplicitAsWritten();
 if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS()) &&
 checkIfTwoExprsAreSame(ContextRef, E, Cond->getRHS())) {
   C = Cond;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 41a054e - [clang] Remove `rm` script which is no longer necessary

2022-05-28 Thread Yuki Okushi via cfe-commits

Author: Yuki Okushi
Date: 2022-05-29T08:49:45+09:00
New Revision: 41a054ef78856b789acfafca92eb8f79b8129ac0

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

LOG: [clang] Remove `rm` script which is no longer necessary

8b4fa2c98e07997469f53bee30c0d24a61dc7c8c added this to remove left-over files 
on January.
Now we could assume they're cleaned up and this `rm` script is no longer 
necessary as FIXME states.

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

Added: 


Modified: 
clang/test/Sema/test-wunaligned-access.c

Removed: 




diff  --git a/clang/test/Sema/test-wunaligned-access.c 
b/clang/test/Sema/test-wunaligned-access.c
index 74945a8539eb8..909cda45f489b 100644
--- a/clang/test/Sema/test-wunaligned-access.c
+++ b/clang/test/Sema/test-wunaligned-access.c
@@ -1,6 +1,3 @@
-// FIXME: Remove rm after a few days.
-// RUN: rm -f %S/test-wunaligned-access.ll
-
 // RUN: %clang_cc1 %s -triple=armv7-none-none-eabi -verify -Wunaligned-access 
-S -emit-llvm -o %t
 // REQUIRES: arm-registered-target
 //



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


[PATCH] D126597: [clang] Remove `rm` script which is no longer necessary

2022-05-28 Thread Yuki Okushi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG41a054ef7885: [clang] Remove `rm` script which is no longer 
necessary (authored by JohnTitor).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126597

Files:
  clang/test/Sema/test-wunaligned-access.c


Index: clang/test/Sema/test-wunaligned-access.c
===
--- clang/test/Sema/test-wunaligned-access.c
+++ clang/test/Sema/test-wunaligned-access.c
@@ -1,6 +1,3 @@
-// FIXME: Remove rm after a few days.
-// RUN: rm -f %S/test-wunaligned-access.ll
-
 // RUN: %clang_cc1 %s -triple=armv7-none-none-eabi -verify -Wunaligned-access 
-S -emit-llvm -o %t
 // REQUIRES: arm-registered-target
 //


Index: clang/test/Sema/test-wunaligned-access.c
===
--- clang/test/Sema/test-wunaligned-access.c
+++ clang/test/Sema/test-wunaligned-access.c
@@ -1,6 +1,3 @@
-// FIXME: Remove rm after a few days.
-// RUN: rm -f %S/test-wunaligned-access.ll
-
 // RUN: %clang_cc1 %s -triple=armv7-none-none-eabi -verify -Wunaligned-access -S -emit-llvm -o %t
 // REQUIRES: arm-registered-target
 //
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126607: [docs] Remove some unavailable modindex links

2022-05-28 Thread Yuki Okushi via Phabricator via cfe-commits
JohnTitor created this revision.
Herald added a subscriber: arphaman.
Herald added projects: Flang, All.
JohnTitor requested review of this revision.
Herald added subscribers: cfe-commits, jdoerfert.
Herald added a project: clang.

These return 404 and I think it's fine to remove them until we can build.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126607

Files:
  clang/docs/index.rst
  flang/docs/index.md


Index: flang/docs/index.md
===
--- flang/docs/index.md
+++ flang/docs/index.md
@@ -68,6 +68,5 @@
 
 ```eval_rst
 * :ref:`genindex`
-* :ref:`modindex`
 * :ref:`search`
 ```
Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -109,6 +109,5 @@
 ==
 
 * :ref:`genindex`
-* :ref:`modindex`
 * :ref:`search`
 


Index: flang/docs/index.md
===
--- flang/docs/index.md
+++ flang/docs/index.md
@@ -68,6 +68,5 @@
 
 ```eval_rst
 * :ref:`genindex`
-* :ref:`modindex`
 * :ref:`search`
 ```
Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -109,6 +109,5 @@
 ==
 
 * :ref:`genindex`
-* :ref:`modindex`
 * :ref:`search`
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126608: [clangd] Remove a test with a duplicate of FileCacheTests

2022-05-28 Thread Yuki Okushi via Phabricator via cfe-commits
JohnTitor created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: All.
JohnTitor requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

FIXME says it should be removed so followed it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126608

Files:
  clang-tools-extra/clangd/unittests/ConfigProviderTests.cpp


Index: clang-tools-extra/clangd/unittests/ConfigProviderTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigProviderTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigProviderTests.cpp
@@ -178,44 +178,6 @@
   EXPECT_THAT(getAddedArgs(Cfg), ElementsAre("bar", "baz"));
 }
 
-// FIXME: delete this test, it's covered by FileCacheTests.
-TEST(ProviderTest, Staleness) {
-  MockFS FS;
-
-  auto StartTime = std::chrono::steady_clock::now();
-  Params StaleOK;
-  StaleOK.FreshTime = StartTime;
-  Params MustBeFresh;
-  MustBeFresh.FreshTime = StartTime + std::chrono::hours(1);
-  CapturedDiags Diags;
-  auto P = Provider::fromYAMLFile(testPath("foo.yaml"), /*Directory=*/"", FS);
-
-  // Initial query always reads, regardless of policy.
-  FS.Files["foo.yaml"] = AddFooWithErr;
-  auto Cfg = P->getConfig(StaleOK, Diags.callback());
-  EXPECT_THAT(Diags.Diagnostics,
-  ElementsAre(diagMessage("Unknown CompileFlags key 'Unknown'")));
-  EXPECT_THAT(getAddedArgs(Cfg), ElementsAre("foo"));
-  Diags.clear();
-
-  // Stale value reused by policy.
-  FS.Files["foo.yaml"] = AddBarBaz;
-  Cfg = P->getConfig(StaleOK, Diags.callback());
-  EXPECT_THAT(Diags.Diagnostics, IsEmpty()) << "Cached, not re-parsed";
-  EXPECT_THAT(getAddedArgs(Cfg), ElementsAre("foo"));
-
-  // Cache revalidated by policy.
-  Cfg = P->getConfig(MustBeFresh, Diags.callback());
-  EXPECT_THAT(Diags.Diagnostics, IsEmpty()) << "New config, no errors";
-  EXPECT_THAT(getAddedArgs(Cfg), ElementsAre("bar", "baz"));
-
-  // Cache revalidated by (default) policy.
-  FS.Files.erase("foo.yaml");
-  Cfg = P->getConfig(Params(), Diags.callback());
-  EXPECT_THAT(Diags.Diagnostics, IsEmpty());
-  EXPECT_THAT(getAddedArgs(Cfg), IsEmpty());
-}
-
 TEST(ProviderTest, SourceInfo) {
   MockFS FS;
 


Index: clang-tools-extra/clangd/unittests/ConfigProviderTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigProviderTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigProviderTests.cpp
@@ -178,44 +178,6 @@
   EXPECT_THAT(getAddedArgs(Cfg), ElementsAre("bar", "baz"));
 }
 
-// FIXME: delete this test, it's covered by FileCacheTests.
-TEST(ProviderTest, Staleness) {
-  MockFS FS;
-
-  auto StartTime = std::chrono::steady_clock::now();
-  Params StaleOK;
-  StaleOK.FreshTime = StartTime;
-  Params MustBeFresh;
-  MustBeFresh.FreshTime = StartTime + std::chrono::hours(1);
-  CapturedDiags Diags;
-  auto P = Provider::fromYAMLFile(testPath("foo.yaml"), /*Directory=*/"", FS);
-
-  // Initial query always reads, regardless of policy.
-  FS.Files["foo.yaml"] = AddFooWithErr;
-  auto Cfg = P->getConfig(StaleOK, Diags.callback());
-  EXPECT_THAT(Diags.Diagnostics,
-  ElementsAre(diagMessage("Unknown CompileFlags key 'Unknown'")));
-  EXPECT_THAT(getAddedArgs(Cfg), ElementsAre("foo"));
-  Diags.clear();
-
-  // Stale value reused by policy.
-  FS.Files["foo.yaml"] = AddBarBaz;
-  Cfg = P->getConfig(StaleOK, Diags.callback());
-  EXPECT_THAT(Diags.Diagnostics, IsEmpty()) << "Cached, not re-parsed";
-  EXPECT_THAT(getAddedArgs(Cfg), ElementsAre("foo"));
-
-  // Cache revalidated by policy.
-  Cfg = P->getConfig(MustBeFresh, Diags.callback());
-  EXPECT_THAT(Diags.Diagnostics, IsEmpty()) << "New config, no errors";
-  EXPECT_THAT(getAddedArgs(Cfg), ElementsAre("bar", "baz"));
-
-  // Cache revalidated by (default) policy.
-  FS.Files.erase("foo.yaml");
-  Cfg = P->getConfig(Params(), Diags.callback());
-  EXPECT_THAT(Diags.Diagnostics, IsEmpty());
-  EXPECT_THAT(getAddedArgs(Cfg), IsEmpty());
-}
-
 TEST(ProviderTest, SourceInfo) {
   MockFS FS;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5ff27fe - [clang-repl] Recover the lookup tables of the primary context.

2022-05-28 Thread Vassil Vassilev via cfe-commits

Author: Purva-Chaudhari
Date: 2022-05-29T04:59:40Z
New Revision: 5ff27fe1ff03d5aeaf8567c97618170f0cef8f58

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

LOG: [clang-repl] Recover the lookup tables of the primary context.

Before this patch, there was re-declaration error if error was encountered in
the same line. The recovery support acted only if this type of error was
encountered in the first line of the program and not in subsequent lines.

For example:

```
clang-repl> int i=9;
clang-repl> int j=9; err;
input_line_3:1:5: error: redefinition of 'j'
int j = 9;
```

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

Added: 


Modified: 
clang/lib/Interpreter/IncrementalParser.cpp
clang/test/Interpreter/execute.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 0f1ef3233a2a1..87687ea6906d7 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -188,7 +188,7 @@ IncrementalParser::ParseOrWrapTopLevelDecl() {
 S.TUScope->setEntity(PreviousTU);
 
 // Clean up the lookup table
-if (StoredDeclsMap *Map = PreviousTU->getLookupPtr()) {
+if (StoredDeclsMap *Map = PreviousTU->getPrimaryContext()->getLookupPtr()) 
{
   for (auto I = Map->begin(); I != Map->end(); ++I) {
 StoredDeclsList &List = I->second;
 DeclContextLookupResult R = List.getLookupResult();

diff  --git a/clang/test/Interpreter/execute.cpp 
b/clang/test/Interpreter/execute.cpp
index 298046c068c37..5f3fe3e837d9a 100644
--- a/clang/test/Interpreter/execute.cpp
+++ b/clang/test/Interpreter/execute.cpp
@@ -1,3 +1,4 @@
+// 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



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


[PATCH] D123674: Clang-Repl Error Recovery Bug Fix

2022-05-28 Thread Vassil Vassilev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5ff27fe1ff03: [clang-repl] Recover the lookup tables of the 
primary context. (authored by Purva-Chaudhari, committed by v.g.vassilev).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D123674?vs=422486&id=432767#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123674

Files:
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -1,3 +1,4 @@
+// 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
Index: clang/lib/Interpreter/IncrementalParser.cpp
===
--- clang/lib/Interpreter/IncrementalParser.cpp
+++ clang/lib/Interpreter/IncrementalParser.cpp
@@ -188,7 +188,7 @@
 S.TUScope->setEntity(PreviousTU);
 
 // Clean up the lookup table
-if (StoredDeclsMap *Map = PreviousTU->getLookupPtr()) {
+if (StoredDeclsMap *Map = PreviousTU->getPrimaryContext()->getLookupPtr()) 
{
   for (auto I = Map->begin(); I != Map->end(); ++I) {
 StoredDeclsList &List = I->second;
 DeclContextLookupResult R = List.getLookupResult();


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -1,3 +1,4 @@
+// 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
Index: clang/lib/Interpreter/IncrementalParser.cpp
===
--- clang/lib/Interpreter/IncrementalParser.cpp
+++ clang/lib/Interpreter/IncrementalParser.cpp
@@ -188,7 +188,7 @@
 S.TUScope->setEntity(PreviousTU);
 
 // Clean up the lookup table
-if (StoredDeclsMap *Map = PreviousTU->getLookupPtr()) {
+if (StoredDeclsMap *Map = PreviousTU->getPrimaryContext()->getLookupPtr()) {
   for (auto I = Map->begin(); I != Map->end(); ++I) {
 StoredDeclsList &List = I->second;
 DeclContextLookupResult R = List.getLookupResult();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D125946: Handles failing driver tests of clang

2022-05-28 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added reviewers: rsmith, lhames, dblaikie, sgraenitz.
v.g.vassilev added a subscriber: rsmith.
v.g.vassilev added a comment.
Herald added a subscriber: StephenFan.

@Purva-Chaudhari, this looks reasonable to me. I am adding more reviewers to 
discuss the way we refer other tests from `clang-repl`.




Comment at: clang/test/Interpreter/clangtests.cpp:1
+// RUN: clang-repl %S/../Lexer/badstring_in_if0.c -Xcc -E -Xcc -verify
+// RUN: clang-repl %S/../Lexer/unknown-char.c -Xcc -E -Xcc -verify

@rsmith, would it be acceptable to have a test that refers other tests from the 
repo in that manner?


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

https://reviews.llvm.org/D125946

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


[PATCH] D125944: Template instantiation error recovery

2022-05-28 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a reviewer: rsmith.
v.g.vassilev added a subscriber: rsmith.
v.g.vassilev added a comment.

@Purva-Chaudhari, can you rebase this patch, seems that it is not buildable.

@rsmith, we need to do something similar in cling to handle pending template 
instantiations, I guess the question is if we can avoid instantiating the 
templates we don't need and still survive.




Comment at: clang/lib/Interpreter/IncrementalParser.cpp:180
   DiagnosticsEngine &Diags = getCI()->getDiagnostics();
+  Sema::PerformPendingInstantiationsRAII PerformPendingInstantiations(S);
   if (Diags.hasErrorOccurred()) {

I suspect we should create this object earlier in this function. Can you export 
the diff with more context like suggested here 
https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface


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

https://reviews.llvm.org/D125944

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