[PATCH] D107040: [clangd] Make use of diagnostic tags for some clang diags

2021-07-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

It is not great to list diag ids by hand, but I don't see any other
solution unless diagnostics are annotated with these explicitly, which is a
bigger change in clang and I am not sure if would be worth it.

Diagnostics handled by this patch is by no means exhaustive, there might be
other checks that don't mention "unused"/"deprecated" in their names. But it
feels like this should be enough to catch common diagnostics and can be extended
over time.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107040

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -65,6 +65,11 @@
   return Field(&Diag::Notes, UnorderedElementsAre(NoteMatcher1, NoteMatcher2));
 }
 
+::testing::Matcher
+WithTag(::testing::Matcher TagMatcher) {
+  return Field(&Diag::Tags, Contains(TagMatcher));
+}
+
 MATCHER_P2(Diag, Range, Message,
"Diag at " + llvm::to_string(Range) + " = [" + Message + "]") {
   return arg.Range == Range && arg.Message == Message;
@@ -665,6 +670,7 @@
 
   clangd::Diag D;
   D.ID = clang::diag::err_undeclared_var_use;
+  D.Tags = {DiagnosticTag::Unnecessary};
   D.Name = "undeclared_var_use";
   D.Source = clangd::Diag::Clang;
   D.Message = "something terrible happened";
@@ -710,6 +716,7 @@
 
 ../foo/baz/header.h:10:11:
 note: declared somewhere in the header file)";
+  MainLSP.tags = {DiagnosticTag::Unnecessary};
 
   clangd::Diagnostic NoteInMainLSP;
   NoteInMainLSP.range = NoteInMain.Range;
@@ -1419,6 +1426,24 @@
 testing::Contains(Diag(Code.range(), "no newline at end of file")));
   }
 }
