[clang] 9698a44 - Fix warning by handling OMPC_fail in switch statement.

2022-05-25 Thread Adrian Kuegel via cfe-commits

Author: Adrian Kuegel
Date: 2022-05-25T09:33:41+02:00
New Revision: 9698a445c664e6f0da5727364338ee99de537d6a

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

LOG: Fix warning by handling OMPC_fail in switch statement.

Added: 


Modified: 
clang/lib/CodeGen/CGStmtOpenMP.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 61e3661e59be0..ebe65e5f72b3e 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -6317,6 +6317,7 @@ static void emitOMPAtomicExpr(CodeGenFunction &CGF, 
OpenMPClauseKind Kind,
   case OMPC_bind:
   case OMPC_align:
   case OMPC_cancellation_construct_type:
+  case OMPC_fail:
 llvm_unreachable("Clause is not allowed in 'omp atomic'.");
   }
 }



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


[PATCH] D126358: clang-format][NFC] Refactor UnwrappedLineParser::parseBlock()

2022-05-25 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: curdeius, HazardyKnusperkeks, MyDeveloperDay.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126358

Files:
  clang/lib/Format/UnwrappedLineParser.cpp


Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -871,30 +871,33 @@
 return IfKind;
   }
 
-  if (SimpleBlock && !KeepBraces) {
+  auto RemoveBraces = [=]() mutable {
+if (KeepBraces || !SimpleBlock)
+  return false;
 assert(Tok->isOneOf(TT_ControlStatementLBrace, TT_ElseLBrace));
 assert(FormatTok->is(tok::r_brace));
+const bool WrappedOpeningBrace = !Tok->Previous;
+if (WrappedOpeningBrace && FollowedByComment)
+  return false;
 const FormatToken *Previous = Tokens->getPreviousToken();
 assert(Previous);
-if (Previous->isNot(tok::r_brace) || Previous->Optional) {
-  assert(!CurrentLines->empty());
-  const FormatToken *OpeningBrace = Tok;
-  if (!Tok->Previous) { // Wrapped l_brace.
-if (FollowedByComment) {
-  KeepBraces = true;
-} else {
-  assert(Index > 0);
-  --Index; // The line above the wrapped l_brace.
-  OpeningBrace = nullptr;
-}
-  }
-  if (!KeepBraces && mightFitOnOneLine(CurrentLines->back()) &&
-  (Tok->is(TT_ElseLBrace) ||
-   mightFitOnOneLine((*CurrentLines)[Index], OpeningBrace))) {
-Tok->MatchingParen = FormatTok;
-FormatTok->MatchingParen = Tok;
-  }
+if (Previous->is(tok::r_brace) && !Previous->Optional)
+  return false;
+assert(!CurrentLines->empty());
+if (!mightFitOnOneLine(CurrentLines->back()))
+  return false;
+if (Tok->is(TT_ElseLBrace))
+  return true;
+if (WrappedOpeningBrace) {
+  assert(Index > 0);
+  --Index; // The line above the wrapped l_brace.
+  Tok = nullptr;
 }
+return mightFitOnOneLine((*CurrentLines)[Index], Tok);
+  };
+  if (RemoveBraces()) {
+Tok->MatchingParen = FormatTok;
+FormatTok->MatchingParen = Tok;
   }
 
   size_t PPEndHash = computePPHash();


Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -871,30 +871,33 @@
 return IfKind;
   }
 
-  if (SimpleBlock && !KeepBraces) {
+  auto RemoveBraces = [=]() mutable {
+if (KeepBraces || !SimpleBlock)
+  return false;
 assert(Tok->isOneOf(TT_ControlStatementLBrace, TT_ElseLBrace));
 assert(FormatTok->is(tok::r_brace));
+const bool WrappedOpeningBrace = !Tok->Previous;
+if (WrappedOpeningBrace && FollowedByComment)
+  return false;
 const FormatToken *Previous = Tokens->getPreviousToken();
 assert(Previous);
-if (Previous->isNot(tok::r_brace) || Previous->Optional) {
-  assert(!CurrentLines->empty());
-  const FormatToken *OpeningBrace = Tok;
-  if (!Tok->Previous) { // Wrapped l_brace.
-if (FollowedByComment) {
-  KeepBraces = true;
-} else {
-  assert(Index > 0);
-  --Index; // The line above the wrapped l_brace.
-  OpeningBrace = nullptr;
-}
-  }
-  if (!KeepBraces && mightFitOnOneLine(CurrentLines->back()) &&
-  (Tok->is(TT_ElseLBrace) ||
-   mightFitOnOneLine((*CurrentLines)[Index], OpeningBrace))) {
-Tok->MatchingParen = FormatTok;
-FormatTok->MatchingParen = Tok;
-  }
+if (Previous->is(tok::r_brace) && !Previous->Optional)
+  return false;
+assert(!CurrentLines->empty());
+if (!mightFitOnOneLine(CurrentLines->back()))
+  return false;
+if (Tok->is(TT_ElseLBrace))
+  return true;
+if (WrappedOpeningBrace) {
+  assert(Index > 0);
+  --Index; // The line above the wrapped l_brace.
+  Tok = nullptr;
 }
+return mightFitOnOneLine((*CurrentLines)[Index], Tok);
+  };
+  if (RemoveBraces()) {
+Tok->MatchingParen = FormatTok;
+FormatTok->MatchingParen = Tok;
   }
 
   size_t PPEndHash = computePPHash();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D125400: [clang][Analyzer] Add errno state to standard functions modeling.

2022-05-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 431909.
balazske marked 13 inline comments as done.
balazske added a comment.

update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125400

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/Inputs/system-header-simulator-for-errno.h
  clang/test/Analysis/errno-stdlibraryfunctions.c

Index: clang/test/Analysis/errno-stdlibraryfunctions.c
===
--- /dev/null
+++ clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -0,0 +1,33 @@
+// RUN: %clang_analyze_cc1 -verify -analyzer-output text %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=apiModeling.Errno \
+// RUN:   -analyzer-checker=alpha.unix.Errno \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true
+
+#include "Inputs/errno_var.h"
+#include "Inputs/system-header-simulator-for-errno.h"
+
+void test1() {
+  access("path", 0); // no note here
+  access("path", 0);
+  // expected-note@-1{{Assuming that function 'access' is successful, in this case the value 'errno' may be undefined after the call and should not be used}}
+  if (errno != 0) { }
+  // expected-warning@-1{{An undefined value may be read from 'errno'}}
+  // expected-note@-2{{An undefined value may be read from 'errno'}}
+}
+
+void test2() {
+  if (access("path", 0) == -1) {
+if (errno != 0) { }
+  }
+}
+
+void test3() {
+  if (access("path", 0) != -1) {
+// expected-note@-1{{Assuming that function 'access' is successful, in this case the value 'errno' may be undefined after the call and should not be used}}
+if (errno != 0) { }
+// expected-warning@-1{{An undefined value may be read from 'errno'}}
+// expected-note@-2{{An undefined value may be read from 'errno'}}
+  }
+}
Index: clang/test/Analysis/Inputs/system-header-simulator-for-errno.h
===
--- /dev/null
+++ clang/test/Analysis/Inputs/system-header-simulator-for-errno.h
@@ -0,0 +1,6 @@
+#pragma clang system_header
+
+typedef __typeof(sizeof(int)) off_t;
+
+int access(const char *path, int amode);
+off_t lseek(int fildes, off_t offset, int whence);
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -40,6 +40,7 @@
 //
 //===--===//
 
+#include "ErrnoModeling.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -56,6 +57,19 @@
 using namespace clang;
 using namespace clang::ento;
 
+static const char *describeErrnoCheckState(errno_modeling::ErrnoCheckState CS) {
+  switch (CS) {
+  case errno_modeling::Errno_Irrelevant:
+return "is not significant";
+  case errno_modeling::Errno_MustBeChecked:
+return "should be checked to verify if the call was successful";
+  case errno_modeling::Errno_MustNotBeChecked:
+return "may be undefined after the call and should not be used";
+  default:
+llvm_unreachable("unknown enum value");
+  };
+}
+
 namespace {
 class StdLibraryFunctionsChecker
 : public Checker {
@@ -377,6 +391,116 @@
   /// The complete list of constraints that defines a single branch.
   using ConstraintSet = std::vector;
 
+  /// Define how a function affects the system variable 'errno'.
+  /// This works together with the ErrnoModeling and ErrnoChecker classes.
+  class ErrnoConstraintBase {
+  public:
+/// Apply specific state changes related to the errno variable.
+virtual ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
+  const Summary &Summary,
+  CheckerContext &C) const = 0;
+/// Get a description about what is applied to 'errno' and how is it allowed
+/// to be used. If ErrnoChecker generates a bug then this message is
+/// displayed as a note at the function call.
+/// It may return empty string if no note tag is to be added.
+virtual std::string describe(StringRef FunctionName) const { return ""; }
+
+virtual ~ErrnoConstraintBase() {}
+
+  protected:
+/// Many of the descendant classes use this value.
+errno_modeling::ErrnoCheckState const CheckState;
+
+ErrnoConstraintBase(errno_modeling::ErrnoCheckState CS) : CheckState(CS) {}
+
+/// This is used for conjure symbol for errno to differentiate from the
+/// original call expression (same expression is used for the errno symbol).
+static int Tag;
+  };
+
+  /// Set value of 'errno' to

[PATCH] D125400: [clang][Analyzer] Add errno state to standard functions modeling.

2022-05-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:454-460
+  std::string Result = "Assuming that function '";
+  Result.append(FunctionName.str());
+  Result.append("' fails, in this case the value 'errno' becomes ");
+  Result.append(BinaryOperator::getOpcodeStr(Relation).str());
+  Result.append(" 0 and ");
+  Result.append(describeErrnoCheckState(CheckState));
+  return Result;

steakhal wrote:
> I believe you should use `Twine` for this.
It should work, `FunctionName.str()` and `getOpcodeStr` and 
`describeErrnoCheckState` should return non-temporary strings.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125400

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


[clang] f75bc5b - [analyzer] Fix symbol simplification assertion failure

2022-05-25 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2022-05-25T10:55:50+02:00
New Revision: f75bc5bfc8f898de10e14163998c63eeb2b9f705

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

LOG: [analyzer] Fix symbol simplification assertion failure

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

The assertion mentioned in the issue is triggered because an
inconsistency is formed in the Sym->Class and Class->Sym relations. A
simpler but similar inconsistency is demonstrated here:
https://reviews.llvm.org/D114887 .

Previously in `removeMember`, we didn't remove the old symbol's
Sym->Class relation. Back then, we explained it with the following two
bullet points:
> 1) This way constraints for the old symbol can still be found via it's
> equivalence class that it used to be the member of.
> 2) Performance and resource reasons. We can spare one removal and thus one
> additional tree in the forest of `ClassMap`.

This patch do remove the old symbol's Sym->Class relation in order to
keep the Sym->Class relation consistent with the Class->Sym relations.
Point 2) above has negligible performance impact, empirical measurements
do not show any noticeable difference in the run-time. Point 1) above
seems to be a not well justified statement. This is because we cannot
create a new symbol that would be equal to the old symbol after the
simplification had happened. The reason for this is that the SValBuilder
uses the available constant constraints for each sub-symbol.

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

Added: 
clang/test/Analysis/symbol-simplification-assertion.c