+
+TEST(Diagnostics, Tags) {
+  TestTU TU;
+  TU.ExtraArgs = {"-Wunused", "-Wdeprecated"};
+  Annotations Test(R"cpp(
+  void bar() __attribute__((deprecated));
+  void foo() {
+int $unused[[x]];
+$deprecated[[bar]]();
+  })cpp");
+  TU.Code = Test.code().str();
+  EXPECT_THAT(*TU.build().getDiagnostics(),
+  UnorderedElementsAre(
+  AllOf(Diag(Test.range("unused"), "unused variable 'x'"),
+WithTag(DiagnosticTag::Unnecessary)),
+  AllOf(Diag(Test.range("deprecated"), "'bar' is deprecated"),
+WithTag(DiagnosticTag::Deprecated;
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -822,6 +822,8 @@
   /// Clients are allowed to rendered diagnostics with this tag strike through.
   Deprecated = 2,
 };
+llvm::json::Value toJSON(DiagnosticTag Tag);
+
 struct CodeAction;
 struct Diagnostic {
   /// The range at which the message applies.
Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -1452,5 +1452,6 @@
   return OS;
 }
 
+llvm::json::Value toJSON(DiagnosticTag Tag) { return static_cast(Tag); }
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -36,6 +36,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -326,24 +327,56 @@
   return capitalize(std::move(Result));
 }
 
-llvm::SmallVector
-getDiagnosticTags(const clang::Diagnostic &D) {
-  llvm::SmallVector Result;
-  if ((diag::warn_deprecated <= D.getID() &&
-   D.getID() <= diag::warn_deprecated_volatile_structured_binding) ||
-  D.getID() == diag::warn_access_decl_deprecated ||
-  D.getID() == diag::warn_atl_uuid_deprecated ||
-  D.getID() == diag::warn_opencl_attr_deprecated_ignored ||
-  D.getID() == diag::warn_property_method_deprecated ||
-  D.getID() == diag::warn_vector_mode_deprecated) {
+std::vector getDiagnosticTags(unsigned DiagID) {
+  static const llvm::DenseSet DeprecatedDiags = {
+  diag::warn_access_decl_deprecated,
+  diag::warn_atl_uuid_deprecated,
+  diag::warn_deprecated,
+  diag::warn_deprecated_altivec_src_compat,
+  diag::warn_deprecated_comma_subscript,
+  diag::warn_deprecated_compound_assign_volatile,
+ 

[PATCH] D106431: [clang-tidy] Fix cppcoreguidelines-init-variables by removing the enum FixIt, and add support for initialization check of scoped enum.

2021-07-29 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

If we are tinkering with the code post-acceptance, could you please also change 
`const char *` to `StringRef`? They are the same thing essentially, but 
accessing the length is (AFIAK) //O(1)// and there isn't a //concerning// 
`strlen` call in the code.


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

https://reviews.llvm.org/D106431

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


[PATCH] D106431: [clang-tidy] Fix cppcoreguidelines-init-variables by removing the enum FixIt, and add support for initialization check of scoped enum.

2021-07-29 Thread Whisperity via Phabricator via cfe-commits
whisperity added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp:85
+  if (TypePtr->isEnumeralType())
+InitializationString = "";
+  else if (TypePtr->isIntegerType())

Also, if we're using //Optional//, this could also be `= nullptr` instead, and 
then we have the state when the //Optional// `hasValue()` but the value itself 
is null. In all other cases, it //both// `hasValue()` and the value is non-null.
This would also eliminate the need for the `strlen` call.


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

https://reviews.llvm.org/D106431

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


[PATCH] D106431: [clang-tidy] Fix cppcoreguidelines-init-variables by removing the enum FixIt, and add support for initialization check of scoped enum.

2021-07-29 Thread Whisperity via Phabricator via cfe-commits
whisperity added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp:85
+  if (TypePtr->isEnumeralType())
+InitializationString = "";
+  else if (TypePtr->isIntegerType())

whisperity wrote:
> Also, if we're using //Optional//, this could also be `= nullptr` instead, 
> and then we have the state when the //Optional// `hasValue()` but the value 
> itself is null. In all other cases, it //both// `hasValue()` and the value is 
> non-null.
> This would also eliminate the need for the `strlen` call.
In the StringRef case, you'd need to `emplace` a default-constructed StringRef 
(which has the semantics of not pointing anywhere and having length 0) into the 
Optional. 


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

https://reviews.llvm.org/D106431

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


[PATCH] D106431: [clang-tidy] Fix cppcoreguidelines-init-variables by removing the enum FixIt, and add support for initialization check of scoped enum.

2021-07-29 Thread gehry via Phabricator via cfe-commits
Sockke updated this revision to Diff 362663.
Sockke added a comment.

You made it very clear, thanks a lot! @whisperity


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

https://reviews.llvm.org/D106431

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-init-variables.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp
@@ -92,3 +92,26 @@
   } catch (int X) {
   }
 }
+
+enum Color { Red, Green, Blue };
+
+enum Car { Benz, BMW = 20, Audi = BMW + 2 };
+
+enum Gender : char { Male, Female };
+
+enum class Direction { Up, Down, Left, Right };
+
+enum class Fruit : int { Apple, Orange };
+
+void uninitialized_enum() {
+  Color color;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'color' is not initialized [cppcoreguidelines-init-variables]
+  Car car;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'car' is not initialized [cppcoreguidelines-init-variables]
+  Gender gender;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: variable 'gender' is not initialized [cppcoreguidelines-init-variables]
+  Direction direction;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'direction' is not initialized [cppcoreguidelines-init-variables]
+  Fruit fruit;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'fruit' is not initialized [cppcoreguidelines-init-variables]
+}
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-init-variables.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-init-variables.rst
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-init-variables.rst
@@ -37,6 +37,21 @@
  // Rest of the function.
}
 
+It warns for the uninitialized enum case, but without a FixIt:
+
+.. code-block:: c++
+
+   enum A {A1, A2, A3};
+   enum A_c : char { A_c1, A_c2, A_c3 };
+   enum class B { B1, B2, B3 };
+   enum class B_i : int { B_i1, B_i2, B_i3 };
+   void function() {
+ A a; // Warning: variable 'a' is not initialized
+ A_c a_c; // Warning: variable 'a_c' is not initialized
+ B b; // Warning: variable 'b' is not initialized
+ B_i b_i; // Warning: variable 'b_i' is not initialized
+   }
+
 Options
 ---
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -149,6 +149,12 @@
   function or assignment to ``nullptr``.
   Added support for pointers to ``std::unique_ptr``.
 
+- Improved :doc:`cppcoreguidelines-init-variables` check.
+
+  Removed generating fixes for enums because the code generated was broken, trying to initialize the enum from an integer.
+
+  The check now also warns for uninitialized scoped enums.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
@@ -78,10 +78,12 @@
 return;
 
   QualType TypePtr = MatchedDecl->getType();
-  const char *InitializationString = nullptr;
+  llvm::Optional InitializationString = llvm::None;
   bool AddMathInclude = false;
 
-  if (TypePtr->isIntegerType())
+  if (TypePtr->isEnumeralType())
+InitializationString = nullptr;
+  else if (TypePtr->isIntegerType())
 InitializationString = " = 0";
   else if (TypePtr->isFloatingType()) {
 InitializationString = " = NAN";
@@ -96,11 +98,12 @@
   if (InitializationString) {
 auto Diagnostic =
 diag(MatchedDecl->getLocation(), "variable %0 is not initialized")
-<< MatchedDecl
-<< FixItHint::CreateInsertion(
-   MatchedDecl->getLocation().getLocWithOffset(
-   MatchedDecl->getName().size()),
-   InitializationString);
+<< MatchedDecl;
+if (*InitializationString != nullptr)
+  Diagnostic << FixItHint::CreateInsertion(
+  MatchedDecl->getLocation().getLocWithOffset(
+  MatchedDecl->getName().size()),
+  *InitializationString);
 if (AddMathInclude) {
   Diagnostic << IncludeInserter.createIncludeInsertion(
   Source.getFileID(MatchedDecl->getBeginLoc()), MathHeader);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mail

[PATCH] D106773: [clang-format] Fix aligning with linebreaks #2

2021-07-29 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

This bug fix should probably be cherry-picked into 13.x branch. WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106773

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


[PATCH] D106939: [RISCV] If the maskedoff is vundefined(), use ta, ma for vsetvli.

2021-07-29 Thread Fraser Cormack via Phabricator via cfe-commits
frasercrmck added a comment.

LGTM but there are test failures. Is that just a whole load of `mu->ma` changes 
that have been omitted for a smaller diff?




Comment at: llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp:379
   bool ForceTailAgnostic = RISCVII::doesForceTailAgnostic(TSFlags);
+  bool MaskAgnostic = true;
   bool TailAgnostic = true;

nit, but purely from a code layout and comment perspective this `MaskAgnostic` 
is in the middle of two "Tail" variables. Also the "tail" variables are 
well-commented ahead of time but the "mask" logic is only commented on inside 
the if statement below. It just looks a bit imbalanced.

I'm wondering if it'd be better there was even something simple like "Default 
to mask agnostic unless the operation is masked and the destination is tied to 
a source."



Comment at: llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp:409
   InstrInfo.setVTYPE(VLMul, SEW, /*TailAgnostic*/ TailAgnostic,
- /*MaskAgnostic*/ false, MaskRegOp);
+ /*MaskAgnostic*/ MaskAgnostic, MaskRegOp);
 

nit: maybe we don't need `/*TailAgnostic*/` or `/*MaskAgnostic*/` anymore?



Comment at: llvm/test/CodeGen/RISCV/rvv/maskedoff-undef.ll:3
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-v -verify-machineinstrs \
+; RUN:   --riscv-no-aliases < %s | FileCheck %s
+

I don't think we're typically using `--riscv-no-aliases` in our CodeGen tests?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106939

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


[PATCH] D106792: [clang-tidy] Always open files using UTF-8 encoding

2021-07-29 Thread Andy Yankovsky via Phabricator via cfe-commits
werat added a comment.

> Hi! Thanks for the patch, it makes sense to me! Honestly, I think having the 
> open shadow is maybe not the best way to solve this (please feel free to let 
> me know if there are reasons it would be better), maybe spell it out 
> explicitly (there aren't that many cases of open)?

It seemed a bit tedious to spell it out explicitly everywhere, but you're 
right, not a script of this size it's not a problem. The benefit of a global 
shadow is that nobody will use regular `open` accidentally, but I think the 
risk of that is relatively low.

> Also, hm... Do we really need these? It's safe to remove those, this 
> shouldn't be a problem, I think.

I don't think using non-ASCII quotes was intentional and we can definitely 
remove them. But future-proofing this script will avoid this problem in the 
future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106792

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


[PATCH] D106644: [clang][analyzer] Add standard streams to alpha.unix.Stream checker.

2021-07-29 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:215-236
+const VarDecl *findStdStreamDecl(StringRef StdName, CheckerContext &C) {
+  ASTContext &ACtx = C.getASTContext();
+
+  IdentifierInfo &II = ACtx.Idents.get(StdName);
+  auto LookupRes = ACtx.getTranslationUnitDecl()->lookup(&II);
+  QualType FILEType = ACtx.getFILEType();
+  if (!FILEType.isNull())

martong wrote:
> Would it be possible to reuse (i.e put in a common place) the 
> StdLibraryFunctionChecker's `lookupTy`? That also handles the cases when 
> FILEType is null or when we have a `typedef struct FILE FILE;`.
Could you please consider the above question?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106644

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


[PATCH] D106792: [clang-tidy] Always open files using UTF-8 encoding

2021-07-29 Thread Andy Yankovsky via Phabricator via cfe-commits
werat updated this revision to Diff 362677.
werat added a comment.

Use `io.open` explicitly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106792

Files:
  clang-tools-extra/clang-tidy/add_new_check.py
  clang-tools-extra/clang-tidy/rename_check.py

Index: clang-tools-extra/clang-tidy/rename_check.py
===
--- clang-tools-extra/clang-tidy/rename_check.py
+++ clang-tools-extra/clang-tidy/rename_check.py
@@ -10,20 +10,25 @@
 
 import argparse
 import glob
+import io
 import os
 import re
 
+# The documentation files are encoded using UTF-8, however on Windows the
+# default encoding might be different (e.g. CP-1252). To make sure UTF-8 is
+# always used, use `io.open(filename, mode, encoding='utf8')` for reading and
+# writing files.
 
 def replaceInFileRegex(fileName, sFrom, sTo):
   if sFrom == sTo:
 return
   txt = None
-  with open(fileName, "r") as f:
+  with io.open(fileName, 'r', encoding='utf8') as f:
 txt = f.read()
 
   txt = re.sub(sFrom, sTo, txt)
   print("Replacing '%s' -> '%s' in '%s'..." % (sFrom, sTo, fileName))
-  with open(fileName, "w") as f:
+  with io.open(fileName, 'w', encoding='utf8') as f:
 f.write(txt)
 
 
@@ -31,7 +36,7 @@
   if sFrom == sTo:
 return
   txt = None
-  with open(fileName, "r") as f:
+  with io.open(fileName, 'r', encoding='utf8') as f:
 txt = f.read()
 
   if sFrom not in txt:
@@ -39,7 +44,7 @@
 
   txt = txt.replace(sFrom, sTo)
   print("Replacing '%s' -> '%s' in '%s'..." % (sFrom, sTo, fileName))
-  with open(fileName, "w") as f:
+  with io.open(fileName, 'w', encoding='utf8') as f:
 f.write(txt)
 
 
@@ -70,7 +75,7 @@
 
 def deleteMatchingLines(fileName, pattern):
   lines = None
-  with open(fileName, "r") as f:
+  with io.open(fileName, 'r', encoding='utf8') as f:
 lines = f.readlines()
 
   not_matching_lines = [l for l in lines if not re.search(pattern, l)]
@@ -79,7 +84,7 @@
 
   print("Removing lines matching '%s' in '%s'..." % (pattern, fileName))
   print('  ' + '  '.join([l for l in lines if re.search(pattern, l)]))
-  with open(fileName, "w") as f:
+  with io.open(fileName, 'w', encoding='utf8') as f:
 f.writelines(not_matching_lines)
 
   return True
@@ -101,7 +106,7 @@
 # entry and 'False' if the entry already existed.
 def adapt_cmake(module_path, check_name_camel):
   filename = os.path.join(module_path, 'CMakeLists.txt')
-  with open(filename, 'r') as f:
+  with io.open(filename, 'r', encoding='utf8') as f:
 lines = f.readlines()
 
   cpp_file = check_name_camel + '.cpp'
@@ -112,7 +117,7 @@
   return False
 
   print('Updating %s...' % filename)
-  with open(filename, 'wb') as f:
+  with io.open(filename, 'wb', encoding='utf8') as f:
 cpp_found = False
 file_added = False
 for line in lines:
@@ -130,11 +135,11 @@
 def adapt_module(module_path, module, check_name, check_name_camel):
   modulecpp = next(filter(lambda p: p.lower() == module.lower() + 'tidymodule.cpp', os.listdir(module_path)))
   filename = os.path.join(module_path, modulecpp)
-  with open(filename, 'r') as f:
+  with io.open(filename, 'r', encoding='utf8') as f:
 lines = f.readlines()
 
   print('Updating %s...' % filename)
-  with open(filename, 'wb') as f:
+  with io.open(filename, 'wb', encoding='utf8') as f:
 header_added = False
 header_found = False
 check_added = False
@@ -169,7 +174,7 @@
 def add_release_notes(clang_tidy_path, old_check_name, new_check_name):
   filename = os.path.normpath(os.path.join(clang_tidy_path,
'../docs/ReleaseNotes.rst'))
-  with open(filename, 'r') as f:
+  with io.open(filename, 'r', encoding='utf8') as f:
 lines = f.readlines()
 
   lineMatcher = re.compile('Renamed checks')
@@ -177,7 +182,7 @@
   checkMatcher = re.compile('- The \'(.*)')
 
   print('Updating %s...' % filename)
-  with open(filename, 'wb') as f:
+  with io.open(filename, 'wb', encoding='utf8') as f:
 note_added = False
 header_found = False
 add_note_here = False
Index: clang-tools-extra/clang-tidy/add_new_check.py
===
--- clang-tools-extra/clang-tidy/add_new_check.py
+++ clang-tools-extra/clang-tidy/add_new_check.py
@@ -11,16 +11,21 @@
 from __future__ import print_function
 
 import argparse
+import io
 import os
 import re
 import sys
 
+# The documentation files are encoded using UTF-8, however on Windows the
+# default encoding might be different (e.g. CP-1252). To make sure UTF-8 is
+# always used, use `io.open(filename, mode, encoding='utf8')` for reading and
+# writing files
 
 # Adapts the module's CMakelist file. Returns 'True' if it could add a new
 # entry and 'False' if the entry already existed.
 def adapt_cmake(module_path, check_name_camel):
   filename = os.path.join(module_path, 'CMakeLists.txt')
-  with open(filename, 'r') as f

[PATCH] D107025: Take OptimizationLevel class out of Pass Builder

2021-07-29 Thread Tarindu Jayatilaka via Phabricator via cfe-commits
tarinduj updated this revision to Diff 362675.
tarinduj added a comment.

added namespace and header guards


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107025

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/examples/Bye/Bye.cpp
  llvm/include/llvm/Passes/OptimizationLevel.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
  llvm/lib/Target/BPF/BPFTargetMachine.cpp
  llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp
  llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
  llvm/tools/opt/NewPMDriver.cpp
  polly/include/polly/Canonicalization.h
  polly/lib/Support/RegisterPasses.cpp
  polly/lib/Transform/Canonicalization.cpp

Index: polly/lib/Transform/Canonicalization.cpp
===
--- polly/lib/Transform/Canonicalization.cpp
+++ polly/lib/Transform/Canonicalization.cpp
@@ -64,7 +64,7 @@
 
 /// Adapted from llvm::PassBuilder::buildInlinerPipeline
 static ModuleInlinerWrapperPass
-buildInlinePasses(llvm::PassBuilder::OptimizationLevel Level) {
+buildInlinePasses(llvm::OptimizationLevel Level) {
   InlineParams IP = getInlineParams(200);
   ModuleInlinerWrapperPass MIWP(IP);
 
@@ -93,7 +93,7 @@
 }
 
 FunctionPassManager polly::buildCanonicalicationPassesForNPM(
-llvm::ModulePassManager &MPM, llvm::PassBuilder::OptimizationLevel Level) {
+llvm::ModulePassManager &MPM, llvm::OptimizationLevel Level) {
   FunctionPassManager FPM;
 
   bool UseMemSSA = true;
@@ -107,7 +107,7 @@
   FPM.addPass(ReassociatePass());
   {
 LoopPassManager LPM;
-LPM.addPass(LoopRotatePass(Level != PassBuilder::OptimizationLevel::Oz));
+LPM.addPass(LoopRotatePass(Level != OptimizationLevel::Oz));
 FPM.addPass(createFunctionToLoopPassAdaptor(
 std::move(LPM), /*UseMemorySSA=*/false,
 /*UseBlockFrequencyInfo=*/false));
Index: polly/lib/Support/RegisterPasses.cpp
===
--- polly/lib/Support/RegisterPasses.cpp
+++ polly/lib/Support/RegisterPasses.cpp
@@ -474,7 +474,7 @@
 /// the analysis passes are added, skipping Polly itself.
 /// The IR may still be modified.
 static void buildCommonPollyPipeline(FunctionPassManager &PM,
- PassBuilder::OptimizationLevel Level,
+ OptimizationLevel Level,
  bool EnableForOpt) {
   PassBuilder PB;
   ScopPassManager SPM;
@@ -574,7 +574,7 @@
 }
 
 static void buildEarlyPollyPipeline(ModulePassManager &MPM,
-PassBuilder::OptimizationLevel Level) {
+OptimizationLevel Level) {
   bool EnableForOpt =
   shouldEnablePollyForOptimization() && Level.isOptimizingForSpeed();
   if (!shouldEnablePollyForDiagnostic() && !EnableForOpt)
@@ -603,7 +603,7 @@
 }
 
 static void buildLatePollyPipeline(FunctionPassManager &PM,
-   PassBuilder::OptimizationLevel Level) {
+   OptimizationLevel Level) {
   bool EnableForOpt =
   shouldEnablePollyForOptimization() && Level.isOptimizingForSpeed();
   if (!shouldEnablePollyForDiagnostic() && !EnableForOpt)
Index: polly/include/polly/Canonicalization.h
===
--- polly/include/polly/Canonicalization.h
+++ polly/include/polly/Canonicalization.h
@@ -30,7 +30,7 @@
 
 llvm::FunctionPassManager
 buildCanonicalicationPassesForNPM(llvm::ModulePassManager &MPM,
-  llvm::PassBuilder::OptimizationLevel Level);
+  llvm::OptimizationLevel Level);
 
 } // namespace polly
 
Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -173,58 +173,58 @@
 static void registerEPCallbacks(PassBuilder &PB) {
   if (tryParsePipelineText(PB, PeepholeEPPipeline))
 PB.registerPeepholeEPCallback(
-[&PB](FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) {
+[&PB](FunctionPassManager &PM, OptimizationLevel Level) {
   ExitOnError Err("Unable to parse PeepholeEP pipeline: ");
   Err(PB.parsePassPipeline(PM, PeepholeEPPipeline));
 });
   if (tryParsePipelineText(PB,
 LateLoopOptimizationsEPPipeline))
 PB.registerLateLoopOptimizationsEPCallback(
-[&PB](LoopPassManager &PM, PassBuilder::OptimizationLevel Level) {
+[&PB](LoopPassManager &PM, OptimizationLevel Level) {
   ExitOnError Err("Unable to parse LateLoopOptimizationsEP pipeline: ");
   Err(PB.parsePassPipeline(PM, Lat

[PATCH] D106792: [clang-tidy] Always open files using UTF-8 encoding

2021-07-29 Thread Andy Yankovsky via Phabricator via cfe-commits
werat updated this revision to Diff 362678.
werat added a comment.

Fix incorrect replace


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106792

Files:
  clang-tools-extra/clang-tidy/add_new_check.py
  clang-tools-extra/clang-tidy/rename_check.py

Index: clang-tools-extra/clang-tidy/rename_check.py
===
--- clang-tools-extra/clang-tidy/rename_check.py
+++ clang-tools-extra/clang-tidy/rename_check.py
@@ -10,20 +10,25 @@
 
 import argparse
 import glob
+import io
 import os
 import re
 
+# The documentation files are encoded using UTF-8, however on Windows the
+# default encoding might be different (e.g. CP-1252). To make sure UTF-8 is
+# always used, use `io.open(filename, mode, encoding='utf8')` for reading and
+# writing files.
 
 def replaceInFileRegex(fileName, sFrom, sTo):
   if sFrom == sTo:
 return
   txt = None
-  with open(fileName, "r") as f:
+  with io.open(fileName, 'r', encoding='utf8') as f:
 txt = f.read()
 
   txt = re.sub(sFrom, sTo, txt)
   print("Replacing '%s' -> '%s' in '%s'..." % (sFrom, sTo, fileName))
-  with open(fileName, "w") as f:
+  with io.open(fileName, 'w', encoding='utf8') as f:
 f.write(txt)
 
 
@@ -31,7 +36,7 @@
   if sFrom == sTo:
 return
   txt = None
-  with open(fileName, "r") as f:
+  with io.open(fileName, 'r', encoding='utf8') as f:
 txt = f.read()
 
   if sFrom not in txt:
@@ -39,7 +44,7 @@
 
   txt = txt.replace(sFrom, sTo)
   print("Replacing '%s' -> '%s' in '%s'..." % (sFrom, sTo, fileName))
-  with open(fileName, "w") as f:
+  with io.open(fileName, 'w', encoding='utf8') as f:
 f.write(txt)
 
 
@@ -70,7 +75,7 @@
 
 def deleteMatchingLines(fileName, pattern):
   lines = None
-  with open(fileName, "r") as f:
+  with io.open(fileName, 'r', encoding='utf8') as f:
 lines = f.readlines()
 
   not_matching_lines = [l for l in lines if not re.search(pattern, l)]
@@ -79,7 +84,7 @@
 
   print("Removing lines matching '%s' in '%s'..." % (pattern, fileName))
   print('  ' + '  '.join([l for l in lines if re.search(pattern, l)]))
-  with open(fileName, "w") as f:
+  with io.open(fileName, 'w', encoding='utf8') as f:
 f.writelines(not_matching_lines)
 
   return True
@@ -101,7 +106,7 @@
 # entry and 'False' if the entry already existed.
 def adapt_cmake(module_path, check_name_camel):
   filename = os.path.join(module_path, 'CMakeLists.txt')
-  with open(filename, 'r') as f:
+  with io.open(filename, 'r', encoding='utf8') as f:
 lines = f.readlines()
 
   cpp_file = check_name_camel + '.cpp'
@@ -112,7 +117,7 @@
   return False
 
   print('Updating %s...' % filename)
-  with open(filename, 'wb') as f:
+  with io.open(filename, 'wb', encoding='utf8') as f:
 cpp_found = False
 file_added = False
 for line in lines:
@@ -130,11 +135,11 @@
 def adapt_module(module_path, module, check_name, check_name_camel):
   modulecpp = next(filter(lambda p: p.lower() == module.lower() + 'tidymodule.cpp', os.listdir(module_path)))
   filename = os.path.join(module_path, modulecpp)
-  with open(filename, 'r') as f:
+  with io.open(filename, 'r', encoding='utf8') as f:
 lines = f.readlines()
 
   print('Updating %s...' % filename)
-  with open(filename, 'wb') as f:
+  with io.open(filename, 'wb', encoding='utf8') as f:
 header_added = False
 header_found = False
 check_added = False
@@ -169,7 +174,7 @@
 def add_release_notes(clang_tidy_path, old_check_name, new_check_name):
   filename = os.path.normpath(os.path.join(clang_tidy_path,
'../docs/ReleaseNotes.rst'))
-  with open(filename, 'r') as f:
+  with io.open(filename, 'r', encoding='utf8') as f:
 lines = f.readlines()
 
   lineMatcher = re.compile('Renamed checks')
@@ -177,7 +182,7 @@
   checkMatcher = re.compile('- The \'(.*)')
 
   print('Updating %s...' % filename)
-  with open(filename, 'wb') as f:
+  with io.open(filename, 'wb', encoding='utf8') as f:
 note_added = False
 header_found = False
 add_note_here = False
Index: clang-tools-extra/clang-tidy/add_new_check.py
===
--- clang-tools-extra/clang-tidy/add_new_check.py
+++ clang-tools-extra/clang-tidy/add_new_check.py
@@ -11,16 +11,21 @@
 from __future__ import print_function
 
 import argparse
+import io
 import os
 import re
 import sys
 
+# The documentation files are encoded using UTF-8, however on Windows the
+# default encoding might be different (e.g. CP-1252). To make sure UTF-8 is
+# always used, use `io.open(filename, mode, encoding='utf8')` for reading and
+# writing files
 
 # Adapts the module's CMakelist file. Returns 'True' if it could add a new
 # entry and 'False' if the entry already existed.
 def adapt_cmake(module_path, check_name_camel):
   filename = os.path.join(module_path, 'CMakeLists.txt')
-  with open(filename, 'r') as f:
+ 

[PATCH] D91950: [clang-format] Add BreakBeforeInlineASMColon configuration

2021-07-29 Thread Anastasiia Lukianenko via Phabricator via cfe-commits
anastasiia_lukianenko updated this revision to Diff 362680.

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

https://reviews.llvm.org/D91950

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -6240,6 +6240,43 @@
 format(Input, Style));
 }
 
+TEST_F(FormatTest, BreakBeforeInlineASMColon) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakStringLiterals = false;
+  Style.BreakBeforeInlineASMColon = FormatStyle::BBIAS_Never;
+  /* Test the behaviour with long lines */
+  Style.ColumnLimit = 40;
+  verifyFormat("asm volatile(\"lng\",\n"
+   " : : val);",
+   Style);
+  verifyFormat("asm volatile(\"lng\",\n"
+   " : val1 : val2);",
+   Style);
+  Style.ColumnLimit = 80;
+  verifyFormat("asm volatile(\"string\", : : val);", Style);
+  verifyFormat("asm volatile(\"string\", : val1 : val2);", Style);
+
+  Style.BreakBeforeInlineASMColon = FormatStyle::BBIAS_Always;
+  verifyFormat("asm volatile(\"string\",\n"
+   " :\n"
+   " : val);",
+   Style);
+  verifyFormat("asm volatile(\"string\",\n"
+   " : val1\n"
+   " : val2);",
+   Style);
+  /* Test the behaviour with long lines */
+  Style.ColumnLimit = 40;
+  verifyFormat("asm volatile(\"lng\",\n"
+   " :\n"
+   " : val);",
+   Style);
+  verifyFormat("asm volatile(\"lng\",\n"
+   " : val1\n"
+   " : val2);",
+   Style);
+}
+
 TEST_F(FormatTest, BreakConstructorInitializersAfterColon) {
   FormatStyle Style = getLLVMStyle();
   Style.BreakConstructorInitializers = FormatStyle::BCIS_AfterColon;
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3602,6 +3602,9 @@
   const FormatToken &Left = *Right.Previous;
   if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0)
 return true;
+  if (Line.startsWith(tok::kw_asm) && Right.is(TT_InlineASMColon) &&
+  Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_Always)
+return true;
 
   if (Style.isCSharp()) {
 if (Right.is(TT_CSharpNamedArgumentColon) ||
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -243,6 +243,16 @@
   }
 };
 
+template <>
+struct ScalarEnumerationTraits {
+  static void
+  enumeration(IO &IO, FormatStyle::BreakBeforeInlineASMColonStyle &Value) {
+IO.enumCase(Value, "Never", FormatStyle::BBIAS_Never);
+IO.enumCase(Value, "OnlyMultiline", FormatStyle::BBIAS_OnlyMultiline);
+IO.enumCase(Value, "Always", FormatStyle::BBIAS_Always);
+  }
+};
+
 template <>
 struct ScalarEnumerationTraits {
   static void
@@ -612,6 +622,9 @@
 Style.BreakInheritanceList == FormatStyle::BILS_BeforeColon)
   Style.BreakInheritanceList = FormatStyle::BILS_BeforeComma;
 
+IO.mapOptional("BreakBeforeInlineASMColon",
+   Style.BreakBeforeInlineASMColon);
+
 IO.mapOptional("BreakBeforeTernaryOperators",
Style.BreakBeforeTernaryOperators);
 
@@ -1006,6 +1019,7 @@
   LLVMStyle.BinPackParameters = true;
   LLVMStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
   LLVMStyle.BreakBeforeConceptDeclarations = true;
+  LLVMStyle.BreakBeforeInlineASMColon = FormatStyle::BBIAS_OnlyMultiline;
   LLVMStyle.BreakBeforeTernaryOperators = true;
   LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
   LLVMStyle.BraceWrapping = {/*AfterCaseLabel=*/false,
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -334,7 +334,10 @@
 auto LambdaBodyLength = getLengthToMatchingParen(Current, State.Stack);
 return (LambdaBodyLength > getColumnLimit(State));
   }
-  if (Current.MustBreakBefore || Current.is(TT_InlineASMColon))
+  if (Current.MustBreakBefore ||
+  (Current.is(TT_InlineASMColon) &&
+   (Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_Always ||
+Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_OnlyMultiline)))
 return true;
   if (State.Stack.back().BreakBeforeClosingBrace &&
   Current.cl

[PATCH] D107047: [clangd] Fix the crash in getQualification

2021-07-29 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev created this revision.
kbobyrev added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman.
kbobyrev requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Happens when DestContext is LinkageSpecDecl and hense CurContext happens to be
both not TagDecl and NamespaceDecl.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107047

Files:
  clang-tools-extra/clangd/AST.cpp


Index: clang-tools-extra/clangd/AST.cpp
===
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -119,17 +119,17 @@
   (void)ReachedNS;
   NNS = NestedNameSpecifier::Create(Context, nullptr, false,
 TD->getTypeForDecl());
-} else {
-  ReachedNS = true;
-  auto *NSD = llvm::cast(CurContext);
-  NNS = NestedNameSpecifier::Create(Context, nullptr, NSD);
-  // Anonymous and inline namespace names are not spelled while qualifying 
a
-  // name, so skip those.
-  if (NSD->isAnonymousNamespace() || NSD->isInlineNamespace())
-continue;
-}
+} else
+  (auto *NSD = llvm::dyn_cast(CurContext)) {
+ReachedNS = true;
+NNS = NestedNameSpecifier::Create(Context, nullptr, NSD);
+// Anonymous and inline namespace names are not spelled while 
qualifying
+// a name, so skip those.
+if (NSD->isAnonymousNamespace() || NSD->isInlineNamespace())
+  continue;
+  }
 // Stop if this namespace is already visible at DestContext.
-if (IsVisible(NNS))
+if (!NNS || IsVisible(NNS))
   break;
 
 Parents.push_back(NNS);


Index: clang-tools-extra/clangd/AST.cpp
===
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -119,17 +119,17 @@
   (void)ReachedNS;
   NNS = NestedNameSpecifier::Create(Context, nullptr, false,
 TD->getTypeForDecl());
-} else {
-  ReachedNS = true;
-  auto *NSD = llvm::cast(CurContext);
-  NNS = NestedNameSpecifier::Create(Context, nullptr, NSD);
-  // Anonymous and inline namespace names are not spelled while qualifying a
-  // name, so skip those.
-  if (NSD->isAnonymousNamespace() || NSD->isInlineNamespace())
-continue;
-}
+} else
+  (auto *NSD = llvm::dyn_cast(CurContext)) {
+ReachedNS = true;
+NNS = NestedNameSpecifier::Create(Context, nullptr, NSD);
+// Anonymous and inline namespace names are not spelled while qualifying
+// a name, so skip those.
+if (NSD->isAnonymousNamespace() || NSD->isInlineNamespace())
+  continue;
+  }
 // Stop if this namespace is already visible at DestContext.
-if (IsVisible(NNS))
+if (!NNS || IsVisible(NNS))
   break;
 
 Parents.push_back(NNS);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107047: [clangd] Fix the crash in getQualification

2021-07-29 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 362687.
kbobyrev added a comment.

Fix formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107047

Files:
  clang-tools-extra/clangd/AST.cpp


Index: clang-tools-extra/clangd/AST.cpp
===
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -119,17 +119,16 @@
   (void)ReachedNS;
   NNS = NestedNameSpecifier::Create(Context, nullptr, false,
 TD->getTypeForDecl());
-} else {
+} else if (auto *NSD = llvm::dyn_cast(CurContext)) {
   ReachedNS = true;
-  auto *NSD = llvm::cast(CurContext);
   NNS = NestedNameSpecifier::Create(Context, nullptr, NSD);
-  // Anonymous and inline namespace names are not spelled while qualifying 
a
-  // name, so skip those.
+  // Anonymous and inline namespace names are not spelled while qualifying
+  // a name, so skip those.
   if (NSD->isAnonymousNamespace() || NSD->isInlineNamespace())
 continue;
 }
 // Stop if this namespace is already visible at DestContext.
-if (IsVisible(NNS))
+if (!NNS || IsVisible(NNS))
   break;
 
 Parents.push_back(NNS);


Index: clang-tools-extra/clangd/AST.cpp
===
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -119,17 +119,16 @@
   (void)ReachedNS;
   NNS = NestedNameSpecifier::Create(Context, nullptr, false,
 TD->getTypeForDecl());
-} else {
+} else if (auto *NSD = llvm::dyn_cast(CurContext)) {
   ReachedNS = true;
-  auto *NSD = llvm::cast(CurContext);
   NNS = NestedNameSpecifier::Create(Context, nullptr, NSD);
-  // Anonymous and inline namespace names are not spelled while qualifying a
-  // name, so skip those.
+  // Anonymous and inline namespace names are not spelled while qualifying
+  // a name, so skip those.
   if (NSD->isAnonymousNamespace() || NSD->isInlineNamespace())
 continue;
 }
 // Stop if this namespace is already visible at DestContext.
-if (IsVisible(NNS))
+if (!NNS || IsVisible(NNS))
   break;
 
 Parents.push_back(NNS);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107049: [clang-repl] Re-implement clang-interpreter as a test case.

2021-07-29 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev created this revision.
v.g.vassilev added reviewers: rsmith, teemperor, lhames, bkramer.
Herald added subscribers: mstorsjo, mgorny.
v.g.vassilev requested review of this revision.

The current infrastructure in lib/Interpreter has a tool, clang-repl, very 
similar to clang-interpreter which also allows incremental compilation.

  

This patch moves clang-interpreter as a test case and drops it as conditionally 
built example as we already have clang-repl in place.


Repository:
  rC Clang

https://reviews.llvm.org/D107049

Files:
  clang/docs/ClangFormattedStatus.rst
  clang/examples/CMakeLists.txt
  clang/examples/clang-interpreter/CMakeLists.txt
  clang/examples/clang-interpreter/README.txt
  clang/examples/clang-interpreter/Test.cxx
  clang/examples/clang-interpreter/main.cpp
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/test/CMakeLists.txt
  clang/test/Misc/interpreter.c
  clang/test/lit.cfg.py
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -14,10 +14,14 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclGroup.h"
+#include "clang/Basic/Version.h"
+#include "clang/Config/config.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
 
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ExecutionEngine/Orc/LLJIT.h"
+#include "llvm/Support/TargetSelect.h"
 
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -53,6 +57,86 @@
   EXPECT_EQ(1U, DeclsSize(R2.TUPart));
 }
 
+// This function isn't referenced outside its translation unit, but it
+// can't use the "static" keyword because its address is used for
+// GetMainExecutable (since some platforms don't support taking the
+// address of main, and some platforms can't implement GetMainExecutable
+// without being given the address of a function in the main executable).
+std::string GetExecutablePath(const char *Argv0, void *MainAddr) {
+  return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
+}
+
+static std::string MakeResourcesPath() {
+  // Dir is bin/ or lib/, depending on where BinaryPath is.
+  void *MainAddr = (void*) (intptr_t) GetExecutablePath;
+  std::string BinaryPath = GetExecutablePath(/*Argv0=*/nullptr, MainAddr);
+
+  // build/tools/clang/unittests/Interpreter/Executable -> build/
+  llvm::StringRef Dir = llvm::sys::path::parent_path(BinaryPath);
+
+  Dir = llvm::sys::path::parent_path(Dir);
+  Dir = llvm::sys::path::parent_path(Dir);
+  Dir = llvm::sys::path::parent_path(Dir);
+  Dir = llvm::sys::path::parent_path(Dir);
+  SmallString<128> P(Dir);
+  llvm::sys::path::append(P, Twine("lib") + CLANG_LIBDIR_SUFFIX, "clang",
+  CLANG_VERSION_STRING);
+
+  return std::string(P.str());
+}
+
+TEST(InterpreterTest, CatchException) {
+  llvm::InitializeNativeTarget();
+  llvm::InitializeNativeTargetAsmPrinter();
+
+  {
+auto J = llvm::orc::LLJITBuilder().create();
+if (!J) {
+  // The platform does not support JITs.
+  llvm::consumeError(J.takeError());
+  return;
+}
+  }
+  const char ExceptionCode[] =
+R"(
+#include 
+#include 
+
+static void ThrowerAnError(const char* Name) {
+  throw std::runtime_error(Name);
+}
+
+int main(int argc, const char** argv) {
+  for (int I = 0; I < argc; ++I)
+   printf("arg[%d]='%s'\n", I, argv[I]);
+
+  try {
+ThrowerAnError("In JIT");
+  } catch (const std::exception& E) {
+printf("Caught: '%s'\n", E.what());
+  } catch (...) {
+printf("Unknown exception\n");
+  }
+  ThrowerAnError("From JIT");
+  return 0;
+}
+)";
+  std::string ResourceDir = MakeResourcesPath();
+  std::unique_ptr Interp =
+  createInterpreter({"-resource-dir", ResourceDir.c_str()});
+  // Adjust the resource-dir
+  llvm::cantFail(Interp->ParseAndExecute(ExceptionCode));
+#if !defined(NDEBUG) && GTEST_HAS_DEATH_TEST
+  testing::internal::CaptureStdout();
+  auto Main = (int (*)(...))llvm::cantFail(Interp->getSymbolAddress("main"));
+  // Compiling this file with exceptions on is problematic on some platforms.
+  // Instead we expect std::terminate to be called upon thrown exception.
+  EXPECT_DEATH(Main(), "terminate called after throwing an instance of '.*'");
+  std::string CapturedStdOut = testing::internal::GetCapturedStdout();
+  EXPECT_EQ(CapturedStdOut, "Caught: 'In JIT'\n");
+#endif
+}
+
 static std::string DeclToString(Decl *D) {
   return llvm::cast(D)->getQualifiedNameAsString();
 }
Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -71,7 +71,6 @@
 
 if config.clang_examples:
 config.available_features.add('examples')

[PATCH] D107025: Take OptimizationLevel class out of Pass Builder

2021-07-29 Thread Tarindu Jayatilaka via Phabricator via cfe-commits
tarinduj updated this revision to Diff 362692.
tarinduj added a comment.

clang-format


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

https://reviews.llvm.org/D107025

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/examples/Bye/Bye.cpp
  llvm/include/llvm/Passes/OptimizationLevel.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
  llvm/lib/Target/BPF/BPFTargetMachine.cpp
  llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp
  llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
  llvm/tools/opt/NewPMDriver.cpp
  polly/include/polly/Canonicalization.h
  polly/lib/Support/RegisterPasses.cpp
  polly/lib/Transform/Canonicalization.cpp

Index: polly/lib/Transform/Canonicalization.cpp
===
--- polly/lib/Transform/Canonicalization.cpp
+++ polly/lib/Transform/Canonicalization.cpp
@@ -64,7 +64,7 @@
 
 /// Adapted from llvm::PassBuilder::buildInlinerPipeline
 static ModuleInlinerWrapperPass
-buildInlinePasses(llvm::PassBuilder::OptimizationLevel Level) {
+buildInlinePasses(llvm::OptimizationLevel Level) {
   InlineParams IP = getInlineParams(200);
   ModuleInlinerWrapperPass MIWP(IP);
 
@@ -92,8 +92,9 @@
   return MIWP;
 }
 
-FunctionPassManager polly::buildCanonicalicationPassesForNPM(
-llvm::ModulePassManager &MPM, llvm::PassBuilder::OptimizationLevel Level) {
+FunctionPassManager
+polly::buildCanonicalicationPassesForNPM(llvm::ModulePassManager &MPM,
+ llvm::OptimizationLevel Level) {
   FunctionPassManager FPM;
 
   bool UseMemSSA = true;
@@ -107,7 +108,7 @@
   FPM.addPass(ReassociatePass());
   {
 LoopPassManager LPM;
-LPM.addPass(LoopRotatePass(Level != PassBuilder::OptimizationLevel::Oz));
+LPM.addPass(LoopRotatePass(Level != OptimizationLevel::Oz));
 FPM.addPass(createFunctionToLoopPassAdaptor(
 std::move(LPM), /*UseMemorySSA=*/false,
 /*UseBlockFrequencyInfo=*/false));
Index: polly/lib/Support/RegisterPasses.cpp
===
--- polly/lib/Support/RegisterPasses.cpp
+++ polly/lib/Support/RegisterPasses.cpp
@@ -474,7 +474,7 @@
 /// the analysis passes are added, skipping Polly itself.
 /// The IR may still be modified.
 static void buildCommonPollyPipeline(FunctionPassManager &PM,
- PassBuilder::OptimizationLevel Level,
+ OptimizationLevel Level,
  bool EnableForOpt) {
   PassBuilder PB;
   ScopPassManager SPM;
@@ -574,7 +574,7 @@
 }
 
 static void buildEarlyPollyPipeline(ModulePassManager &MPM,
-PassBuilder::OptimizationLevel Level) {
+OptimizationLevel Level) {
   bool EnableForOpt =
   shouldEnablePollyForOptimization() && Level.isOptimizingForSpeed();
   if (!shouldEnablePollyForDiagnostic() && !EnableForOpt)
@@ -603,7 +603,7 @@
 }
 
 static void buildLatePollyPipeline(FunctionPassManager &PM,
-   PassBuilder::OptimizationLevel Level) {
+   OptimizationLevel Level) {
   bool EnableForOpt =
   shouldEnablePollyForOptimization() && Level.isOptimizingForSpeed();
   if (!shouldEnablePollyForDiagnostic() && !EnableForOpt)
Index: polly/include/polly/Canonicalization.h
===
--- polly/include/polly/Canonicalization.h
+++ polly/include/polly/Canonicalization.h
@@ -30,7 +30,7 @@
 
 llvm::FunctionPassManager
 buildCanonicalicationPassesForNPM(llvm::ModulePassManager &MPM,
-  llvm::PassBuilder::OptimizationLevel Level);
+  llvm::OptimizationLevel Level);
 
 } // namespace polly
 
Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -173,58 +173,58 @@
 static void registerEPCallbacks(PassBuilder &PB) {
   if (tryParsePipelineText(PB, PeepholeEPPipeline))
 PB.registerPeepholeEPCallback(
-[&PB](FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) {
+[&PB](FunctionPassManager &PM, OptimizationLevel Level) {
   ExitOnError Err("Unable to parse PeepholeEP pipeline: ");
   Err(PB.parsePassPipeline(PM, PeepholeEPPipeline));
 });
   if (tryParsePipelineText(PB,
 LateLoopOptimizationsEPPipeline))
 PB.registerLateLoopOptimizationsEPCallback(
-[&PB](LoopPassManager &PM, PassBuilder::OptimizationLevel Level) {
+[&PB](LoopPassManager &PM, OptimizationLevel Level) {
   ExitOnError Err("Unable to parse LateLoopOptimizationsEP p

[clang-tools-extra] d8fd214 - NFC: Change quotes from Unicode to ASCII

2021-07-29 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2021-07-29T11:37:10+02:00
New Revision: d8fd2146daaa28d118fd7c29d63e817a8c955b81

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

LOG: NFC: Change quotes from Unicode to ASCII

This was causing some problems for Python scripts that we have.

Context: https://reviews.llvm.org/D106792

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/checks/abseil-no-internal-dependencies.rst

Removed: 




diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/abseil-no-internal-dependencies.rst 
b/clang-tools-extra/docs/clang-tidy/checks/abseil-no-internal-dependencies.rst
index bcf68ffd2d505..75e72adf5f36b 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/abseil-no-internal-dependencies.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/abseil-no-internal-dependencies.rst
@@ -4,7 +4,7 @@ abseil-no-internal-dependencies
 ===
 
 Warns if code using Abseil depends on internal details. If something is in a
-namespace that includes the word “internal”, code is not allowed to depend upon
+namespace that includes the word "internal", code is not allowed to depend upon
 it beaucse it’s an implementation detail. They cannot friend it, include it,
 you mention it or refer to it in any way. Doing so violates Abseil's
 compatibility guidelines and may result in breakage. See



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


[PATCH] D106773: [clang-format] Fix aligning with linebreaks #2

2021-07-29 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D106773#2912732 , @curdeius wrote:

> This bug fix should probably be cherry-picked into 13.x branch. WDYT?

Yeah, I wrote already an email about it. Or can (and should) I push it myself?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106773

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


[PATCH] D107051: [clang][analyzer] Improve bug report in alpha.security.ReturnPtrRange

2021-07-29 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: manas, steakhal, ASDenysPetrov, martong, gamesh411, 
dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun, whisperity.
Herald added a reviewer: Szelethus.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add some notes and track of bad return value.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107051

Files:
  clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp
  clang/test/Analysis/return-ptr-range.cpp

Index: clang/test/Analysis/return-ptr-range.cpp
===
--- clang/test/Analysis/return-ptr-range.cpp
+++ clang/test/Analysis/return-ptr-range.cpp
@@ -1,29 +1,42 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.security.ReturnPtrRange -verify %s
+// RUN1: %clang_analyze_cc1 -analyzer-checker=alpha.security.ReturnPtrRange -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.security.ReturnPtrRange -analyzer-output text -verify=notes %s
 
-int arr[10];
+
+#include "Inputs/system-header-simulator.h"
+void *malloc(size_t);
+
+int arr1[10]; // notes-note{{Memory object declared here}}
+int arr2[10]; // notes-note{{Memory object declared here}}
+int arr3[10]; // notes-note{{Memory object declared here}}
 int *ptr;
 
 int conjure_index();
 
 int *test_element_index_lifetime() {
-  do {
+  do { // notes-note{{Loop condition is false.  Exiting loop}}
 int x = conjure_index();
-ptr = arr + x;
-if (x != 20)
-  return arr; // no-warning
+ptr = arr1 + x; // notes-note{{Value assigned to 'ptr'}}
+if (x != 20) // notes-note{{Assuming 'x' is equal to 20}}
+ // notes-note@-1{{Taking false branch}}
+  return arr1; // no-warning
   } while (0);
-  return ptr; // expected-warning{{Returned pointer value points outside the original object (potential buffer overflow)}}
+  return ptr; // expected-warning{{Returned pointer value points outside the original object with size of 10 'int' objects (potential buffer overflow) [alpha.security.ReturnPtrRange]}}
+  // notes-warning@-1{{Returned pointer value points outside the original object with size of 10 'int' objects (potential buffer overflow) [alpha.security.ReturnPtrRange]}}
+  // notes-note@-2{{Returned pointer value points outside the original object with size of 10 'int' objects (potential buffer overflow)}}
 }
 
 int *test_element_index_lifetime_with_local_ptr() {
   int *local_ptr;
-  do {
+  do { // notes-note{{Loop condition is false.  Exiting loop}}
 int x = conjure_index();
-local_ptr = arr + x;
-if (x != 20)
-  return arr; // no-warning
+local_ptr = arr2 + x; // notes-note{{Value assigned to 'local_ptr'}}
+if (x != 20) // notes-note{{Assuming 'x' is equal to 20}}
+ // notes-note@-1{{Taking false branch}}
+  return arr2; // no-warning
   } while (0);
-  return local_ptr; // expected-warning{{Returned pointer value points outside the original object (potential buffer overflow)}}
+  return local_ptr; // expected-warning{{Returned pointer value points outside the original object with size of 10 'int' objects (potential buffer overflow) [alpha.security.ReturnPtrRange]}}
+// notes-warning@-1{{Returned pointer value points outside the original object with size of 10 'int' objects (potential buffer overflow) [alpha.security.ReturnPtrRange]}}
+// notes-note@-2{{Returned pointer value points outside the original object with size of 10 'int' objects (potential buffer overflow)}}
 }
 
 template 
@@ -55,17 +68,46 @@
 
 template 
 class BadIterable {
-  int buffer[N];
+  int buffer[N]; // notes-note{{Memory object declared here}}
   int *start, *finish;
 
 public:
-  BadIterable() : start(buffer), finish(buffer + N) {}
+  BadIterable() : start(buffer), finish(buffer + N) {} // notes-note{{Value assigned to 'iter.finish'}}
 
   int* begin() { return start; }
-  int* end() { return finish + 1; } // expected-warning{{Returned pointer value points outside the original object (potential buffer overflow)}}
+  int* end() { return finish + 1; } // expected-warning{{Returned pointer value with index 21 points outside the original object with size of 20 'int' objects (potential buffer overflow) [alpha.security.ReturnPtrRange]}}
+// notes-warning@-1{{Returned pointer value with index 21 points outside the original object with size of 20 'int' objects (potential buffer overflow) [alpha.security.ReturnPtrRange]}}
+// notes-note@-2{{Returned pointer value with index 21 points outside the original object with size of 20 'int' objects (potential buffer overflow)}}
 };
 
 void use_bad_iterable_object() {
-  BadIterable<20> iter;
-  iter.end();
+  BadIterable<20> iter; // notes-note{{Calling default construct

[PATCH] D91950: [clang-format] Add BreakBeforeInlineASMColon configuration

2021-07-29 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

And format what clang-format says. Then it looks good to me.




Comment at: clang/unittests/Format/FormatTest.cpp:6250
+  verifyFormat("asm volatile(\"lng\",\n"
+   " : : val);",
+   Style);

Could you add for Never and Always the code from Above?

```
  "asm(\"movq\\t%%rbx, %%rsi\\n\\t\"\n"
  "\"cpuid\\n\\t\"\n"
  "\"xchgq\\t%%rbx, %%rsi\\n\\t\"\n"
  ": \"=a\"(*rEAX), \"=S\"(*rEBX), \"=c\"(*rECX), \"=d\"(*rEDX)\n"
  ": \"a\"(value));"
```


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

https://reviews.llvm.org/D91950

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


[PATCH] D106792: [clang-tidy] Always open files using UTF-8 encoding

2021-07-29 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

Makes sense, thank you for the explanation. I've changed the problematic doc 
but this is probably still fine. Honestly, I don't really think we should have 
more Unicode symbols in the docs for generators hence this patch might not be 
needed but I'd be OK if you really still want to land it. The "problem" is that 
we'd be left with somewhat non-uniformity (there are many other Python scripts 
with `open` and inputs there might also have similar issues) but I guess that's 
what we have anyway.




Comment at: clang-tools-extra/clang-tidy/add_new_check.py:19
 
+# The documentation files are encoded using UTF-8, however on Windows the
+# default encoding might be different (e.g. CP-1252). To make sure UTF-8 is

The comments look misplaced now. Maybe add it next to the first `io.open` and 
end with "Here and elsewhere"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106792

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


[PATCH] D106792: [clang-tidy] Always open files using UTF-8 encoding

2021-07-29 Thread Andy Yankovsky via Phabricator via cfe-commits
werat added a comment.

In D106792#2912955 , @kbobyrev wrote:

> Honestly, I don't really think we should have more Unicode symbols in the 
> docs for generators

I'm not very familiar with the documentation build process, but maybe we could 
enforce only-ASCII there? Then all scripts and tools can just assume it will 
work with plan `open`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106792

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


[PATCH] D107049: [clang-repl] Re-implement clang-interpreter as a test case.

2021-07-29 Thread Lang Hames via Phabricator via cfe-commits
lhames added a comment.

LGTM, but a clang dev should probably check this out too.


Repository:
  rC Clang

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

https://reviews.llvm.org/D107049

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


[PATCH] D107004: Turn off fp reassociation in IA intrinsic header files.

2021-07-29 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon requested changes to this revision.
RKSimon added a comment.
This revision now requires changes to proceed.

I really don't support this change - -ffast-math should be allowed to perform 
aggressive folds and it makes no sense to make an exception for common 
intrinsics like these.

We should just ensure the intrinsics are suitably documented to warn that they 
are affected by fast math flags like any other operation.

An alternative, if you have specific (and common) use cases, would be to add an 
opt-in command line switch that disables fast math flags on intrinsics.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107004

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


[PATCH] D107047: [clangd] Fix the crash in getQualification

2021-07-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

thanks for chasing this down! as mentioned offline a test case like:

  namespace ns {
  extern "C" {
  typedef int foo;
  }
  foo Fo^o(int id) { return id; }
  }

in define outline should be enough to ensure it is WAI.




Comment at: clang-tools-extra/clangd/AST.cpp:129
 continue;
 }
 // Stop if this namespace is already visible at DestContext.

rather than having `!NNS` in the check below it might be nicer to put:
```
else {
// Other types of contexts cannot be spelled in code, just skip over them.
continue;
}
```

I believe continue makes sense, that way we can spell in cases like:
```
namespace ns {
extern "C" {
typedef int foo;
}
foo Foo(int id) { return id; }
}
```

`foo` should still become `ns::foo` in other contexts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107047

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


[PATCH] D107051: [clang][analyzer] Improve bug report in alpha.security.ReturnPtrRange

2021-07-29 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Aside from that `Returned pointer value points outside the original object with 
size of 10 'int' objects` reads somewhat unnatural I have no objections.
A couple of nits here and there but overall I'm pleased to see more verbose bug 
reports.




Comment at: 
clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp:83-84
 
-// FIXME: It would be nice to eventually make this diagnostic more clear,
-// e.g., by referencing the original declaration or by saying *why* this
-// reference is outside the range.
+auto ConcreteElementCount = ElementCount.getAs();
+auto ConcreteIdx = Idx.getAs();
+





Comment at: clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp:102
 // Generate a report for this bug.
-auto report =
-std::make_unique(*BT, BT->getDescription(), N);
-
+auto report = std::make_unique(*BT, SBuf, N);
 report->addRange(RetE->getSourceRange());





Comment at: clang/test/Analysis/return-ptr-range.cpp:1
-// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.security.ReturnPtrRange 
-verify %s
+// RUN1: %clang_analyze_cc1 -analyzer-checker=alpha.security.ReturnPtrRange 
-verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.security.ReturnPtrRange 
-analyzer-output text -verify=notes %s

Is `RUN1` intentional? If so, what does it do?



Comment at: clang/test/Analysis/return-ptr-range.cpp:2
+// RUN1: %clang_analyze_cc1 -analyzer-checker=alpha.security.ReturnPtrRange 
-verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.security.ReturnPtrRange 
-analyzer-output text -verify=notes %s
 

You can specify multiple match prefixes.
If you were passing `-verify=expected,notes`, you would not have to duplicate 
each warning.



Comment at: clang/test/Analysis/return-ptr-range.cpp:8-10
+int arr1[10]; // notes-note{{Memory object declared here}}
+int arr2[10]; // notes-note{{Memory object declared here}}
+int arr3[10]; // notes-note{{Memory object declared here}}

Only a single array should be enough.
You can specify the match count for the diagnostic verifier.

`// notes-note 3 {{Memory object...}}` Will succeed only if exactly 3 times 
matched.



Comment at: clang/test/Analysis/return-ptr-range.cpp:11
+int arr3[10]; // notes-note{{Memory object declared here}}
 int *ptr;
 

This is not used in every test case. I would recommend moving this to the 
function parameter where it's actually being used.



Comment at: clang/test/Analysis/return-ptr-range.cpp:19-20
+ptr = arr1 + x; // notes-note{{Value assigned to 'ptr'}}
+if (x != 20) // notes-note{{Assuming 'x' is equal to 20}}
+ // notes-note@-1{{Taking false branch}}
+  return arr1; // no-warning

This is probably more of a taste.
I would prefer fewer indentations.
The same applies everywhere.



Comment at: clang/test/Analysis/return-ptr-range.cpp:23
   } while (0);
-  return ptr; // expected-warning{{Returned pointer value points outside the 
original object (potential buffer overflow)}}
+  return ptr; // expected-warning{{Returned pointer value points outside the 
original object with size of 10 'int' objects (potential buffer overflow) 
[alpha.security.ReturnPtrRange]}}
+  // notes-warning@-1{{Returned pointer value points outside the 
original object with size of 10 'int' objects (potential buffer overflow) 
[alpha.security.ReturnPtrRange]}}

I think it's fine to leave the common suffix `(potential ...` out of the 
matched string. They give only a little value.
The same applies everywhere, except keeping a single one maybe.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107051

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


[PATCH] D106773: [clang-format] Fix aligning with linebreaks #2

2021-07-29 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a subscriber: tstellar.
curdeius added a comment.

In D106773#2912925 , 
@HazardyKnusperkeks wrote:

> In D106773#2912732 , @curdeius 
> wrote:
>
>> This bug fix should probably be cherry-picked into 13.x branch. WDYT?
>
> Yeah, I wrote already an email about it. Or can (and should) I push it myself?

I think we should ask @tstellar for permission before cherry-picking.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106773

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


[PATCH] D98709: [clang-tidy] New feature --skip-headers, part 1, LocFilter

2021-07-29 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 362702.
chh added a comment.

sync to the latest source; apply clang-format; add new skip-headers-4.cpp test;
skip modernize-use-nullptr warnings in header files in UseNullptrCheck.cpp


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

https://reviews.llvm.org/D98709

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/a.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/unused-using-decls.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-2.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-3.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-4.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1202,6 +1202,8 @@
   if (!DeclNode) {
 return true;
   }
+  if (Options.Filter && Options.Filter->skipLocation(DeclNode->getLocation()))
+return true;
 
   bool ScopedTraversal =
   TraversingASTNodeNotSpelledInSource || DeclNode->isImplicit();
@@ -1232,6 +1234,13 @@
   if (!StmtNode) {
 return true;
   }
+  // When a function call is in the main file or wanted header fi

[PATCH] D98710: [clang-tidy] New feature --skip-headers, part 1, setTraversalScope

2021-07-29 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 362704.
chh added a comment.

sync to the latest source; apply clang-format; add new skip-headers-4.cpp test


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

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/a.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/unused-using-decls.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-2.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-3.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-4.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/Frontend/MultiplexConsumer.h

Index: clang/include/clang/Frontend/MultiplexConsumer.h
===
--- clang/include/clang/Frontend/MultiplexConsumer.h
+++ clang/include/clang/Frontend/MultiplexConsumer.h
@@ -77,8 +77,9 @@
   void InitializeSema(Sema &S) override;
   void ForgetSema() override;
 
-private:
+protected:
   std::vector> Consumers; // Owns these.
+private:
   std::unique_ptr MutationListener;
   std::unique_ptr DeserializationListener;
 };
Index: clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -line-filter='[{"name":"line-filter.cpp","lines":[[18,18],[22,22]]},{"name":"header1.h","lines":[[1,2]]},{"name":"header2.h"},{"name":"header3.h"}]' -header-filter='header[12]\.h$' %s -- -I %S/Inputs/line-filter 2>&1 | FileCheck %s
+// RUN: clang-tidy --skip-headers=0 -checks='-*,google-explicit-constructor' -line-filter='[{"name":"line-filter.cpp","lines":[[18,18],[22,22]]},{"name":"header1.h"

[PATCH] D107047: [clangd] Fix the crash in getQualification

2021-07-29 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 362707.
kbobyrev added a comment.

Make the controol flow less confusing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107047

Files:
  clang-tools-extra/clangd/AST.cpp


Index: clang-tools-extra/clangd/AST.cpp
===
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -119,14 +119,15 @@
   (void)ReachedNS;
   NNS = NestedNameSpecifier::Create(Context, nullptr, false,
 TD->getTypeForDecl());
-} else {
+} else if (auto *NSD = llvm::dyn_cast(CurContext)) {
   ReachedNS = true;
-  auto *NSD = llvm::cast(CurContext);
   NNS = NestedNameSpecifier::Create(Context, nullptr, NSD);
-  // Anonymous and inline namespace names are not spelled while qualifying 
a
-  // name, so skip those.
+  // Anonymous and inline namespace names are not spelled while qualifying
+  // a name, so skip those.
   if (NSD->isAnonymousNamespace() || NSD->isInlineNamespace())
 continue;
+} else {
+  continue;
 }
 // Stop if this namespace is already visible at DestContext.
 if (IsVisible(NNS))


Index: clang-tools-extra/clangd/AST.cpp
===
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -119,14 +119,15 @@
   (void)ReachedNS;
   NNS = NestedNameSpecifier::Create(Context, nullptr, false,
 TD->getTypeForDecl());
-} else {
+} else if (auto *NSD = llvm::dyn_cast(CurContext)) {
   ReachedNS = true;
-  auto *NSD = llvm::cast(CurContext);
   NNS = NestedNameSpecifier::Create(Context, nullptr, NSD);
-  // Anonymous and inline namespace names are not spelled while qualifying a
-  // name, so skip those.
+  // Anonymous and inline namespace names are not spelled while qualifying
+  // a name, so skip those.
   if (NSD->isAnonymousNamespace() || NSD->isInlineNamespace())
 continue;
+} else {
+  continue;
 }
 // Stop if this namespace is already visible at DestContext.
 if (IsVisible(NNS))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks when an FP atomic instruction is converted into a CAS loop or unsafe hardware instruction for GFX90A

2021-07-29 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 362470.
gandhi21299 added a comment.

- added an OpenCL test to check for unsafe HW instructions
- CUDA forces CAS loop over using unsafe HW instructions even with 
`-munsafe-fp-atomics`, eliminated that test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

Files:
  clang/test/CodeGenCUDA/fp-atomics-optremarks.cu
  clang/test/CodeGenOpenCL/fp-atomics-optremarks-gfx90a.cl
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.h

Index: llvm/lib/Target/AMDGPU/SIISelLowering.h
===
--- llvm/lib/Target/AMDGPU/SIISelLowering.h
+++ llvm/lib/Target/AMDGPU/SIISelLowering.h
@@ -30,6 +30,7 @@
 class SITargetLowering final : public AMDGPUTargetLowering {
 private:
   const GCNSubtarget *Subtarget;
+  OptimizationRemarkEmitter *ORE;
 
 public:
   MVT getRegisterTypeForCallingConv(LLVMContext &Context,
Index: llvm/lib/Target/AMDGPU/SIISelLowering.cpp
===
--- llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -19,6 +19,7 @@
 #include "SIRegisterInfo.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/LegacyDivergenceAnalysis.h"
+#include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/BinaryFormat/ELF.h"
 #include "llvm/CodeGen/Analysis.h"
 #include "llvm/CodeGen/FunctionLoweringInfo.h"
@@ -12117,6 +12118,27 @@
   return DenormMode == DenormalMode::getIEEE();
 }
 
+static TargetLowering::AtomicExpansionKind
+atomicExpandReturn(OptimizationRemarkEmitter *ORE, AtomicRMWInst *RMW,
+   TargetLowering::AtomicExpansionKind Kind, bool UnsafeFlag) {
+  ORE = new OptimizationRemarkEmitter(RMW->getFunction());
+  if (Kind == TargetLowering::AtomicExpansionKind::CmpXChg) {
+ORE->emit([&]() {
+  OptimizationRemark Remark(DEBUG_TYPE, "Passed", RMW->getFunction());
+  Remark << "An FP atomic instruction was expanded into a CAS loop.";
+  return Remark;
+});
+  } else if (Kind == TargetLowering::AtomicExpansionKind::None && UnsafeFlag) {
+ORE->emit([&]() {
+  OptimizationRemark Remark(DEBUG_TYPE, "Passed", RMW->getFunction());
+  Remark << "An unsafe hardware instruction was generated.";
+  return Remark;
+});
+  }
+  delete ORE;
+  return Kind;
+}
+
 TargetLowering::AtomicExpansionKind
 SITargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const {
   switch (RMW->getOperation()) {
@@ -12132,35 +12154,42 @@
   return AtomicExpansionKind::CmpXChg;
 
 unsigned AS = RMW->getPointerAddressSpace();
-
+bool UnsafeFPAtomicFlag = RMW->getFunction()
+  ->getFnAttribute("amdgpu-unsafe-fp-atomics")
+  .getValueAsBool();
 if ((AS == AMDGPUAS::GLOBAL_ADDRESS || AS == AMDGPUAS::FLAT_ADDRESS) &&
  Subtarget->hasAtomicFaddInsts()) {
   // The amdgpu-unsafe-fp-atomics attribute enables generation of unsafe
   // floating point atomic instructions. May generate more efficient code,
   // but may not respect rounding and denormal modes, and may give incorrect
   // results for certain memory destinations.
-  if (RMW->getFunction()
-  ->getFnAttribute("amdgpu-unsafe-fp-atomics")
-  .getValueAsString() != "true")
-return AtomicExpansionKind::CmpXChg;
+  if (!UnsafeFPAtomicFlag)
+return atomicExpandReturn(ORE, RMW, AtomicExpansionKind::CmpXChg,
+  UnsafeFPAtomicFlag);
+  atomicExpandReturn(ORE, RMW, AtomicExpansionKind::None, UnsafeFPAtomicFlag);
 
   if (Subtarget->hasGFX90AInsts()) {
 if (Ty->isFloatTy() && AS == AMDGPUAS::FLAT_ADDRESS)
-  return AtomicExpansionKind::CmpXChg;
+  return atomicExpandReturn(ORE, RMW, AtomicExpansionKind::CmpXChg,
+UnsafeFPAtomicFlag);
 
 auto SSID = RMW->getSyncScopeID();
 if (SSID == SyncScope::System ||
 SSID == RMW->getContext().getOrInsertSyncScopeID("one-as"))
-  return AtomicExpansionKind::CmpXChg;
+  return atomicExpandReturn(ORE, RMW, AtomicExpansionKind::CmpXChg,
+UnsafeFPAtomicFlag);
 
-return AtomicExpansionKind::None;
+return atomicExpandReturn(ORE, RMW, AtomicExpansionKind::None,
+  UnsafeFPAtomicFlag);
   }
 
   if (AS == AMDGPUAS::FLAT_ADDRESS)
-return AtomicExpansionKind::CmpXChg;
+return atomicExpandReturn(ORE, RMW, AtomicExpansionKind::CmpXChg,
+  UnsafeFPAtomicFlag);
 
-  return RMW->use_empty() ? AtomicExpansionKind::None
-  : AtomicExpansionKind::CmpXChg;
+  auto Kind = RMW->use_empty() ? AtomicExpansionKind::None
+   

[PATCH] D106909: [clang] Add clang builtins support for gfx90a

2021-07-29 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 362487.
gandhi21299 added a comment.

- added scope argument
- removed irrelevant tests and updated them
- replaced __constant by __generic qualifier for two of the test functions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106909

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenOpenCL/builtins-fp-atomics.cl

Index: clang/test/CodeGenOpenCL/builtins-fp-atomics.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/builtins-fp-atomics.cl
@@ -0,0 +1,133 @@
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx90a \
+// RUN:   %s -S -emit-llvm -o - | FileCheck %s -check-prefix=CHECK
+
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx90a \
+// RUN:   -S -o - %s | FileCheck -check-prefix=GFX90A %s
+
+
+typedef enum memory_order {
+  memory_order_relaxed = __ATOMIC_RELAXED,
+  memory_order_acquire = __ATOMIC_ACQUIRE,
+  memory_order_release = __ATOMIC_RELEASE,
+  memory_order_acq_rel = __ATOMIC_ACQ_REL,
+  memory_order_seq_cst = __ATOMIC_SEQ_CST
+} memory_order;
+
+typedef half __attribute__((ext_vector_type(2))) half2;
+
+// CHECK-LABEL: test_global_add
+// CHECK: tail call double @llvm.amdgcn.global.atomic.fadd.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A:  test_global_add
+// GFX90A:  global_atomic_add_f64 v2, v[0:1], s[0:1]
+// GFX90A:  s_endpgm
+kernel void test_global_add(__global double *addr, double x) {
+  __builtin_amdgcn_global_atomic_fadd_f64(addr, x, memory_order_relaxed, "workgroup");
+}
+
+// CHECK-LABEL: test_global_addf
+// CHECK: tail call float @llvm.amdgcn.global.atomic.fadd.f32.p1f32.f32(float addrspace(1)* %{{.*}}, float %{{.*}})
+// GFX90A-LABEL: test_global_addf
+// GFX90A: global_atomic_add_f32 v0, v1, s[0:1]
+// GFX90A: s_endpgm
+kernel void test_global_addf(__global float *addr, float x) {
+  __builtin_amdgcn_global_atomic_fadd_f32(addr, x, memory_order_relaxed, "workgroup");
+}
+
+// CHECK-LABEL: test_global_add2h
+// CHECK: tail call <2 x half> @llvm.amdgcn.global.atomic.fadd.v2f16.p1v2f16.v2f16(<2 x half> addrspace(1)* %{{.*}}, <2 x half> %{{.*}})
+// GFX90A-LABEL: test_global_add2h
+// GFX90A: global_atomic_pk_add_f16 v0, v1, s[0:1]
+// GFX90A: s_endpgm
+kernel void test_global_add2h(__global half2 *addr, half2 x){
+  __builtin_amdgcn_global_atomic_fadd_2f16(addr, x, memory_order_relaxed, "workgroup");
+}
+
+// CHECK-LABEL: test_global_global_min
+// CHECK: tail call double @llvm.amdgcn.global.atomic.fmin.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_global_global_min
+// GFX90A:  global_atomic_min_f64 v2, v[0:1], s[0:1]
+// GFX90A:  s_endpgm
+kernel void test_global_global_min(__global double *addr, double x){
+  __builtin_amdgcn_global_atomic_fmin_f64(addr, x, memory_order_relaxed, "workgroup");
+}
+
+// CHECK-LABEL: test_global_max
+// CHECK: tail call double @llvm.amdgcn.global.atomic.fmax.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A:  test_global_max
+// GFX90A:  global_atomic_max_f64 v2, v[0:1], s[0:1]
+// GFX90A:  s_endpgm
+kernel void test_global_max(__global double *addr, double x){
+  __builtin_amdgcn_global_atomic_fmax_f64(addr, x, memory_order_relaxed, "workgroup");
+}
+
+// CHECK-LABEL: test_flat_add_local
+// CHECK: tail call double @llvm.amdgcn.flat.atomic.fadd.f64.p3f64.f64(double addrspace(3)* %{{.*}}, double %{{.*}})
+// GFX90A:  test_flat_add_local
+// GFX90A:  ds_add_f64 v2, v[0:1]
+// GFX90A:  s_endpgm
+kernel void test_flat_add_local(__local double *addr, double x){
+  __builtin_amdgcn_flat_atomic_fadd_f64(addr, x, memory_order_relaxed, "workgroup");
+}
+
+// CHECK-LABEL: test_flat_global_add
+// CHECK: tail call double @llvm.amdgcn.flat.atomic.fadd.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A:  test_flat_global_add
+// GFX90A:  global_atomic_add_f64
+// GFX90A:  s_endpgm
+kernel void test_flat_global_add(__global double *addr, double x){
+  __builtin_amdgcn_flat_atomic_fadd_f64(addr, x, memory_order_relaxed, "workgroup");
+}
+
+// CHECK-LABEL: test_flat_min_constant
+// CHECK: tail call double @llvm.amdgcn.flat.atomic.fmin.f64.p4f64.f64(double addrspace(4)* %{{.*}}, double %{{.*}})
+// GFX90A:  test_flat_min_constant
+// GFX90A:  global_atomic_min_f64
+// GFX90A:  s_endpgm
+kernel void test_flat_min_constant(__generic double *addr, double x){
+  __builtin_amdgcn_flat_atomic_fmin_f64(addr, x, memory_order_relaxed, "workgroup");
+}
+
+// CHECK-LABEL: test_flat_global_min
+// CHECK: tail call double @llvm.amdgcn.flat.atomic.fmin.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A:  test_flat_global_min
+// GFX90A:  global_atomic_min_f64
+// GFX90A:  s_endpgm
+kernel void test_flat_global_min(__global double *addr, double x){
+  __builtin

[PATCH] D106899: [LLVM][NFC] Remove LLVM_ATTRIBUTE_NORETURN and use [[noreturn]] directly

2021-07-29 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 362492.
gAlfonso-bit added a comment.

Fix clang format


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

https://reviews.llvm.org/D106899

Files:
  clang-tools-extra/pp-trace/PPTrace.cpp
  clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
  flang/include/flang/Optimizer/Support/FatalError.h
  lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
  lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp
  llvm/include/llvm/Support/Compiler.h

Index: llvm/include/llvm/Support/Compiler.h
===
--- llvm/include/llvm/Support/Compiler.h
+++ llvm/include/llvm/Support/Compiler.h
@@ -242,12 +242,12 @@
 #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline
 #endif
 
-#ifdef __GNUC__
-#define LLVM_ATTRIBUTE_NORETURN __attribute__((noreturn))
-#elif defined(_MSC_VER)
-#define LLVM_ATTRIBUTE_NORETURN __declspec(noreturn)
+// C++ has [[noreturn]]. We are going to remove this eventually, but for now
+// let's keep it
+#ifdef(__cplusplus)
+#define LLVM_ATTRIBUTE_NORETURN [[noreturn]]
 #else
-#define LLVM_ATTRIBUTE_NORETURN
+#define LLVM_ATTRIBUTE_NORETURN _Noreturn
 #endif
 
 #if __has_attribute(returns_nonnull) || LLVM_GNUC_PREREQ(4, 9, 0)
Index: lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp
===
--- lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp
+++ lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp
@@ -29,7 +29,7 @@
 #if defined(__arm64__) || defined(__aarch64__)
 namespace {
 
-void LLVM_ATTRIBUTE_NORETURN Child() {
+[[noreturn]] void Child() {
   if (ptrace(PTRACE_TRACEME, 0, nullptr, nullptr) == -1)
 _exit(1);
 
Index: lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
===
--- lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
+++ lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
@@ -20,8 +20,8 @@
 #include 
 #include 
 
-#include 
 #include 
+#include 
 
 #ifdef __ANDROID__
 #include 
@@ -46,8 +46,7 @@
 #endif
 }
 
-static void LLVM_ATTRIBUTE_NORETURN ExitWithError(int error_fd,
-  const char *operation) {
+[[noreturn]] static void ExitWithError(int error_fd, const char *operation) {
   int err = errno;
   llvm::raw_fd_ostream os(error_fd, true);
   os << operation << " failed: " << llvm::sys::StrError(err);
@@ -55,7 +54,8 @@
   _exit(1);
 }
 
-static void DisableASLRIfRequested(int error_fd, const ProcessLaunchInfo &info) {
+static void DisableASLRIfRequested(int error_fd,
+   const ProcessLaunchInfo &info) {
 #if defined(__linux__)
   if (info.GetFlags().Test(lldb::eLaunchFlagDisableASLR)) {
 const unsigned long personality_get_current = 0x;
@@ -72,8 +72,8 @@
 
 static void DupDescriptor(int error_fd, const FileSpec &file_spec, int fd,
   int flags) {
-  int target_fd = llvm::sys::RetryAfterSignal(-1, ::open,
-  file_spec.GetCString(), flags, 0666);
+  int target_fd = llvm::sys::RetryAfterSignal(
+  -1, ::open, file_spec.GetCString(), flags, 0666);
 
   if (target_fd == -1)
 ExitWithError(error_fd, "DupDescriptor-open");
@@ -88,8 +88,8 @@
   return;
 }
 
-static void LLVM_ATTRIBUTE_NORETURN ChildFunc(int error_fd,
-  const ProcessLaunchInfo &info) {
+[[noreturn]] static void ChildFunc(int error_fd,
+   const ProcessLaunchInfo &info) {
   if (info.GetFlags().Test(eLaunchFlagLaunchInSeparateProcessGroup)) {
 if (setpgid(0, 0) != 0)
   ExitWithError(error_fd, "setpgid");
Index: flang/include/flang/Optimizer/Support/FatalError.h
===
--- flang/include/flang/Optimizer/Support/FatalError.h
+++ flang/include/flang/Optimizer/Support/FatalError.h
@@ -20,8 +20,8 @@
 
 /// Fatal error reporting helper. Report a fatal error with a source location
 /// and immediately abort flang.
-LLVM_ATTRIBUTE_NORETURN inline void emitFatalError(mlir::Location loc,
-   const llvm::Twine &message) {
+[[noreturn]] inline void emitFatalError(mlir::Location loc,
+const llvm::Twine &message) {
   mlir::emitError(loc, message);
   llvm::report_fatal_error("aborting");
 }
Index: clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
===
--- clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -614,7 +614,7 @@
 return It->second.Root;
   }
 
-  LLVM_ATTRIBUTE_NORETURN void PrintFatalError(llvm::Twine const &Msg) const {
+  [[noreturn]] void PrintFatalError(llvm::Twine const &Msg) const {
 assert(EvaluatingRecord && "not evaluating a record?");
 llvm::PrintFatalError(EvaluatingRecord->getLoc(), Msg);
   }
Index: cl

[PATCH] D106899: [LLVM][NFC] Remove LLVM_ATTRIBUTE_NORETURN and use [[noreturn]] directly

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

Drop llvm/include/llvm/Support/Compiler.h change.


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

https://reviews.llvm.org/D106899

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


[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks when an FP atomic instruction is converted into a CAS loop or unsafe hardware instruction for GFX90A

2021-07-29 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 362518.
gandhi21299 added a comment.

- code format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

Files:
  clang/test/CodeGenCUDA/fp-atomics-optremarks.cu
  clang/test/CodeGenOpenCL/fp-atomics-optremarks-gfx90a.cl
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.h

Index: llvm/lib/Target/AMDGPU/SIISelLowering.h
===
--- llvm/lib/Target/AMDGPU/SIISelLowering.h
+++ llvm/lib/Target/AMDGPU/SIISelLowering.h
@@ -30,6 +30,7 @@
 class SITargetLowering final : public AMDGPUTargetLowering {
 private:
   const GCNSubtarget *Subtarget;
+  OptimizationRemarkEmitter *ORE;
 
 public:
   MVT getRegisterTypeForCallingConv(LLVMContext &Context,
Index: llvm/lib/Target/AMDGPU/SIISelLowering.cpp
===
--- llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -19,6 +19,7 @@
 #include "SIRegisterInfo.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/LegacyDivergenceAnalysis.h"
+#include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/BinaryFormat/ELF.h"
 #include "llvm/CodeGen/Analysis.h"
 #include "llvm/CodeGen/FunctionLoweringInfo.h"
@@ -12117,6 +12118,27 @@
   return DenormMode == DenormalMode::getIEEE();
 }
 
+static TargetLowering::AtomicExpansionKind
+atomicExpandReturn(OptimizationRemarkEmitter *ORE, AtomicRMWInst *RMW,
+   TargetLowering::AtomicExpansionKind Kind, bool UnsafeFlag) {
+  ORE = new OptimizationRemarkEmitter(RMW->getFunction());
+  if (Kind == TargetLowering::AtomicExpansionKind::CmpXChg) {
+ORE->emit([&]() {
+  OptimizationRemark Remark(DEBUG_TYPE, "Passed", RMW->getFunction());
+  Remark << "An FP atomic instruction was expanded into a CAS loop.";
+  return Remark;
+});
+  } else if (Kind == TargetLowering::AtomicExpansionKind::None && UnsafeFlag) {
+ORE->emit([&]() {
+  OptimizationRemark Remark(DEBUG_TYPE, "Passed", RMW->getFunction());
+  Remark << "An unsafe hardware instruction was generated.";
+  return Remark;
+});
+  }
+  delete ORE;
+  return Kind;
+}
+
 TargetLowering::AtomicExpansionKind
 SITargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const {
   switch (RMW->getOperation()) {
@@ -12132,35 +12154,43 @@
   return AtomicExpansionKind::CmpXChg;
 
 unsigned AS = RMW->getPointerAddressSpace();
-
+bool UnsafeFPAtomicFlag = RMW->getFunction()
+  ->getFnAttribute("amdgpu-unsafe-fp-atomics")
+  .getValueAsBool();
 if ((AS == AMDGPUAS::GLOBAL_ADDRESS || AS == AMDGPUAS::FLAT_ADDRESS) &&
  Subtarget->hasAtomicFaddInsts()) {
   // The amdgpu-unsafe-fp-atomics attribute enables generation of unsafe
   // floating point atomic instructions. May generate more efficient code,
   // but may not respect rounding and denormal modes, and may give incorrect
   // results for certain memory destinations.
-  if (RMW->getFunction()
-  ->getFnAttribute("amdgpu-unsafe-fp-atomics")
-  .getValueAsString() != "true")
-return AtomicExpansionKind::CmpXChg;
+  if (!UnsafeFPAtomicFlag)
+return atomicExpandReturn(ORE, RMW, AtomicExpansionKind::CmpXChg,
+  UnsafeFPAtomicFlag);
+  atomicExpandReturn(ORE, RMW, AtomicExpansionKind::None, 
+UnsafeFPAtomicFlag);
 
   if (Subtarget->hasGFX90AInsts()) {
 if (Ty->isFloatTy() && AS == AMDGPUAS::FLAT_ADDRESS)
-  return AtomicExpansionKind::CmpXChg;
+  return atomicExpandReturn(ORE, RMW, AtomicExpansionKind::CmpXChg,
+UnsafeFPAtomicFlag);
 
 auto SSID = RMW->getSyncScopeID();
 if (SSID == SyncScope::System ||
 SSID == RMW->getContext().getOrInsertSyncScopeID("one-as"))
-  return AtomicExpansionKind::CmpXChg;
+  return atomicExpandReturn(ORE, RMW, AtomicExpansionKind::CmpXChg,
+UnsafeFPAtomicFlag);
 
-return AtomicExpansionKind::None;
+return atomicExpandReturn(ORE, RMW, AtomicExpansionKind::None,
+  UnsafeFPAtomicFlag);
   }
 
   if (AS == AMDGPUAS::FLAT_ADDRESS)
-return AtomicExpansionKind::CmpXChg;
+return atomicExpandReturn(ORE, RMW, AtomicExpansionKind::CmpXChg,
+  UnsafeFPAtomicFlag);
 
-  return RMW->use_empty() ? AtomicExpansionKind::None
-  : AtomicExpansionKind::CmpXChg;
+  auto Kind = RMW->use_empty() ? AtomicExpansionKind::None
+   : AtomicExpansionKind::CmpXChg;
+  return atomicExpandReturn(ORE, RMW, Kind, UnsafeFPAtomicFlag);
 }
 
 // DS FP at

[PATCH] D106909: [clang] Add clang builtins support for gfx90a

2021-07-29 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 362522.
gandhi21299 added a comment.
Herald added subscribers: llvm-commits, foad, hiraditya.
Herald added a project: LLVM.

- removed `kernel` from functions taking in `__generic` qualified `addr`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106909

Files:
  clang/test/CodeGenCUDA/fp-atomics-optremarks.cu
  clang/test/CodeGenOpenCL/builtins-fp-atomics.cl
  clang/test/CodeGenOpenCL/fp-atomics-optremarks-gfx90a.cl
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.h

Index: llvm/lib/Target/AMDGPU/SIISelLowering.h
===
--- llvm/lib/Target/AMDGPU/SIISelLowering.h
+++ llvm/lib/Target/AMDGPU/SIISelLowering.h
@@ -30,6 +30,7 @@
 class SITargetLowering final : public AMDGPUTargetLowering {
 private:
   const GCNSubtarget *Subtarget;
+  OptimizationRemarkEmitter *ORE;
 
 public:
   MVT getRegisterTypeForCallingConv(LLVMContext &Context,
Index: llvm/lib/Target/AMDGPU/SIISelLowering.cpp
===
--- llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -19,6 +19,7 @@
 #include "SIRegisterInfo.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/LegacyDivergenceAnalysis.h"
+#include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/BinaryFormat/ELF.h"
 #include "llvm/CodeGen/Analysis.h"
 #include "llvm/CodeGen/FunctionLoweringInfo.h"
@@ -12117,6 +12118,27 @@
   return DenormMode == DenormalMode::getIEEE();
 }
 
+static TargetLowering::AtomicExpansionKind
+atomicExpandReturn(OptimizationRemarkEmitter *ORE, AtomicRMWInst *RMW,
+   TargetLowering::AtomicExpansionKind Kind, bool UnsafeFlag) {
+  ORE = new OptimizationRemarkEmitter(RMW->getFunction());
+  if (Kind == TargetLowering::AtomicExpansionKind::CmpXChg) {
+ORE->emit([&]() {
+  OptimizationRemark Remark(DEBUG_TYPE, "Passed", RMW->getFunction());
+  Remark << "An FP atomic instruction was expanded into a CAS loop.";
+  return Remark;
+});
+  } else if (Kind == TargetLowering::AtomicExpansionKind::None && UnsafeFlag) {
+ORE->emit([&]() {
+  OptimizationRemark Remark(DEBUG_TYPE, "Passed", RMW->getFunction());
+  Remark << "An unsafe hardware instruction was generated.";
+  return Remark;
+});
+  }
+  delete ORE;
+  return Kind;
+}
+
 TargetLowering::AtomicExpansionKind
 SITargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const {
   switch (RMW->getOperation()) {
@@ -12132,35 +12154,43 @@
   return AtomicExpansionKind::CmpXChg;
 
 unsigned AS = RMW->getPointerAddressSpace();
-
+bool UnsafeFPAtomicFlag = RMW->getFunction()
+  ->getFnAttribute("amdgpu-unsafe-fp-atomics")
+  .getValueAsBool();
 if ((AS == AMDGPUAS::GLOBAL_ADDRESS || AS == AMDGPUAS::FLAT_ADDRESS) &&
  Subtarget->hasAtomicFaddInsts()) {
   // The amdgpu-unsafe-fp-atomics attribute enables generation of unsafe
   // floating point atomic instructions. May generate more efficient code,
   // but may not respect rounding and denormal modes, and may give incorrect
   // results for certain memory destinations.
-  if (RMW->getFunction()
-  ->getFnAttribute("amdgpu-unsafe-fp-atomics")
-  .getValueAsString() != "true")
-return AtomicExpansionKind::CmpXChg;
+  if (!UnsafeFPAtomicFlag)
+return atomicExpandReturn(ORE, RMW, AtomicExpansionKind::CmpXChg,
+  UnsafeFPAtomicFlag);
+  atomicExpandReturn(ORE, RMW, AtomicExpansionKind::None, 
+UnsafeFPAtomicFlag);
 
   if (Subtarget->hasGFX90AInsts()) {
 if (Ty->isFloatTy() && AS == AMDGPUAS::FLAT_ADDRESS)
-  return AtomicExpansionKind::CmpXChg;
+  return atomicExpandReturn(ORE, RMW, AtomicExpansionKind::CmpXChg,
+UnsafeFPAtomicFlag);
 
 auto SSID = RMW->getSyncScopeID();
 if (SSID == SyncScope::System ||
 SSID == RMW->getContext().getOrInsertSyncScopeID("one-as"))
-  return AtomicExpansionKind::CmpXChg;
+  return atomicExpandReturn(ORE, RMW, AtomicExpansionKind::CmpXChg,
+UnsafeFPAtomicFlag);
 
-return AtomicExpansionKind::None;
+return atomicExpandReturn(ORE, RMW, AtomicExpansionKind::None,
+  UnsafeFPAtomicFlag);
   }
 
   if (AS == AMDGPUAS::FLAT_ADDRESS)
-return AtomicExpansionKind::CmpXChg;
+return atomicExpandReturn(ORE, RMW, AtomicExpansionKind::CmpXChg,
+  UnsafeFPAtomicFlag);
 
-  return RMW->use_empty() ? AtomicExpansionKind::None
-  : AtomicExpansionKind::CmpXChg;
+  auto Kind = RMW->use_emp

[PATCH] D106899: [LLVM][NFC] Replace LLVM_ATTRIBUTE_NORETURN with [[noreturn]]

2021-07-29 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 362533.
gAlfonso-bit retitled this revision from "[LLVM][NFC] Remove 
LLVM_ATTRIBUTE_NORETURN and use [[noreturn]] directly" to "[LLVM][NFC] Replace 
LLVM_ATTRIBUTE_NORETURN with [[noreturn]]".
gAlfonso-bit added a comment.

Removed Compiler.h changes


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

https://reviews.llvm.org/D106899

Files:
  clang-tools-extra/pp-trace/PPTrace.cpp
  clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
  flang/include/flang/Optimizer/Support/FatalError.h
  lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
  lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp

Index: lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp
===
--- lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp
+++ lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp
@@ -29,7 +29,7 @@
 #if defined(__arm64__) || defined(__aarch64__)
 namespace {
 
-void LLVM_ATTRIBUTE_NORETURN Child() {
+[[noreturn]] void Child() {
   if (ptrace(PTRACE_TRACEME, 0, nullptr, nullptr) == -1)
 _exit(1);
 
Index: lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
===
--- lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
+++ lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
@@ -20,8 +20,8 @@
 #include 
 #include 
 
-#include 
 #include 
+#include 
 
 #ifdef __ANDROID__
 #include 
@@ -46,8 +46,7 @@
 #endif
 }
 
-static void LLVM_ATTRIBUTE_NORETURN ExitWithError(int error_fd,
-  const char *operation) {
+[[noreturn]] static void ExitWithError(int error_fd, const char *operation) {
   int err = errno;
   llvm::raw_fd_ostream os(error_fd, true);
   os << operation << " failed: " << llvm::sys::StrError(err);
@@ -55,7 +54,8 @@
   _exit(1);
 }
 
-static void DisableASLRIfRequested(int error_fd, const ProcessLaunchInfo &info) {
+static void DisableASLRIfRequested(int error_fd,
+   const ProcessLaunchInfo &info) {
 #if defined(__linux__)
   if (info.GetFlags().Test(lldb::eLaunchFlagDisableASLR)) {
 const unsigned long personality_get_current = 0x;
@@ -72,8 +72,8 @@
 
 static void DupDescriptor(int error_fd, const FileSpec &file_spec, int fd,
   int flags) {
-  int target_fd = llvm::sys::RetryAfterSignal(-1, ::open,
-  file_spec.GetCString(), flags, 0666);
+  int target_fd = llvm::sys::RetryAfterSignal(
+  -1, ::open, file_spec.GetCString(), flags, 0666);
 
   if (target_fd == -1)
 ExitWithError(error_fd, "DupDescriptor-open");
@@ -88,8 +88,8 @@
   return;
 }
 
-static void LLVM_ATTRIBUTE_NORETURN ChildFunc(int error_fd,
-  const ProcessLaunchInfo &info) {
+[[noreturn]] static void ChildFunc(int error_fd,
+   const ProcessLaunchInfo &info) {
   if (info.GetFlags().Test(eLaunchFlagLaunchInSeparateProcessGroup)) {
 if (setpgid(0, 0) != 0)
   ExitWithError(error_fd, "setpgid");
Index: flang/include/flang/Optimizer/Support/FatalError.h
===
--- flang/include/flang/Optimizer/Support/FatalError.h
+++ flang/include/flang/Optimizer/Support/FatalError.h
@@ -20,8 +20,8 @@
 
 /// Fatal error reporting helper. Report a fatal error with a source location
 /// and immediately abort flang.
-LLVM_ATTRIBUTE_NORETURN inline void emitFatalError(mlir::Location loc,
-   const llvm::Twine &message) {
+[[noreturn]] inline void emitFatalError(mlir::Location loc,
+const llvm::Twine &message) {
   mlir::emitError(loc, message);
   llvm::report_fatal_error("aborting");
 }
Index: clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
===
--- clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -614,7 +614,7 @@
 return It->second.Root;
   }
 
-  LLVM_ATTRIBUTE_NORETURN void PrintFatalError(llvm::Twine const &Msg) const {
+  [[noreturn]] void PrintFatalError(llvm::Twine const &Msg) const {
 assert(EvaluatingRecord && "not evaluating a record?");
 llvm::PrintFatalError(EvaluatingRecord->getLoc(), Msg);
   }
Index: clang-tools-extra/pp-trace/PPTrace.cpp
===
--- clang-tools-extra/pp-trace/PPTrace.cpp
+++ clang-tools-extra/pp-trace/PPTrace.cpp
@@ -69,7 +69,7 @@
 cl::desc("Output trace to the given file name or '-' for stdout."),
 cl::cat(Cat));
 
-LLVM_ATTRIBUTE_NORETURN static void error(Twine Message) {
+[[noreturn]] static void error(Twine Message) {
   WithColor::error() << Message << '\n';
   exit(1);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org

[PATCH] D106909: [clang] Add clang builtins support for gfx90a

2021-07-29 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 362555.
gandhi21299 added a comment.

- eliminated scope argument, seemed irrelevant


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106909

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenOpenCL/builtins-fp-atomics.cl

Index: clang/test/CodeGenOpenCL/builtins-fp-atomics.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/builtins-fp-atomics.cl
@@ -0,0 +1,133 @@
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx90a \
+// RUN:   %s -S -emit-llvm -o - | FileCheck %s -check-prefix=CHECK
+
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx90a \
+// RUN:   -S -o - %s | FileCheck -check-prefix=GFX90A %s
+
+
+typedef enum memory_order {
+  memory_order_relaxed = __ATOMIC_RELAXED,
+  memory_order_acquire = __ATOMIC_ACQUIRE,
+  memory_order_release = __ATOMIC_RELEASE,
+  memory_order_acq_rel = __ATOMIC_ACQ_REL,
+  memory_order_seq_cst = __ATOMIC_SEQ_CST
+} memory_order;
+
+typedef half __attribute__((ext_vector_type(2))) half2;
+
+// CHECK-LABEL: test_global_add
+// CHECK: tail call double @llvm.amdgcn.global.atomic.fadd.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A:  test_global_add
+// GFX90A:  global_atomic_add_f64 v2, v[0:1], s[0:1]
+// GFX90A:  s_endpgm
+kernel void test_global_add(__global double *addr, double x) {
+  __builtin_amdgcn_global_atomic_fadd_f64(addr, x, memory_order_relaxed);
+}
+
+// CHECK-LABEL: test_global_addf
+// CHECK: tail call float @llvm.amdgcn.global.atomic.fadd.f32.p1f32.f32(float addrspace(1)* %{{.*}}, float %{{.*}})
+// GFX90A-LABEL: test_global_addf
+// GFX90A: global_atomic_add_f32 v0, v1, s[0:1]
+// GFX90A: s_endpgm
+kernel void test_global_addf(__global float *addr, float x) {
+  __builtin_amdgcn_global_atomic_fadd_f32(addr, x, memory_order_relaxed);
+}
+
+// CHECK-LABEL: test_global_add2h
+// CHECK: tail call <2 x half> @llvm.amdgcn.global.atomic.fadd.v2f16.p1v2f16.v2f16(<2 x half> addrspace(1)* %{{.*}}, <2 x half> %{{.*}})
+// GFX90A-LABEL: test_global_add2h
+// GFX90A: global_atomic_pk_add_f16 v0, v1, s[0:1]
+// GFX90A: s_endpgm
+kernel void test_global_add2h(__global half2 *addr, half2 x){
+  __builtin_amdgcn_global_atomic_fadd_2f16(addr, x, memory_order_relaxed);
+}
+
+// CHECK-LABEL: test_global_global_min
+// CHECK: tail call double @llvm.amdgcn.global.atomic.fmin.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_global_global_min
+// GFX90A:  global_atomic_min_f64 v2, v[0:1], s[0:1]
+// GFX90A:  s_endpgm
+kernel void test_global_global_min(__global double *addr, double x){
+  __builtin_amdgcn_global_atomic_fmin_f64(addr, x, memory_order_relaxed);
+}
+
+// CHECK-LABEL: test_global_max
+// CHECK: tail call double @llvm.amdgcn.global.atomic.fmax.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A:  test_global_max
+// GFX90A:  global_atomic_max_f64 v2, v[0:1], s[0:1]
+// GFX90A:  s_endpgm
+kernel void test_global_max(__global double *addr, double x){
+  __builtin_amdgcn_global_atomic_fmax_f64(addr, x, memory_order_relaxed);
+}
+
+// CHECK-LABEL: test_flat_add_local
+// CHECK: tail call double @llvm.amdgcn.flat.atomic.fadd.f64.p3f64.f64(double addrspace(3)* %{{.*}}, double %{{.*}})
+// GFX90A:  test_flat_add_local
+// GFX90A:  ds_add_f64 v2, v[0:1]
+// GFX90A:  s_endpgm
+kernel void test_flat_add_local(__local double *addr, double x){
+  __builtin_amdgcn_flat_atomic_fadd_f64(addr, x, memory_order_relaxed);
+}
+
+// CHECK-LABEL: test_flat_global_add
+// CHECK: tail call double @llvm.amdgcn.flat.atomic.fadd.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A:  test_flat_global_add
+// GFX90A:  global_atomic_add_f64
+// GFX90A:  s_endpgm
+kernel void test_flat_global_add(__global double *addr, double x){
+  __builtin_amdgcn_flat_atomic_fadd_f64(addr, x, memory_order_relaxed);
+}
+
+// CHECK-LABEL: test_flat_min_constant
+// CHECK: tail call double @llvm.amdgcn.flat.atomic.fmin.f64.p4f64.f64(double addrspace(4)* %{{.*}}, double %{{.*}})
+// GFX90A:  test_flat_min_constant
+// GFX90A:  global_atomic_min_f64
+// GFX90A:  s_endpgm
+void test_flat_min_constant(__generic double *addr, double x){
+  __builtin_amdgcn_flat_atomic_fmin_f64(addr, x, memory_order_relaxed);
+}
+
+// CHECK-LABEL: test_flat_global_min
+// CHECK: tail call double @llvm.amdgcn.flat.atomic.fmin.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A:  test_flat_global_min
+// GFX90A:  global_atomic_min_f64
+// GFX90A:  s_endpgm
+kernel void test_flat_global_min(__global double *addr, double x){
+  __builtin_amdgcn_flat_atomic_fmin_f64(addr, x, memory_order_relaxed);
+}
+
+// CHECK-LABEL: test_flat_max_constant
+// CHECK: tail call double @llvm.amdgcn.flat.atomic.fmax.f64.p4f64.f64(double addrspace(4)* %{{.*}}

[PATCH] D104556: [InstrProfiling] Make CountersPtr in __profd_ relative

2021-07-29 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

release/13.x has been created. This if merged will go into 14.x. We have plenty 
of time making more format changes if needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104556

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


[PATCH] D106778: [OpenCL] opencl-c.h: add CL 3.0 non-generic address space atomics

2021-07-29 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106778

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


[PATCH] D106262: [clang][analyzer] Use generic note tag in alpha.unix.Stream .

2021-07-29 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus requested changes to this revision.
Szelethus added a comment.
This revision now requires changes to proceed.

I like the generalization still, but I don't agree with how you retrieve the 
`NoteTag` message. Its the wrong way around. This is how you invoke your 
function:

  void StreamChecker::evalFclose(/* ... */, CheckerContext &C) const {
ProgramStateRef State = C.getState();
SymbolRef Sym = /* get stream object */;
const StreamState *SS = State->get(Sym);
  
// early returns, asserts, etc...
  
// Close the File Descriptor.
// Regardless if the close fails or not, stream becomes "closed"
// and can not be used any more.
State = State->set(Sym, StreamState::getClosed(Desc));
  
C.addTransition(State, constructNoteTag(C, Sym, {&BT_UseAfterClose})); // 
<--- (#)
  }

What are you telling in `(#)`? Its confusing, no bug occurred here, what is a 
`BugType` doing here? Are you guessing that if a bug will occur, the bug will 
have that specific `BugType`? You need to go out of your way to find the 
mapping to `BugMessages`, read a bunch of documentation and comments to realize 
what the intent was. Even if its algorithmically correct, its a bit upside down.

If you passed the note message:

  C.addTransition(State, constructNoteTag(C, Sym, "Stream closed here"));
  
  // or from some NoteMessageKind or whatever enum:
  
  C.addTransition(State, constructNoteTag(C, Sym, NMK_StreamClosedHere));

you could move the logic of displaying this note only for specific kinds of 
`BugType`s, or a single `BugType` into `constructNoteTag`. That would be a big 
improvement already. The call site will be very telling of whats happening: you 
are constructing a `NoteTag` with the string that is passed as an argument. I 
realize this feels like over the top nitpicking, but easily readable code is 
very valuable, not to mention this is the experience I had when I read this 
patch for the first time.

Of course, the person who will have to debug this checker later on as to why 
the `NoteTag` isn't displaying for a different `BugType` to that will again 
have to go through that function and the comments to understand that these 
messages are only displayed for specific `BugTypes`, this is why my 
four-argument suggestion would be, in my world, the ideal solution. I don't 
think that adds any complexity, but would make the code a lot more readable.




Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:236-242
+  const BugMessageMap BugMessages = {
+  {&BT_FileNull, "Assuming opening the stream fails here"},
+  {&BT_UseAfterClose, "Stream closed here"},
+  {&BT_UseAfterOpenFailed, "Assuming opening the stream fails here"},
+  {&BT_IndeterminatePosition, "Assuming this stream operation fails"},
+  {&BT_StreamEof, "Assuming stream reaches end-of-file here"},
+  {&BT_ResourceLeak, "Stream opened here"}};

balazske wrote:
> balazske wrote:
> > Szelethus wrote:
> > > Well this looks odd: for both `BT_StreamEof` AND 
> > > `BT_IndeterminatePosition` we want to display a `NoteTag` for a failed 
> > > `fseek`, for one you print "Assuming stream reaches end-of-file here", 
> > > for the other, "Assuming this stream operation fails". This seems to 
> > > contradict your comment in the fseek evaluating function:
> > > 
> > > ```
> > > If fseek failed, assume that the file position becomes indeterminate in 
> > > any case.
> > > ```
> > > 
> > > Also, these `BugTypes` should be responsible for the *error message*, not 
> > > the `NoteTag` message. I'd prefer if we mapped an enum to these strings 
> > > (`NoteTagMsgKind`?), pass that as well to `constructNoteTag`, and allow 
> > > the caller to decide that for which `BugTypes` the `NoteTag` is worth 
> > > displaying for.
> > > 
> > > I think such a 4-argument `constructNoteTag` would capture best what we 
> > > want here.
> > It is still unclear how to model the `fseek` (and other functions). (But 
> > this is not a problem for this patch.) We can do it according the POSIX or 
> > C standard, or just by the experience that a `fseek` may fail with EOF or 
> > `ferror` or none of them. The standards are not exact but do not mention 
> > that `fseek` should cause the indeterminate flag to be set at all, or that 
> > `fseek` can cause `feof` state.
> The message for a NoteTag depends on the bug type and at this state the bug 
> type is sufficient to determine the note message. Because it is possible to 
> add multiple bug types to a NoteTag, passing a custom message to it can be 
> done only by passing a BugType->Message map to the note tag. This may be 
> unnecessary complexity for the current use case.
>It is still unclear how to model the fseek (and other functions). (But this is 
>not a problem for this patch.) 
I agree, we can discuss that another time.

> The message for a NoteTag depends on the bug type and at this state the bug 
> type is sufficient to determine the note me

[PATCH] D107054: [Clang][CUDA] Add descriptors, mappings, and features for missing CUDA and PTX versions

2021-07-29 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen created this revision.
steffenlarsen added a reviewer: tra.
Herald added subscribers: dexonsmith, hiraditya, yaxunl, jholewinski.
steffenlarsen requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Adds missing descriptors and mappings for CUDA 11.4 and older. Also adds 
missing sub-target features for PTX 7.4 and older.

Authored-by: Steffen Larsen 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107054

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/include/clang/Basic/Cuda.h
  clang/lib/Basic/Cuda.cpp
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  llvm/lib/Target/NVPTX/NVPTX.td
  llvm/lib/Target/NVPTX/NVPTXInstrInfo.td

Index: llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
===
--- llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
+++ llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
@@ -147,6 +147,9 @@
 def hasPTX65 : Predicate<"Subtarget->getPTXVersion() >= 65">;
 def hasPTX70 : Predicate<"Subtarget->getPTXVersion() >= 70">;
 def hasPTX71 : Predicate<"Subtarget->getPTXVersion() >= 71">;
+def hasPTX72 : Predicate<"Subtarget->getPTXVersion() >= 72">;
+def hasPTX73 : Predicate<"Subtarget->getPTXVersion() >= 73">;
+def hasPTX74 : Predicate<"Subtarget->getPTXVersion() >= 74">;
 
 def hasSM30 : Predicate<"Subtarget->getSmVersion() >= 30">;
 def hasSM70 : Predicate<"Subtarget->getSmVersion() >= 70">;
Index: llvm/lib/Target/NVPTX/NVPTX.td
===
--- llvm/lib/Target/NVPTX/NVPTX.td
+++ llvm/lib/Target/NVPTX/NVPTX.td
@@ -89,6 +89,10 @@
  "Use PTX version 7.1">;
 def PTX72 : SubtargetFeature<"ptx72", "PTXVersion", "72",
  "Use PTX version 7.2">;
+def PTX73 : SubtargetFeature<"ptx73", "PTXVersion", "73",
+ "Use PTX version 7.3">;
+def PTX74 : SubtargetFeature<"ptx74", "PTXVersion", "74",
+ "Use PTX version 7.4">;
 
 //===--===//
 // NVPTX supported processors.
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -77,6 +77,12 @@
 return CudaVersion::CUDA_110;
   if (raw_version < 11020)
 return CudaVersion::CUDA_111;
+  if (raw_version < 11030)
+return CudaVersion::CUDA_112;
+  if (raw_version < 11040)
+return CudaVersion::CUDA_113;
+  if (raw_version < 11050)
+return CudaVersion::CUDA_114;
   return CudaVersion::LATEST;
 }
 
@@ -131,7 +137,9 @@
   SmallVector Candidates;
 
   // In decreasing order so we prefer newer versions to older versions.
-  std::initializer_list Versions = {"8.0", "7.5", "7.0"};
+  std::initializer_list Versions = {
+  "11.4", "11.3", "11.2", "11.1", "10.2", "10.1", "10.0",
+  "9.2",  "9.1",  "9.0",  "8.0",  "7.5",  "7.0"};
   auto &FS = D.getVFS();
 
   if (Args.hasArg(clang::driver::options::OPT_cuda_path_EQ)) {
@@ -720,6 +728,8 @@
   case CudaVersion::CUDA_##CUDA_VER:   \
 PtxFeature = "+ptx" #PTX_VER;  \
 break;
+CASE_CUDA_VERSION(114, 74);
+CASE_CUDA_VERSION(113, 73);
 CASE_CUDA_VERSION(112, 72);
 CASE_CUDA_VERSION(111, 71);
 CASE_CUDA_VERSION(110, 70);
Index: clang/lib/Basic/Targets/NVPTX.cpp
===
--- clang/lib/Basic/Targets/NVPTX.cpp
+++ clang/lib/Basic/Targets/NVPTX.cpp
@@ -45,6 +45,8 @@
 if (!Feature.startswith("+ptx"))
   continue;
 PTXVersion = llvm::StringSwitch(Feature)
+ .Case("+ptx74", 74)
+ .Case("+ptx73", 73)
  .Case("+ptx72", 72)
  .Case("+ptx71", 71)
  .Case("+ptx70", 70)
Index: clang/lib/Basic/Cuda.cpp
===
--- clang/lib/Basic/Cuda.cpp
+++ clang/lib/Basic/Cuda.cpp
@@ -36,6 +36,10 @@
 return "11.1";
   case CudaVersion::CUDA_112:
 return "11.2";
+  case CudaVersion::CUDA_113:
+return "11.3";
+  case CudaVersion::CUDA_114:
+return "11.4";
   }
   llvm_unreachable("invalid enum");
 }
@@ -54,6 +58,8 @@
   .Case("11.0", CudaVersion::CUDA_110)
   .Case("11.1", CudaVersion::CUDA_111)
   .Case("11.2", CudaVersion::CUDA_112)
+  .Case("11.3", CudaVersion::CUDA_113)
+  .Case("11.4", CudaVersion::CUDA_114)
   .Default(CudaVersion::UNKNOWN);
 }
 
@@ -227,6 +233,10 @@
 return CudaVersion::CUDA_111;
   case 112:
 return CudaVersion::CUDA_112;
+  case 113:
+return CudaVersion::CUDA_113;
+  case 114:
+return CudaVersion::CUDA_114;
   default:
 return CudaVersion::UNKNOWN;
   }
Index: clang/include/cl

[PATCH] D106431: [clang-tidy] Fix cppcoreguidelines-init-variables by removing the enum FixIt, and add support for initialization check of scoped enum.

2021-07-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D106431#2912589 , @Sockke wrote:

> Thank you for your reply! I generally understand what you mean, but there are 
> three cases, namely, no diagnosis, providing diagnosis, and providing 
> diagnosis & FixIt.  Only by judging whether "diagnosis" is null may fail to 
> achieve the goal.  I have revised it a little bit, do you think that's 
> alright? @aaron.ballman

By how the code looks, you made the exact changes I was hoping to see. Thank 
you!


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

https://reviews.llvm.org/D106431

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


[clang-tools-extra] 68546c9 - bugprone-forwarding-reference-overload: support non-type template parameters

2021-07-29 Thread Aaron Ballman via cfe-commits

Author: Jesse Towner
Date: 2021-07-29T07:01:19-04:00
New Revision: 68546c9d6fc54a7ca7ad487cd4b6a5dafea9b4f3

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

LOG: bugprone-forwarding-reference-overload: support non-type template 
parameters

Many concepts emulation libraries, such as the one found in Range v3, tend to
use non-type template parameters for the enable_if type expression, due to
their versatility in template functions and constructors containing variadic
template parameter packs.

Unfortunately the bugprone-forwarding-reference-overload check does not
handle non-type template parameters, as was first noted in this bug report:
https://bugs.llvm.org/show_bug.cgi?id=38081

This patch fixes this long standing issue and allows for the check to be 
suppressed
with the use of a non-type template parameter containing enable_if or 
enable_if_t in
the type expression, so long as it has a default literal value.

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp

clang-tools-extra/docs/clang-tidy/checks/bugprone-forwarding-reference-overload.rst

clang-tools-extra/test/clang-tidy/checkers/bugprone-forwarding-reference-overload.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
index aeb3db92f16ec..857ef15f9d0c7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
@@ -74,9 +74,15 @@ void 
ForwardingReferenceOverloadCheck::registerMatchers(MatchFinder *Finder) {
   unless(hasAnyParameter(
   // No warning: enable_if as constructor parameter.
   parmVarDecl(hasType(isEnableIf(),
-  unless(hasParent(functionTemplateDecl(has(templateTypeParmDecl(
+  unless(hasParent(functionTemplateDecl(anyOf(
   // No warning: enable_if as type parameter.
-  hasDefaultArgument(isEnableIf(
+  has(templateTypeParmDecl(hasDefaultArgument(isEnableIf(,
+  // No warning: enable_if as non-type template parameter.
+  has(nonTypeTemplateParmDecl(
+  hasType(isEnableIf()),
+  anyOf(hasDescendant(cxxBoolLiteral()),
+hasDescendant(cxxNullPtrLiteralExpr()),
+hasDescendant(integerLiteral())
   .bind("ctor");
   Finder->addMatcher(FindOverload, this);
 }

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone-forwarding-reference-overload.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone-forwarding-reference-overload.rst
index b2a9e0f3b3dfb..37078d498b330 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone-forwarding-reference-overload.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone-forwarding-reference-overload.rst
@@ -26,9 +26,14 @@ Consider the following example:
   explicit Person(T&& n, int x = 1) {}
 
   // C3: perfect forwarding ctor guarded with enable_if
-  template,void>>
+  template, void>>
   explicit Person(T&& n) {}
 
+  // C4: variadic perfect forwarding ctor guarded with enable_if
+  template, A&&...>, int> = 0>
+  explicit Person(A&&... a) {}
+
   // (possibly compiler generated) copy ctor
   Person(const Person& rhs);
 };
@@ -37,13 +42,15 @@ The check warns for constructors C1 and C2, because those 
can hide copy and move
 constructors. We suppress warnings if the copy and the move constructors are 
both
 disabled (deleted or private), because there is nothing the perfect forwarding
 constructor could hide in this case. We also suppress warnings for constructors
-like C3 that are guarded with an ``enable_if``, assuming the programmer was 
aware of
-the possible hiding.
+like C3 and C4 that are guarded with an ``enable_if``, assuming the programmer 
was
+aware of the possible hiding.
 
 Background
 --
 
 For deciding whether a constructor is guarded with enable_if, we consider the
-default values of the type parameters and the types of the constructor
-parameters. If any part of these types is ``std::enable_if`` or 
``std::enable_if_t``,
-we assume the constructor is guarded.
+types of the constructor parameters, the default values of template type 
parameters
+and the types of non-type template parameters with a default literal value. If 
any
+part of these types is ``std::enable_if`` or ``std::enable_if_t``, we assume 
the
+constructor is guarded.
+

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-forwarding-reference-overload.cpp
 
b/clang-tools-extra/test/clang-ti

[PATCH] D103385: [clang-tidy] bugprone-forwarding-reference-overload: support non-type template parameters

2021-07-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

I've committed on your behalf in 68546c9d6fc54a7ca7ad487cd4b6a5dafea9b4f3 
, thank 
you for the fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103385

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


[PATCH] D107026: [Clang] Add support for attribute 'escape'

2021-07-29 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

Great job!  It looks good, but I have a couple of minor tweaks.

I see that the "applies to pointer arguments only" warning is not tested for 
`noescape`, but I still find it to be a good practice to write a test with a 
bunch of cases with attributes applied in wrong places.

Additionally, I believe that `escape` and `noescape` convey the same 
information, and it is totally okay to have two attributes because the user has 
to have a choice to say either "I do escape it" or "I definitely do not escape 
it" when the default is unspecified at all.  But I do think that we should add 
a check disallowing both of these attributes to be used at the same time for 
the same parameter, since they directly contradict one another.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107026

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


[PATCH] D106732: Support macro deprecation #pragma clang deprecated

2021-07-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D106732#2911552 , @beanz wrote:

> Covered taken #elif* directives per @aaron.ballmon's feedback.

Thanks!

> Handling non-taken #elif directives is non-trivial because clang skips 
> parsing the conditionals for non-taken directives. At present clang won't 
> even error on malformed #elif directives if an earlier branch is taken.

Yeah, that's what I was worried about. Can you add some FIXME comments into 
`Preprocessor::SkipExcludedConditionalBlock()` about wanting to diagnose this 
situation, and add some test cases with FIXME comments showing we know we don't 
handle this case perfectly yet?

> Also with this update I refactored the error emitting code out to a function 
> on the Preprocessor, since it is just getting copy and pasted over and over 
> again, and this change would have added another copy.

Thank you, that's a nice cleanup!




Comment at: clang/include/clang/Lex/Preprocessor.h:2409
+
+  void emitMacroExpansionWarnings(Token &Identifier);
+





Comment at: clang/lib/Lex/Preprocessor.cpp:1416
 
+void Preprocessor::emitMacroExpansionWarnings(Token &Identifier) {
+  if (Identifier.getIdentifierInfo()->isDeprecatedMacro()) {





Comment at: clang/test/Lexer/deprecate-macro.c:62
+
+// Test that we diagnose on #elif
+#if 0




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106732

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


[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

2021-07-29 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:143
+llvm::ArrayRef ValidNames(STD_PTR_NAMES);
+return llvm::is_contained(ValidNames, Name);
   }

And why can't we pass `STD_PTR_NAMES` directly to `llvm::is_contained`?



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:378-387
+llvm::errs() << "Found destructor call\n";
+State = DC->invalidateRegions(C.blockCount(), State);
+const MemRegion *ThisRegion = DC->getCXXThisVal().getAsRegion();
+assert(ThisRegion && "We do not support explicit calls to destructor");
+const auto *InnerPtrVal = State->get(ThisRegion);
+State = State->remove(ThisRegion);
+if (InnerPtrVal)

I suggest to add a ton of comments with the reasoning behind these actions.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:381
+const MemRegion *ThisRegion = DC->getCXXThisVal().getAsRegion();
+assert(ThisRegion && "We do not support explicit calls to destructor");
+const auto *InnerPtrVal = State->get(ThisRegion);

And if it happens we are going to crash with assertion failure?



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:421-422
   const auto *TrackingExpr = Call.getArgExpr(0);
-  assert(TrackingExpr->getType()->isPointerType() &&
- "Adding a non pointer value to TrackedRegionMap");
+  if (TrackingExpr->getType()->isPointerType())
+return false;
   auto ArgVal = Call.getArgSVal(0);

Okay, I'm either missing something or this condition is missing `!` here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105821

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


[PATCH] D106277: [SVE] Remove the interface for getMaxVScale in favour of the IR attributes

2021-07-29 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm added a comment.

@craig.topper can you share RISCV plans around supporting vscale_range?  In 
essence we'd like to deprecate the TTI method and have LLVM IR contain all 
relevant information when is comes to interpreting vscale.

Currently the usage is minimal and so checking both interfaces is not too bad 
but they'll come a point when there's no TTI available and then only the side 
supporting vscale_range can be considered.  There's also the LTO side of things 
where relying on opt/llc flags to set register widths becomes fragile.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106277

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


[PATCH] D104601: [Preprocessor] Implement -fminimize-whitespace.

2021-07-29 Thread Romanov Vlad via Phabricator via cfe-commits
romanovvlad added a comment.

Hi @Meinersbur,

It seems the patch introduces one more regression. The following test doesn't 
pass on Windows:

  // RUN: %clang -E %s -o %t.ii
  // RUN: %clang %t.ii
  
  #include "string.h"
  
  int main() {
return 0;
  }

The following macro from vcruntime.h:

  #define _CRT_BEGIN_C_HEADER\
  __pragma(pack(push, _CRT_PACKING)) \
  extern "C" {

Becomes

  #pragma pack(push, 8) extern "C" {

in the preprocessed file.

I'm not an expert in this code, but partially returning old behavior helped 
with that:

diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp 
b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index b725956..b49b247 100644

- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp

+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -772,6 +772,7 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token 
&Tok,

  bool IsStartOfLine = false;
  char Buffer[256];
  while (1) {

+Callbacks->MoveToLine(Tok.getLocation(), /*RequireStartOfLine=*/false);

  // Two lines joined with line continuation ('\' as last character on the
  // line) must be emitted as one line even though Tok.getLine() returns two
  // different values. In this situation Tok.isAtStartOfLine() is false even

Could you please take a look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104601

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


[PATCH] D106898: Revert "Revert "[clang][pp] adds '#pragma include_instead'""

2021-07-29 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 with the testing and formatting fix.




Comment at: clang/include/clang/Basic/DiagnosticLexKinds.td:307
+def err_pragma_include_instead_system_reserved : Error<
+  "header '%0' is an implementation detail; #include %select{'%2'|either '%2' 
or '%3'|one of %2}1 instead">;
+

80-col wrapping.



Comment at: clang/test/PCH/ms-pch-macro-include_instead-regression.c:2
+// Enabling MS extensions should allow us to add BAR definitions.
+// RUN: %clang_cc1 -DMSEXT -fms-extensions -DBAZ=\"Inputs/pch-through1.h\" 
-emit-pch -o %t1.pch
+// RUN: %clang_cc1 -DMSEXT -fms-extensions -include-pch %t1.pch -verify %s

This fixes the shell issue when I try it out locally on Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106898

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


[PATCH] D105981: [AMDGPU][OpenMP] Support linking of math libraries

2021-07-29 Thread Pushpinder Singh via Phabricator via cfe-commits
pdhaliwal updated this revision to Diff 362717.
pdhaliwal added a comment.

Rename method to getCommonDeviceLibNames


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105981

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPU.h
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/test/Driver/amdgpu-openmp-toolchain.c

Index: clang/test/Driver/amdgpu-openmp-toolchain.c
===
--- clang/test/Driver/amdgpu-openmp-toolchain.c
+++ clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -74,3 +74,6 @@
 
 // RUN:   %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-EMIT-LLVM-IR
 // CHECK-EMIT-LLVM-IR: clang{{.*}}"-cc1"{{.*}}"-triple" "amdgcn-amd-amdhsa"{{.*}}"-emit-llvm"
+
+// RUN: env LIBRARY_PATH=%S/Inputs/hip_dev_lib %clang -### -target x86_64-pc-linux-gnu -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 -lm --rocm-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode %s 2>&1 | FileCheck %s --check-prefix=CHECK-LIB-DEVICE
+// CHECK-LIB-DEVICE: clang{{.*}}"-cc1"{{.*}}"-triple" "amdgcn-amd-amdhsa"{{.*}}"-mlink-builtin-bitcode"{{.*}}libomptarget-amdgcn-gfx803.bc"{{.*}}"-mlink-builtin-bitcode"{{.*}}ocml.bc" "-mlink-builtin-bitcode"{{.*}}ockl.bc" "-mlink-builtin-bitcode"{{.*}}oclc_daz_opt_on.bc" "-mlink-builtin-bitcode"{{.*}}oclc_unsafe_math_off.bc" "-mlink-builtin-bitcode"{{.*}}oclc_finite_only_off.bc" "-mlink-builtin-bitcode"{{.*}}oclc_correctly_rounded_sqrt_on.bc" "-mlink-builtin-bitcode"{{.*}}oclc_wavefrontsize64_on.bc" "-mlink-builtin-bitcode"{{.*}}oclc_isa_version_803.bc"
Index: clang/lib/Driver/ToolChains/HIP.cpp
===
--- clang/lib/Driver/ToolChains/HIP.cpp
+++ clang/lib/Driver/ToolChains/HIP.cpp
@@ -395,35 +395,8 @@
 }
 StringRef GpuArch = getGPUArch(DriverArgs);
 assert(!GpuArch.empty() && "Must have an explicit GPU arch.");
-(void)GpuArch;
-auto Kind = llvm::AMDGPU::parseArchAMDGCN(GpuArch);
-const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind);
-
-std::string LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch);
-if (LibDeviceFile.empty()) {
-  getDriver().Diag(diag::err_drv_no_rocm_device_lib) << 1 << GpuArch;
-  return {};
-}
 
 // If --hip-device-lib is not set, add the default bitcode libraries.
-// TODO: There are way too many flags that change this. Do we need to check
-// them all?
-bool DAZ = DriverArgs.hasFlag(options::OPT_fgpu_flush_denormals_to_zero,
-  options::OPT_fno_gpu_flush_denormals_to_zero,
-  getDefaultDenormsAreZeroForTarget(Kind));
-bool FiniteOnly =
-DriverArgs.hasFlag(options::OPT_ffinite_math_only,
-   options::OPT_fno_finite_math_only, false);
-bool UnsafeMathOpt =
-DriverArgs.hasFlag(options::OPT_funsafe_math_optimizations,
-   options::OPT_fno_unsafe_math_optimizations, false);
-bool FastRelaxedMath = DriverArgs.hasFlag(
-options::OPT_ffast_math, options::OPT_fno_fast_math, false);
-bool CorrectSqrt = DriverArgs.hasFlag(
-options::OPT_fhip_fp32_correctly_rounded_divide_sqrt,
-options::OPT_fno_hip_fp32_correctly_rounded_divide_sqrt);
-bool Wave64 = isWave64(DriverArgs, Kind);
-
 if (DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
options::OPT_fno_gpu_sanitize, false)) {
   auto AsanRTL = RocmInstallation.getAsanRTLPath();
@@ -442,10 +415,8 @@
 // Add the HIP specific bitcode library.
 BCLibs.push_back(RocmInstallation.getHIPPath().str());
 
-// Add the generic set of libraries.
-BCLibs.append(RocmInstallation.getCommonBitcodeLibs(
-DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
-FastRelaxedMath, CorrectSqrt));
+// Add common device libraries like ocml etc.
+BCLibs.append(getCommonDeviceLibNames(DriverArgs, GpuArch.str()));
 
 // Add instrument lib.
 auto InstLib =
Index: clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -9,12 +9,14 @@
 #include "AMDGPUOpenMP.h"
 #include "AMDGPU.h"
 #include "CommonArgs.h"
+#include "ToolChains/ROCm.h"
 #include "clang/Basic/DiagnosticDriver.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Su

[PATCH] D105981: [AMDGPU][OpenMP] Support linking of math libraries

2021-07-29 Thread Pushpinder Singh via Phabricator via cfe-commits
pdhaliwal updated this revision to Diff 362718.
pdhaliwal added a comment.

Missed comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105981

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPU.h
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/test/Driver/amdgpu-openmp-toolchain.c

Index: clang/test/Driver/amdgpu-openmp-toolchain.c
===
--- clang/test/Driver/amdgpu-openmp-toolchain.c
+++ clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -74,3 +74,6 @@
 
 // RUN:   %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-EMIT-LLVM-IR
 // CHECK-EMIT-LLVM-IR: clang{{.*}}"-cc1"{{.*}}"-triple" "amdgcn-amd-amdhsa"{{.*}}"-emit-llvm"
+
+// RUN: env LIBRARY_PATH=%S/Inputs/hip_dev_lib %clang -### -target x86_64-pc-linux-gnu -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 -lm --rocm-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode %s 2>&1 | FileCheck %s --check-prefix=CHECK-LIB-DEVICE
+// CHECK-LIB-DEVICE: clang{{.*}}"-cc1"{{.*}}"-triple" "amdgcn-amd-amdhsa"{{.*}}"-mlink-builtin-bitcode"{{.*}}libomptarget-amdgcn-gfx803.bc"{{.*}}"-mlink-builtin-bitcode"{{.*}}ocml.bc" "-mlink-builtin-bitcode"{{.*}}ockl.bc" "-mlink-builtin-bitcode"{{.*}}oclc_daz_opt_on.bc" "-mlink-builtin-bitcode"{{.*}}oclc_unsafe_math_off.bc" "-mlink-builtin-bitcode"{{.*}}oclc_finite_only_off.bc" "-mlink-builtin-bitcode"{{.*}}oclc_correctly_rounded_sqrt_on.bc" "-mlink-builtin-bitcode"{{.*}}oclc_wavefrontsize64_on.bc" "-mlink-builtin-bitcode"{{.*}}oclc_isa_version_803.bc"
Index: clang/lib/Driver/ToolChains/HIP.cpp
===
--- clang/lib/Driver/ToolChains/HIP.cpp
+++ clang/lib/Driver/ToolChains/HIP.cpp
@@ -395,35 +395,8 @@
 }
 StringRef GpuArch = getGPUArch(DriverArgs);
 assert(!GpuArch.empty() && "Must have an explicit GPU arch.");
-(void)GpuArch;
-auto Kind = llvm::AMDGPU::parseArchAMDGCN(GpuArch);
-const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind);
-
-std::string LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch);
-if (LibDeviceFile.empty()) {
-  getDriver().Diag(diag::err_drv_no_rocm_device_lib) << 1 << GpuArch;
-  return {};
-}
 
 // If --hip-device-lib is not set, add the default bitcode libraries.
-// TODO: There are way too many flags that change this. Do we need to check
-// them all?
-bool DAZ = DriverArgs.hasFlag(options::OPT_fgpu_flush_denormals_to_zero,
-  options::OPT_fno_gpu_flush_denormals_to_zero,
-  getDefaultDenormsAreZeroForTarget(Kind));
-bool FiniteOnly =
-DriverArgs.hasFlag(options::OPT_ffinite_math_only,
-   options::OPT_fno_finite_math_only, false);
-bool UnsafeMathOpt =
-DriverArgs.hasFlag(options::OPT_funsafe_math_optimizations,
-   options::OPT_fno_unsafe_math_optimizations, false);
-bool FastRelaxedMath = DriverArgs.hasFlag(
-options::OPT_ffast_math, options::OPT_fno_fast_math, false);
-bool CorrectSqrt = DriverArgs.hasFlag(
-options::OPT_fhip_fp32_correctly_rounded_divide_sqrt,
-options::OPT_fno_hip_fp32_correctly_rounded_divide_sqrt);
-bool Wave64 = isWave64(DriverArgs, Kind);
-
 if (DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
options::OPT_fno_gpu_sanitize, false)) {
   auto AsanRTL = RocmInstallation.getAsanRTLPath();
@@ -442,10 +415,8 @@
 // Add the HIP specific bitcode library.
 BCLibs.push_back(RocmInstallation.getHIPPath().str());
 
-// Add the generic set of libraries.
-BCLibs.append(RocmInstallation.getCommonBitcodeLibs(
-DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
-FastRelaxedMath, CorrectSqrt));
+// Add common device libraries like ocml etc.
+BCLibs.append(getCommonDeviceLibNames(DriverArgs, GpuArch.str()));
 
 // Add instrument lib.
 auto InstLib =
Index: clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -9,12 +9,14 @@
 #include "AMDGPUOpenMP.h"
 #include "AMDGPU.h"
 #include "CommonArgs.h"
+#include "ToolChains/ROCm.h"
 #include "clang/Basic/DiagnosticDriver.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/FileSystem.h"
 #inc

[PATCH] D106614: [Clang] add btf_tag attribute

2021-07-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D106614#2912292 , @yonghong-song 
wrote:

>> This currently has no codegen, so it only adds the attribute to the AST and 
>> does nothing with it. Can you also add the codegen components to this patch?
>
> In one of my early PIC patches, David Blaikie suggested to break into 
> manageable pieces
> for review and that is why I have multiple patches instead of one giant one. 
> Please let
> me know if you have better suggestions.

Ah, nope, this is fine -- I had missed noticing that this was part of a patch 
stack.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106614

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


[PATCH] D106614: [Clang] add btf_tag attribute

2021-07-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:1835
+  let Args = [StringArgument<"BTFTag">];
+  let Subjects = SubjectList<[Var, Function, Record, Field], ErrorDiag>;
+  let Documentation = [BTFTagDocs];

yonghong-song wrote:
> aaron.ballman wrote:
> > ObjC method declarations?
> > 
> > Also, can this apply to *any* kind of variable declaration? e.g., does it 
> > do something useful on a `constexpr` variable that never gets emitted at 
> > runtime?
> The attribute named btf_tag and it is supposed to be used for bpf programs 
> and kernel, and currently all our use cases are C, so hence ObjC is not 
> considered and I marked it as COnly.
> 
> constexpr is not our use case so it is okay the variable (and possible 
> attricute) is gone.
Great, thank you!



Comment at: clang/test/Sema/attr-btf_tag.c:15
+  return arg->a;
+}

yonghong-song wrote:
> aaron.ballman wrote:
> > There are quite a few test cases that are missing. Can you please add tests 
> > for applying the attribute to something invalid (like an enumeration), not 
> > given any arguments, given too many arguments.
> > 
> > Also missing are test cases for how this attribute merges on 
> > redeclarations, especially with conflicting arguments. e.g.,
> > ```
> > void __attribute__((btf_tag("tag"))) bar();
> > void __attribute__((btf_tag("derp"))) bar() {} // Which argument "wins" or 
> > should this be an error?
> > ```
> > Should it be valid to apply this to an incomplete structure declaration? 
> > e.g.,
> > ```
> > struct __attribute__((btf_tag("tag"))) S; // Should this be valid or 
> > invalid?
> > ```
> Thanks. I will add more test cases about redeclaration. For redeclaration 
> case, my current thinking is they should match *exactly*. Otherwise, we 
> should fail the compilation. I guess some implementation may be needed here.
> 
> For forward declaration, the current intention is not allowed. the btf_tag 
> should just appear in the actual type definition.
> 
> For other types like enum, we didn't find a use case for that yet and that is 
> why is not supported. I will add more tests to cover such invalid cases.
> Thanks. I will add more test cases about redeclaration. For redeclaration 
> case, my current thinking is they should match *exactly*. Otherwise, we 
> should fail the compilation. I guess some implementation may be needed here.

That sounds reasonable to me.  In terms of the implementation work, you're 
going to want to use the "attribute merge" pattern, which has a number of good 
examples to follow such as: 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaDecl.cpp#L2634.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106614

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


[PATCH] D102343: [clang][patch][FPEnv} Initialization of C++ globals not strictfp aware

2021-07-29 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.

Giving my official LGTM now that there's been a week for folks to comment with 
additional concerns.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102343

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


[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

2021-07-29 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:421-422
   const auto *TrackingExpr = Call.getArgExpr(0);
-  assert(TrackingExpr->getType()->isPointerType() &&
- "Adding a non pointer value to TrackedRegionMap");
+  if (TrackingExpr->getType()->isPointerType())
+return false;
   auto ArgVal = Call.getArgSVal(0);

vsavchenko wrote:
> Okay, I'm either missing something or this condition is missing `!` here.
And that's the ghost bug I am chasing around for the last few hours.
Thanks :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105821

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


[PATCH] D106644: [clang][analyzer] Add standard streams to alpha.unix.Stream checker.

2021-07-29 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a reviewer: vsavchenko.
Szelethus added a comment.

I like the idea, though I wonder whether `evalAssume` would be a better 
callback for this. That way, you'd only need to add an assumption when you 
reach a condition where one of the operands is standard.

Though it may be more trouble than its worth. I don't have strong feelings on 
this.




Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:238
+
+SymbolRef findStdStream(StringRef StdName, CheckerContext &C) {
+  const LocationContext *LCtx = C.getLocationContext();

How about `getStdStreamSymbol`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106644

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


[PATCH] D107002: [PowerPC] Implement XL compatibility builtin __addex

2021-07-29 Thread Lei Huang via Phabricator via cfe-commits
lei updated this revision to Diff 362734.
lei added a comment.

put back unintentional space change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107002

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-64bit.c
  clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-error.c
  clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-warning.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/P9InstrResources.td
  llvm/lib/Target/PowerPC/PPCInstr64Bit.td
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll

Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll
===
--- llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll
@@ -29,3 +29,24 @@
   ret double %0
 }
 declare double @llvm.ppc.insert.exp(double, i64)
+
+declare i64 @llvm.ppc.addex(i64, i64, i32 immarg)
+define dso_local i64 @call_addex_0(i64 %a, i64 %b) {
+; CHECK-LABEL: call_addex_0:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:addex 3, 3, 4, 0
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call i64 @llvm.ppc.addex(i64 %a, i64 %b, i32 0)
+  ret i64 %0
+}
+
+define dso_local i64 @call_addex_1(i64 %a, i64 %b) {
+; CHECK-LABEL: call_addex_1:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:addex 3, 3, 4, 0
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call i64 @llvm.ppc.addex(i64 %a, i64 %b, i32 0)
+  ret i64 %0
+}
Index: llvm/lib/Target/PowerPC/PPCInstr64Bit.td
===
--- llvm/lib/Target/PowerPC/PPCInstr64Bit.td
+++ llvm/lib/Target/PowerPC/PPCInstr64Bit.td
@@ -1670,6 +1670,13 @@
  "hashchkp $RB, $D_RA_XD", IIC_IntGeneral, []>;
 }
 
+let Interpretation64Bit = 1, isCodeGenOnly = 1, hasSideEffects = 1 in
+def ADDEX8 : Z23Form_RTAB5_CY2<31, 170, (outs g8rc:$rT),
+  (ins g8rc:$rA, g8rc:$rB, u2imm:$CY),
+  "addex $rT, $rA, $rB, $CY", IIC_IntGeneral,
+  [(set i64:$rT, (int_ppc_addex i64:$rA, i64:$rB,
+timm:$CY))]>;
+
 //===--===//
 // Instruction Patterns
 //
Index: llvm/lib/Target/PowerPC/P9InstrResources.td
===
--- llvm/lib/Target/PowerPC/P9InstrResources.td
+++ llvm/lib/Target/PowerPC/P9InstrResources.td
@@ -1430,5 +1430,6 @@
   DCBI,
   DCCCI,
   ICCCI,
-  ADDEX
+  ADDEX,
+  ADDEX8
 )> { let Unsupported = 1; }
Index: llvm/include/llvm/IR/IntrinsicsPowerPC.td
===
--- llvm/include/llvm/IR/IntrinsicsPowerPC.td
+++ llvm/include/llvm/IR/IntrinsicsPowerPC.td
@@ -1706,7 +1706,10 @@
   def int_ppc_fres
   : GCCBuiltin<"__builtin_ppc_fres">,
 Intrinsic <[llvm_float_ty], [llvm_float_ty], [IntrNoMem]>;
-  
+  def int_ppc_addex
+  : GCCBuiltin<"__builtin_ppc_addex">,
+Intrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i64_ty, llvm_i32_ty],
+  [IntrNoMem, IntrHasSideEffects, ImmArg>]>;
   def int_ppc_fsel : GCCBuiltin<"__builtin_ppc_fsel">,
  Intrinsic<[llvm_double_ty], [llvm_double_ty, llvm_double_ty, 
   llvm_double_ty], [IntrNoMem]>;
Index: clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-warning.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-warning.c
@@ -0,0 +1,11 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc64-unknown-unknown -target-cpu pwr9 \
+// RUN:   -verify %s
+
+extern unsigned long long ull;
+extern long long ll;
+
+void test_builtin_ppc_addex() {
+  long long res = __builtin_ppc_addex(ll, ll, 1); // expected-warning {{argument value 1 will resullt in undefined behaviour}}
+  unsigned long long res2 = __builtin_ppc_addex(ull, ull, 3); // expected-warning {{argument value 3 will resullt in undefined behaviour}}
+}
Index: clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-error.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-error.c
+++ clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-error.c
@@ -9,7 +9,18 @@
 // RUN:   -fsyntax-only -Wall -Werror -verify %s
 
 extern unsigned int ui;
+extern unsigned long long ull;
+extern long long ll;
 
 void test_builtin_ppc_cmprb() {
   int res = __builtin_ppc_cmprb(3, ui, ui); // expected-error {{argument value 3 is outside the valid range [0, 1]}}
 }
+
+#ifdef __PPC64__
+
+void test_builtin_ppc_ad

[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

2021-07-29 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:143
+llvm::ArrayRef ValidNames(STD_PTR_NAMES);
+return llvm::is_contained(ValidNames, Name);
   }

vsavchenko wrote:
> And why can't we pass `STD_PTR_NAMES` directly to `llvm::is_contained`?
Ooh, so there is an overload for that as well. :)



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:381
+const MemRegion *ThisRegion = DC->getCXXThisVal().getAsRegion();
+assert(ThisRegion && "We do not support explicit calls to destructor");
+const auto *InnerPtrVal = State->get(ThisRegion);

vsavchenko wrote:
> And if it happens we are going to crash with assertion failure?
Assuming assertions are enabled, that is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105821

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


[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

2021-07-29 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 362738.
RedDocMD added a comment.

Bug fixes, some cleanup


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105821

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp


Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -753,10 +753,13 @@
 *Call, *this);
 
   ExplodedNodeSet DstInvalidated;
-  StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
-  for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
-   I != E; ++I)
-defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  // StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
+  // for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E =
+  // DstPreCall.end();
+  //  I != E; ++I)
+  //   defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  getCheckerManager().runCheckersForEvalCall(DstInvalidated, DstPreCall, *Call,
+ *this, CallOpts);
 
   getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated,
  *Call, *this);
Index: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -664,14 +664,11 @@
 for (const auto &EvalCallChecker : EvalCallCheckers) {
   // TODO: Support the situation when the call doesn't correspond
   // to any Expr.
-  ProgramPoint L = ProgramPoint::getProgramPoint(
-  Call.getOriginExpr(), ProgramPoint::PostStmtKind,
-  Pred->getLocationContext(), EvalCallChecker.Checker);
   bool evaluated = false;
   { // CheckerContext generates transitions(populates checkDest) on
 // destruction, so introduce the scope to make sure it gets properly
 // populated.
-CheckerContext C(B, Eng, Pred, L);
+CheckerContext C(B, Eng, Pred, Call.getProgramPoint());
 evaluated = EvalCallChecker(Call, C);
   }
   assert(!(evaluated && anyEvaluated)
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -139,7 +139,7 @@
 
   if (RD->getDeclName().isIdentifier()) {
 StringRef Name = RD->getName();
-return Name == "shared_ptr" || Name == "unique_ptr" || Name == "weak_ptr";
+return llvm::is_contained(STD_PTR_NAMES, Name);
   }
   return false;
 }
@@ -279,6 +279,7 @@
 CheckerContext &C) const {
 
   ProgramStateRef State = C.getState();
+  Call.dump();
 
   // If any one of the arg is a unique_ptr, then
   // we can try this function
@@ -372,6 +373,20 @@
 }
   }
 
+  if (const auto *DC = dyn_cast(&Call)) {
+llvm::errs() << "Found destructor call\n";
+State = DC->invalidateRegions(C.blockCount(), State);
+const MemRegion *ThisRegion = DC->getCXXThisVal().getAsRegion();
+assert(ThisRegion && "We do not support explicit calls to destructor");
+const auto *InnerPtrVal = State->get(ThisRegion);
+State = State->remove(ThisRegion);
+if (InnerPtrVal)
+  State = State->invalidateRegions(*InnerPtrVal, nullptr, C.blockCount(),
+   C.getLocationContext(), true);
+C.addTransition(State);
+return true;
+  }
+
   if (!ModelSmartPtrDereference)
 return false;
 
@@ -402,8 +417,8 @@
   }));
 } else {
   const auto *TrackingExpr = Call.getArgExpr(0);
-  assert(TrackingExpr->getType()->isPointerType() &&
- "Adding a non pointer value to TrackedRegionMap");
+  if (!TrackingExpr->getType()->isPointerType())
+return false;
   auto ArgVal = Call.getArgSVal(0);
   State = State->set(ThisRegion, ArgVal);
 


Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -753,10 +753,13 @@
 *Call, *this);
 
   ExplodedNodeSet DstInvalidated;
-  StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
-  for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
-   I != E; ++I)
-defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  // StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
+  // for (ExplodedNodeSet::iterator I = DstPreCall.

[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

2021-07-29 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:381
+const MemRegion *ThisRegion = DC->getCXXThisVal().getAsRegion();
+assert(ThisRegion && "We do not support explicit calls to destructor");
+const auto *InnerPtrVal = State->get(ThisRegion);

RedDocMD wrote:
> vsavchenko wrote:
> > And if it happens we are going to crash with assertion failure?
> Assuming assertions are enabled, that is.
We should never crash or fail on valid C++ code.  We can abandon everything, 
forbid checker to report anything on a function that has something that we 
don't know how to handle properly, but never fail the overall analysis process 
because of that. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105821

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


[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

2021-07-29 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:381
+const MemRegion *ThisRegion = DC->getCXXThisVal().getAsRegion();
+assert(ThisRegion && "We do not support explicit calls to destructor");
+const auto *InnerPtrVal = State->get(ThisRegion);

vsavchenko wrote:
> RedDocMD wrote:
> > vsavchenko wrote:
> > > And if it happens we are going to crash with assertion failure?
> > Assuming assertions are enabled, that is.
> We should never crash or fail on valid C++ code.  We can abandon everything, 
> forbid checker to report anything on a function that has something that we 
> don't know how to handle properly, but never fail the overall analysis 
> process because of that. 
Ah right, I should have put in a TODO. This assert was put to see how often I 
run into this (none so far). It must be removed before this patch is accepted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105821

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


[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

2021-07-29 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 362741.
RedDocMD added a comment.

Put in a TODO


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105821

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp


Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -753,10 +753,13 @@
 *Call, *this);
 
   ExplodedNodeSet DstInvalidated;
-  StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
-  for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
-   I != E; ++I)
-defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  // StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
+  // for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E =
+  // DstPreCall.end();
+  //  I != E; ++I)
+  //   defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  getCheckerManager().runCheckersForEvalCall(DstInvalidated, DstPreCall, *Call,
+ *this, CallOpts);
 
   getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated,
  *Call, *this);
Index: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -664,14 +664,11 @@
 for (const auto &EvalCallChecker : EvalCallCheckers) {
   // TODO: Support the situation when the call doesn't correspond
   // to any Expr.
-  ProgramPoint L = ProgramPoint::getProgramPoint(
-  Call.getOriginExpr(), ProgramPoint::PostStmtKind,
-  Pred->getLocationContext(), EvalCallChecker.Checker);
   bool evaluated = false;
   { // CheckerContext generates transitions(populates checkDest) on
 // destruction, so introduce the scope to make sure it gets properly
 // populated.
-CheckerContext C(B, Eng, Pred, L);
+CheckerContext C(B, Eng, Pred, Call.getProgramPoint());
 evaluated = EvalCallChecker(Call, C);
   }
   assert(!(evaluated && anyEvaluated)
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -139,7 +139,7 @@
 
   if (RD->getDeclName().isIdentifier()) {
 StringRef Name = RD->getName();
-return Name == "shared_ptr" || Name == "unique_ptr" || Name == "weak_ptr";
+return llvm::is_contained(STD_PTR_NAMES, Name);
   }
   return false;
 }
@@ -279,6 +279,7 @@
 CheckerContext &C) const {
 
   ProgramStateRef State = C.getState();
+  Call.dump();
 
   // If any one of the arg is a unique_ptr, then
   // we can try this function
@@ -372,6 +373,21 @@
 }
   }
 
+  if (const auto *DC = dyn_cast(&Call)) {
+llvm::errs() << "Found destructor call\n";
+State = DC->invalidateRegions(C.blockCount(), State);
+const MemRegion *ThisRegion = DC->getCXXThisVal().getAsRegion();
+// TODO: Remove this before pushing
+assert(ThisRegion && "We do not support explicit calls to destructor");
+const auto *InnerPtrVal = State->get(ThisRegion);
+State = State->remove(ThisRegion);
+if (InnerPtrVal)
+  State = State->invalidateRegions(*InnerPtrVal, nullptr, C.blockCount(),
+   C.getLocationContext(), true);
+C.addTransition(State);
+return true;
+  }
+
   if (!ModelSmartPtrDereference)
 return false;
 
@@ -402,8 +418,8 @@
   }));
 } else {
   const auto *TrackingExpr = Call.getArgExpr(0);
-  assert(TrackingExpr->getType()->isPointerType() &&
- "Adding a non pointer value to TrackedRegionMap");
+  if (!TrackingExpr->getType()->isPointerType())
+return false;
   auto ArgVal = Call.getArgSVal(0);
   State = State->set(ThisRegion, ArgVal);
 


Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -753,10 +753,13 @@
 *Call, *this);
 
   ExplodedNodeSet DstInvalidated;
-  StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
-  for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
-   I != E; ++I)
-defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  // StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
+  // for (ExplodedNo

[PATCH] D107063: Set TargetCPUName for AIX to default to pwr7.

2021-07-29 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser created this revision.
jamieschmeiser added reviewers: hubert.reinterpretcast, ZarkoCA, stevewan.
jamieschmeiser requested review of this revision.
Herald added a project: clang.

Set the TargetCPUName for AIX to default to pwr7, removing the setting
of it based on the major/minor of the OS version, which previously
set it to pwr4 for AIX 7.1 and earlier.  The old code would also set it to
pwr4 when the OS version was not specified and with the change, it will
default it to pwr7 in all cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107063

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/aix-mcpu-default.c


Index: clang/test/Driver/aix-mcpu-default.c
===
--- clang/test/Driver/aix-mcpu-default.c
+++ clang/test/Driver/aix-mcpu-default.c
@@ -6,13 +6,13 @@
 // CHECK-MCPU-DEFAULT-AIX72: {{.*}}clang{{.*}}" "-cc1"
 // CHECK-MCPU-DEFAULT-AIX72: "-target-cpu" "pwr7"
 
-// Check that the target cpu defaults to power4 on AIX7.1 and below.
+// Check that the target cpu defaults to power7 on AIX7.1 and below.
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
 // RUN:-target powerpc-ibm-aix7.1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX71 %s
 // CHECK-MCPU-DEFAULT-AIX71-NOT: warning:
 // CHECK-MCPU-DEFAULT-AIX71: {{.*}}clang{{.*}}" "-cc1"
-// CHECK-MCPU-DEFAULT-AIX71: "-target-cpu" "pwr4"
+// CHECK-MCPU-DEFAULT-AIX71: "-target-cpu" "pwr7"
 
 // Check that the user is able to overwrite the default with '-mcpu'.
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -403,14 +403,9 @@
 if (!TargetCPUName.empty())
   return TargetCPUName;
 
-if (T.isOSAIX()) {
-  unsigned major, minor, unused_micro;
-  T.getOSVersion(major, minor, unused_micro);
-  // The minimal arch level moved from pwr4 for AIX7.1 to
-  // pwr7 for AIX7.2.
-  TargetCPUName =
-  (major < 7 || (major == 7 && minor < 2)) ? "pwr4" : "pwr7";
-} else if (T.getArch() == llvm::Triple::ppc64le)
+if (T.isOSAIX())
+  TargetCPUName = "pwr7";
+else if (T.getArch() == llvm::Triple::ppc64le)
   TargetCPUName = "ppc64le";
 else if (T.getArch() == llvm::Triple::ppc64)
   TargetCPUName = "ppc64";


Index: clang/test/Driver/aix-mcpu-default.c
===
--- clang/test/Driver/aix-mcpu-default.c
+++ clang/test/Driver/aix-mcpu-default.c
@@ -6,13 +6,13 @@
 // CHECK-MCPU-DEFAULT-AIX72: {{.*}}clang{{.*}}" "-cc1"
 // CHECK-MCPU-DEFAULT-AIX72: "-target-cpu" "pwr7"
 
-// Check that the target cpu defaults to power4 on AIX7.1 and below.
+// Check that the target cpu defaults to power7 on AIX7.1 and below.
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
 // RUN:-target powerpc-ibm-aix7.1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX71 %s
 // CHECK-MCPU-DEFAULT-AIX71-NOT: warning:
 // CHECK-MCPU-DEFAULT-AIX71: {{.*}}clang{{.*}}" "-cc1"
-// CHECK-MCPU-DEFAULT-AIX71: "-target-cpu" "pwr4"
+// CHECK-MCPU-DEFAULT-AIX71: "-target-cpu" "pwr7"
 
 // Check that the user is able to overwrite the default with '-mcpu'.
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -403,14 +403,9 @@
 if (!TargetCPUName.empty())
   return TargetCPUName;
 
-if (T.isOSAIX()) {
-  unsigned major, minor, unused_micro;
-  T.getOSVersion(major, minor, unused_micro);
-  // The minimal arch level moved from pwr4 for AIX7.1 to
-  // pwr7 for AIX7.2.
-  TargetCPUName =
-  (major < 7 || (major == 7 && minor < 2)) ? "pwr4" : "pwr7";
-} else if (T.getArch() == llvm::Triple::ppc64le)
+if (T.isOSAIX())
+  TargetCPUName = "pwr7";
+else if (T.getArch() == llvm::Triple::ppc64le)
   TargetCPUName = "ppc64le";
 else if (T.getArch() == llvm::Triple::ppc64)
   TargetCPUName = "ppc64";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107002: [PowerPC] Implement XL compatibility builtin __addex

2021-07-29 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added inline comments.



Comment at: llvm/lib/Target/PowerPC/P9InstrResources.td:1434
+  ADDEX,
+  ADDEX8
 )> { let Unsupported = 1; }

You have added the 64-bit version of this, but it seems this is only available 
for 64-bit operands in 64-bit mode. Under which conditions do we need the plain 
`ADDEX`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107002

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


[PATCH] D107051: [clang][analyzer] Improve bug report in alpha.security.ReturnPtrRange

2021-07-29 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added reviewers: steakhal, NoQ, martong, vsavchenko.
Szelethus added a comment.
Herald added a subscriber: rnkovacs.

One of the test files needs fixing: 
https://reviews.llvm.org/harbormaster/unit/view/931615/

Love the patch, though I agree that the note message needs some improvement. 
How about we change from this:

  warning: Returned pointer value with index 11 points outside the original 
object with size of 10 'Data' objects (potential buffer overflow)

To this:

  warning: Returned pointer points outside the original object (potential 
buffer overflow)
  note: The original object 'Data' is an int array of size 10, the returned 
pointer points at the 11th element

or this:

  warning: Returned pointer points to the 11th element of 'Data', but that is 
an int array of size 10 (potential buffer overflow)




Comment at: clang/test/Analysis/return-ptr-range.cpp:1
-// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.security.ReturnPtrRange 
-verify %s
+// RUN1: %clang_analyze_cc1 -analyzer-checker=alpha.security.ReturnPtrRange 
-verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.security.ReturnPtrRange 
-analyzer-output text -verify=notes %s

steakhal wrote:
> Is `RUN1` intentional? If so, what does it do?
We could just delete it. I guess that was the intent, to make this RUN line 
non-functional.



Comment at: clang/test/Analysis/return-ptr-range.cpp:2
+// RUN1: %clang_analyze_cc1 -analyzer-checker=alpha.security.ReturnPtrRange 
-verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.security.ReturnPtrRange 
-analyzer-output text -verify=notes %s
 

steakhal wrote:
> You can specify multiple match prefixes.
> If you were passing `-verify=expected,notes`, you would not have to duplicate 
> each warning.
Don't forget `core`!



Comment at: clang/test/Analysis/return-ptr-range.cpp:11
+int arr3[10]; // notes-note{{Memory object declared here}}
 int *ptr;
 

steakhal wrote:
> This is not used in every test case. I would recommend moving this to the 
> function parameter where it's actually being used.
If this is a cpp file, just use namespaces, and redeclare everything inside 
them, like this: 
https://github.com/llvm/llvm-project/blob/main/clang/test/Analysis/track-control-dependency-conditions.cpp



Comment at: clang/test/Analysis/return-ptr-range.cpp:19-20
+ptr = arr1 + x; // notes-note{{Value assigned to 'ptr'}}
+if (x != 20) // notes-note{{Assuming 'x' is equal to 20}}
+ // notes-note@-1{{Taking false branch}}
+  return arr1; // no-warning

steakhal wrote:
> This is probably more of a taste.
> I would prefer fewer indentations.
> The same applies everywhere.
I disagree, and prefer it as it is written now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107051

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


[PATCH] D101960: [openmp] Drop requirement on library path environment variables

2021-07-29 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

Just ran into this again. It's really annoying that a test fails, and prints a 
run line, which can be copied into a terminal where it abjectly fails to run 
because the environment variables aren't set.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101960

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


[PATCH] D107063: Set TargetCPUName for AIX to default to pwr7.

2021-07-29 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast accepted this revision.
hubert.reinterpretcast added a comment.
This revision is now accepted and ready to land.

LGTM with comment.




Comment at: clang/test/Driver/aix-mcpu-default.c:9
 
-// Check that the target cpu defaults to power4 on AIX7.1 and below.
+// Check that the target cpu defaults to power7 on AIX7.1 and below.
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \

I suggest this test be modified to check that the target cpu is power7 even 
when the version level is unspecified.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107063

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


[PATCH] D107063: Set TargetCPUName for AIX to default to pwr7.

2021-07-29 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA added a comment.

Thanks @jamieschmeiser this change LGTM but I'll defer to 
@hubert.reinterpretcast for final approval.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107063

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


[PATCH] D106854: Pass `--start-group` and `--end-group` to the linker when using the AVR toolchain

2021-07-29 Thread Ben Shi via Phabricator via cfe-commits
benshi001 accepted this revision.
benshi001 added a comment.
This revision is now accepted and ready to land.

Do you need I land your patch for you?

What name and email do you expected to see in the commit message ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106854

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


[PATCH] D106854: Pass `--start-group` and `--end-group` to the linker when using the AVR toolchain

2021-07-29 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added a comment.

Do you mind if I change the title to "Pass --start-group and --end-group to 
avr-ld in clang driver" ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106854

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


[PATCH] D106899: [LLVM][NFC] Replace LLVM_ATTRIBUTE_NORETURN with [[noreturn]]

2021-07-29 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit added a comment.

I don't know why this is failing


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

https://reviews.llvm.org/D106899

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


[PATCH] D107063: Set TargetCPUName for AIX to default to pwr7.

2021-07-29 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser updated this revision to Diff 362760.
jamieschmeiser added a comment.

Respond to review comment:  expand testing.


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

https://reviews.llvm.org/D107063

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/aix-mcpu-default.c


Index: clang/test/Driver/aix-mcpu-default.c
===
--- clang/test/Driver/aix-mcpu-default.c
+++ clang/test/Driver/aix-mcpu-default.c
@@ -2,17 +2,35 @@
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
 // RUN:-target powerpc-ibm-aix7.2 \
 // RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
-// CHECK-MCPU-DEFAULT-AIX72-NOT: warning:
-// CHECK-MCPU-DEFAULT-AIX72: {{.*}}clang{{.*}}" "-cc1"
-// CHECK-MCPU-DEFAULT-AIX72: "-target-cpu" "pwr7"
 
-// Check that the target cpu defaults to power4 on AIX7.1 and below.
+// Check that the target cpu defaults to power7 on AIX7.2 and up.
+// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
+// RUN:-target powerpc64-ibm-aix7.2 \
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// Check that the target cpu defaults to power7 on AIX7.1 and below.
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
 // RUN:-target powerpc-ibm-aix7.1 \
-// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX71 %s
-// CHECK-MCPU-DEFAULT-AIX71-NOT: warning:
-// CHECK-MCPU-DEFAULT-AIX71: {{.*}}clang{{.*}}" "-cc1"
-// CHECK-MCPU-DEFAULT-AIX71: "-target-cpu" "pwr4"
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// Check that the target cpu defaults to power7 on AIX7.1 and below.
+// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
+// RUN:-target powerpc64-ibm-aix7.1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// Check that the target cpu defaults to power7 when level not specified.
+// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
+// RUN:-target powerpc-ibm-aix \
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// Check that the target cpu defaults to power7 when level not specified.
+// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
+// RUN:-target powerpc64-ibm-aix \
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// CHECK-MCPU-DEFAULT-AIX72-NOT: warning:
+// CHECK-MCPU-DEFAULT-AIX72: {{.*}}clang{{.*}}" "-cc1"
+// CHECK-MCPU-DEFAULT-AIX72: "-target-cpu" "pwr7"
 
 // Check that the user is able to overwrite the default with '-mcpu'.
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -403,14 +403,9 @@
 if (!TargetCPUName.empty())
   return TargetCPUName;
 
-if (T.isOSAIX()) {
-  unsigned major, minor, unused_micro;
-  T.getOSVersion(major, minor, unused_micro);
-  // The minimal arch level moved from pwr4 for AIX7.1 to
-  // pwr7 for AIX7.2.
-  TargetCPUName =
-  (major < 7 || (major == 7 && minor < 2)) ? "pwr4" : "pwr7";
-} else if (T.getArch() == llvm::Triple::ppc64le)
+if (T.isOSAIX())
+  TargetCPUName = "pwr7";
+else if (T.getArch() == llvm::Triple::ppc64le)
   TargetCPUName = "ppc64le";
 else if (T.getArch() == llvm::Triple::ppc64)
   TargetCPUName = "ppc64";


Index: clang/test/Driver/aix-mcpu-default.c
===
--- clang/test/Driver/aix-mcpu-default.c
+++ clang/test/Driver/aix-mcpu-default.c
@@ -2,17 +2,35 @@
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
 // RUN:-target powerpc-ibm-aix7.2 \
 // RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
-// CHECK-MCPU-DEFAULT-AIX72-NOT: warning:
-// CHECK-MCPU-DEFAULT-AIX72: {{.*}}clang{{.*}}" "-cc1"
-// CHECK-MCPU-DEFAULT-AIX72: "-target-cpu" "pwr7"
 
-// Check that the target cpu defaults to power4 on AIX7.1 and below.
+// Check that the target cpu defaults to power7 on AIX7.2 and up.
+// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
+// RUN:-target powerpc64-ibm-aix7.2 \
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// Check that the target cpu defaults to power7 on AIX7.1 and below.
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
 // RUN:-target powerpc-ibm-aix7.1 \
-// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX71 %s
-// CHECK-MCPU-DEFAULT-AIX71-NOT: warning:
-// CHECK-MCPU-DEFAULT-AIX71: {{.*}}clang{{.*}}" "-cc1"
-// CHECK-MCPU-DEFAULT-AIX71: "-target-cpu" "pwr4"
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// Check that the target cpu defaults to power7 on AIX7.1 and below.
+// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
+// RUN:-target pow

[PATCH] D107063: Set TargetCPUName for AIX to default to pwr7.

2021-07-29 Thread Jamie Schmeiser 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 rGc3c1826c310c: Set TargetCPUName for AIX to default to pwr7. 
(authored by jamieschmeiser).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107063

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/aix-mcpu-default.c


Index: clang/test/Driver/aix-mcpu-default.c
===
--- clang/test/Driver/aix-mcpu-default.c
+++ clang/test/Driver/aix-mcpu-default.c
@@ -2,17 +2,35 @@
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
 // RUN:-target powerpc-ibm-aix7.2 \
 // RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
-// CHECK-MCPU-DEFAULT-AIX72-NOT: warning:
-// CHECK-MCPU-DEFAULT-AIX72: {{.*}}clang{{.*}}" "-cc1"
-// CHECK-MCPU-DEFAULT-AIX72: "-target-cpu" "pwr7"
 
-// Check that the target cpu defaults to power4 on AIX7.1 and below.
+// Check that the target cpu defaults to power7 on AIX7.2 and up.
+// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
+// RUN:-target powerpc64-ibm-aix7.2 \
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// Check that the target cpu defaults to power7 on AIX7.1 and below.
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
 // RUN:-target powerpc-ibm-aix7.1 \
-// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX71 %s
-// CHECK-MCPU-DEFAULT-AIX71-NOT: warning:
-// CHECK-MCPU-DEFAULT-AIX71: {{.*}}clang{{.*}}" "-cc1"
-// CHECK-MCPU-DEFAULT-AIX71: "-target-cpu" "pwr4"
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// Check that the target cpu defaults to power7 on AIX7.1 and below.
+// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
+// RUN:-target powerpc64-ibm-aix7.1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// Check that the target cpu defaults to power7 when level not specified.
+// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
+// RUN:-target powerpc-ibm-aix \
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// Check that the target cpu defaults to power7 when level not specified.
+// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
+// RUN:-target powerpc64-ibm-aix \
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// CHECK-MCPU-DEFAULT-AIX72-NOT: warning:
+// CHECK-MCPU-DEFAULT-AIX72: {{.*}}clang{{.*}}" "-cc1"
+// CHECK-MCPU-DEFAULT-AIX72: "-target-cpu" "pwr7"
 
 // Check that the user is able to overwrite the default with '-mcpu'.
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -403,14 +403,9 @@
 if (!TargetCPUName.empty())
   return TargetCPUName;
 
-if (T.isOSAIX()) {
-  unsigned major, minor, unused_micro;
-  T.getOSVersion(major, minor, unused_micro);
-  // The minimal arch level moved from pwr4 for AIX7.1 to
-  // pwr7 for AIX7.2.
-  TargetCPUName =
-  (major < 7 || (major == 7 && minor < 2)) ? "pwr4" : "pwr7";
-} else if (T.getArch() == llvm::Triple::ppc64le)
+if (T.isOSAIX())
+  TargetCPUName = "pwr7";
+else if (T.getArch() == llvm::Triple::ppc64le)
   TargetCPUName = "ppc64le";
 else if (T.getArch() == llvm::Triple::ppc64)
   TargetCPUName = "ppc64";


Index: clang/test/Driver/aix-mcpu-default.c
===
--- clang/test/Driver/aix-mcpu-default.c
+++ clang/test/Driver/aix-mcpu-default.c
@@ -2,17 +2,35 @@
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
 // RUN:-target powerpc-ibm-aix7.2 \
 // RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
-// CHECK-MCPU-DEFAULT-AIX72-NOT: warning:
-// CHECK-MCPU-DEFAULT-AIX72: {{.*}}clang{{.*}}" "-cc1"
-// CHECK-MCPU-DEFAULT-AIX72: "-target-cpu" "pwr7"
 
-// Check that the target cpu defaults to power4 on AIX7.1 and below.
+// Check that the target cpu defaults to power7 on AIX7.2 and up.
+// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
+// RUN:-target powerpc64-ibm-aix7.2 \
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// Check that the target cpu defaults to power7 on AIX7.1 and below.
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
 // RUN:-target powerpc-ibm-aix7.1 \
-// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX71 %s
-// CHECK-MCPU-DEFAULT-AIX71-NOT: warning:
-// CHECK-MCPU-DEFAULT-AIX71: {{.*}}clang{{.*}}" "-cc1"
-// CHECK-MCPU-DEFAULT-AIX71: "-target-cpu" "pwr4"
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// Ch

[clang] c3c1826 - Set TargetCPUName for AIX to default to pwr7.

2021-07-29 Thread Jamie Schmeiser via cfe-commits

Author: Jamie Schmeiser
Date: 2021-07-29T09:59:24-04:00
New Revision: c3c1826c310c42244c7cad8d0c6af3a368fcd064

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

LOG: Set TargetCPUName for AIX to default to pwr7.

Summary:
Set the TargetCPUName for AIX to default to pwr7, removing the setting
of it based on the major/minor of the OS version, which previously
set it to pwr4 for AIX 7.1 and earlier. The old code would also set it to
pwr4 when the OS version was not specified and with the change, it will
default it to pwr7 in all cases.

Author: Jamie Schmeiser 
Reviewed By:hubert.reinterpretcast (Hubert Tong)
Differential Revision: https://reviews.llvm.org/D107063

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/aix-mcpu-default.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 83cab3ac00cb6..d9a6599a24160 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -403,14 +403,9 @@ std::string tools::getCPUName(const ArgList &Args, const 
llvm::Triple &T,
 if (!TargetCPUName.empty())
   return TargetCPUName;
 
-if (T.isOSAIX()) {
-  unsigned major, minor, unused_micro;
-  T.getOSVersion(major, minor, unused_micro);
-  // The minimal arch level moved from pwr4 for AIX7.1 to
-  // pwr7 for AIX7.2.
-  TargetCPUName =
-  (major < 7 || (major == 7 && minor < 2)) ? "pwr4" : "pwr7";
-} else if (T.getArch() == llvm::Triple::ppc64le)
+if (T.isOSAIX())
+  TargetCPUName = "pwr7";
+else if (T.getArch() == llvm::Triple::ppc64le)
   TargetCPUName = "ppc64le";
 else if (T.getArch() == llvm::Triple::ppc64)
   TargetCPUName = "ppc64";

diff  --git a/clang/test/Driver/aix-mcpu-default.c 
b/clang/test/Driver/aix-mcpu-default.c
index 7b55839a80661..3bb3c7f95e1e9 100644
--- a/clang/test/Driver/aix-mcpu-default.c
+++ b/clang/test/Driver/aix-mcpu-default.c
@@ -2,17 +2,35 @@
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
 // RUN:-target powerpc-ibm-aix7.2 \
 // RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
-// CHECK-MCPU-DEFAULT-AIX72-NOT: warning:
-// CHECK-MCPU-DEFAULT-AIX72: {{.*}}clang{{.*}}" "-cc1"
-// CHECK-MCPU-DEFAULT-AIX72: "-target-cpu" "pwr7"
 
-// Check that the target cpu defaults to power4 on AIX7.1 and below.
+// Check that the target cpu defaults to power7 on AIX7.2 and up.
+// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
+// RUN:-target powerpc64-ibm-aix7.2 \
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// Check that the target cpu defaults to power7 on AIX7.1 and below.
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
 // RUN:-target powerpc-ibm-aix7.1 \
-// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX71 %s
-// CHECK-MCPU-DEFAULT-AIX71-NOT: warning:
-// CHECK-MCPU-DEFAULT-AIX71: {{.*}}clang{{.*}}" "-cc1"
-// CHECK-MCPU-DEFAULT-AIX71: "-target-cpu" "pwr4"
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// Check that the target cpu defaults to power7 on AIX7.1 and below.
+// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
+// RUN:-target powerpc64-ibm-aix7.1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// Check that the target cpu defaults to power7 when level not specified.
+// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
+// RUN:-target powerpc-ibm-aix \
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// Check that the target cpu defaults to power7 when level not specified.
+// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
+// RUN:-target powerpc64-ibm-aix \
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s
+
+// CHECK-MCPU-DEFAULT-AIX72-NOT: warning:
+// CHECK-MCPU-DEFAULT-AIX72: {{.*}}clang{{.*}}" "-cc1"
+// CHECK-MCPU-DEFAULT-AIX72: "-target-cpu" "pwr7"
 
 // Check that the user is able to overwrite the default with '-mcpu'.
 // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \



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


[PATCH] D107073: [analyzer] Disable direct binding from list initialization for constant arrays of local storage duration.

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

Ignore direct bindings for constant arrays of local storage duration with list 
initialization. Constant arrays don't change their values during a lifetime. 
Therefore, we don't have to bind values directly for each array element. 
Retrieve values from list initialization on-demand as it currently works for 
arrays of global storage duration (See https://reviews.llvm.org/D106681 for 
details).

Example: `const int arr[42] = {1,2,3,4};`.
We can get values directly from list initializaion in any time, no matter 
whether the array has **global** or **local** storage duration. Previously it 
works only for **global** arrays.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107073

Files:
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/initialization.c
  clang/test/Analysis/initialization.cpp

Index: clang/test/Analysis/initialization.cpp
===
--- clang/test/Analysis/initialization.cpp
+++ clang/test/Analysis/initialization.cpp
@@ -167,7 +167,7 @@
   clang_analyzer_eval(glob_arr3[3][1] == 0); // expected-warning{{TRUE}}
 }
 
-void negative_index1() {
+void glob_arr_negative_index1() {
   int x = 2, y = -2;
   clang_analyzer_eval(glob_arr3[x][y] == 3); // expected-warning{{TRUE}}
   x = 4;
@@ -175,12 +175,12 @@
   clang_analyzer_eval(glob_arr3[x][y] == 7); // expected-warning{{TRUE}}
 }
 
-void out_of_bound_index1() {
+void glob_arr_out_of_bound_index1() {
   int x = -3, y = 2;
   int res = glob_arr3[x][y]; // expected-warning{{garbage or undefined}}
 }
 
-void out_of_bound_index2() {
+void glob_arr_out_of_bound_index2() {
   int x = 3, y = 2;
   int res = glob_arr3[x][y]; // expected-warning{{garbage or undefined}}
 }
@@ -197,12 +197,101 @@
   clang_analyzer_eval(glob_arr4[7] == 0); // expected-warning{{TRUE}}
 }
 
-void out_of_bound_index3() {
+void glob_arr_out_of_bound_index3() {
   int x = -42;
   int res = glob_arr4[x]; // expected-warning{{garbage or undefined}}
 }
 
-void out_of_bound_index4() {
+void glob_arr_out_of_bound_index4() {
   int x = 42;
   int res = glob_arr4[x]; // expected-warning{{garbage or undefined}}
 }
+
+void local_arr_index1() {
+  const int local_arr[2][2][3] = {{{1, 2}}, {{7}}};
+  clang_analyzer_eval(local_arr[0][0][0] == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[0][0][1] == 2); // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[0][0][2] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[0][1][0] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[0][1][1] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[0][1][2] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[1][0][0] == 7); // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[1][0][1] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[1][0][2] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[1][1][0] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[1][1][1] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[1][1][2] == 0); // expected-warning{{TRUE}}
+}
+
+void local_arr_index2() {
+  int const local_arr[2][2][3] = {{{1, 2}, {}}, {{7, 8}, {10, 11, 12}}};
+  clang_analyzer_eval(local_arr[0][0][0] == 1);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[0][0][1] == 2);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[0][0][2] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[0][1][0] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[0][1][1] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[0][1][2] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[1][0][0] == 7);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[1][0][1] == 8);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[1][0][2] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[1][1][0] == 10); // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[1][1][1] == 11); // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[1][1][2] == 12); // expected-warning{{TRUE}}
+}
+
+void local_arr_index3() {
+  const int local_arr[4][2] = {{}, {3}, {}, {7}};
+  clang_analyzer_eval(local_arr[0][0] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[0][1] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[1][0] == 3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[1][1] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(local_arr[2][

[PATCH] D92928: [analyzer] Highlight arrows for currently selected event

2021-07-29 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov accepted this revision.
ASDenysPetrov added a comment.
This revision is now accepted and ready to land.

Let's load this patch and I will prepare the adjustment for IE in pursuit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92928

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


[PATCH] D106732: Support macro deprecation #pragma clang deprecated

2021-07-29 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 362764.
beanz marked 3 inline comments as done.
beanz added a comment.

Addressing @aaron.ballman's feedback.

I've added FIXMEs and test cases with not-expected annotations so that in the 
future if the underlying issue gets fixed, the tests should only need updating 
from not-expected to expected.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106732

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Lex/Pragma.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/test/Lexer/deprecate-macro.c

Index: clang/test/Lexer/deprecate-macro.c
===
--- /dev/null
+++ clang/test/Lexer/deprecate-macro.c
@@ -0,0 +1,98 @@
+// RUN: %clang_cc1 -Wdeprecated %s -fsyntax-only -verify
+
+// expected-error@+1{{expected (}}
+#pragma clang deprecated
+
+// expected-error@+1{{expected identifier}}
+#pragma clang deprecated(4
+
+// expected-error@+1{{no macro named foo}}
+#pragma clang deprecated(foo)
+
+#define bar 1
+#pragma clang deprecated(bar, "bar is deprecated use 1")
+
+// expected-warning@+1{{macro 'bar' has been marked as deprecated: bar is deprecated use 1}}
+#if bar
+#endif
+
+#define foo 1
+#pragma clang deprecated(foo)
+
+// expected-error@+1{{expected )}}
+#pragma clang deprecated(foo
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#if foo
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#if defined(foo)
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#ifdef foo
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#ifndef foo
+#endif
+
+int main(int argc, char** argv) {
+  // expected-error@+1{{no macro named main}}
+#pragma clang deprecated(main)
+
+  // expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+  return foo;
+}
+
+#define frobble 1
+#pragma clang deprecated(frobble)
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#undef frobble // Expect no diagnostics here
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#define frobble 1 // How about here given that this was undefined?
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#if defined(frobble)
+#endif
+
+// Test that we diagnose on #elif.
+#if 0
+#elif foo
+// expected-warning@-1{{macro 'foo' has been marked as deprecated}}
+#endif
+
+
+// Test that we diagnose on #elifdef.
+#ifdef baz
+#elifdef foo
+// expected-warning@-1{{macro 'foo' has been marked as deprecated}}
+#endif
+
+// Test that we diagnose on #elifndef.
+#ifdef baz
+#elifndef foo
+#endif
+// expected-warning@-2{{macro 'foo' has been marked as deprecated}}
+
+// FIXME: These cases are currently not handled because clang doesn't expand
+// conditions on skipped #elif* blocks. See the FIXME notes in
+// Preprocessor::SkipExcludedConditionalBlock.
+
+#ifdef frobble
+// not-expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#elifndef foo
+#endif
+
+#ifdef frobble
+// not-expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#elifdef foo
+#endif
+
+#if 1
+// not-expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#elif foo
+#endif
Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -1413,6 +1413,18 @@
   return true;
 }
 
+void Preprocessor::emitMacroExpansionWarnings(const Token &Identifier) {
+  if (Identifier.getIdentifierInfo()->isDeprecatedMacro()) {
+auto DepMsg = getMacroDeprecationMsg(Identifier.getIdentifierInfo());
+if (!DepMsg)
+  Diag(Identifier, diag::warn_pragma_deprecated_macro_use)
+  << Identifier.getIdentifierInfo() << 0;
+else
+  Diag(Identifier, diag::warn_pragma_deprecated_macro_use)
+  << Identifier.getIdentifierInfo() << 1 << *DepMsg;
+  }
+}
+
 ModuleLoader::~ModuleLoader() = default;
 
 CommentHandler::~CommentHandler() = default;
Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1911,6 +1911,57 @@
   }
 };
 
+/// "\#pragma clang deprecated(...)"
+///
+/// The syntax is
+/// \code
+///   #pragma clang deprecate(MACRO_NAME [, Message])
+/// \endcode
+struct PragmaDeprecatedHandler : public PragmaHandler {
+  PragmaDeprecatedHandler() : PragmaHandler("deprecated") {}
+
+  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
+Token &Tok) override {
+std

[PATCH] D106277: [SVE] Remove the interface for getMaxVScale in favour of the IR attributes

2021-07-29 Thread Fraser Cormack via Phabricator via cfe-commits
frasercrmck added a comment.

In D106277#2913136 , @paulwalker-arm 
wrote:

> @craig.topper can you share RISCV plans around supporting vscale_range?  In 
> essence we'd like to deprecate the TTI method and have LLVM IR contain all 
> relevant information when is comes to interpreting vscale.
>
> Currently the usage is minimal and so checking both interfaces is not too bad 
> but they'll come a point when there's no TTI available and then only the side 
> supporting vscale_range can be considered.  There's also the LTO side of 
> things where relying on opt/llc flags to set register widths becomes fragile.

As it happens I was playing around with adding support for that today at least 
to get us started. I was going to put something up for review based on this 
patch, assuming this gets merged first.

However in the TTI method we're currently making use of some `RISCVSubtarget` 
properties to help refine the vscale range, so we'll need to think about how 
we'll deal with those.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106277

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


[PATCH] D104854: Introduce intrinsic llvm.isnan

2021-07-29 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: llvm/test/CodeGen/X86/x86-fpclass.ll:173
+
+define <1 x i1> @isnan_double_vec1(<1 x double> %x) {
+; CHECK-32-LABEL: isnan_double_vec1:

RKSimon wrote:
> add nounwind to reduce cfi noise (other tests would benefit as well)?
Good hint, thank you!



Comment at: llvm/test/Transforms/InstSimplify/ConstProp/fpclassify.ll:1
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+

RKSimon wrote:
> Use update_test_checks.py?
Done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104854

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


[PATCH] D107077: [PowerPC] Fix return type of XL compat CAS

2021-07-29 Thread Kai Luo via Phabricator via cfe-commits
lkail created this revision.
lkail added reviewers: jsji, PowerPC.
Herald added subscribers: shchenz, kbarton, nemanjai.
lkail requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`__compare_and_swap*` should return `i32` rather than `i1`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107077

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-cas.c


Index: clang/test/CodeGen/builtins-ppc-xlcompat-cas.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat-cas.c
+++ clang/test/CodeGen/builtins-ppc-xlcompat-cas.c
@@ -20,10 +20,11 @@
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { i32, i1 } [[TMP2]], 0
 // CHECK-NEXT:[[TMP4:%.*]] = extractvalue { i32, i1 } [[TMP2]], 1
 // CHECK-NEXT:store i32 [[TMP3]], i32* [[B_ADDR]], align 4
-// CHECK-NEXT:ret void
+// CHECK-NEXT:[[TMP5:%.*]] = zext i1 [[TMP4]] to i32
+// CHECK-NEXT:ret i32 [[TMP5]]
 //
-void test_builtin_ppc_compare_and_swap(int a, int b, int c) {
-  __compare_and_swap(&a, &b, c);
+int test_builtin_ppc_compare_and_swap(int a, int b, int c) {
+  return __compare_and_swap(&a, &b, c);
 }
 
 
@@ -41,9 +42,10 @@
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { i64, i1 } [[TMP2]], 0
 // CHECK-NEXT:[[TMP4:%.*]] = extractvalue { i64, i1 } [[TMP2]], 1
 // CHECK-NEXT:store i64 [[TMP3]], i64* [[B_ADDR]], align 8
-// CHECK-NEXT:ret void
+// CHECK-NEXT:[[TMP5:%.*]] = zext i1 [[TMP4]] to i32
+// CHECK-NEXT:ret i32 [[TMP5]]
 //
-void test_builtin_ppc_compare_and_swaplp(long a, long b, long c) {
-  __compare_and_swaplp(&a, &b, c);
+int test_builtin_ppc_compare_and_swaplp(long a, long b, long c) {
+  return __compare_and_swaplp(&a, &b, c);
 }
 
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -15808,7 +15808,7 @@
 // store.
 Value *LoadedVal = Pair.first.getScalarVal();
 Builder.CreateStore(LoadedVal, OldValAddr);
-return Pair.second;
+return Builder.CreateZExt(Pair.second, Builder.getInt32Ty());
   }
   case PPC::BI__builtin_ppc_fetch_and_add:
   case PPC::BI__builtin_ppc_fetch_and_addlp: {


Index: clang/test/CodeGen/builtins-ppc-xlcompat-cas.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat-cas.c
+++ clang/test/CodeGen/builtins-ppc-xlcompat-cas.c
@@ -20,10 +20,11 @@
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { i32, i1 } [[TMP2]], 0
 // CHECK-NEXT:[[TMP4:%.*]] = extractvalue { i32, i1 } [[TMP2]], 1
 // CHECK-NEXT:store i32 [[TMP3]], i32* [[B_ADDR]], align 4
-// CHECK-NEXT:ret void
+// CHECK-NEXT:[[TMP5:%.*]] = zext i1 [[TMP4]] to i32
+// CHECK-NEXT:ret i32 [[TMP5]]
 //
-void test_builtin_ppc_compare_and_swap(int a, int b, int c) {
-  __compare_and_swap(&a, &b, c);
+int test_builtin_ppc_compare_and_swap(int a, int b, int c) {
+  return __compare_and_swap(&a, &b, c);
 }
 
 
@@ -41,9 +42,10 @@
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { i64, i1 } [[TMP2]], 0
 // CHECK-NEXT:[[TMP4:%.*]] = extractvalue { i64, i1 } [[TMP2]], 1
 // CHECK-NEXT:store i64 [[TMP3]], i64* [[B_ADDR]], align 8
-// CHECK-NEXT:ret void
+// CHECK-NEXT:[[TMP5:%.*]] = zext i1 [[TMP4]] to i32
+// CHECK-NEXT:ret i32 [[TMP5]]
 //
-void test_builtin_ppc_compare_and_swaplp(long a, long b, long c) {
-  __compare_and_swaplp(&a, &b, c);
+int test_builtin_ppc_compare_and_swaplp(long a, long b, long c) {
+  return __compare_and_swaplp(&a, &b, c);
 }
 
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -15808,7 +15808,7 @@
 // store.
 Value *LoadedVal = Pair.first.getScalarVal();
 Builder.CreateStore(LoadedVal, OldValAddr);
-return Pair.second;
+return Builder.CreateZExt(Pair.second, Builder.getInt32Ty());
   }
   case PPC::BI__builtin_ppc_fetch_and_add:
   case PPC::BI__builtin_ppc_fetch_and_addlp: {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107077: [PowerPC] Fix return type of XL compat CAS

2021-07-29 Thread Jinsong Ji via Phabricator via cfe-commits
jsji accepted this revision as: jsji.
jsji added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107077

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


[PATCH] D107078: [analyzer] Catch leaking stack addresses via stack variables

2021-07-29 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: NoQ, vsavchenko, martong, Szelethus.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun, 
whisperity.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Not only global variables can hold references to dead stack variables.
Consider this example:

  void write_stack_address_to(char **q) {
char local;
*q = &local;
  }
  
  void test_stack() {
char *p;
write_stack_address_to(&p);
  }

The address of `local` is assigned to `p`, which becomes a dangling
pointer after `write_stack_address_to()` returns.

The `StackAddrEscapeChecker` was looking for bindings in the store which
referred to variables of the popped stack frame, but it only considered
global variables in this regard. This patch relaxes this, catching
stack variable bindings as well.

---

This patch also works for temporary objects like:

  struct Bar {
const int &ref;
explicit Bar(int y) : ref(y) {
  // Okay.
} // End of the constructor call, `ref` is dangling now. Warning!
  };
  
  void test() {
Bar{33}; // Temporary object, so the corresponding memregion is
 // *not* a VarRegion.
  }



---

The **r**eturn **v**alue **o**ptimization aka. //copy-elision// might kick in 
but that
is modeled by passing an imaginary `CXXThisRegion` which refers to the
parent stack frame which is supposed to be the //return slot//.
Objects residing in the //return slot// outlive the scope of the inner
call, thus we should expect no warning about them - except if we
explicitly disable //copy-elision//.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107078

Files:
  clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
  clang/test/Analysis/copy-elision.cpp
  clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
  clang/test/Analysis/loop-block-counts.c
  clang/test/Analysis/stack-addr-ps.cpp

Index: clang/test/Analysis/stack-addr-ps.cpp
===
--- clang/test/Analysis/stack-addr-ps.cpp
+++ clang/test/Analysis/stack-addr-ps.cpp
@@ -137,3 +137,15 @@
   }
 }
 
+void write_stack_address_to(char **q) {
+  char local;
+  *q = &local;
+  // expected-warning@-1 {{Address of stack memory associated with local \
+variable 'local' is still referred to by the stack variable 'p' upon \
+returning to the caller}}
+}
+
+void test_stack() {
+  char *p;
+  write_stack_address_to(&p);
+}
Index: clang/test/Analysis/loop-block-counts.c
===
--- clang/test/Analysis/loop-block-counts.c
+++ clang/test/Analysis/loop-block-counts.c
@@ -5,6 +5,9 @@
 void callee(void **p) {
   int x;
   *p = &x;
+  // expected-warning@-1 {{Address of stack memory associated with local \
+variable 'x' is still referred to by the stack variable 'arr' upon \
+returning to the caller}}
 }
 
 void loop() {
Index: clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
===
--- clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
+++ clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
@@ -71,12 +71,17 @@
   void *allocaPtr;
   int dontGetFilteredByNonPedanticMode = 0;
 
+  // expected-warning-re@+3 {{Address of stack memory allocated by call to \
+alloca() on line {{[0-9]+}} is still referred to by a temporary object on the \
+stack upon returning to the caller.  This will be a dangling reference}}
   UntypedAllocaTest() : allocaPtr(__builtin_alloca(sizeof(int))) {
 // All good!
   }
 };
 
 void fUntypedAllocaTest() {
+  // expected-note@+2 {{The temporary object gets destroyed at the end of the \
+full expression}}
   UntypedAllocaTest();
 }
 
@@ -86,9 +91,14 @@
 
   TypedAllocaTest1() // expected-warning{{1 uninitialized field}}
   : allocaPtr(static_cast(__builtin_alloca(sizeof(int {}
+  // expected-warning-re@-2 {{Address of stack memory allocated by call to \
+alloca() on line {{[0-9]+}} is still referred to by a temporary object on the \
+stack upon returning to the caller.  This will be a dangling reference}}
 };
 
 void fTypedAllocaTest1() {
+  // expected-note@+2 {{The temporary object gets destroyed at the end of the \
+full expression}}
   TypedAllocaTest1();
 }
 
@@ -96,6 +106,9 @@
   int *allocaPtr;
   int dontGetFilteredByNonPedanticMode = 0;
 
+  // expected-warning-re@+5 {{Address of stack memory allocated by call to \
+alloca() on line {{[0-9]+}} is still referred to by a temporary object on the \
+stack upon returning to the caller.  This will be a dangling reference}}
   TypedAllocaTest2()
   : allocaPtr(static_cast(__builtin_alloca(sizeof(int {
 *allocaPtr = 5;
@@ -104,6 +117,8 @@
 };
 
 void fTypedAllocaTest2() {
+  // expected-note@+2 {{The temporary object gets destroyed at the end of 

[PATCH] D89380: [clang-tidy] Fix for cppcoreguidelines-prefer-member-initializer to handle classes declared in macros

2021-07-29 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

@baloghadamsoftware Ping.


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

https://reviews.llvm.org/D89380

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


[PATCH] D105904: [clangd] Support `#pragma mark` in the outline

2021-07-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/CollectMacros.cpp:13
 
+namespace {
+class CollectPragmaMarks : public clang::PPCallbacks {

can you nest this inside `clang::clangd` and drop the qualifiers ?



Comment at: clang-tools-extra/clangd/CollectMacros.cpp:20
+  void PragmaMark(clang::SourceLocation Loc, clang::StringRef Trivia) override 
{
+if (clang::clangd::isInsideMainFile(Loc, SM)) {
+  clang::StringRef Name = Trivia.trim();

nit: drop braces



Comment at: clang-tools-extra/clangd/CollectMacros.h:106
+struct PragmaMark {
+  SourceLocation Loc;
+  std::string Text;

sammccall wrote:
> Line number is enough, right?
> Column is not interesting, and pragma marks expanded from macros are not 
> possible (and wouldn't be in the main file for our purposes)
okay then let's store a `Range` here instead, and get rid of the dependency on 
a SourceManager for rendering it maybe?



Comment at: clang-tools-extra/clangd/FindSymbols.cpp:682
+  // here since editors won't properly render the symbol otherwise.
+  StringRef MaybeGroupName = Name;
+  if (MaybeGroupName.consume_front("-") &&

I think this reads easier:

```
bool IsGroup = Name.consume_front("-");
Name = Name.ltrim();
if (Name.empty())
  Name = IsGroup ? "unnamed group" : ...;
```



Comment at: clang-tools-extra/clangd/FindSymbols.cpp:535
+/// by range.
+std::vector mergePragmas(std::vector &Syms,
+ std::vector 
&Pragmas,

dgoldman wrote:
> sammccall wrote:
> > FWIW the flow control/how we make progress seem hard to follow here to me.
> > 
> > In particular I think I'm struggling with the statefulness of "is there an 
> > open mark group".
> > 
> > Possible simplifications:
> >  - define a dummy root symbol, which seems clearer than the vector 
> > + range
> >  - avoid reverse-sorting the list of pragma symbols, and just consume from 
> > the front of an ArrayRef instead
> >  - make the outer loop over pragmas, rather than symbols. It would first 
> > check if the pragma belongs directly here or not, and if so, loop over 
> > symbols to work out which should become children. This seems very likely to 
> > be efficient enough in practice (few pragmas, or most children are grouped 
> > into pragmas)
> > define a dummy root symbol, which seems clearer than the vector + 
> > range
> 
> I guess? Then we'd take in a `DocumentSymbol & and a 
> ArrayRef & (or just by value and then return it as well). 
> The rest would be the same though
> 
> > In particular I think I'm struggling with the statefulness of "is there an 
> > open mark group".
> 
> We need to track the current open group if there is one in order to move 
> children to it.
> 
> > make the outer loop over pragmas, rather than symbols. It would first check 
> > if the pragma belongs directly here or not, and if so, loop over symbols to 
> > work out which should become children. This seems very likely to be 
> > efficient enough in practice (few pragmas, or most children are grouped 
> > into pragmas)
> 
> The important thing here is knowing where the pragma mark ends - if it 
> doesn't, it actually gets all of the children. So we'd have to peak at the 
> next pragma mark, add all symbols before it to us as children, and then 
> potentially recurse to nest it inside of a symbol. I'll try it out and see if 
> it's simpler.
> 
> 
```
while(Pragmas) {
// We'll figure out where the Pragmas.front() should go.
Pragma P = Pragmas.front();
DocumentSymbol *Cur = Root;
while(Cur->contains(P)) {
  auto *OldCur = Cur;
  for(auto *C : Cur->children) {
 // We assume at most 1 child can contain the pragma (as pragmas are on a 
single line, and children have disjoint ranges)
 if (C->contains(P)) {
 Cur = C;
 break;
 }
  }
  // Cur is immediate parent of P
  if (OldCur == Cur) {
// Just insert P into children if it is not a group and we are done.
// Otherwise we need to figure out when current pragma is terminated:
// if next pragma is not contained in Cur, or is contained in one of the 
children, It is at the end of Cur, nest all the children that appear after P 
under the symbol node for P.
// Otherwise nest all the children that appear after P but before next pragma 
under the symbol node for P.
// Pop Pragmas and break
  }
}
}
```

Does that make sense, i hope i am not missing something obvious? 
Complexity-wise in the worst case we'll go all the way down to a leaf once per 
pragma, since there will only be a handful of pragmas most of the time it 
shouldn't be too bad.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105904

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

[PATCH] D106644: [clang][analyzer] Add standard streams to alpha.unix.Stream checker.

2021-07-29 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 362775.
balazske added a comment.
Herald added a subscriber: mgorny.

Split some type lookup functions from StdLibraryFunctionsChecker into separate 
files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106644

Files:
  clang/lib/StaticAnalyzer/Checkers/ASTLookup.cpp
  clang/lib/StaticAnalyzer/Checkers/ASTLookup.h
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/stream.c

Index: clang/test/Analysis/stream.c
===
--- clang/test/Analysis/stream.c
+++ clang/test/Analysis/stream.c
@@ -267,3 +267,12 @@
 } // expected-warning {{Opened stream never closed. Potential resource leak}}
 // FIXME: This warning should be placed at the `return` above.
 // See https://reviews.llvm.org/D83120 about details.
+
+void check_fopen_is_not_std(FILE *F, int Std) {
+  if (!Std)
+F = fopen("file", "r");
+  if (!F)
+return;
+  if (F != stdin && F != stdout && F != stderr)
+fclose(F); // no warning: the opened file can not be equal to std streams
+}
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -10,6 +10,8 @@
 //
 //===--===//
 
+#include "ASTLookup.h"
+#include "clang/AST/ParentMapContext.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -157,6 +159,11 @@
 // StreamChecker class and utility functions.
 //===--===//
 
+// This map holds the state of a stream.
+// The stream is identified with a SymbolRef that is created when a stream
+// opening function is modeled by the checker.
+REGISTER_MAP_WITH_PROGRAMSTATE(StreamMap, SymbolRef, StreamState)
+
 namespace {
 
 class StreamChecker;
@@ -206,8 +213,49 @@
   return State;
 }
 
-class StreamChecker : public Checker {
+const VarDecl *findStdStreamDecl(StringRef StdName, CheckerContext &C) {
+  ASTContext &ACtx = C.getASTContext();
+
+  ast_lookup::LookupType LookupType(ACtx);
+  ast_lookup::GetPointerTy GetPointer(ACtx);
+
+  IdentifierInfo &II = ACtx.Idents.get(StdName);
+  auto LookupRes = ACtx.getTranslationUnitDecl()->lookup(&II);
+
+  Optional FILEType = GetPointer(LookupType("FILE"));
+
+  for (Decl *D : LookupRes) {
+D = D->getCanonicalDecl();
+if (!C.getSourceManager().isInSystemHeader(D->getLocation()))
+  continue;
+if (auto *VD = dyn_cast(D)) {
+  if (FILEType && !ACtx.hasSameType(*FILEType, VD->getType()))
+continue;
+  return VD;
+}
+  }
+
+  return nullptr;
+}
+
+SymbolRef findStdStream(StringRef StdName, CheckerContext &C) {
+  const LocationContext *LCtx = C.getLocationContext();
+
+  const VarDecl *StdDecl = findStdStreamDecl(StdName, C);
+  if (!StdDecl)
+return nullptr;
+
+  const VarRegion *RegionOfStdStreamVar =
+  C.getState()->getRegion(StdDecl, LCtx);
+  if (!RegionOfStdStreamVar)
+return nullptr;
+  SVal StdVal = C.getState()->getSVal(RegionOfStdStreamVar, StdDecl->getType());
+  return StdVal.getAsSymbol();
+}
+
+class StreamChecker
+: public Checker {
   BugType BT_FileNull{this, "NULL stream pointer", "Stream handling error"};
   BugType BT_UseAfterClose{this, "Closed stream", "Stream handling error"};
   BugType BT_UseAfterOpenFailed{this, "Invalid stream",
@@ -221,6 +269,7 @@
   /*SuppressOnSink =*/true};
 
 public:
+  void checkBeginFunction(CheckerContext &C) const;
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
   void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
@@ -285,6 +334,10 @@
 0}},
   };
 
+  mutable SymbolRef OrigStdin;
+  mutable SymbolRef OrigStdout;
+  mutable SymbolRef OrigStderr;
+
   void evalFopen(const FnDescription *Desc, const CallEvent &Call,
  CheckerContext &C) const;
 
@@ -414,16 +467,15 @@
 
 } // end anonymous namespace
 
-// This map holds the state of a stream.
-// The stream is identified with a SymbolRef that is created when a stream
-// opening function is modeled by the checker.
-REGISTER_MAP_WITH_PROGRAMSTATE(StreamMap, SymbolRef, StreamState)
-
 inline void assertStreamStateOpened(const StreamState *SS) {
   assert(SS->isOpened() &&
  "Previous create of error node for non-opened stream failed?");
 }
 
+//===--===//
+// Methods of StreamCh

[PATCH] D104854: Introduce intrinsic llvm.isnan

2021-07-29 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: llvm/test/Transforms/InstCombine/fpclass.ll:29
+  ret <2 x i1> %t
+}
+

You probably need some negative tests (no flags, ninf instead of nnan etc.)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104854

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


[PATCH] D105904: [clangd] Support `#pragma mark` in the outline

2021-07-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/FindSymbols.cpp:535
+/// by range.
+std::vector mergePragmas(std::vector &Syms,
+ std::vector 
&Pragmas,

dgoldman wrote:
> kadircet wrote:
> > dgoldman wrote:
> > > sammccall wrote:
> > > > FWIW the flow control/how we make progress seem hard to follow here to 
> > > > me.
> > > > 
> > > > In particular I think I'm struggling with the statefulness of "is there 
> > > > an open mark group".
> > > > 
> > > > Possible simplifications:
> > > >  - define a dummy root symbol, which seems clearer than the 
> > > > vector + range
> > > >  - avoid reverse-sorting the list of pragma symbols, and just consume 
> > > > from the front of an ArrayRef instead
> > > >  - make the outer loop over pragmas, rather than symbols. It would 
> > > > first check if the pragma belongs directly here or not, and if so, loop 
> > > > over symbols to work out which should become children. This seems very 
> > > > likely to be efficient enough in practice (few pragmas, or most 
> > > > children are grouped into pragmas)
> > > > define a dummy root symbol, which seems clearer than the 
> > > > vector + range
> > > 
> > > I guess? Then we'd take in a `DocumentSymbol & and a 
> > > ArrayRef & (or just by value and then return it as 
> > > well). The rest would be the same though
> > > 
> > > > In particular I think I'm struggling with the statefulness of "is there 
> > > > an open mark group".
> > > 
> > > We need to track the current open group if there is one in order to move 
> > > children to it.
> > > 
> > > > make the outer loop over pragmas, rather than symbols. It would first 
> > > > check if the pragma belongs directly here or not, and if so, loop over 
> > > > symbols to work out which should become children. This seems very 
> > > > likely to be efficient enough in practice (few pragmas, or most 
> > > > children are grouped into pragmas)
> > > 
> > > The important thing here is knowing where the pragma mark ends - if it 
> > > doesn't, it actually gets all of the children. So we'd have to peak at 
> > > the next pragma mark, add all symbols before it to us as children, and 
> > > then potentially recurse to nest it inside of a symbol. I'll try it out 
> > > and see if it's simpler.
> > > 
> > > 
> > ```
> > while(Pragmas) {
> > // We'll figure out where the Pragmas.front() should go.
> > Pragma P = Pragmas.front();
> > DocumentSymbol *Cur = Root;
> > while(Cur->contains(P)) {
> >   auto *OldCur = Cur;
> >   for(auto *C : Cur->children) {
> >  // We assume at most 1 child can contain the pragma (as pragmas are on 
> > a single line, and children have disjoint ranges)
> >  if (C->contains(P)) {
> >  Cur = C;
> >  break;
> >  }
> >   }
> >   // Cur is immediate parent of P
> >   if (OldCur == Cur) {
> > // Just insert P into children if it is not a group and we are done.
> > // Otherwise we need to figure out when current pragma is terminated:
> > // if next pragma is not contained in Cur, or is contained in one of the 
> > children, It is at the end of Cur, nest all the children that appear after 
> > P under the symbol node for P.
> > // Otherwise nest all the children that appear after P but before next 
> > pragma under the symbol node for P.
> > // Pop Pragmas and break
> >   }
> > }
> > }
> > ```
> > 
> > Does that make sense, i hope i am not missing something obvious? 
> > Complexity-wise in the worst case we'll go all the way down to a leaf once 
> > per pragma, since there will only be a handful of pragmas most of the time 
> > it shouldn't be too bad.
> I've implemented your suggestion. I don't think it's simpler, but LMK, maybe 
> it can be improved.
oops, i was looking into an older revision and missed mergepragmas2, i think it 
looks quite similar to this one but we can probably get rid of the recursion as 
well and simplify a couple more cases


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105904

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


[clang] e4902e6 - [PowerPC] Fix return type of XL compat CAS

2021-07-29 Thread Kai Luo via cfe-commits

Author: Kai Luo
Date: 2021-07-29T14:49:26Z
New Revision: e4902e69e99d07d6d311425d87d4c1d075b72bf8

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

LOG: [PowerPC] Fix return type of XL compat CAS

`__compare_and_swap*` should return `i32` rather than `i1`.

Reviewed By: jsji

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins-ppc-xlcompat-cas.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d9b2a5fe16bec..b316a865f2fc7 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -15808,7 +15808,7 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 // store.
 Value *LoadedVal = Pair.first.getScalarVal();
 Builder.CreateStore(LoadedVal, OldValAddr);
-return Pair.second;
+return Builder.CreateZExt(Pair.second, Builder.getInt32Ty());
   }
   case PPC::BI__builtin_ppc_fetch_and_add:
   case PPC::BI__builtin_ppc_fetch_and_addlp: {

diff  --git a/clang/test/CodeGen/builtins-ppc-xlcompat-cas.c 
b/clang/test/CodeGen/builtins-ppc-xlcompat-cas.c
index cd66eb09d36f3..9407f696d6ff9 100644
--- a/clang/test/CodeGen/builtins-ppc-xlcompat-cas.c
+++ b/clang/test/CodeGen/builtins-ppc-xlcompat-cas.c
@@ -20,10 +20,11 @@
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { i32, i1 } [[TMP2]], 0
 // CHECK-NEXT:[[TMP4:%.*]] = extractvalue { i32, i1 } [[TMP2]], 1
 // CHECK-NEXT:store i32 [[TMP3]], i32* [[B_ADDR]], align 4
-// CHECK-NEXT:ret void
+// CHECK-NEXT:[[TMP5:%.*]] = zext i1 [[TMP4]] to i32
+// CHECK-NEXT:ret i32 [[TMP5]]
 //
-void test_builtin_ppc_compare_and_swap(int a, int b, int c) {
-  __compare_and_swap(&a, &b, c);
+int test_builtin_ppc_compare_and_swap(int a, int b, int c) {
+  return __compare_and_swap(&a, &b, c);
 }
 
 
@@ -41,9 +42,10 @@ void test_builtin_ppc_compare_and_swap(int a, int b, int c) {
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { i64, i1 } [[TMP2]], 0
 // CHECK-NEXT:[[TMP4:%.*]] = extractvalue { i64, i1 } [[TMP2]], 1
 // CHECK-NEXT:store i64 [[TMP3]], i64* [[B_ADDR]], align 8
-// CHECK-NEXT:ret void
+// CHECK-NEXT:[[TMP5:%.*]] = zext i1 [[TMP4]] to i32
+// CHECK-NEXT:ret i32 [[TMP5]]
 //
-void test_builtin_ppc_compare_and_swaplp(long a, long b, long c) {
-  __compare_and_swaplp(&a, &b, c);
+int test_builtin_ppc_compare_and_swaplp(long a, long b, long c) {
+  return __compare_and_swaplp(&a, &b, c);
 }
 



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


[PATCH] D107077: [PowerPC] Fix return type of XL compat CAS

2021-07-29 Thread Kai Luo 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 rGe4902e69e99d: [PowerPC] Fix return type of XL compat CAS 
(authored by lkail).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107077

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-cas.c


Index: clang/test/CodeGen/builtins-ppc-xlcompat-cas.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat-cas.c
+++ clang/test/CodeGen/builtins-ppc-xlcompat-cas.c
@@ -20,10 +20,11 @@
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { i32, i1 } [[TMP2]], 0
 // CHECK-NEXT:[[TMP4:%.*]] = extractvalue { i32, i1 } [[TMP2]], 1
 // CHECK-NEXT:store i32 [[TMP3]], i32* [[B_ADDR]], align 4
-// CHECK-NEXT:ret void
+// CHECK-NEXT:[[TMP5:%.*]] = zext i1 [[TMP4]] to i32
+// CHECK-NEXT:ret i32 [[TMP5]]
 //
-void test_builtin_ppc_compare_and_swap(int a, int b, int c) {
-  __compare_and_swap(&a, &b, c);
+int test_builtin_ppc_compare_and_swap(int a, int b, int c) {
+  return __compare_and_swap(&a, &b, c);
 }
 
 
@@ -41,9 +42,10 @@
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { i64, i1 } [[TMP2]], 0
 // CHECK-NEXT:[[TMP4:%.*]] = extractvalue { i64, i1 } [[TMP2]], 1
 // CHECK-NEXT:store i64 [[TMP3]], i64* [[B_ADDR]], align 8
-// CHECK-NEXT:ret void
+// CHECK-NEXT:[[TMP5:%.*]] = zext i1 [[TMP4]] to i32
+// CHECK-NEXT:ret i32 [[TMP5]]
 //
-void test_builtin_ppc_compare_and_swaplp(long a, long b, long c) {
-  __compare_and_swaplp(&a, &b, c);
+int test_builtin_ppc_compare_and_swaplp(long a, long b, long c) {
+  return __compare_and_swaplp(&a, &b, c);
 }
 
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -15808,7 +15808,7 @@
 // store.
 Value *LoadedVal = Pair.first.getScalarVal();
 Builder.CreateStore(LoadedVal, OldValAddr);
-return Pair.second;
+return Builder.CreateZExt(Pair.second, Builder.getInt32Ty());
   }
   case PPC::BI__builtin_ppc_fetch_and_add:
   case PPC::BI__builtin_ppc_fetch_and_addlp: {


Index: clang/test/CodeGen/builtins-ppc-xlcompat-cas.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat-cas.c
+++ clang/test/CodeGen/builtins-ppc-xlcompat-cas.c
@@ -20,10 +20,11 @@
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { i32, i1 } [[TMP2]], 0
 // CHECK-NEXT:[[TMP4:%.*]] = extractvalue { i32, i1 } [[TMP2]], 1
 // CHECK-NEXT:store i32 [[TMP3]], i32* [[B_ADDR]], align 4
-// CHECK-NEXT:ret void
+// CHECK-NEXT:[[TMP5:%.*]] = zext i1 [[TMP4]] to i32
+// CHECK-NEXT:ret i32 [[TMP5]]
 //
-void test_builtin_ppc_compare_and_swap(int a, int b, int c) {
-  __compare_and_swap(&a, &b, c);
+int test_builtin_ppc_compare_and_swap(int a, int b, int c) {
+  return __compare_and_swap(&a, &b, c);
 }
 
 
@@ -41,9 +42,10 @@
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { i64, i1 } [[TMP2]], 0
 // CHECK-NEXT:[[TMP4:%.*]] = extractvalue { i64, i1 } [[TMP2]], 1
 // CHECK-NEXT:store i64 [[TMP3]], i64* [[B_ADDR]], align 8
-// CHECK-NEXT:ret void
+// CHECK-NEXT:[[TMP5:%.*]] = zext i1 [[TMP4]] to i32
+// CHECK-NEXT:ret i32 [[TMP5]]
 //
-void test_builtin_ppc_compare_and_swaplp(long a, long b, long c) {
-  __compare_and_swaplp(&a, &b, c);
+int test_builtin_ppc_compare_and_swaplp(long a, long b, long c) {
+  return __compare_and_swaplp(&a, &b, c);
 }
 
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -15808,7 +15808,7 @@
 // store.
 Value *LoadedVal = Pair.first.getScalarVal();
 Builder.CreateStore(LoadedVal, OldValAddr);
-return Pair.second;
+return Builder.CreateZExt(Pair.second, Builder.getInt32Ty());
   }
   case PPC::BI__builtin_ppc_fetch_and_add:
   case PPC::BI__builtin_ppc_fetch_and_addlp: {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104285: [analyzer] Retrieve value by direct index from list initialization of constant array declaration.

2021-07-29 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

I like the idea and I think this is a valuable patch. However, because of the 
changes under `lib/AST` we need to add other reviewers who are responsible for 
those parts (e.g. aaronballman or rsmith). Is there really no way to workaround 
those changes? E.g. could we have a free function outside of the `InitListExpr` 
to implement `getExprForConstArrayByRawIndex`?


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

https://reviews.llvm.org/D104285

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


[PATCH] D89380: [clang-tidy] Fix for cppcoreguidelines-prefer-member-initializer to handle classes declared in macros

2021-07-29 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

In D89380#2913664 , @martong wrote:

> @baloghadamsoftware Ping.

Bug 47778  is marked //FIXED// by 
D97132 .


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

https://reviews.llvm.org/D89380

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


[PATCH] D107025: Take OptimizationLevel class out of Pass Builder

2021-07-29 Thread Mircea Trofin via Phabricator via cfe-commits
mtrofin accepted this revision.
mtrofin added inline comments.
This revision is now accepted and ready to land.



Comment at: llvm/include/llvm/Passes/OptimizationLevel.h:128
+#endif
\ No newline at end of file


add a newline here (it helps diff tools)


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

https://reviews.llvm.org/D107025

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


[PATCH] D106899: [LLVM][NFC] Replace LLVM_ATTRIBUTE_NORETURN with [[noreturn]]

2021-07-29 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 362780.
gAlfonso-bit added a comment.

Had to fix a clang-tidy issue for this to even compile


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

https://reviews.llvm.org/D106899

Files:
  clang-tools-extra/pp-trace/PPTrace.cpp
  clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
  flang/include/flang/Optimizer/Support/FatalError.h
  lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
  lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
  lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp

Index: lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp
===
--- lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp
+++ lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp
@@ -29,7 +29,7 @@
 #if defined(__arm64__) || defined(__aarch64__)
 namespace {
 
-void LLVM_ATTRIBUTE_NORETURN Child() {
+[[noreturn]] void Child() {
   if (ptrace(PTRACE_TRACEME, 0, nullptr, nullptr) == -1)
 _exit(1);
 
Index: lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
===
--- lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
+++ lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
@@ -144,7 +144,7 @@
 private:
   MainLoop::SignalHandleUP m_sigchld_handle;
   ArchSpec m_arch;
-  MainLoop& m_main_loop;
+  MainLoop &m_main_loop;
 
   LazyBool m_supports_mem_region = eLazyBoolCalculate;
   std::vector> m_mem_region_cache;
Index: lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
===
--- lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
+++ lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
@@ -20,8 +20,8 @@
 #include 
 #include 
 
-#include 
 #include 
+#include 
 
 #ifdef __ANDROID__
 #include 
@@ -46,8 +46,7 @@
 #endif
 }
 
-static void LLVM_ATTRIBUTE_NORETURN ExitWithError(int error_fd,
-  const char *operation) {
+[[noreturn]] static void ExitWithError(int error_fd, const char *operation) {
   int err = errno;
   llvm::raw_fd_ostream os(error_fd, true);
   os << operation << " failed: " << llvm::sys::StrError(err);
@@ -55,7 +54,8 @@
   _exit(1);
 }
 
-static void DisableASLRIfRequested(int error_fd, const ProcessLaunchInfo &info) {
+static void DisableASLRIfRequested(int error_fd,
+   const ProcessLaunchInfo &info) {
 #if defined(__linux__)
   if (info.GetFlags().Test(lldb::eLaunchFlagDisableASLR)) {
 const unsigned long personality_get_current = 0x;
@@ -72,8 +72,8 @@
 
 static void DupDescriptor(int error_fd, const FileSpec &file_spec, int fd,
   int flags) {
-  int target_fd = llvm::sys::RetryAfterSignal(-1, ::open,
-  file_spec.GetCString(), flags, 0666);
+  int target_fd = llvm::sys::RetryAfterSignal(
+  -1, ::open, file_spec.GetCString(), flags, 0666);
 
   if (target_fd == -1)
 ExitWithError(error_fd, "DupDescriptor-open");
@@ -88,8 +88,8 @@
   return;
 }
 
-static void LLVM_ATTRIBUTE_NORETURN ChildFunc(int error_fd,
-  const ProcessLaunchInfo &info) {
+[[noreturn]] static void ChildFunc(int error_fd,
+   const ProcessLaunchInfo &info) {
   if (info.GetFlags().Test(eLaunchFlagLaunchInSeparateProcessGroup)) {
 if (setpgid(0, 0) != 0)
   ExitWithError(error_fd, "setpgid");
Index: flang/include/flang/Optimizer/Support/FatalError.h
===
--- flang/include/flang/Optimizer/Support/FatalError.h
+++ flang/include/flang/Optimizer/Support/FatalError.h
@@ -20,8 +20,8 @@
 
 /// Fatal error reporting helper. Report a fatal error with a source location
 /// and immediately abort flang.
-LLVM_ATTRIBUTE_NORETURN inline void emitFatalError(mlir::Location loc,
-   const llvm::Twine &message) {
+[[noreturn]] inline void emitFatalError(mlir::Location loc,
+const llvm::Twine &message) {
   mlir::emitError(loc, message);
   llvm::report_fatal_error("aborting");
 }
Index: clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
===
--- clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -614,7 +614,7 @@
 return It->second.Root;
   }
 
-  LLVM_ATTRIBUTE_NORETURN void PrintFatalError(llvm::Twine const &Msg) const {
+  [[noreturn]] void PrintFatalError(llvm::Twine const &Msg) const {
 assert(EvaluatingRecord && "not evaluating a record?");
 llvm::PrintFatalError(EvaluatingRecord->getLoc(), Msg);
   }
Index: clang-tools-extra/pp-trace/PPTrace.cpp
===
--- clang-tools-extra/pp-trace/PPTrace.cpp
+++ clang-tools-extra/pp-trace/PPTrace.cpp
@@ -69,7 +69

[PATCH] D106644: [clang][analyzer] Add standard streams to alpha.unix.Stream checker.

2021-07-29 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D106644#2913676 , @balazske wrote:

> Split some type lookup functions from StdLibraryFunctionsChecker into 
> separate files.

Thank you, this is awesome!




Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:504
+
+  OrigStdin = findStdStream("stdin", C);
+  OrigStdout = findStdStream("stdout", C);

We should be careful, to cache the results (either here, or deeper in the call 
stack).
I mean, we certainly don't want to do a lookup of "stdin" every time a function 
is evaluated. We should do this lazily, only once.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106644

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


[PATCH] D89380: [clang-tidy] Fix for cppcoreguidelines-prefer-member-initializer to handle classes declared in macros

2021-07-29 Thread Gabor Marton via Phabricator via cfe-commits
martong commandeered this revision.
martong added a reviewer: baloghadamsoftware.
martong added a comment.

In D89380#2913750 , @whisperity wrote:

> In D89380#2913664 , @martong wrote:
>
>> @baloghadamsoftware Ping.
>
> Bug 47778  is marked //FIXED// by 
> D97132 .

Okay, thanks! So, I am going to abandon/close this.


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

https://reviews.llvm.org/D89380

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


[PATCH] D106864: [clang][cli] Expose -fno-cxx-modules in cc1

2021-07-29 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: clang/test/Modules/cxx20-disable.cpp:2
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 -x objective-c++ -std=c++20 -fno-cxx-modules -I %t %s
+

jansvoboda11 wrote:
> I'm not sure how to best test this. Checking the error messages is not that 
> useful, since they don't make the intent here any clearer:
> 
> ```
> /llvm-project/clang/test/Modules/cxx20-disable.cpp:4:8: error: expected 
> template
> export module Foo;
>^
> /llvm-project/clang/test/Modules/cxx20-disable.cpp:4:8: error: unknown 
> type name 'module'
> 2 errors generated.
> ```
You could still check the errors with -verify but add a comment that expressed 
the intent of why these errors are verified. Also it might make sense to add an 
inverse test case that doesn't use the `-fno-cxx-modules` flag, where this will 
just work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106864

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


[PATCH] D106862: [clang][modules] Avoid creating partial FullSourceLoc for explicit modules imports

2021-07-29 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

I think this approach makes sense for now. It's unfortunate that the 
constructor of FullSourceLoc is unable to validate this requirement, do you 
know how many clients that you describe as modifying their ID to make them 
valid are there?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106862

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


  1   2   3   >