Modified: 
clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index 1c17d48844ea3..e0ceac51d14f3 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2508,12 +2508,6 @@ EquivalenceClass::removeMember(ProgramStateRef State, 
const SymbolRef Old) {
   SymbolSet ClsMembers = getClassMembers(State);
   assert(ClsMembers.contains(Old));
 
-  // We don't remove `Old`'s Sym->Class relation for two reasons:
-  // 1) This way constraints for the old symbol can still be found via it's
-  // equivalence class that it used to be the member of.
-  // 2) Performance and resource reasons. We can spare one removal and thus one
-  // additional tree in the forest of `ClassMap`.
-
   // Remove `Old`'s Class->Sym relation.
   SymbolSet::Factory &F = getMembersFactory(State);
   ClassMembersTy::Factory &EMFactory = State->get_context();
@@ -2527,6 +2521,12 @@ EquivalenceClass::removeMember(ProgramStateRef State, 
const SymbolRef Old) {
   ClassMembersMap = EMFactory.add(ClassMembersMap, *this, ClsMembers);
   State = State->set(ClassMembersMap);
 
+  // Remove `Old`'s Sym->Class relation.
+  ClassMapTy Classes = State->get();
+  ClassMapTy::Factory &CMF = State->get_context();
+  Classes = CMF.remove(Classes, Old);
+  State = State->set(Classes);
+
   return State;
 }
 

diff  --git a/clang/test/Analysis/symbol-simplification-assertion.c 
b/clang/test/Analysis/symbol-simplification-assertion.c
new file mode 100644
index 0..e17f5a619158a
--- /dev/null
+++ b/clang/test/Analysis/symbol-simplification-assertion.c
@@ -0,0 +1,25 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=true \
+// RUN:   -verify
+
+// Here we test that no assertion is fired during symbol simplification.
+// Related issue: https://github.com/llvm/llvm-project/issues/55546
+
+extern void abort() __attribute__((__noreturn__));
+#define assert(expr) ((expr) ? (void)(0) : abort())
+
+void clang_analyzer_warnIfReached();
+
+int a, b, c;
+long L, L1;
+void test() {
+  assert(a + L + 1 + b != c);
+  assert(L == a);
+  assert(c == 0);
+  L1 = 0;
+  assert(a + L1 + 1 + b != c);
+  assert(a == 0); // no-assertion
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}



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


[PATCH] D126281: [analyzer] Fix symbol simplification assertion failure

2022-05-25 Thread Gabor Marton 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 rGf75bc5bfc8f8: [analyzer] Fix symbol simplification assertion 
failure (authored by martong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126281

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/symbol-simplification-assertion.c


Index: clang/test/Analysis/symbol-simplification-assertion.c
===
--- /dev/null
+++ clang/test/Analysis/symbol-simplification-assertion.c
@@ -0,0 +1,25 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=true \
+// RUN:   -verify
+
+// Here we test that no assertion is fired during symbol simplification.
+// Related issue: https://github.com/llvm/llvm-project/issues/55546
+
+extern void abort() __attribute__((__noreturn__));
+#define assert(expr) ((expr) ? (void)(0) : abort())
+
+void clang_analyzer_warnIfReached();
+
+int a, b, c;
+long L, L1;
+void test() {
+  assert(a + L + 1 + b != c);
+  assert(L == a);
+  assert(c == 0);
+  L1 = 0;
+  assert(a + L1 + 1 + b != c);
+  assert(a == 0); // no-assertion
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2508,12 +2508,6 @@
   SymbolSet ClsMembers = getClassMembers(State);
   assert(ClsMembers.contains(Old));
 
-  // We don't remove `Old`'s Sym->Class relation for two reasons:
-  // 1) This way constraints for the old symbol can still be found via it's
-  // equivalence class that it used to be the member of.
-  // 2) Performance and resource reasons. We can spare one removal and thus one
-  // additional tree in the forest of `ClassMap`.
-
   // Remove `Old`'s Class->Sym relation.
   SymbolSet::Factory &F = getMembersFactory(State);
   ClassMembersTy::Factory &EMFactory = State->get_context();
@@ -2527,6 +2521,12 @@
   ClassMembersMap = EMFactory.add(ClassMembersMap, *this, ClsMembers);
   State = State->set(ClassMembersMap);
 
+  // Remove `Old`'s Sym->Class relation.
+  ClassMapTy Classes = State->get();
+  ClassMapTy::Factory &CMF = State->get_context();
+  Classes = CMF.remove(Classes, Old);
+  State = State->set(Classes);
+
   return State;
 }
 


Index: clang/test/Analysis/symbol-simplification-assertion.c
===
--- /dev/null
+++ clang/test/Analysis/symbol-simplification-assertion.c
@@ -0,0 +1,25 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=true \
+// RUN:   -verify
+
+// Here we test that no assertion is fired during symbol simplification.
+// Related issue: https://github.com/llvm/llvm-project/issues/55546
+
+extern void abort() __attribute__((__noreturn__));
+#define assert(expr) ((expr) ? (void)(0) : abort())
+
+void clang_analyzer_warnIfReached();
+
+int a, b, c;
+long L, L1;
+void test() {
+  assert(a + L + 1 + b != c);
+  assert(L == a);
+  assert(c == 0);
+  L1 = 0;
+  assert(a + L1 + 1 + b != c);
+  assert(a == 0); // no-assertion
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2508,12 +2508,6 @@
   SymbolSet ClsMembers = getClassMembers(State);
   assert(ClsMembers.contains(Old));
 
-  // We don't remove `Old`'s Sym->Class relation for two reasons:
-  // 1) This way constraints for the old symbol can still be found via it's
-  // equivalence class that it used to be the member of.
-  // 2) Performance and resource reasons. We can spare one removal and thus one
-  // additional tree in the forest of `ClassMap`.
-
   // Remove `Old`'s Class->Sym relation.
   SymbolSet::Factory &F = getMembersFactory(State);
   ClassMembersTy::Factory &EMFactory = State->get_context();
@@ -2527,6 +2521,12 @@
   ClassMembersMap = EMFactory.add(ClassMembersMap, *this, ClsMembers);
   State = State->set(ClassMembersMap);
 
+  // Remove `Old`'s Sym->Class relation.
+  ClassMapTy Classes = State->get();
+  ClassMapTy::Factory &CMF = State->get_context();
+  Classes = CMF.remove(Classes, Old);
+  State = State->set(Classes);
+
   return State;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.o

[clang] 0d7f8d4 - [OpenCL] Remove argument names from async copy builtins

2022-05-25 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-05-25T10:05:25+01:00
New Revision: 0d7f8d42fd170a434006a928a7106b894bdbdd16

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

LOG: [OpenCL] Remove argument names from async copy builtins

This simplifies completeness comparisons against OpenCLBuiltins.td and
also makes the header no longer "claim" the argument name identifiers.

Continues the direction set out in D119560.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 69e2c85610bae..1942da77f5e50 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -12515,141 +12515,141 @@ cl_mem_fence_flags __ovld get_fence(void *ptr);
  * synchronization of source data such as using a
  * barrier before performing the copy.
  */
-event_t __ovld async_work_group_copy(__local char *dst, const __global char 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local uchar *dst, const __global uchar 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local short *dst, const __global short 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local ushort *dst, const __global 
ushort *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local int *dst, const __global int 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local uint *dst, const __global uint 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local long *dst, const __global long 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local ulong *dst, const __global ulong 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local float *dst, const __global float 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local char2 *dst, const __global char2 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local uchar2 *dst, const __global 
uchar2 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local short2 *dst, const __global 
short2 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local ushort2 *dst, const __global 
ushort2 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local int2 *dst, const __global int2 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local uint2 *dst, const __global uint2 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local long2 *dst, const __global long2 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local ulong2 *dst, const __global 
ulong2 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local float2 *dst, const __global 
float2 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local char3 *dst, const __global char3 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local uchar3 *dst, const __global 
uchar3 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local short3 *dst, const __global 
short3 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local ushort3 *dst, const __global 
ushort3 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local int3 *dst, const __global int3 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local uint3 *dst, const __global uint3 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local long3 *dst, const __global long3 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local ulong3 *dst, const __global 
ulong3 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local float3 *dst, const __global 
float3 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local char4 *dst, const __global char4 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local uchar4 *dst, const __global 
uchar4 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local short4 *dst, const __global 
short4 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local ushort4 *dst, const __global 
ushort4 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local int4 *dst, const __global int4 
*src, size_t num_e

[clang-tools-extra] cd2292e - [pseudo] A basic implementation of compiling cxx grammar at build time.

2022-05-25 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-05-25T11:26:06+02:00
New Revision: cd2292ef824591cc34cc299910a3098545c840c7

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

LOG: [pseudo] A basic implementation of compiling cxx grammar at build time.

The main idea is to compile the cxx grammar at build time, and construct
the core pieces (Grammar, LRTable) of the pseudoparse based on the compiled
data sources.

This is a tiny implementation, which is good for start:

- defines how the public API should look like;
- integrates the cxx grammar compilation workflow with the cmake system.
- onlynonterminal symbols of the C++ grammar are compiled, anything
  else are still doing the real compilation work at runtime, we can opt-in more
  bits in the future;
- splits the monolithic clangPsuedo library for better layering;

Reviewed By: sammccall

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

Added: 
clang-tools-extra/pseudo/gen/CMakeLists.txt
clang-tools-extra/pseudo/gen/Main.cpp
clang-tools-extra/pseudo/include/CMakeLists.txt
clang-tools-extra/pseudo/include/clang-pseudo/cxx/CXX.h
clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
clang-tools-extra/pseudo/lib/cxx/CXX.cpp
clang-tools-extra/pseudo/lib/grammar/CMakeLists.txt
clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
clang-tools-extra/pseudo/lib/grammar/LRGraph.cpp
clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp

Modified: 
clang-tools-extra/pseudo/CMakeLists.txt
clang-tools-extra/pseudo/lib/CMakeLists.txt

Removed: 
clang-tools-extra/pseudo/lib/Grammar.cpp
clang-tools-extra/pseudo/lib/GrammarBNF.cpp
clang-tools-extra/pseudo/lib/LRGraph.cpp
clang-tools-extra/pseudo/lib/LRTable.cpp
clang-tools-extra/pseudo/lib/LRTableBuild.cpp



diff  --git a/clang-tools-extra/pseudo/CMakeLists.txt 
b/clang-tools-extra/pseudo/CMakeLists.txt
index 0891cc0a0f885..24bc1530bb7d6 100644
--- a/clang-tools-extra/pseudo/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/CMakeLists.txt
@@ -1,5 +1,7 @@
 include_directories(include)
 include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
+add_subdirectory(include)
+add_subdirectory(gen)
 add_subdirectory(lib)
 add_subdirectory(tool)
 add_subdirectory(fuzzer)

diff  --git a/clang-tools-extra/pseudo/gen/CMakeLists.txt 
b/clang-tools-extra/pseudo/gen/CMakeLists.txt
new file mode 100644
index 0..a104e05b53da9
--- /dev/null
+++ b/clang-tools-extra/pseudo/gen/CMakeLists.txt
@@ -0,0 +1,10 @@
+set(LLVM_LINK_COMPONENTS Support)
+
+add_clang_executable(pseudo-gen
+  Main.cpp
+  )
+
+target_link_libraries(pseudo-gen
+  PRIVATE
+  clangPseudoGrammar
+  )

diff  --git a/clang-tools-extra/pseudo/gen/Main.cpp 
b/clang-tools-extra/pseudo/gen/Main.cpp
new file mode 100644
index 0..535f863268df1
--- /dev/null
+++ b/clang-tools-extra/pseudo/gen/Main.cpp
@@ -0,0 +1,89 @@
+//===--- Main.cpp - Compile BNF grammar 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This is a tool to compile a BNF grammar, it is used by the build system to
+// generate a necessary data bits to statically construct core pieces (Grammar,
+// LRTable etc) of the LR parser.
+//
+//===--===//
+
+#include "clang-pseudo/Grammar.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include 
+
+using llvm::cl::desc;
+using llvm::cl::init;
+using llvm::cl::opt;
+using llvm::cl::values;
+
+namespace {
+enum EmitType {
+  EmitSymbolList,
+  EmitGrammarContent,
+};
+
+opt Grammar("grammar", desc("Parse a BNF grammar file."),
+ init(""));
+opt
+Emit(desc("which information to emit:"),
+ values(clEnumValN(EmitSymbolList, "emit-symbol-list",
+   "Print nonterminal symbols (default)"),
+clEnumValN(EmitGrammarContent, "emit-grammar-content",
+   "Print the BNF grammar content as a string")));
+std::string readOrDie(llvm::StringRef Path) {
+  llvm::ErrorOr> Text =
+  llvm::MemoryBuffer::getFile(Path);
+  if (std::error_code EC = Text.getError()) {
+llvm::errs() << "Error: can't read grammar file '" << Path
+ << "': " << EC.message() << "\n";
+::exit(1);
+  }
+  return Text.get()->getBuffer().str();
+}

[PATCH] D125667: [pseudo] A basic implementation of compiling cxx grammar at build time.

2022-05-25 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcd2292ef8245: [pseudo] A basic implementation of compiling 
cxx grammar at build time. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D125667?vs=431746&id=431917#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125667

Files:
  clang-tools-extra/pseudo/CMakeLists.txt
  clang-tools-extra/pseudo/gen/CMakeLists.txt
  clang-tools-extra/pseudo/gen/Main.cpp
  clang-tools-extra/pseudo/include/CMakeLists.txt
  clang-tools-extra/pseudo/include/clang-pseudo/cxx/CXX.h
  clang-tools-extra/pseudo/lib/CMakeLists.txt
  clang-tools-extra/pseudo/lib/Grammar.cpp
  clang-tools-extra/pseudo/lib/GrammarBNF.cpp
  clang-tools-extra/pseudo/lib/LRGraph.cpp
  clang-tools-extra/pseudo/lib/LRTable.cpp
  clang-tools-extra/pseudo/lib/LRTableBuild.cpp
  clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
  clang-tools-extra/pseudo/lib/cxx/CXX.cpp
  clang-tools-extra/pseudo/lib/grammar/CMakeLists.txt
  clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
  clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
  clang-tools-extra/pseudo/lib/grammar/LRGraph.cpp
  clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
  clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp

Index: clang-tools-extra/pseudo/lib/grammar/CMakeLists.txt
===
--- /dev/null
+++ clang-tools-extra/pseudo/lib/grammar/CMakeLists.txt
@@ -0,0 +1,18 @@
+set(LLVM_LINK_COMPONENTS Support)
+
+# This library intents to keep as minimal dependencies as possible, it is a base
+# library of the cxx generator, to avoid creating long dep paths in the build
+# graph.
+add_clang_library(clangPseudoGrammar
+  Grammar.cpp
+  GrammarBNF.cpp
+  LRGraph.cpp
+  LRTable.cpp
+  LRTableBuild.cpp
+
+  # FIXME: can we get rid of the clangBasic dependency? We need it for the
+  # clang::tok::getTokenName and clang::tok::getPunctuatorSpelling functions, we
+  # could consider remimplement these functions.
+  LINK_LIBS
+  clangBasic
+  )
Index: clang-tools-extra/pseudo/lib/cxx/CXX.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/lib/cxx/CXX.cpp
@@ -0,0 +1,34 @@
+//===--- CXX.cpp - Define public interfaces for C++ grammar ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang-pseudo/cxx/CXX.h"
+#include "clang-pseudo/LRTable.h"
+
+namespace clang {
+namespace pseudo {
+namespace cxx {
+
+static const char *CXXBNF =
+#include "CXXBNF.inc"
+;
+
+const Grammar &getGrammar() {
+  static std::vector Diags;
+  static Grammar *G = Grammar::parseBNF(CXXBNF, Diags).release();
+  assert(Diags.empty());
+  return *G;
+}
+
+const LRTable &getLRTable() {
+  static LRTable *Table = new LRTable(LRTable::buildSLR(getGrammar()));
+  return *Table;
+}
+
+} // namespace cxx
+} // namespace pseudo
+} // namespace clang
Index: clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
===
--- /dev/null
+++ clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
@@ -0,0 +1,9 @@
+add_clang_library(clangPseudoCXX
+  CXX.cpp
+
+  DEPENDS
+  cxx_gen
+
+  LINK_LIBS
+  clangPseudoGrammar
+  )
Index: clang-tools-extra/pseudo/lib/CMakeLists.txt
===
--- clang-tools-extra/pseudo/lib/CMakeLists.txt
+++ clang-tools-extra/pseudo/lib/CMakeLists.txt
@@ -1,3 +1,6 @@
+add_subdirectory(cxx)
+add_subdirectory(grammar)
+
 set(LLVM_LINK_COMPONENTS Support)
 
 add_clang_library(clangPseudo
@@ -5,15 +8,11 @@
   DirectiveTree.cpp
   Forest.cpp
   GLR.cpp
-  Grammar.cpp
-  GrammarBNF.cpp
   Lex.cpp
-  LRGraph.cpp
-  LRTable.cpp
-  LRTableBuild.cpp
   Token.cpp
 
   LINK_LIBS
   clangBasic
   clangLex
+  clangPseudoGrammar
   )
Index: clang-tools-extra/pseudo/include/clang-pseudo/cxx/CXX.h
===
--- /dev/null
+++ clang-tools-extra/pseudo/include/clang-pseudo/cxx/CXX.h
@@ -0,0 +1,51 @@
+//===--- CXX.h - Public interfaces for the C++ grammar ---*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines public interfaces for the C++ grammar
+//  (pseudo/lib/cxx.bnf). It provides a fast way to access core building pieces
+//  of the LR parser, e.g. Grammar, LRTable, rather than parsing the grammar
+//  file 

[PATCH] D111617: [RISCV] Lazily add RVV C intrinsics.

2022-05-25 Thread Zakk Chen via Phabricator via cfe-commits
khchen added inline comments.



Comment at: clang/lib/Sema/SemaRVVLookup.cpp:175
+  for (auto &Record : RVVIntrinsicRecords) {
+// Create Intrinsics for each type and LMUL.
+BasicType BaseType = BasicType::Unknown;

Those code logic need to sync with createRVVIntrinsics, maybe we could add more 
comment address that.



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:91
 private:
   /// Create all intrinsics and add them to \p Out
   void createRVVIntrinsics(std::vector> &Out);

and also init SemaRecords?



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:93
   void createRVVIntrinsics(std::vector> &Out);
+  /// Create all intrinsics record from RVVIntrinsics.
+  void createRVVIntrinsicRecord(std::vector &Out);

I think it should be "Create all intrinsics record and SemaSignatureTable from 
SemaRecords"?



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:99
 
-  /// Emit Acrh predecessor definitions and body, assume the element of Defs 
are
-  /// sorted by extension.
-  void emitArchMacroAndBody(
-  std::vector> &Defs, raw_ostream &o,
-  std::function);
-
-  // Emit the architecture preprocessor definitions. Return true when emits
-  // non-empty string.
-  bool emitMacroRestrictionStr(RISCVPredefinedMacroT PredefinedMacros,
-   raw_ostream &o);
+  /// Construct a compressed signature table used for createSema.
+  void ConstructSemaSignatureTable();

/// Construct a compressed signature table from SemaRecords which is used for 
createSema.
maybe better.




Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:103
+  unsigned
+  GetSemaSignatureIndex(const SmallVector &Signature);
 };

This is ambiguous of naming and comment because it also insert signature into 
SemaSignatureTable if not found in the table.



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:597
+  };
+
+  for (const auto &SemaRecord : SemaRecords) {

maybe we need an assert to check SemaRecords is not empty.



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:637
+  std::vector RVVIntrinsicRecords;
+  createRVVIntrinsics(Defs);
+

we only need SemaRecords initialization part of createRVVIntrinsics, right?



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:639
+
+  createRVVIntrinsicRecord(RVVIntrinsicRecords);
+

`createRVVIntrinsicRecord also init SemaSignatureTable implicitly.`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111617

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


[PATCH] D126061: [clang] [WIP] Reject non-declaration C++11 attributes on declarations

2022-05-25 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 431919.
mboehme added a comment.

Changes in response to review comments.

One major change is that Declaration now has a reference to the declaration
attributes instead of owning them by value.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126061

Files:
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Parse/RAIIObjectsForParser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Basic/Attributes.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/ParsedAttr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaDeclObjC.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/Sema/annotate-type.c
  clang/test/SemaCXX/address-space-placement.cpp
  clang/test/SemaCXX/annotate-type.cpp
  clang/test/SemaOpenCL/address-spaces.cl
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3734,7 +3734,7 @@
 if (!StmtSubjects.empty()) {
   OS << "bool diagAppertainsToDecl(Sema &S, const ParsedAttr &AL, ";
   OS << "const Decl *D) const override {\n";
-  OS << "  S.Diag(AL.getLoc(), diag::err_stmt_attribute_invalid_on_decl)\n";
+  OS << "  S.Diag(AL.getLoc(), diag::err_attribute_invalid_on_decl)\n";
   OS << "<< AL << D->getLocation();\n";
   OS << "  return false;\n";
   OS << "}\n\n";
Index: clang/test/SemaOpenCL/address-spaces.cl
===
--- clang/test/SemaOpenCL/address-spaces.cl
+++ clang/test/SemaOpenCL/address-spaces.cl
@@ -266,9 +266,9 @@
   __attribute__((opencl_private)) private_int_t var5;  // expected-warning {{multiple identical address spaces specified for type}}
   __attribute__((opencl_private)) private_int_t *var6; // expected-warning {{multiple identical address spaces specified for type}}
 #if __OPENCL_CPP_VERSION__
-  [[clang::opencl_private]] __global int var7; // expected-error {{multiple address spaces specified for type}}
-  [[clang::opencl_private]] __global int *var8;// expected-error {{multiple address spaces specified for type}}
-  [[clang::opencl_private]] private_int_t var9;// expected-warning {{multiple identical address spaces specified for type}}
-  [[clang::opencl_private]] private_int_t *var10;  // expected-warning {{multiple identical address spaces specified for type}}
+  __global int [[clang::opencl_private]] var7; // expected-error {{multiple address spaces specified for type}}
+  __global int [[clang::opencl_private]] *var8;// expected-error {{multiple address spaces specified for type}}
+  private_int_t [[clang::opencl_private]] var9;// expected-warning {{multiple identical address spaces specified for type}}
+  private_int_t [[clang::opencl_private]] *var10;  // expected-warning {{multiple identical address spaces specified for type}}
 #endif // !__OPENCL_CPP_VERSION__
 }
Index: clang/test/SemaCXX/annotate-type.cpp
===
--- clang/test/SemaCXX/annotate-type.cpp
+++ clang/test/SemaCXX/annotate-type.cpp
@@ -2,10 +2,7 @@
 
 struct S1 {
   void f() [[clang::annotate_type("foo")]];
-  // FIXME: We would want to prohibit the attribute in the following location.
-  // However, Clang currently generally doesn't prohibit type-only C++11
-  // attributes on declarations. This should be fixed more generally.
-  [[clang::annotate_type("foo")]] void g();
+  [[clang::annotate_type("foo")]] void g(); // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
 };
 
 template  struct is_same {
@@ -48,23 +45,21 @@
 
 // More error cases: Prohibit adding the attribute to declarations.
 // Different declarations hit different code paths, so they need separate tests.
-// FIXME: Clang currently generally doesn't prohibit type-only C++11
-// attributes on declarations.
-namespace [[clang::annotate_type("foo")]] my_namespace {}
-struct [[clang::annotate_type("foo")]] S3;
-struct [[clang::annotate_type("foo")]] S3{
-  [[clang::annotate_type("foo")]] int member;
+namespace [[clang::annotate_type("foo")]] my_namespace {} // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
+struct [[clang::annotate_type("foo")]] S3; //

[PATCH] D126061: [clang] [WIP] Reject non-declaration C++11 attributes on declarations

2022-05-25 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 431921.
mboehme added a comment.

Changes in response to review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126061

Files:
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Parse/RAIIObjectsForParser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Basic/Attributes.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/ParsedAttr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaDeclObjC.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/Parser/MicrosoftExtensions.cpp
  clang/test/Parser/asm.c
  clang/test/Parser/asm.cpp
  clang/test/Parser/c2x-attributes.c
  clang/test/Parser/cxx0x-attributes.cpp
  clang/test/Sema/annotate-type.c
  clang/test/SemaCXX/address-space-placement.cpp
  clang/test/SemaCXX/annotate-type.cpp
  clang/test/SemaOpenCL/address-spaces.cl
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3734,7 +3734,7 @@
 if (!StmtSubjects.empty()) {
   OS << "bool diagAppertainsToDecl(Sema &S, const ParsedAttr &AL, ";
   OS << "const Decl *D) const override {\n";
-  OS << "  S.Diag(AL.getLoc(), diag::err_stmt_attribute_invalid_on_decl)\n";
+  OS << "  S.Diag(AL.getLoc(), diag::err_attribute_invalid_on_decl)\n";
   OS << "<< AL << D->getLocation();\n";
   OS << "  return false;\n";
   OS << "}\n\n";
Index: clang/test/SemaOpenCL/address-spaces.cl
===
--- clang/test/SemaOpenCL/address-spaces.cl
+++ clang/test/SemaOpenCL/address-spaces.cl
@@ -266,9 +266,9 @@
   __attribute__((opencl_private)) private_int_t var5;  // expected-warning {{multiple identical address spaces specified for type}}
   __attribute__((opencl_private)) private_int_t *var6; // expected-warning {{multiple identical address spaces specified for type}}
 #if __OPENCL_CPP_VERSION__
-  [[clang::opencl_private]] __global int var7; // expected-error {{multiple address spaces specified for type}}
-  [[clang::opencl_private]] __global int *var8;// expected-error {{multiple address spaces specified for type}}
-  [[clang::opencl_private]] private_int_t var9;// expected-warning {{multiple identical address spaces specified for type}}
-  [[clang::opencl_private]] private_int_t *var10;  // expected-warning {{multiple identical address spaces specified for type}}
+  __global int [[clang::opencl_private]] var7; // expected-error {{multiple address spaces specified for type}}
+  __global int [[clang::opencl_private]] *var8;// expected-error {{multiple address spaces specified for type}}
+  private_int_t [[clang::opencl_private]] var9;// expected-warning {{multiple identical address spaces specified for type}}
+  private_int_t [[clang::opencl_private]] *var10;  // expected-warning {{multiple identical address spaces specified for type}}
 #endif // !__OPENCL_CPP_VERSION__
 }
Index: clang/test/SemaCXX/annotate-type.cpp
===
--- clang/test/SemaCXX/annotate-type.cpp
+++ clang/test/SemaCXX/annotate-type.cpp
@@ -2,10 +2,7 @@
 
 struct S1 {
   void f() [[clang::annotate_type("foo")]];
-  // FIXME: We would want to prohibit the attribute in the following location.
-  // However, Clang currently generally doesn't prohibit type-only C++11
-  // attributes on declarations. This should be fixed more generally.
-  [[clang::annotate_type("foo")]] void g();
+  [[clang::annotate_type("foo")]] void g(); // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
 };
 
 template  struct is_same {
@@ -48,23 +45,21 @@
 
 // More error cases: Prohibit adding the attribute to declarations.
 // Different declarations hit different code paths, so they need separate tests.
-// FIXME: Clang currently generally doesn't prohibit type-only C++11
-// attributes on declarations.
-namespace [[clang::annotate_type("foo")]] my_namespace {}
-struct [[clang::annotate_type("foo")]] S3;
-struct [[clang::annotate_type("foo")]] S3{
-  [[clang::annotate_type("foo")]] int member;
+namespace [[clang::annotate_type("foo")]] my_namespace {} // expected-error {{'annotate_type' attribute cannot be applied to a decla

[PATCH] D126061: [clang] [WIP] Reject non-declaration C++11 attributes on declarations

2022-05-25 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 431923.
mboehme added a comment.

Changes in response to review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126061

Files:
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Parse/RAIIObjectsForParser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Basic/Attributes.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/ParsedAttr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaDeclObjC.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/Parser/MicrosoftExtensions.cpp
  clang/test/Parser/asm.c
  clang/test/Parser/asm.cpp
  clang/test/Parser/c2x-attributes.c
  clang/test/Parser/cxx0x-attributes.cpp
  clang/test/Sema/annotate-type.c
  clang/test/SemaCXX/address-space-placement.cpp
  clang/test/SemaCXX/annotate-type.cpp
  clang/test/SemaOpenCL/address-spaces.cl
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3734,7 +3734,7 @@
 if (!StmtSubjects.empty()) {
   OS << "bool diagAppertainsToDecl(Sema &S, const ParsedAttr &AL, ";
   OS << "const Decl *D) const override {\n";
-  OS << "  S.Diag(AL.getLoc(), diag::err_stmt_attribute_invalid_on_decl)\n";
+  OS << "  S.Diag(AL.getLoc(), diag::err_attribute_invalid_on_decl)\n";
   OS << "<< AL << D->getLocation();\n";
   OS << "  return false;\n";
   OS << "}\n\n";
Index: clang/test/SemaOpenCL/address-spaces.cl
===
--- clang/test/SemaOpenCL/address-spaces.cl
+++ clang/test/SemaOpenCL/address-spaces.cl
@@ -266,9 +266,9 @@
   __attribute__((opencl_private)) private_int_t var5;  // expected-warning {{multiple identical address spaces specified for type}}
   __attribute__((opencl_private)) private_int_t *var6; // expected-warning {{multiple identical address spaces specified for type}}
 #if __OPENCL_CPP_VERSION__
-  [[clang::opencl_private]] __global int var7; // expected-error {{multiple address spaces specified for type}}
-  [[clang::opencl_private]] __global int *var8;// expected-error {{multiple address spaces specified for type}}
-  [[clang::opencl_private]] private_int_t var9;// expected-warning {{multiple identical address spaces specified for type}}
-  [[clang::opencl_private]] private_int_t *var10;  // expected-warning {{multiple identical address spaces specified for type}}
+  __global int [[clang::opencl_private]] var7; // expected-error {{multiple address spaces specified for type}}
+  __global int [[clang::opencl_private]] *var8;// expected-error {{multiple address spaces specified for type}}
+  private_int_t [[clang::opencl_private]] var9;// expected-warning {{multiple identical address spaces specified for type}}
+  private_int_t [[clang::opencl_private]] *var10;  // expected-warning {{multiple identical address spaces specified for type}}
 #endif // !__OPENCL_CPP_VERSION__
 }
Index: clang/test/SemaCXX/annotate-type.cpp
===
--- clang/test/SemaCXX/annotate-type.cpp
+++ clang/test/SemaCXX/annotate-type.cpp
@@ -2,10 +2,7 @@
 
 struct S1 {
   void f() [[clang::annotate_type("foo")]];
-  // FIXME: We would want to prohibit the attribute in the following location.
-  // However, Clang currently generally doesn't prohibit type-only C++11
-  // attributes on declarations. This should be fixed more generally.
-  [[clang::annotate_type("foo")]] void g();
+  [[clang::annotate_type("foo")]] void g(); // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
 };
 
 template  struct is_same {
@@ -48,23 +45,21 @@
 
 // More error cases: Prohibit adding the attribute to declarations.
 // Different declarations hit different code paths, so they need separate tests.
-// FIXME: Clang currently generally doesn't prohibit type-only C++11
-// attributes on declarations.
-namespace [[clang::annotate_type("foo")]] my_namespace {}
-struct [[clang::annotate_type("foo")]] S3;
-struct [[clang::annotate_type("foo")]] S3{
-  [[clang::annotate_type("foo")]] int member;
+namespace [[clang::annotate_type("foo")]] my_namespace {} // expected-error {{'annotate_type' attribute cannot be applied to a decla

[PATCH] D125400: [clang][Analyzer] Add errno state to standard functions modeling.

2022-05-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 431924.
balazske edited the summary of this revision.
balazske added a comment.

fixed some problems


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125400

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/Inputs/system-header-simulator-for-errno.h
  clang/test/Analysis/errno-stdlibraryfunctions.c

Index: clang/test/Analysis/errno-stdlibraryfunctions.c
===
--- /dev/null
+++ clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -0,0 +1,34 @@
+// RUN: %clang_analyze_cc1 -verify -analyzer-output text %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=apiModeling.Errno \
+// RUN:   -analyzer-checker=alpha.unix.Errno \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true
+
+#include "Inputs/errno_var.h"
+#include "Inputs/system-header-simulator-for-errno.h"
+
+void test1() {
+  access("path", 0); // no note here
+  access("path", 0);
+  // expected-note@-1{{Assuming that function 'access' is successful, in this case the value 'errno' may be undefined after the call and should not be used}}
+  if (errno != 0) { }
+  // expected-warning@-1{{An undefined value may be read from 'errno'}}
+  // expected-note@-2{{An undefined value may be read from 'errno'}}
+}
+
+void test2() {
+  if (access("path", 0) == -1) {
+if (errno != 0) { }
+  }
+}
+
+void test3() {
+  if (access("path", 0) != -1) {
+// expected-note@-1{{Assuming that function 'access' is successful, in this case the value 'errno' may be undefined after the call and should not be used}}
+// expected-note@-2{{Taking true branch}}
+if (errno != 0) { }
+// expected-warning@-1{{An undefined value may be read from 'errno'}}
+// expected-note@-2{{An undefined value may be read from 'errno'}}
+  }
+}
Index: clang/test/Analysis/Inputs/system-header-simulator-for-errno.h
===
--- /dev/null
+++ clang/test/Analysis/Inputs/system-header-simulator-for-errno.h
@@ -0,0 +1,6 @@
+#pragma clang system_header
+
+typedef __typeof(sizeof(int)) off_t;
+
+int access(const char *path, int amode);
+off_t lseek(int fildes, off_t offset, int whence);
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -40,6 +40,7 @@
 //
 //===--===//
 
+#include "ErrnoModeling.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -56,6 +57,19 @@
 using namespace clang;
 using namespace clang::ento;
 
+static const char *describeErrnoCheckState(errno_modeling::ErrnoCheckState CS) {
+  switch (CS) {
+  case errno_modeling::Errno_Irrelevant:
+return "is not significant";
+  case errno_modeling::Errno_MustBeChecked:
+return "should be checked to verify if the call was successful";
+  case errno_modeling::Errno_MustNotBeChecked:
+return "may be undefined after the call and should not be used";
+  default:
+llvm_unreachable("unknown enum value");
+  };
+}
+
 namespace {
 class StdLibraryFunctionsChecker
 : public Checker {
@@ -377,6 +391,113 @@
   /// The complete list of constraints that defines a single branch.
   using ConstraintSet = std::vector;
 
+  /// Define how a function affects the system variable 'errno'.
+  /// This works together with the ErrnoModeling and ErrnoChecker classes.
+  class ErrnoConstraintBase {
+  public:
+/// Apply specific state changes related to the errno variable.
+virtual ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
+  const Summary &Summary,
+  CheckerContext &C) const = 0;
+/// Get a description about what is applied to 'errno' and how is it allowed
+/// to be used. If ErrnoChecker generates a bug then this message is
+/// displayed as a note at the function call.
+/// It may return empty string if no note tag is to be added.
+virtual std::string describe(StringRef FunctionName) const { return ""; }
+
+virtual ~ErrnoConstraintBase() {}
+
+  protected:
+/// Many of the descendant classes use this value.
+errno_modeling::ErrnoCheckState const CheckState;
+
+ErrnoConstraintBase(errno_modeling::ErrnoCheckState CS) : CheckState(CS) {}
+
+/// This is used for conjure symbol for errno to differentiate from the
+/// original call expression (same expression is used for the errno symbol

[PATCH] D126364: Fix interaction of pragma FENV_ACCESS with other pragmas

2022-05-25 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff created this revision.
sepavloff added reviewers: aaron.ballman, andrew.w.kaylor, rjmccall, efriedma, 
kpn.
Herald added a project: All.
sepavloff requested review of this revision.
Herald added a project: clang.

Previously `#pragma STDC FENV_ACCESS ON` always set dynamic rounding
mode and strict exception handling. It is however too pessimistic in
many cases. In practice the pragma can be used to change rounding mode
only or to check exception flags without changing rounding mode. It
could be made by using other pragmas, `FENV_ROUND` or `clang fp
exception`, but their effect was overwritten by `FENV_ACCESS`. This
change modifies treatment of this pragma so that it sets rounding and
exception handling only if they are not set by other pragmas.

Also `#pragma STDC FENV_ACCESS OFF` turned off only FEnvAccess flag
leaving rounding mode and exception handling unchanged, which does not
make sense in many cases. The change fixes this behavior also.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126364

Files:
  clang/lib/Sema/SemaAttr.cpp
  clang/test/CodeGen/pragma-fenv_access.c

Index: clang/test/CodeGen/pragma-fenv_access.c
===
--- clang/test/CodeGen/pragma-fenv_access.c
+++ clang/test/CodeGen/pragma-fenv_access.c
@@ -20,7 +20,7 @@
   return x + y;
 }
 // CHECK-LABEL: @func_02
-// CHECK: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.ignore")
+// CHECK: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.ignore")
 
 
 float func_03(float x, float y) {
@@ -41,7 +41,7 @@
   return x + y;
 }
 // CHECK-LABEL: @func_04
-// CHECK: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.ignore")
+// CHECK: fadd float
 
 
 float func_05(float x, float y) {
@@ -57,7 +57,7 @@
   return x + y;
 }
 // CHECK-LABEL: @func_06
-// CHECK: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.ignore")
+// CHECK: fadd float
 
 
 float func_07(float x, float y) {
@@ -69,6 +69,58 @@
   return y + 4;
 }
 // CHECK-LABEL: @func_07
-// CHECK: call float @llvm.experimental.constrained.fsub.f32(float {{.*}}, float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.strict")
+// CHECK: call float @llvm.experimental.constrained.fsub.f32(float {{.*}}, float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.ignore")
 // CHECK: call float @llvm.experimental.constrained.fmul.f32(float {{.*}}, float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.strict")
-// CHECK: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.strict")
+// CHECK: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.ignore")
+
+
+float func_08(float x, float y) {
+  #pragma STDC FENV_ROUND FE_UPWARD
+  #pragma STDC FENV_ACCESS ON
+  return x + y;
+}
+// CHECK-LABEL: @func_08
+// CHECK:  call float @llvm.experimental.constrained.fadd.f32({{.*}}, metadata !"round.upward", metadata !"fpexcept.strict")
+
+
+float func_09(float x, float y) {
+  #pragma clang fp exceptions(maytrap)
+  #pragma STDC FENV_ACCESS ON
+  return x + y;
+}
+// CHECK-LABEL: @func_09
+// CHECK:  call float @llvm.experimental.constrained.fadd.f32({{.*}}, metadata !"round.dynamic", metadata !"fpexcept.maytrap")
+
+float func_10(float x, float y) {
+  #pragma clang fp exceptions(maytrap)
+  #pragma STDC FENV_ROUND FE_UPWARD
+  #pragma STDC FENV_ACCESS ON
+  return x + y;
+}
+// CHECK-LABEL: @func_10
+// CHECK:  call float @llvm.experimental.constrained.fadd.f32({{.*}}, metadata !"round.upward", metadata !"fpexcept.maytrap")
+
+float func_11(float x, float y, float z) {
+  #pragma STDC FENV_ACCESS ON
+  float res = x * y;
+  {
+#pragma STDC FENV_ACCESS OFF
+return res + z;
+  }
+}
+// CHECK-LABEL: @func_11
+// CHECK:  call float @llvm.experimental.constrained.fmul.f32({{.*}}, metadata !"round.dynamic", metadata !"fpexcept.strict")
+// CHECK:  call float @llvm.experimental.constrained.fadd.f32({{.*}}, metadata !"round.tonearest", metadata !"fpexcept.ignore")
+
+float func_12(float x, float y, float z) {
+  #pragma STDC FENV_ROUND FE_TOWARDZERO
+  #pragma STDC FENV_ACCESS ON
+  float res = x * y;
+  {
+#pragma STDC FENV_ACCESS OFF
+return res + z;
+  }
+}
+// CHECK-LABEL: @func_12
+// CHECK:  call float @llvm.experimental.constrained.fmul.f32({{.*}}, metadata !"round.towardzero", metadata !"fpexcept.strict")
+// CHECK:  call float @llvm.experimental.constrained.fadd.f32({{.*}}, metadata !"round.towardzero", metadata !"fpexcept.ignore")
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clan

[PATCH] D125862: [clang][driver] Add gcc-toolset/devtoolset 12 to prefixes

2022-05-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 431928.
tbaeder added a comment.

@MaskRay Ignored the new test on Windows hosts now like you suggested. Does 
this look good?


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

https://reviews.llvm.org/D125862

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/unittests/Driver/ToolChainTest.cpp

Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -18,6 +18,7 @@
 #include "clang/Driver/Driver.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/MC/TargetRegistry.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
@@ -610,4 +611,100 @@
   DiagConsumer->clear();
 }
 
+TEST(ToolChainTest, Toolsets) {
+
+  // Ignore this test on Windows hosts.
+  llvm::Triple Host(llvm::sys::getProcessTriple());
+  if (Host.isOSWindows())
+GTEST_SKIP();
+
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  struct TestDiagnosticConsumer : public DiagnosticConsumer {};
+
+  // Check (newer) GCC toolset installation.
+  {
+IntrusiveRefCntPtr InMemoryFileSystem(
+new llvm::vfs::InMemoryFileSystem);
+
+// These should be ignored.
+InMemoryFileSystem->addFile("/opt/rh/gcc-toolset-2", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+InMemoryFileSystem->addFile("/opt/rh/gcc-toolset-", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+InMemoryFileSystem->addFile("/opt/rh/gcc-toolset--", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+InMemoryFileSystem->addFile("/opt/rh/gcc-toolset--1", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+
+// File needed for GCC installation detection.
+InMemoryFileSystem->addFile(
+"/opt/rh/gcc-toolset-12/lib/gcc/x86_64-redhat-linux/11/crtbegin.o", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+
+DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+Driver TheDriver("/bin/clang", "x86_64-redhat-linux", Diags,
+ "clang LLVM compiler", InMemoryFileSystem);
+std::unique_ptr C(
+TheDriver.BuildCompilation({"--gcc-toolchain="}));
+ASSERT_TRUE(C);
+std::string S;
+{
+  llvm::raw_string_ostream OS(S);
+  C->getDefaultToolChain().printVerboseInfo(OS);
+}
+if (is_style_windows(llvm::sys::path::Style::native))
+  std::replace(S.begin(), S.end(), '\\', '/');
+EXPECT_EQ("Found candidate GCC installation: "
+  "/opt/rh/gcc-toolset-12/lib/gcc/x86_64-redhat-linux/11\n"
+  "Selected GCC installation: "
+  "/opt/rh/gcc-toolset-12/lib/gcc/x86_64-redhat-linux/11\n"
+  "Candidate multilib: .;@m64\n"
+  "Selected multilib: .;@m64\n",
+  S);
+  }
+
+  // And older devtoolset.
+  {
+IntrusiveRefCntPtr InMemoryFileSystem(
+new llvm::vfs::InMemoryFileSystem);
+
+// These should be ignored.
+InMemoryFileSystem->addFile("/opt/rh/devtoolset-2", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+InMemoryFileSystem->addFile("/opt/rh/devtoolset-", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+InMemoryFileSystem->addFile("/opt/rh/devtoolset--", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+InMemoryFileSystem->addFile("/opt/rh/devtoolset--1", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+
+// File needed for GCC installation detection.
+InMemoryFileSystem->addFile(
+"/opt/rh/devtoolset-12/lib/gcc/x86_64-redhat-linux/11/crtbegin.o", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+
+DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+Driver TheDriver("/bin/clang", "x86_64-redhat-linux", Diags,
+ "clang LLVM compiler", InMemoryFileSystem);
+std::unique_ptr C(
+TheDriver.BuildCompilation({"--gcc-toolchain="}));
+ASSERT_TRUE(C);
+std::string S;
+{
+  llvm::raw_string_ostream OS(S);
+  C->getDefaultToolChain().printVerboseInfo(OS);
+}
+if (is_style_windows(llvm::sys::path::Style::native))
+  std::replace(S.begin(), S.end(), '\\', '/');
+EXPECT_EQ("Found candidate GCC installation: "
+  "/opt/rh/devtoolset-12/lib/gcc/x86_64-redhat-linux/11\n"
+  "Selected GCC installation: "
+  "/opt/rh/devtoolset-12/lib/gcc/x86_64-redhat-linux/11\n"
+  "Candidate multilib: .;@m64\n"
+  "Selected multilib: .;@m64\n",
+  S);
+  }
+}
+
 } // end anonymous namespace.
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===

[PATCH] D126061: [clang] [WIP] Reject non-declaration C++11 attributes on declarations

2022-05-25 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 431929.
mboehme marked 2 inline comments as done.
mboehme added a comment.

Changes in response to review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126061

Files:
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Parse/RAIIObjectsForParser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Basic/Attributes.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/ParsedAttr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaDeclObjC.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/Parser/MicrosoftExtensions.cpp
  clang/test/Parser/asm.c
  clang/test/Parser/asm.cpp
  clang/test/Parser/c2x-attributes.c
  clang/test/Parser/cxx0x-attributes.cpp
  clang/test/Sema/annotate-type.c
  clang/test/SemaCXX/address-space-placement.cpp
  clang/test/SemaCXX/annotate-type.cpp
  clang/test/SemaOpenCL/address-spaces.cl
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3734,7 +3734,7 @@
 if (!StmtSubjects.empty()) {
   OS << "bool diagAppertainsToDecl(Sema &S, const ParsedAttr &AL, ";
   OS << "const Decl *D) const override {\n";
-  OS << "  S.Diag(AL.getLoc(), diag::err_stmt_attribute_invalid_on_decl)\n";
+  OS << "  S.Diag(AL.getLoc(), diag::err_attribute_invalid_on_decl)\n";
   OS << "<< AL << D->getLocation();\n";
   OS << "  return false;\n";
   OS << "}\n\n";
Index: clang/test/SemaOpenCL/address-spaces.cl
===
--- clang/test/SemaOpenCL/address-spaces.cl
+++ clang/test/SemaOpenCL/address-spaces.cl
@@ -266,9 +266,9 @@
   __attribute__((opencl_private)) private_int_t var5;  // expected-warning {{multiple identical address spaces specified for type}}
   __attribute__((opencl_private)) private_int_t *var6; // expected-warning {{multiple identical address spaces specified for type}}
 #if __OPENCL_CPP_VERSION__
-  [[clang::opencl_private]] __global int var7; // expected-error {{multiple address spaces specified for type}}
-  [[clang::opencl_private]] __global int *var8;// expected-error {{multiple address spaces specified for type}}
-  [[clang::opencl_private]] private_int_t var9;// expected-warning {{multiple identical address spaces specified for type}}
-  [[clang::opencl_private]] private_int_t *var10;  // expected-warning {{multiple identical address spaces specified for type}}
+  __global int [[clang::opencl_private]] var7; // expected-error {{multiple address spaces specified for type}}
+  __global int [[clang::opencl_private]] *var8;// expected-error {{multiple address spaces specified for type}}
+  private_int_t [[clang::opencl_private]] var9;// expected-warning {{multiple identical address spaces specified for type}}
+  private_int_t [[clang::opencl_private]] *var10;  // expected-warning {{multiple identical address spaces specified for type}}
 #endif // !__OPENCL_CPP_VERSION__
 }
Index: clang/test/SemaCXX/annotate-type.cpp
===
--- clang/test/SemaCXX/annotate-type.cpp
+++ clang/test/SemaCXX/annotate-type.cpp
@@ -2,10 +2,7 @@
 
 struct S1 {
   void f() [[clang::annotate_type("foo")]];
-  // FIXME: We would want to prohibit the attribute in the following location.
-  // However, Clang currently generally doesn't prohibit type-only C++11
-  // attributes on declarations. This should be fixed more generally.
-  [[clang::annotate_type("foo")]] void g();
+  [[clang::annotate_type("foo")]] void g(); // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
 };
 
 template  struct is_same {
@@ -48,23 +45,21 @@
 
 // More error cases: Prohibit adding the attribute to declarations.
 // Different declarations hit different code paths, so they need separate tests.
-// FIXME: Clang currently generally doesn't prohibit type-only C++11
-// attributes on declarations.
-namespace [[clang::annotate_type("foo")]] my_namespace {}
-struct [[clang::annotate_type("foo")]] S3;
-struct [[clang::annotate_type("foo")]] S3{
-  [[clang::annotate_type("foo")]] int member;
+namespace [[clang::annotate_type("foo")]] my_namespace {} // expected-error {{'annotate_ty

[clang-tools-extra] f1df651 - [pseudo] Add missing dependency, fix shared library build.

2022-05-25 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-05-25T12:38:23+02:00
New Revision: f1df6515e3fe54f688739927c57cb6adec01c307

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

LOG: [pseudo] Add missing dependency, fix shared library build.

Added: 


Modified: 
clang-tools-extra/pseudo/benchmarks/CMakeLists.txt
clang-tools-extra/pseudo/fuzzer/CMakeLists.txt
clang-tools-extra/pseudo/tool/CMakeLists.txt
clang-tools-extra/pseudo/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/pseudo/benchmarks/CMakeLists.txt 
b/clang-tools-extra/pseudo/benchmarks/CMakeLists.txt
index 20804061ffdb5..b088f8f7c68b8 100644
--- a/clang-tools-extra/pseudo/benchmarks/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/benchmarks/CMakeLists.txt
@@ -3,5 +3,6 @@ add_benchmark(ClangPseudoBenchmark Benchmark.cpp)
 target_link_libraries(ClangPseudoBenchmark
   PRIVATE
   clangPseudo
+  clangPseudoGrammar
   LLVMSupport
   )

diff  --git a/clang-tools-extra/pseudo/fuzzer/CMakeLists.txt 
b/clang-tools-extra/pseudo/fuzzer/CMakeLists.txt
index 556c2f438d388..e5061cee3bf9d 100644
--- a/clang-tools-extra/pseudo/fuzzer/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/fuzzer/CMakeLists.txt
@@ -11,4 +11,5 @@ add_llvm_fuzzer(clang-pseudo-fuzzer
 target_link_libraries(clang-pseudo-fuzzer
   PRIVATE
   clangPseudo
+  clangPseudoGrammar
   )

diff  --git a/clang-tools-extra/pseudo/tool/CMakeLists.txt 
b/clang-tools-extra/pseudo/tool/CMakeLists.txt
index bf73f89d4e1dd..8b47d54e766c2 100644
--- a/clang-tools-extra/pseudo/tool/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/tool/CMakeLists.txt
@@ -12,5 +12,6 @@ clang_target_link_libraries(clang-pseudo
 target_link_libraries(clang-pseudo
   PRIVATE
   clangPseudo
+  clangPseudoGrammar
   )
 

diff  --git a/clang-tools-extra/pseudo/unittests/CMakeLists.txt 
b/clang-tools-extra/pseudo/unittests/CMakeLists.txt
index 73b13984d93e6..2185e4e4c146b 100644
--- a/clang-tools-extra/pseudo/unittests/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/unittests/CMakeLists.txt
@@ -23,4 +23,5 @@ clang_target_link_libraries(ClangPseudoTests
 target_link_libraries(ClangPseudoTests
   PRIVATE
   clangPseudo
+  clangPseudoGrammar
   )



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


[PATCH] D126291: [flang][Driver] Update link job on windows

2022-05-25 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added a comment.

@rovka in case you missed this, the test is failing in windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126291

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


[PATCH] D126324: [clang] Allow const variables with weak attribute to be overridden

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

Diff updated to be git-clang-format clean and to (hopefully) accommodate for 
differences in test output on w64.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126324

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/global-init.c
  clang/test/CodeGen/weak_constant.c

Index: clang/test/CodeGen/weak_constant.c
===
--- clang/test/CodeGen/weak_constant.c
+++ clang/test/CodeGen/weak_constant.c
@@ -1,13 +1,31 @@
 // RUN: %clang_cc1 -w -emit-llvm %s -O1 -o - | FileCheck %s
-// Check for bug compatibility with gcc.
+// This used to "check for bug compatibility with gcc".
+// Now it checks that that the "weak" declaration makes the value
+// fully interposable whereas a "selectany" one is handled as constant
+// and propagated.
 
+// CHECK: @x = weak {{.*}}constant i32 123
 const int x __attribute((weak)) = 123;
 
+// CHECK: @y = weak_odr {{.*}}constant i32 234
+const int y __attribute((selectany)) = 234;
+
 int* f(void) {
   return &x;
 }
 
 int g(void) {
-  // CHECK: ret i32 123
+  // CHECK: load i32, ptr @x
+  // CHECK-NOT: ret i32 123
   return *f();
 }
+
+int *k(void) {
+  return &y;
+}
+
+int l(void) {
+  // CHECK-NOT: load i32, ptr @y
+  // CHECK: ret i32 234
+  return *k();
+}
Index: clang/test/CodeGen/global-init.c
===
--- clang/test/CodeGen/global-init.c
+++ clang/test/CodeGen/global-init.c
@@ -9,14 +9,20 @@
 
 // This should get normal weak linkage.
 int c __attribute__((weak))= 0;
-// CHECK: @c = weak{{.*}} global i32 0
+// CHECK: @c = weak global i32 0
 
-
-// Since this is marked const, it should get weak_odr linkage, since all
-// definitions have to be the same.
-// CHECK: @d = weak_odr constant i32 0
+// Even though is marked const, it should get still get "weak"
+// linkage, not "weak_odr" as the weak attribute makes it possible
+// that there is a strong definition that changes the value linktime,
+// so the value must not be considered constant.
+// CHECK: @d = weak constant i32 0
 const int d __attribute__((weak))= 0;
 
+// However, "selectany" is similar to "weak", but isn't interposable
+// by a strong definition, and should appear as weak_odr.
+// CHECK: @e = weak_odr constant i32 17
+const int e __attribute__((selectany)) = 17;
+
 // PR6168 "too many undefs"
 struct ManyFields {
   int a;
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4893,12 +4893,8 @@
   if (Linkage == GVA_Internal)
 return llvm::Function::InternalLinkage;
 
-  if (D->hasAttr()) {
-if (IsConstantVariable)
-  return llvm::GlobalVariable::WeakODRLinkage;
-else
-  return llvm::GlobalVariable::WeakAnyLinkage;
-  }
+  if (D->hasAttr())
+return llvm::GlobalVariable::WeakAnyLinkage;
 
   if (const auto *FD = D->getAsFunction())
 if (FD->isMultiVersion() && Linkage == GVA_AvailableExternally)
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -6477,3 +6477,69 @@
 The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-groupindex
   }];
 }
+
+def WeakDocs : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+
+In supported output formats the ``weak`` attribute can be used to
+specify that a variable or function should be emitted as a symbol with
+``weak`` (if a definition) or ``extern_weak`` (if a declaration of an
+external symbol) `linkage
+`_.
+
+If there is a non-weak definition of the symbol the linker will select
+that over the weak. They must have same type and alignment (variables
+must also have the same size), but may have a different value.
+
+If there are multiple weak definitions of same symbol, but no non-weak
+definition, they should have same type, size, alignment and value, the
+linker will select one of them (see also selectany_ attribute).
+
+If the ``weak`` attribute is applied to a ``const`` qualified variable
+definition that variable is no longer consider a compiletime constant
+as its value can change during linking (or dynamic linking). This
+means that it can e.g no longer be part of an initializer expression.
+
+.. code-block:: c
+
+  const int ANSWER __attribute__ ((weak)) = 42;
+
+  /* This function may be replaced link-time */
+  __attribute__ ((weak)) void debug_log(const char *msg)
+  {
+  fprintf(stderr, "DEBUG: %s\n", msg);
+  }
+
+  int main(int argc, const char **argv)
+  {
+  debug_

[PATCH] D126365: [clang-format] Stop ignoring changes for files with space in path

2022-05-25 Thread Eitot via Phabricator via cfe-commits
Eitot created this revision.
Eitot added a project: clang-format.
Herald added a project: All.
Eitot requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`git-clang-format` does not format files with spaces in their path.

  % git diff -p -U0 
  diff --git a/Test/Application/AppDelegate.m b/Test/Application/AppDelegate.m
  index 8bdd8b4..3effa19 100644
  --- a/Test/Application/AppDelegate.m
  +++ b/Test/Application/AppDelegate.m
  @@ -17 +17,2 @@ @implementation AppDelegate
  -- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
  +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
  +{
  diff --git a/Test/Main Window/MainWindowController.m b/Test/Main 
Window/MainWindowController.m
  index df56059..49e1a9f 100644
  --- a/Test/Main Window/MainWindowController.m   
  +++ b/Test/Main Window/MainWindowController.m   
  @@ -16 +16,2 @@ @implementation MainWindowController
  -- (void)windowDidLoad {
  +- (void)windowDidLoad
  +{



  % git-clang-format -v
  Ignoring changes in the following files (wrong extension or symlink):
  Test/Main Window/MainWindowController.m   
  Running clang-format on the following files:
  Test/Application/AppDelegate.m
  old tree: 9cbacaf7a33dd4184bdc46ae93c6295cfef56030
  new tree: 2a60aca2e1252612dd07032151c32536fcda6758
  changed files:
  Test/Application/AppDelegate.m

The issue is not the space itself, but the tab character appended to the path 
(`Test/Main Window/MainWindowController.m\t`) by `git-diff`.

This has been reported before at https://bugs.llvm.org/show_bug.cgi?id=28654.

Resolves https://github.com/llvm/llvm-project/issues/29028#issue-1076357057


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126365

Files:
  clang/tools/clang-format/git-clang-format


Index: clang/tools/clang-format/git-clang-format
===
--- clang/tools/clang-format/git-clang-format
+++ clang/tools/clang-format/git-clang-format
@@ -345,7 +345,7 @@
 line = convert_string(line)
 match = re.search(r'^\+\+\+\ [^/]+/(.*)', line)
 if match:
-  filename = match.group(1).rstrip('\r\n')
+  filename = match.group(1).rstrip('\r\n\t')
 match = re.search(r'^@@ -[0-9,]+ \+(\d+)(,(\d+))?', line)
 if match:
   start_line = int(match.group(1))


Index: clang/tools/clang-format/git-clang-format
===
--- clang/tools/clang-format/git-clang-format
+++ clang/tools/clang-format/git-clang-format
@@ -345,7 +345,7 @@
 line = convert_string(line)
 match = re.search(r'^\+\+\+\ [^/]+/(.*)', line)
 if match:
-  filename = match.group(1).rstrip('\r\n')
+  filename = match.group(1).rstrip('\r\n\t')
 match = re.search(r'^@@ -[0-9,]+ \+(\d+)(,(\d+))?', line)
 if match:
   start_line = int(match.group(1))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126365: [clang-format] Stop ignoring changes for files with space in path

2022-05-25 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

Would it be possible to add a test please?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126365

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


[PATCH] D126358: clang-format][NFC] Refactor UnwrappedLineParser::parseBlock()

2022-05-25 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:874
 
-  if (SimpleBlock && !KeepBraces) {
+  auto RemoveBraces = [=]() mutable {
+if (KeepBraces || !SimpleBlock)

Are there many captures here? Wouldn't it be better to be explicit and/or 
capture by ref? Do we need a mutable lambda?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126358

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


[PATCH] D125679: [Clang] Added options for integrated backend only used for SPIR-V for now

2022-05-25 Thread Anastasia Stulova via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG730dc4e9bce8: [Clang] Added options for integrated backend. 
(authored by Anastasia).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D125679?vs=429676&id=431938#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125679

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/SPIRV.h
  clang/test/Driver/clang_f_opts.c
  clang/test/Driver/spirv-toolchain.cl

Index: clang/test/Driver/spirv-toolchain.cl
===
--- clang/test/Driver/spirv-toolchain.cl
+++ clang/test/Driver/spirv-toolchain.cl
@@ -69,3 +69,11 @@
 // SPLINK-SAME: "-o" [[BC:".*bc"]]
 // SPLINK: {{llvm-spirv.*"}} [[BC]] "-o" [[SPV2:".*o"]]
 // SPLINK: {{spirv-link.*"}} [[SPV1]] [[SPV2]] "-o" "a.out"
+
+//-
+// Check external vs internal object emission.
+// RUN: %clang -### --target=spirv64 -fno-integrated-objemitter %s 2>&1 | FileCheck --check-prefix=XTOR %s
+// RUN: %clang -### --target=spirv64 -fintegrated-objemitter %s 2>&1 | FileCheck --check-prefix=BACKEND %s
+
+// XTOR: {{llvm-spirv.*"}}
+// BACKEND-NOT: {{llvm-spirv.*"}}
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -605,3 +605,8 @@
 // CHECK_JMC_WARN_NOT_ELF: -fjmc works only for ELF; option ignored
 // CHECK_NOJMC-NOT: -fjmc
 // CHECK_JMC: -fjmc
+
+// RUN: %clang -### -fintegrated-objemitter -target x86_64 %s 2>&1 | FileCheck -check-prefix=CHECK-INT-OBJEMITTER %s
+// CHECK-INT-OBJEMITTER-NOT: unsupported option '-fintegrated-objemitter' for target
+// RUN: %clang -### -fno-integrated-objemitter -target x86_64 %s 2>&1 | FileCheck -check-prefix=CHECK-NOINT-OBJEMITTER %s
+// CHECK-NOINT-OBJEMITTER: unsupported option '-fno-integrated-objemitter' for target
Index: clang/lib/Driver/ToolChains/SPIRV.h
===
--- clang/lib/Driver/ToolChains/SPIRV.h
+++ clang/lib/Driver/ToolChains/SPIRV.h
@@ -64,8 +64,9 @@
   : ToolChain(D, Triple, Args) {}
 
   bool useIntegratedAs() const override { return true; }
-  bool useIntegratedBackend() const override { return false; }
 
+  bool IsIntegratedBackendDefault() const override { return false; }
+  bool IsNonIntegratedBackendSupported() const override { return true; }
   bool IsMathErrnoDefault() const override { return false; }
   bool isCrossCompiling() const override { return true; }
   bool isPICDefault() const override { return false; }
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -106,6 +106,34 @@
   IsIntegratedAssemblerDefault());
 }
 
+bool ToolChain::useIntegratedBackend() const {
+  assert(
+  ((IsIntegratedBackendDefault() && IsIntegratedBackendSupported()) ||
+   (!IsIntegratedBackendDefault() || IsNonIntegratedBackendSupported())) &&
+  "(Non-)integrated backend set incorrectly!");
+
+  bool IBackend = Args.hasFlag(options::OPT_fintegrated_objemitter,
+   options::OPT_fno_integrated_objemitter,
+   IsIntegratedBackendDefault());
+
+  // Diagnose when integrated-objemitter options are not supported by this
+  // toolchain.
+  unsigned DiagID;
+  if ((IBackend && !IsIntegratedBackendSupported()) ||
+  (!IBackend && !IsNonIntegratedBackendSupported()))
+DiagID = clang::diag::err_drv_unsupported_opt_for_target;
+  else
+DiagID = clang::diag::warn_drv_unsupported_opt_for_target;
+  Arg *A = Args.getLastArg(options::OPT_fno_integrated_objemitter);
+  if (A && !IsNonIntegratedBackendSupported())
+D.Diag(DiagID) << A->getAsString(Args) << Triple.getTriple();
+  A = Args.getLastArg(options::OPT_fintegrated_objemitter);
+  if (A && !IsIntegratedBackendSupported())
+D.Diag(DiagID) << A->getAsString(Args) << Triple.getTriple();
+
+  return IBackend;
+}
+
 bool ToolChain::useRelaxRelocations() const {
   return ENABLE_X86_RELAX_RELOCATIONS;
 }
Index: clang/include/clang/Driver/ToolChain.h
===
--- clang/include/clang/Driver/ToolChain.h
+++ clang/include/clang/Driver/ToolChain.h
@@ -385,11 +385,23 @@
   /// by default.
   virtual bool IsIntegratedAssemblerDefault() const { return false; }
 
+  /// IsIntegratedBackendDefault - Does this tool chain enable
+  /// -fintegrated-objemitter by default.
+  virtual bool IsIntegratedBackendDefault() const { return true; }
+
+  /// IsIntegratedBackendSup

[clang] 730dc4e - [Clang] Added options for integrated backend.

2022-05-25 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2022-05-25T12:07:33+01:00
New Revision: 730dc4e9bce8189c037a32e520d18b141250d265

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

LOG: [Clang] Added options for integrated backend.

Following the new flow for external object code emission,
provide flags to switch between integrated and external
backend similar to the integrated assembler options.

SPIR-V target is the only user of this functionality at
this point.

This patch also updated SPIR-V documentation to clarify
that integrated object code emission for SPIR-V is an
experimental feature.

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

Added: 


Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Driver/Options.td
clang/include/clang/Driver/ToolChain.h
clang/lib/Driver/ToolChain.cpp
clang/lib/Driver/ToolChains/SPIRV.h
clang/test/Driver/clang_f_opts.c
clang/test/Driver/spirv-toolchain.cl

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index aaba6dffd2e5b..45de85d342c80 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3180,8 +3180,8 @@ Generic Targets
 
.. code-block:: console
 
-$ clang -target spirv32 test.cl
-$ clang -target spirv64 test.cl
+$ clang -target spirv32 -c test.cl
+$ clang -target spirv64 -c test.cl
 
   More details can be found in :ref:`the SPIR-V support section `.
 
@@ -3657,8 +3657,8 @@ Example usage for OpenCL kernel compilation:
 
.. code-block:: console
 
- $ clang -target spirv32 test.cl
- $ clang -target spirv64 test.cl
+ $ clang -target spirv32 -c test.cl
+ $ clang -target spirv64 -c test.cl
 
 Both invocations of Clang will result in the generation of a SPIR-V binary file
 `test.o` for 32 bit and 64 bit respectively. This file can be imported
@@ -3669,6 +3669,18 @@ Converting to SPIR-V produced with the optimization 
levels other than `-O0` is
 currently available as an experimental feature and it is not guaranteed to work
 in all cases.
 
+Clang also supports integrated generation of SPIR-V without use of 
``llvm-spirv``
+tool as an experimental feature when ``-fintegrated-objemitter`` flag is 
passed in
+the command line.
+
+   .. code-block:: console
+
+ $ clang -target spirv32 -fintegrated-objemitter -c test.cl
+
+Note that only very basic functionality is supported at this point and 
therefore
+it is not suitable for arbitrary use cases. This feature is only enabled when 
clang
+build is configured with ``-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=SPIRV`` option.
+
 Linking is done using ``spirv-link`` from `the SPIRV-Tools project
 `_. Similar to other 
external
 linkers, Clang will expect ``spirv-link`` to be installed separately and to be
@@ -3676,6 +3688,10 @@ present in the ``PATH`` environment variable. Please 
refer to `the build and
 installation instructions
 `_.
 
+   .. code-block:: console
+
+ $ clang -target spirv64 test1.cl test2.cl
+
 .. _clang-cl:
 
 clang-cl

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 55f4f0999c403..d34cec766a2e2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4170,6 +4170,13 @@ def fno_integrated_cc1 : Flag<["-"], 
"fno-integrated-cc1">,
  Flags<[CoreOption, NoXarchOption]>, Group,
  HelpText<"Spawn a separate process for each cc1">;
 
+def fintegrated_objemitter : Flag<["-"], "fintegrated-objemitter">,
+  Flags<[CoreOption, NoXarchOption]>, Group,
+  HelpText<"Use internal machine object code emitter.">;
+def fno_integrated_objemitter : Flag<["-"], "fno-integrated-objemitter">,
+  Flags<[CoreOption, NoXarchOption]>, Group,
+  HelpText<"Use external machine object code emitter.">;
+
 def : Flag<["-"], "integrated-as">, Alias, 
Flags<[NoXarchOption]>;
 def : Flag<["-"], "no-integrated-as">, Alias,
   Flags<[CC1Option, FlangOption, NoXarchOption]>;

diff  --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 269b24dc83c39..0bc345a970dfb 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -385,11 +385,23 @@ class ToolChain {
   /// by default.
   virtual bool IsIntegratedAssemblerDefault() const { return false; }
 
+  /// IsIntegratedBackendDefault - Does this tool chain enable
+  /// -fintegrated-objemitter by default.
+  virtual bool IsIntegratedBackendDefault() const { return true; }
+
+  /// IsIntegratedBackendSupported - Does this tool chain support
+  /// -fintegrated-objemitter.
+  virtual bool IsIntegratedBackendSupported() const { 

[PATCH] D126324: [clang] Allow const variables with weak attribute to be overridden

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

The changes so far look sensible, but I think we should add some more tests for 
a few situations. 1) Using a const weak symbol as a valid initializer should be 
diagnosed (with a warning? with an error?) so users are alerted to the 
behavioral quirks. 2) Using a const weak symbol in a constant expression 
context should probably be an error, right? e.g.,

  const int hmm __attribute__((weak)) = 12;
  int erp = hmm; // Error in C, dynamic init in C++?
  
  int main() {
int blerp = hmm; // OK in both languages
constexpr int derp = hmm; // Error in C++
int array[hmm]; // Error in both languages
  }

Also, this definitely could use a release note so users know about the 
behavioral change.

Do you have any ideas on how much code this change is expected to break? (Is it 
sufficient enough that we want to have an explicit deprecation period of the 
existing behavior before we switch to the new behavior?)




Comment at: clang/include/clang/Basic/Attr.td:2962
   let Subjects = SubjectList<[Var, Function, CXXRecord]>;
-  let Documentation = [Undocumented];
+  let Documentation = [WeakDocs];
   let SimpleHandler = 1;

THANK YOU!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126324

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


[PATCH] D126369: [LLVM] Add rcp.approx.ftz.f32 intrinsic

2022-05-25 Thread Christian Sigg via Phabricator via cfe-commits
csigg created this revision.
csigg added a reviewer: tra.
Herald added subscribers: mattd, gchakrabarti, asavonic, sanjoy.google, 
hiraditya.
Herald added a project: All.
csigg requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, jdoerfert, jholewinski.
Herald added projects: clang, LLVM.

Split out from https://reviews.llvm.org/D126158.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126369

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td


Index: llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
===
--- llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
+++ llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
@@ -1034,6 +1034,8 @@
 def INT_NVVM_RCP_RP_D : F_MATH_1<"rcp.rp.f64 \t$dst, $src0;", Float64Regs,
   Float64Regs, int_nvvm_rcp_rp_d>;
 
+def INT_NVVM_RCP_APPROX_FTZ_F : F_MATH_1<"rcp.approx.ftz.f32 \t$dst, $src0;",
+  Float32Regs, Float32Regs, int_nvvm_rcp_approx_ftz_f>;
 def INT_NVVM_RCP_APPROX_FTZ_D : F_MATH_1<"rcp.approx.ftz.f64 \t$dst, $src0;",
   Float64Regs, Float64Regs, int_nvvm_rcp_approx_ftz_d>;
 
Index: llvm/include/llvm/IR/IntrinsicsNVVM.td
===
--- llvm/include/llvm/IR/IntrinsicsNVVM.td
+++ llvm/include/llvm/IR/IntrinsicsNVVM.td
@@ -933,6 +933,8 @@
   def int_nvvm_rcp_rp_d : GCCBuiltin<"__nvvm_rcp_rp_d">,
   DefaultAttrsIntrinsic<[llvm_double_ty], [llvm_double_ty], [IntrNoMem]>;
 
+  def int_nvvm_rcp_approx_ftz_f : GCCBuiltin<"__nvvm_rcp_approx_ftz_f">,
+  DefaultAttrsIntrinsic<[llvm_float_ty], [llvm_float_ty], [IntrNoMem]>;
   def int_nvvm_rcp_approx_ftz_d : GCCBuiltin<"__nvvm_rcp_approx_ftz_d">,
   DefaultAttrsIntrinsic<[llvm_double_ty], [llvm_double_ty], [IntrNoMem]>;
 
Index: clang/include/clang/Basic/BuiltinsNVPTX.def
===
--- clang/include/clang/Basic/BuiltinsNVPTX.def
+++ clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -343,6 +343,8 @@
 BUILTIN(__nvvm_rcp_rz_d, "dd", "")
 BUILTIN(__nvvm_rcp_rm_d, "dd", "")
 BUILTIN(__nvvm_rcp_rp_d, "dd", "")
+
+BUILTIN(__nvvm_rcp_approx_ftz_f, "ff", "")
 BUILTIN(__nvvm_rcp_approx_ftz_d, "dd", "")
 
 // Sqrt


Index: llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
===
--- llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
+++ llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
@@ -1034,6 +1034,8 @@
 def INT_NVVM_RCP_RP_D : F_MATH_1<"rcp.rp.f64 \t$dst, $src0;", Float64Regs,
   Float64Regs, int_nvvm_rcp_rp_d>;
 
+def INT_NVVM_RCP_APPROX_FTZ_F : F_MATH_1<"rcp.approx.ftz.f32 \t$dst, $src0;",
+  Float32Regs, Float32Regs, int_nvvm_rcp_approx_ftz_f>;
 def INT_NVVM_RCP_APPROX_FTZ_D : F_MATH_1<"rcp.approx.ftz.f64 \t$dst, $src0;",
   Float64Regs, Float64Regs, int_nvvm_rcp_approx_ftz_d>;
 
Index: llvm/include/llvm/IR/IntrinsicsNVVM.td
===
--- llvm/include/llvm/IR/IntrinsicsNVVM.td
+++ llvm/include/llvm/IR/IntrinsicsNVVM.td
@@ -933,6 +933,8 @@
   def int_nvvm_rcp_rp_d : GCCBuiltin<"__nvvm_rcp_rp_d">,
   DefaultAttrsIntrinsic<[llvm_double_ty], [llvm_double_ty], [IntrNoMem]>;
 
+  def int_nvvm_rcp_approx_ftz_f : GCCBuiltin<"__nvvm_rcp_approx_ftz_f">,
+  DefaultAttrsIntrinsic<[llvm_float_ty], [llvm_float_ty], [IntrNoMem]>;
   def int_nvvm_rcp_approx_ftz_d : GCCBuiltin<"__nvvm_rcp_approx_ftz_d">,
   DefaultAttrsIntrinsic<[llvm_double_ty], [llvm_double_ty], [IntrNoMem]>;
 
Index: clang/include/clang/Basic/BuiltinsNVPTX.def
===
--- clang/include/clang/Basic/BuiltinsNVPTX.def
+++ clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -343,6 +343,8 @@
 BUILTIN(__nvvm_rcp_rz_d, "dd", "")
 BUILTIN(__nvvm_rcp_rm_d, "dd", "")
 BUILTIN(__nvvm_rcp_rp_d, "dd", "")
+
+BUILTIN(__nvvm_rcp_approx_ftz_f, "ff", "")
 BUILTIN(__nvvm_rcp_approx_ftz_d, "dd", "")
 
 // Sqrt
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126158: [MLIR][GPU] Replace fdiv on fp16 with promoted (fp32) multiplication with reciprocal plus one (conditional) Newton iteration.

2022-05-25 Thread Christian Sigg via Phabricator via cfe-commits
csigg added a comment.

In D126158#3534750 , @tra wrote:

> I would suggest separating it into separate LLVM and MLIR patches.

Thanks Artem. I separated out the LLVM changes in 
https://reviews.llvm.org/D126369.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126158

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


[PATCH] D126162: [clang-tidy] Extend SimplifyBooleanExpr demorgan support.

2022-05-25 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 431945.
njames93 added a comment.

Add note to docs that this new option has no effect if SimplifyDeMorgan is 
false.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126162

Files:
  clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
  clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
  clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp
@@ -1,9 +1,30 @@
 // RUN: %check_clang_tidy %s readability-simplify-boolean-expr %t
 
+// Check when we can convert !(A Op B) -> !A InvOp !B.
+// RUN: %check_clang_tidy -check-suffixes=",RELAXED" %s \
+// RUN: readability-simplify-boolean-expr %t -- -config="{CheckOptions: [{ \
+// RUN: key: "readability-simplify-boolean-expr.SimplifyDeMorganRelaxed", value: true}]}" --
+
+// Verify warning issued when invalid options are specified.
+// RUN: clang-tidy %s -checks=-*,readability-simplify-boolean-expr -config="{CheckOptions: [ \
+// RUN:   {key: readability-simplify-boolean-expr.SimplifyDeMorgan, value: false}, \
+// RUN:   {key: readability-simplify-boolean-expr.SimplifyDeMorganRelaxed, value: true}]}" \
+// RUN: -- 2>&1 | FileCheck %s -check-prefix=CHECK-BAD-CONFIG \
+// RUN:   -implicit-check-not="{{warning|error}}:"
+
+// CHECK-BAD-CONFIG: warning: readability-simplify-boolean-expr: 'SimplifyDeMorganRelaxed' cannot be enabled without 'SimplifyDeMorgan' enabled
 void eat(bool);
 
 void foo(bool A1, bool A2, bool A3, bool A4) {
   bool X;
+
+  X = !(A1 && A2);
+  X = !(A1 || A2);
+  // CHECK-MESSAGES-RELAXED: :[[@LINE-2]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-MESSAGES-RELAXED: :[[@LINE-2]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-FIXES-RELAXED: X = !A1 || !A2;
+  // CHECK-FIXES-NEXT-RELAXED: X = !A1 && !A2;
+
   X = !(!A1 || A2);
   X = !(A1 || !A2);
   X = !(!A1 || !A2);
Index: clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
@@ -96,3 +96,23 @@
 
If `true`, DeMorgan's Theorem will be applied to simplify negated
conjunctions and disjunctions.  Default is `true`.
+
+.. option:: SimplifyDeMorganRelaxed
+
+   If `true`, :option:`SimplifyDeMorgan` will also transform negated 
+   conjunctions and disjunctions where there is no negation on either operand. 
+   Default is `false`.
+
+   When Enabled:
+
+   .. code-block::
+
+  bool X = !(A && B)
+  bool Y = !(A || B)
+
+   Would be transformed to:
+
+   .. code-block::
+
+  bool X = !A || !B
+  bool Y = !A && !B
Index: clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
===
--- clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
+++ clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
@@ -69,6 +69,7 @@
   const bool ChainedConditionalReturn;
   const bool ChainedConditionalAssignment;
   const bool SimplifyDeMorgan;
+  const bool SimplifyDeMorganRelaxed;
 };
 
 } // namespace readability
Index: clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -558,7 +558,8 @@
 if (!BinaryOp || !BinaryOp->isLogicalOp() ||
 !BinaryOp->getType()->isBooleanType())
   return Base::TraverseUnaryOperator(Op);
-if (checkEitherSide(BinaryOp, isUnaryLNot) ||
+if (Check->SimplifyDeMorganRelaxed ||
+checkEitherSide(BinaryOp, isUnaryLNot) ||
 checkEitherSide(BinaryOp,
 [](const Expr *E) { return nestedDemorgan(E, 1); })) {
   if (Check->reportDeMorgan(Context, Op, BinaryOp, !IsProcessing, parent(),
@@ -584,7 +585,13 @@
   ChainedConditionalReturn(Options.get("ChainedConditionalReturn", false)),
   ChainedConditionalAssignment(
   Options.get("ChainedConditionalAssignment", false)),
-  SimplifyDeMorgan(Options.get("SimplifyDeMorgan", true)) {}
+  SimplifyDeMorgan(Options.get("SimplifyDeMorgan", true)),
+  SimplifyDeMorganRelaxed(Options.

[clang-tools-extra] f3c1d28 - [clang-tidy] Extend SimplifyBooleanExpr demorgan support.

2022-05-25 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2022-05-25T13:09:00+01:00
New Revision: f3c1d281767a5849b9f3e712e3c3406bd9410c81

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

LOG: [clang-tidy] Extend SimplifyBooleanExpr demorgan support.

Adds an option SimplifyDemorganRelaxed which, when enabled, will transform 
negated conjunctions or disjunctions when neither operand is a negation.
Default value is `false`.

Reviewed By: LegalizeAdulthood

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h

clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst

clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index f35f7839dc257..8ae990a929dfd 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -558,7 +558,8 @@ class SimplifyBooleanExprCheck::Visitor : public 
RecursiveASTVisitor {
 if (!BinaryOp || !BinaryOp->isLogicalOp() ||
 !BinaryOp->getType()->isBooleanType())
   return Base::TraverseUnaryOperator(Op);
-if (checkEitherSide(BinaryOp, isUnaryLNot) ||
+if (Check->SimplifyDeMorganRelaxed ||
+checkEitherSide(BinaryOp, isUnaryLNot) ||
 checkEitherSide(BinaryOp,
 [](const Expr *E) { return nestedDemorgan(E, 1); })) {
   if (Check->reportDeMorgan(Context, Op, BinaryOp, !IsProcessing, parent(),
@@ -584,7 +585,13 @@ 
SimplifyBooleanExprCheck::SimplifyBooleanExprCheck(StringRef Name,
   ChainedConditionalReturn(Options.get("ChainedConditionalReturn", false)),
   ChainedConditionalAssignment(
   Options.get("ChainedConditionalAssignment", false)),
-  SimplifyDeMorgan(Options.get("SimplifyDeMorgan", true)) {}
+  SimplifyDeMorgan(Options.get("SimplifyDeMorgan", true)),
+  SimplifyDeMorganRelaxed(Options.get("SimplifyDeMorganRelaxed", false)) {
+  if (SimplifyDeMorganRelaxed && !SimplifyDeMorgan)
+configurationDiag("%0: 'SimplifyDeMorganRelaxed' cannot be enabled "
+  "without 'SimplifyDeMorgan' enabled")
+<< Name;
+}
 
 static bool containsBoolLiteral(const Expr *E) {
   if (!E)
@@ -667,6 +674,7 @@ void 
SimplifyBooleanExprCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "ChainedConditionalAssignment",
 ChainedConditionalAssignment);
   Options.store(Opts, "SimplifyDeMorgan", SimplifyDeMorgan);
+  Options.store(Opts, "SimplifyDeMorganRelaxed", SimplifyDeMorganRelaxed);
 }
 
 void SimplifyBooleanExprCheck::registerMatchers(MatchFinder *Finder) {

diff  --git 
a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h 
b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
index 72d8f3354b890..8da20f37b975e 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
@@ -69,6 +69,7 @@ class SimplifyBooleanExprCheck : public ClangTidyCheck {
   const bool ChainedConditionalReturn;
   const bool ChainedConditionalAssignment;
   const bool SimplifyDeMorgan;
+  const bool SimplifyDeMorganRelaxed;
 };
 
 } // namespace readability

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
index 240e7be64ad45..f25d4c418695f 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
@@ -96,3 +96,23 @@ Options
 
If `true`, DeMorgan's Theorem will be applied to simplify negated
conjunctions and disjunctions.  Default is `true`.
+
+.. option:: SimplifyDeMorganRelaxed
+
+   If `true`, :option:`SimplifyDeMorgan` will also transform negated 
+   conjunctions and disjunctions where there is no negation on either operand. 
+   Default is `false`.
+
+   When Enabled:
+
+   .. code-block::
+
+  bool X = !(A && B)
+  bool Y = !(A || B)
+
+   Would be transformed to:
+
+   .. code-block::
+
+  bool X = !A || !B
+  bool Y = !A && !B

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp
index 12a9eb65352d8..6787273daa8c5 100644
--- 
a/clang-

[PATCH] D126162: [clang-tidy] Extend SimplifyBooleanExpr demorgan support.

2022-05-25 Thread Nathan James 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 rGf3c1d281767a: [clang-tidy] Extend SimplifyBooleanExpr 
demorgan support. (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126162

Files:
  clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
  clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
  clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp
@@ -1,9 +1,30 @@
 // RUN: %check_clang_tidy %s readability-simplify-boolean-expr %t
 
+// Check when we can convert !(A Op B) -> !A InvOp !B.
+// RUN: %check_clang_tidy -check-suffixes=",RELAXED" %s \
+// RUN: readability-simplify-boolean-expr %t -- -config="{CheckOptions: [{ \
+// RUN: key: "readability-simplify-boolean-expr.SimplifyDeMorganRelaxed", value: true}]}" --
+
+// Verify warning issued when invalid options are specified.
+// RUN: clang-tidy %s -checks=-*,readability-simplify-boolean-expr -config="{CheckOptions: [ \
+// RUN:   {key: readability-simplify-boolean-expr.SimplifyDeMorgan, value: false}, \
+// RUN:   {key: readability-simplify-boolean-expr.SimplifyDeMorganRelaxed, value: true}]}" \
+// RUN: -- 2>&1 | FileCheck %s -check-prefix=CHECK-BAD-CONFIG \
+// RUN:   -implicit-check-not="{{warning|error}}:"
+
+// CHECK-BAD-CONFIG: warning: readability-simplify-boolean-expr: 'SimplifyDeMorganRelaxed' cannot be enabled without 'SimplifyDeMorgan' enabled
 void eat(bool);
 
 void foo(bool A1, bool A2, bool A3, bool A4) {
   bool X;
+
+  X = !(A1 && A2);
+  X = !(A1 || A2);
+  // CHECK-MESSAGES-RELAXED: :[[@LINE-2]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-MESSAGES-RELAXED: :[[@LINE-2]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-FIXES-RELAXED: X = !A1 || !A2;
+  // CHECK-FIXES-NEXT-RELAXED: X = !A1 && !A2;
+
   X = !(!A1 || A2);
   X = !(A1 || !A2);
   X = !(!A1 || !A2);
Index: clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
@@ -96,3 +96,23 @@
 
If `true`, DeMorgan's Theorem will be applied to simplify negated
conjunctions and disjunctions.  Default is `true`.
+
+.. option:: SimplifyDeMorganRelaxed
+
+   If `true`, :option:`SimplifyDeMorgan` will also transform negated 
+   conjunctions and disjunctions where there is no negation on either operand. 
+   Default is `false`.
+
+   When Enabled:
+
+   .. code-block::
+
+  bool X = !(A && B)
+  bool Y = !(A || B)
+
+   Would be transformed to:
+
+   .. code-block::
+
+  bool X = !A || !B
+  bool Y = !A && !B
Index: clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
===
--- clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
+++ clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
@@ -69,6 +69,7 @@
   const bool ChainedConditionalReturn;
   const bool ChainedConditionalAssignment;
   const bool SimplifyDeMorgan;
+  const bool SimplifyDeMorganRelaxed;
 };
 
 } // namespace readability
Index: clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -558,7 +558,8 @@
 if (!BinaryOp || !BinaryOp->isLogicalOp() ||
 !BinaryOp->getType()->isBooleanType())
   return Base::TraverseUnaryOperator(Op);
-if (checkEitherSide(BinaryOp, isUnaryLNot) ||
+if (Check->SimplifyDeMorganRelaxed ||
+checkEitherSide(BinaryOp, isUnaryLNot) ||
 checkEitherSide(BinaryOp,
 [](const Expr *E) { return nestedDemorgan(E, 1); })) {
   if (Check->reportDeMorgan(Context, Op, BinaryOp, !IsProcessing, parent(),
@@ -584,7 +585,13 @@
   ChainedConditionalReturn(Options.get("ChainedConditionalReturn", false)),
   ChainedConditionalAssignment(
   Options.get("ChainedConditionalAssignment", false)),
-  SimplifyDeMorgan(Options.get("SimplifyDeMorgan", true)) {}
+  Simplify

[PATCH] D102122: Support warn_unused_result on typedefs

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

Thank you for the ping, this fell entirely off my radar!

In D102122#3344317 , @dblaikie wrote:

> I don't recall all the context, but did try discussing this with the 
> committee folks and got a variety of strong opinions/wasn't sure whether 
> there was a path forward: 
> https://lists.isocpp.org/ext/2021/05/index.php#msg16554 (for those with 
> access to that). What's your take on the discussion there? Worth pushing 
> forward?

The C++ side was definitely mixed review, so I'm on the fence about whether 
it's worth pushing forward in C++. However, I think the story in C is rather 
different because there are less reasonable alternatives there and the type 
system is far less complex. I think it's reasonable to experiment with support 
in C only under `[[clang::warn_unused_result]]`, keeping in mind some of the 
WG21 feedback in mind regarding questions like behavior of typedefs of typedef 
types, etc, if that's of interest to you.

The story with `[[nodiscard]]` is a bit more complex -- I would expect this 
attribute to appear in header files shared between C and C++, so I think it 
would be bad for it to be applicable to typedefs in only one language but not 
the other. However, so long as we issue a pedantic warning that the 
`[[nodiscard]]` attribute on a typedef is a Clang extension, I think we could 
technically do it. But it might not be worth it given the lack of portability; 
at that point, the user can use `[[clang::warn_unused_result]]` to the same 
effect.

> & some minor questions I guess I wrote last year...
>
> In D102122#2748529 , @aaron.ballman 
> wrote:
>
>> In D102122#2748271 , @dblaikie 
>> wrote:
>>
>>> In D102122#2748206 , 
>>> @aaron.ballman wrote:
>>>
 Let me start off by saying: thanks, I think this is really useful 
 functionality. As a ridiculously obvious example, Annex K has an integer 
 type alias `errno_t` and it would incredibly handy to be able to mark that 
 as `[[nodiscard]]` to strongly encourage checking for errors for functions 
 that return that type (not that we support Annex K, but the general idea 
 extends to any integer-based error type).

 That said, there are multiple different ways to spell the same semantic 
 attribute, and it's not clear to me that we want to change them all the 
 same way.

 `[[clang::warn_unused_result]]` is ours to do with as we please, so 
 there's no issue changing that behavior.

 `__attribute__((warn_unused_result))` and `[[gnu::warn_unused_result]]` 
 are governed by GCC and we try to be compatible with their behavior. GCC 
 does not appear to support the attribute on typedefs from my testing, so 
 we'd want to coordinate with the GCC folks to see if there's an appetite 
 for the change.
>>>
>>> FWIW, looks like we already diverge from GCC's behavior - GCC doesn't seem 
>>> to support this attribute on types at all: https://godbolt.org/z/8YjqnE4cv 
>>> (but does support [[nodiscard]] in that place)
>>
>> Whomp whomp! :-(
>>
 `[[nodiscard]]` is governed by both the C++ and C standards and we should 
 not be changing its behavior without some extra diagnostics about 
 extensions (and, preferably, some sort of attempt to standardize the 
 behavior with WG14/WG21).
>>>
>>> Might be a compatible extension, though - to use a standard attribute in a 
>>> non-standard context? (at least clang and gcc only warn on putting 
>>> [[nodiscard]] in non-standard places, they don't error)
>>
>> It's a bit unclear -- there's a list of things the attribute applies to, and 
>> typedef is not on the list, so it would be reasonable to think that means 
>> the attribute can't be written on anything else. But because the standard 
>> doesn't say what happens if you DO apply it to a typedef, perhaps that's 
>> sufficiently undefined to allow us to call it a conforming extension. Given 
>> that you're fine trying to get this standardized and it seems like it 
>> shouldn't be contentious, I think we aren't behaving badly if we accept 
>> `[[nodiscard]]` on a typedef so long as we give an extension warning.
>
> Fair enough - does the spec say what happens if you use a completely unknown 
> spelling like `[[foobar]]`? I guess the spec reserves that for future 
> attributes, so implementations aren't meant to add support in there 
> (implementations being expected to use some namespace to put their extensions 
> in)
>
> Just curiious.

It's allowed with implementation-defined semantics (per 
https://eel.is/c++draft/dcl.attr#grammar-6.sentence-1) but we'd be evil, bad 
folks and I'd be opposed to it as attribute code owner due to it stepping on 
the WG21 and WG14 design space for attributes (per 
https://eel.is/c++draft/dcl.attr#grammar-6.sentence-3).

 Do you have an a

[clang-tools-extra] 09ef6da - [clang-tidy] Update docs for SimplifyDeMorganRelaxed

2022-05-25 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2022-05-25T13:12:20+01:00
New Revision: 09ef6da8dcd848258c9f876ba9298c7db0d589a9

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

LOG: [clang-tidy] Update docs for SimplifyDeMorganRelaxed

Forgot to add this to f3c1d281767

Added: 


Modified: 

clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst

Removed: 




diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
index f25d4c418695..18ab84b26a25 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
@@ -101,6 +101,7 @@ Options
 
If `true`, :option:`SimplifyDeMorgan` will also transform negated 
conjunctions and disjunctions where there is no negation on either operand. 
+   This option has no effect if :option:`SimplifyDeMorgan` is `false`.
Default is `false`.
 
When Enabled:



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


[clang] f96aa83 - Test C DR conformance (part three of many)

2022-05-25 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-05-25T08:18:16-04:00
New Revision: f96aa834d7d77bb875d5bb727b89ab4af7940a0c

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

LOG: Test C DR conformance (part three of many)

This adds more of the tests for the first 100 DRs in C and updates
their status on the status page.

Added: 
clang/test/C/drs/dr094.c

Modified: 
clang/test/C/drs/dr0xx.c
clang/www/c_dr_status.html

Removed: 




diff  --git a/clang/test/C/drs/dr094.c b/clang/test/C/drs/dr094.c
new file mode 100644
index 0..132193ba05cbd
--- /dev/null
+++ b/clang/test/C/drs/dr094.c
@@ -0,0 +1,29 @@
+/* RUN: %clang_cc1 -std=c89 -emit-llvm -o - %s | FileCheck %s
+   RUN: %clang_cc1 -std=c99 -emit-llvm -o - %s | FileCheck %s
+   RUN: %clang_cc1 -std=c11 -emit-llvm -o - %s | FileCheck %s
+   RUN: %clang_cc1 -std=c17 -emit-llvm -o - %s | FileCheck %s
+   RUN: %clang_cc1 -std=c2x -emit-llvm -o - %s | FileCheck %s
+ */
+
+/* WG14 DR094: yes
+ * Are constraints on function return the same as assignment?
+ */
+
+float func(void) { return 1.0f; }
+void other_func(void) {
+  int i;
+  float f;
+
+  /* Test that there's been a conversion from float to int. */
+  i = func();
+  // CHECK: %call = call float @func()
+  // CHECK-NEXT: %conv = fptosi float %call to i32
+  // CHECK-NEXT: store i32 %conv, ptr %i, align 4
+
+  /* Test that the conversion looks the same as an assignment. */
+  i = f;
+  // CHECK: %0 = load float, ptr %f, align 4
+  // CHECK-NEXT: %conv1 = fptosi float %0 to i32
+  // CHECK-NEXT: store i32 %conv1, ptr %i, align 4
+}
+

diff  --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index b0b57fa289149..22b38de1a8876 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -57,6 +57,27 @@
  *
  * WG14 DR067: yes
  * Integer and integral type confusion
+ *
+ * WG14 DR069: yes
+ * Questions about the representation of integer types
+ *
+ * WG14 DR077: yes
+ * Stability of addresses
+ *
+ * WG14 DR080: yes
+ * Merging of string constants
+ *
+ * WG14 DR086: yes
+ * Object-like macros in system headers
+ *
+ * WG14 DR091: yes
+ * Multibyte encodings
+ *
+ * WG14 DR092: dup 060
+ * Partial initialization of strings
+ *
+ * WG14 DR093: yes
+ * Reservation of identifiers
  */
 
 
@@ -238,6 +259,17 @@ _Static_assert(DR038(DR038_X + DR038_Y) == DR038_X + 
DR038_Y, "fail");
  */
 _Static_assert(sizeof('a') == sizeof(int), "fail");
 
+/* WG14 DR040: partial
+ * 9 unrelated questions about C89
+ *
+ * Question 6
+ */
+struct dr040 { /* expected-note {{definition of 'struct dr040' is not complete 
until the closing '}'}} */
+  char c;
+  short s;
+  int i[__builtin_offsetof(struct dr040, s)]; /* expected-error {{offsetof of 
incomplete type 'struct dr040'}} */
+};
+
 /* WG14 DR043: yes
  * On the definition of the NULL macro
  */
@@ -345,3 +377,146 @@ void dr068(void) {
   _Static_assert('\xFF' == 0xFF, "fail");
 #endif
 }
+
+#if __STDC_VERSION__ < 202000L
+/* WG14: DR070: yes
+ * Interchangeability of function arguments
+ *
+ * Note: we could issue a pedantic warning in this case. We are claiming
+ * conformance not because we diagnose the UB when we could but because we're
+ * not obligated to do anything about it and we make it "just work" via the
+ * usual conversion rules.
+ *
+ * This behavior is specific to functions without prototypes. A function with
+ * a prototype causes implicit conversions rather than relying on default
+ * argument promotion and warm thoughts.
+ */
+void dr070_1(c) /* expected-warning {{a function declaration without a 
prototype is deprecated in all versions of C and is not supported in C2x}} */
+  int c; {
+}
+
+void dr070_2(void) {
+  dr070_1(6);
+  dr070_1(6U); /* Pedantically UB */
+}
+#endif /* __STDC_VERSION__ < 202000L */
+
+/* WG14 DR071: yes
+ * Enumerated types
+ */
+enum dr071_t { foo_A = 0, foo_B = 1, foo_C = 8 };
+void dr071(void) {
+  /* Test that in-range values not present in the enumeration still round-trip
+   * to the original value.
+   */
+  _Static_assert(100 == (int)(enum dr071_t)100, "fail");
+}
+
+/* WG14 DR081: yes
+ * Left shift operator
+ */
+void dr081(void) {
+  /* Demonstrate that we don't crash when left shifting a signed value; that's
+   * implementation defined behavior.
+   */
+ _Static_assert(-1 << 1 == -2, "fail"); /* Didn't shift a zero into the "sign 
bit". */
+ _Static_assert(1 << 3 == 1u << 3u, "fail"); /* Shift of a positive signed 
value does sensible things. */
+}
+
+/* WG14 DR084: yes
+ * Incomplete type in function declaration
+ *
+ * Note: because the situation is UB, we're free to do what we want. We elect
+ * to accept and require the incomplete type to be completed before the
+ * function definition.
+ */
+struct dr084_t; /* expected-note {{forward declaration of 'struct dr084_t

[PATCH] D126061: [clang] [WIP] Reject non-declaration C++11 attributes on declarations

2022-05-25 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 431948.
mboehme marked 30 inline comments as done.
mboehme added a comment.

Changes in response to review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126061

Files:
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Parse/RAIIObjectsForParser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Basic/Attributes.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/ParsedAttr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaDeclObjC.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/Parser/MicrosoftExtensions.cpp
  clang/test/Parser/asm.c
  clang/test/Parser/asm.cpp
  clang/test/Parser/c2x-attributes.c
  clang/test/Parser/cxx0x-attributes.cpp
  clang/test/Sema/annotate-type.c
  clang/test/SemaCXX/address-space-placement.cpp
  clang/test/SemaCXX/annotate-type.cpp
  clang/test/SemaOpenCL/address-spaces.cl
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3734,7 +3734,7 @@
 if (!StmtSubjects.empty()) {
   OS << "bool diagAppertainsToDecl(Sema &S, const ParsedAttr &AL, ";
   OS << "const Decl *D) const override {\n";
-  OS << "  S.Diag(AL.getLoc(), diag::err_stmt_attribute_invalid_on_decl)\n";
+  OS << "  S.Diag(AL.getLoc(), diag::err_attribute_invalid_on_decl)\n";
   OS << "<< AL << D->getLocation();\n";
   OS << "  return false;\n";
   OS << "}\n\n";
Index: clang/test/SemaOpenCL/address-spaces.cl
===
--- clang/test/SemaOpenCL/address-spaces.cl
+++ clang/test/SemaOpenCL/address-spaces.cl
@@ -266,9 +266,9 @@
   __attribute__((opencl_private)) private_int_t var5;  // expected-warning {{multiple identical address spaces specified for type}}
   __attribute__((opencl_private)) private_int_t *var6; // expected-warning {{multiple identical address spaces specified for type}}
 #if __OPENCL_CPP_VERSION__
-  [[clang::opencl_private]] __global int var7; // expected-error {{multiple address spaces specified for type}}
-  [[clang::opencl_private]] __global int *var8;// expected-error {{multiple address spaces specified for type}}
-  [[clang::opencl_private]] private_int_t var9;// expected-warning {{multiple identical address spaces specified for type}}
-  [[clang::opencl_private]] private_int_t *var10;  // expected-warning {{multiple identical address spaces specified for type}}
+  __global int [[clang::opencl_private]] var7; // expected-error {{multiple address spaces specified for type}}
+  __global int [[clang::opencl_private]] *var8;// expected-error {{multiple address spaces specified for type}}
+  private_int_t [[clang::opencl_private]] var9;// expected-warning {{multiple identical address spaces specified for type}}
+  private_int_t [[clang::opencl_private]] *var10;  // expected-warning {{multiple identical address spaces specified for type}}
 #endif // !__OPENCL_CPP_VERSION__
 }
Index: clang/test/SemaCXX/annotate-type.cpp
===
--- clang/test/SemaCXX/annotate-type.cpp
+++ clang/test/SemaCXX/annotate-type.cpp
@@ -2,10 +2,7 @@
 
 struct S1 {
   void f() [[clang::annotate_type("foo")]];
-  // FIXME: We would want to prohibit the attribute in the following location.
-  // However, Clang currently generally doesn't prohibit type-only C++11
-  // attributes on declarations. This should be fixed more generally.
-  [[clang::annotate_type("foo")]] void g();
+  [[clang::annotate_type("foo")]] void g(); // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
 };
 
 template  struct is_same {
@@ -48,23 +45,21 @@
 
 // More error cases: Prohibit adding the attribute to declarations.
 // Different declarations hit different code paths, so they need separate tests.
-// FIXME: Clang currently generally doesn't prohibit type-only C++11
-// attributes on declarations.
-namespace [[clang::annotate_type("foo")]] my_namespace {}
-struct [[clang::annotate_type("foo")]] S3;
-struct [[clang::annotate_type("foo")]] S3{
-  [[clang::annotate_type("foo")]] int member;
+namespace [[clang::annotate_type("foo")]] my_namespace {} // expected-error {{'annotate_t

[PATCH] D126373: [pseudo-gen] Add -o flag, make --grammar required

2022-05-25 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: hokein.
Herald added a subscriber: mgorny.
Herald added a project: All.
thakis requested review of this revision.
Herald added a project: clang-tools-extra.

Virtually all LLVM tools accept a `-o` flag, so add one. This will make it
possible to possibly add a --write-if-changed flag later.

Marking --grammar as `Required` allows removing some manual
verification code for it.


https://reviews.llvm.org/D126373

Files:
  clang-tools-extra/pseudo/gen/Main.cpp
  clang-tools-extra/pseudo/include/CMakeLists.txt

Index: clang-tools-extra/pseudo/include/CMakeLists.txt
===
--- clang-tools-extra/pseudo/include/CMakeLists.txt
+++ clang-tools-extra/pseudo/include/CMakeLists.txt
@@ -7,7 +7,7 @@
COMMAND "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/pseudo-gen"
  --grammar ${cxx_bnf}
  --emit-symbol-list
- > ${cxx_symbols_inc}
+ -o ${cxx_symbols_inc}
COMMENT "Generating nonterminal symbol file for cxx grammar..."
DEPENDS pseudo-gen
VERBATIM)
@@ -17,7 +17,7 @@
COMMAND "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/pseudo-gen"
  --grammar ${cxx_bnf}
  --emit-grammar-content
- > ${cxx_bnf_inc}
+ -o ${cxx_bnf_inc}
COMMENT "Generating bnf string file for cxx grammar..."
DEPENDS pseudo-gen
VERBATIM)
Index: clang-tools-extra/pseudo/gen/Main.cpp
===
--- clang-tools-extra/pseudo/gen/Main.cpp
+++ clang-tools-extra/pseudo/gen/Main.cpp
@@ -15,13 +15,17 @@
 #include "clang-pseudo/Grammar.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/ToolOutputFile.h"
 #include 
 
+using llvm::cl::Required;
 using llvm::cl::desc;
 using llvm::cl::init;
 using llvm::cl::opt;
+using llvm::cl::value_desc;
 using llvm::cl::values;
 
 namespace {
@@ -31,13 +35,17 @@
 };
 
 opt Grammar("grammar", desc("Parse a BNF grammar file."),
- init(""));
+ Required);
 opt
 Emit(desc("which information to emit:"),
  values(clEnumValN(EmitSymbolList, "emit-symbol-list",
"Print nonterminal symbols (default)"),
 clEnumValN(EmitGrammarContent, "emit-grammar-content",
"Print the BNF grammar content as a string")));
+
+opt OutputFilename("o", init("-"), desc("Output"),
+value_desc("file"));
+
 std::string readOrDie(llvm::StringRef Path) {
   llvm::ErrorOr> Text =
   llvm::MemoryBuffer::getFile(Path);
@@ -52,10 +60,6 @@
 
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "");
-  if (!Grammar.getNumOccurrences()) {
-llvm::errs() << "Grammar file must be provided!\n";
-return 1;
-  }
 
   std::string GrammarText = readOrDie(Grammar);
   std::vector Diags;
@@ -65,25 +69,34 @@
 llvm::errs() << llvm::join(Diags, "\n");
 return 1;
   }
-  switch (Emit) {
 
+  std::error_code EC;
+  llvm::ToolOutputFile Out{OutputFilename, EC, llvm::sys::fs::OF_None};
+  if (EC) {
+llvm::errs() << EC.message() << '\n';
+return 1;
+  }
+
+  switch (Emit) {
   case EmitSymbolList:
 for (clang::pseudo::SymbolID ID = 0; ID < G->table().Nonterminals.size();
  ++ID) {
   std::string Name = G->symbolName(ID).str();
   // translation-unit -> translation_unit
   std::replace(Name.begin(), Name.end(), '-', '_');
-  llvm::outs() << (llvm::formatv("NONTERMINAL({0}, {1})\n", Name, ID));
+  Out.os() << llvm::formatv("NONTERMINAL({0}, {1})\n", Name, ID);
 }
 break;
   case EmitGrammarContent:
 for (llvm::StringRef Line : llvm::split(GrammarText, '\n')) {
-  llvm::outs() << '"';
-  llvm::outs().write_escaped((Line + "\n").str());
-  llvm::outs() << "\"\n";
+  Out.os() << '"';
+  Out.os().write_escaped((Line + "\n").str());
+  Out.os() << "\"\n";
 }
 break;
   }
 
+  Out.keep();
+
   return 0;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126061: [clang] [WIP] Reject non-declaration C++11 attributes on declarations

2022-05-25 Thread Martin Böhme via Phabricator via cfe-commits
mboehme marked 6 inline comments as done.
mboehme added a comment.

Thank you @rsmith and @aaron.ballman for the detailed review comments!

I hope I've addressed everything -- do let me know if there's anything I've 
missed.

In D126061#3528966 , @rsmith wrote:

> This direction looks good to me. Thanks!
>
> Regarding the possibility of storing the declaration attributes on the 
> `DeclSpec` rather than on the `Declarator`, I wonder if a better choice might 
> be to make the `Declarator` hold a non-owning reference to the attributes, 
> like it does for the `DeclSpec`?

Thanks for the suggestion -- this has turned out to make the code simpler and 
more logical in a number of places.




Comment at: clang/include/clang/Sema/DeclSpec.h:1853-1856
   /// Attrs - Attributes.
   ParsedAttributes Attrs;
 
+  ParsedAttributes DeclarationAttrs;

aaron.ballman wrote:
> We should probably rename `Attrs` to be less generic and add some comments to 
> explain why there are two lists of parsed attributes.
I've added some comments to clarify the difference. I'm not sure what a good 
alternative name for `Attrs` would be though. The only obvious candidate that 
comes to mind is `DeclaratorAttrs`, but that seems pretty redundant given that 
this is a field of `Declarator`.

I think there is actually a good case for calling the first list simply `Attrs` 
because, unlike `DeclarationAttrs`, it applies directly to the `Declarator`. 
This distinction is amplified by the fact that, since your review, I've changed 
`DeclarationAttrs` to be a reference, not a by-value field.



Comment at: clang/include/clang/Sema/DeclSpec.h:1975-1984
   /// Reset the contents of this Declarator.
   void clear() {
+clearExceptDeclarationAttrs();
+DeclarationAttrs.clear();
+  }
+
+  /// Reset the contents of this Declarator, except for the declaration

rsmith wrote:
> Note that neither of these functions clear the `DeclSpec`. I suppose that 
> makes sense given that the `Declarator` does not own the `DeclSpec` but 
> merely holds a reference to it. Perhaps we could do the same thing with the 
> declaration attributes?
This is a great idea that also helps with other things. It's similar in spirit 
to the idea that I'd floated in our discussion on 
https://reviews.llvm.org/D111548 of introducing a `Declaration` and having 
`Declarator` hold a reference to that, but it seemed a bit excessive to 
introduce a new `Declaration` class solely for the purpose of holding the 
declaration attributes. Holding a reference directly to the declaration 
attributes achieves the same thing, but without having to introduce yet another 
class. I like it.

One implication of this is that we should only have a const version of 
`getDeclarationAttributes()`; a non-const version would be dangerous because 
we're potentially sharing the attribute list with other declarators. (In fact, 
this wasn't really sound before either because we were effectively already 
sharing the attribute list too by moving it around between declarators.) 
Fortunately, it turns out that all of the places that were using the non-const 
`getDeclarationAttributes()` didn't actually need to be manipulating the 
declaration attribute list. I've added source code comments to call this out 
where appropriate.



Comment at: clang/include/clang/Sema/ParsedAttr.h:657-658
+  /// "slides" to the decl-specifier-seq).
+  /// Attributes with GNU, __declspec or keyword syntax generally slide
+  /// to the decl-specifier-seq. C++11 attributes specified ahead of the
+  /// declaration always appertain to the declaration according to the 
standard,

aaron.ballman wrote:
> rsmith wrote:
> > I don't think this sentence is correct: "Attributes with GNU, __declspec or 
> > keyword syntax generally slide to the decl-specifier-seq." Instead, I think 
> > those attribute syntaxes are never parsed as declaration attributes in the 
> > first place, so there is no possibility of "sliding" anywhere -- they 
> > simply always are decl-spec attributes.
> That's fair -- I tend to think "sliding" is also what happens (at least 
> notionally) in a case like `__attribute__((address_space(1))) int *i;` 
> because it's a type attribute rather than a declaration attribute, but that's 
> also a declaration specifier, so it doesn't really slide anywhere.
Yes, this was inteded to refer to the fact that non-[[]] attributes also 
notionally slide to the `DeclSpec`. In the initial version of my patch, it was 
possible for `slidesFromDeclToDeclSpec()` to be called on non-[[]] attributes 
within the default case in `ProcessDeclAttribute()`.

However, I've realized that this is confusing; it's better to restrict this 
function only to [[]] attributes and to do an explicit check in 
`ProcessDeclAttribute()` to see whether we're looking at a [[]] attribute. I've 
added documentation to this function 

[PATCH] D126373: [pseudo-gen] Add -o flag, make --grammar required

2022-05-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

Thanks!


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

https://reviews.llvm.org/D126373

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


[clang-tools-extra] 788463e - [pseudo-gen] Add -o flag, make --grammar required

2022-05-25 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2022-05-25T09:11:42-04:00
New Revision: 788463e72af847d11476793fdd5d57a104b18b3d

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

LOG: [pseudo-gen] Add -o flag, make --grammar required

Virtually all LLVM tools accept a `-o` flag, so add one. This will make it
possible to possibly add a --write-if-changed flag later. It also makes it
so that the file isn't partially written if the tool oesn't run successfully.

Marking --grammar as `Required` allows removing some manual
verification code for it.

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

Added: 


Modified: 
clang-tools-extra/pseudo/gen/Main.cpp
clang-tools-extra/pseudo/include/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/pseudo/gen/Main.cpp 
b/clang-tools-extra/pseudo/gen/Main.cpp
index 535f863268df1..47ba7f2e71b54 100644
--- a/clang-tools-extra/pseudo/gen/Main.cpp
+++ b/clang-tools-extra/pseudo/gen/Main.cpp
@@ -15,13 +15,17 @@
 #include "clang-pseudo/Grammar.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/ToolOutputFile.h"
 #include 
 
 using llvm::cl::desc;
 using llvm::cl::init;
 using llvm::cl::opt;
+using llvm::cl::Required;
+using llvm::cl::value_desc;
 using llvm::cl::values;
 
 namespace {
@@ -31,13 +35,17 @@ enum EmitType {
 };
 
 opt Grammar("grammar", desc("Parse a BNF grammar file."),
- init(""));
+ Required);
 opt
 Emit(desc("which information to emit:"),
  values(clEnumValN(EmitSymbolList, "emit-symbol-list",
"Print nonterminal symbols (default)"),
 clEnumValN(EmitGrammarContent, "emit-grammar-content",
"Print the BNF grammar content as a string")));
+
+opt OutputFilename("o", init("-"), desc("Output"),
+value_desc("file"));
+
 std::string readOrDie(llvm::StringRef Path) {
   llvm::ErrorOr> Text =
   llvm::MemoryBuffer::getFile(Path);
@@ -52,10 +60,6 @@ std::string readOrDie(llvm::StringRef Path) {
 
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "");
-  if (!Grammar.getNumOccurrences()) {
-llvm::errs() << "Grammar file must be provided!\n";
-return 1;
-  }
 
   std::string GrammarText = readOrDie(Grammar);
   std::vector Diags;
@@ -65,25 +69,34 @@ int main(int argc, char *argv[]) {
 llvm::errs() << llvm::join(Diags, "\n");
 return 1;
   }
-  switch (Emit) {
 
+  std::error_code EC;
+  llvm::ToolOutputFile Out{OutputFilename, EC, llvm::sys::fs::OF_None};
+  if (EC) {
+llvm::errs() << EC.message() << '\n';
+return 1;
+  }
+
+  switch (Emit) {
   case EmitSymbolList:
 for (clang::pseudo::SymbolID ID = 0; ID < G->table().Nonterminals.size();
  ++ID) {
   std::string Name = G->symbolName(ID).str();
   // translation-unit -> translation_unit
   std::replace(Name.begin(), Name.end(), '-', '_');
-  llvm::outs() << (llvm::formatv("NONTERMINAL({0}, {1})\n", Name, ID));
+  Out.os() << llvm::formatv("NONTERMINAL({0}, {1})\n", Name, ID);
 }
 break;
   case EmitGrammarContent:
 for (llvm::StringRef Line : llvm::split(GrammarText, '\n')) {
-  llvm::outs() << '"';
-  llvm::outs().write_escaped((Line + "\n").str());
-  llvm::outs() << "\"\n";
+  Out.os() << '"';
+  Out.os().write_escaped((Line + "\n").str());
+  Out.os() << "\"\n";
 }
 break;
   }
 
+  Out.keep();
+
   return 0;
 }

diff  --git a/clang-tools-extra/pseudo/include/CMakeLists.txt 
b/clang-tools-extra/pseudo/include/CMakeLists.txt
index e2a6f0efc0a32..a79dd0dab8184 100644
--- a/clang-tools-extra/pseudo/include/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/include/CMakeLists.txt
@@ -7,7 +7,7 @@ add_custom_command(OUTPUT ${cxx_symbols_inc}
COMMAND "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/pseudo-gen"
  --grammar ${cxx_bnf}
  --emit-symbol-list
- > ${cxx_symbols_inc}
+ -o ${cxx_symbols_inc}
COMMENT "Generating nonterminal symbol file for cxx grammar..."
DEPENDS pseudo-gen
VERBATIM)
@@ -17,7 +17,7 @@ add_custom_command(OUTPUT ${cxx_bnf_inc}
COMMAND "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/pseudo-gen"
  --grammar ${cxx_bnf}
  --emit-grammar-content
- > ${cxx_bnf_inc}
+ -o ${cxx_bnf_inc}
COMMENT "Generating bnf string file for cxx grammar..."
DEPENDS pseudo-gen
VERBATIM)



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


[PATCH] D126373: [pseudo-gen] Add -o flag, make --grammar required

2022-05-25 Thread Nico Weber 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 rG788463e72af8: [pseudo-gen] Add -o flag, make --grammar 
required (authored by thakis).

Changed prior to commit:
  https://reviews.llvm.org/D126373?vs=431954&id=431958#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126373

Files:
  clang-tools-extra/pseudo/gen/Main.cpp
  clang-tools-extra/pseudo/include/CMakeLists.txt

Index: clang-tools-extra/pseudo/include/CMakeLists.txt
===
--- clang-tools-extra/pseudo/include/CMakeLists.txt
+++ clang-tools-extra/pseudo/include/CMakeLists.txt
@@ -7,7 +7,7 @@
COMMAND "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/pseudo-gen"
  --grammar ${cxx_bnf}
  --emit-symbol-list
- > ${cxx_symbols_inc}
+ -o ${cxx_symbols_inc}
COMMENT "Generating nonterminal symbol file for cxx grammar..."
DEPENDS pseudo-gen
VERBATIM)
@@ -17,7 +17,7 @@
COMMAND "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/pseudo-gen"
  --grammar ${cxx_bnf}
  --emit-grammar-content
- > ${cxx_bnf_inc}
+ -o ${cxx_bnf_inc}
COMMENT "Generating bnf string file for cxx grammar..."
DEPENDS pseudo-gen
VERBATIM)
Index: clang-tools-extra/pseudo/gen/Main.cpp
===
--- clang-tools-extra/pseudo/gen/Main.cpp
+++ clang-tools-extra/pseudo/gen/Main.cpp
@@ -15,13 +15,17 @@
 #include "clang-pseudo/Grammar.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/ToolOutputFile.h"
 #include 
 
 using llvm::cl::desc;
 using llvm::cl::init;
 using llvm::cl::opt;
+using llvm::cl::Required;
+using llvm::cl::value_desc;
 using llvm::cl::values;
 
 namespace {
@@ -31,13 +35,17 @@
 };
 
 opt Grammar("grammar", desc("Parse a BNF grammar file."),
- init(""));
+ Required);
 opt
 Emit(desc("which information to emit:"),
  values(clEnumValN(EmitSymbolList, "emit-symbol-list",
"Print nonterminal symbols (default)"),
 clEnumValN(EmitGrammarContent, "emit-grammar-content",
"Print the BNF grammar content as a string")));
+
+opt OutputFilename("o", init("-"), desc("Output"),
+value_desc("file"));
+
 std::string readOrDie(llvm::StringRef Path) {
   llvm::ErrorOr> Text =
   llvm::MemoryBuffer::getFile(Path);
@@ -52,10 +60,6 @@
 
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "");
-  if (!Grammar.getNumOccurrences()) {
-llvm::errs() << "Grammar file must be provided!\n";
-return 1;
-  }
 
   std::string GrammarText = readOrDie(Grammar);
   std::vector Diags;
@@ -65,25 +69,34 @@
 llvm::errs() << llvm::join(Diags, "\n");
 return 1;
   }
-  switch (Emit) {
 
+  std::error_code EC;
+  llvm::ToolOutputFile Out{OutputFilename, EC, llvm::sys::fs::OF_None};
+  if (EC) {
+llvm::errs() << EC.message() << '\n';
+return 1;
+  }
+
+  switch (Emit) {
   case EmitSymbolList:
 for (clang::pseudo::SymbolID ID = 0; ID < G->table().Nonterminals.size();
  ++ID) {
   std::string Name = G->symbolName(ID).str();
   // translation-unit -> translation_unit
   std::replace(Name.begin(), Name.end(), '-', '_');
-  llvm::outs() << (llvm::formatv("NONTERMINAL({0}, {1})\n", Name, ID));
+  Out.os() << llvm::formatv("NONTERMINAL({0}, {1})\n", Name, ID);
 }
 break;
   case EmitGrammarContent:
 for (llvm::StringRef Line : llvm::split(GrammarText, '\n')) {
-  llvm::outs() << '"';
-  llvm::outs().write_escaped((Line + "\n").str());
-  llvm::outs() << "\"\n";
+  Out.os() << '"';
+  Out.os().write_escaped((Line + "\n").str());
+  Out.os() << "\"\n";
 }
 break;
   }
 
+  Out.keep();
+
   return 0;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c673d67 - [AST] Dont invalidate a ref-type var decl if it has no initializer.

2022-05-25 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-05-25T15:14:35+02:00
New Revision: c673d67bc76bfa31b78e3eee23899b9f262158ea

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

LOG: [AST] Dont invalidate a ref-type var decl if it has no initializer.

This would allow more AST nodes being preserved for broken code, and
have a more consistent valid bit for ref-type var decl (currently, a
ref-type var decl with a broken initializer is valid).

Per https://reviews.llvm.org/D76831#1973053, the initializer of a variable
should play no part in its "invalid" bit.

Reviewed By: sammccall

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

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/AST/ast-dump-invalid-initialized.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b150a88e0aa21..c5d4075a49e2f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13199,7 +13199,6 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
 if (Type->isReferenceType()) {
   Diag(Var->getLocation(), diag::err_reference_var_requires_init)
   << Var << SourceRange(Var->getLocation(), Var->getLocation());
-  Var->setInvalidDecl();
   return;
 }
 

diff  --git a/clang/test/AST/ast-dump-invalid-initialized.cpp 
b/clang/test/AST/ast-dump-invalid-initialized.cpp
index 1b3c8581a94fb..1c374ae716a9d 100644
--- a/clang/test/AST/ast-dump-invalid-initialized.cpp
+++ b/clang/test/AST/ast-dump-invalid-initialized.cpp
@@ -12,10 +12,10 @@ void test() {
   const A a2;
   // CHECK: `-VarDecl {{.*}} a3 'A'
   A a3 = garbage();
+  // CHECK: `-VarDecl {{.*}} a4 'const A &'
+  const A& a4;
 
 
-  // CHECK: `-VarDecl {{.*}} invalid b1 'const A &'
-  const A& b1;
   // CHECK: `-VarDecl {{.*}} invalid b2 'ForwardDecl'
   ForwardDecl b2;
   // CHECK: `-VarDecl {{.*}} invalid b3 'auto'



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


[PATCH] D122935: [AST] Dont invalidate a ref-type var decl if it has no initializer.

2022-05-25 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc673d67bc76b: [AST] Dont invalidate a ref-type var decl if 
it has no initializer. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122935

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/AST/ast-dump-invalid-initialized.cpp


Index: clang/test/AST/ast-dump-invalid-initialized.cpp
===
--- clang/test/AST/ast-dump-invalid-initialized.cpp
+++ clang/test/AST/ast-dump-invalid-initialized.cpp
@@ -12,10 +12,10 @@
   const A a2;
   // CHECK: `-VarDecl {{.*}} a3 'A'
   A a3 = garbage();
+  // CHECK: `-VarDecl {{.*}} a4 'const A &'
+  const A& a4;
 
 
-  // CHECK: `-VarDecl {{.*}} invalid b1 'const A &'
-  const A& b1;
   // CHECK: `-VarDecl {{.*}} invalid b2 'ForwardDecl'
   ForwardDecl b2;
   // CHECK: `-VarDecl {{.*}} invalid b3 'auto'
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13199,7 +13199,6 @@
 if (Type->isReferenceType()) {
   Diag(Var->getLocation(), diag::err_reference_var_requires_init)
   << Var << SourceRange(Var->getLocation(), Var->getLocation());
-  Var->setInvalidDecl();
   return;
 }
 


Index: clang/test/AST/ast-dump-invalid-initialized.cpp
===
--- clang/test/AST/ast-dump-invalid-initialized.cpp
+++ clang/test/AST/ast-dump-invalid-initialized.cpp
@@ -12,10 +12,10 @@
   const A a2;
   // CHECK: `-VarDecl {{.*}} a3 'A'
   A a3 = garbage();
+  // CHECK: `-VarDecl {{.*}} a4 'const A &'
+  const A& a4;
 
 
-  // CHECK: `-VarDecl {{.*}} invalid b1 'const A &'
-  const A& b1;
   // CHECK: `-VarDecl {{.*}} invalid b2 'ForwardDecl'
   ForwardDecl b2;
   // CHECK: `-VarDecl {{.*}} invalid b3 'auto'
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13199,7 +13199,6 @@
 if (Type->isReferenceType()) {
   Diag(Var->getLocation(), diag::err_reference_var_requires_init)
   << Var << SourceRange(Var->getLocation(), Var->getLocation());
-  Var->setInvalidDecl();
   return;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-05-25 Thread Paul Robinson via Phabricator via cfe-commits
probinson added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:5596
+  DefaultedSMFArePOD = false;
+  }
+

Does this mean `-fclang-abi-compat` will override the PS4/Darwin special case?  
I think we don't want to do that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[clang] a17fc7f - Fix unused-variable warning, NFC.

2022-05-25 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-05-25T15:25:03+02:00
New Revision: a17fc7fd865096f4be6b8b4a7e6e0834aae6c048

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

LOG: Fix unused-variable warning, NFC.

Added: 


Modified: 
clang/tools/libclang/CIndex.cpp

Removed: 




diff  --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index cf31524bbc43..7bc945379329 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -1511,8 +1511,7 @@ bool CursorVisitor::VisitTemplateParameters(
   }
 
   if (const auto *E = Params->getRequiresClause()) {
-if (Visit(MakeCXCursor(Params->getRequiresClause(), nullptr, TU,
-   RegionOfInterest)))
+if (Visit(MakeCXCursor(E, nullptr, TU, RegionOfInterest)))
   return true;
   }
 



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


[PATCH] D125847: LTO: Decide upfront whether to use opaque/non-opaque pointer types

2022-05-25 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

Looks reasonable to me, but probably @MaskRay should review.

We could add a `-fno-opaque-pointers` driver option that covers both the 
compiler backend and LTO, but we can probably get away without it as well.




Comment at: lld/ELF/Options.td:311
+  "Use opaque pointers in IR used during LTO",
+  "Use typed pointers in IR used during LTO (default)">;
+

`(default)` here is outdated.

Possibly this option should be `lto_opaque_pointers`? That seems to be the 
convention for other related options.



Comment at: llvm/docs/OpaquePointers.rst:69
+LLVM tools like ``opt``, or ``-Xclang -opaque-pointers`` in clang,
+``-Wl,-plugin-opt=-opaque-pointers`` for LTO. Additionally, opaque pointer mode
+is automatically enabled for IR and bitcode files that use the ``ptr`` type.

`-plugin-opt=opaque-pointers`. Though it probably makes more sense now to 
mention this at the end of the document, as an option to //disable//.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125847

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


[PATCH] D126365: [git-clang-format] Stop ignoring changes for files with space in path

2022-05-25 Thread Eitot via Phabricator via cfe-commits
Eitot added a comment.

In D126365#3536736 , @curdeius wrote:

> Would it be possible to add a test please?

Could you tell me what kind of test you would like me to add? I have edited the 
description above to include my result. I can add a basic shell script to set 
up a git repo and a few test files to illustrate the problem, if that is what 
you have in mind?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126365

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


[clang] d8dda57 - [PS5] Default to -fno-rtti

2022-05-25 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-05-25T06:48:21-07:00
New Revision: d8dda57ae7798a052e52ef5979980e815d2e4bc5

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

LOG: [PS5] Default to -fno-rtti

Added: 


Modified: 
clang/lib/Driver/ToolChain.cpp
clang/test/Driver/rtti-options.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index efbf2442acfc..eb3117e689d8 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -67,8 +67,8 @@ static ToolChain::RTTIMode CalculateRTTIMode(const ArgList 
&Args,
   return ToolChain::RM_Disabled;
   }
 
-  // -frtti is default, except for the PS4 and DriverKit.
-  bool NoRTTI = Triple.isPS4() || Triple.isDriverKit();
+  // -frtti is default, except for the PS4/PS5 and DriverKit.
+  bool NoRTTI = Triple.isPS() || Triple.isDriverKit();
   return NoRTTI ? ToolChain::RM_Disabled : ToolChain::RM_Enabled;
 }
 

diff  --git a/clang/test/Driver/rtti-options.cpp 
b/clang/test/Driver/rtti-options.cpp
index e1d37d35bb68..5a8a9fe43c74 100644
--- a/clang/test/Driver/rtti-options.cpp
+++ b/clang/test/Driver/rtti-options.cpp
@@ -22,6 +22,7 @@
 // RUN: %clang -### -c -target x86_64-unknown-linux -fsanitize=undefined %s 
2>&1 | FileCheck -check-prefix=CHECK-OK %s
 // RUN: %clang -### -c -target x86_64-unknown-linux -fsanitize=undefined 
-frtti %s 2>&1 | FileCheck -check-prefix=CHECK-OK %s
 // RUN: %clang -### -c -target x86_64-scei-ps4 -fsanitize=vptr %s 2>&1 | 
FileCheck -check-prefix=CHECK-SAN-WARN %s
+// RUN: %clang -### -c -target x86_64-sie-ps5 -fsanitize=vptr %s 2>&1 | 
FileCheck -check-prefix=CHECK-SAN-WARN %s
 
 // Exceptions + no/default rtti
 // RUN: %clang -### -c -target x86_64-unknown-unknown -fcxx-exceptions 
-fno-rtti %s 2>&1 | FileCheck -check-prefix=CHECK-OK %s
@@ -35,6 +36,7 @@
 
 // -f{no-,}rtti/default
 // RUN: %clang -### -c -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-RTTI %s
+// RUN: %clang -### -c -target x86_64-sie-ps5 %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-RTTI %s
 // RUN: %clang -### -c -target x86_64-unknown-unknown -frtti %s 2>&1 | 
FileCheck -check-prefix=CHECK-RTTI %s
 // RUN: %clang -### -c -target x86_64-unknown-unknown -fno-rtti %s 2>&1 | 
FileCheck -check-prefix=CHECK-NO-RTTI %s
 // RUN: %clang -### -c -target x86_64-unknown-unknown %s 2>&1 | FileCheck 
-check-prefix=CHECK-RTTI %s



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


[PATCH] D124860: [clang][AArch64][SVE] Implicit conversions for vector-scalar operations

2022-05-25 Thread David Truby via Phabricator via cfe-commits
DavidTruby added a comment.

In D124860#3533878 , @c-rhodes wrote:

> can the diagnostics improvements be broke out into separate patches? I think 
> it would make this easier to review

I've split the diagnostic changes from this out as D126377 
 and will repost this patch soon based on 
that one. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124860

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


[PATCH] D125547: [analyzer][solver] Handle UnarySymExpr in SMTConv

2022-05-25 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 431970.
martong added a comment.

- Fix Assertion `*Solver->getSort(LHS) == *Solver->getSort(RHS) && "AST's must 
have the same sort!"' failed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125547

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h
  clang/test/Analysis/unary-sym-expr-z3-refutation.c
  clang/test/Analysis/z3-crosscheck.c


Index: clang/test/Analysis/z3-crosscheck.c
===
--- clang/test/Analysis/z3-crosscheck.c
+++ clang/test/Analysis/z3-crosscheck.c
@@ -14,6 +14,20 @@
   return 0;
 }
 
+int unary(int x, long l)
+{
+  int *z = 0;
+  int y = l;
+  if ((x & 1) && ((x & 1) ^ 1))
+if (-y)
+#ifdef NO_CROSSCHECK
+return *z; // expected-warning {{Dereference of null pointer (loaded 
from variable 'z')}}
+#else
+return *z; // no-warning
+#endif
+  return 0;
+}
+
 void g(int d);
 
 void f(int *a, int *b) {
Index: clang/test/Analysis/unary-sym-expr-z3-refutation.c
===
--- /dev/null
+++ clang/test/Analysis/unary-sym-expr-z3-refutation.c
@@ -0,0 +1,33 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=true \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=true \
+// RUN:   -analyzer-config support-symbolic-integer-casts=true \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=true \
+// RUN:   -analyzer-config crosscheck-with-z3=true \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=true \
+// RUN:   -analyzer-config crosscheck-with-z3=true \
+// RUN:   -analyzer-config support-symbolic-integer-casts=true \
+// RUN:   -verify
+
+// REQUIRES: z3
+
+void k(long L) {
+  int g = L;
+  int h = g + 1;
+  int j;
+  j += -h < 0; // should not crash
+  // expected-warning@-1{{garbage}}
+}
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h
@@ -446,6 +446,28 @@
   return getCastExpr(Solver, Ctx, Exp, FromTy, Sym->getType());
 }
 
+if (const UnarySymExpr *USE = dyn_cast(Sym)) {
+  if (RetTy)
+*RetTy = Sym->getType();
+
+  QualType OperandTy;
+  llvm::SMTExprRef OperandExp =
+  getSymExpr(Solver, Ctx, USE->getOperand(), &OperandTy, 
hasComparison);
+  llvm::SMTExprRef UnaryExp =
+  fromUnOp(Solver, USE->getOpcode(), OperandExp);
+
+  // Currently, without the `support-symbolic-integer-casts=true` option,
+  // we do not emit `SymbolCast`s for implicit casts.
+  // One such implicit cast is missing if the operand of the unary operator
+  // has a different type than the unary itself.
+  if (OperandTy != Sym->getType()) {
+if (hasComparison)
+  *hasComparison = false;
+return getCastExpr(Solver, Ctx, UnaryExp, OperandTy, Sym->getType());
+  }
+  return UnaryExp;
+}
+
 if (const BinarySymExpr *BSE = dyn_cast(Sym)) {
   llvm::SMTExprRef Exp =
   getSymBinExpr(Solver, Ctx, BSE, hasComparison, RetTy);


Index: clang/test/Analysis/z3-crosscheck.c
===
--- clang/test/Analysis/z3-crosscheck.c
+++ clang/test/Analysis/z3-crosscheck.c
@@ -14,6 +14,20 @@
   return 0;
 }
 
+int unary(int x, long l)
+{
+  int *z = 0;
+  int y = l;
+  if ((x & 1) && ((x & 1) ^ 1))
+if (-y)
+#ifdef NO_CROSSCHECK
+return *z; // expected-warning {{Dereference of null pointer (loaded from variable 'z')}}
+#else
+return *z; // no-warning
+#endif
+  return 0;
+}
+
 void g(int d);
 
 void f(int *a, int *b) {
Index: clang/test/Analysis/unary-sym-expr-z3-refutation.c
===
--- /dev/null
+++ clang/test/Analysis/unary-sym-expr-z3-refutation.c
@@ -0,0 +1,33 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=true \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=true \
+// RUN:   -analyzer-config support-symbolic-integer-casts=true \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=true \
+// RUN:   -anal

[PATCH] D124525: [OpenMP][ClangLinkerWrapper] Extending linker wrapper to embed metadata for multi-arch fat binaries

2022-05-25 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam updated this revision to Diff 431975.
saiislam added a comment.

Changed the embedding scheme to add ImageInfo field in __tgt_device_image.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124525

Files:
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  clang/tools/clang-linker-wrapper/OffloadWrapper.cpp
  clang/tools/clang-linker-wrapper/OffloadWrapper.h
  openmp/libomptarget/include/omptarget.h
  openmp/libomptarget/src/rtl.cpp

Index: openmp/libomptarget/src/rtl.cpp
===
--- openmp/libomptarget/src/rtl.cpp
+++ openmp/libomptarget/src/rtl.cpp
@@ -13,6 +13,7 @@
 #include "rtl.h"
 #include "device.h"
 #include "private.h"
+//#include "llvm/OffloadArch/OffloadArch.h"
 
 #include 
 #include 
@@ -20,6 +21,8 @@
 #include 
 #include 
 #include 
+// It's strange we do not have llvm tools for openmp runtime, so we use stat
+#include 
 
 // List of all plugins that can support offloading.
 static const char *RTLNames[] = {
@@ -351,18 +354,108 @@
 initRTLonce(R);
 }
 
+/// Query runtime capabilities of this system by calling offload-arch -c
+/// offload_arch_output_buffer is persistant storage returned by this
+/// __tgt_get_active_offload_env.
+static void
+__tgt_get_active_offload_env(__tgt_active_offload_env *active_env,
+ char *offload_arch_output_buffer,
+ size_t offload_arch_output_buffer_size) {
+
+  // If OFFLOAD_ARCH_OVERRIDE env varible is present then use its value instead
+  // of querying it using LLVMOffloadArch library.
+  if (char *OffloadArchEnvVar = getenv("OFFLOAD_ARCH_OVERRIDE")) {
+if (OffloadArchEnvVar) {
+  active_env->capabilities = OffloadArchEnvVar;
+  return;
+}
+  }
+  // Qget runtime capabilities of this system with libLLVMOffloadArch.a
+  // if (int rc = getRuntimeCapabilities(offload_arch_output_buffer,
+  // offload_arch_output_buffer_size))
+  //   return;
+  // active_env->capabilities = offload_arch_output_buffer;
+  // return;
+}
+
+std::vector _splitstrings(char *input, const char *sep) {
+  std::vector split_strings;
+  std::string s(input);
+  std::string delimiter(sep);
+  size_t pos = 0;
+  while ((pos = s.find(delimiter)) != std::string::npos) {
+if (pos != 0)
+  split_strings.push_back(s.substr(0, pos));
+s.erase(0, pos + delimiter.length());
+  }
+  if (s.length() > 1)
+split_strings.push_back(s.substr(0, s.length()));
+  return split_strings;
+}
+
+static bool _ImageIsCompatibleWithEnv(__tgt_image_info *image_info,
+  __tgt_active_offload_env *active_env) {
+  // get_image_info will return null if no image information was registered.
+  // If no image information, assume application built with old compiler and
+  // check each image.
+  if (!image_info)
+return true;
+
+  if (!active_env->capabilities)
+return false;
+
+  // Each runtime requirement for the compiled image is stored in
+  // the image_info->offload_arch (TargetID) string.
+  // Each runtime capability obtained from "offload-arch -c" is stored in
+  // actvie_env->capabilities (TargetID) string.
+  // If every requirement has a matching capability, then the image
+  // is compatible with active environment
+
+  std::vector reqs = _splitstrings(image_info->offload_arch, ":");
+  std::vector caps = _splitstrings(active_env->capabilities, ":");
+
+  bool is_compatible = true;
+  for (auto req : reqs) {
+bool missing_capability = true;
+for (auto capability : caps)
+  if (capability == req)
+missing_capability = false;
+if (missing_capability) {
+  DP("Image requires %s but runtime capability %s is missing.\n",
+ image_info->offload_arch, req.c_str());
+  is_compatible = false;
+}
+  }
+  return is_compatible;
+}
+
+#define MAX_CAPS_STR_SIZE 1024
 void RTLsTy::RegisterLib(__tgt_bin_desc *desc) {
+
+  // Get the current active offload environment
+  __tgt_active_offload_env offload_env = {nullptr};
+  // Need a buffer to hold results of offload-arch -c command
+  size_t offload_arch_output_buffer_size = MAX_CAPS_STR_SIZE;
+  std::vector offload_arch_output_buffer;
+  offload_arch_output_buffer.resize(offload_arch_output_buffer_size);
+  __tgt_get_active_offload_env(&offload_env, offload_arch_output_buffer.data(),
+   offload_arch_output_buffer_size);
+
+  RTLInfoTy *FoundRTL = NULL;
   PM->RTLsMtx.lock();
   // Register the images with the RTLs that understand them, if any.
   for (int32_t i = 0; i < desc->NumDeviceImages; ++i) {
 // Obtain the image.
 __tgt_device_image *img = &desc->DeviceImages[i];
 
-RTLInfoTy *FoundRTL = nullptr;
-
+// Get corresponding image info offload_arch and check with runtime
+if (!_ImageIsCompatibleWithEnv(img->ImageInfo, &offload_env))
+  continue;
+

[PATCH] D125604: [FileCheck] Catch missspelled directives.

2022-05-25 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev updated this revision to Diff 431979.
kosarev added a comment.

Rebased on top of fixes for non-trivial cases. Going to submit this
tomorrow, if no objections.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125604

Files:
  clang/test/CodeGenCXX/attr-mustprogress.cpp
  clang/test/CodeGenCXX/eh-aggregate-copy-destroy.cpp
  clang/test/CodeGenCXX/inheriting-constructor.cpp
  clang/test/CodeGenObjC/non-runtime-protocol.m
  clang/test/OpenMP/master_taskloop_private_codegen.cpp
  clang/test/OpenMP/master_taskloop_simd_private_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_private_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_private_codegen.cpp
  clang/test/OpenMP/task_private_codegen.cpp
  clang/test/OpenMP/taskgroup_task_reduction_codegen.cpp
  clang/test/OpenMP/taskloop_private_codegen.cpp
  clang/test/OpenMP/taskloop_simd_private_codegen.cpp
  flang/test/Fir/convert-to-llvm.fir
  flang/test/Lower/Intrinsics/not.f90
  llvm/include/llvm/FileCheck/FileCheck.h
  llvm/lib/FileCheck/FileCheck.cpp
  llvm/test/Analysis/MemorySSA/phi-translation.ll
  llvm/test/Analysis/RegionInfo/infinite_loop_4.ll
  llvm/test/CodeGen/AMDGPU/divergence-driven-bfe-isel.ll
  llvm/test/CodeGen/AMDGPU/hoist-cond.ll
  llvm/test/CodeGen/AMDGPU/llvm.amdgcn.ps.live.ll
  llvm/test/CodeGen/AMDGPU/mode-register.mir
  llvm/test/CodeGen/AMDGPU/smrd.ll
  llvm/test/CodeGen/ARM/cmpxchg-O0-be.ll
  llvm/test/CodeGen/AVR/atomics/fence.ll
  llvm/test/CodeGen/BPF/CORE/offset-reloc-middle-chain.ll
  llvm/test/CodeGen/WebAssembly/libcalls.ll
  llvm/test/DebugInfo/NVPTX/debug-info.ll
  llvm/test/FileCheck/missspelled-directive.txt
  llvm/test/MC/AMDGPU/data.s
  llvm/test/MC/AsmParser/directive_file-g.s
  llvm/test/MC/PowerPC/ppc64-reloc-directive-pcrel.s
  llvm/test/MC/WebAssembly/unnamed-data.ll
  llvm/test/Transforms/Inline/inline-strictfp.ll
  llvm/test/Transforms/LoopVectorize/X86/gather-vs-interleave.ll
  llvm/test/Transforms/MergeFunc/alias.ll
  llvm/test/Transforms/PGOProfile/PR41279.ll
  llvm/test/Transforms/PGOProfile/memop_clone.ll
  llvm/test/Transforms/PGOProfile/memop_size_from_strlen.ll
  llvm/test/tools/llvm-dwp/X86/tu_units_v5.s
  llvm/test/tools/llvm-dwp/X86/type_dedup_v5.test
  llvm/test/tools/llvm-objdump/MachO/disassemble-all.test
  llvm/test/tools/llvm-readobj/COFF/unwind-arm64-windows.test
  mlir/test/Dialect/Affine/loop-coalescing.mlir
  mlir/test/Dialect/Linalg/fuse-with-reshape-by-collapsing.mlir
  mlir/test/Dialect/Linalg/tile-and-fuse-no-fuse.mlir
  mlir/test/Dialect/MemRef/canonicalize.mlir
  mlir/test/Dialect/SPIRV/IR/memory-ops.mlir
  mlir/test/Dialect/Vector/vector-transfer-full-partial-split.mlir
  mlir/test/IR/dynamic.mlir
  mlir/test/mlir-tblgen/op-decl-and-defs.td
  polly/test/ScopDetect/dot-scops-npm.ll

Index: polly/test/ScopDetect/dot-scops-npm.ll
===
--- polly/test/ScopDetect/dot-scops-npm.ll
+++ polly/test/ScopDetect/dot-scops-npm.ll
@@ -30,35 +30,35 @@
 ; CHECK-NEXT: Node0x[[OUTER_EXIT]] -> Node0x[[RETURN_ID:.*]];
 ; CHECK-NEXT: Node0x[[RETURN_ID]] [shape=record,label="{return:
 ; CHECK-NEXT: colorscheme = "paired12"
-; CHECK_NEXT: subgraph cluster_0x[[:.*]] {
-; CHECK_NEXT: label = "";
-; CHECK_NEXT: style = solid;
-; CHECK_NEXT: color = 1
-; CHECK_NEXT: subgraph cluster_0x[[:.*]] {
-; CHECK_NEXT: label = "";
-; CHECK_NEXT: style = filled;
-; CHECK_NEXT: color = 3subgraph cluster_0x7152c40 {
-; CHECK_NEXT: label = "";
-; CHECK_NEXT: style = solid;
-; CHECK_NEXT: color = 5
-; CHECK_NEXT: subgraph cluster_0x[[:.*]] {
-; CHECK_NEXT: label = "";
-; CHECK_NEXT: style = solid;
-; CHECK_NEXT: color = 7
-; CHECK_NEXT: Node0x[[INNER_FOR_ID]];
-; CHECK_NEXT: Node0x[[BABY1_ID]];
-; CHECK_NEXT: Node0x[[INNER_INC_ID]];
-; CHECK_NEXT: }
-; CHECK_NEXT: Node0x[[OUTER_FOR_ID]];
-; CHECK_NEXT: Node0x[[INNER_EXIT_ID]];
-; CHECK_NEXT: Node0x[[OUTER_INC_ID]];
-; CHECK_NEXT: }
-; CHECK_NEXT: Node0x[[OUTER_EXIT]];
-; CHECK_NEXT: }
-; CHECK_NEXT: Node0x[[EntryID]];
-; CHECK_NEXT: Node0x[[RETURN_ID]];
-; CHECK_NEXT: }
-; CHECK_NEXT: }
+; CHECK-NEXT: subgraph cluster_0x{{.*}} {
+; CHECK-NEXT: label = "";
+; CHECK-NEXT: style = solid;
+; CHECK-NEXT: color = 1
+; CHECK-NEXT: subgraph cluster_0x{{.*}} {
+; CHECK-NEXT: label = "";
+; CHECK-NEXT: style = filled;
+; CHECK-NEXT: color = 3subgraph cluster_0x{{.*}} {
+; CHECK-NEXT: label = "";
+; CHECK-NEXT: style = solid;
+; CHECK-NEXT: color = 5
+; CHECK-NEXT: subgraph cluster_0x{{.*}} {
+; CHECK-NEXT: label = "";
+; CHECK-NEXT: style = solid;
+; CHECK-NEXT: color = 7
+; CHECK-NEXT: Node0x[[INNER_FOR_ID]];
+; CHECK-NEXT: Node0x[[BABY1_ID]];
+; CHECK-NEXT: Node0x[[INNER_INC_ID]];
+; CHECK-NEXT: }
+; CHECK-NEXT: Node0x[[OUTER_FOR_ID]];
+; CHECK-NEXT: Node0x[[INNER_EXIT_ID]];
+; CHECK-NEXT: Node0x[[OUTER_INC_ID]];
+; CHECK-NEXT: }
+; CHECK-NEXT: Node0x[[OUTER_EXIT]];
+; CHECK-NEXT: }
+; CHECK-NEX

[PATCH] D124081: [clang] [WIP] Reject non-declaration C++11 attributes on declarations.

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

It appears that we are converging on the approach in 
https://reviews.llvm.org/D126061, so I'm abandoning this revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124081

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


[PATCH] D124083: [clang] [WIP] Reject C++ 11 attributes appertaining to the wrong entity type.

2022-05-25 Thread Martin Böhme via Phabricator via cfe-commits
mboehme abandoned this revision.
mboehme added a comment.

It appears that we're converging on the approach in 
https://reviews.llvm.org/D126061, so I'm abandoning this change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124083

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


[PATCH] D124919: [clang] [WIP] Reject non-declaration C++11 attributes on declarations.

2022-05-25 Thread Martin Böhme via Phabricator via cfe-commits
mboehme abandoned this revision.
mboehme added a comment.

It appears that we're converging on the approach in 
https://reviews.llvm.org/D126061, so I'm abandoning this change.


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

https://reviews.llvm.org/D124919

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


[PATCH] D101471: [clang-tidy] Add proper emplace checks to modernize-use-emplace

2022-05-25 Thread Jakub Kuderski via Phabricator via cfe-commits
kuhar accepted this revision.
kuhar added a comment.
This revision is now accepted and ready to land.

LGTM but please get a second approval before submitting.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101471

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


[PATCH] D126380: [clang][AArch64][SVE] Implicit conversions for vector-scalar operations

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

This patch allows the same implicit conversions for vector-scalar
operations in SVE that are allowed for NEON.

Depends on D126377 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126380

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGen/aarch64-sve-vector-arith-ops.c
  clang/test/Sema/aarch64-sve-vector-scalar-ops.c
  clang/test/Sema/sizeless-1.c
  clang/test/SemaCXX/sizeless-1.cpp

Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -213,23 +213,6 @@
   local_int8 &&init_int8;  // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
   local_int8 || init_int8; // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
 
-  local_int8 + 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 - 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 * 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 / 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 % 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 & 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 | 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 ^ 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 < 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 <= 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 == 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 != 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 >= 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 > 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 && 0; // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
-  local_int8 || 0; // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
-
   if (local_int8) { // expected-error {{not contextually convertible to 'bool'}}
   }
   while (local_int8) { // expected-error {{not contextually convertible to 'bool'}}
Index: clang/test/Sema/sizeless-1.c
===
--- clang/test/Sema/sizeless-1.c
+++ clang/test/Sema/sizeless-1.c
@@ -201,23 +201,6 @@
   local_int8 &&init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 || init_int8; // expected-error {{invalid operands to binary expression}}
 
-  local_int8 + 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 - 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 * 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 / 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 % 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 & 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 | 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 ^ 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 < 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 <= 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 == 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 != 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 >= 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 > 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 && 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 || 0; // expected-error {{invalid operands to binary expression}}
-
   if (local_int8) { // expected-error {{statement requires expression of scalar type}}
   }
   while (local_int8) { // expected-error {{statement requires expression of scalar type}}
Index: clang/test/Sema/aarch64-sve-vector-scalar-ops.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve-vector-scalar-ops.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -verify -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +neon -fallow-half-arguments-and-returns -fsyntax-only %s
+
+// R

[PATCH] D124860: [clang][AArch64][SVE] Implicit conversions for vector-scalar operations

2022-05-25 Thread David Truby via Phabricator via cfe-commits
DavidTruby abandoned this revision.
DavidTruby added a comment.

I've resubmitted this split from the diagnostic changes as D126380 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124860

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


[PATCH] D125547: [analyzer][solver] Handle UnarySymExpr in SMTConv

2022-05-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.

I think it looks greatt
There are a couple questions you need to think about, but I don't insist about 
changing anything if the code works passed widescale testing.




Comment at: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h:463
+  // has a different type than the unary itself.
+  if (OperandTy != Sym->getType()) {
+if (hasComparison)

Could this fail spuriously due to a constness mismatch, since you compare 
QualTypes instead of types?
What happens if one of these refers to typedef? 
Shouldn't we compare the canonical type pointers instead? Or this works out 
just fine in practice. I might over-worry this :D

ALternatively, we could emit this cast only if the bitwidths are different. 
(which caused the sort difference, thus the crash)



Comment at: clang/test/Analysis/unary-sym-expr-z3-refutation.c:28
+void k(long L) {
+  int g = L;
+  int h = g + 1;

So this is the implicit cast that we don't emit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125547

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


[PATCH] D126324: [clang] Allow const variables with weak attribute to be overridden

2022-05-25 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In D126324#3536785 , @aaron.ballman 
wrote:

> The changes so far look sensible, but I think we should add some more tests 
> for a few situations. 1) Using a const weak symbol as a valid initializer 
> should be diagnosed (with a warning? with an error?) so users are alerted to 
> the behavioral quirks.

I don't feel this is really necessary.

> 2. Using a const weak symbol in a constant expression context should probably 
> be an error, right? e.g.,

That's already the case (except, using a VLA is not an error in either language 
mode). Clang previously _only_ treated weak symbols as compile-time-known in 
the backend; the frontend has treated it as an non-constant-evaluable variable 
for ages, and that behavior is unchanged by this patch.

> Also, this definitely could use a release note so users know about the 
> behavioral change.
>
> Do you have any ideas on how much code this change is expected to break? (Is 
> it sufficient enough that we want to have an explicit deprecation period of 
> the existing behavior before we switch to the new behavior?)

Because it's only changing the optimizer behavior not the frontend constant 
evaluator, I think it's pretty safe (which is also why I'm OK with it).




Comment at: clang/include/clang/Basic/AttrDocs.td:6527
+If an external declaration is marked weak and that symbol does not
+exist during linking (possibly dynamic) the linker will replace that
+with NULL.

Better said:
"""
If an external declaration is marked weak and that symbol does not
exist during linking (possibly dynamic) the address of the symbol
will evaluate to NULL.
"""

(function decls are just weird in that `&f` is treated as equivalent to `f`)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126324

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


[PATCH] D124758: [analyzer] Implement assume in terms of assumeDual

2022-05-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

This commit introduced a serious runtime regression on this code:

  #define DEMONSTRATE_HANG
  
  typedef unsigned char uint8_t;
  typedef unsigned short uint16_t;
  typedef unsigned long uint64_t;
  
  void clang_analyzer_numTimesReached(void);
  
  int filter_slice_word(int sat_linesize, int sigma, int radius, uint64_t *sat,
uint64_t *square_sat, int width, int height,
int src_linesize, int dst_linesize, const uint16_t *src,
uint16_t *dst, int jobnr, int nb_jobs) {
const int starty = height * jobnr / nb_jobs;
const int endy = height * (jobnr + 1) / nb_jobs;
  
clang_analyzer_numTimesReached(); // 1 times
for (int y = starty; y < endy; y++) {
  clang_analyzer_numTimesReached(); // 285 times
  
  int lower_y = y - radius < 0 ? 0 : y - radius;
  int higher_y = y + radius + 1 > height ? height : y + radius + 1;
  int dist_y = higher_y - lower_y;
  clang_analyzer_numTimesReached(); // 1128 times
  
  for (int x = 0; x < width; x++) {
clang_analyzer_numTimesReached(); // 560 times

int lower_x = x - radius < 0 ? 0 : x - radius;
int higher_x = x + radius + 1 > width ? width : x + radius + 1;
int count = dist_y * (higher_x - lower_x);
  #ifdef DEMONSTRATE_HANG
uint64_t sum = sat[higher_y * sat_linesize + higher_x] -
   sat[higher_y * sat_linesize + lower_x] -
   sat[lower_y * sat_linesize + higher_x] +
   sat[lower_y * sat_linesize + lower_x];
uint64_t square_sum = square_sat[higher_y * sat_linesize + higher_x] -
  square_sat[higher_y * sat_linesize + lower_x] -
  square_sat[lower_y * sat_linesize + higher_x] +
  square_sat[lower_y * sat_linesize + lower_x];
uint64_t mean = sum / count;
uint64_t var = (square_sum - sum * sum / count) / count;
dst[y * dst_linesize + x] =
(sigma * mean + var * src[y * src_linesize + x]) / (sigma + var);
  #endif
  }
}
return 0;
  }

  /build/release/bin/clang --analyze -Xclang 
-analyzer-checker=core,alpha.security.ArrayBoundV2,debug.ExprInspection test.c

Prior to this commit, the analysis of this code took about 2.6 seconds on my 
machine (release build with shared libs)
After this commit, it takes more than 67 minutes, and most of the time is spent 
in the constraint solver doing simplification I think.

Be reminded of the `ArrayBoundV2` checker which will try to express the 
symbolic atom of the indexer expression:
`0 <= (x + 3) < extent` => `-3 <= x < extent - 3` (this is more complex in the 
wild, it's for demonstration now).
So, it will create new and new states during this process, while gathering 
constraints to make the indexing well-formed.

However, the nested loops and the eager bifurcation over the `<` and `>` 
operators cause a significant path explosion, and on each one of them, we do 
this complex equality system reorganization, aggregating constraints, thus 
causing constraint system simplifications down the line.
I'm not sure how to tackle this problem ATM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124758

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


[PATCH] D125788: [flang][driver] Rename `flang-new` as `flang`

2022-05-25 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added a comment.

In D125788#3535199 , @sscalpone wrote:

> My proposal is:
>
> If the compiler compiles it, it ought to run.
> If the compiler can't compile it, it ought to clearly say why.
>
> 1. All tests of legal Fortran that compile & link must also execute correctly 
> (which excludes tests that expect to catch a problem at runtime)
> 2. For all tests with unsupported features, the compiler must issues an error 
> message and the message references the source-location of the unsupported 
> feature
>
> My preference is to use the NAG test suite.   It is not freely available.

I strongly suspect that you might be able to win over some of the folks by 
sharing the status/list of failures/list of issues to be fixed for getting the 
NAG test suite to pass. As I have mentioned before, at least the companies 
involved have access to the NAG testsuite. The community can probably help you 
achieve the outlined goals faster. It can also help focus our efforts.  Some of 
our engineers have now worked with f18/flang for some time. While some issues 
might require a fix by the experts, many can be fixed by others.

A separate issue we have is that it is not clear which branch is it that is 
being used for testing with NAG. Since many fixes have landed in 
llvm-project/flang, I assume that fir-dev is now out of date. While most of 
upstreaming is complete there is still a bit of things left to upstream, should 
not take much time though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125788

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


[PATCH] D126324: [clang] Allow const variables with weak attribute to be overridden

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

In D126324#3536785 , @aaron.ballman 
wrote:

> The changes so far look sensible, but I think we should add some more tests 
> for a few situations. 1) Using a const weak symbol as a valid initializer 
> should be diagnosed (with a warning? with an error?) so users are alerted to 
> the behavioral quirks. 2) Using a const weak symbol in a constant expression 
> context should probably be an error, right? e.g.,

I do think we have already diagnose/fail on all the relevant cases here. And 
have tests for them, like

  extern const int weak_int __attribute__((weak));
  const int weak_int = 42;
  int weak_int_test = weak_int; // expected-error {{not a compile-time 
constant}}

in clang/test/Sema/const-eval.c

But I'll have another look to make sure we have proper coverage.

> Also, this definitely could use a release note so users know about the 
> behavioral change.

Happy to write one, but not sure what it should say.
The "only" change in behavior is that frontend no longer tells backend it is 
allowed to optimize based on initializer value. Frontend behavior is intended 
to be kept exactly the same (it already is restrictive enough).

> Do you have any ideas on how much code this change is expected to break? (Is 
> it sufficient enough that we want to have an explicit deprecation period of 
> the existing behavior before we switch to the new behavior?)

I don't really know much code out there would be affected. As mentioned in the 
discourse thread 
https://discourse.llvm.org/t/weak-attribute-semantics-on-const-variables/62311/7
 I did some grepping in open source projects I could find. This was biased 
towards looking at C code.
I could see two different uses of const+weak:

1. For defining a constant in a header file (which makes that symbol end up in 
many object files, making it weak avoids multiple definition link errors)
2. To define some default configuration/identificationstring which is 
overridden by a strong symbol

There might of course be other uses of weak that I'm not aware of or could find.

But these two cases I want to think are fine with the proposed change:

For 1. we wouldn't alter behavior of code just speed due to optimization being 
prevented. (I think these uses want to use "selectany" attribute instead)

For 2. this change should actually fix a bug where functions in the same 
translation unit that provided the default was using the default rather than 
overridden value.

Here are some examples I found:
In u-boot they do this 
https://source.denx.de/u-boot/u-boot/-/blob/master/common/hwconfig.c#L71 and I 
think (havn't verified) clang/llvm would optimize the `strlen(cpu_hwconfig)` on 
line 103 to `0`. So here I believe this code currently has incorrect behavior 
when compiled with clang.

Arduino for esp does this constant in header 
https://github.com/esp8266/Arduino/blob/master/variants/generic/common.h#L79 so 
that would cause an extra load of the value from memory for everyone blinking 
the LED using the old deprecaded name for that pin.

Here is a c++ example 
https://github.com/ClickHouse/ClickHouse/blob/master/src/Common/Allocator.cpp#L11
 which I think it might not allow overriding the variable with a strong 
definition as intended when compiling with clang.

The case that motivated me to look into this is like:

  const char VERSION[] __attribute__ ((weak))= "devel";
  
  int is_devel_version(void) {
  return !strcmp (VERSION, "devel");
  }

and when "VERSION" gets "weak_odr" linkage "is_devel_version" gets optimized to 
"return 1".  Even if VERSION gets replaced with a strong value later in link 
phase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126324

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


[clang] 6f4644d - [clang] Don't parse MS attributes in `ParseExportDeclaration()`.

2022-05-25 Thread Martin Boehme via cfe-commits

Author: Martin Boehme
Date: 2022-05-25T17:15:41+02:00
New Revision: 6f4644d194da594562027a5d458d9fb7a20ebc39

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

LOG: [clang] Don't parse MS attributes in `ParseExportDeclaration()`.

As @rsmith commented on https://reviews.llvm.org/D111548: "That looks like it's
simply a bug as far as I can tell, and that call can be removed. MS attributes
will be parsed as part of the decl specifier sequence as needed and don't need
to be parsed as declaration attributes."

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/lib/Parse/ParseDeclCXX.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 22ad9e030b0d8..5ed989f17c1bc 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -438,7 +438,6 @@ Decl *Parser::ParseExportDeclaration() {
 // FIXME: Factor out a ParseExternalDeclarationWithAttrs.
 ParsedAttributes Attrs(AttrFactory);
 MaybeParseCXX11Attributes(Attrs);
-MaybeParseMicrosoftAttributes(Attrs);
 ParseExternalDeclaration(Attrs);
 return Actions.ActOnFinishExportDecl(getCurScope(), ExportDecl,
  SourceLocation());
@@ -458,7 +457,6 @@ Decl *Parser::ParseExportDeclaration() {
  Tok.isNot(tok::eof)) {
 ParsedAttributes Attrs(AttrFactory);
 MaybeParseCXX11Attributes(Attrs);
-MaybeParseMicrosoftAttributes(Attrs);
 ParseExternalDeclaration(Attrs);
   }
 



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


[PATCH] D126062: [clang] Don't parse MS attributes in `ParseExportDeclaration()`.

2022-05-25 Thread Martin Böhme via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6f4644d194da: [clang] Don't parse MS attributes in 
`ParseExportDeclaration()`. (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126062

Files:
  clang/lib/Parse/ParseDeclCXX.cpp


Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -438,7 +438,6 @@
 // FIXME: Factor out a ParseExternalDeclarationWithAttrs.
 ParsedAttributes Attrs(AttrFactory);
 MaybeParseCXX11Attributes(Attrs);
-MaybeParseMicrosoftAttributes(Attrs);
 ParseExternalDeclaration(Attrs);
 return Actions.ActOnFinishExportDecl(getCurScope(), ExportDecl,
  SourceLocation());
@@ -458,7 +457,6 @@
  Tok.isNot(tok::eof)) {
 ParsedAttributes Attrs(AttrFactory);
 MaybeParseCXX11Attributes(Attrs);
-MaybeParseMicrosoftAttributes(Attrs);
 ParseExternalDeclaration(Attrs);
   }
 


Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -438,7 +438,6 @@
 // FIXME: Factor out a ParseExternalDeclarationWithAttrs.
 ParsedAttributes Attrs(AttrFactory);
 MaybeParseCXX11Attributes(Attrs);
-MaybeParseMicrosoftAttributes(Attrs);
 ParseExternalDeclaration(Attrs);
 return Actions.ActOnFinishExportDecl(getCurScope(), ExportDecl,
  SourceLocation());
@@ -458,7 +457,6 @@
  Tok.isNot(tok::eof)) {
 ParsedAttributes Attrs(AttrFactory);
 MaybeParseCXX11Attributes(Attrs);
-MaybeParseMicrosoftAttributes(Attrs);
 ParseExternalDeclaration(Attrs);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123235: [OpenMP] atomic compare fail : Parser & AST support

2022-05-25 Thread Kevin Athey via Phabricator via cfe-commits
kda added a comment.

This has broken sanitizer buildbot:
https://lab.llvm.org/buildbot/#/builders/5/builds/24074

Relevant log snippet:

  FAIL: Clang :: OpenMP/atomic_messages.cpp (9696 of 66080)
   TEST 'Clang :: OpenMP/atomic_messages.cpp' FAILED 

  Script:
  --
  : 'RUN: at line 1';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/lib/clang/15.0.0/include 
-nostdsysteminc -verify=expected,omp45 -fopenmp -fopenmp-version=45 
-ferror-limit 150 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/OpenMP/atomic_messages.cpp
 -Wuninitialized
  : 'RUN: at line 2';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/lib/clang/15.0.0/include 
-nostdsysteminc -verify=expected,omp50 -fopenmp -ferror-limit 150 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/OpenMP/atomic_messages.cpp
 -Wuninitialized
  : 'RUN: at line 3';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/lib/clang/15.0.0/include 
-nostdsysteminc -DOMP51 -verify=expected,omp50,omp51 -fopenmp 
-fopenmp-version=51 -ferror-limit 150 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/OpenMP/atomic_messages.cpp
 -Wuninitialized
  : 'RUN: at line 5';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/lib/clang/15.0.0/include 
-nostdsysteminc -verify=expected,omp45 -fopenmp-simd -fopenmp-version=45 
-ferror-limit 150 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/OpenMP/atomic_messages.cpp
 -Wuninitialized
  : 'RUN: at line 6';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/lib/clang/15.0.0/include 
-nostdsysteminc -verify=expected,omp50 -fopenmp-simd -ferror-limit 150 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/OpenMP/atomic_messages.cpp
 -Wuninitialized
  : 'RUN: at line 7';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/lib/clang/15.0.0/include 
-nostdsysteminc -DOMP51 -verify=expected,omp50,omp51 -fopenmp-simd 
-fopenmp-version=51 -ferror-limit 150 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/OpenMP/atomic_messages.cpp
 -Wuninitialized
  --
  Exit Code: 1
  Command Output (stderr):
  --
  ==75693==WARNING: MemorySanitizer: use-of-uninitialized-value
  #0 0x561f8672eb0e in (anonymous 
namespace)::OpenMPAtomicFailChecker::checkSubClause(llvm::ArrayRef,
 clang::SourceLocation*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaOpenMP.cpp:12060:11
  #1 0x561f866ef4bc in 
clang::Sema::ActOnOpenMPAtomicDirective(llvm::ArrayRef, 
clang::Stmt*, clang::SourceLocation, clang::SourceLocation) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaOpenMP.cpp:12634:22
  #2 0x561f866c0775 in 
clang::Sema::ActOnOpenMPExecutableDirective(llvm::omp::Directive, 
clang::DeclarationNameInfo const&, llvm::omp::Directive, 
llvm::ArrayRef, clang::Stmt*, clang::SourceLocation, 
clang::SourceLocation) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaOpenMP.cpp:6168:11
  #3 0x561f856da291 in 
clang::Parser::ParseOpenMPDeclarativeOrExecutableDirective(clang::Parser::ParsedStmtContext,
 bool) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseOpenMP.cpp:2922:25
  #4 0x561f8553b46f in 
clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, 
clang::ParsedAttributes&) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseStmt.cpp:413:12
  #5 0x561f85537f27 in 
clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseStmt.cpp:113:20
  #6 0x561f85551be1 in clang::Parser::ParseCompoundStatementBody(bool) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseStmt.cpp::11
  #7 0x561f85554cfd in 
clang::Parser::ParseFunctionStatementBody(clang::Decl*, 
clang::Parser::ParseScope&) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseStmt.cpp:2379:21
  #8 0x561f854cfa8e in 
clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, 
clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/Parser.cpp:1407:10
  #9 0x561f855bbc3e in 
clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, 
clang::DeclaratorContext, clang::SourceLocat

[PATCH] D125904: [Cuda] Use fallback method to mangle externalized decls if no CUID given

2022-05-25 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

Also, for the OpenMP case, we already pass the host-IR as a dependency for the 
device compilation. So it would be relatively easy for us to just generate 
these names on the host and then read them from the IR for the device. The 
problem is that CUDA / HIP doesn't use this approach so it wouldn't be a great 
solution to have two different ways to do this. So we would either need to make 
CUDA / HIP take the host IR and use that, or move OpenMP to use the driver. The 
benefit of passing the IR is that we can much more stably generate some 
arbitrary string to mangle these names and we're guarunteed to have them match 
up because we read them from the host. The downside is that it'd be somewhat of 
a regression because now we have an extra call to Clang for CUDA / HIP when we 
previously didn't need to.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125904

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


[PATCH] D126158: [MLIR][GPU] Replace fdiv on fp16 with promoted (fp32) multiplication with reciprocal plus one (conditional) Newton iteration.

2022-05-25 Thread Stephan Herhut via Phabricator via cfe-commits
herhut added inline comments.



Comment at: mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp:158
+// by the same divisor.
+struct ExpandDivF16 : public ConvertOpToLLVMPattern {
+  using ConvertOpToLLVMPattern::ConvertOpToLLVMPattern;

This pattern is a bit misplaced here, as `LLVM::FDivOp` is not really a GPU 
dialect operation. Instead, should this be a special lowering of the arith 
dialect to NVVM (which we do not have yet) or a rewrite at the LLVM dialect 
level?

When lowering to LLVM, we already typically configure a different lowering for 
math dialect, so configuring the lowering of arith dialect differently seems 
like an OK option. That would mean a specialized pattern for `arith.divf` with 
higher priority. That would also give users a choice.



Comment at: mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp:304
 
+  patterns.add(converter);
+

I assume this is to differentiate this pattern somehow but there is no need for 
an extra `patterns.add` here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126158

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


[PATCH] D124525: [OpenMP][ClangLinkerWrapper] Extending linker wrapper to embed metadata for multi-arch fat binaries

2022-05-25 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

Where is the code to change the target registration? We need a new 
initialization runtime call to use and change the old one to reallocate the 
`__tgt_device_image` array. Did you work around that some other way?




Comment at: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp:613-614
   CmdArgs.push_back("-shared");
+  std::string ArchArg = std::string("-plugin-opt=mcpu=").append(Arch.str());
+  CmdArgs.push_back(ArchArg);
   CmdArgs.push_back("-o");

Does this just pass the architecture to the AMD link? Is this related? If not 
move it to a separate patch and I'll review it.



Comment at: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp:1069
 bool WholeProgram = false;
+std::string TheArch = File.Arch;
 

Is this necessary?



Comment at: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp:1153
   SmallVector, 4> ImagesToWrap;
+  SmallVector, 4> OffloadArchs;
+  std::string Arch;

This should be a StringRef, the data is stable. When you create the struct just 
use this and it will add the null terminator for you.
```
Constant *ConstantStr = ConstantDataArray::getString(M.getContext(), Str);
```



Comment at: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp:1165
+
+if (Arch.empty()) {
+  Arch = std::string(File.Arch);

An empty `StringRef` should already create a null string when you create a 
ConstantDataArray, should be fine to just push it back.



Comment at: clang/tools/clang-linker-wrapper/OffloadWrapper.cpp:62-63
+//   int32_t version;
+//   int32_t image_number;
+//   int32_t number_images;
+//   char* offload_arch;

The struct should be contained within the image itself so we can query it 
during registration, why do we need to know the number?



Comment at: clang/tools/clang-linker-wrapper/OffloadWrapper.cpp:64-65
+//   int32_t number_images;
+//   char* offload_arch;
+//   char* target_compile_opts;
+// };





Comment at: clang/tools/clang-linker-wrapper/OffloadWrapper.cpp:191-194
+  auto *NullPtr = llvm::ConstantPointerNull::get(Type::getInt8PtrTy(C));
+  unsigned int ImgCount = 0;
+  std::string OffloadArchBase = "__offload_arch";
+  std::string OffloadImageBase = "offload_image_info";

You should be able to pass the name to the constructor, if it's internal LLVM 
will give you a new name.



Comment at: clang/tools/clang-linker-wrapper/OffloadWrapper.cpp:214
 
-ImagesInits.push_back(ConstantStruct::get(getDeviceImageTy(M), ImageB,
-  ImageE, EntriesB, EntriesE));
+auto OArch = OffloadArchs[ImgCount];
+Constant *OArchV = ConstantDataArray::get(C, OArch);

I would just assert that the metadata vector's size matches the number of 
images, we're always going to generate these now so it makes sense to generate 
them in pairs. Then just use `llvm::zip` or just an iterator to go through both 
of these at the same time.



Comment at: clang/tools/clang-linker-wrapper/OffloadWrapper.cpp:215-227
+Constant *OArchV = ConstantDataArray::get(C, OArch);
+std::string OffloadArchGV(OffloadArchBase),
+OffloadImageGV(OffloadImageBase);
+if (ImgCount) {
+  auto Suffix = std::to_string(ImgCount);
+  OffloadArchGV.append(".").append(Suffix);
+  OffloadImageGV.append(".").append(Suffix);

Why do we need all these strings? Should just be generating a constant 
initializer.



Comment at: clang/tools/clang-linker-wrapper/OffloadWrapper.cpp:229-232
+// store value of these variables (i.e. offload archs) into a custom
+// section which will be used by "offload-arch -f". It won't be
+// removed during binary stripping.
+GV->setSection(".offload_arch_list");

Why does this need a custom section? We should just use it like this, not sure 
why we need these to  be anything but some internal struct.
```
for (auto *Image : BinDesc->Images) {
  if (Image->Info)
   // Use Info
}
```



Comment at: clang/tools/clang-linker-wrapper/OffloadWrapper.cpp:240-241
+getImageInfoTy(M), ConstantInt::get(Type::getInt32Ty(C), 1),
+ConstantInt::get(Type::getInt32Ty(C), ImgCount++),
+ConstantInt::get(Type::getInt32Ty(C), (uint32_t)OffloadArchs.size()),
+RequirementVPtr,

Why do we need this when we should already know which image we're looking at?



Comment at: openmp/libomptarget/include/omptarget.h:122
 
+/// __tgt_image_info:
+///

This comment is extremely long. It should be sufficient to just say what it 
does, 3 lines max. Specify that it may be null in the device image struct.



Comment at: openmp/libomptarget/include/omptarget.h:145-1

[PATCH] D125547: [analyzer][solver] Handle UnarySymExpr in SMTConv

2022-05-25 Thread Gabor Marton via Phabricator via cfe-commits
martong marked an inline comment as done.
martong added inline comments.



Comment at: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h:463
+  // has a different type than the unary itself.
+  if (OperandTy != Sym->getType()) {
+if (hasComparison)

steakhal wrote:
> Could this fail spuriously due to a constness mismatch, since you compare 
> QualTypes instead of types?
> What happens if one of these refers to typedef? 
> Shouldn't we compare the canonical type pointers instead? Or this works out 
> just fine in practice. I might over-worry this :D
> 
> ALternatively, we could emit this cast only if the bitwidths are different. 
> (which caused the sort difference, thus the crash)
> Could this fail spuriously due to a constness mismatch, since you compare 
> QualTypes instead of types?
No, I don't think so. The underlying `fromCast` would simply return the same 
`SMTExprRef` if the bitwidths are the same.

> What happens if one of these refers to typedef? 
The same as in case of the qualifier mismatch.

> Shouldn't we compare the canonical type pointers instead? Or this works out 
> just fine in practice. I might over-worry this :D
> 
> ALternatively, we could emit this cast only if the bitwidths are different. 
> (which caused the sort difference, thus the crash)
Good point. The code would be more direct and efficient like that, I am going 
to update.




Comment at: clang/test/Analysis/unary-sym-expr-z3-refutation.c:28
+void k(long L) {
+  int g = L;
+  int h = g + 1;

steakhal wrote:
> So this is the implicit cast that we don't emit.
Yes.


Actually, without emitting SymbolCasts: `h` is evaluated as `$L + 1`. 
However, the expression's type is `int`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125547

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


[PATCH] D125547: [analyzer][solver] Handle UnarySymExpr in SMTConv

2022-05-25 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 432019.
martong marked an inline comment as done.
martong added a comment.

- Compare the size of the types instead of the type pointers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125547

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h
  clang/test/Analysis/unary-sym-expr-z3-refutation.c
  clang/test/Analysis/z3-crosscheck.c


Index: clang/test/Analysis/z3-crosscheck.c
===
--- clang/test/Analysis/z3-crosscheck.c
+++ clang/test/Analysis/z3-crosscheck.c
@@ -14,6 +14,20 @@
   return 0;
 }
 
+int unary(int x, long l)
+{
+  int *z = 0;
+  int y = l;
+  if ((x & 1) && ((x & 1) ^ 1))
+if (-y)
+#ifdef NO_CROSSCHECK
+return *z; // expected-warning {{Dereference of null pointer (loaded 
from variable 'z')}}
+#else
+return *z; // no-warning
+#endif
+  return 0;
+}
+
 void g(int d);
 
 void f(int *a, int *b) {
Index: clang/test/Analysis/unary-sym-expr-z3-refutation.c
===
--- /dev/null
+++ clang/test/Analysis/unary-sym-expr-z3-refutation.c
@@ -0,0 +1,33 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=true \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=true \
+// RUN:   -analyzer-config support-symbolic-integer-casts=true \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=true \
+// RUN:   -analyzer-config crosscheck-with-z3=true \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=true \
+// RUN:   -analyzer-config crosscheck-with-z3=true \
+// RUN:   -analyzer-config support-symbolic-integer-casts=true \
+// RUN:   -verify
+
+// REQUIRES: z3
+
+void k(long L) {
+  int g = L;
+  int h = g + 1;
+  int j;
+  j += -h < 0; // should not crash
+  // expected-warning@-1{{garbage}}
+}
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h
@@ -446,6 +446,28 @@
   return getCastExpr(Solver, Ctx, Exp, FromTy, Sym->getType());
 }
 
+if (const UnarySymExpr *USE = dyn_cast(Sym)) {
+  if (RetTy)
+*RetTy = Sym->getType();
+
+  QualType OperandTy;
+  llvm::SMTExprRef OperandExp =
+  getSymExpr(Solver, Ctx, USE->getOperand(), &OperandTy, 
hasComparison);
+  llvm::SMTExprRef UnaryExp =
+  fromUnOp(Solver, USE->getOpcode(), OperandExp);
+
+  // Currently, without the `support-symbolic-integer-casts=true` option,
+  // we do not emit `SymbolCast`s for implicit casts.
+  // One such implicit cast is missing if the operand of the unary operator
+  // has a different type than the unary itself.
+  if (Ctx.getTypeSize(OperandTy) != Ctx.getTypeSize(Sym->getType())) {
+if (hasComparison)
+  *hasComparison = false;
+return getCastExpr(Solver, Ctx, UnaryExp, OperandTy, Sym->getType());
+  }
+  return UnaryExp;
+}
+
 if (const BinarySymExpr *BSE = dyn_cast(Sym)) {
   llvm::SMTExprRef Exp =
   getSymBinExpr(Solver, Ctx, BSE, hasComparison, RetTy);


Index: clang/test/Analysis/z3-crosscheck.c
===
--- clang/test/Analysis/z3-crosscheck.c
+++ clang/test/Analysis/z3-crosscheck.c
@@ -14,6 +14,20 @@
   return 0;
 }
 
+int unary(int x, long l)
+{
+  int *z = 0;
+  int y = l;
+  if ((x & 1) && ((x & 1) ^ 1))
+if (-y)
+#ifdef NO_CROSSCHECK
+return *z; // expected-warning {{Dereference of null pointer (loaded from variable 'z')}}
+#else
+return *z; // no-warning
+#endif
+  return 0;
+}
+
 void g(int d);
 
 void f(int *a, int *b) {
Index: clang/test/Analysis/unary-sym-expr-z3-refutation.c
===
--- /dev/null
+++ clang/test/Analysis/unary-sym-expr-z3-refutation.c
@@ -0,0 +1,33 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=true \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=true \
+// RUN:   -analyzer-config support-symbolic-integer-casts=true \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-ass

[PATCH] D126324: [clang] Allow const variables with weak attribute to be overridden

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

In D126324#3537282 , @jyknight wrote:

> In D126324#3536785 , @aaron.ballman 
> wrote:
>
>> The changes so far look sensible, but I think we should add some more tests 
>> for a few situations. 1) Using a const weak symbol as a valid initializer 
>> should be diagnosed (with a warning? with an error?) so users are alerted to 
>> the behavioral quirks.
>
> I don't feel this is really necessary.

Why?

My thinking is: it's invalid to initialize a file scope variable in C from 
something other than a constant expression. These are not constant expressions. 
Why should the initialization work silently and maybe do something wrong?

>> 2. Using a const weak symbol in a constant expression context should 
>> probably be an error, right? e.g.,
>
> That's already the case (except, using a VLA is not an error in either 
> language mode). Clang previously _only_ treated weak symbols as 
> compile-time-known in the backend; the frontend has treated it as an 
> non-constant-evaluable variable for ages, and that behavior is unchanged by 
> this patch.

Ah, okay, then it sounds like we already have the behavior I was hoping for, 
great.

>> Also, this definitely could use a release note so users know about the 
>> behavioral change.
>>
>> Do you have any ideas on how much code this change is expected to break? (Is 
>> it sufficient enough that we want to have an explicit deprecation period of 
>> the existing behavior before we switch to the new behavior?)
>
> Because it's only changing the optimizer behavior not the frontend constant 
> evaluator, I think it's pretty safe (which is also why I'm OK with it).

+1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126324

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


[PATCH] D125291: Introduce @llvm.threadlocal.address intrinsic to access TLS variable (1/3)

2022-05-25 Thread Wenlei He via Phabricator via cfe-commits
wenlei added a subscriber: weiwang.
wenlei added a comment.

+@weiwang


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

https://reviews.llvm.org/D125291

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


[PATCH] D124753: [HLSL] Set main as default entry.

2022-05-25 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 432023.
python3kgae added a comment.

Update comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124753

Files:
  clang/lib/Driver/ToolChains/HLSL.cpp
  clang/test/CodeGenHLSL/entry_default.hlsl


Index: clang/test/CodeGenHLSL/entry_default.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/entry_default.hlsl
@@ -0,0 +1,10 @@
+// RUN: %clang --driver-mode=dxc -Tcs_6_1 -fcgl -Fo - %s | FileCheck %s
+
+// Make sure main is default entry.
+// Make sure not mangle entry.
+// CHECK:define void @main()
+// Make sure add function attribute.
+// CHECK:"dx.shader"="compute"
+[numthreads(1, 1, 1)] void main() {
+
+}
Index: clang/lib/Driver/ToolChains/HLSL.cpp
===
--- clang/lib/Driver/ToolChains/HLSL.cpp
+++ clang/lib/Driver/ToolChains/HLSL.cpp
@@ -188,5 +188,11 @@
 Opts.getOption(options::OPT_dxil_validator_version),
 DefaultValidatorVer);
   }
+  // If entry is not set explicitly, default is main.
+  if (!DAL->hasArg(options::OPT_hlsl_entrypoint)) {
+const StringRef DefaultEntry = "main";
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_hlsl_entrypoint),
+DefaultEntry);
+  }
   return DAL;
 }


Index: clang/test/CodeGenHLSL/entry_default.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/entry_default.hlsl
@@ -0,0 +1,10 @@
+// RUN: %clang --driver-mode=dxc -Tcs_6_1 -fcgl -Fo - %s | FileCheck %s
+
+// Make sure main is default entry.
+// Make sure not mangle entry.
+// CHECK:define void @main()
+// Make sure add function attribute.
+// CHECK:"dx.shader"="compute"
+[numthreads(1, 1, 1)] void main() {
+
+}
Index: clang/lib/Driver/ToolChains/HLSL.cpp
===
--- clang/lib/Driver/ToolChains/HLSL.cpp
+++ clang/lib/Driver/ToolChains/HLSL.cpp
@@ -188,5 +188,11 @@
 Opts.getOption(options::OPT_dxil_validator_version),
 DefaultValidatorVer);
   }
+  // If entry is not set explicitly, default is main.
+  if (!DAL->hasArg(options::OPT_hlsl_entrypoint)) {
+const StringRef DefaultEntry = "main";
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_hlsl_entrypoint),
+DefaultEntry);
+  }
   return DAL;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126324: [clang] Allow const variables with weak attribute to be overridden

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

In D126324#3537373 , @wanders wrote:

> In D126324#3536785 , @aaron.ballman 
> wrote:
>
>> The changes so far look sensible, but I think we should add some more tests 
>> for a few situations. 1) Using a const weak symbol as a valid initializer 
>> should be diagnosed (with a warning? with an error?) so users are alerted to 
>> the behavioral quirks. 2) Using a const weak symbol in a constant expression 
>> context should probably be an error, right? e.g.,
>
> I do think we have already diagnose/fail on all the relevant cases here. And 
> have tests for them, like
>
>   extern const int weak_int __attribute__((weak));
>   const int weak_int = 42;
>   int weak_int_test = weak_int; // expected-error {{not a compile-time 
> constant}}
>
> in clang/test/Sema/const-eval.c
>
> But I'll have another look to make sure we have proper coverage.

Thanks for double-checking it -- if we've got reasonable coverage, then that's 
great (nothing else needs to happen).

>> Also, this definitely could use a release note so users know about the 
>> behavioral change.
>
> Happy to write one, but not sure what it should say.
> The "only" change in behavior is that frontend no longer tells backend it is 
> allowed to optimize based on initializer value. Frontend behavior is intended 
> to be kept exactly the same (it already is restrictive enough).

I thought this was more disruptive than it actually is, so I feel less 
strongly. But if you wanted to add one, I'd put it under the `Attribute Changes 
in Clang` heading and something along the lines of what you just wrote about 
the backend no longer being allowed to optimize in some circumstances.

>> Do you have any ideas on how much code this change is expected to break? (Is 
>> it sufficient enough that we want to have an explicit deprecation period of 
>> the existing behavior before we switch to the new behavior?)
>
> I don't really know much code out there would be affected. As mentioned in 
> the discourse thread 
> https://discourse.llvm.org/t/weak-attribute-semantics-on-const-variables/62311/7
>  I did some grepping in open source projects I could find. This was biased 
> towards looking at C code.
> I could see two different uses of const+weak:
>
> 1. For defining a constant in a header file (which makes that symbol end up 
> in many object files, making it weak avoids multiple definition link errors)
> 2. To define some default configuration/identificationstring which is 
> overridden by a strong symbol
>
> There might of course be other uses of weak that I'm not aware of or could 
> find.
>
> But these two cases I want to think are fine with the proposed change:
>
> For 1. we wouldn't alter behavior of code just speed due to optimization 
> being prevented. (I think these uses want to use "selectany" attribute 
> instead)
>
> For 2. this change should actually fix a bug where functions in the same 
> translation unit that provided the default was using the default rather than 
> overridden value.
>
> Here are some examples I found:
> In u-boot they do this 
> https://source.denx.de/u-boot/u-boot/-/blob/master/common/hwconfig.c#L71 and 
> I think (havn't verified) clang/llvm would optimize the 
> `strlen(cpu_hwconfig)` on line 103 to `0`. So here I believe this code 
> currently has incorrect behavior when compiled with clang.
>
> Arduino for esp does this constant in header 
> https://github.com/esp8266/Arduino/blob/master/variants/generic/common.h#L79 
> so that would cause an extra load of the value from memory for everyone 
> blinking the LED using the old deprecaded name for that pin.
>
> Here is a c++ example 
> https://github.com/ClickHouse/ClickHouse/blob/master/src/Common/Allocator.cpp#L11
>  which I think it might not allow overriding the variable with a strong 
> definition as intended when compiling with clang.
>
> The case that motivated me to look into this is like:
>
>   const char VERSION[] __attribute__ ((weak))= "devel";
>   
>   int is_devel_version(void) {
>   return !strcmp (VERSION, "devel");
>   }
>
> and when "VERSION" gets "weak_odr" linkage "is_devel_version" gets optimized 
> to "return 1".  Even if VERSION gets replaced with a strong value later in 
> link phase.

Excellent, thank you!

I am comfortable moving forward with this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126324

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


[PATCH] D125814: Improve the strict prototype diagnostic behavior

2022-05-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 432020.
aaron.ballman added a comment.

Update based on review feedback.


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

https://reviews.llvm.org/D125814

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/C/drs/dr0xx.c
  clang/test/CodeGen/2009-06-01-addrofknr.c
  clang/test/Parser/declarators.c
  clang/test/Sema/arg-duplicate.c
  clang/test/Sema/knr-def-call.c
  clang/test/Sema/knr-variadic-def.c
  clang/test/Sema/warn-deprecated-non-prototype.c
  clang/test/Sema/warn-strict-prototypes.c

Index: clang/test/Sema/warn-strict-prototypes.c
===
--- clang/test/Sema/warn-strict-prototypes.c
+++ clang/test/Sema/warn-strict-prototypes.c
@@ -48,7 +48,7 @@
 }
 
 // K&R function definition not preceded by full prototype
-int foo9(a, b) // expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x}}
+int foo9(a, b) // expected-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C2x}}
   int a, b;
 {
   return a + b;
@@ -56,17 +56,17 @@
 
 // Function declaration with no types
 void foo10(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}} \
- expected-note {{a function declaration without a prototype is not supported in C2x}}
+ expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C2x, conflicting with a subsequent definition}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"void"
 // K&R function definition with incomplete param list declared
-void foo10(p, p2) void *p; {} // expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x}} \
+void foo10(p, p2) void *p; {} // expected-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C2x}} \
  expected-warning {{parameter 'p2' was not declared, defaults to 'int'; ISO C99 and later do not support implicit int}}
 
 void foo11(int p, int p2);
-void foo11(p, p2) int p; int p2; {} // expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x}}
+void foo11(p, p2) int p; int p2; {} // expected-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C2x}}
 
 // PR31020
-void __attribute__((cdecl)) foo12(d) // expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x}}
+void __attribute__((cdecl)) foo12(d) // expected-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C2x}}
   short d;
 {}
 
Index: clang/test/Sema/warn-deprecated-non-prototype.c
===
--- clang/test/Sema/warn-deprecated-non-prototype.c
+++ clang/test/Sema/warn-deprecated-non-prototype.c
@@ -23,15 +23,14 @@
 void again() {} // strict-warning {{a function declaration without a prototype is deprecated in all versions of C}}
 
 // On by default warnings
-void func(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x}} \
-strict-warning {{a function declaration without a prototype is deprecated in all versions of C}} \
-strict-note {{a function declaration without a prototype is not supported in C2x}}
-void func(a, b) int a, b; {} // both-warning {{a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x}}
+void func(); // both-warning {{a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C2x, conflicting with a subsequent definition}} \
+strict-warning {{a function declaration without a prototype is deprecated in all versions of C}}
+void func(a, b) int a, b; {} // both-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C2x}}
 
-void one_more(a, b) int a, b; {} // both-warning {{a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x}}
+void one_more(a, b) int a, b; {} // both-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C2x}}
 
 void sheesh(int a);
-void sheesh(a) int a; {} // both-warning {{a function declaration without a prototype is deprecated in all versions o

[PATCH] D125814: Improve the strict prototype diagnostic behavior

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

In D125814#3535452 , @jyknight wrote:

> Good improvement, but an additional change to wording for just the zero-arg 
> non-prototype function declaration case could help a lot. The fact that 
> zero-arg it's only being warned about because of the "...because of" note 
> isn't particularly clear -- especially when the "because of" isn't emitted.
>
> So, suggestion for zero-arg-specific warning text:

Thanks for the suggestion! I've implemented something along these lines in this 
patch and I think the diagnostics are better this way.


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

https://reviews.llvm.org/D125814

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


[PATCH] D123235: [OpenMP] atomic compare fail : Parser & AST support

2022-05-25 Thread Sunil K via Phabricator via cfe-commits
koops added subscribers: cchen, dreachem, tianshilei1992, jdoerfert, soumitra.
koops added a comment.

Hello Kevin,

I am not sure why it is indicating an uninitialized variable at that point. The 
code at " llvm-project/clang/lib/Sema/SemaOpenMP.cpp:12060 " is as below:

  for (const OMPClause *C : Clauses) {
if (C->getClauseKind() == OMPC_fail) {
  NoOfFails++;
  const OMPFailClause *FC = static_cast(C);
  const OMPClause *MemOrderC = FC->const_getMemoryOrderClause();
  /* Clauses contains OMPC_fail and the subclause */
  if (MemOrderC) {

Here " if (MemOrderC) { " is the 12060 line.

Regards,
--Sunil


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123235

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


[PATCH] D125667: [pseudo] A basic implementation of compiling cxx grammar at build time.

2022-05-25 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

This breaks cross-compilation, because we're building `pseudo-gen` for the 
target but then trying to run it on the build machine. You'll need to do 
something like TableGen does (see 
https://github.com/llvm/llvm-project/blob/main/llvm/cmake/modules/CrossCompile.cmake
 and the uses of `build_native_tool`). That being said, I'm trying to figure 
out why our builds are attempting to build this in the first place, since as 
far as I can tell nothing external depends on it yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125667

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


[PATCH] D123235: [OpenMP] atomic compare fail : Parser & AST support

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

In D123235#3537580 , @koops wrote:

> I am not sure why it is indicating an uninitialized variable at that point. 
> The code at " llvm-project/clang/lib/Sema/SemaOpenMP.cpp:12060 " is as below:

FWIW, it's outright crashing for me on Windows.

  FAIL: Clang :: OpenMP/atomic_messages.cpp (255 of 15035)
   TEST 'Clang :: OpenMP/atomic_messages.cpp' FAILED 

  Script:
  --
  : 'RUN: at line 1';   
f:\source\llvm-project\llvm\out\build\x64-debug\bin\clang.exe -cc1 
-internal-isystem 
f:\source\llvm-project\llvm\out\build\x64-debug\lib\clang\15.0.0\include 
-nostdsysteminc -verify=expected,omp45 -fopenmp -fopenmp-version=45 
-ferror-limit 150 F:\source\llvm-project\clang\test\OpenMP\atomic_messages.cpp 
-Wuninitialized
  : 'RUN: at line 2';   
f:\source\llvm-project\llvm\out\build\x64-debug\bin\clang.exe -cc1 
-internal-isystem 
f:\source\llvm-project\llvm\out\build\x64-debug\lib\clang\15.0.0\include 
-nostdsysteminc -verify=expected,omp50 -fopenmp -ferror-limit 150 
F:\source\llvm-project\clang\test\OpenMP\atomic_messages.cpp -Wuninitialized
  : 'RUN: at line 3';   
f:\source\llvm-project\llvm\out\build\x64-debug\bin\clang.exe -cc1 
-internal-isystem 
f:\source\llvm-project\llvm\out\build\x64-debug\lib\clang\15.0.0\include 
-nostdsysteminc -DOMP51 -verify=expected,omp50,omp51 -fopenmp 
-fopenmp-version=51 -ferror-limit 150 
F:\source\llvm-project\clang\test\OpenMP\atomic_messages.cpp -Wuninitialized
  : 'RUN: at line 5';   
f:\source\llvm-project\llvm\out\build\x64-debug\bin\clang.exe -cc1 
-internal-isystem 
f:\source\llvm-project\llvm\out\build\x64-debug\lib\clang\15.0.0\include 
-nostdsysteminc -verify=expected,omp45 -fopenmp-simd -fopenmp-version=45 
-ferror-limit 150 F:\source\llvm-project\clang\test\OpenMP\atomic_messages.cpp 
-Wuninitialized
  : 'RUN: at line 6';   
f:\source\llvm-project\llvm\out\build\x64-debug\bin\clang.exe -cc1 
-internal-isystem 
f:\source\llvm-project\llvm\out\build\x64-debug\lib\clang\15.0.0\include 
-nostdsysteminc -verify=expected,omp50 -fopenmp-simd -ferror-limit 150 
F:\source\llvm-project\clang\test\OpenMP\atomic_messages.cpp -Wuninitialized
  : 'RUN: at line 7';   
f:\source\llvm-project\llvm\out\build\x64-debug\bin\clang.exe -cc1 
-internal-isystem 
f:\source\llvm-project\llvm\out\build\x64-debug\lib\clang\15.0.0\include 
-nostdsysteminc -DOMP51 -verify=expected,omp50,omp51 -fopenmp-simd 
-fopenmp-version=51 -ferror-limit 150 
F:\source\llvm-project\clang\test\OpenMP\atomic_messages.cpp -Wuninitialized
  --
  Exit Code: 3221225477
  
  Command Output (stdout):
  --
  $ ":" "RUN: at line 1"
  $ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\clang.exe" "-cc1" 
"-internal-isystem" 
"f:\source\llvm-project\llvm\out\build\x64-debug\lib\clang\15.0.0\include" 
"-nostdsysteminc" "-verify=expected,omp45" "-fopenmp" "-fopenmp-version=45" 
"-ferror-limit" "150" 
"F:\source\llvm-project\clang\test\OpenMP\atomic_messages.cpp" "-Wuninitialized"
  $ ":" "RUN: at line 2"
  $ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\clang.exe" "-cc1" 
"-internal-isystem" 
"f:\source\llvm-project\llvm\out\build\x64-debug\lib\clang\15.0.0\include" 
"-nostdsysteminc" "-verify=expected,omp50" "-fopenmp" "-ferror-limit" "150" 
"F:\source\llvm-project\clang\test\OpenMP\atomic_messages.cpp" "-Wuninitialized"
  $ ":" "RUN: at line 3"
  $ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\clang.exe" "-cc1" 
"-internal-isystem" 
"f:\source\llvm-project\llvm\out\build\x64-debug\lib\clang\15.0.0\include" 
"-nostdsysteminc" "-DOMP51" "-verify=expected,omp50,omp51" "-fopenmp" 
"-fopenmp-version=51" "-ferror-limit" "150" 
"F:\source\llvm-project\clang\test\OpenMP\atomic_messages.cpp" "-Wuninitialized"
  # command stderr:
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
and include the crash backtrace, preprocessed source, and associated run script.
  Stack dump:
  0.  Program arguments: 
f:\\source\\llvm-project\\llvm\\out\\build\\x64-debug\\bin\\clang.exe -cc1 
-internal-isystem 
f:\\source\\llvm-project\\llvm\\out\\build\\x64-debug\\lib\\clang\\15.0.0\\include
 -nostdsysteminc -DOMP51 -verify=expected,omp50,omp51 -fopenmp 
-fopenmp-version=51 -ferror-limit 150 
F:\\source\\llvm-project\\clang\\test\\OpenMP\\atomic_messages.cpp 
-Wuninitialized
  1.  F:\source\llvm-project\clang\test\OpenMP\atomic_messages.cpp:968:1: 
at annotation token
  2.  F:\source\llvm-project\clang\test\OpenMP\atomic_messages.cpp:930:13: 
parsing function body 'mixed'
  3.  F:\source\llvm-project\clang\test\OpenMP\atomic_messages.cpp:930:13: 
in compound statement ('{}')
   #0 0x7ff61281a32b clang::OMPClause::getClauseKind(void) const 
F:\source\llvm-project\clang\include\clang\AST\OpenMPClause.h:83:0
   #1 0x7ff617bcf805 `anonymous 
namespace'::OpenMPAtomicFailChecker::checkSubClause 
F:\source\llvm-project\clang\lib\Sema\SemaOpenMP.cpp:12061:0
   #2 0x7ff6

[PATCH] D125667: [pseudo] A basic implementation of compiling cxx grammar at build time.

2022-05-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

I'll see if I can fix it quickly, else will revert (there are a couple of fixes 
stacked on top already, so revert isn't quite clean)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125667

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


[PATCH] D126341: Order implicitly instantiated global variable's initializer by the reverse instantiation order

2022-05-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: clang-language-wg.
aaron.ballman added a comment.

Adding the language WG as a reviewer in case others have opinions.

> The underlying problem is basically wg21.link/cwg362 which has no concensus 
> yet.

According to https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#362 
this was resolved in CD1 and we track it as being not applicable to us 
(https://clang.llvm.org/cxx_dr_status.html#362). (Is our status actually 
correct for this?)

> Will the reviewers be supportive if I make the original cwg362 test case work 
> too?

To me, it depends on what it does to compile times and memory overhead for the 
compiler when run on large projects. If the extra tracking is cheap and doesn't 
really impact anything, I think it's reasonable to want to match GCC's 
behavior. If it turns out this is expensive, I'm less keen on matching GCC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126341

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


[PATCH] D125667: [pseudo] A basic implementation of compiling cxx grammar at build time.

2022-05-25 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

In D125667#3537655 , @sammccall wrote:

> I'll see if I can fix it quickly, else will revert (there are a couple of 
> fixes stacked on top already, so revert isn't quite clean)

Thank you! I'll have some time to look at this a bit later myself as well, and 
it should hopefully be a quick fix, so we can try to avoid the revert :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125667

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


[PATCH] D126170: C++ DR2394: Const-default-constructible for members.

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

LGTM (minor nit with release notes, take it or leave it at your discretion).




Comment at: clang/docs/ReleaseNotes.rst:155
   This fixes Issue `Issue 54881 
`_.
+- Fix `CWG 2394 `_: Const class members may
+  be initialized with a defaulted default constructor under the same




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126170

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


[PATCH] D126397: [pseudo] Fix pseudo-gen usage when cross-compiling

2022-05-25 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai created this revision.
smeenai added reviewers: hokein, sammccall.
Herald added a subscriber: mgorny.
Herald added a project: All.
smeenai requested review of this revision.
Herald added subscribers: cfe-commits, alextsao1999.
Herald added a project: clang-tools-extra.

Use the LLVM build system's cross-compilation support for the tool, so
that the build works for both host and cross-compilation scenarios.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126397

Files:
  clang-tools-extra/pseudo/include/CMakeLists.txt


Index: clang-tools-extra/pseudo/include/CMakeLists.txt
===
--- clang-tools-extra/pseudo/include/CMakeLists.txt
+++ clang-tools-extra/pseudo/include/CMakeLists.txt
@@ -1,25 +1,35 @@
 # The cxx.bnf grammar file
 set(cxx_bnf ${CMAKE_CURRENT_SOURCE_DIR}/../lib/cxx.bnf)
 
+# Using CMAKE_CROSSCOMPILING and not LLVM_USE_HOST_TOOLS because the latter is
+# also set for LLVM_OPTIMIZED_TABLEGEN, which we don't care about here.
+if(CMAKE_CROSSCOMPILING)
+  build_native_tool(pseudo-gen pseudo_gen)
+  set(pseudo_gen_target "${pseudo_gen}")
+else()
+  set(pseudo_gen $)
+  set(pseudo_gen_target pseudo-gen)
+endif()
+
 # Generate inc files.
 set(cxx_symbols_inc ${CMAKE_CURRENT_BINARY_DIR}/CXXSymbols.inc)
 add_custom_command(OUTPUT ${cxx_symbols_inc}
-   COMMAND "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/pseudo-gen"
+   COMMAND "${pseudo_gen}"
  --grammar ${cxx_bnf}
  --emit-symbol-list
  -o ${cxx_symbols_inc}
COMMENT "Generating nonterminal symbol file for cxx grammar..."
-   DEPENDS pseudo-gen
+   DEPENDS ${pseudo_gen_target}
VERBATIM)
 
 set(cxx_bnf_inc ${CMAKE_CURRENT_BINARY_DIR}/CXXBNF.inc)
 add_custom_command(OUTPUT ${cxx_bnf_inc}
-   COMMAND "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/pseudo-gen"
+   COMMAND "${pseudo_gen}"
  --grammar ${cxx_bnf}
  --emit-grammar-content
  -o ${cxx_bnf_inc}
COMMENT "Generating bnf string file for cxx grammar..."
-   DEPENDS pseudo-gen
+   DEPENDS ${pseudo_gen_target}
VERBATIM)
 
 # add_custom_command does not create a new target, we need to deine a target


Index: clang-tools-extra/pseudo/include/CMakeLists.txt
===
--- clang-tools-extra/pseudo/include/CMakeLists.txt
+++ clang-tools-extra/pseudo/include/CMakeLists.txt
@@ -1,25 +1,35 @@
 # The cxx.bnf grammar file
 set(cxx_bnf ${CMAKE_CURRENT_SOURCE_DIR}/../lib/cxx.bnf)
 
+# Using CMAKE_CROSSCOMPILING and not LLVM_USE_HOST_TOOLS because the latter is
+# also set for LLVM_OPTIMIZED_TABLEGEN, which we don't care about here.
+if(CMAKE_CROSSCOMPILING)
+  build_native_tool(pseudo-gen pseudo_gen)
+  set(pseudo_gen_target "${pseudo_gen}")
+else()
+  set(pseudo_gen $)
+  set(pseudo_gen_target pseudo-gen)
+endif()
+
 # Generate inc files.
 set(cxx_symbols_inc ${CMAKE_CURRENT_BINARY_DIR}/CXXSymbols.inc)
 add_custom_command(OUTPUT ${cxx_symbols_inc}
-   COMMAND "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/pseudo-gen"
+   COMMAND "${pseudo_gen}"
  --grammar ${cxx_bnf}
  --emit-symbol-list
  -o ${cxx_symbols_inc}
COMMENT "Generating nonterminal symbol file for cxx grammar..."
-   DEPENDS pseudo-gen
+   DEPENDS ${pseudo_gen_target}
VERBATIM)
 
 set(cxx_bnf_inc ${CMAKE_CURRENT_BINARY_DIR}/CXXBNF.inc)
 add_custom_command(OUTPUT ${cxx_bnf_inc}
-   COMMAND "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/pseudo-gen"
+   COMMAND "${pseudo_gen}"
  --grammar ${cxx_bnf}
  --emit-grammar-content
  -o ${cxx_bnf_inc}
COMMENT "Generating bnf string file for cxx grammar..."
-   DEPENDS pseudo-gen
+   DEPENDS ${pseudo_gen_target}
VERBATIM)
 
 # add_custom_command does not create a new target, we need to deine a target
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D125667: [pseudo] A basic implementation of compiling cxx grammar at build time.

2022-05-25 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

In D125667#3537678 , @smeenai wrote:

> In D125667#3537655 , @sammccall 
> wrote:
>
>> I'll see if I can fix it quickly, else will revert (there are a couple of 
>> fixes stacked on top already, so revert isn't quite clean)
>
> Thank you! I'll have some time to look at this a bit later myself as well, 
> and it should hopefully be a quick fix, so we can try to avoid the revert :)

D126397 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125667

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


[PATCH] D125678: [clang][extract-api] Don't emit symbols prefixed with an underscore

2022-05-25 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added a comment.

In D125678#3517174 , @zixuw wrote:

> In D125678#3517168 , 
> @QuietMisdreavus wrote:
>
>> clang-format failed:
>>
>>   ---  clang-format
>>   
>>   changed files:
>>   
>>   clang/test/ExtractAPI/underscored.c
>
> I think it's fine. clang-format always get tripped on split-file tests 
> because of the mixed format and what not.

Yeah this always unfortunately happens can't expect clang format to seamlessly 
accept to format both C and JSON. Also formatting matters less in tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125678

___
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-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: clang-language-wg.
aaron.ballman added a comment.

Please add more details to the summary and remove the rdar link (nobody outside 
of Apple can access that anyway). Also, this should have a release note for the 
bug fix.




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

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.


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] D126398: [Clang] Introduce `-dl` option to perform offload device linking

2022-05-25 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: MaskRay, jdoerfert, yaxunl, tra.
Herald added a subscriber: StephenFan.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

The new driver uses an augmented linker wrapper to perform the device
linking phase, but to the user looks like a regular linker invocation.
Contrary to the old driver, the new driver contains all the information
necessary to produce a linked device image in the host object itself.
Currently, we infer the usage of the device linker by the user
specifying an offloading toolchain, e.g. (--offload-arch=...) or
(-fopenmp-targets=...), but this shouldn't be strictly necessary.
This patch introduces a new option `-dl` to tell the driver to use the
offloading linker instead. So a compilation flow can now look like this,

  clang foo.cu --offload-new-driver -fgpu-rdc --offload-arch=sm_70 -c
  clang foo.o -dl -lcudart

I was considering if this could be merged into the `-fuse-ld` option,
but becuse the device linker wraps over the users linker it would
conflict with that. In the future it's possible to merge this into `lld`
completely or `gold` via a plugin. Let me know what you think for this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126398

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/cuda-openmp-driver.cu


Index: clang/test/Driver/cuda-openmp-driver.cu
===
--- clang/test/Driver/cuda-openmp-driver.cu
+++ clang/test/Driver/cuda-openmp-driver.cu
@@ -35,3 +35,8 @@
 
 // RUN: %clang -### -target x86_64-linux-gnu -nocudalib --cuda-feature=+ptx61 
--offload-arch=sm_70 %s 2>&1 | FileCheck -check-prefix MANUAL-FEATURE %s
 // MANUAL-FEATURE: -cc1{{.*}}-target-feature{{.*}}+ptx61
+
+// RUN: %clang -### -target x86_64-linux-gnu -nocudalib -ccc-print-bindings 
-dl %s 2>&1 \
+// RUN: | FileCheck -check-prefix DEVICE-LINK %s
+
+// DEVICE-LINK: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: 
["[[INPUT:.+]]"], output: "a.out"
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4158,7 +4158,8 @@
 // Check if this Linker Job should emit a static library.
 if (ShouldEmitStaticLibrary(Args)) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
-} else if (UseNewOffloadingDriver) {
+} else if (UseNewOffloadingDriver ||
+   Args.hasArg(options::OPT_device_link)) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
   LA->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
/*BoundArch=*/nullptr);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -820,6 +820,8 @@
 def z : Separate<["-"], "z">, Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass -z  to the linker">, MetaVarName<"">,
   Group;
+def device_link : Flag<["-"], "dl">,
+  HelpText<"Use the new offloading linker to perform the link job.">;
 def Xlinker : Separate<["-"], "Xlinker">, Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass  to the linker">, MetaVarName<"">,
   Group;
Index: clang/docs/ClangCommandLineReference.rst
===
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -4209,6 +4209,10 @@
 
 Pass the comma separated arguments in  to the linker
 
+.. option:: -dl
+
+Use the linker supporting offloading device linking.
+
 .. option:: -X
 
 .. option:: -Xlinker , --for-linker , --for-linker=


Index: clang/test/Driver/cuda-openmp-driver.cu
===
--- clang/test/Driver/cuda-openmp-driver.cu
+++ clang/test/Driver/cuda-openmp-driver.cu
@@ -35,3 +35,8 @@
 
 // RUN: %clang -### -target x86_64-linux-gnu -nocudalib --cuda-feature=+ptx61 --offload-arch=sm_70 %s 2>&1 | FileCheck -check-prefix MANUAL-FEATURE %s
 // MANUAL-FEATURE: -cc1{{.*}}-target-feature{{.*}}+ptx61
+
+// RUN: %clang -### -target x86_64-linux-gnu -nocudalib -ccc-print-bindings -dl %s 2>&1 \
+// RUN: | FileCheck -check-prefix DEVICE-LINK %s
+
+// DEVICE-LINK: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: ["[[INPUT:.+]]"], output: "a.out"
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4158,7 +4158,8 @@
 // Check if this Linker Job should emit a static library.
 if (ShouldEmitStaticLibrary(Args)) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
-} else if (UseNewOffloadingDriver) {
+ 

[PATCH] D126369: [LLVM] Add rcp.approx.ftz.f32 intrinsic

2022-05-25 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

LGTM. Do you need me to land it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126369

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


[clang] 8a1984c - [Clang][Docs] Document `-Xoffload-linker` flag

2022-05-25 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-05-25T13:33:10-04:00
New Revision: 8a1984c25e2c982a9388c14bdaf99bdcd3e26bd4

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

LOG: [Clang][Docs] Document `-Xoffload-linker` flag

Summary:
I added the `-Xoffload-linker` flag and did not provide additional
documentation. This patch adds it.

Added: 


Modified: 
clang/docs/ClangCommandLineReference.rst

Removed: 




diff  --git a/clang/docs/ClangCommandLineReference.rst 
b/clang/docs/ClangCommandLineReference.rst
index 13e175a4e5203..5926decc85fc1 100644
--- a/clang/docs/ClangCommandLineReference.rst
+++ b/clang/docs/ClangCommandLineReference.rst
@@ -4215,6 +4215,10 @@ Pass the comma separated arguments in  to the linker
 
 Pass  to the linker
 
+.. option:: -Xoffload-linker , -Xoffload-linker- 
+
+Pass  to all the device linking jobs, or for only  if specified.
+
 .. program:: clang1
 .. option:: -Z
 .. program:: clang



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


[clang] ba3f853 - [OpenMP] Add diagnostic for unterminated 'omp [begin] declare target'

2022-05-25 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2022-05-25T10:34:07-07:00
New Revision: ba3f85390bde10eab1cbdb68f744b8f5ab31859b

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

LOG: [OpenMP] Add diagnostic for unterminated 'omp [begin] declare target'

Warns when end-of-file is reached without seeing all matching
'omp end declare target' directives. The diagnostic shows the
location of the related begin directive.

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

Added: 
clang/test/OpenMP/Inputs/unterminated_declare_target_include.h

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/declare_target_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 2969e24e3baf8..6dfe5af6ecfa3 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11001,6 +11001,9 @@ def err_omp_append_args_with_varargs : Error<
   "'append_args' is not allowed with varargs functions">;
 def err_openmp_vla_in_task_untied : Error<
   "variable length arrays are not supported in OpenMP tasking regions with 
'untied' clause">;
+def warn_omp_unterminated_declare_target : Warning<
+  "expected '#pragma omp end declare target' at end of file to match '#pragma 
omp %0'">,
+  InGroup;
 } // end of OpenMP category
 
 let CategoryName = "Related Result Type Issue" in {

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9cbbeadc3d74b..bd7a809e40474 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10769,6 +10769,10 @@ class Sema final {
   /// encountered.
   void ActOnFinishedOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI);
 
+  /// Report unterminated 'omp declare target' or 'omp begin declare target' at
+  /// the end of a compilation unit.
+  void DiagnoseUnterminatedOpenMPDeclareTarget();
+
   /// Searches for the provided declaration name for OpenMP declare target
   /// directive.
   NamedDecl *lookupOpenMPDeclareTargetName(Scope *CurScope,

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index ce104f377730c..ad2cb62a18f0c 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1157,6 +1157,7 @@ void Sema::ActOnEndOfTranslationUnit() {
 
   DiagnoseUnterminatedPragmaAlignPack();
   DiagnoseUnterminatedPragmaAttribute();
+  DiagnoseUnterminatedOpenMPDeclareTarget();
 
   // All delayed member exception specs should be checked or we end up 
accepting
   // incompatible declarations.

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 1fdb7df1feea4..fdb7658f77bda 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -22101,6 +22101,14 @@ void Sema::ActOnFinishedOpenMPDeclareTargetContext(
 ActOnOpenMPDeclareTargetName(It.first, It.second.Loc, It.second.MT, DTCI);
 }
 
+void Sema::DiagnoseUnterminatedOpenMPDeclareTarget() {
+  if (DeclareTargetNesting.empty())
+return;
+  DeclareTargetContextInfo &DTCI = DeclareTargetNesting.back();
+  Diag(DTCI.Loc, diag::warn_omp_unterminated_declare_target)
+  << getOpenMPDirectiveName(DTCI.Kind);
+}
+
 NamedDecl *Sema::lookupOpenMPDeclareTargetName(Scope *CurScope,
CXXScopeSpec &ScopeSpec,
const DeclarationNameInfo &Id) {

diff  --git a/clang/test/OpenMP/Inputs/unterminated_declare_target_include.h 
b/clang/test/OpenMP/Inputs/unterminated_declare_target_include.h
new file mode 100644
index 0..ddb60d562de15
--- /dev/null
+++ b/clang/test/OpenMP/Inputs/unterminated_declare_target_include.h
@@ -0,0 +1,3 @@
+// expected-warning@+1 {{expected '#pragma omp end declare target' at end of 
file to match '#pragma omp declare target'}}
+#pragma omp declare target
+void zxy();

diff  --git a/clang/test/OpenMP/declare_target_messages.cpp 
b/clang/test/OpenMP/declare_target_messages.cpp
index 31185881e192b..7e7cc60e75e35 100644
--- a/clang/test/OpenMP/declare_target_messages.cpp
+++ b/clang/test/OpenMP/declare_target_messages.cpp
@@ -6,6 +6,9 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 
-verify=expected,omp5,host5 -fopenmp-simd -fopenmp-is-device 
-fopenmp-targets=x86_64-apple-macos10.7.0 -fnoopenmp-use-tls -ferror-limit 100 
-o - %s
 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp45 
-fopenmp-version=45 -fopenmp-simd -fnoopenmp-use-tls -ferror-limit 100 -o - %s
 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 
-fopenmp -fopenmp-version=51 -fnoopenmp-use-tls -ferror-limi

[clang] 69da3b6 - Revert "[OpenMP] atomic compare fail : Parser & AST support"

2022-05-25 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-05-25T13:34:34-04:00
New Revision: 69da3b6aead2e7a18a2578aad661d6d36b8d30cf

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

LOG: Revert "[OpenMP] atomic compare fail : Parser & AST support"

This reverts commit 232bf8189ef7d574a468bd5bfd1e84e962f7f16e.

It broke the sanitize buildbot: 
https://lab.llvm.org/buildbot/#/builders/5/builds/24074

It also reproduces on Windows debug builds as a crash.

Added: 


Modified: 
clang/include/clang/AST/ASTNodeTraverser.h
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/atomic_ast_print.cpp
clang/test/OpenMP/atomic_messages.cpp
clang/tools/libclang/CIndex.cpp
flang/lib/Semantics/check-omp-structure.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang/AST/ASTNodeTraverser.h 
b/clang/include/clang/AST/ASTNodeTraverser.h
index cb5bbeb644812..f2c5c01ac88de 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -214,10 +214,6 @@ class ASTNodeTraverser
   }
 
   void Visit(const OMPClause *C) {
-if (OMPFailClause::classof(C)) {
-  Visit(static_cast(C));
-  return;
-}
 getNodeDelegate().AddChild([=] {
   getNodeDelegate().Visit(C);
   for (const auto *S : C->children())
@@ -225,13 +221,6 @@ class ASTNodeTraverser
 });
   }
 
-  void Visit(const OMPFailClause *C) {
-getNodeDelegate().AddChild([=] {
-  getNodeDelegate().Visit(C);
-  const OMPClause *MOC = C->const_getMemoryOrderClause();
-  Visit(MOC);
-});
-  }
   void Visit(const GenericSelectionExpr::ConstAssociation &A) {
 getNodeDelegate().AddChild([=] {
   getNodeDelegate().Visit(A);

diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index aa9503c565779..a745df1143468 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -2266,133 +2266,6 @@ class OMPCompareClause final : public OMPClause {
   }
 };
 
-/// This represents 'fail' clause in the '#pragma omp atomic'
-/// directive.
-///
-/// \code
-/// #pragma omp atomic compare fail
-/// \endcode
-/// In this example directive '#pragma omp atomic compare' has 'fail' clause.
-class OMPFailClause final
-: public OMPClause,
-  private llvm::TrailingObjects {
-  OMPClause *MemoryOrderClause;
-
-  friend class OMPClauseReader;
-  friend TrailingObjects;
-
-  /// Define the sizes of each trailing object array except the last one. This
-  /// is required for TrailingObjects to work properly.
-  size_t numTrailingObjects(OverloadToken) const {
-// 2 locations: for '(' and argument location.
-return 2;
-  }
-
-  /// Sets the location of '(' in fail clause.
-  void setLParenLoc(SourceLocation Loc) {
-*getTrailingObjects() = Loc;
-  }
-
-  /// Sets the location of memoryOrder clause argument in fail clause.
-  void setArgumentLoc(SourceLocation Loc) {
-*std::next(getTrailingObjects(), 1) = Loc;
-  }
-
-  /// Sets the mem_order clause for 'atomic compare fail' directive.
-  void setMemOrderClauseKind(OpenMPClauseKind MemOrder) {
-OpenMPClauseKind *MOCK = getTrailingObjects();
-*MOCK = MemOrder;
-  }
-
-  /// Sets the mem_order clause for 'atomic compare fail' directive.
-  void setMemOrderClause(OMPClause *MemoryOrderClauseParam) {
-MemoryOrderClause = MemoryOrderClauseParam;
-  }
-public:
-  /// Build 'fail' clause.
-  ///
-  /// \param StartLoc Starting location of the clause.
-  /// \param EndLoc Ending location of the clause.
-  OMPFailClause(SourceLocation StartLoc, SourceLocation EndLoc)
-  : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc) {}
-
-  /// Build an empty clause.
-  OMPFailClause()
-  : OMPClause(llvm::omp::OMPC_fail, SourceLocation(), SourceLocation()) {}
-
-  static OMPFailClause *CreateEmpty(const ASTContext &C);
-  static OMPFailClause *Create(const ASTContext &C, SourceLocation StartLoc,
-   SourceLocation EndLoc);
-
-  child_range children() {
-return child_range(child_iterator(), child_iterator());
-  }
-
-
-  const_child_range children() const {
-return const_child_range(const_child_iterator(), const_child_iterator());
-  }
-
-  child_range used_children() {
-return child_range(c

[PATCH] D126331: [OpenMP] Add diagnostic for unterminated 'omp [begin] declare target'

2022-05-25 Thread Mike Rice via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGba3f85390bde: [OpenMP] Add diagnostic for unterminated 
'omp [begin] declare target' (authored by mikerice).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126331

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/Inputs/unterminated_declare_target_include.h
  clang/test/OpenMP/declare_target_messages.cpp


Index: clang/test/OpenMP/declare_target_messages.cpp
===
--- clang/test/OpenMP/declare_target_messages.cpp
+++ clang/test/OpenMP/declare_target_messages.cpp
@@ -6,6 +6,9 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 
-verify=expected,omp5,host5 -fopenmp-simd -fopenmp-is-device 
-fopenmp-targets=x86_64-apple-macos10.7.0 -fnoopenmp-use-tls -ferror-limit 100 
-o - %s
 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp45 
-fopenmp-version=45 -fopenmp-simd -fnoopenmp-use-tls -ferror-limit 100 -o - %s
 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 
-fopenmp -fopenmp-version=51 -fnoopenmp-use-tls -ferror-limit 100 -o - %s
+// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 
-fopenmp -fopenmp-version=51 -fnoopenmp-use-tls -ferror-limit 100 -DTESTEND=1 
-o - %s
+// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 
-fopenmp -fopenmp-version=51 -fnoopenmp-use-tls -ferror-limit 100 -I%S/Inputs 
-DTESTENDINC=1 -o - %s
+// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 
-fopenmp-version=51 -fopenmp-simd -fnoopenmp-use-tls -ferror-limit 100 -o - %s
 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 
-fopenmp-version=51 -fopenmp-simd -fnoopenmp-use-tls -ferror-limit 100 -o - %s
 
 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp5 
-fopenmp -fnoopenmp-use-tls -ferror-limit 100 -o - %s
@@ -228,5 +231,12 @@
 #pragma omp declare target to(MultiDevTy) device_type(host)   // omp45-error 
{{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} 
omp5-error {{'device_type(host)' does not match previously specified 
'device_type(any)' for the same declaration}} omp51-error {{'device_type(host)' 
does not match previously specified 'device_type(any)' for the same 
declaration}}
 #pragma omp declare target to(MultiDevTy) device_type(nohost) // omp45-error 
{{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} 
omp5-error {{'device_type(nohost)' does not match previously specified 
'device_type(any)' for the same declaration}} // omp51-error 
{{'device_type(nohost)' does not match previously specified 'device_type(any)' 
for the same declaration}}
 
-// TODO: Issue an error message error {{expected '#pragma omp end declare 
target'}} note {{to match this '#pragma omp declare target'}}
+#if TESTENDINC
+#include "unterminated_declare_target_include.h"
+#elif TESTEND
+// expected-warning@+1 {{expected '#pragma omp end declare target' at end of 
file to match '#pragma omp declare target'}}
 #pragma omp declare target
+#else
+// expected-warning@+1 {{expected '#pragma omp end declare target' at end of 
file to match '#pragma omp begin declare target'}}
+#pragma omp begin declare target
+#endif
Index: clang/test/OpenMP/Inputs/unterminated_declare_target_include.h
===
--- /dev/null
+++ clang/test/OpenMP/Inputs/unterminated_declare_target_include.h
@@ -0,0 +1,3 @@
+// expected-warning@+1 {{expected '#pragma omp end declare target' at end of 
file to match '#pragma omp declare target'}}
+#pragma omp declare target
+void zxy();
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -22101,6 +22101,14 @@
 ActOnOpenMPDeclareTargetName(It.first, It.second.Loc, It.second.MT, DTCI);
 }
 
+void Sema::DiagnoseUnterminatedOpenMPDeclareTarget() {
+  if (DeclareTargetNesting.empty())
+return;
+  DeclareTargetContextInfo &DTCI = DeclareTargetNesting.back();
+  Diag(DTCI.Loc, diag::warn_omp_unterminated_declare_target)
+  << getOpenMPDirectiveName(DTCI.Kind);
+}
+
 NamedDecl *Sema::lookupOpenMPDeclareTargetName(Scope *CurScope,
CXXScopeSpec &ScopeSpec,
const DeclarationNameInfo &Id) {
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -1157,6 +1157,7 @@
 
   DiagnoseUnterminatedPragmaAlignPack();
   DiagnoseUnterminated

[PATCH] D123235: [OpenMP] atomic compare fail : Parser & AST support

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

In D123235#3537636 , @aaron.ballman 
wrote:

> Please revert the changes while investigating how to resolve the crashes 
> though.

I just noticed that you needed someone to commit on your behalf for this, so I 
went ahead and did the revert myself in 
69da3b6aead2e7a18a2578aad661d6d36b8d30cf 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123235

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


[PATCH] D123924: [clang-apply-replacements] Added an option to ignore insert conflict.

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

I think this has sat for long enough and my LGTM will have to suffice. :-)


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

https://reviews.llvm.org/D123924

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


[PATCH] D126397: [pseudo] Fix pseudo-gen usage when cross-compiling

2022-05-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thank you! I have been banging my head against this, I'm not entirely sure why 
this works and my version doesn't.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126397

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


[PATCH] D126397: [pseudo] Fix pseudo-gen usage when cross-compiling

2022-05-25 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

In D126397#3537843 , @sammccall wrote:

> Thank you! I have been banging my head against this, I'm not entirely sure 
> why this works and my version doesn't.

Ah, sorry for the duplicated work :( Thanks for the review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126397

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


[PATCH] D126341: Order implicitly instantiated global variable's initializer by the reverse instantiation order

2022-05-25 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

In D126341#3537675 , @aaron.ballman 
wrote:

> Adding the language WG as a reviewer in case others have opinions.
>
>> The underlying problem is basically wg21.link/cwg362 which has no concensus 
>> yet.
>
> According to 
> https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#362 this was 
> resolved in CD1 and we track it as being not applicable to us 
> (https://clang.llvm.org/cxx_dr_status.html#362). (Is our status actually 
> correct for this?)
>
>> Will the reviewers be supportive if I make the original cwg362 test case 
>> work too?
>
> To me, it depends on what it does to compile times and memory overhead for 
> the compiler when run on large projects. If the extra tracking is cheap and 
> doesn't really impact anything, I think it's reasonable to want to match 
> GCC's behavior. If it turns out this is expensive, I'm less keen on matching 
> GCC.

Thanks for the opinion @aaron.ballman. I think the cost would be low. I'll get 
back with some numbers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126341

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


[clang] 9368bf9 - Removing this as part of the revert done in 69da3b6aead2e7a18a2578aad661d6d36b8d30cf

2022-05-25 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-05-25T13:45:17-04:00
New Revision: 9368bf9023eee0dc6fcfa007e157fe30e1540fcc

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

LOG: Removing this as part of the revert done in 
69da3b6aead2e7a18a2578aad661d6d36b8d30cf

This appears to have been added in a follow-up commit that I missed.

Added: 


Modified: 
clang/lib/CodeGen/CGStmtOpenMP.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index ebe65e5f72b3e..61e3661e59be0 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -6317,7 +6317,6 @@ static void emitOMPAtomicExpr(CodeGenFunction &CGF, 
OpenMPClauseKind Kind,
   case OMPC_bind:
   case OMPC_align:
   case OMPC_cancellation_construct_type:
-  case OMPC_fail:
 llvm_unreachable("Clause is not allowed in 'omp atomic'.");
   }
 }



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


[PATCH] D123235: [OpenMP] atomic compare fail : Parser & AST support

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

In D123235#3537820 , @aaron.ballman 
wrote:

> In D123235#3537636 , @aaron.ballman 
> wrote:
>
>> Please revert the changes while investigating how to resolve the crashes 
>> though.
>
> I just noticed that you needed someone to commit on your behalf for this, so 
> I went ahead and did the revert myself in 
> 69da3b6aead2e7a18a2578aad661d6d36b8d30cf 
> .

There was a follow-up I also needed to revert in 
9368bf9023eee0dc6fcfa007e157fe30e1540fcc 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123235

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


  1   2   >