[PATCH] D117120: [Doc] Add documentation for the clang-offload-wrapper tool (NFC)

2022-01-12 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam created this revision.
saiislam added reviewers: sdmitriev, jdoerfert, grokos, JonChesterfield, 
carlo.bertolli, vzakhari.
Herald added a subscriber: arphaman.
saiislam requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Add the missing documentation for this tool.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117120

Files:
  clang/docs/ClangOffloadWrapper.rst
  clang/docs/index.rst

Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -84,6 +84,7 @@
ClangFormattedStatus
ClangNvlinkWrapper
ClangOffloadBundler
+   ClangOffloadWrapper
 
 Design Documents
 
Index: clang/docs/ClangOffloadWrapper.rst
===
--- /dev/null
+++ clang/docs/ClangOffloadWrapper.rst
@@ -0,0 +1,220 @@
+=
+Clang Offload Wrapper
+=
+
+.. contents::
+   :local:
+
+.. _clang-offload-wrapper:
+
+Introduction
+
+
+This tool is used in OpenMP offloading toolchain to embed device code objects
+(usually ELF) into a wrapper host llvm IR (bitcode) file. The wrapper host IR
+is then assembled and linked with host code objects to generate the executable
+binary. See :ref:`image-binary-embedding-execution` for more details.
+
+Usage
+=
+
+This tool can be used as follows:
+
+.. code-block:: console
+
+  $ clang-offload-wrapper -help
+  OVERVIEW: A tool to create a wrapper bitcode for offload target binaries.
+  Takes offload target binaries as input and produces bitcode file containing
+  target binaries packaged as data and initialization code which registers
+  target binaries in offload runtime.
+  USAGE: clang-offload-wrapper [options] 
+  OPTIONS:
+  Generic Options:
+--help - Display available options (--help-hidden for more)
+--help-list- Display list of available options (--help-list-hidden for more)
+--version  - Display the version of this program
+  clang-offload-wrapper options:
+-o=  - Output filename
+--target=  - Target triple for the output module
+
+Example
+===
+
+.. code-block:: console
+
+  clang-offload-wrapper -target host-triple -o host-wrapper.bc gfx90a-binary.out
+
+.. _openmp-device-binary_embedding:
+
+OpenMP Device Binary Embedding
+==
+
+Various structures and functions used in the wrapper host IR form the interface
+between the executable binary and the OpenMP runtime.
+
+Enum Types
+--
+
+:ref:`table-offloading-declare-target-flags` lists different flag for
+offloading entries.
+
+  .. table:: Offloading Declare Target Flags Enum
+:name: table-offloading-declare-target-flags
+
++-+---+--+
+|  Name   | Value | Description  |
++=+===+==+
+| OMP_DECLARE_TARGET_LINK | 0x01  | Mark the entry as having a 'link' attribute (w.r.t. link clause) |
++-+---+--+
+| OMP_DECLARE_TARGET_CTOR | 0x02  | Mark the entry as being a global constructor |
++-+---+--+
+| OMP_DECLARE_TARGET_DTOR | 0x04  | Mark the entry as being a global destructor  |
++-+---+--+
+
+Structure Types
+---
+
+:ref:`table-tgt_offload_entry`, :ref:`table-tgt_device_image`, and
+:ref:`table-tgt_bin_desc` are the structures used in the wrapper host IR.
+
+  .. table:: __tgt_offload_entry structure
+:name: table-tgt_offload_entry
+
++-+++
+|   Type  | Identifier | Description|
++=+++
+|  void*  |addr| Address of global symbol within device image (function or global)  |
++-+++
+|  char*  |name| Name of the symbol |
++-+++
+|  size_t |size| Size of 

[PATCH] D117056: [clangd] Properly compute framework-style include spelling

2022-01-12 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 399336.
dgoldman added a comment.

Run clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117056

Files:
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang/lib/Lex/HeaderSearch.cpp

Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1049,6 +1049,11 @@
 getUniqueFrameworkName(StringRef(Filename.begin(), SlashPos));
   if (CurDir->isIndexHeaderMap())
 HFI.IndexHeaderMapHeader = 1;
+} else if (CurDir->isFramework()) {
+  size_t SlashPos = Filename.find('/');
+  if (SlashPos != StringRef::npos)
+HFI.Framework =
+getUniqueFrameworkName(StringRef(Filename.begin(), SlashPos));
 }
 
 if (checkMSVCHeaderSearch(Diags, MSFE ? &MSFE->getFileEntry() : nullptr,
Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -663,6 +663,109 @@
   QName("Cat::meow"), QName("Cat::pur")));
 }
 
+TEST_F(SymbolCollectorTest, ObjCFrameworkIncludeHeader) {
+  CollectorOpts.CollectIncludePath = true;
+  auto FrameworksPath = testPath("Frameworks/");
+  auto FrameworkHeaderPath =
+  testPath("Frameworks/Foundation.framework/Headers/NSObject.h");
+  const std::string FrameworkHeader = R"(
+__attribute((objc_root_class))
+@interface NSObject
+@end
+  )";
+  InMemoryFileSystem->addFile(
+  FrameworkHeaderPath, 0,
+  llvm::MemoryBuffer::getMemBuffer(FrameworkHeader));
+
+  const std::string Header = R"(
+#import 
+
+@interface Container : NSObject
+@end
+  )";
+  const std::string Main = "";
+  TestFileName = testPath("test.m");
+  runSymbolCollector(Header, Main, {"-F", FrameworksPath, "-xobjective-c++"});
+  EXPECT_THAT(Symbols, UnorderedElementsAre(
+   AllOf(QName("NSObject"),
+ IncludeHeader("\"Foundation/NSObject.h\"")),
+   AllOf(QName("Container";
+}
+
+TEST_F(SymbolCollectorTest, ObjCUmbrellaFrameworkIncludeHeader) {
+  CollectorOpts.CollectIncludePath = true;
+  auto FrameworksPath = testPath("Frameworks/");
+  auto UmbrellaHeaderPath =
+  testPath("Frameworks/Foundation.framework/Headers/Foundation.h");
+  const std::string UmbrellaHeader = R"(
+#import 
+  )";
+  auto FrameworkHeaderPath =
+  testPath("Frameworks/Foundation.framework/Headers/NSObject.h");
+  const std::string FrameworkHeader = R"(
+__attribute((objc_root_class))
+@interface NSObject
+@end
+  )";
+  InMemoryFileSystem->addFile(UmbrellaHeaderPath, 0,
+  llvm::MemoryBuffer::getMemBuffer(UmbrellaHeader));
+  InMemoryFileSystem->addFile(
+  FrameworkHeaderPath, 0,
+  llvm::MemoryBuffer::getMemBuffer(FrameworkHeader));
+
+  const std::string Header = R"(
+#import 
+
+@interface Container : NSObject
+@end
+  )";
+  const std::string Main = "";
+  TestFileName = testPath("test.m");
+  runSymbolCollector(Header, Main, {"-F", FrameworksPath, "-xobjective-c++"});
+  EXPECT_THAT(Symbols, UnorderedElementsAre(
+   AllOf(QName("NSObject"),
+ IncludeHeader("\"Foundation/Foundation.h\"")),
+   AllOf(QName("Container";
+}
+
+TEST_F(SymbolCollectorTest, ObjCSystemUmbrellaFrameworkIncludeHeader) {
+  CollectorOpts.CollectIncludePath = true;
+  auto FrameworksPath = testPath("Frameworks/");
+  auto UmbrellaHeaderPath =
+  testPath("Frameworks/Foundation.framework/Headers/Foundation.h");
+  const std::string UmbrellaHeader = R"(
+#import 
+  )";
+  auto FrameworkHeaderPath =
+  testPath("Frameworks/Foundation.framework/Headers/NSObject.h");
+  const std::string FrameworkHeader = R"(
+__attribute((objc_root_class))
+@interface NSObject
+@end
+  )";
+  InMemoryFileSystem->addFile(UmbrellaHeaderPath, 0,
+  llvm::MemoryBuffer::getMemBuffer(UmbrellaHeader));
+  InMemoryFileSystem->addFile(
+  FrameworkHeaderPath, 0,
+  llvm::MemoryBuffer::getMemBuffer(FrameworkHeader));
+
+  const std::string Header = R"(
+#import 
+
+@interface Container : NSObject
+@end
+  )";
+  const std::string Main = "";
+  TestFileName = testPath("test.m");
+  runSymbolCollector(
+  Header, Main,
+  {"-iframeworkwithsysroot", FrameworksPath, "-xobjective-c++"});
+  EXPECT_THAT(Symbols, UnorderedElementsAre(
+   AllOf(QName("NSObject"),
+ IncludeHeader("")),
+   AllOf(QName(

[PATCH] D115253: [C2x] Support the *_WIDTH macros in limits.h and stdint.h

2022-01-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 399337.
aaron.ballman added a comment.

Updating based on review feedback -- adds the signed versions of the __macros__ 
for consistency and uses them in limits.h.


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

https://reviews.llvm.org/D115253

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Headers/limits.h
  clang/lib/Headers/stdint.h
  clang/test/Headers/limits.cpp
  clang/test/Headers/stdint.c
  clang/test/Preprocessor/init-aarch64.c
  clang/test/Preprocessor/init.c
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -715,11 +715,7 @@
 
   Two's complement sign representation
   http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2412.pdf";>N2412
-  
-Partial
-  Lacking width macros in limits.h and stdint.h
-
-  
+  Clang 14
 
 
   Adding the u8 character prefix
Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -1520,6 +1520,7 @@
 // WEBASSEMBLY-NEXT:#define __ATOMIC_RELEASE 3
 // WEBASSEMBLY-NEXT:#define __ATOMIC_SEQ_CST 5
 // WEBASSEMBLY-NEXT:#define __BIGGEST_ALIGNMENT__ 16
+// WEBASSEMBLY-NEXT:#define __BOOL_WIDTH__ 8
 // WEBASSEMBLY-NEXT:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
 // WEBASSEMBLY-NEXT:#define __CHAR16_TYPE__ unsigned short
 // WEBASSEMBLY-NEXT:#define __CHAR32_TYPE__ unsigned int
@@ -1609,21 +1610,25 @@
 // WEBASSEMBLY-NEXT:#define __INT16_FMTi__ "hi"
 // WEBASSEMBLY-NEXT:#define __INT16_MAX__ 32767
 // WEBASSEMBLY-NEXT:#define __INT16_TYPE__ short
+// WEBASSEMBLY-NEXT:#define __INT16_WIDTH__ 16
 // WEBASSEMBLY-NEXT:#define __INT32_C_SUFFIX__
 // WEBASSEMBLY-NEXT:#define __INT32_FMTd__ "d"
 // WEBASSEMBLY-NEXT:#define __INT32_FMTi__ "i"
 // WEBASSEMBLY-NEXT:#define __INT32_MAX__ 2147483647
 // WEBASSEMBLY-NEXT:#define __INT32_TYPE__ int
+// WEBASSEMBLY-NEXT:#define __INT32_WIDTH__ 32
 // WEBASSEMBLY-NEXT:#define __INT64_C_SUFFIX__ LL
 // WEBASSEMBLY-NEXT:#define __INT64_FMTd__ "lld"
 // WEBASSEMBLY-NEXT:#define __INT64_FMTi__ "lli"
 // WEBASSEMBLY-NEXT:#define __INT64_MAX__ 9223372036854775807LL
 // WEBASSEMBLY-NEXT:#define __INT64_TYPE__ long long int
+// WEBASSEMBLY-NEXT:#define __INT64_WIDTH__ 64
 // WEBASSEMBLY-NEXT:#define __INT8_C_SUFFIX__
 // WEBASSEMBLY-NEXT:#define __INT8_FMTd__ "hhd"
 // WEBASSEMBLY-NEXT:#define __INT8_FMTi__ "hhi"
 // WEBASSEMBLY-NEXT:#define __INT8_MAX__ 127
 // WEBASSEMBLY-NEXT:#define __INT8_TYPE__ signed char
+// WEBASSEMBLY-NEXT:#define __INT8_WIDTH__ 8
 // WEBASSEMBLY-NEXT:#define __INTMAX_C_SUFFIX__ LL
 // WEBASSEMBLY-NEXT:#define __INTMAX_FMTd__ "lld"
 // WEBASSEMBLY-NEXT:#define __INTMAX_FMTi__ "lli"
@@ -1641,35 +1646,44 @@
 // WEBASSEMBLY-NEXT:#define __INT_FAST16_FMTi__ "hi"
 // WEBASSEMBLY-NEXT:#define __INT_FAST16_MAX__ 32767
 // WEBASSEMBLY-NEXT:#define __INT_FAST16_TYPE__ short
+// WEBASSEMBLY-NEXT:#define __INT_FAST16_WIDTH__ 16
 // WEBASSEMBLY-NEXT:#define __INT_FAST32_FMTd__ "d"
 // WEBASSEMBLY-NEXT:#define __INT_FAST32_FMTi__ "i"
 // WEBASSEMBLY-NEXT:#define __INT_FAST32_MAX__ 2147483647
 // WEBASSEMBLY-NEXT:#define __INT_FAST32_TYPE__ int
+// WEBASSEMBLY-NEXT:#define __INT_FAST32_WIDTH__ 32
 // WEBASSEMBLY-NEXT:#define __INT_FAST64_FMTd__ "lld"
 // WEBASSEMBLY-NEXT:#define __INT_FAST64_FMTi__ "lli"
 // WEBASSEMBLY-NEXT:#define __INT_FAST64_MAX__ 9223372036854775807LL
 // WEBASSEMBLY-NEXT:#define __INT_FAST64_TYPE__ long long int
+// WEBASSEMBLY-NEXT:#define __INT_FAST64_WIDTH__ 64
 // WEBASSEMBLY-NEXT:#define __INT_FAST8_FMTd__ "hhd"
 // WEBASSEMBLY-NEXT:#define __INT_FAST8_FMTi__ "hhi"
 // WEBASSEMBLY-NEXT:#define __INT_FAST8_MAX__ 127
 // WEBASSEMBLY-NEXT:#define __INT_FAST8_TYPE__ signed char
+// WEBASSEMBLY-NEXT:#define __INT_FAST8_WIDTH__ 8
 // WEBASSEMBLY-NEXT:#define __INT_LEAST16_FMTd__ "hd"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST16_FMTi__ "hi"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST16_MAX__ 32767
 // WEBASSEMBLY-NEXT:#define __INT_LEAST16_TYPE__ short
+// WEBASSEMBLY-NEXT:#define __INT_LEAST16_WIDTH__ 16
 // WEBASSEMBLY-NEXT:#define __INT_LEAST32_FMTd__ "d"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST32_FMTi__ "i"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST32_MAX__ 2147483647
 // WEBASSEMBLY-NEXT:#define __INT_LEAST32_TYPE__ int
+// WEBASSEMBLY-NEXT:#define __INT_LEAST32_WIDTH__ 32
 // WEBASSEMBLY-NEXT:#define __INT_LEAST64_FMTd__ "lld"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST64_FMTi__ "lli"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST64_MAX__ 9223372036854775807LL
 // WEBASSEMBLY-NEXT:#define __INT_LEAST64_TYPE__ long long int
+// WEBASSEMBLY-NEXT:#define __INT_LEAST64_WIDTH__ 64
 // WEBASSEMBLY-NEXT:#define __INT_LEAST8_FMTd__ "hhd"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST8_FMTi__ "hhi"
 // WEBASSEMBLY-NEXT:#

[PATCH] D114439: [Annotation] Allow parameter pack expansions in annotate attribute

2022-01-12 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen updated this revision to Diff 399334.
steffenlarsen added a comment.

I have made the changes suggested in my previous comment. This makes 
significantly more changes to the parsing of attribute arguments as the old 
path was needed for attributes that allow both expressions and types. It also 
required some new controlling arguments for `ParseExpressionList`.

Because these changes also allow intializer lists in attribute arguments I have 
added a test case showing that `clang::annotate` parses these but will not 
accept them.

@erichkeane & @aaron.ballman - Is this in line with what you were thinking?


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

https://reviews.llvm.org/D114439

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/Parser/cxx0x-attributes.cpp
  clang/test/SemaTemplate/attributes.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1164,10 +1164,12 @@
   };
 
   class VariadicExprArgument : public VariadicArgument {
+bool AllowPack = false;
+
   public:
 VariadicExprArgument(const Record &Arg, StringRef Attr)
-  : VariadicArgument(Arg, Attr, "Expr *")
-{}
+: VariadicArgument(Arg, Attr, "Expr *"),
+  AllowPack(Arg.getValueAsBit("AllowPack")) {}
 
 void writeASTVisitorTraversal(raw_ostream &OS) const override {
   OS << "  {\n";
@@ -2264,6 +2266,47 @@
   OS << "#endif // CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST\n\n";
 }
 
+static void emitClangAttrNumArgs(RecordKeeper &Records, raw_ostream &OS) {
+  OS << "#if defined(CLANG_ATTR_NUM_ARGS)\n";
+  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
+  for (const auto *A : Attrs) {
+std::vector Args = A->getValueAsListOfDefs("Args");
+forEachUniqueSpelling(*A, [&](const FlattenedSpelling &S) {
+  OS << ".Case(\"" << S.name() << "\", " << Args.size() << ")\n";
+});
+  }
+  OS << "#endif // CLANG_ATTR_NUM_ARGS\n\n";
+}
+
+static bool argSupportsParmPack(const Record *Arg) {
+  return !Arg->getSuperClasses().empty() &&
+ llvm::StringSwitch(
+ Arg->getSuperClasses().back().first->getName())
+ .Case("VariadicExprArgument", true)
+ .Default(false) &&
+ Arg->getValueAsBit("AllowPack");
+}
+
+static void emitClangAttrLastArgParmPackSupport(RecordKeeper &Records,
+raw_ostream &OS) {
+  OS << "#if defined(CLANG_ATTR_LAST_ARG_PARM_PACK_SUPPORT)\n";
+  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
+  for (const auto *A : Attrs) {
+std::vector Args = A->getValueAsListOfDefs("Args");
+bool LastArgSupportsParmPack =
+!Args.empty() && argSupportsParmPack(Args.back());
+forEachUniqueSpelling(*A, [&](const FlattenedSpelling &S) {
+  OS << ".Case(\"" << S.name() << "\", " << LastArgSupportsParmPack
+ << ")\n";
+});
+  }
+  OS << "#endif // CLANG_ATTR_LAST_ARG_PARM_PACK_SUPPORT\n\n";
+}
+
+static bool isArgVariadic(const Record &R, StringRef AttrName) {
+  return createArgument(R, AttrName)->isVariadic();
+}
+
 static void emitAttributes(RecordKeeper &Records, raw_ostream &OS,
bool Header) {
   std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
@@ -2320,6 +2363,18 @@
 std::vector> Args;
 Args.reserve(ArgRecords.size());
 
+if (!ArgRecords.empty()) {
+  const bool LastArgSupportsPack = argSupportsParmPack(ArgRecords.back());
+  for (size_t I = 0; I < ArgRecords.size() - 1; ++I) {
+assert((!LastArgSupportsPack ||
+!isArgVariadic(*ArgRecords[I], R.getName())) &&
+   "Attributes supporting packs can only have the last "
+   "argument as variadic");
+assert(!argSupportsParmPack(ArgRecords[I]) &&
+   "Only the last argument can allow packs");
+  }
+}
+
 bool HasOptArg = false;
 bool HasFakeArg = false;
 for (const auto *ArgRecord : ArgRecords) {
@@ -3382,10 +3437,6 @@
   }
 }
 
-static bool isArgVariadic(const Record &R, StringRef AttrName) {
-  return createArgument(R, AttrName)->isVariadic();
-}
-
 static void emitArgInfo(const Record &R, raw_ostream &OS) {
   // This function will count the number of arguments specified for the
   // attribute and emit the number of required arguments followed by the
@@ -4219,6 +4270,8 @@
   emitClangAttrIdentifierArgList(Records, OS);
   emitClangAttrVariadicIdentifierArgList(Records, OS);
   emitClangAttrThisIsaIdentifierArgList(Records, OS);
+  emitClangAttrNumArgs(Records, OS);
+  emitClangAttrLastArgParmPackSupport(Records, OS);

[PATCH] D115253: [C2x] Support the *_WIDTH macros in limits.h and stdint.h

2022-01-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:900-903
+  Builder.defineMacro("__USHRT_WIDTH__", Twine(TI.getShortWidth()));
+  Builder.defineMacro("__UINT_WIDTH__", Twine(TI.getIntWidth()));
+  Builder.defineMacro("__ULONG_WIDTH__", Twine(TI.getLongWidth()));
+  Builder.defineMacro("__ULLONG_WIDTH__", Twine(TI.getLongLongWidth()));

jyknight wrote:
> aaron.ballman wrote:
> > jyknight wrote:
> > > This seems odd? We define `__LONG_LONG_MAX__` but not 
> > > `__LONG_LONG_WIDTH__`, for signed long long, and we define 
> > > `__ULLONG_WIDTH__` but not `__ULLONG_MAX__`, for unsigned long long?
> > > This seems odd?
> > 
> > Yeah, this stuff is a bit twisty.
> > 
> > > We define __LONG_LONG_MAX__ but not __LONG_LONG_WIDTH__, for signed long 
> > > long,
> > 
> > Correct.
> > 
> > > and we define __ULLONG_WIDTH__ but not __ULLONG_MAX__, for unsigned long 
> > > long?
> > 
> > Correct.
> > 
> > The basic approach I took was: for types with signed/unsigned pairs, define 
> > the `unsigned` variants with an underscore name and use them to define the 
> > `signed` variants in the header file because the width of signed and 
> > unsigned has to be the same per spec ("The macro blah_WIDTH represents the 
> > width of the type blah and shall expand to the same value as Ublah_WIDTH.") 
> > So that's why you generally only see the "unsigned" width variants added 
> > here with a double underscore name. I could expose the signed versions as 
> > well (like we do for many of the MAX macros), but that makes the 
> > preprocessor slower for no real benefit as we want the users to use the 
> > non-underscore versions of these macros whenever possible.
> 1. But, in this patch, it is exposing WIDTH for both variants of all the 
> other types. Shouldn't we consistently expose WIDTH for only one of each pair 
> (e.g. intmax_t, int_fast16_t, etc), instead of exposing both for some types, 
> and one for others?
> 
> 2. Exposing it only for unsigned seems like the wrong choice and confusing, 
> since that implies having a basically-extraneous "U" in all of the names, and 
> is inconsistent with previous practice. Can we expose only the signed 
> variants instead of the unsigned?
Ah, I see what you mean now, thanks for pushing back. Yes, I can add the signed 
variants here so we expose both the signed and unsigned versions for everything 
consistently. I'll also switch the headers to use both the signed and unsigned 
variants as appropriate -- the tests ensure these values won't get out of sync.


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

https://reviews.llvm.org/D115253

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


[PATCH] D116511: [clang-cl] Support the /HOTPATCH flag

2022-01-12 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm with comments




Comment at: clang/test/CodeGenCXX/debug-info-hotpatch-arm.cpp:13
+// RUN: llvm-pdbutil dump -symbols %t.obj | FileCheck %s 
--check-prefix=HOTPATCH
+// ERR-HOTPATCH: error: unsupported option '/hotpatch' for target
+// HOTPATCH: S_COMPILE3 [size = [[#]]]

Does MSVC error for ARM/ARM64 too, or does it just ignore the flag?



Comment at: clang/test/CodeGenCXX/debug-info-hotpatch-arm.cpp:19
+///
+// RUN: %clang_cl --target=aarch64-pc-windows-msvc /c %s -o %t.obj
+// RUN: llvm-pdbutil dump -symbols %t.obj | FileCheck %s 
--check-prefix=NO-HOTPATCH

nit: We still need -- before %s with clang-cl (%s could be /Users/... and get 
interpreted as a flag), and so it needs to come last. Same for the line in 
debug-info-hotpatch.cpp.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116511

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


[PATCH] D116939: [AArch64] clang support for Armv8.8/9.3 HBC

2022-01-12 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 updated this revision to Diff 399341.
tyb0807 marked an inline comment as done.
tyb0807 added a comment.

Removed checks that set HBC flag based on the target architecture and unset it
if command line explicitly disables it. This is because HBC feature does not
require any new intrinsic in the IR, so the frontend does not need to know about
whether HBC flag is set or unset in the command line.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116939

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/test/Driver/aarch64-hbc.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1485,43 +1485,41 @@
 }
 
 TEST(TargetParserTest, AArch64ArchExtFeature) {
-  const char *ArchExt[][4] = {{"crc", "nocrc", "+crc", "-crc"},
-  {"crypto", "nocrypto", "+crypto", "-crypto"},
-  {"flagm", "noflagm", "+flagm", "-flagm"},
-  {"fp", "nofp", "+fp-armv8", "-fp-armv8"},
-  {"simd", "nosimd", "+neon", "-neon"},
-  {"fp16", "nofp16", "+fullfp16", "-fullfp16"},
-  {"fp16fml", "nofp16fml", "+fp16fml", "-fp16fml"},
-  {"profile", "noprofile", "+spe", "-spe"},
-  {"ras", "noras", "+ras", "-ras"},
-  {"lse", "nolse", "+lse", "-lse"},
-  {"rdm", "nordm", "+rdm", "-rdm"},
-  {"sve", "nosve", "+sve", "-sve"},
-  {"sve2", "nosve2", "+sve2", "-sve2"},
-  {"sve2-aes", "nosve2-aes", "+sve2-aes",
-   "-sve2-aes"},
-  {"sve2-sm4", "nosve2-sm4", "+sve2-sm4",
-   "-sve2-sm4"},
-  {"sve2-sha3", "nosve2-sha3", "+sve2-sha3",
-   "-sve2-sha3"},
-  {"sve2-bitperm", "nosve2-bitperm",
-   "+sve2-bitperm", "-sve2-bitperm"},
-  {"dotprod", "nodotprod", "+dotprod", "-dotprod"},
-  {"rcpc", "norcpc", "+rcpc", "-rcpc" },
-  {"rng", "norng", "+rand", "-rand"},
-  {"memtag", "nomemtag", "+mte", "-mte"},
-  {"tme", "notme", "+tme", "-tme"},
-  {"pauth", "nopauth", "+pauth", "-pauth"},
-  {"ssbs", "nossbs", "+ssbs", "-ssbs"},
-  {"sb", "nosb", "+sb", "-sb"},
-  {"predres", "nopredres", "+predres", "-predres"},
-  {"i8mm", "noi8mm", "+i8mm", "-i8mm"},
-  {"f32mm", "nof32mm", "+f32mm", "-f32mm"},
-  {"f64mm", "nof64mm", "+f64mm", "-f64mm"},
-  {"sme", "nosme", "+sme", "-sme"},
-  {"sme-f64", "nosme-f64", "+sme-f64", "-sme-f64"},
-  {"sme-i64", "nosme-i64", "+sme-i64", "-sme-i64"},
-};
+  const char *ArchExt[][4] = {
+  {"crc", "nocrc", "+crc", "-crc"},
+  {"crypto", "nocrypto", "+crypto", "-crypto"},
+  {"flagm", "noflagm", "+flagm", "-flagm"},
+  {"fp", "nofp", "+fp-armv8", "-fp-armv8"},
+  {"simd", "nosimd", "+neon", "-neon"},
+  {"fp16", "nofp16", "+fullfp16", "-fullfp16"},
+  {"fp16fml", "nofp16fml", "+fp16fml", "-fp16fml"},
+  {"profile", "noprofile", "+spe", "-spe"},
+  {"ras", "noras", "+ras", "-ras"},
+  {"lse", "nolse", "+lse", "-lse"},
+  {"rdm", "nordm", "+rdm", "-rdm"},
+  {"sve", "nosve", "+sve", "-sve"},
+  {"sve2", "nosve2", "+sve2", "-sve2"},
+  {"sve2-aes", "nosve2-aes", "+sve2-aes", "-sve2-aes"},
+  {"sve2-sm4", "nosve2-sm4", "+sve2-sm4", "-sve2-sm4"},
+  {"sve2-sha3", "nosve2-sha3", "+sve2-sha3", "-sve2-sha3"},
+  {"sve2-bitperm", "nosve2-bitperm", "+sve2-bitperm", "-sve2-bitperm"},
+  {"dotprod", "nodotprod", "+dotprod", "-dotprod"},
+  {"rcpc", "norcpc", "+rcpc", "-rcpc"},
+  {"rng", "norng", "+rand", "-rand"},
+  {"memtag", "nomemtag", "+mte", "-mte"},
+  {"tme", "notme", "+tme", "-tme"},
+  {"pauth", "nopauth", "+pauth", "-pauth"},
+  {"ssbs", "nossbs", "+ssbs", "-ssbs"},
+  {"sb", "nosb", "+sb", "-sb"},
+  {"predres", "nopredres", "+predres", "-predres"},
+  {"i8mm", "noi8mm", "+i8mm", "-i8mm

[PATCH] D114787: [clang][PR51931] Enable `-Wdeclaration-after-statement` for all C versions

2022-01-12 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! Thanks for the improvement!


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

https://reviews.llvm.org/D114787

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


[PATCH] D117123: [clang][dataflow] Add transfer functions for initializers

2022-01-12 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev created this revision.
sgatev added reviewers: ymandel, xazax.hun, gribozavr2.
Herald added a subscriber: rnkovacs.
sgatev requested review of this revision.
Herald added a project: clang.

This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117123

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

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1171,4 +1171,114 @@
   });
 }
 
+TEST_F(TransferTest, ConstructorInitializer) {
+  std::string Code = R"(
+struct target {
+  int Bar;
+
+  target(int Foo) : Bar(Foo) {
+int Qux = Bar;
+// [[p]]
+  }
+};
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const auto *ThisLoc = dyn_cast(
+Env.getThisPointeeStorageLocation());
+ASSERT_THAT(ThisLoc, NotNull());
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const auto *FooVal =
+cast(Env.getValue(*FooDecl, SkipPast::None));
+
+const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ASSERT_THAT(QuxDecl, NotNull());
+EXPECT_EQ(Env.getValue(*QuxDecl, SkipPast::None), FooVal);
+  });
+}
+
+TEST_F(TransferTest, DefaultInitializer) {
+  std::string Code = R"(
+struct target {
+  int Bar;
+  int Baz = Bar;
+
+  target(int Foo) : Bar(Foo) {
+int Qux = Baz;
+// [[p]]
+  }
+};
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const auto *ThisLoc = dyn_cast(
+Env.getThisPointeeStorageLocation());
+ASSERT_THAT(ThisLoc, NotNull());
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const auto *FooVal =
+cast(Env.getValue(*FooDecl, SkipPast::None));
+
+const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ASSERT_THAT(QuxDecl, NotNull());
+EXPECT_EQ(Env.getValue(*QuxDecl, SkipPast::None), FooVal);
+  });
+}
+
+TEST_F(TransferTest, DefaultInitializerReference) {
+  std::string Code = R"(
+struct target {
+  int &Bar;
+  int &Baz = Bar;
+
+  target(int &Foo) : Bar(Foo) {
+int &Qux = Baz;
+// [[p]]
+  }
+};
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const auto *ThisLoc = dyn_cast(
+Env.getThisPointeeStorageLocation());
+ASSERT_THAT(ThisLoc, NotNull());
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const auto *FooVal =
+cast(Env.getValue(*FooDecl, SkipPast::None));
+
+const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ASSERT_THAT(QuxDecl, NotNull());
+
+const auto *QuxVal =
+cast(Env.getValue(*QuxDecl, SkipPast::None));
+EXPECT_EQ(&QuxVal->getPointeeLoc(), &FooVal->getPointeeLoc());
+  });
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -11,15 +11,18 @@
 //
 //===--===//
 
+#include 
 #include 
 #include 
 
+#include "clang/AST/DeclCXX.h"
 #include "clang/Analysis/Analyses/PostOrderCFGView.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/

[PATCH] D105340: [analyzer] Produce SymbolCast symbols for integral types in SValBuilder::evalCast

2022-01-12 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D105340#3237430 , @ASDenysPetrov 
wrote:

> In D105340#3232671 , @NoQ wrote:
>
>> This looks great with the option flag. Landing this patch will enable more 
>> people to test the new mode and produce feedback on whether the constraint 
>> solver keeps working well enough in presence of the new symbols.
>
> Many thanks for your approval, @NoQ! The upset thing is that to get this 
> loaded we also should close this parent revision D103094 
>  :-(

Actually, this patch does not depend on `castTo` and thus it is independent 
from the rest of the patch stack. So we could just land it as it is. (In this 
patch, you just create the `SymbolCast`s but there is no handling of that in 
the constraint manager which needs the `castTo`.)


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

https://reviews.llvm.org/D105340

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


[PATCH] D116701: Respect -fsanitize-memory-param-retval flag.

2022-01-12 Thread Kevin Athey via Phabricator via cfe-commits
kda updated this revision to Diff 399345.
kda added a comment.
Herald added subscribers: Sanitizers, ormris, dexonsmith, dang.
Herald added a project: Sanitizers.

enable eager-checks in llvm via flag (-fsanitize-memory-param-retval).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116701

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGen/attr-noundef.cpp
  clang/test/CodeGen/indirect-noundef.cpp
  compiler-rt/test/msan/noundef_analysis.cpp

Index: compiler-rt/test/msan/noundef_analysis.cpp
===
--- compiler-rt/test/msan/noundef_analysis.cpp
+++ compiler-rt/test/msan/noundef_analysis.cpp
@@ -2,6 +2,8 @@
 // RUN: FileCheck %s --check-prefix=MISSED --allow-empty < %t.out
 // RUN: %clangxx_msan %s -Xclang -enable-noundef-analysis -mllvm -msan-eager-checks=1 -o %t && not %run %t >%t.out 2>&1
 // RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan %s -fsanitize-memory-param-retval -o %t && not %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
 
 struct SimpleStruct {
   int md1;
Index: clang/test/CodeGen/indirect-noundef.cpp
===
--- clang/test/CodeGen/indirect-noundef.cpp
+++ clang/test/CodeGen/indirect-noundef.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -enable-noundef-analysis -o - %s | FileCheck %s
+// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -fsanitize-memory-param-retval -o - %s | FileCheck %s
 
 union u1 {
   int val;
Index: clang/test/CodeGen/attr-noundef.cpp
===
--- clang/test/CodeGen/attr-noundef.cpp
+++ clang/test/CodeGen/attr-noundef.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -enable-noundef-analysis %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
 // RUN: %clang -cc1 -triple aarch64-gnu-linux -x c++ -S -emit-llvm -enable-noundef-analysis %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
+// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
+// RUN: %clang -cc1 -triple aarch64-gnu-linux -x c++ -S -emit-llvm -fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
 
 // Passing structs by value
 // TODO: No structs may currently be marked noundef
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -641,10 +641,14 @@
 Args.hasFlag(options::OPT_fsanitize_memory_use_after_dtor,
  options::OPT_fno_sanitize_memory_use_after_dtor,
  MsanUseAfterDtor);
+MsanParamRetval = Args.hasFlag(
+options::OPT_fsanitize_memory_param_retval,
+options::OPT_fno_sanitize_memory_param_retval, MsanParamRetval);
 NeedPIE |= !(TC.getTriple().isOSLinux() &&
  TC.getTriple().getArch() == llvm::Triple::x86_64);
   } else {
 MsanUseAfterDtor = false;
+MsanParamRetval = false;
   }
 
   if (AllAddedKinds & SanitizerKind::Thread) {
@@ -1096,6 +1100,9 @@
   if (MsanUseAfterDtor)
 CmdArgs.push_back("-fsanitize-memory-use-after-dtor");
 
+  if (MsanParamRetval)
+CmdArgs.push_back("-fsanitize-memory-param-retval");
+
   // FIXME: Pass these parameters as function attributes, not as -llvm flags.
   if (!TsanMemoryAccess) {
 CmdArgs.push_back("-mllvm");
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1620,6 +1620,8 @@
 
   llvm::Metadata *CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
StringRef Suffix);
+
+  bool NoundefAnalysisEnabled = false;
 };
 
 }  // end namespace CodeGen
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -209,6 +209,9 @@
 ModuleNameHash = (Twine(".__uniq.") +
 Twine(toString(IntHash, /* Radix = */ 10, /* Signed = */false))).str();
   }
+
+  NoundefAnalysisEnabled =
+  CodeGenOpts.EnableNoundefAttrs || CodeGenOpts.SanitizeMemoryParamRetval;
 }
 
 CodeGenModule::~CodeGenModule() {}
Index: clang/lib/CodeGen/CGCall.cpp
==

[PATCH] D116701: Respect -fsanitize-memory-param-retval flag.

2022-01-12 Thread Kevin Athey via Phabricator via cfe-commits
kda updated this revision to Diff 399347.
kda added a comment.

Correcting diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116701

Files:
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  compiler-rt/test/msan/noundef_analysis.cpp


Index: compiler-rt/test/msan/noundef_analysis.cpp
===
--- compiler-rt/test/msan/noundef_analysis.cpp
+++ compiler-rt/test/msan/noundef_analysis.cpp
@@ -2,6 +2,8 @@
 // RUN: FileCheck %s --check-prefix=MISSED --allow-empty < %t.out
 // RUN: %clangxx_msan %s -Xclang -enable-noundef-analysis -mllvm 
-msan-eager-checks=1 -o %t && not %run %t >%t.out 2>&1
 // RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan %s -fsanitize-memory-param-retval -o %t && not %run %t 
>%t.out 2>&1
+// RUN: FileCheck %s < %t.out
 
 struct SimpleStruct {
   int md1;
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -641,10 +641,14 @@
 Args.hasFlag(options::OPT_fsanitize_memory_use_after_dtor,
  options::OPT_fno_sanitize_memory_use_after_dtor,
  MsanUseAfterDtor);
+MsanParamRetval = Args.hasFlag(
+options::OPT_fsanitize_memory_param_retval,
+options::OPT_fno_sanitize_memory_param_retval, MsanParamRetval);
 NeedPIE |= !(TC.getTriple().isOSLinux() &&
  TC.getTriple().getArch() == llvm::Triple::x86_64);
   } else {
 MsanUseAfterDtor = false;
+MsanParamRetval = false;
   }
 
   if (AllAddedKinds & SanitizerKind::Thread) {
@@ -1096,6 +1100,9 @@
   if (MsanUseAfterDtor)
 CmdArgs.push_back("-fsanitize-memory-use-after-dtor");
 
+  if (MsanParamRetval)
+CmdArgs.push_back("-fsanitize-memory-param-retval");
+
   // FIXME: Pass these parameters as function attributes, not as -llvm flags.
   if (!TsanMemoryAccess) {
 CmdArgs.push_back("-mllvm");
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -358,7 +358,8 @@
   int TrackOrigins = CGOpts.SanitizeMemoryTrackOrigins;
   bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::Memory);
   PM.add(createMemorySanitizerLegacyPassPass(
-  MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel}));
+  MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel,
+ CGOpts.SanitizeMemoryParamRetval != 0}));
 
   // MemorySanitizer inserts complex instrumentation that mostly follows
   // the logic of the original code, but operates on "shadow" values.
@@ -1163,11 +1164,11 @@
 int TrackOrigins = CodeGenOpts.SanitizeMemoryTrackOrigins;
 bool Recover = CodeGenOpts.SanitizeRecover.has(Mask);
 
-MPM.addPass(
-ModuleMemorySanitizerPass({TrackOrigins, Recover, CompileKernel}));
+MemorySanitizerOptions options(TrackOrigins, Recover, CompileKernel,
+   CodeGenOpts.SanitizeMemoryParamRetval);
+MPM.addPass(ModuleMemorySanitizerPass(options));
 FunctionPassManager FPM;
-FPM.addPass(
-MemorySanitizerPass({TrackOrigins, Recover, CompileKernel}));
+FPM.addPass(MemorySanitizerPass(options));
 if (Level != OptimizationLevel::O0) {
   // MemorySanitizer inserts complex instrumentation that mostly
   // follows the logic of the original code, but operates on
Index: clang/include/clang/Driver/SanitizerArgs.h
===
--- clang/include/clang/Driver/SanitizerArgs.h
+++ clang/include/clang/Driver/SanitizerArgs.h
@@ -33,6 +33,7 @@
   int CoverageFeatures = 0;
   int MsanTrackOrigins = 0;
   bool MsanUseAfterDtor = true;
+  bool MsanParamRetval = false;
   bool CfiCrossDso = false;
   bool CfiICallGeneralizePointers = false;
   bool CfiCanonicalJumpTables = false;


Index: compiler-rt/test/msan/noundef_analysis.cpp
===
--- compiler-rt/test/msan/noundef_analysis.cpp
+++ compiler-rt/test/msan/noundef_analysis.cpp
@@ -2,6 +2,8 @@
 // RUN: FileCheck %s --check-prefix=MISSED --allow-empty < %t.out
 // RUN: %clangxx_msan %s -Xclang -enable-noundef-analysis -mllvm -msan-eager-checks=1 -o %t && not %run %t >%t.out 2>&1
 // RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan %s -fsanitize-memory-param-retval -o %t && not %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
 
 struct SimpleStruct {
   int md1;
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -641,10 +64

[PATCH] D116701: Respect -fsanitize-memory-param-retval flag.

2022-01-12 Thread Kevin Athey via Phabricator via cfe-commits
kda added a comment.

PTAL


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116701

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


[PATCH] D115932: [Analyzer] Create and handle SymbolCast for pointer to integral conversion

2022-01-12 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Thanks for the review guys.

Artem, I agree, that we should remove `LocAsInteger`. `LocaAsInteger` is a 
primitive handling of a specific cast operation (when we cast a pointer to an 
integer). The integration of  `LocaAsInteger` into the `SymExpr` hierarchy is 
problematic as both this patch and its parent shows.

For precision, we should produce a `SymbolCast` when we evaluate a cast 
operation of a pointer to an integral type. I agree with Denys, that 
`makeSymExprValNN` is probably not the best place to do that. I took Denys' 
patch D105340  and created a prototype on top 
of that to create the `SymbolCast` in 
`SValBuilder::evalCastSubKind(loc::MemRegionVal V,`.

  void test_param(int *p) {
long p_as_integer = (long)p;
clang_analyzer_dump(p);// 
expected-warning{{&SymRegion{reg_$0}}}
clang_analyzer_dump(p_as_integer); // expected-warning{{(long) (reg_$0)}}

I'd like to upload that soon.

Once we produce the `SymbolCast`s, then we can start handling them 
semantically. In my opinion, we should follow these steps:

1. Produce `SymbolCast`s. This is done in D105340 
, plus I am going to create another patch for 
pointer-to-int casts.
2. Handle `SymbolCast`s for the simplest cases. E.g. when we cast a (64bit 
width) pointer to a (64bit width unsigned) integer. This requires the 
foundation for an additional mapping in the `ProgramState` that can map a base 
symbol to cast symbols. This would be used in the constraint manager and this 
mapping must be super efficient.
3. Gradually handle more complex `SymbolCast` semantics. E.g. a widening cast.
4. Remove `LocAsInteger`. Produce the `SymbolCast`s by default and remove the 
option of `ShouldSupportSymbolicIntegerCasts`.

Point 2) and 3) are already started in D103096 
. But again, I think first we have to get the 
solid foundations with the `State` and with the `ConstraintManager` before 
getting into the more complex implementations of widening.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115932

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


[PATCH] D116511: [clang-cl] Support the /HOTPATCH flag

2022-01-12 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea marked 2 inline comments as done.
aganea added inline comments.



Comment at: clang/test/CodeGenCXX/debug-info-hotpatch-arm.cpp:13
+// RUN: llvm-pdbutil dump -symbols %t.obj | FileCheck %s 
--check-prefix=HOTPATCH
+// ERR-HOTPATCH: error: unsupported option '/hotpatch' for target
+// HOTPATCH: S_COMPILE3 [size = [[#]]]

hans wrote:
> Does MSVC error for ARM/ARM64 too, or does it just ignore the flag?
It prints a warning:
```
D:\git\llvm-project>cl /c main.cpp /hotpatch
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30138 for ARM64
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9002 : ignoring unknown option '/hotpatch'
main.cpp
```
But in our case, the issue is that `PATCHABLE_OP` isn't supported on ARM 
backend, so it ends up asserting in 
`D:/git/llvm-project/release/lib/Target/AArch64/AArch64GenMCCodeEmitter.inc` in 
`AArch64MCCodeEmitter::getBinaryCodeForInstr`. There's perhaps a (better?) way 
for shortcutting the use of `/hotpatch` on ARM, instead of erroring-out like 
today.

Should we be more clear in the message, saying that hotpatching is supported 
but we don't the flag? Or just consume and ignore it?



Comment at: clang/test/CodeGenCXX/debug-info-hotpatch-arm.cpp:19
+///
+// RUN: %clang_cl --target=aarch64-pc-windows-msvc /c %s -o %t.obj
+// RUN: llvm-pdbutil dump -symbols %t.obj | FileCheck %s 
--check-prefix=NO-HOTPATCH

hans wrote:
> nit: We still need -- before %s with clang-cl (%s could be /Users/... and get 
> interpreted as a flag), and so it needs to come last. Same for the line in 
> debug-info-hotpatch.cpp.
Thanks will do!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116511

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


[PATCH] D105169: [Clang/Test]: Rename enable_noundef_analysis to disable-noundef-analysis and turn it off by default

2022-01-12 Thread Nathan Chancellor via Phabricator via cfe-commits
nathanchance added a comment.

In D105169#3236484 , @hyeongyukim 
wrote:

> @nathanchance
>
> I tried to reproduce the last warning (intelfbhw_validate_mode), but I failed 
> to produce it.
> I think my reproducer is correct, but it does not make any warning.
> Can you tell me which part was wrong?
>
>   clang -O2 -flto=thin -fsanitize=integer-divide-by-zero -c -o intelfb.o 
> intelfb.i
>   ld.lld -m elf_x86_64 -r -o intelfb.lto.o --whole-archive intelfb.o
>   objtool orc generate --module --no-fp --no-unreachable --uaccess --mcount 
> intelfb.lto.o
>
> I use these commands, and I attached the `intelfb.i` file.F21595840: 
> intelfb.i 

It looks like this particular case also needs `-fsanitize-coverage=trace-pc` 
(which comes from `CONFIG_KCOV`). Once I add that with your reduced reproducer, 
I see the initial warning.

  $ clang -O2 -flto=thin -fsanitize=integer-divide-by-zero 
-fsanitize-coverage=trace-pc -c -o intelfb.{o,i}
  
  $ ld.lld -m elf_x86_64 -r -o intelfb.lto.o --whole-archive intelfb.o
  
  $ ./objtool orc generate --module --no-fp --no-unreachable --uaccess --mcount 
intelfb.lto.o
  intelfb.lto.o: warning: objtool: .text.intelfbhw_validate_mode: unexpected 
end of section


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105169

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


[PATCH] D116701: Respect -fsanitize-memory-param-retval flag.

2022-01-12 Thread Kevin Athey via Phabricator via cfe-commits
kda updated this revision to Diff 399352.
kda added a comment.
Herald added subscribers: luke957, s.egerton, simoncook.

add param usage test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116701

Files:
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/Driver/fsanitize-memory-param-retval.c
  compiler-rt/test/msan/noundef_analysis.cpp

Index: compiler-rt/test/msan/noundef_analysis.cpp
===
--- compiler-rt/test/msan/noundef_analysis.cpp
+++ compiler-rt/test/msan/noundef_analysis.cpp
@@ -2,6 +2,8 @@
 // RUN: FileCheck %s --check-prefix=MISSED --allow-empty < %t.out
 // RUN: %clangxx_msan %s -Xclang -enable-noundef-analysis -mllvm -msan-eager-checks=1 -o %t && not %run %t >%t.out 2>&1
 // RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan %s -fsanitize-memory-param-retval -o %t && not %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
 
 struct SimpleStruct {
   int md1;
Index: clang/test/Driver/fsanitize-memory-param-retval.c
===
--- /dev/null
+++ clang/test/Driver/fsanitize-memory-param-retval.c
@@ -0,0 +1,12 @@
+// RUN: %clang -target i386-gnu-linux %s -fsanitize=memory -fsanitize-memory-param-retval -c -### 2>&1 | FileCheck %s
+// RUN: %clang -target x86_64-linux-gnu %s -fsanitize=memory -fsanitize-memory-param-retval -c -### 2>&1 | FileCheck %s
+// RUN: %clang -target aarch64-linux-gnu %s -fsanitize=memory -fsanitize-memory-param-retval -c -### 2>&1 | FileCheck %s
+// RUN: %clang -target riscv32-linux-gnu %s -fsanitize=memory -fsanitize-memory-param-retval -c -### 2>&1 | FileCheck %s
+// RUN: %clang -target riscv64-linux-gnu %s -fsanitize=memory -fsanitize-memory-param-retval -c -### 2>&1 | FileCheck %s
+// CHECK: "-fsanitize-memory-param-retval"
+
+// RUN: %clang -target aarch64-linux-gnu -fsyntax-only %s -fsanitize=memory -fsanitize-memory-param-retval -c -### 2>&1 | FileCheck --check-prefix=11 %s
+// 11: "-fsanitize-memory-param-retval"
+
+// RUN: not %clang -target x86_64-linux-gnu -fsyntax-only %s -fsanitize=memory -fsanitize-memory-param-retval=1 2>&1 | FileCheck --check-prefix=EXCESS %s
+// EXCESS: error: unknown argument: '-fsanitize-memory-param-retval=
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -641,10 +641,14 @@
 Args.hasFlag(options::OPT_fsanitize_memory_use_after_dtor,
  options::OPT_fno_sanitize_memory_use_after_dtor,
  MsanUseAfterDtor);
+MsanParamRetval = Args.hasFlag(
+options::OPT_fsanitize_memory_param_retval,
+options::OPT_fno_sanitize_memory_param_retval, MsanParamRetval);
 NeedPIE |= !(TC.getTriple().isOSLinux() &&
  TC.getTriple().getArch() == llvm::Triple::x86_64);
   } else {
 MsanUseAfterDtor = false;
+MsanParamRetval = false;
   }
 
   if (AllAddedKinds & SanitizerKind::Thread) {
@@ -1096,6 +1100,9 @@
   if (MsanUseAfterDtor)
 CmdArgs.push_back("-fsanitize-memory-use-after-dtor");
 
+  if (MsanParamRetval)
+CmdArgs.push_back("-fsanitize-memory-param-retval");
+
   // FIXME: Pass these parameters as function attributes, not as -llvm flags.
   if (!TsanMemoryAccess) {
 CmdArgs.push_back("-mllvm");
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -358,7 +358,8 @@
   int TrackOrigins = CGOpts.SanitizeMemoryTrackOrigins;
   bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::Memory);
   PM.add(createMemorySanitizerLegacyPassPass(
-  MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel}));
+  MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel,
+ CGOpts.SanitizeMemoryParamRetval != 0}));
 
   // MemorySanitizer inserts complex instrumentation that mostly follows
   // the logic of the original code, but operates on "shadow" values.
@@ -1163,11 +1164,11 @@
 int TrackOrigins = CodeGenOpts.SanitizeMemoryTrackOrigins;
 bool Recover = CodeGenOpts.SanitizeRecover.has(Mask);
 
-MPM.addPass(
-ModuleMemorySanitizerPass({TrackOrigins, Recover, CompileKernel}));
+MemorySanitizerOptions options(TrackOrigins, Recover, CompileKernel,
+   CodeGenOpts.SanitizeMemoryParamRetval);
+MPM.addPass(ModuleMemorySanitizerPass(options));
 FunctionPassManager FPM;
-FPM.addPass(
-MemorySanitizerPass({TrackOrigins, Recover, CompileKernel}));
+FPM.addPass(MemorySanitizerPass(options));
 if (Level != OptimizationLevel::O0) {
   // MemorySanitiz

[PATCH] D115932: [Analyzer] Create and handle SymbolCast for pointer to integral conversion

2022-01-12 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Ah, I forgot to mention one last point:

5. Revert D115149 . We should never reach 
that problematic assertion once we produce the `SymbolCast`s.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115932

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


[clang] 118f966 - [clang][#51931] Enable `-Wdeclaration-after-statement` for all C versions

2022-01-12 Thread Markus Böck via cfe-commits

Author: Markus Böck
Date: 2022-01-12T18:21:46+01:00
New Revision: 118f966b46cfb60897b56a9878e1c68fd0e2afa4

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

LOG: [clang][#51931] Enable `-Wdeclaration-after-statement` for all C versions

-Wdeclaration-after-statement currently only outputs an diagnostic if the user 
is compiling in C versions older than C99, even if the warning was explicitly 
requested by the user.
This patch makes the warning also available in later C versions. If the C 
version is C99 or later it is simply a normal warning that is disabled by 
default (as it is valid C99) and has to be enabled by users. In older versions 
it remains an extension warning, and therefore affected by -pedantic.

The above behaviour also matches GCCs behaviour.

Fixes https://bugs.llvm.org/show_bug.cgi?id=51931

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

Added: 
clang/test/Sema/warn-mixed-decls.c

Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaStmt.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index c0642efaee4e..1bc879a68a8c 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -241,6 +241,7 @@ def Documentation : DiagGroup<"documentation",
 
 def EmptyBody : DiagGroup<"empty-body">;
 def Exceptions : DiagGroup<"exceptions">;
+def DeclarationAfterStatement : DiagGroup<"declaration-after-statement">;
 
 def GNUEmptyInitializer : DiagGroup<"gnu-empty-initializer">;
 def GNUEmptyStruct : DiagGroup<"gnu-empty-struct">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index dfd1069096ea..19ce0ffcec51 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9861,8 +9861,11 @@ def err_constant_integer_arg_type : Error<
   "argument to %0 must be a constant integer">;
 
 def ext_mixed_decls_code : Extension<
-  "ISO C90 forbids mixing declarations and code">,
-  InGroup>;
+  "mixing declarations and code is a C99 extension">,
+  InGroup;
+def warn_mixed_decls_code : Warning<
+  "mixing declarations and code is incompatible with standards before C99">,
+  InGroup, DefaultIgnore;
 
 def err_non_local_variable_decl_in_for : Error<
   "declaration of non-local variable in 'for' loop">;

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 7fe92f492b5e..ef498f9a5228 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -410,9 +410,10 @@ StmtResult Sema::ActOnCompoundStmt(SourceLocation L, 
SourceLocation R,
ArrayRef Elts, bool isStmtExpr) {
   const unsigned NumElts = Elts.size();
 
-  // If we're in C89 mode, check that we don't have any decls after stmts.  If
-  // so, emit an extension diagnostic.
-  if (!getLangOpts().C99 && !getLangOpts().CPlusPlus) {
+  // If we're in C mode, check that we don't have any decls after stmts.  If
+  // so, emit an extension diagnostic in C89 and potentially a warning in later
+  // versions.
+  if (!getLangOpts().CPlusPlus) {
 // Note that __extension__ can be around a decl.
 unsigned i = 0;
 // Skip over all declarations.
@@ -425,7 +426,8 @@ StmtResult Sema::ActOnCompoundStmt(SourceLocation L, 
SourceLocation R,
 
 if (i != NumElts) {
   Decl *D = *cast(Elts[i])->decl_begin();
-  Diag(D->getLocation(), diag::ext_mixed_decls_code);
+  Diag(D->getLocation(), !getLangOpts().C99 ? diag::ext_mixed_decls_code
+: diag::warn_mixed_decls_code);
 }
   }
 

diff  --git a/clang/test/Sema/warn-mixed-decls.c 
b/clang/test/Sema/warn-mixed-decls.c
new file mode 100644
index ..219d64472b58
--- /dev/null
+++ b/clang/test/Sema/warn-mixed-decls.c
@@ -0,0 +1,28 @@
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -pedantic %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c99 
-Wdeclaration-after-statement %s
+ */
+
+/* Should not emit diagnostic when not pedantic, not enabled or in C++ Code*/
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c89 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c99 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ 
-Wdeclaration-after-statement %s
+ */
+
+/* none-no-diagnostics */
+
+int foo(int i)
+{
+  i += 1;
+  int f = i;
+#if __STDC_VERSION__ < 199901L
+  /* expected-warning@-2 {{mixing declarations and code is a C99 extension}}*/
+#else
+  /* expected-warning@-4 {{mixing declarations and code is incompatib

[PATCH] D114787: [clang][PR51931] Enable `-Wdeclaration-after-statement` for all C versions

2022-01-12 Thread Markus Böck via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG118f966b46cf: [clang][#51931] Enable 
`-Wdeclaration-after-statement` for all C versions (authored by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114787

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaStmt.cpp
  clang/test/Sema/warn-mixed-decls.c


Index: clang/test/Sema/warn-mixed-decls.c
===
--- /dev/null
+++ clang/test/Sema/warn-mixed-decls.c
@@ -0,0 +1,28 @@
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -pedantic %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c99 
-Wdeclaration-after-statement %s
+ */
+
+/* Should not emit diagnostic when not pedantic, not enabled or in C++ Code*/
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c89 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c99 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ 
-Wdeclaration-after-statement %s
+ */
+
+/* none-no-diagnostics */
+
+int foo(int i)
+{
+  i += 1;
+  int f = i;
+#if __STDC_VERSION__ < 199901L
+  /* expected-warning@-2 {{mixing declarations and code is a C99 extension}}*/
+#else
+  /* expected-warning@-4 {{mixing declarations and code is incompatible with 
standards before C99}}*/
+#endif
+  return f;
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -410,9 +410,10 @@
ArrayRef Elts, bool isStmtExpr) {
   const unsigned NumElts = Elts.size();
 
-  // If we're in C89 mode, check that we don't have any decls after stmts.  If
-  // so, emit an extension diagnostic.
-  if (!getLangOpts().C99 && !getLangOpts().CPlusPlus) {
+  // If we're in C mode, check that we don't have any decls after stmts.  If
+  // so, emit an extension diagnostic in C89 and potentially a warning in later
+  // versions.
+  if (!getLangOpts().CPlusPlus) {
 // Note that __extension__ can be around a decl.
 unsigned i = 0;
 // Skip over all declarations.
@@ -425,7 +426,8 @@
 
 if (i != NumElts) {
   Decl *D = *cast(Elts[i])->decl_begin();
-  Diag(D->getLocation(), diag::ext_mixed_decls_code);
+  Diag(D->getLocation(), !getLangOpts().C99 ? diag::ext_mixed_decls_code
+: diag::warn_mixed_decls_code);
 }
   }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9861,8 +9861,11 @@
   "argument to %0 must be a constant integer">;
 
 def ext_mixed_decls_code : Extension<
-  "ISO C90 forbids mixing declarations and code">,
-  InGroup>;
+  "mixing declarations and code is a C99 extension">,
+  InGroup;
+def warn_mixed_decls_code : Warning<
+  "mixing declarations and code is incompatible with standards before C99">,
+  InGroup, DefaultIgnore;
 
 def err_non_local_variable_decl_in_for : Error<
   "declaration of non-local variable in 'for' loop">;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -241,6 +241,7 @@
 
 def EmptyBody : DiagGroup<"empty-body">;
 def Exceptions : DiagGroup<"exceptions">;
+def DeclarationAfterStatement : DiagGroup<"declaration-after-statement">;
 
 def GNUEmptyInitializer : DiagGroup<"gnu-empty-initializer">;
 def GNUEmptyStruct : DiagGroup<"gnu-empty-struct">;


Index: clang/test/Sema/warn-mixed-decls.c
===
--- /dev/null
+++ clang/test/Sema/warn-mixed-decls.c
@@ -0,0 +1,28 @@
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -pedantic %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -Wdeclaration-after-statement %s
+ */
+
+/* Should not emit diagnostic when not pedantic, not enabled or in C++ Code*/
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c89 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c99 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ -Wdeclaration-after-statement %s
+ */
+
+/* none-no-diagnostics */
+
+int foo(int i)
+{
+  i += 1;
+  int f = i;
+#if __STDC_VERSION__ < 199901L
+  /* expected-warning@-2 {{mixing declarations and code is a C99 extension}}*/
+#else
+  /* expected-warning@-4 {{mixing declarations and code is incompatible with standards before C99}}*/
+#endif
+  return f;
+}
Index: clang/lib/Sema/SemaStmt.cpp
===

[PATCH] D116994: [RISCV] Add bfp and bfpw intrinsic in zbf extension

2022-01-12 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116994

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


[PATCH] D116633: Add -fsanitize-address-param-retval to clang.

2022-01-12 Thread Kevin Athey via Phabricator via cfe-commits
kda updated this revision to Diff 399362.
kda added a comment.

add test to validate that flag does not conflict with enable-noundef-analysis


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116633

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/attr-noundef.cpp
  clang/test/CodeGen/indirect-noundef.cpp

Index: clang/test/CodeGen/indirect-noundef.cpp
===
--- clang/test/CodeGen/indirect-noundef.cpp
+++ clang/test/CodeGen/indirect-noundef.cpp
@@ -1,4 +1,9 @@
 // RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -enable-noundef-analysis -o - %s | FileCheck %s
+// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -fsanitize-memory-param-retval -o - %s | FileCheck %s
+
+// no-sanitize-memory-param-retval does NOT conflict with enable-noundef-analysis
+// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -fno-sanitize-memory-param-retval -enable-noundef-analysis -o - %s | FileCheck %s
+// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -enable-noundef-analysis -fno-sanitize-memory-param-retval -o - %s | FileCheck %s
 
 union u1 {
   int val;
Index: clang/test/CodeGen/attr-noundef.cpp
===
--- clang/test/CodeGen/attr-noundef.cpp
+++ clang/test/CodeGen/attr-noundef.cpp
@@ -1,5 +1,11 @@
 // RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -enable-noundef-analysis %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
 // RUN: %clang -cc1 -triple aarch64-gnu-linux -x c++ -S -emit-llvm -enable-noundef-analysis %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
+// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
+// RUN: %clang -cc1 -triple aarch64-gnu-linux -x c++ -S -emit-llvm -fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
+
+// no-sanitize-memory-param-retval does NOT conflict with enable-noundef-analysis
+// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -enable-noundef-analysis -fno-sanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
+// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -fno-sanitize-memory-param-retval -enable-noundef-analysis %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
 
 // Passing structs by value
 // TODO: No structs may currently be marked noundef
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1620,6 +1620,8 @@
 
   llvm::Metadata *CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
StringRef Suffix);
+
+  bool NoundefAnalysisEnabled = false;
 };
 
 }  // end namespace CodeGen
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -209,6 +209,9 @@
 ModuleNameHash = (Twine(".__uniq.") +
 Twine(toString(IntHash, /* Radix = */ 10, /* Signed = */false))).str();
   }
+
+  NoundefAnalysisEnabled =
+  CodeGenOpts.EnableNoundefAttrs || CodeGenOpts.SanitizeMemoryParamRetval;
 }
 
 CodeGenModule::~CodeGenModule() {}
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2243,7 +2243,7 @@
  getLangOpts().Sanitize.has(SanitizerKind::Return);
 
   // Determine if the return type could be partially undef
-  if (CodeGenOpts.EnableNoundefAttrs && HasStrictReturn) {
+  if (NoundefAnalysisEnabled && HasStrictReturn) {
 if (!RetTy->isVoidType() && RetAI.getKind() != ABIArgInfo::Indirect &&
 DetermineNoUndef(RetTy, getTypes(), DL, RetAI))
   RetAttrs.addAttribute(llvm::Attribute::NoUndef);
@@ -2378,7 +2378,7 @@
 
 // Decide whether the argument we're handling could be partially undef
 bool ArgNoUndef = DetermineNoUndef(ParamType, getTypes(), DL, AI);
-if (CodeGenOpts.EnableNoundefAttrs && ArgNoUndef)
+if (NoundefAnalysisEnabled && ArgNoUndef)
   Attrs.addAttribute(llvm::Attribute::NoUndef);
 
 // 'restrict' -> 'noalias' is done in EmitFunctionProlog when we
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driv

[PATCH] D116633: Add -fsanitize-address-param-retval to clang.

2022-01-12 Thread Kevin Athey via Phabricator via cfe-commits
kda added a comment.

>>> This needs a clang/test/Driver test to show that `%clang 
>>> -fsanitize-memory-param-retval` translates to CC1 
>>> `-fsanitize-memory-param-retval`.
>>
>> Could you point me to an example?
>
> `test/Driver/fpatchable-function-entry.c` `test/Driver/fbinutils-version.c` :)

I added some conflict tests here.
I added the CC1 tests to: https://reviews.llvm.org/D116701


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116633

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


[PATCH] D115253: [C2x] Support the *_WIDTH macros in limits.h and stdint.h

2022-01-12 Thread James Y Knight via Phabricator via cfe-commits
jyknight added inline comments.



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:900-903
+  Builder.defineMacro("__USHRT_WIDTH__", Twine(TI.getShortWidth()));
+  Builder.defineMacro("__UINT_WIDTH__", Twine(TI.getIntWidth()));
+  Builder.defineMacro("__ULONG_WIDTH__", Twine(TI.getLongWidth()));
+  Builder.defineMacro("__ULLONG_WIDTH__", Twine(TI.getLongLongWidth()));

aaron.ballman wrote:
> jyknight wrote:
> > aaron.ballman wrote:
> > > jyknight wrote:
> > > > This seems odd? We define `__LONG_LONG_MAX__` but not 
> > > > `__LONG_LONG_WIDTH__`, for signed long long, and we define 
> > > > `__ULLONG_WIDTH__` but not `__ULLONG_MAX__`, for unsigned long long?
> > > > This seems odd?
> > > 
> > > Yeah, this stuff is a bit twisty.
> > > 
> > > > We define __LONG_LONG_MAX__ but not __LONG_LONG_WIDTH__, for signed 
> > > > long long,
> > > 
> > > Correct.
> > > 
> > > > and we define __ULLONG_WIDTH__ but not __ULLONG_MAX__, for unsigned 
> > > > long long?
> > > 
> > > Correct.
> > > 
> > > The basic approach I took was: for types with signed/unsigned pairs, 
> > > define the `unsigned` variants with an underscore name and use them to 
> > > define the `signed` variants in the header file because the width of 
> > > signed and unsigned has to be the same per spec ("The macro blah_WIDTH 
> > > represents the width of the type blah and shall expand to the same value 
> > > as Ublah_WIDTH.") So that's why you generally only see the "unsigned" 
> > > width variants added here with a double underscore name. I could expose 
> > > the signed versions as well (like we do for many of the MAX macros), but 
> > > that makes the preprocessor slower for no real benefit as we want the 
> > > users to use the non-underscore versions of these macros whenever 
> > > possible.
> > 1. But, in this patch, it is exposing WIDTH for both variants of all the 
> > other types. Shouldn't we consistently expose WIDTH for only one of each 
> > pair (e.g. intmax_t, int_fast16_t, etc), instead of exposing both for some 
> > types, and one for others?
> > 
> > 2. Exposing it only for unsigned seems like the wrong choice and confusing, 
> > since that implies having a basically-extraneous "U" in all of the names, 
> > and is inconsistent with previous practice. Can we expose only the signed 
> > variants instead of the unsigned?
> Ah, I see what you mean now, thanks for pushing back. Yes, I can add the 
> signed variants here so we expose both the signed and unsigned versions for 
> everything consistently. I'll also switch the headers to use both the signed 
> and unsigned variants as appropriate -- the tests ensure these values won't 
> get out of sync.
It's not clear to me why you made that change in response to my comments.

You gave a good rationale before as to why we don't want to have both signed 
and unsigned versions of the macros, so the change I was trying to suggest in 
my last comment is to //consistently// expose only the signed variants for 
`__*_WIDTH__`, and not the unsigned variants.

For comparison, gcc 11.2, `gcc -E -dM -xc /dev/null |grep WIDTH|sort` gives:
```
#define __INT_FAST16_WIDTH__ 64
#define __INT_FAST32_WIDTH__ 64
#define __INT_FAST64_WIDTH__ 64
#define __INT_FAST8_WIDTH__ 8
#define __INT_LEAST16_WIDTH__ 16
#define __INT_LEAST32_WIDTH__ 32
#define __INT_LEAST64_WIDTH__ 64
#define __INT_LEAST8_WIDTH__ 8
#define __INTMAX_WIDTH__ 64
#define __INTPTR_WIDTH__ 64
#define __INT_WIDTH__ 32
#define __LONG_LONG_WIDTH__ 64
#define __LONG_WIDTH__ 64
#define __PTRDIFF_WIDTH__ 64
#define __SCHAR_WIDTH__ 8
#define __SHRT_WIDTH__ 16
#define __SIG_ATOMIC_WIDTH__ 32
#define __SIZE_WIDTH__ 64
#define __WCHAR_WIDTH__ 32
#define __WINT_WIDTH__ 32
```


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

https://reviews.llvm.org/D115253

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


[clang] 3a32d2e - [Clang][Sema] Use VersionMap from SDKSettings for remapping tvOS and watchOS availability

2022-01-12 Thread Egor Zhdan via cfe-commits

Author: Egor Zhdan
Date: 2022-01-12T17:40:18Z
New Revision: 3a32d2e74e5c03d97a41ef7b0a01f206af62ad4f

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

LOG: [Clang][Sema] Use VersionMap from SDKSettings for remapping tvOS and 
watchOS availability

This makes the mapping between iOS & tvOS/watchOS versions more accurate. For 
example, iOS 9.3 now gets correctly mapped into tvOS 9.2 and not tvOS 9.3.

Before this change, the incorrect mapping could cause excessive or missing 
warnings for code that specifies availability for iOS, but not for tvOS/watchOS.

rdar://81491680

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

Added: 
clang/test/Sema/Inputs/AppleTVOS15.0.sdk/SDKSettings.json
clang/test/Sema/Inputs/WatchOS7.0.sdk/SDKSettings.json

Modified: 
clang/include/clang/Basic/DarwinSDKInfo.h
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Sema/attr-availability-tvos.c
clang/test/Sema/attr-availability-watchos.c

Removed: 




diff  --git a/clang/include/clang/Basic/DarwinSDKInfo.h 
b/clang/include/clang/Basic/DarwinSDKInfo.h
index b0673dc8b3cd8..df16827debfc0 100644
--- a/clang/include/clang/Basic/DarwinSDKInfo.h
+++ b/clang/include/clang/Basic/DarwinSDKInfo.h
@@ -57,6 +57,20 @@ class DarwinSDKInfo {
llvm::Triple::MacOSX, llvm::Triple::UnknownEnvironment);
 }
 
+/// Returns the os-environment mapping pair that's used to represent the
+/// iOS -> watchOS version mapping.
+static inline constexpr OSEnvPair iOStoWatchOSPair() {
+  return OSEnvPair(llvm::Triple::IOS, llvm::Triple::UnknownEnvironment,
+   llvm::Triple::WatchOS, 
llvm::Triple::UnknownEnvironment);
+}
+
+/// Returns the os-environment mapping pair that's used to represent the
+/// iOS -> tvOS version mapping.
+static inline constexpr OSEnvPair iOStoTvOSPair() {
+  return OSEnvPair(llvm::Triple::IOS, llvm::Triple::UnknownEnvironment,
+   llvm::Triple::TvOS, llvm::Triple::UnknownEnvironment);
+}
+
   private:
 StorageType Value;
 

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b4d8d1494e705..b1ef02865328f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1565,8 +1565,11 @@ class Sema final {
   /// assignment.
   llvm::DenseMap RefsMinusAssignments;
 
+private:
   Optional> CachedDarwinSDKInfo;
 
+  bool WarnedDarwinSDKInfoMissing = false;
+
 public:
   Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
TranslationUnitKind TUKind = TU_Complete,
@@ -1595,8 +1598,10 @@ class Sema final {
   ASTConsumer &getASTConsumer() const { return Consumer; }
   ASTMutationListener *getASTMutationListener() const;
   ExternalSemaSource* getExternalSource() const { return ExternalSource; }
+
   DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking(SourceLocation Loc,
  StringRef Platform);
+  DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking();
 
   ///Registers an external source. If an external source already exists,
   /// creates a multiplex external source and appends to it.

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 60f37c17c3f18..aaa31adf2e97a 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -60,6 +60,16 @@ ModuleLoader &Sema::getModuleLoader() const { return 
PP.getModuleLoader(); }
 DarwinSDKInfo *
 Sema::getDarwinSDKInfoForAvailabilityChecking(SourceLocation Loc,
   StringRef Platform) {
+  auto *SDKInfo = getDarwinSDKInfoForAvailabilityChecking();
+  if (!SDKInfo && !WarnedDarwinSDKInfoMissing) {
+Diag(Loc, diag::warn_missing_sdksettings_for_availability_checking)
+<< Platform;
+WarnedDarwinSDKInfoMissing = true;
+  }
+  return SDKInfo;
+}
+
+DarwinSDKInfo *Sema::getDarwinSDKInfoForAvailabilityChecking() {
   if (CachedDarwinSDKInfo)
 return CachedDarwinSDKInfo->get();
   auto SDKInfo = parseDarwinSDKInfo(
@@ -71,8 +81,6 @@ Sema::getDarwinSDKInfoForAvailabilityChecking(SourceLocation 
Loc,
   }
   if (!SDKInfo)
 llvm::consumeError(SDKInfo.takeError());
-  Diag(Loc, diag::warn_missing_sdksettings_for_availability_checking)
-  << Platform;
   CachedDarwinSDKInfo = std::unique_ptr();
   return nullptr;
 }

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 642b878e02706..955f477760429 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2625,9 +2625,25 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
   NewII = &S.Context.Idents.get("watchos_app_extension");

[PATCH] D116822: [Clang][Sema] Use VersionMap from SDKSettings for remapping tvOS and watchOS availability

2022-01-12 Thread Egor Zhdan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3a32d2e74e5c: [Clang][Sema] Use VersionMap from SDKSettings 
for remapping tvOS and watchOS… (authored by egorzhdan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116822

Files:
  clang/include/clang/Basic/DarwinSDKInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/Inputs/AppleTVOS15.0.sdk/SDKSettings.json
  clang/test/Sema/Inputs/WatchOS7.0.sdk/SDKSettings.json
  clang/test/Sema/attr-availability-tvos.c
  clang/test/Sema/attr-availability-watchos.c

Index: clang/test/Sema/attr-availability-watchos.c
===
--- clang/test/Sema/attr-availability-watchos.c
+++ clang/test/Sema/attr-availability-watchos.c
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 "-triple" "arm64-apple-watchos3.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "arm64-apple-watchos4.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "arm64-apple-watchos4.0" -DUSE_VERSION_MAP -isysroot %S/Inputs/WatchOS7.0.sdk -fsyntax-only -verify %s
 
 void f0(int) __attribute__((availability(ios,introduced=2.0,deprecated=2.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
 void f1(int) __attribute__((availability(ios,introduced=2.1)));
@@ -58,3 +59,19 @@
 void test_ios_correctly_map_to_watchos() {
   deprecatedAfterIntroduced(); // expected-warning {{'deprecatedAfterIntroduced' is deprecated: first deprecated in watchOS 3}}
 }
+
+#ifdef USE_VERSION_MAP
+// iOS 10.3.1 corresponds to watchOS 3.2, as indicated in 'SDKSettings.json'.
+void f9(int) __attribute__((availability(ios,deprecated=10.3.1))); // expected-note {{'f9' has been explicitly marked deprecated here}}
+
+void testWithVersionMap() {
+  f9(0); // expected-warning {{'f9' is deprecated: first deprecated in watchOS 3.2}}
+}
+#else
+// Without VersionMap, watchOS version is inferred incorrectly as 3.3.1.
+void f9(int) __attribute__((availability(ios,deprecated=10.3.1))); // expected-note {{'f9' has been explicitly marked deprecated here}}
+
+void testWithoutVersionMap() {
+  f9(0); // expected-warning {{'f9' is deprecated: first deprecated in watchOS 3.3.1}}
+}
+#endif
Index: clang/test/Sema/attr-availability-tvos.c
===
--- clang/test/Sema/attr-availability-tvos.c
+++ clang/test/Sema/attr-availability-tvos.c
@@ -1,63 +1,80 @@
-// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos3.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos13.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos13.0" -DUSE_VERSION_MAP -isysroot %S/Inputs/AppleTVOS15.0.sdk -fsyntax-only -verify %s
 
-void f0(int) __attribute__((availability(tvos,introduced=2.0,deprecated=2.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
-void f1(int) __attribute__((availability(tvos,introduced=2.1)));
-void f2(int) __attribute__((availability(tvos,introduced=2.0,deprecated=3.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
-void f3(int) __attribute__((availability(tvos,introduced=3.0)));
-void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(tvos,introduced=2.0,deprecated=2.1,obsoleted=3.0))); // expected-note{{explicitly marked unavailable}}
+void f0(int) __attribute__((availability(tvos,introduced=12.0,deprecated=12.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
+void f1(int) __attribute__((availability(tvos,introduced=12.1)));
+void f2(int) __attribute__((availability(tvos,introduced=12.0,deprecated=13.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
+void f3(int) __attribute__((availability(tvos,introduced=13.0)));
+void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(tvos,introduced=12.0,deprecated=12.1,obsoleted=13.0))); // expected-note{{explicitly marked unavailable}}
 
-void f5(int) __attribute__((availability(tvos,introduced=2.0))) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
-void f6(int) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
-void f6(int) __attribute__((availability(tvos,introduced=2.0)));
+void f5(int) __attribute__((availability(tvos,introduced=12.0))) __attribute__((availability(tvos,deprecated=13.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(tvos,deprecated=13.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(tvos,introduced=12.0)));
 
 void test() {
-  f0(0); // expected-warning{{

[PATCH] D115523: [OpenCL] Set external linkage for block enqueue kernels

2022-01-12 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D115523#3237410 , @yaxunl wrote:

> It is possible that block kernels are defined and invoked in static 
> functions, therefore two block kernels in different TU's may have the same 
> name. Making such kernels external may cause duplicate symbols.

Potentially we should append the name of the translation unit to all kernel 
wrapper names for the enqueued blocks to resolve this? For example, global 
constructors stubs are using such a similar naming scheme taken from the 
translation unit.

But the kernel function in OpenCL has to be globally visible and many tools 
have been built with this assumption. Additionally, some toolchains might 
require the enqueued kernels to be globally visible as well in order to access 
them as an execution entry point.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115523

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


[PATCH] D112718: Add intrinsics and builtins for PTX atomics with semantic orders

2022-01-12 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsNVPTX.def:1057
+
+BUILTIN(__nvvm_atom_xchg_global_i, "iiD*i", "n")
+TARGET_BUILTIN(__nvvm_atom_cta_xchg_global_i, "iiD*i", "n", SM_60)

t4c1 wrote:
> tra wrote:
> > Naghasan wrote:
> > > tra wrote:
> > > > t4c1 wrote:
> > > > > tra wrote:
> > > > > > t4c1 wrote:
> > > > > > > tra wrote:
> > > > > > > > We need to figure out how address-space-specific builtins are 
> > > > > > > > supposed to work.
> > > > > > > > Right now two competing approaches.
> > > > > > > > 
> > > > > > > > This patch declares builtins with generic pointer as an 
> > > > > > > > argument, but, according to the test, expects to be used with 
> > > > > > > > the AS-specific pointer.
> > > > > > > > It probably does not catch a wrong-AS pointer passed as an 
> > > > > > > > argument, either.
> > > > > > > > It does happen to work, but I think it's mostly due to the fact 
> > > > > > > > that LLVM intrinsics are overloaded and we happen to end up 
> > > > > > > > addrspacecast'ing  things correctly if the builtin gets the 
> > > > > > > > right kind of pointer.
> > > > > > > > 
> > > > > > > > The other approach is to declare the pointer with the expected 
> > > > > > > > AS. E.g:
> > > > > > > > > TARGET_BUILTIN(__nvvm_mbarrier_init_shared, "vWi*3i", "", 
> > > > > > > > > AND(SM_80,PTX70))
> > > > > > > > 
> > > > > > > > IMO, this is the correct way to do it, but it is also rather 
> > > > > > > > inconvenient to use from CUDA code as it operates on generic 
> > > > > > > > pointers.
> > > > > > > > 
> > > > > > > > @jdoerfert - WDYT?
> > > > > > > >TARGET_BUILTIN(__nvvm_mbarrier_init_shared, "vWi*3i", "", 
> > > > > > > >AND(SM_80,PTX70))
> > > > > > > >IMO, this is the correct way to do it, but it is also rather 
> > > > > > > >inconvenient to use from CUDA code as it operates on generic 
> > > > > > > >pointers.
> > > > > > > 
> > > > > > > I tried doing this, however it is also completely unusable from 
> > > > > > > OpenCL code (which is our use case). Trying to use it gives you 
> > > > > > > errors about how casting pointers to different address spaces  - 
> > > > > > > for example from local to AS3 is not allowed.
> > > > > > Hmm. It should've worked. It would need the same explicit cast to a 
> > > > > > pointer in AS(3) as in your tests, but it would safeguard against 
> > > > > > attempts to pass it a generic pointer. E.g. 
> > > > > > https://godbolt.org/z/qE6oxzheM
> > > > > > 
> > > > > > Explicit casting to AS(X) for AS-specific variants is annoying, but 
> > > > > > it's probably unavoidable at the moment regardless of whether we 
> > > > > > declare the pointer argument to be AS-specific or not.  LLVM will 
> > > > > > not always be able to infer that a pointer is in particular AS.
> > > > > > Using specific AS in the declaration has a minor benefit of 
> > > > > > safeguarding at compile time against unintentional use of generic 
> > > > > > pointers.
> > > > > > 
> > > > > > Ideally we may want to convert generic variant of the builtin to 
> > > > > > AS-specific one, if LLVM does know the AS. We currently do this for 
> > > > > > loads/stores, but not for other instructions.
> > > > > > 
> > > > > Well, it does not work. See: https://godbolt.org/z/vM6bKncc4. 
> > > > > Declaring the pointer to be in generic AS is the only way I got it to 
> > > > > work. If you know a way to call a builtin declared with AS numbers in 
> > > > > OpenCL, I am happy to do that instead.
> > > > Could you help me understand how different address spaces are handled 
> > > > by OpenCL in clang and LLVM?
> > > > What exactly are `__local` or `__private` in OpenCL? Do they map to 
> > > > LLVM's address spaces? 
> > > > Clang does complain that we're trying to change AS, but I do not see AS 
> > > > used in the IR: https://godbolt.org/z/soajoE991
> > > > 
> > > > AFAICT what happens is:
> > > > * OpenCL does use explicit AS for pointers (`__local`, `__private` seem 
> > > > to pop up in the error messages)
> > > > * `__attribute__((address_space(3)))` does not match the AS of 
> > > > `__local` and that leads to an error.
> > > > * generic pointer argument works because we are allowed to cast any 
> > > > specific AS to generic one.
> > > > 
> > > > In other words, having specific-AS arguemt works as intended, we just 
> > > > have a mismatch between AS number used by OpenCL and AS number used by 
> > > > NVPTX and we're not allowed to cast between two specific AS.
> > > > 
> > > > If that's indeed the case, then what we appear to be missing is the 
> > > > mapping from OpenCL AS to the target-specific AS, which should, 
> > > > ideally, be done by clang itself. So, if NVPTX-specific builtin 
> > > > operating on shared pointer is called with a pointer in OpenCL's 
> > > > equivalent of CUDA's `__shared__`, it should be mapped to AS(3).
> > > > 
> > > > Could you help me understand how different address spaces are handled 
> > > > by

[PATCH] D116673: [Clang][NVPTX]Add NVPTX intrinsics and builtins for CUDA PTX cvt sm80 instructions

2022-01-12 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D116673#3237342 , @JackAKirk wrote:

> I thought I should let you know that I do not have commit access to land the 
> patch.  I'm also happy to wait a little longer in case you think other 
> interested parties might still chime in.

I can land the patch on your behalf. Are you OK to use the name/email in this 
patch or do you prefer to use a different email for the LLVM commit?

> fatal error: error in backend: Cannot select: intrinsic 
> %llvm.nvvm.shfl.idx.f32

Thank you for letting me know. I'll take a look.


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

https://reviews.llvm.org/D116673

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


[PATCH] D116673: [Clang][NVPTX]Add NVPTX intrinsics and builtins for CUDA PTX cvt sm80 instructions

2022-01-12 Thread Jack Kirk via Phabricator via cfe-commits
JackAKirk marked 2 inline comments as done.
JackAKirk added a comment.



>> I can land the patch on your behalf. Are you OK to use the name/email in 
>> this patch or do you prefer to use a different email for the LLVM commit?
>
> Thanks very much.  Yes the name/email in the patch is fine.




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

https://reviews.llvm.org/D116673

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


[PATCH] D117098: [RISCV] update zfh and zfhmin extention to v1.0

2022-01-12 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/test/Preprocessor/riscv-target-features.c:207
 
 // RUN: %clang -target riscv32-unknown-linux-gnu 
-menable-experimental-extensions \
+// RUN: -march=rv32izfhmin1p0 -x c -E -dM %s \

If it's not experimental now, do you need -menable-experimental-extensions?



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoZfh.td:1
 //===-- RISCVInstrInfoFH.td - RISC-V 'FH' instructions -*- tablegen 
-*-===//
 //

While you're in here can you fix this line by replacing 'FH' with 'Zfh'


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117098

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


[PATCH] D116190: Comment parsing: Don't recognize commands in single-line double quotation

2022-01-12 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/lib/AST/CommentLexer.cpp:278
+
+again:
+  size_t End =

I'd suggest refactoring to a `while (true)` if you don't mind.



Comment at: clang/lib/AST/CommentLexer.cpp:290
+if (End != StringRef::npos && *(TokenPtr + End) == '\"')
+  TokenPtr += End + 1;
+goto again;

Does Doxygen understand escaped quotes?

```
/// "@hello\"@hello"
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116190

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


[PATCH] D115253: [C2x] Support the *_WIDTH macros in limits.h and stdint.h

2022-01-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:900-903
+  Builder.defineMacro("__USHRT_WIDTH__", Twine(TI.getShortWidth()));
+  Builder.defineMacro("__UINT_WIDTH__", Twine(TI.getIntWidth()));
+  Builder.defineMacro("__ULONG_WIDTH__", Twine(TI.getLongWidth()));
+  Builder.defineMacro("__ULLONG_WIDTH__", Twine(TI.getLongLongWidth()));

jyknight wrote:
> aaron.ballman wrote:
> > jyknight wrote:
> > > aaron.ballman wrote:
> > > > jyknight wrote:
> > > > > This seems odd? We define `__LONG_LONG_MAX__` but not 
> > > > > `__LONG_LONG_WIDTH__`, for signed long long, and we define 
> > > > > `__ULLONG_WIDTH__` but not `__ULLONG_MAX__`, for unsigned long long?
> > > > > This seems odd?
> > > > 
> > > > Yeah, this stuff is a bit twisty.
> > > > 
> > > > > We define __LONG_LONG_MAX__ but not __LONG_LONG_WIDTH__, for signed 
> > > > > long long,
> > > > 
> > > > Correct.
> > > > 
> > > > > and we define __ULLONG_WIDTH__ but not __ULLONG_MAX__, for unsigned 
> > > > > long long?
> > > > 
> > > > Correct.
> > > > 
> > > > The basic approach I took was: for types with signed/unsigned pairs, 
> > > > define the `unsigned` variants with an underscore name and use them to 
> > > > define the `signed` variants in the header file because the width of 
> > > > signed and unsigned has to be the same per spec ("The macro blah_WIDTH 
> > > > represents the width of the type blah and shall expand to the same 
> > > > value as Ublah_WIDTH.") So that's why you generally only see the 
> > > > "unsigned" width variants added here with a double underscore name. I 
> > > > could expose the signed versions as well (like we do for many of the 
> > > > MAX macros), but that makes the preprocessor slower for no real benefit 
> > > > as we want the users to use the non-underscore versions of these macros 
> > > > whenever possible.
> > > 1. But, in this patch, it is exposing WIDTH for both variants of all the 
> > > other types. Shouldn't we consistently expose WIDTH for only one of each 
> > > pair (e.g. intmax_t, int_fast16_t, etc), instead of exposing both for 
> > > some types, and one for others?
> > > 
> > > 2. Exposing it only for unsigned seems like the wrong choice and 
> > > confusing, since that implies having a basically-extraneous "U" in all of 
> > > the names, and is inconsistent with previous practice. Can we expose only 
> > > the signed variants instead of the unsigned?
> > Ah, I see what you mean now, thanks for pushing back. Yes, I can add the 
> > signed variants here so we expose both the signed and unsigned versions for 
> > everything consistently. I'll also switch the headers to use both the 
> > signed and unsigned variants as appropriate -- the tests ensure these 
> > values won't get out of sync.
> It's not clear to me why you made that change in response to my comments.
> 
> You gave a good rationale before as to why we don't want to have both signed 
> and unsigned versions of the macros, so the change I was trying to suggest in 
> my last comment is to //consistently// expose only the signed variants for 
> `__*_WIDTH__`, and not the unsigned variants.
> 
> For comparison, gcc 11.2, `gcc -E -dM -xc /dev/null |grep WIDTH|sort` gives:
> ```
> #define __INT_FAST16_WIDTH__ 64
> #define __INT_FAST32_WIDTH__ 64
> #define __INT_FAST64_WIDTH__ 64
> #define __INT_FAST8_WIDTH__ 8
> #define __INT_LEAST16_WIDTH__ 16
> #define __INT_LEAST32_WIDTH__ 32
> #define __INT_LEAST64_WIDTH__ 64
> #define __INT_LEAST8_WIDTH__ 8
> #define __INTMAX_WIDTH__ 64
> #define __INTPTR_WIDTH__ 64
> #define __INT_WIDTH__ 32
> #define __LONG_LONG_WIDTH__ 64
> #define __LONG_WIDTH__ 64
> #define __PTRDIFF_WIDTH__ 64
> #define __SCHAR_WIDTH__ 8
> #define __SHRT_WIDTH__ 16
> #define __SIG_ATOMIC_WIDTH__ 32
> #define __SIZE_WIDTH__ 64
> #define __WCHAR_WIDTH__ 32
> #define __WINT_WIDTH__ 32
> ```
> It's not clear to me why you made that change in response to my comments.

I had the impression you wanted both signed and unsigned _WIDTH macros to be 
emitted for consistency with the exact-width (et al) macros. Guess it was the 
opposite, you want the exact-width and basic macros to only define the signed 
versions. However, this makes use of `DefineTypeSizeAndWidth()` within 
`DefineExactWidthIntTypeSize()` and similar kind of awkward -- that now has to 
track whether we're defining a signed vs unsigned type to decide whether to 
emit the _WIDTH macro. So I guess that'll have to be reworked.


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

https://reviews.llvm.org/D115253

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


[PATCH] D117129: [clang-tidy] Extract Class IncluderClangTidyCheck

2022-01-12 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood created this revision.
LegalizeAdulthood added a reviewer: alexfh.
LegalizeAdulthood added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, arphaman, kbarton, xazax.hun, mgorny, 
nemanjai.
LegalizeAdulthood requested review of this revision.

IncluderClangTidyCheck is a base class for checks that
want to insert include files as part of their fixits.

IncluderClangTidyCheck::storeOptions should be called
first by any derived classes that override storeOptions.

IncluderClangTidyCheck::registerPPCallbacks should be
called first by any derived classes that override
registerPPCallbacks and perform additional preprocessor
logic.

Switch the following classes to use IncluderClangTidyCheck:

- abseil::StringFindStartswithCheck
- bugprone::ImplicitWideningOfMultiplicationResultCheck
- cppcoreguidelines::InitVariablesCheck
- cppcoreguidelines::ProBoundsCOnstantArrayIndexCheck
- misc::UniqueptrResetReleaseCheck
- modernize::LoopConvertCheck
- modernize::MakeSmartPtrCheck
- modernize::PassByValueCheck
- modernize::ReplaceAutoPtrCheck
- modernize::ReplaceRandomShuffleCheck
- performance::TypePromotionInMathFnCheck
- performance::UnnecessaryValueParamCheck
- utils::TransformerClangTidyCheck


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117129

Files:
  clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
  clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
  
clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
  
clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.h
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.h
  clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
  clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.h
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h
  clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
  clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.h
  clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.h
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h
  clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h
  clang-tools-extra/clang-tidy/utils/CMakeLists.txt
  clang-tools-extra/clang-tidy/utils/IncluderClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/utils/IncluderClangTidyCheck.h
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h

Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
===
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
@@ -9,8 +9,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_TRANSFORMER_CLANG_TIDY_CHECK_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_TRANSFORMER_CLANG_TIDY_CHECK_H
 
-#include "../ClangTidyCheck.h"
-#include "IncludeInserter.h"
+#include "IncluderClangTidyCheck.h"
 #include "IncludeSorter.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Tooling/Transformer/Transformer.h"
@@ -36,7 +35,7 @@
 //  the source code, 'llvm' or 'google'.  Default is 'llvm'. The naming
 //  convention influences how canonical headers are distinguished from other
 //  includes.
-class TransformerClangTidyCheck : public ClangTidyCheck {
+class TransformerClangTidyCheck : public IncluderClangTidyCheck {
 public:
   TransformerClangTidyCheck(StringRef Name, ClangTidyContext *Context);
 
@@ -58,15 +57,9 @@
   TransformerClangTidyCheck(transformer::RewriteRule R, StringRef Name,
 ClangTidyContext *Context);
 
-  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
-   Preprocessor *ModuleExpanderPP) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) final;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) final;
 
-  /// Derived classes that override this function should call this method from
-  /// the overridden method.
-  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
-
 

[PATCH] D116518: [ast-matchers] Add hasSubstatementSequence matcher

2022-01-12 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

Thanks for looping me in. I'll try to take a detailed look later today. In the 
meantime, I'll note that we have something similar internally which I never got 
around to upstreaming. However, we chose to support arbitrarily many matchers, 
with this interface:

  const clang::ast_matchers::internal::VariadicFunction<
  clang::ast_matchers::internal::Matcher,
  internal::SequenceMatcher,
  internal::hasSubstatementSequenceFunc>
  hasSubstatementSequence = {};

The `SequenceMatcher` API is:

  // The following definitions all support the `hasSubstatementSequence`
  // matcher. This matcher supports describing the series of statements in a
  // compound statement, in a style inspired by regular expressions. Unlike
  // regular expressions, however, these operators are deterministic. Choices 
are
  // tried in order. For optional-style operators (`maybeOne`, `zeroOrMore` and
  // `oneOrMore`) the positive choice is considered first.
  template 
  internal::SequenceMatcher exactlyOne(
  clang::ast_matchers::internal::Matcher Matcher) {
return {std::move(Matcher)};
  }
  
  template 
  internal::SequenceMatcher maybeOne(
  clang::ast_matchers::internal::Matcher Matcher) {
return {internal::SequenceElementKind::ZeroOrOne, std::move(Matcher)};
  }
  
  template 
  internal::SequenceMatcher zeroOrMore(
  clang::ast_matchers::internal::Matcher Matcher) {
return {internal::SequenceElementKind::ZeroOrMore, std::move(Matcher)};
  }
  
  template 
  internal::SequenceMatcher oneOrMore(
  clang::ast_matchers::internal::Matcher Matcher) {
return {internal::SequenceElementKind::OneOrMore, std::move(Matcher)};
  }

I also implemented a non-deterministic version using backtracking. But, that 
scared me off because of its potential cost (potential, b/c we could use 
memoization like packrat parsing to avoid the exponential).

That said, my experience indicates that once you're thinking in terms of 
sequences, you're probably going to find that you want to match over the CFG, 
rather than the AST directly.


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

https://reviews.llvm.org/D116518

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


[PATCH] D114823: Filter string_view from the nullptr diagnosis of bugprone-string-constructor to prevent duplicate warnings with bugprone-stringview-nullptr

2022-01-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 399370.
CJ-Johnson added a comment.

Only filter out basic_string_view when bugprone-stringview-nullptr is enabled


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114823

Files:
  clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h


Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
@@ -30,6 +30,7 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
+  const bool IsStringviewNullptrCheckEnabled;
   const bool WarnOnLargeLength;
   const unsigned int LargeLengthThreshold;
   std::vector StringNames;
Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
@@ -43,6 +43,8 @@
 StringConstructorCheck::StringConstructorCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
+  IsStringviewNullptrCheckEnabled(
+  Context->isCheckEnabled("bugprone-stringview-nullptr")),
   WarnOnLargeLength(Options.get("WarnOnLargeLength", true)),
   LargeLengthThreshold(Options.get("LargeLengthThreshold", 0x80)),
   StringNames(utils::options::parseStringList(
@@ -121,17 +123,20 @@
   // Check the literal string constructor with char pointer.
   // [i.e. string (const char* s);]
   Finder->addMatcher(
-  traverse(TK_AsIs,
-   cxxConstructExpr(
-   hasDeclaration(cxxConstructorDecl(ofClass(cxxRecordDecl(
-   hasAnyName(removeNamespaces(StringNames)),
-   hasArgument(0, expr().bind("from-ptr")),
-   // do not match std::string(ptr, int)
-   // match std::string(ptr, alloc)
-   // match std::string(ptr)
-   anyOf(hasArgument(1, unless(hasType(isInteger(,
- argumentCountIs(1)))
-   .bind("constructor")),
+  traverse(
+  TK_AsIs,
+  cxxConstructExpr(
+  hasDeclaration(cxxConstructorDecl(ofClass(anyOf(
+  cxxRecordDecl(hasName("basic_string_view"))
+  .bind("basic_string_view_decl"),
+  cxxRecordDecl(hasAnyName(removeNamespaces(StringNames))),
+  hasArgument(0, expr().bind("from-ptr")),
+  // do not match std::string(ptr, int)
+  // match std::string(ptr, alloc)
+  // match std::string(ptr)
+  anyOf(hasArgument(1, unless(hasType(isInteger(,
+argumentCountIs(1)))
+  .bind("constructor")),
   this);
 }
 
@@ -167,6 +172,12 @@
 Ptr->EvaluateAsRValue(ConstPtr, Ctx) &&
 ((ConstPtr.Val.isInt() && ConstPtr.Val.getInt().isZero()) ||
  (ConstPtr.Val.isLValue() && ConstPtr.Val.isNullPointer( {
+  if (IsStringviewNullptrCheckEnabled &&
+  Result.Nodes.getNodeAs("basic_string_view_decl")) {
+// Filter out `basic_string_view` to avoid conflicts with
+// `bugprone-stringview-nullptr`
+return;
+  }
   diag(Loc, "constructing string from nullptr is undefined behaviour");
 }
   }


Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
@@ -30,6 +30,7 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
+  const bool IsStringviewNullptrCheckEnabled;
   const bool WarnOnLargeLength;
   const unsigned int LargeLengthThreshold;
   std::vector StringNames;
Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
@@ -43,6 +43,8 @@
 StringConstructorCheck::StringConstructorCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
+  IsStringviewNullptrCheckEnabled(
+  Context->isCheckEnabled("bugprone-stringview-nullptr")),
   WarnOnLargeLength(Options.get("WarnOnLargeLength", true)),
   LargeLengthThreshold(Options.get("LargeLengthThreshold", 0x80)),
   StringNames(utils::

[PATCH] D114823: Filter string_view from the nullptr diagnosis of bugprone-string-constructor to prevent duplicate warnings with bugprone-stringview-nullptr

2022-01-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added a comment.

In D114823#3229990 , @njames93 wrote:

> I'm in 2 minds about this. This diagnostic is a good fit for this warning and 
> shouldn't be removed. Likewise duplicate diagnostics from different checks is 
> annoying. Maybe a better path forward would be to suppress the diagnostic if 
> the `bugprone-stringview-nullptr` check is enabled. These kinds of intercheck 
> dependencies are found in modernize-prefer-member-init check IIRC. You can 
> just copy the impl from there.

Great suggestion! I've updated this diff to do exactly that. Thanks! :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114823

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


[PATCH] D117049: [OpenMP] Add support for embedding bitcode images in wrapper tool

2022-01-12 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 399373.
jhuber6 added a comment.

Update approach, improve LTO file handling for multiple outputs and don't 
change the LTO config.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117049

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -76,13 +76,18 @@
cl::desc("Path for the target bitcode library"),
cl::cat(ClangLinkerWrapperCategory));
 
+static cl::opt EmbedBC(
+"target-embed-bc", cl::ZeroOrMore,
+cl::desc("Embed linked bitcode instead of an executable device image."),
+cl::init(false), cl::cat(ClangLinkerWrapperCategory));
+
 // Do not parse linker options.
 static cl::list
 HostLinkerArgs(cl::Positional,
cl::desc("..."));
 
 /// Path of the current binary.
-static std::string LinkerExecutable;
+static const char *LinkerExecutable;
 
 /// Temporary files created by the linker wrapper.
 static SmallVector TempFiles;
@@ -423,8 +428,8 @@
 
   std::unique_ptr Buffer =
   MemoryBuffer::getMemBuffer(Library.getMemoryBufferRef(), false);
-  if (Error Err = writeArchive(TempFile, Members, true, Library.kind(),
-true, Library.isThin(), std::move(Buffer)))
+  if (Error Err = writeArchive(TempFile, Members, true, Library.kind(), true,
+   Library.isThin(), std::move(Buffer)))
 return std::move(Err);
 
   return static_cast(TempFile);
@@ -501,7 +506,7 @@
   return static_cast(TempFile);
 }
 
-Expected link(ArrayRef InputFiles,
+Expected link(ArrayRef InputFiles,
ArrayRef LinkerArgs, Triple TheTriple,
StringRef Arch) {
   // NVPTX uses the nvlink binary to link device object files.
@@ -535,7 +540,7 @@
   CmdArgs.push_back(Arg);
 
   // Add extracted input files.
-  for (auto Input : InputFiles)
+  for (StringRef Input : InputFiles)
 CmdArgs.push_back(Input);
 
   if (sys::ExecuteAndWait(*NvlinkPath, CmdArgs))
@@ -545,7 +550,7 @@
 }
 } // namespace nvptx
 
-Expected linkDevice(ArrayRef InputFiles,
+Expected linkDevice(ArrayRef InputFiles,
  ArrayRef LinkerArgs,
  Triple TheTriple, StringRef Arch) {
   switch (TheTriple.getArch()) {
@@ -612,8 +617,10 @@
   llvm_unreachable("Invalid optimization level");
 }
 
-std::unique_ptr createLTO(const Triple &TheTriple, StringRef Arch,
-bool WholeProgram) {
+template >
+std::unique_ptr createLTO(
+const Triple &TheTriple, StringRef Arch, bool WholeProgram,
+ModuleHook Hook = [](size_t, const Module &) { return true; }) {
   lto::Config Conf;
   lto::ThinBackend Backend;
   // TODO: Handle index-only thin-LTO
@@ -652,11 +659,11 @@
  [](char C) { return C == '_' || isAlnum(C); });
 }
 
-Expected> linkBitcodeFiles(ArrayRef InputFiles,
- const Triple &TheTriple,
- StringRef Arch) {
+Error linkBitcodeFiles(SmallVectorImpl &InputFiles,
+   const Triple &TheTriple, StringRef Arch) {
   SmallVector, 4> SavedBuffers;
   SmallVector, 4> BitcodeFiles;
+  SmallVector NewInputFiles;
   StringMap UsedInRegularObj;
 
   // Search for bitcode files in the input and create an LTO input file. If it
@@ -675,6 +682,7 @@
   if (!ObjFile)
 return ObjFile.takeError();
 
+  NewInputFiles.push_back(File.str());
   for (auto &Sym : (*ObjFile)->symbols()) {
 Expected Name = Sym.getName();
 if (!Name)
@@ -694,12 +702,36 @@
   }
 
   if (BitcodeFiles.empty())
-return None;
+return Error::success();
+
+  auto HandleError = [&](std::error_code EC) {
+logAllUnhandledErrors(errorCodeToError(EC),
+  WithColor::error(errs(), LinkerExecutable));
+exit(1);
+  };
+
+  // LTO Module hook to output bitcode without running the backend.
+  auto LinkOnly = [&](size_t Task, const Module &M) {
+SmallString<128> TempFile;
+if (std::error_code EC = sys::fs::createTemporaryFile(
+"jit-" + TheTriple.getTriple(), "bc", TempFile))
+  HandleError(EC);
+std::error_code EC;
+raw_fd_ostream LinkedBitcode(TempFile, EC, sys::fs::OF_None);
+if (EC)
+  HandleError(EC);
+WriteBitcodeToFile(M, LinkedBitcode);
+TempFiles.push_back(static_cast(TempFile));
+NewInputFiles.push_back(static_cast(TempFile));
+return false;
+  };
 
   // We have visi

[clang] 6e77ad1 - Add an assert in cpudispatch emit to try to track down an error.

2022-01-12 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2022-01-12T10:31:28-08:00
New Revision: 6e77ad11ffab71fa71629fe4df0af1ecefcfa649

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

LOG: Add an assert in cpudispatch emit to try to track down an error.

I'm attempting to debug an issue that I can only get to happen on
godbolt, where the cpu-dispatch resolver for an out of line member
function is generated with the wrong name, causing a link failure.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 6d6f154f45bf8..d824cb3980506 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3492,11 +3492,14 @@ void 
CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
 
   llvm::Type *ResolverType;
   GlobalDecl ResolverGD;
-  if (getTarget().supportsIFunc())
+  if (getTarget().supportsIFunc()) {
 ResolverType = llvm::FunctionType::get(
 llvm::PointerType::get(DeclTy,
Context.getTargetAddressSpace(FD->getType())),
 false);
+assert(ResolverName.endswith(".resolver") &&
+   "CPUDispatch IFunc resolver doesn't end with .resolver?");
+  }
   else {
 ResolverType = DeclTy;
 ResolverGD = GD;



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


[PATCH] D115121: Update bugprone-stringview-nullptr to support return statements and constructors for any T which accepts basic_string_view

2022-01-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 399376.
CJ-Johnson added a comment.

Nits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115121

Files:
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -16,78 +16,116 @@
 template 
 class basic_string_view {
 public:
-  basic_string_view();
+  constexpr basic_string_view() {}
 
-  basic_string_view(const CharT *);
+  constexpr basic_string_view(const CharT *) {}
 
   // Not present in C++17 and C++20:
-  // basic_string_view(std::nullptr_t);
+  // constexpr basic_string_view(std::nullptr_t) {}
 
-  basic_string_view(const CharT *, size_t);
+  constexpr basic_string_view(const CharT *, size_t) {}
 
-  basic_string_view(const basic_string_view &);
+  constexpr basic_string_view(const basic_string_view &) {}
 
-  basic_string_view &operator=(const basic_string_view &);
+  constexpr basic_string_view &operator=(const basic_string_view &) {}
 };
 
 template 
-bool operator<(basic_string_view, basic_string_view);
+constexpr bool operator<(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<(type_identity_t>,
-   basic_string_view);
+constexpr bool operator<(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator<(basic_string_view,
-   type_identity_t>);
+constexpr bool operator<(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator<=(basic_string_view, basic_string_view);
+constexpr bool operator<=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(type_identity_t>,
-basic_string_view);
+constexpr bool operator<=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(basic_string_view,
-type_identity_t>);
+constexpr bool operator<=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>(basic_string_view, basic_string_view);
+constexpr bool operator>(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator>(type_identity_t>,
-   basic_string_view);
+constexpr bool operator>(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator>(basic_string_view,
-   type_identity_t>);
+constexpr bool operator>(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>=(basic_string_view, basic_string_view);
+constexpr bool operator>=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator>=(type_identity_t>,
-basic_string_view);
+constexpr bool operator>=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator>=(basic_string_view,
-type_identity_t>);
+constexpr bool operator>=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator==(basic_string_view, basic_string_view);
+constexpr bool operator==(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator==(type_identity_t>,
-basic_string_view);
+constexpr bool operator==(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator==(basic_string_view,
-type_identity_t>);
+constexpr bool operator==(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator!=(basic_string_view, basic_string_view);
+constexpr bool operator!=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(type_identity_t>,
-basic_string_view);
+constexpr bool operator!=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(basic_string_view,
-type_identity_t>);
+constexpr bool operator!=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 using string_view = basic_string_view;
 
 } // namespace std
 
+using SV = std::string_view; // Used in some places for shorter line length
+
 void function(std::string_view);
 void function(std::string_view, std::string_view);
 
@@ -200,19 +238,19 @@
   // Static Cast
   {
 (void)(static_cast(nullptr)) /* a25 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: constructing{{.*}}defau

[PATCH] D117130: [RISCV] Move Zba/Zbb/Zbc/Zbs out of experimental since they have been ratified.

2022-01-12 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: asb, luismarques, jrtc27, evandro.
Herald added subscribers: VincentWu, luke957, achieveartificialintelligence, 
StephenFan, vkmr, frasercrmck, jdoerfert, apazos, sameer.abuasal, s.egerton, 
Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, 
edward-jones, zzheng, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, 
hiraditya.
craig.topper requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117130

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbc.c
  clang/test/Driver/riscv-arch.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/test/CodeGen/RISCV/addimm-mulimm.ll
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/CodeGen/RISCV/div-by-constant.ll
  llvm/test/CodeGen/RISCV/imm.ll
  llvm/test/CodeGen/RISCV/rv32zba.ll
  llvm/test/CodeGen/RISCV/rv32zbb-intrinsic.ll
  llvm/test/CodeGen/RISCV/rv32zbb-zbp.ll
  llvm/test/CodeGen/RISCV/rv32zbb.ll
  llvm/test/CodeGen/RISCV/rv32zbc-intrinsic.ll
  llvm/test/CodeGen/RISCV/rv32zbs.ll
  llvm/test/CodeGen/RISCV/rv64i-exhaustive-w-insts.ll
  llvm/test/CodeGen/RISCV/rv64zba.ll
  llvm/test/CodeGen/RISCV/rv64zbb-intrinsic.ll
  llvm/test/CodeGen/RISCV/rv64zbb-zbp.ll
  llvm/test/CodeGen/RISCV/rv64zbb.ll
  llvm/test/CodeGen/RISCV/rv64zbc-intrinsic.ll
  llvm/test/CodeGen/RISCV/rv64zbs.ll
  llvm/test/CodeGen/RISCV/rvv/fixed-vectors-store-merge-crash.ll
  llvm/test/CodeGen/RISCV/sadd_sat.ll
  llvm/test/CodeGen/RISCV/sadd_sat_plus.ll
  llvm/test/CodeGen/RISCV/selectcc-to-shiftand.ll
  llvm/test/CodeGen/RISCV/sextw-removal.ll
  llvm/test/CodeGen/RISCV/ssub_sat.ll
  llvm/test/CodeGen/RISCV/ssub_sat_plus.ll
  llvm/test/CodeGen/RISCV/uadd_sat.ll
  llvm/test/CodeGen/RISCV/uadd_sat_plus.ll
  llvm/test/CodeGen/RISCV/unfold-masked-merge-scalar-variablemask.ll
  llvm/test/CodeGen/RISCV/usub_sat.ll
  llvm/test/CodeGen/RISCV/usub_sat_plus.ll
  llvm/test/CodeGen/RISCV/xaluo.ll
  llvm/test/MC/RISCV/attribute-arch-invalid.s
  llvm/test/MC/RISCV/rv32zba-invalid.s
  llvm/test/MC/RISCV/rv32zba-valid.s
  llvm/test/MC/RISCV/rv32zbb-aliases-valid.s
  llvm/test/MC/RISCV/rv32zbb-invalid.s
  llvm/test/MC/RISCV/rv32zbb-valid.s
  llvm/test/MC/RISCV/rv32zbbp-invalid.s
  llvm/test/MC/RISCV/rv32zbbp-only-valid.s
  llvm/test/MC/RISCV/rv32zbbp-valid.s
  llvm/test/MC/RISCV/rv32zbc-invalid.s
  llvm/test/MC/RISCV/rv32zbc-valid.s
  llvm/test/MC/RISCV/rv32zbs-aliases-valid.s
  llvm/test/MC/RISCV/rv32zbs-invalid.s
  llvm/test/MC/RISCV/rv32zbs-valid.s
  llvm/test/MC/RISCV/rv64zba-aliases-valid.s
  llvm/test/MC/RISCV/rv64zba-invalid.s
  llvm/test/MC/RISCV/rv64zba-valid.s
  llvm/test/MC/RISCV/rv64zbb-aliases-valid.s
  llvm/test/MC/RISCV/rv64zbb-invalid.s
  llvm/test/MC/RISCV/rv64zbb-valid.s
  llvm/test/MC/RISCV/rv64zbbp-invalid.s
  llvm/test/MC/RISCV/rv64zbbp-valid.s
  llvm/test/MC/RISCV/rv64zbs-aliases-valid.s
  llvm/test/Transforms/ConstantHoisting/RISCV/immediates.ll
  llvm/test/Transforms/LoopIdiom/RISCV/popcnt.ll

Index: llvm/test/Transforms/LoopIdiom/RISCV/popcnt.ll
===
--- llvm/test/Transforms/LoopIdiom/RISCV/popcnt.ll
+++ llvm/test/Transforms/LoopIdiom/RISCV/popcnt.ll
@@ -1,6 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -loop-idiom -mtriple=riscv32 -mattr=+experimental-zbb -S < %s | FileCheck %s --check-prefixes=CPOP
-; RUN: opt -loop-idiom -mtriple=riscv64 -mattr=+experimental-zbb -S < %s | FileCheck %s --check-prefixes=CPOP
+; RUN: opt -loop-idiom -mtriple=riscv32 -mattr=+zbb -S < %s | FileCheck %s --check-prefixes=CPOP
+; RUN: opt -loop-idiom -mtriple=riscv64 -mattr=+zbb -S < %s | FileCheck %s --check-prefixes=CPOP
 ; RUN: opt -loop-idiom -mtriple=riscv32 -S < %s | FileCheck %s --check-prefixes=NOCPOP
 ; RUN: opt -loop-idiom -mtriple=riscv64 -S < %s | FileCheck %s --check-prefixes=NOCPOP
 
Index: llvm/test/Transforms/ConstantHoisting/RISCV/immediates.ll
===
--- llvm/test/Transforms/ConstantHoisting/RISCV/immediates.ll
+++ llvm/test/Transforms/ConstantHoisting/RISCV/immediates.ll
@@ -47,7 +47,7 @@
 }
 
 ; Check that we don't hoist zext.h with 65535 with Zbb.
-define i32 @test6(i32 %a) nounwind "target-features"="+experimental-zbb" {
+define i32 @test6(i32 %a) nounwind "target-features"="+zbb" {
 ; CHECK-LABEL: test6
 ; CHECK: and i32 %a, 65535
   %1 = and i32 %a, 65535
@@ -65,7 +65,7 @@
 }
 
 ; Check that we don't hoist zext.w with Zba.
-define i64 @test8(i64 %a) nounwind "target-features"="+experi

[PATCH] D115253: [C2x] Support the *_WIDTH macros in limits.h and stdint.h

2022-01-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 399383.
aaron.ballman added a comment.

Reworked a different way -- expose the signed versions of the width macros 
rather than the unsigned versions or both versions. Note, `__UINTPTR_WIDTH__` 
and `__UINTMAX_WIDTH__` were both preexisting macros, so I did not remove them.


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

https://reviews.llvm.org/D115253

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Headers/limits.h
  clang/lib/Headers/stdint.h
  clang/test/Headers/limits.cpp
  clang/test/Headers/stdint.c
  clang/test/Preprocessor/init-aarch64.c
  clang/test/Preprocessor/init.c
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -715,11 +715,7 @@
 
   Two's complement sign representation
   http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2412.pdf";>N2412
-  
-Partial
-  Lacking width macros in limits.h and stdint.h
-
-  
+  Clang 14
 
 
   Adding the u8 character prefix
Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -1520,6 +1520,7 @@
 // WEBASSEMBLY-NEXT:#define __ATOMIC_RELEASE 3
 // WEBASSEMBLY-NEXT:#define __ATOMIC_SEQ_CST 5
 // WEBASSEMBLY-NEXT:#define __BIGGEST_ALIGNMENT__ 16
+// WEBASSEMBLY-NEXT:#define __BOOL_WIDTH__ 8
 // WEBASSEMBLY-NEXT:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
 // WEBASSEMBLY-NEXT:#define __CHAR16_TYPE__ unsigned short
 // WEBASSEMBLY-NEXT:#define __CHAR32_TYPE__ unsigned int
@@ -1609,21 +1610,25 @@
 // WEBASSEMBLY-NEXT:#define __INT16_FMTi__ "hi"
 // WEBASSEMBLY-NEXT:#define __INT16_MAX__ 32767
 // WEBASSEMBLY-NEXT:#define __INT16_TYPE__ short
+// WEBASSEMBLY-NEXT:#define __INT16_WIDTH__ 16
 // WEBASSEMBLY-NEXT:#define __INT32_C_SUFFIX__
 // WEBASSEMBLY-NEXT:#define __INT32_FMTd__ "d"
 // WEBASSEMBLY-NEXT:#define __INT32_FMTi__ "i"
 // WEBASSEMBLY-NEXT:#define __INT32_MAX__ 2147483647
 // WEBASSEMBLY-NEXT:#define __INT32_TYPE__ int
+// WEBASSEMBLY-NEXT:#define __INT32_WIDTH__ 32
 // WEBASSEMBLY-NEXT:#define __INT64_C_SUFFIX__ LL
 // WEBASSEMBLY-NEXT:#define __INT64_FMTd__ "lld"
 // WEBASSEMBLY-NEXT:#define __INT64_FMTi__ "lli"
 // WEBASSEMBLY-NEXT:#define __INT64_MAX__ 9223372036854775807LL
 // WEBASSEMBLY-NEXT:#define __INT64_TYPE__ long long int
+// WEBASSEMBLY-NEXT:#define __INT64_WIDTH__ 64
 // WEBASSEMBLY-NEXT:#define __INT8_C_SUFFIX__
 // WEBASSEMBLY-NEXT:#define __INT8_FMTd__ "hhd"
 // WEBASSEMBLY-NEXT:#define __INT8_FMTi__ "hhi"
 // WEBASSEMBLY-NEXT:#define __INT8_MAX__ 127
 // WEBASSEMBLY-NEXT:#define __INT8_TYPE__ signed char
+// WEBASSEMBLY-NEXT:#define __INT8_WIDTH__ 8
 // WEBASSEMBLY-NEXT:#define __INTMAX_C_SUFFIX__ LL
 // WEBASSEMBLY-NEXT:#define __INTMAX_FMTd__ "lld"
 // WEBASSEMBLY-NEXT:#define __INTMAX_FMTi__ "lli"
@@ -1641,35 +1646,44 @@
 // WEBASSEMBLY-NEXT:#define __INT_FAST16_FMTi__ "hi"
 // WEBASSEMBLY-NEXT:#define __INT_FAST16_MAX__ 32767
 // WEBASSEMBLY-NEXT:#define __INT_FAST16_TYPE__ short
+// WEBASSEMBLY-NEXT:#define __INT_FAST16_WIDTH__ 16
 // WEBASSEMBLY-NEXT:#define __INT_FAST32_FMTd__ "d"
 // WEBASSEMBLY-NEXT:#define __INT_FAST32_FMTi__ "i"
 // WEBASSEMBLY-NEXT:#define __INT_FAST32_MAX__ 2147483647
 // WEBASSEMBLY-NEXT:#define __INT_FAST32_TYPE__ int
+// WEBASSEMBLY-NEXT:#define __INT_FAST32_WIDTH__ 32
 // WEBASSEMBLY-NEXT:#define __INT_FAST64_FMTd__ "lld"
 // WEBASSEMBLY-NEXT:#define __INT_FAST64_FMTi__ "lli"
 // WEBASSEMBLY-NEXT:#define __INT_FAST64_MAX__ 9223372036854775807LL
 // WEBASSEMBLY-NEXT:#define __INT_FAST64_TYPE__ long long int
+// WEBASSEMBLY-NEXT:#define __INT_FAST64_WIDTH__ 64
 // WEBASSEMBLY-NEXT:#define __INT_FAST8_FMTd__ "hhd"
 // WEBASSEMBLY-NEXT:#define __INT_FAST8_FMTi__ "hhi"
 // WEBASSEMBLY-NEXT:#define __INT_FAST8_MAX__ 127
 // WEBASSEMBLY-NEXT:#define __INT_FAST8_TYPE__ signed char
+// WEBASSEMBLY-NEXT:#define __INT_FAST8_WIDTH__ 8
 // WEBASSEMBLY-NEXT:#define __INT_LEAST16_FMTd__ "hd"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST16_FMTi__ "hi"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST16_MAX__ 32767
 // WEBASSEMBLY-NEXT:#define __INT_LEAST16_TYPE__ short
+// WEBASSEMBLY-NEXT:#define __INT_LEAST16_WIDTH__ 16
 // WEBASSEMBLY-NEXT:#define __INT_LEAST32_FMTd__ "d"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST32_FMTi__ "i"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST32_MAX__ 2147483647
 // WEBASSEMBLY-NEXT:#define __INT_LEAST32_TYPE__ int
+// WEBASSEMBLY-NEXT:#define __INT_LEAST32_WIDTH__ 32
 // WEBASSEMBLY-NEXT:#define __INT_LEAST64_FMTd__ "lld"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST64_FMTi__ "lli"
 // WEBASSEMBLY-NEXT:#define __INT_LEAST64_MAX__ 9223372036854775807LL
 // WEBASSEMBLY-NEXT:#define __INT_LEAST64_TYPE__ long long int
+// WEBASSEMBLY-NEXT:#define __INT_LEAST64_WIDTH__ 64
 // WEBASSEMBLY-NEXT:

[PATCH] D117131: [RISCV] Update recently ratified Zb{a,b,c,s} extensions to no longer be experimental

2022-01-12 Thread Alex Bradbury via Phabricator via cfe-commits
asb created this revision.
asb added reviewers: craig.topper, luismarques.
Herald added subscribers: VincentWu, luke957, achieveartificialintelligence, 
StephenFan, vkmr, frasercrmck, jdoerfert, evandro, apazos, sameer.abuasal, 
s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, 
rogfer01, edward-jones, zzheng, jrtc27, kito-cheng, niosHD, sabuasal, 
simoncook, johnrusso, rbar, hiraditya.
asb requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

Agreed policy is that RISC-V extensions that have not yet been ratified should 
be marked as experimental, and enabling them requires the use of the 
-menable-experimental-extensions flag when using clang alongside the version 
number. These extensions have now been ratified, so this is no longer 
necessary, and the target feature names can be renamed to no longer be prefixed 
with "experimental-".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117131

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbc.c
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
  llvm/test/CodeGen/RISCV/addimm-mulimm.ll
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/CodeGen/RISCV/div-by-constant.ll
  llvm/test/CodeGen/RISCV/imm.ll
  llvm/test/CodeGen/RISCV/rv32zba.ll
  llvm/test/CodeGen/RISCV/rv32zbb-intrinsic.ll
  llvm/test/CodeGen/RISCV/rv32zbb-zbp.ll
  llvm/test/CodeGen/RISCV/rv32zbb.ll
  llvm/test/CodeGen/RISCV/rv32zbc-intrinsic.ll
  llvm/test/CodeGen/RISCV/rv32zbs.ll
  llvm/test/CodeGen/RISCV/rv64i-exhaustive-w-insts.ll
  llvm/test/CodeGen/RISCV/rv64zba.ll
  llvm/test/CodeGen/RISCV/rv64zbb-intrinsic.ll
  llvm/test/CodeGen/RISCV/rv64zbb-zbp.ll
  llvm/test/CodeGen/RISCV/rv64zbb.ll
  llvm/test/CodeGen/RISCV/rv64zbc-intrinsic.ll
  llvm/test/CodeGen/RISCV/rv64zbs.ll
  llvm/test/CodeGen/RISCV/rvv/fixed-vectors-store-merge-crash.ll
  llvm/test/CodeGen/RISCV/sadd_sat.ll
  llvm/test/CodeGen/RISCV/sadd_sat_plus.ll
  llvm/test/CodeGen/RISCV/selectcc-to-shiftand.ll
  llvm/test/CodeGen/RISCV/sextw-removal.ll
  llvm/test/CodeGen/RISCV/ssub_sat.ll
  llvm/test/CodeGen/RISCV/ssub_sat_plus.ll
  llvm/test/CodeGen/RISCV/uadd_sat.ll
  llvm/test/CodeGen/RISCV/uadd_sat_plus.ll
  llvm/test/CodeGen/RISCV/unfold-masked-merge-scalar-variablemask.ll
  llvm/test/CodeGen/RISCV/usub_sat.ll
  llvm/test/CodeGen/RISCV/usub_sat_plus.ll
  llvm/test/CodeGen/RISCV/xaluo.ll
  llvm/test/MC/RISCV/attribute-arch-invalid.s
  llvm/test/MC/RISCV/rv32zba-invalid.s
  llvm/test/MC/RISCV/rv32zba-valid.s
  llvm/test/MC/RISCV/rv32zbb-aliases-valid.s
  llvm/test/MC/RISCV/rv32zbb-invalid.s
  llvm/test/MC/RISCV/rv32zbb-valid.s
  llvm/test/MC/RISCV/rv32zbbp-invalid.s
  llvm/test/MC/RISCV/rv32zbbp-only-valid.s
  llvm/test/MC/RISCV/rv32zbbp-valid.s
  llvm/test/MC/RISCV/rv32zbc-invalid.s
  llvm/test/MC/RISCV/rv32zbc-valid.s
  llvm/test/MC/RISCV/rv32zbs-aliases-valid.s
  llvm/test/MC/RISCV/rv32zbs-invalid.s
  llvm/test/MC/RISCV/rv32zbs-valid.s
  llvm/test/MC/RISCV/rv64zba-aliases-valid.s
  llvm/test/MC/RISCV/rv64zba-invalid.s
  llvm/test/MC/RISCV/rv64zba-valid.s
  llvm/test/MC/RISCV/rv64zbb-aliases-valid.s
  llvm/test/MC/RISCV/rv64zbb-invalid.s
  llvm/test/MC/RISCV/rv64zbb-valid.s
  llvm/test/MC/RISCV/rv64zbbp-invalid.s
  llvm/test/MC/RISCV/rv64zbbp-valid.s
  llvm/test/MC/RISCV/rv64zbs-aliases-valid.s
  llvm/test/Transforms/ConstantHoisting/RISCV/immediates.ll
  llvm/test/Transforms/LoopIdiom/RISCV/popcnt.ll

Index: llvm/test/Transforms/LoopIdiom/RISCV/popcnt.ll
===
--- llvm/test/Transforms/LoopIdiom/RISCV/popcnt.ll
+++ llvm/test/Transforms/LoopIdiom/RISCV/popcnt.ll
@@ -1,6 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -loop-idiom -mtriple=riscv32 -mattr=+experimental-zbb -S < %s | FileCheck %s --check-prefixes=CPOP
-; RUN: opt -loop-idiom -mtriple=riscv64 -mattr=+experimental-zbb -S < %s | FileCheck %s --check-prefixes=CPOP
+; RUN: opt -loop-idiom -mtriple=riscv32 -mattr=+zbb -S < %s | FileCheck %s --check-prefixes=CPOP
+; RUN: opt -loop-idiom -mtriple=riscv64 -mattr=+zbb -S < %s | FileCheck %s --check-prefixes=CPOP
 ; RUN: opt -loop-idiom -mtriple=riscv32 -S < %s | FileCheck %s --check-prefixes=NOCPOP
 ; RUN: opt -loop-idiom -mtriple=riscv64 -S < %s | FileCheck %s --check-prefixes=NOCPOP
 
Index: llvm/test/Transforms/ConstantHoisting/RISCV/immediates.ll
===
--- llvm/test/Transforms/ConstantHoisting/RISCV/immediates.ll
+++ llvm

[PATCH] D117130: [RISCV] Move Zba/Zbb/Zbc/Zbs out of experimental since they have been ratified.

2022-01-12 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

Doh - looks like we had the same idea at the same time :) D117131 
. I've not done a full diff, but one thing I 
spotted was that the RISCVInstrInfoZb.td header needs updating.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117130

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


[PATCH] D117130: [RISCV] Move Zba/Zbb/Zbc/Zbs out of experimental since they have been ratified.

2022-01-12 Thread Craig Topper via Phabricator via cfe-commits
craig.topper abandoned this revision.
craig.topper added a comment.

Abandoning in favor of D117131 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117130

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


[PATCH] D117131: [RISCV] Update recently ratified Zb{a,b,c,s} extensions to no longer be experimental

2022-01-12 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117131

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


[PATCH] D87279: [clang] Fix handling of physical registers in inline assembly operands.

2022-01-12 Thread Jonas Paulsson via Phabricator via cfe-commits
jonpa added a comment.

Sorry for the delay.

> This change seems like it's done in the wrong layer -- why do we add a 
> special-case in Clang to emit "={r11},{r11}", instead of fixing LLVM to not 
> break when given the previously-output "={r11},0"?

We were starting out with a test case that was the result of macro-intensive 
code (Linux kernel). It had a tied physreg def/use, with an additional use of 
the same physreg, which did not compile with clang. There were two problems: 
TwoAddress could not handle this case and therefore asserted, and also the 
extra COPY in the output of the same physreg that would also have to be dealt 
with.

Instead of trying to improve TwoAddress to recognize and handle a special case 
like this while also making sure no redundant COPYs would be produced, we found 
it more reasonable to handle this in the front end. The reasoning was that "= 
{r7},0" should be completely equivalent with "= {r7},{r7}", and they should be 
treated the same by the compiler. A tied physreg did not seem useful in the 
first place, so we decided to always emit the second form from the front end.

This is pretty much what the original commit message said: "Background: Macro 
intensive user code may contain inline assembly statements with multiple 
operands constrained to the same physreg. Such a case (with the operand 
constraints "+r" : "r") currently triggers the TwoAddressInstructionPass 
assertion against any extra use of a tied register. Furthermore, TwoAddress 
will insert a COPY to that physreg even though isel has already done so (for 
the non-tied use), which may lead to a second redundant instruction currently. 
A simple fix for this is to not emit tied physreg uses in the first place for 
the "+r" constraint, which is what this patch does."

> Furthermore, since earlyclobber was exempted from this change, doesn't the 
> same TwoAddressInstructionPass bug still affect earlyclobber uses?

I was never under the impression that this was a bug in TwoAddress, but rather 
an unhandled ("odd") case of phys-regs. ISel produced the first COPY, and 
TwoAddress the second one. How should that be cleaned up? Seemed best to avoid 
adding unnecessarily to TwoAddress if possible to avoid it...

Sorry, we don't have early clobber operands on SystemZ, so I haven't really 
thought much about that. We decided we had to exclude them from this patch per 
the reasoning of https://reviews.llvm.org/D87279#2334519.

So I would guess it might still be a problem to compile an early-clobber tied 
def/use of a physreg with an extra use (or several) of the same physreg. If 
that case is something you intend to handle, I would agree that perhaps then 
the front end change of this patch would not be needed anymore as it is the 
alternative approach.

> @nathanchance reports in https://github.com/ClangBuiltLinux/linux/issues/1512 
> that... now seems to be crashing as a result of this change.

I tested x.c, and it "works" on SystemZ, while it did not pass ISel on X86, 
from what I understand. Given the above reasoning of the equivalency between 
the two expressions (use either tied or explicit of the same phys-reg), I would 
also wonder if X86 is "choking on valid IR"...

As another matter, the SystemZ backend actually can't handle x.c, as it 
triggers `SpillGPRs.LowGPR != SpillGPRs.HighGPR && "Should be saving %r15 and 
something else". This is however a problem in the prologe/epilog emission if 
anything... I guess the case of just clobbering SP in a function has not been 
seen before.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87279

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


[PATCH] D117123: [clang][dataflow] Add transfer functions for initializers

2022-01-12 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:171
+
+Value *InitExprVal = Env.getValue(*InitExpr, SkipPast::None);
+if (InitExprVal == nullptr)

why `None`? Is the idea that if the expression generates a reference, we want 
to get the pointer value, not the pointee?
So, in the example below, the value set for field `y` will (correctly) be the 
same pointer stored in field `x`?
```
struct A {
  int &x;
  int &y = x;
};
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117123

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


[PATCH] D115942: [X86][MS] Change the alignment of f80 to 16 bytes on Windows 32bits to match with ICC

2022-01-12 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Not sure I agree with the "fix" to the lld tests.  If the linker is crashing, 
clearly there's a bug, not just an incorrect test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115942

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


[PATCH] D115942: [X86][MS] Change the alignment of f80 to 16 bytes on Windows 32bits to match with ICC

2022-01-12 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Right, the auto-upgrade should upgrade and prevent the need to change the 
bitcode data layout. LTO is the main use case for auto-upgrading.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115942

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


[PATCH] D116939: [AArch64] clang support for Armv8.8/9.3 HBC

2022-01-12 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 marked 2 inline comments as done.
tyb0807 added inline comments.



Comment at: clang/lib/Basic/Targets/AArch64.cpp:666-675
+  HasHBC |= ArchKind == llvm::AArch64::ArchKind::ARMV8_8A ||
+ArchKind == llvm::AArch64::ArchKind::ARMV9_3A;
+
+  // Check features that are manually disabled by command line options.
+  // This needs to be checked after architecture-related features are handled,
+  // making sure they are properly disabled when required.
+  for (const auto &Feature : Features) {

nickdesaulniers wrote:
> this whole block is suspect to me. Why is HBC special with regards to all 
> other architectural extensions?
Indeed, HBC does not require the frontend to generate any special intrinsic in 
the IR, so  the frontend does not need to know about whether HBC is enabled or 
disabled in the command line. This can thus be completely handled by the target 
parser.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116939

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


[PATCH] D116859: Fix for: clang-format: break added to macro define with ColumnLimit: 0

2022-01-12 Thread Armen Khachkinaev via Phabricator via cfe-commits
futuarmo updated this revision to Diff 399394.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116859

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4804,6 +4804,13 @@
Style);
 }
 
+TEST_F(FormatTest, FormatMacroWithZeroColumnWidth) {
+  FormatStyle ZeroColumn = getLLVMStyleWithColumns(0);
+
+  verifyFormat("#define A LOOONG() LOOONG()\n",
+   ZeroColumn);
+}
+
 TEST_F(FormatTest, LayoutMacroDefinitionsStatementsSpanningBlocks) {
   verifyFormat("#define A \\\n"
"  f({ \\\n"
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -485,7 +485,8 @@
 // different LineFormatter would be used otherwise.
 if (Previous.ClosesTemplateDeclaration)
   return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_No;
-if (Previous.is(TT_FunctionAnnotationRParen))
+if (Previous.is(TT_FunctionAnnotationRParen) &&
+State.Line->Type != LT_PreprocessorDirective)
   return true;
 if (Previous.is(TT_LeadingJavaAnnotation) && Current.isNot(tok::l_paren) &&
 Current.isNot(TT_LeadingJavaAnnotation))


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4804,6 +4804,13 @@
Style);
 }
 
+TEST_F(FormatTest, FormatMacroWithZeroColumnWidth) {
+  FormatStyle ZeroColumn = getLLVMStyleWithColumns(0);
+
+  verifyFormat("#define A LOOONG() LOOONG()\n",
+   ZeroColumn);
+}
+
 TEST_F(FormatTest, LayoutMacroDefinitionsStatementsSpanningBlocks) {
   verifyFormat("#define A \\\n"
"  f({ \\\n"
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -485,7 +485,8 @@
 // different LineFormatter would be used otherwise.
 if (Previous.ClosesTemplateDeclaration)
   return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_No;
-if (Previous.is(TT_FunctionAnnotationRParen))
+if (Previous.is(TT_FunctionAnnotationRParen) &&
+State.Line->Type != LT_PreprocessorDirective)
   return true;
 if (Previous.is(TT_LeadingJavaAnnotation) && Current.isNot(tok::l_paren) &&
 Current.isNot(TT_LeadingJavaAnnotation))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 33d008b - [RISCV] Update recently ratified Zb{a,b,c,s} extensions to no longer be experimental

2022-01-12 Thread Alex Bradbury via cfe-commits

Author: Alex Bradbury
Date: 2022-01-12T19:33:44Z
New Revision: 33d008b169f3c813a4a45da220d0952f795ac477

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

LOG: [RISCV] Update recently ratified Zb{a,b,c,s} extensions to no longer be 
experimental

Agreed policy is that RISC-V extensions that have not yet been ratified
should be marked as experimental, and enabling them requires the use of
the -menable-experimental-extensions flag when using clang alongside the
version number. These extensions have now been ratified, so this is no
longer necessary, and the target feature names can be renamed to no
longer be prefixed with "experimental-".

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsRISCV.def
clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbc.c
clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbc.c
clang/test/Driver/riscv-arch.c
clang/test/Preprocessor/riscv-target-features.c
llvm/lib/Support/RISCVISAInfo.cpp
llvm/lib/Target/RISCV/RISCV.td
llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
llvm/test/CodeGen/RISCV/addimm-mulimm.ll
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/CodeGen/RISCV/div-by-constant.ll
llvm/test/CodeGen/RISCV/imm.ll
llvm/test/CodeGen/RISCV/rv32zba.ll
llvm/test/CodeGen/RISCV/rv32zbb-intrinsic.ll
llvm/test/CodeGen/RISCV/rv32zbb-zbp.ll
llvm/test/CodeGen/RISCV/rv32zbb.ll
llvm/test/CodeGen/RISCV/rv32zbc-intrinsic.ll
llvm/test/CodeGen/RISCV/rv32zbs.ll
llvm/test/CodeGen/RISCV/rv64i-exhaustive-w-insts.ll
llvm/test/CodeGen/RISCV/rv64zba.ll
llvm/test/CodeGen/RISCV/rv64zbb-intrinsic.ll
llvm/test/CodeGen/RISCV/rv64zbb-zbp.ll
llvm/test/CodeGen/RISCV/rv64zbb.ll
llvm/test/CodeGen/RISCV/rv64zbc-intrinsic.ll
llvm/test/CodeGen/RISCV/rv64zbs.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-store-merge-crash.ll
llvm/test/CodeGen/RISCV/sadd_sat.ll
llvm/test/CodeGen/RISCV/sadd_sat_plus.ll
llvm/test/CodeGen/RISCV/selectcc-to-shiftand.ll
llvm/test/CodeGen/RISCV/sextw-removal.ll
llvm/test/CodeGen/RISCV/ssub_sat.ll
llvm/test/CodeGen/RISCV/ssub_sat_plus.ll
llvm/test/CodeGen/RISCV/uadd_sat.ll
llvm/test/CodeGen/RISCV/uadd_sat_plus.ll
llvm/test/CodeGen/RISCV/unfold-masked-merge-scalar-variablemask.ll
llvm/test/CodeGen/RISCV/usub_sat.ll
llvm/test/CodeGen/RISCV/usub_sat_plus.ll
llvm/test/CodeGen/RISCV/xaluo.ll
llvm/test/MC/RISCV/attribute-arch-invalid.s
llvm/test/MC/RISCV/rv32zba-invalid.s
llvm/test/MC/RISCV/rv32zba-valid.s
llvm/test/MC/RISCV/rv32zbb-aliases-valid.s
llvm/test/MC/RISCV/rv32zbb-invalid.s
llvm/test/MC/RISCV/rv32zbb-valid.s
llvm/test/MC/RISCV/rv32zbbp-invalid.s
llvm/test/MC/RISCV/rv32zbbp-only-valid.s
llvm/test/MC/RISCV/rv32zbbp-valid.s
llvm/test/MC/RISCV/rv32zbc-invalid.s
llvm/test/MC/RISCV/rv32zbc-valid.s
llvm/test/MC/RISCV/rv32zbs-aliases-valid.s
llvm/test/MC/RISCV/rv32zbs-invalid.s
llvm/test/MC/RISCV/rv32zbs-valid.s
llvm/test/MC/RISCV/rv64zba-aliases-valid.s
llvm/test/MC/RISCV/rv64zba-invalid.s
llvm/test/MC/RISCV/rv64zba-valid.s
llvm/test/MC/RISCV/rv64zbb-aliases-valid.s
llvm/test/MC/RISCV/rv64zbb-invalid.s
llvm/test/MC/RISCV/rv64zbb-valid.s
llvm/test/MC/RISCV/rv64zbbp-invalid.s
llvm/test/MC/RISCV/rv64zbbp-valid.s
llvm/test/MC/RISCV/rv64zbs-aliases-valid.s
llvm/test/Transforms/ConstantHoisting/RISCV/immediates.ll
llvm/test/Transforms/LoopIdiom/RISCV/popcnt.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsRISCV.def 
b/clang/include/clang/Basic/BuiltinsRISCV.def
index 06560415e6861..f33b2a8349d84 100644
--- a/clang/include/clang/Basic/BuiltinsRISCV.def
+++ b/clang/include/clang/Basic/BuiltinsRISCV.def
@@ -16,13 +16,13 @@
 #endif
 
 // Zbb extension
-TARGET_BUILTIN(__builtin_riscv_orc_b_32, "ZiZi", "nc", "experimental-zbb")
-TARGET_BUILTIN(__builtin_riscv_orc_b_64, "WiWi", "nc", 
"experimental-zbb,64bit")
+TARGET_BUILTIN(__builtin_riscv_orc_b_32, "ZiZi", "nc", "zbb")
+TARGET_BUILTIN(__builtin_riscv_orc_b_64, "WiWi", "nc", "zbb,64bit")
 
 // Zbc extension
-TARGET_BUILTIN(__builtin_riscv_clmul, "LiLiLi", "nc", "experimental-zbc")
-TARGET_BUILTIN(__builtin_riscv_clmulh, "LiLiLi", "nc", "experimental-zbc")
-TARGET_BUILTIN(__builtin_riscv_clmulr, "LiLiLi", "nc", "experimental-zbc")
+TARGET_BUILTIN(__builtin_riscv_clmul, "LiLiLi", "nc", "zbc")
+TARGET_BUILTIN(__builtin_riscv_clmulh, "LiLiLi", "nc", "zbc")
+TARGET_BUILTIN(__builtin_riscv_clmulr, "LiLiLi", "nc", "zbc")
 
 // Zbe extension
 TAR

[PATCH] D117131: [RISCV] Update recently ratified Zb{a,b,c,s} extensions to no longer be experimental

2022-01-12 Thread Alex Bradbury 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 rG33d008b169f3: [RISCV] Update recently ratified Zb{a,b,c,s} 
extensions to no longer be… (authored by asb).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117131

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbc.c
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
  llvm/test/CodeGen/RISCV/addimm-mulimm.ll
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/CodeGen/RISCV/div-by-constant.ll
  llvm/test/CodeGen/RISCV/imm.ll
  llvm/test/CodeGen/RISCV/rv32zba.ll
  llvm/test/CodeGen/RISCV/rv32zbb-intrinsic.ll
  llvm/test/CodeGen/RISCV/rv32zbb-zbp.ll
  llvm/test/CodeGen/RISCV/rv32zbb.ll
  llvm/test/CodeGen/RISCV/rv32zbc-intrinsic.ll
  llvm/test/CodeGen/RISCV/rv32zbs.ll
  llvm/test/CodeGen/RISCV/rv64i-exhaustive-w-insts.ll
  llvm/test/CodeGen/RISCV/rv64zba.ll
  llvm/test/CodeGen/RISCV/rv64zbb-intrinsic.ll
  llvm/test/CodeGen/RISCV/rv64zbb-zbp.ll
  llvm/test/CodeGen/RISCV/rv64zbb.ll
  llvm/test/CodeGen/RISCV/rv64zbc-intrinsic.ll
  llvm/test/CodeGen/RISCV/rv64zbs.ll
  llvm/test/CodeGen/RISCV/rvv/fixed-vectors-store-merge-crash.ll
  llvm/test/CodeGen/RISCV/sadd_sat.ll
  llvm/test/CodeGen/RISCV/sadd_sat_plus.ll
  llvm/test/CodeGen/RISCV/selectcc-to-shiftand.ll
  llvm/test/CodeGen/RISCV/sextw-removal.ll
  llvm/test/CodeGen/RISCV/ssub_sat.ll
  llvm/test/CodeGen/RISCV/ssub_sat_plus.ll
  llvm/test/CodeGen/RISCV/uadd_sat.ll
  llvm/test/CodeGen/RISCV/uadd_sat_plus.ll
  llvm/test/CodeGen/RISCV/unfold-masked-merge-scalar-variablemask.ll
  llvm/test/CodeGen/RISCV/usub_sat.ll
  llvm/test/CodeGen/RISCV/usub_sat_plus.ll
  llvm/test/CodeGen/RISCV/xaluo.ll
  llvm/test/MC/RISCV/attribute-arch-invalid.s
  llvm/test/MC/RISCV/rv32zba-invalid.s
  llvm/test/MC/RISCV/rv32zba-valid.s
  llvm/test/MC/RISCV/rv32zbb-aliases-valid.s
  llvm/test/MC/RISCV/rv32zbb-invalid.s
  llvm/test/MC/RISCV/rv32zbb-valid.s
  llvm/test/MC/RISCV/rv32zbbp-invalid.s
  llvm/test/MC/RISCV/rv32zbbp-only-valid.s
  llvm/test/MC/RISCV/rv32zbbp-valid.s
  llvm/test/MC/RISCV/rv32zbc-invalid.s
  llvm/test/MC/RISCV/rv32zbc-valid.s
  llvm/test/MC/RISCV/rv32zbs-aliases-valid.s
  llvm/test/MC/RISCV/rv32zbs-invalid.s
  llvm/test/MC/RISCV/rv32zbs-valid.s
  llvm/test/MC/RISCV/rv64zba-aliases-valid.s
  llvm/test/MC/RISCV/rv64zba-invalid.s
  llvm/test/MC/RISCV/rv64zba-valid.s
  llvm/test/MC/RISCV/rv64zbb-aliases-valid.s
  llvm/test/MC/RISCV/rv64zbb-invalid.s
  llvm/test/MC/RISCV/rv64zbb-valid.s
  llvm/test/MC/RISCV/rv64zbbp-invalid.s
  llvm/test/MC/RISCV/rv64zbbp-valid.s
  llvm/test/MC/RISCV/rv64zbs-aliases-valid.s
  llvm/test/Transforms/ConstantHoisting/RISCV/immediates.ll
  llvm/test/Transforms/LoopIdiom/RISCV/popcnt.ll

Index: llvm/test/Transforms/LoopIdiom/RISCV/popcnt.ll
===
--- llvm/test/Transforms/LoopIdiom/RISCV/popcnt.ll
+++ llvm/test/Transforms/LoopIdiom/RISCV/popcnt.ll
@@ -1,6 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -loop-idiom -mtriple=riscv32 -mattr=+experimental-zbb -S < %s | FileCheck %s --check-prefixes=CPOP
-; RUN: opt -loop-idiom -mtriple=riscv64 -mattr=+experimental-zbb -S < %s | FileCheck %s --check-prefixes=CPOP
+; RUN: opt -loop-idiom -mtriple=riscv32 -mattr=+zbb -S < %s | FileCheck %s --check-prefixes=CPOP
+; RUN: opt -loop-idiom -mtriple=riscv64 -mattr=+zbb -S < %s | FileCheck %s --check-prefixes=CPOP
 ; RUN: opt -loop-idiom -mtriple=riscv32 -S < %s | FileCheck %s --check-prefixes=NOCPOP
 ; RUN: opt -loop-idiom -mtriple=riscv64 -S < %s | FileCheck %s --check-prefixes=NOCPOP
 
Index: llvm/test/Transforms/ConstantHoisting/RISCV/immediates.ll
===
--- llvm/test/Transforms/ConstantHoisting/RISCV/immediates.ll
+++ llvm/test/Transforms/ConstantHoisting/RISCV/immediates.ll
@@ -47,7 +47,7 @@
 }
 
 ; Check that we don't hoist zext.h with 65535 with Zbb.
-define i32 @test6(i32 %a) nounwind "target-features"="+experimental-zbb" {
+define i32 @test6(i32 %a) nounwind "target-features"="+zbb" {
 ; CHECK-LABEL: test6
 ; CHECK: and i32 %a, 65535
   %1 = and i32 %a, 65535
@@ -65,7 +65,7 @@
 }
 
 ; Check that we don't hoist zext.w with Zba.
-define i64 @test8(i64 %a) nounwind "target-features"="+experimental-zbb" {
+define i64 @test8(i64 %a) nounwind "target-features"="+zbb" {
 ; CHECK-LABEL: test8
 ; CHECK: and i64 %a, 4294967295
   %1 = and 

[PATCH] D116859: Fix for: clang-format: break added to macro define with ColumnLimit: 0

2022-01-12 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.

If the pre merge checks pass.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116859

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


[PATCH] D116859: Fix for: clang-format: break added to macro define with ColumnLimit: 0

2022-01-12 Thread Armen Khachkinaev via Phabricator via cfe-commits
futuarmo added a comment.

Yes. Looks like I understood wrong how pre-merge clang-format check works, 
thanks everyone for help


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116859

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


[PATCH] D117137: [Driver] Add a flag cuda-device-triple

2022-01-12 Thread Daniele Castagna via Phabricator via cfe-commits
dcastagna created this revision.
Herald added subscribers: dang, yaxunl.
dcastagna requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This CL adds a flag "cuda-device-triple" to clang driver that can be
used to override the triple passed to the device compilation phase.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117137

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/cuda-device-triple.cu


Index: clang/test/Driver/cuda-device-triple.cu
===
--- /dev/null
+++ clang/test/Driver/cuda-device-triple.cu
@@ -0,0 +1,8 @@
+// REQUIRES: clang-driver
+
+// RUN: %clang -### -emit-llvm --cuda-device-only \
+// RUN:   -nocudalib -nocudainc --cuda-device-triple=spirv32-unknown-unknown 
-c %s 2>&1 | FileCheck %s
+
+// CHECK: clang{{.*}}" "-cc1" "-triple" "spirv32-unknown-unknown" {{.*}} 
"-fcuda-is-device" {{.*}}
+
+
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -706,8 +706,13 @@
 const llvm::Triple &HostTriple = HostTC->getTriple();
 StringRef DeviceTripleStr;
 auto OFK = Action::OFK_Cuda;
-DeviceTripleStr =
-HostTriple.isArch64Bit() ? "nvptx64-nvidia-cuda" : "nvptx-nvidia-cuda";
+if (auto *CudaOverrideDeviceTriple =
+C.getInputArgs().getLastArg(options::OPT_cuda_device_triple)) {
+  DeviceTripleStr = CudaOverrideDeviceTriple->getValue();
+} else {
+  DeviceTripleStr =
+  HostTriple.isArch64Bit() ? "nvptx64-nvidia-cuda" : 
"nvptx-nvidia-cuda";
+}
 llvm::Triple CudaTriple(DeviceTripleStr);
 // Use the CUDA and host triples as the key into the ToolChains map,
 // because the device toolchain we create depends on both.
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -921,6 +921,8 @@
"specified more than once.">;
 def cuda_gpu_arch_EQ : Joined<["--"], "cuda-gpu-arch=">, 
Flags<[NoXarchOption]>,
   Alias;
+def cuda_device_triple: Joined<["--"], "cuda-device-triple=">,
+  HelpText<"Override the triple passed to CUDA device compilation phase">;
 def hip_link : Flag<["--"], "hip-link">,
   HelpText<"Link clang-offload-bundler bundles for HIP">;
 def no_offload_arch_EQ : Joined<["--"], "no-offload-arch=">, 
Flags<[NoXarchOption]>,


Index: clang/test/Driver/cuda-device-triple.cu
===
--- /dev/null
+++ clang/test/Driver/cuda-device-triple.cu
@@ -0,0 +1,8 @@
+// REQUIRES: clang-driver
+
+// RUN: %clang -### -emit-llvm --cuda-device-only \
+// RUN:   -nocudalib -nocudainc --cuda-device-triple=spirv32-unknown-unknown -c %s 2>&1 | FileCheck %s
+
+// CHECK: clang{{.*}}" "-cc1" "-triple" "spirv32-unknown-unknown" {{.*}} "-fcuda-is-device" {{.*}}
+
+
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -706,8 +706,13 @@
 const llvm::Triple &HostTriple = HostTC->getTriple();
 StringRef DeviceTripleStr;
 auto OFK = Action::OFK_Cuda;
-DeviceTripleStr =
-HostTriple.isArch64Bit() ? "nvptx64-nvidia-cuda" : "nvptx-nvidia-cuda";
+if (auto *CudaOverrideDeviceTriple =
+C.getInputArgs().getLastArg(options::OPT_cuda_device_triple)) {
+  DeviceTripleStr = CudaOverrideDeviceTriple->getValue();
+} else {
+  DeviceTripleStr =
+  HostTriple.isArch64Bit() ? "nvptx64-nvidia-cuda" : "nvptx-nvidia-cuda";
+}
 llvm::Triple CudaTriple(DeviceTripleStr);
 // Use the CUDA and host triples as the key into the ToolChains map,
 // because the device toolchain we create depends on both.
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -921,6 +921,8 @@
"specified more than once.">;
 def cuda_gpu_arch_EQ : Joined<["--"], "cuda-gpu-arch=">, Flags<[NoXarchOption]>,
   Alias;
+def cuda_device_triple: Joined<["--"], "cuda-device-triple=">,
+  HelpText<"Override the triple passed to CUDA device compilation phase">;
 def hip_link : Flag<["--"], "hip-link">,
   HelpText<"Link clang-offload-bundler bundles for HIP">;
 def no_offload_arch_EQ : Joined<["--"], "no-offload-arch=">, Flags<[NoXarchOption]>,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116316: [clang-format] Add an experimental option to remove optional control statement braces in LLVM C++ code

2022-01-12 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/include/clang/Format/Format.h:3059
+  /// and ``while``) in C++ according to the LLVM coding style.
+  /// \warning
+  ///  This option will be renamed and expanded to support other styles!

This should be two warning blocks.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:466
+
+bool UnwrappedLineParser::parseLevel(bool HasOpeningBrace, IfStmtKind *IfKind) 
{
+  const bool IsPrecededByCommentOrPPDirective =

This should be an enum, a bool suggests that the return value is a 
failure/success indicator.


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

https://reviews.llvm.org/D116316

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


[PATCH] D115031: [AST] Print NTTP args as string-literals when possible

2022-01-12 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 399415.
lichray added a comment.

- clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115031

Files:
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/AST/PrettyPrinter.h
  clang/include/clang/Basic/CharInfo.h
  clang/lib/AST/APValue.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/test/SemaTemplate/temp_arg_string_printing.cpp
  clang/unittests/AST/TypePrinterTest.cpp

Index: clang/unittests/AST/TypePrinterTest.cpp
===
--- clang/unittests/AST/TypePrinterTest.cpp
+++ clang/unittests/AST/TypePrinterTest.cpp
@@ -62,4 +62,35 @@
   ASSERT_TRUE(PrintedTypeMatches(
   Code, {}, Matcher, "const N::Type &",
   [](PrintingPolicy &Policy) { Policy.FullyQualifiedName = true; }));
-}
\ No newline at end of file
+}
+
+TEST(TypePrinter, TemplateIdWithNTTP) {
+  constexpr char Code[] = R"cpp(
+template 
+struct Str {
+  constexpr Str(char const (&s)[N]) { __builtin_memcpy(value, s, N); }
+  char value[N];
+};
+template  class ASCII {};
+
+ASCII<"this nontype template argument is too long to print"> x;
+  )cpp";
+  auto Matcher = classTemplateSpecializationDecl(
+  hasName("ASCII"), has(cxxConstructorDecl(
+isMoveConstructor(),
+has(parmVarDecl(hasType(qualType().bind("id")));
+
+  ASSERT_TRUE(PrintedTypeMatches(
+  Code, {"-std=c++20"}, Matcher,
+  R"(ASCII<{"this nontype template argument is [...]"}> &&)",
+  [](PrintingPolicy &Policy) {
+Policy.EntireContentsOfLargeArray = false;
+  }));
+
+  ASSERT_TRUE(PrintedTypeMatches(
+  Code, {"-std=c++20"}, Matcher,
+  R"(ASCII<{"this nontype template argument is too long to print"}> &&)",
+  [](PrintingPolicy &Policy) {
+Policy.EntireContentsOfLargeArray = true;
+  }));
+}
Index: clang/test/SemaTemplate/temp_arg_string_printing.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/temp_arg_string_printing.cpp
@@ -0,0 +1,141 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -ast-print %s | FileCheck %s
+
+using size_t = __SIZE_TYPE__;
+static_assert(__has_builtin(__make_integer_seq));
+
+template  class idx_seq {};
+template  using make_idx_seq = __make_integer_seq;
+
+template 
+struct Str {
+  constexpr Str(CharT const (&s)[N]) : Str(s, make_idx_seq()) {}
+  CharT value[N];
+
+private:
+  template 
+  constexpr Str(CharT const (&s)[N], idx_seq) : value{s[I]...} {}
+};
+
+template  class ASCII {};
+
+void not_string() {
+  // CHECK{LITERAL}: ASCII<{{9, -1, 42}}>
+  new ASCII<(int[]){9, -1, 42}>;
+  // CHECK{LITERAL}: ASCII<{{3.14e+00, 0.00e+00, 4.20e+01}}>
+  new ASCII<(double[]){3.14, 0., 42.}>;
+}
+
+void narrow() {
+  // CHECK{LITERAL}: ASCII<{""}>
+  new ASCII<"">;
+  // CHECK{LITERAL}: ASCII<{"the quick brown fox jumps"}>
+  new ASCII<"the quick brown fox jumps">;
+  // CHECK{LITERAL}: ASCII<{"OVER THE LAZY DOG 0123456789"}>
+  new ASCII<"OVER THE LAZY DOG 0123456789">;
+  // CHECK{LITERAL}: ASCII<{"\\`~!@#$%^&*()_+-={}[]|\'\";:,.<>?/"}>
+  new ASCII?/)">;
+  // CHECK{LITERAL}: ASCII<{{101, 115, 99, 97, 112, 101, 0, 0}}>
+  new ASCII<"escape\0">;
+  // CHECK{LITERAL}: ASCII<{"escape\r\n"}>
+  new ASCII<"escape\r\n">;
+  // CHECK{LITERAL}: ASCII<{"escape\\\t\f\v"}>
+  new ASCII<"escape\\\t\f\v">;
+  // CHECK{LITERAL}: ASCII<{"escape\a\bc"}>
+  new ASCII<"escape\a\b\c">;
+  // CHECK{LITERAL}: ASCII<{{110, 111, 116, 17, 0}}>
+  new ASCII<"not\x11">;
+  // CHECK{LITERAL}: ASCII<{{18, 20, 127, 16, 1, 32, 97, 98, 99, 0}}>
+  new ASCII<"\x12\x14\x7f\x10\x01 abc">;
+  // CHECK{LITERAL}: ASCII<{{18, 20, 127, 16, 1, 32, 97, 98, 99, 100, ...}}>
+  new ASCII<"\x12\x14\x7f\x10\x01 abcd">;
+  // CHECK{LITERAL}: ASCII<{"print more characters as string"}>
+  new ASCII<"print more characters as string">;
+  // CHECK{LITERAL}: ASCII<{"print even more characters as string"}>
+  new ASCII<"print even more characters as string">;
+  // CHECK{LITERAL}: ASCII<{"print many characters no more than[...]"}>
+  new ASCII<"print many characters no more than a limit">;
+  // CHECK{LITERAL}: ASCII<{"\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r"}>
+  new ASCII<"\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r">;
+  // CHECK{LITERAL}: ASCII<{"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n[...]"}>
+  new ASCII<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n">;
+}
+
+void wide() {
+  // CHECK{LITERAL}: ASCII<{L""}>
+  new ASCII;
+  // CHECK{LITERAL}: ASCII<{L"the quick brown fox jumps"}>
+  new ASCII;
+  // CHECK{LITERAL}: ASCII<{L"OVER THE LAZY DOG 0123456789"}>
+  new ASCII;
+  // CHECK{LITERAL}: ASCII<{L"\\`~!@#$%^&*()_+-={}[]

[PATCH] D117137: [Driver] Add a flag cuda-device-triple

2022-01-12 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

I think instead of setting the triple directly from the command line, we should 
start with adding another `--cuda-gpu-arch` (AKA --offload-arch)  variant and 
derive the triple and other parameters from it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117137

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


[PATCH] D117142: [clang-format] Fix short functions being considered as inline inside an indented namespace.

2022-01-12 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius created this revision.
curdeius added reviewers: MyDeveloperDay, HazardyKnusperkeks, owenpan.
curdeius requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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

With config:

  AllowShortFunctionsOnASingleLine: Inline
  NamespaceIndentation: All

The code:

  namespace Test
  {
  void f()
  {
  return;
  }
  }

was incorrectly formatted to:

  namespace Test
  {
  void f() { return; }
  }

since the function `f` was considered being inside a class/struct/record.
That's because the check was simplistic and only checked for a non-zero 
indentation level of the line starting `f`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117142

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestCSharp.cpp
  clang/unittests/Format/FormatTestJava.cpp

Index: clang/unittests/Format/FormatTestJava.cpp
===
--- clang/unittests/Format/FormatTestJava.cpp
+++ clang/unittests/Format/FormatTestJava.cpp
@@ -602,5 +602,16 @@
"}");
 }
 
+TEST_F(FormatTestJava, ShortFunctions) {
+  FormatStyle Style = getLLVMStyle(FormatStyle::LK_Java);
+  Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
+  verifyFormat("enum Enum {\n"
+   "  E1,\n"
+   "  E2;\n"
+   "  void f() { return; }\n"
+   "}",
+   Style);
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -1518,5 +1518,32 @@
Style);
 }
 
+TEST_F(FormatTestCSharp, ShortFunctions) {
+  FormatStyle Style = getLLVMStyle(FormatStyle::LK_CSharp);
+  Style.NamespaceIndentation = FormatStyle::NI_All;
+  Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
+  verifyFormat("interface Interface {\n"
+   "  void f() { return; }\n"
+   "};",
+   Style);
+  verifyFormat("public interface Interface {\n"
+   "  void f() { return; }\n"
+   "};",
+   Style);
+  verifyFormat("namespace {\n"
+   "  void f() {\n"
+   "return;\n"
+   "  }\n"
+   "};",
+   Style);
+  // "union" is not a keyword in C#.
+  verifyFormat("namespace union {\n"
+   "  void f() {\n"
+   "return;\n"
+   "  }\n"
+   "};",
+   Style);
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -3554,6 +3554,86 @@
"} // namespace out",
Style));
 
+  FormatStyle ShortInlineFunctions = getLLVMStyle();
+  ShortInlineFunctions.NamespaceIndentation = FormatStyle::NI_All;
+  ShortInlineFunctions.AllowShortFunctionsOnASingleLine =
+  FormatStyle::SFS_Inline;
+  verifyFormat("namespace {\n"
+   "  void f() {\n"
+   "return;\n"
+   "  }\n"
+   "} // namespace\n",
+   ShortInlineFunctions);
+  verifyFormat("namespace {\n"
+   "  int some_int;\n"
+   "  void f() {\n"
+   "return;\n"
+   "  }\n"
+   "} // namespace\n",
+   ShortInlineFunctions);
+  verifyFormat("namespace interface {\n"
+   "  void f() {\n"
+   "return;\n"
+   "  }\n"
+   "} // namespace interface\n",
+   ShortInlineFunctions);
+  verifyFormat("namespace {\n"
+   "  class X {\n"
+   "void f() { return; }\n"
+   "  };\n"
+   "} // namespace\n",
+   ShortInlineFunctions);
+  verifyFormat("namespace {\n"
+   "  struct X {\n"
+   "void f() { return; }\n"
+   "  };\n"
+   "} // namespace\n",
+   ShortInlineFunctions);
+  verifyFormat("namespace {\n"
+   "  union X {\n"
+   "void f() { return; }\n"
+   "  };\n"
+   "} // namespace\n",
+   ShortInlineFunctions);
+  verifyFormat("extern \"C\" {\n"
+   "void f() {\n"
+   "  return;\n"
+   "}\n"
+   "} // namespace\n",
+   ShortInlineFunctions);
+  verifyFormat("namespace {\n"
+   "  class X {\n"
+   "void f() { return; }\n"
+   "  } x;\n"
+   "} // namespace\n",
+   ShortInli

[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2022-01-12 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:687
   // TODO: This has been removed in later specs, which specify that D implies F
   if (HasD && !HasF)
 return createStringError(errc::invalid_argument,

Do we need the equivalent of this for Zfinx and Zdinx?



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoD.td:228
 
+let Predicates = [HasStdExtZdinx] in {
+def : InstAlias<"fabs.d $rd, $rs", (FSGNJX_D_INX FPR64INX:$rd, FPR64INX:$rs, 
FPR64INX:$rs)>;

Don't we need IN32X aliases too?



Comment at: llvm/lib/Target/RISCV/RISCVRegisterInfo.td:552
+
+def GPRF16 : RegisterClass<"RISCV", [f16], 16, (add
+(sequence "X%u", 10, 17),

Is possible to reference GPR here to avoid listing the allocation order again? 
Similar to how GPRNoX0 does (sub GPR, X0). Not sure if there is a way to be 
exactly another list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93298

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


[PATCH] D117142: [clang-format] Fix short functions being considered as inline inside an indented namespace.

2022-01-12 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

Still WIP but I'd like to have some feedback.




Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:283
+
+  // FIXME: Use IndentTracker to avoid loop?
+  // Find the last line with lower level.

Because of this I consider this patch as a WIP still.
I'm all ears if anyone has an idea how to efficiently find the "parent" line of 
the current one, i.e. a line with level smaller by one.
There are places where we use a stack for similar purposes. I'm not sure if 
there's already something existing I could use.

As a last resort, I'll add a stack of Lines that start a new level in 
`LevelIndentTracker` and update it in `nextLine()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117142

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


[PATCH] D117142: [clang-format] Fix short functions being considered as inline inside an indented namespace.

2022-01-12 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added inline comments.



Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:278
+// Just checking TheLine->Level != 0 is not enough, because it
+// provokes treating functions inside intended namespaces as short.
+if ((*I)->Level != 0) {

TODO: typo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117142

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


[PATCH] D116425: [clang-tidy] Improve modernize-redundant-void-arg to recognize macro uses

2022-01-12 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, thanks!


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

https://reviews.llvm.org/D116425

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


[PATCH] D116859: [clang-format] Fix break being added to macro define with ColumnLimit: 0

2022-01-12 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.

LGTM. Thanks for working on this!
But before landing, please retest the original misformatted code from the bug 
report with a freshly built clang-format.

Also, do you have commit rights? If not, do you want someone to land it on your 
behalf? If so, please send your name and email address to be used for the 
contribution.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116859

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


[PATCH] D116518: [ast-matchers] Add hasSubstatementSequence matcher

2022-01-12 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood added a comment.

In D116518#3237927 , @ymandel wrote:

> [...] In the meantime, I'll note that we have something similar internally
> which I never got around to upstreaming.

That's very interesting and is certainly more general than what I have
which is just scratching my own immediate itch.  I got lost in the variadic
functor/matcher infrastructure last night when I tried to reverse engineer
it to try and generalize what I had.

> That said, my experience indicates that once you're thinking in terms
> of sequences, you're probably going to find that you want to match
> over the CFG, rather than the AST directly.

Is there any tooling for matching the CFG currently?  I haven't come across
it but the code base is large and there's lots of stuff I haven't personally
browsed.


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

https://reviews.llvm.org/D116518

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


[clang-tools-extra] fff59f4 - [clang-tidy] Improve modernize-redundant-void-arg to recognize macro uses

2022-01-12 Thread via cfe-commits

Author: Richard
Date: 2022-01-12T13:51:50-07:00
New Revision: fff59f48173dc2f2a3ce867fa0c7836b23214110

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

LOG: [clang-tidy] Improve modernize-redundant-void-arg to recognize macro uses

Sometimes a macro invocation will look like an argument list
declaration.  Improve the check to detect this situation and not
try to modify the macro invocation.

Thanks to Nathan James for the fix.

- Ignore implicit typedefs (e.g. compiler builtins)
- Improve lexing state machine to locate void argument tokens
- Add additional return_t() macro tests
- clang-format control in the test case file
- remove braces around single statements per LLVM style guide

Fixes #43791

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize-redundant-void-arg.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
index 3214ae84b74de..4f791d404d9da 100644
--- a/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -20,15 +20,12 @@ namespace {
 
 // Determine if the given QualType is a nullary function or pointer to same.
 bool protoTypeHasNoParms(QualType QT) {
-  if (const auto *PT = QT->getAs()) {
+  if (const auto *PT = QT->getAs())
 QT = PT->getPointeeType();
-  }
-  if (auto *MPT = QT->getAs()) {
+  if (auto *MPT = QT->getAs())
 QT = MPT->getPointeeType();
-  }
-  if (const auto *FP = QT->getAs()) {
+  if (const auto *FP = QT->getAs())
 return FP->getNumParams() == 0;
-  }
   return false;
 }
 
@@ -48,7 +45,8 @@ void RedundantVoidArgCheck::registerMatchers(MatchFinder 
*Finder) {
   unless(isInstantiated()), 
unless(isExternC()))
  .bind(FunctionId),
  this);
-  Finder->addMatcher(typedefNameDecl().bind(TypedefId), this);
+  Finder->addMatcher(typedefNameDecl(unless(isImplicit())).bind(TypedefId),
+ this);
   auto ParenFunctionType = parenType(innerType(functionType()));
   auto PointerToFunctionType = pointee(ParenFunctionType);
   auto FunctionOrMemberPointer =
@@ -72,34 +70,36 @@ void RedundantVoidArgCheck::registerMatchers(MatchFinder 
*Finder) {
 
 void RedundantVoidArgCheck::check(const MatchFinder::MatchResult &Result) {
   const BoundNodes &Nodes = Result.Nodes;
-  if (const auto *Function = Nodes.getNodeAs(FunctionId)) {
+  if (const auto *Function = Nodes.getNodeAs(FunctionId))
 processFunctionDecl(Result, Function);
-  } else if (const auto *TypedefName =
- Nodes.getNodeAs(TypedefId)) {
+  else if (const auto *TypedefName =
+   Nodes.getNodeAs(TypedefId))
 processTypedefNameDecl(Result, TypedefName);
-  } else if (const auto *Member = Nodes.getNodeAs(FieldId)) {
+  else if (const auto *Member = Nodes.getNodeAs(FieldId))
 processFieldDecl(Result, Member);
-  } else if (const auto *Var = Nodes.getNodeAs(VarId)) {
+  else if (const auto *Var = Nodes.getNodeAs(VarId))
 processVarDecl(Result, Var);
-  } else if (const auto *NamedCast =
- Nodes.getNodeAs(NamedCastId)) {
+  else if (const auto *NamedCast =
+   Nodes.getNodeAs(NamedCastId))
 processNamedCastExpr(Result, NamedCast);
-  } else if (const auto *CStyleCast =
- Nodes.getNodeAs(CStyleCastId)) {
+  else if (const auto *CStyleCast =
+   Nodes.getNodeAs(CStyleCastId))
 processExplicitCastExpr(Result, CStyleCast);
-  } else if (const auto *ExplicitCast =
- Nodes.getNodeAs(ExplicitCastId)) {
+  else if (const auto *ExplicitCast =
+   Nodes.getNodeAs(ExplicitCastId))
 processExplicitCastExpr(Result, ExplicitCast);
-  } else if (const auto *Lambda = Nodes.getNodeAs(LambdaId)) {
+  else if (const auto *Lambda = Nodes.getNodeAs(LambdaId))
 processLambdaExpr(Result, Lambda);
-  }
 }
 
 void RedundantVoidArgCheck::processFunctionDecl(
 const MatchFinder::MatchResult &Result, const FunctionDecl *Function) {
+  const auto *Method = dyn_cast(Function);
+  SourceLocation Start = Method && Method->getParent()->isLambda()
+ ? Method->getBeginLoc()
+ : Function->getLocation();
+  SourceLocation End = Function->getEndLoc();
   if (Function->isThisDeclarationADefinition()) {
-SourceLocation Start = Function->getBeginLoc();
-SourceLocation End = Function->getEndLoc();
 if (const Stmt *Body = Function->getBody()) {
   End = Body->getBeginLoc();
   if (End.isMa

[PATCH] D116425: [clang-tidy] Improve modernize-redundant-void-arg to recognize macro uses

2022-01-12 Thread Richard via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfff59f48173d: [clang-tidy] Improve 
modernize-redundant-void-arg to recognize macro uses (authored by 
LegalizeAdulthood).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116425

Files:
  clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-redundant-void-arg.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-redundant-void-arg.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-redundant-void-arg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-redundant-void-arg.cpp
@@ -199,6 +199,7 @@
 // CHECK-FIXES-NEXT: {{^\);$}}
 
 // intentionally not LLVM style to check preservation of whitespace
+// clang-format off
 typedef
 void
 (
@@ -240,7 +241,7 @@
 // CHECK-FIXES-NOT:  {{[^ ]}}
 // CHECK-FIXES:  {{^\)$}}
 // CHECK-FIXES-NEXT: {{^;$}}
-
+// clang-format on
 
 void (gronk::*p1)(void);
 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: {{.*}} in variable declaration
@@ -556,3 +557,38 @@
   S_3();
   g_3();
 }
+
+#define return_t(T) T
+extern return_t(void) func(void);
+// CHECK-MESSAGES: :[[@LINE-1]]:28: warning: redundant void argument list in function declaration
+// CHECK-FIXES: extern return_t(void) func();
+
+return_t(void) func(void) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: redundant void argument list in function definition
+  // CHECK-FIXES: return_t(void) func() {
+  int a;
+  (void)a;
+}
+
+extern return_t(void) func(return_t(void) (*fp)(void));
+// CHECK-MESSAGES: :[[@LINE-1]]:49: warning: redundant void argument list in variable declaration
+// CHECK-FIXES: extern return_t(void) func(return_t(void) (*fp)());
+
+return_t(void) func(return_t(void) (*fp)(void)) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: redundant void argument list in variable declaration
+  // CHECK-FIXES: return_t(void) func(return_t(void) (*fp)()) {
+  int a;
+  (void)a;
+}
+
+extern return_t(return_t(void)) func2(return_t(return_t(void)) (*fp)(void));
+// CHECK-MESSAGES: :[[@LINE-1]]:70: warning: redundant void argument list in variable declaration
+// CHECK-FIXES: extern return_t(return_t(void)) func2(return_t(return_t(void)) (*fp)());
+
+return_t(return_t(void)) func2(return_t(return_t(void)) (*fp)(void)) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:63: warning: redundant void argument list in variable declaration
+  // CHECK-FIXES: return_t(return_t(void)) func2(return_t(return_t(void)) (*fp)()) {
+  int a;
+  (void)a;
+}
+#undef return_t
Index: clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -20,15 +20,12 @@
 
 // Determine if the given QualType is a nullary function or pointer to same.
 bool protoTypeHasNoParms(QualType QT) {
-  if (const auto *PT = QT->getAs()) {
+  if (const auto *PT = QT->getAs())
 QT = PT->getPointeeType();
-  }
-  if (auto *MPT = QT->getAs()) {
+  if (auto *MPT = QT->getAs())
 QT = MPT->getPointeeType();
-  }
-  if (const auto *FP = QT->getAs()) {
+  if (const auto *FP = QT->getAs())
 return FP->getNumParams() == 0;
-  }
   return false;
 }
 
@@ -48,7 +45,8 @@
   unless(isInstantiated()), unless(isExternC()))
  .bind(FunctionId),
  this);
-  Finder->addMatcher(typedefNameDecl().bind(TypedefId), this);
+  Finder->addMatcher(typedefNameDecl(unless(isImplicit())).bind(TypedefId),
+ this);
   auto ParenFunctionType = parenType(innerType(functionType()));
   auto PointerToFunctionType = pointee(ParenFunctionType);
   auto FunctionOrMemberPointer =
@@ -72,34 +70,36 @@
 
 void RedundantVoidArgCheck::check(const MatchFinder::MatchResult &Result) {
   const BoundNodes &Nodes = Result.Nodes;
-  if (const auto *Function = Nodes.getNodeAs(FunctionId)) {
+  if (const auto *Function = Nodes.getNodeAs(FunctionId))
 processFunctionDecl(Result, Function);
-  } else if (const auto *TypedefName =
- Nodes.getNodeAs(TypedefId)) {
+  else if (const auto *TypedefName =
+   Nodes.getNodeAs(TypedefId))
 processTypedefNameDecl(Result, TypedefName);
-  } else if (const auto *Member = Nodes.getNodeAs(FieldId)) {
+  else if (const auto *Member = Nodes.getNodeAs(FieldId))
 processFieldDecl(Result, Member);
-  } else if (const auto *Var = Nodes.getNodeAs(VarId)) {
+  else if (const auto *Var = Nodes.getNodeAs(VarId))
 processVarDecl(Result, Var);
-  } else if (const auto *NamedCast =
- Nodes.getNodeAs(NamedCastId)) {
+  else if (const auto *NamedCast =
+   Nodes.getNodeAs(NamedCastId)

[PATCH] D117093: [C++20] [Modules] Exit early if export decl is invalid

2022-01-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaModule.cpp:530-531
 
+  CurContext->addDecl(D);
+  PushDeclContext(S, D);
+

Am I understanding properly that this moved up here so that the for loop on 
line 553 can traverse the new context?

If so, can it be moved down to immediately before the for loop?



Comment at: clang/lib/Sema/SemaModule.cpp:539-550
+return D;
   } else if (!ModuleScopes.back().ModuleInterface) {
 Diag(ExportLoc, diag::err_export_not_in_module_interface) << 1;
 Diag(ModuleScopes.back().BeginLoc,
  diag::note_not_module_interface_add_export)
 << FixItHint::CreateInsertion(ModuleScopes.back().BeginLoc, "export ");
+return D;

It seems a bit suspicious to me that we call `D->getInvalidDecl()` below within 
the for loop, but all the other places we leave it as a valid declaration 
despite it causing error diagnostics.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117093

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


[PATCH] D116859: [clang-format] Fix break being added to macro define with ColumnLimit: 0

2022-01-12 Thread Armen Khachkinaev via Phabricator via cfe-commits
futuarmo added a comment.

I will build fresh main branch tomorrow (it tooks 1+ hour) and will comment 
here about test results
I don't have commit rights, so it will be great if someone commit it with user 
"Armen Khachkinaev" and email "armen...@yandex.ru"
Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116859

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


[PATCH] D117078: Minor adjustment in order of noundef analysis to be a bit more optimal (when disabled).

2022-01-12 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added a comment.
This revision is now accepted and ready to land.

my editor recommends me to keep git titles <50 chars
Maybe something shorter with exactly the same meaning
"[NFC] Optimize noundef analysis condition"




Comment at: clang/lib/CodeGen/CGCall.cpp:2380-2381
 // Decide whether the argument we're handling could be partially undef
-bool ArgNoUndef = DetermineNoUndef(ParamType, getTypes(), DL, AI);
-if (CodeGenOpts.EnableNoundefAttrs && ArgNoUndef)
-  Attrs.addAttribute(llvm::Attribute::NoUndef);
+if (CodeGenOpts.EnableNoundefAttrs) {
+  if (DetermineNoUndef(ParamType, getTypes(), DL, AI))
+Attrs.addAttribute(llvm::Attribute::NoUndef);




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117078

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


[PATCH] D117129: [clang-tidy] Extract Class IncluderClangTidyCheck

2022-01-12 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

Overall, this change looks good and makes sense. But, it doesn't scale past 1 
feature, which makes me a bit hesitant. I don't have another example offhand, 
but include-inserter is an arbitrary feature and I don't love conflating 
feature addition with the class hierarchy. Might there be some other way to get 
the benefits of saving implementers the cut and paste (and bug-prone code that 
comes with it) without changing the class hierarchy?




Comment at: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h:13
+#include "IncluderClangTidyCheck.h"
 #include "IncludeSorter.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"

can you delete this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117129

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


[clang] d102197 - Omit "clang" from CHECK lines.

2022-01-12 Thread James Y Knight via cfe-commits

Author: James Y Knight
Date: 2022-01-12T21:18:52Z
New Revision: d1021978b8e7e35dcc30201ca1731d64b5a602a8

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

LOG: Omit "clang" from CHECK lines.

This avoids spurious failures in some environemnts.
Similar change to eafc64ed6325eba962096d4a947d7e45e909bfde.

Added: 


Modified: 
clang/test/Driver/spirv-toolchain.cl

Removed: 




diff  --git a/clang/test/Driver/spirv-toolchain.cl 
b/clang/test/Driver/spirv-toolchain.cl
index 5c95a57488426..7f50ed89cb127 100644
--- a/clang/test/Driver/spirv-toolchain.cl
+++ b/clang/test/Driver/spirv-toolchain.cl
@@ -62,10 +62,10 @@
 // Check linking when multiple input files are passed.
 // RUN: %clang -### -target spirv64 %s %s 2>&1 | FileCheck 
--check-prefix=SPLINK %s
 
-// SPLINK: clang{{.*}} "-cc1" "-triple" "spirv64"
+// SPLINK: "-cc1" "-triple" "spirv64"
 // SPLINK-SAME: "-o" [[BC:".*bc"]]
 // SPLINK: {{llvm-spirv.*"}} [[BC]] "-o" [[SPV1:".*o"]]
-// SPLINK: clang{{.*}} "-cc1" "-triple" "spirv64"
+// SPLINK: "-cc1" "-triple" "spirv64"
 // SPLINK-SAME: "-o" [[BC:".*bc"]]
 // SPLINK: {{llvm-spirv.*"}} [[BC]] "-o" [[SPV2:".*o"]]
 // SPLINK: {{spirv-link.*"}} [[SPV1]] [[SPV2]] "-o" "a.out"



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


[PATCH] D117129: [clang-tidy] Extract Class IncluderClangTidyCheck

2022-01-12 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood added a comment.

In D117129#3238433 , @ymandel wrote:

> Overall, this change looks good and makes sense. But, it doesn't scale past 1 
> feature
> [...] Might there be some other way to get the benefits of saving 
> implementers the
> cut and paste (and bug-prone code that comes with it) without changing the 
> class
> hierarchy?

Maybe some sort of mix-in approach or "implementation inheritance" as they say?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117129

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


[PATCH] D117129: [clang-tidy] Extract Class IncluderClangTidyCheck

2022-01-12 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood added a comment.

Another option would be to migrate this to `ClangTidyCheck` itself
and add a flag/option passed to the ClangTidyCheck c'tor to opt-in
to the feature?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117129

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


[PATCH] D117078: [NFC] Minimize noundef analysis when disabled

2022-01-12 Thread Kevin Athey via Phabricator via cfe-commits
kda updated this revision to Diff 399432.
kda marked an inline comment as done.
kda added a comment.

reduce nesting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117078

Files:
  clang/lib/CodeGen/CGCall.cpp


Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2377,9 +2377,9 @@
 }
 
 // Decide whether the argument we're handling could be partially undef
-if (CodeGenOpts.EnableNoundefAttrs) {
-  if (DetermineNoUndef(ParamType, getTypes(), DL, AI))
-Attrs.addAttribute(llvm::Attribute::NoUndef);
+if (CodeGenOpts.EnableNoundefAttrs &&
+DetermineNoUndef(ParamType, getTypes(), DL, AI)) {
+  Attrs.addAttribute(llvm::Attribute::NoUndef);
 }
 
 // 'restrict' -> 'noalias' is done in EmitFunctionProlog when we


Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2377,9 +2377,9 @@
 }
 
 // Decide whether the argument we're handling could be partially undef
-if (CodeGenOpts.EnableNoundefAttrs) {
-  if (DetermineNoUndef(ParamType, getTypes(), DL, AI))
-Attrs.addAttribute(llvm::Attribute::NoUndef);
+if (CodeGenOpts.EnableNoundefAttrs &&
+DetermineNoUndef(ParamType, getTypes(), DL, AI)) {
+  Attrs.addAttribute(llvm::Attribute::NoUndef);
 }
 
 // 'restrict' -> 'noalias' is done in EmitFunctionProlog when we
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D117078: [NFC] Minimize noundef analysis when disabled

2022-01-12 Thread Kevin Athey via Phabricator via cfe-commits
kda added a comment.

In D117078#3238422 , @vitalybuka 
wrote:

> my editor recommends me to keep git titles <50 chars
> Maybe something shorter with exactly the same meaning
> "[NFC] Optimize noundef analysis condition"

Done!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117078

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


[PATCH] D115031: [AST] Print NTTP args as string-literals when possible

2022-01-12 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 399433.
lichray added a comment.

  Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115031

Files:
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/AST/PrettyPrinter.h
  clang/include/clang/Basic/CharInfo.h
  clang/lib/AST/APValue.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/test/SemaTemplate/temp_arg_string_printing.cpp
  clang/unittests/AST/TypePrinterTest.cpp

Index: clang/unittests/AST/TypePrinterTest.cpp
===
--- clang/unittests/AST/TypePrinterTest.cpp
+++ clang/unittests/AST/TypePrinterTest.cpp
@@ -62,4 +62,35 @@
   ASSERT_TRUE(PrintedTypeMatches(
   Code, {}, Matcher, "const N::Type &",
   [](PrintingPolicy &Policy) { Policy.FullyQualifiedName = true; }));
-}
\ No newline at end of file
+}
+
+TEST(TypePrinter, TemplateIdWithNTTP) {
+  constexpr char Code[] = R"cpp(
+template 
+struct Str {
+  constexpr Str(char const (&s)[N]) { __builtin_memcpy(value, s, N); }
+  char value[N];
+};
+template  class ASCII {};
+
+ASCII<"this nontype template argument is too long to print"> x;
+  )cpp";
+  auto Matcher = classTemplateSpecializationDecl(
+  hasName("ASCII"), has(cxxConstructorDecl(
+isMoveConstructor(),
+has(parmVarDecl(hasType(qualType().bind("id")));
+
+  ASSERT_TRUE(PrintedTypeMatches(
+  Code, {"-std=c++20"}, Matcher,
+  R"(ASCII<{"this nontype template argument is [...]"}> &&)",
+  [](PrintingPolicy &Policy) {
+Policy.EntireContentsOfLargeArray = false;
+  }));
+
+  ASSERT_TRUE(PrintedTypeMatches(
+  Code, {"-std=c++20"}, Matcher,
+  R"(ASCII<{"this nontype template argument is too long to print"}> &&)",
+  [](PrintingPolicy &Policy) {
+Policy.EntireContentsOfLargeArray = true;
+  }));
+}
Index: clang/test/SemaTemplate/temp_arg_string_printing.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/temp_arg_string_printing.cpp
@@ -0,0 +1,141 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -ast-print %s | FileCheck %s
+
+using size_t = __SIZE_TYPE__;
+static_assert(__has_builtin(__make_integer_seq));
+
+template  class idx_seq {};
+template  using make_idx_seq = __make_integer_seq;
+
+template 
+struct Str {
+  constexpr Str(CharT const (&s)[N]) : Str(s, make_idx_seq()) {}
+  CharT value[N];
+
+private:
+  template 
+  constexpr Str(CharT const (&s)[N], idx_seq) : value{s[I]...} {}
+};
+
+template  class ASCII {};
+
+void not_string() {
+  // CHECK{LITERAL}: ASCII<{{9, -1, 42}}>
+  new ASCII<(int[]){9, -1, 42}>;
+  // CHECK{LITERAL}: ASCII<{{3.14e+00, 0.00e+00, 4.20e+01}}>
+  new ASCII<(double[]){3.14, 0., 42.}>;
+}
+
+void narrow() {
+  // CHECK{LITERAL}: ASCII<{""}>
+  new ASCII<"">;
+  // CHECK{LITERAL}: ASCII<{"the quick brown fox jumps"}>
+  new ASCII<"the quick brown fox jumps">;
+  // CHECK{LITERAL}: ASCII<{"OVER THE LAZY DOG 0123456789"}>
+  new ASCII<"OVER THE LAZY DOG 0123456789">;
+  // CHECK{LITERAL}: ASCII<{"\\`~!@#$%^&*()_+-={}[]|\'\";:,.<>?/"}>
+  new ASCII?/)">;
+  // CHECK{LITERAL}: ASCII<{{101, 115, 99, 97, 112, 101, 0, 0}}>
+  new ASCII<"escape\0">;
+  // CHECK{LITERAL}: ASCII<{"escape\r\n"}>
+  new ASCII<"escape\r\n">;
+  // CHECK{LITERAL}: ASCII<{"escape\\\t\f\v"}>
+  new ASCII<"escape\\\t\f\v">;
+  // CHECK{LITERAL}: ASCII<{"escape\a\bc"}>
+  new ASCII<"escape\a\b\c">;
+  // CHECK{LITERAL}: ASCII<{{110, 111, 116, 17, 0}}>
+  new ASCII<"not\x11">;
+  // CHECK{LITERAL}: ASCII<{{18, 20, 127, 16, 1, 32, 97, 98, 99, 0}}>
+  new ASCII<"\x12\x14\x7f\x10\x01 abc">;
+  // CHECK{LITERAL}: ASCII<{{18, 20, 127, 16, 1, 32, 97, 98, 99, 100, ...}}>
+  new ASCII<"\x12\x14\x7f\x10\x01 abcd">;
+  // CHECK{LITERAL}: ASCII<{"print more characters as string"}>
+  new ASCII<"print more characters as string">;
+  // CHECK{LITERAL}: ASCII<{"print even more characters as string"}>
+  new ASCII<"print even more characters as string">;
+  // CHECK{LITERAL}: ASCII<{"print many characters no more than[...]"}>
+  new ASCII<"print many characters no more than a limit">;
+  // CHECK{LITERAL}: ASCII<{"\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r"}>
+  new ASCII<"\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r">;
+  // CHECK{LITERAL}: ASCII<{"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n[...]"}>
+  new ASCII<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n">;
+}
+
+void wide() {
+  // CHECK{LITERAL}: ASCII<{L""}>
+  new ASCII;
+  // CHECK{LITERAL}: ASCII<{L"the quick brown fox jumps"}>
+  new ASCII;
+  // CHECK{LITERAL}: ASCII<{L"OVER THE LAZY DOG 0123456789"}>
+  new ASCII;
+  // CHECK{LITERAL}: ASCII<{L"\\`~!@#$%^&*()_+-={}[]|\'\";

[PATCH] D117123: [clang][dataflow] Add transfer functions for initializers

2022-01-12 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev marked an inline comment as done.
sgatev added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:171
+
+Value *InitExprVal = Env.getValue(*InitExpr, SkipPast::None);
+if (InitExprVal == nullptr)

ymandel wrote:
> why `None`? Is the idea that if the expression generates a reference, we want 
> to get the pointer value, not the pointee?
> So, in the example below, the value set for field `y` will (correctly) be the 
> same pointer stored in field `x`?
> ```
> struct A {
>   int &x;
>   int &y = x;
> };
> ```
Right, `y` gets assigned the same `ReferenceValue` as `x` in this case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117123

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


[PATCH] D115121: Update bugprone-stringview-nullptr to support return statements and constructors for any T which accepts basic_string_view

2022-01-12 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added a comment.
This revision is now accepted and ready to land.

Bravo!  This is an impressively thorough job. Thanks for pushing through to 
completion!




Comment at: clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp:263
+  auto HandleConstructorInvocation =
+  makeRule(cxxConstructExpr(hasAnyArgument(ignoringImpCasts(
+BasicStringViewConstructingFromNullExpr)),

precede with `argumentCountIs(1)`? Also, please comment on choice of 
`hasAnyArgument` (copying what you wrote in the patch description is fine).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115121

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


[PATCH] D117129: [clang-tidy] Extract Class IncluderClangTidyCheck

2022-01-12 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

In D117129#3238441 , 
@LegalizeAdulthood wrote:

> Another option would be to migrate this to `ClangTidyCheck` itself
> and add a flag/option passed to the ClangTidyCheck c'tor to opt-in
> to the feature?

Right, I was wondering about this. The feature is pretty core to handling C++ 
files and widely used, so it may warrant that. But, I don't know who the right 
reviewers are to ask about making changes to the `ClangTidyCheck` class.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117129

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


[PATCH] D115121: Update bugprone-stringview-nullptr to support return statements and constructors for any T which accepts basic_string_view

2022-01-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 399436.
CJ-Johnson marked an inline comment as done.
CJ-Johnson added a comment.

Add code comment about the choice of hasAnyArgument


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115121

Files:
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -16,78 +16,116 @@
 template 
 class basic_string_view {
 public:
-  basic_string_view();
+  constexpr basic_string_view() {}
 
-  basic_string_view(const CharT *);
+  constexpr basic_string_view(const CharT *) {}
 
   // Not present in C++17 and C++20:
-  // basic_string_view(std::nullptr_t);
+  // constexpr basic_string_view(std::nullptr_t) {}
 
-  basic_string_view(const CharT *, size_t);
+  constexpr basic_string_view(const CharT *, size_t) {}
 
-  basic_string_view(const basic_string_view &);
+  constexpr basic_string_view(const basic_string_view &) {}
 
-  basic_string_view &operator=(const basic_string_view &);
+  constexpr basic_string_view &operator=(const basic_string_view &) {}
 };
 
 template 
-bool operator<(basic_string_view, basic_string_view);
+constexpr bool operator<(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<(type_identity_t>,
-   basic_string_view);
+constexpr bool operator<(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator<(basic_string_view,
-   type_identity_t>);
+constexpr bool operator<(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator<=(basic_string_view, basic_string_view);
+constexpr bool operator<=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(type_identity_t>,
-basic_string_view);
+constexpr bool operator<=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(basic_string_view,
-type_identity_t>);
+constexpr bool operator<=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>(basic_string_view, basic_string_view);
+constexpr bool operator>(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator>(type_identity_t>,
-   basic_string_view);
+constexpr bool operator>(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator>(basic_string_view,
-   type_identity_t>);
+constexpr bool operator>(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>=(basic_string_view, basic_string_view);
+constexpr bool operator>=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator>=(type_identity_t>,
-basic_string_view);
+constexpr bool operator>=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator>=(basic_string_view,
-type_identity_t>);
+constexpr bool operator>=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator==(basic_string_view, basic_string_view);
+constexpr bool operator==(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator==(type_identity_t>,
-basic_string_view);
+constexpr bool operator==(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator==(basic_string_view,
-type_identity_t>);
+constexpr bool operator==(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator!=(basic_string_view, basic_string_view);
+constexpr bool operator!=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(type_identity_t>,
-basic_string_view);
+constexpr bool operator!=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(basic_string_view,
-type_identity_t>);
+constexpr bool operator!=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 using string_view = basic_string_view;
 
 } // namespace std
 
+using SV = std::string_view; // Used in some places for shorter line length
+
 void function(std::string_view);
 void function(std::string_view, std::string_view);
 
@@ -200,19 +238,19 @@
   // Static Cast
   {
 (void)(static_cast(nu

[PATCH] D115121: Update bugprone-stringview-nullptr to support return statements and constructors for any T which accepts basic_string_view

2022-01-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp:263
+  auto HandleConstructorInvocation =
+  makeRule(cxxConstructExpr(hasAnyArgument(ignoringImpCasts(
+BasicStringViewConstructingFromNullExpr)),

ymandel wrote:
> precede with `argumentCountIs(1)`? Also, please comment on choice of 
> `hasAnyArgument` (copying what you wrote in the patch description is fine).
Added the code comments, but not the argument count matcher. This case 
intentionally matches any number of arguments since some types make take 2+ 
parameters where one of them is string_view.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115121

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


[clang] 963f400 - [clang][dataflow] Add transfer functions for initializers

2022-01-12 Thread Stanislav Gatev via cfe-commits

Author: Stanislav Gatev
Date: 2022-01-12T21:51:39Z
New Revision: 963f40051a4216936b47dad56765d60b64b7840d

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

LOG: [clang][dataflow] Add transfer functions for initializers

This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.

Reviewed-by: ymandel, xazax.hun

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

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp 
b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
index a1817687bd68e..3ad2ed640cc1c 100644
--- a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
@@ -49,6 +49,7 @@ ControlFlowContext::build(const Decl *D, Stmt *S, ASTContext 
*C) {
   Options.AddImplicitDtors = true;
   Options.AddTemporaryDtors = true;
   Options.AddInitializers = true;
+  Options.AddCXXDefaultInitExprInCtors = true;
 
   // Ensure that all sub-expressions in basic blocks are evaluated.
   Options.setAllAlwaysAdd();

diff  --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index f28271101b9c1..7681b729d2b8e 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -164,6 +164,23 @@ class TransferVisitor : public 
ConstStmtVisitor {
 }
   }
 
+  void VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
+const Expr *InitExpr = S->getExpr();
+assert(InitExpr != nullptr);
+
+Value *InitExprVal = Env.getValue(*InitExpr, SkipPast::None);
+if (InitExprVal == nullptr)
+  return;
+
+const FieldDecl *Field = S->getField();
+assert(Field != nullptr);
+
+auto &ThisLoc =
+*cast(Env.getThisPointeeStorageLocation());
+auto &FieldLoc = ThisLoc.getChild(*Field);
+Env.setValue(FieldLoc, *InitExprVal);
+  }
+
   // FIXME: Add support for:
   // - CallExpr
   // - CXXBindTemporaryExpr

diff  --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 0d7f3b31e6c48..722b24f5b9718 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -11,15 +11,18 @@
 //
 
//===--===//
 
+#include 
 #include 
 #include 
 
+#include "clang/AST/DeclCXX.h"
 #include "clang/Analysis/Analyses/PostOrderCFGView.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/DataflowWorklist.h"
 #include "clang/Analysis/FlowSensitive/Transfer.h"
 #include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"
+#include "clang/Analysis/FlowSensitive/Value.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/Support/raw_ostream.h"
@@ -103,6 +106,60 @@ static TypeErasedDataflowAnalysisState 
computeBlockInputState(
   return *MaybeState;
 }
 
+/// Transfers `State` by evaluating `CfgStmt` in the context of `Analysis`.
+/// `HandleTransferredStmt` (if provided) will be applied to `CfgStmt`, after 
it
+/// is evaluated.
+static void
+transferCFGStmt(const CFGStmt &CfgStmt, TypeErasedDataflowAnalysis &Analysis,
+TypeErasedDataflowAnalysisState &State,
+std::function
+HandleTransferredStmt) {
+  const Stmt *S = CfgStmt.getStmt();
+  assert(S != nullptr);
+
+  transfer(*S, State.Env);
+  Analysis.transferTypeErased(S, State.Lattice, State.Env);
+
+  if (HandleTransferredStmt != nullptr)
+HandleTransferredStmt(CfgStmt, State);
+}
+
+/// Transfers `State` by evaluating `CfgInit`.
+static void transferCFGInitializer(const CFGInitializer &CfgInit,
+   TypeErasedDataflowAnalysisState &State) {
+  const auto &ThisLoc = *cast(
+  State.Env.getThisPointeeStorageLocation());
+
+  const CXXCtorInitializer *Initializer = CfgInit.getInitializer();
+  assert(Initializer != nullptr);
+
+  auto *InitStmt = Initializer->getInit();
+  assert(InitStmt != nullptr);
+
+  auto *InitStmtLoc =
+  State.Env.getStorageLocation(*InitStmt, SkipPast::Reference);
+  if (InitStmtLoc == nullptr)
+return;
+
+  auto *InitStmtVal = State.Env.getValue(*InitStmtLoc);
+  if (InitStmtVal == nullptr)
+return;
+
+  const FieldDecl *Member = I

[PATCH] D117123: [clang][dataflow] Add transfer functions for initializers

2022-01-12 Thread Stanislav Gatev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
sgatev marked an inline comment as done.
Closed by commit rG963f40051a42: [clang][dataflow] Add transfer functions for 
initializers (authored by sgatev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117123

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

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1171,4 +1171,114 @@
   });
 }
 
+TEST_F(TransferTest, ConstructorInitializer) {
+  std::string Code = R"(
+struct target {
+  int Bar;
+
+  target(int Foo) : Bar(Foo) {
+int Qux = Bar;
+// [[p]]
+  }
+};
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const auto *ThisLoc = dyn_cast(
+Env.getThisPointeeStorageLocation());
+ASSERT_THAT(ThisLoc, NotNull());
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const auto *FooVal =
+cast(Env.getValue(*FooDecl, SkipPast::None));
+
+const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ASSERT_THAT(QuxDecl, NotNull());
+EXPECT_EQ(Env.getValue(*QuxDecl, SkipPast::None), FooVal);
+  });
+}
+
+TEST_F(TransferTest, DefaultInitializer) {
+  std::string Code = R"(
+struct target {
+  int Bar;
+  int Baz = Bar;
+
+  target(int Foo) : Bar(Foo) {
+int Qux = Baz;
+// [[p]]
+  }
+};
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const auto *ThisLoc = dyn_cast(
+Env.getThisPointeeStorageLocation());
+ASSERT_THAT(ThisLoc, NotNull());
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const auto *FooVal =
+cast(Env.getValue(*FooDecl, SkipPast::None));
+
+const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ASSERT_THAT(QuxDecl, NotNull());
+EXPECT_EQ(Env.getValue(*QuxDecl, SkipPast::None), FooVal);
+  });
+}
+
+TEST_F(TransferTest, DefaultInitializerReference) {
+  std::string Code = R"(
+struct target {
+  int &Bar;
+  int &Baz = Bar;
+
+  target(int &Foo) : Bar(Foo) {
+int &Qux = Baz;
+// [[p]]
+  }
+};
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const auto *ThisLoc = dyn_cast(
+Env.getThisPointeeStorageLocation());
+ASSERT_THAT(ThisLoc, NotNull());
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const auto *FooVal =
+cast(Env.getValue(*FooDecl, SkipPast::None));
+
+const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ASSERT_THAT(QuxDecl, NotNull());
+
+const auto *QuxVal =
+cast(Env.getValue(*QuxDecl, SkipPast::None));
+EXPECT_EQ(&QuxVal->getPointeeLoc(), &FooVal->getPointeeLoc());
+  });
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -11,15 +11,18 @@
 //
 //===--===//
 
+#include 
 #include 
 #include 
 
+#include "clang/AST/DeclCXX.h"
 #include "clang/Analysis/Analyses/PostOrderCFGView.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/DataflowWorklist.h"
 #include "clang/Anal

[PATCH] D115121: Update bugprone-stringview-nullptr to support return statements and constructors for any T which accepts basic_string_view

2022-01-12 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp:263
+  auto HandleConstructorInvocation =
+  makeRule(cxxConstructExpr(hasAnyArgument(ignoringImpCasts(
+BasicStringViewConstructingFromNullExpr)),

CJ-Johnson wrote:
> ymandel wrote:
> > precede with `argumentCountIs(1)`? Also, please comment on choice of 
> > `hasAnyArgument` (copying what you wrote in the patch description is fine).
> Added the code comments, but not the argument count matcher. This case 
> intentionally matches any number of arguments since some types make take 2+ 
> parameters where one of them is string_view.
got it. I misunderstood the existing comment. thx


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115121

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


[clang-tools-extra] 7e29da8 - Add support for return values in bugprone-stringview-nullptr

2022-01-12 Thread CJ Johnson via cfe-commits

Author: CJ Johnson
Date: 2022-01-12T16:53:13-05:00
New Revision: 7e29da875ca95cd916e7ce6668fa85b638c3bd5f

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

LOG: Add support for return values in bugprone-stringview-nullptr

bugprone-stringview-nullptr was not initially written with tests for return 
statements. After landing the check, the thought crossed my mind to add such 
tests. After writing them, I realized they needed additional handling in the 
matchers.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
index 1f7dc48bbe8fb..a0ae262318914 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
@@ -9,6 +9,8 @@
 #include "StringviewNullptrCheck.h"
 #include "../utils/TransformerClangTidyCheck.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/OperationKinds.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Tooling/Transformer/RangeSelector.h"
@@ -24,15 +26,24 @@ using namespace ::clang::ast_matchers;
 using namespace ::clang::transformer;
 
 namespace {
+
 AST_MATCHER_P(InitListExpr, initCountIs, unsigned, N) {
   return Node.getNumInits() == N;
 }
+
+AST_MATCHER(clang::VarDecl, isDirectInitialization) {
+  return Node.getInitStyle() != clang::VarDecl::InitializationStyle::CInit;
+}
+
 } // namespace
 
 RewriteRule StringviewNullptrCheckImpl() {
   auto construction_warning =
   cat("constructing basic_string_view from null is undefined; replace with 
"
   "the default constructor");
+  auto static_cast_warning =
+  cat("casting to basic_string_view from null is undefined; replace with "
+  "the empty string");
   auto assignment_warning =
   cat("assignment to basic_string_view from null is undefined; replace "
   "with the default constructor");
@@ -42,143 +53,247 @@ RewriteRule StringviewNullptrCheckImpl() {
   auto equality_comparison_warning =
   cat("comparing basic_string_view to null is undefined; replace with the "
   "emptiness query");
-  auto StringViewConstructingFromNullExpr =
+  auto constructor_argument_warning =
+  cat("passing null as basic_string_view is undefined; replace with the "
+  "empty string");
+
+  // Matches declarations and expressions of type `basic_string_view`
+  auto HasBasicStringViewType = hasType(hasUnqualifiedDesugaredType(recordType(
+  hasDeclaration(cxxRecordDecl(hasName("::std::basic_string_view"));
+
+  // Matches `nullptr` and `(nullptr)` binding to a pointer
+  auto NullLiteral = implicitCastExpr(
+  hasCastKind(clang::CK_NullToPointer),
+  hasSourceExpression(ignoringParens(cxxNullPtrLiteralExpr(;
+
+  // Matches `{nullptr}` and `{(nullptr)}` binding to a pointer
+  auto NullInitList = initListExpr(initCountIs(1), hasInit(0, NullLiteral));
+
+  // Matches `{}`
+  auto EmptyInitList = initListExpr(initCountIs(0));
+
+  // Matches null construction without `basic_string_view` type spelling
+  auto BasicStringViewConstructingFromNullExpr =
   cxxConstructExpr(
-  hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
-  cxxRecordDecl(hasName("::std::basic_string_view")),
-  argumentCountIs(1),
-  hasArgument(
-  0, anyOf(ignoringParenImpCasts(cxxNullPtrLiteralExpr()),
-   initListExpr(initCountIs(1),
-hasInit(0, ignoringParenImpCasts(
-   cxxNullPtrLiteralExpr(,
-   initListExpr(initCountIs(0,
-  has(expr().bind("null_argument_expr")))
+  HasBasicStringViewType, argumentCountIs(1),
+  hasAnyArgument(/* `hasArgument` would skip over parens */ anyOf(
+  NullLiteral, NullInitList, EmptyInitList)),
+  unless(cxxTemporaryObjectExpr(/* filters out type spellings */)),
+  has(expr().bind("null_arg_expr")))
   .bind("construct_expr");
 
+  // `std::string_view(null_arg_expr)`
   auto HandleTemporaryCXXFunctionalCastExpr =
-  makeRule(cxxFunctionalCastExpr(
-   hasSourceExpression(StringViewConstructingFromNullExpr)),
-   remove(node("null_argument_expr")), construction_warning);
+  makeRule(cxxFunctionalCastExpr(hasSourceExpression(
+   Basic

[PATCH] D115121: Update bugprone-stringview-nullptr to support return statements and constructors for any T which accepts basic_string_view

2022-01-12 Thread CJ Johnson 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 rG7e29da875ca9: Add support for return values in 
bugprone-stringview-nullptr (authored by CJ-Johnson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115121

Files:
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -16,78 +16,116 @@
 template 
 class basic_string_view {
 public:
-  basic_string_view();
+  constexpr basic_string_view() {}
 
-  basic_string_view(const CharT *);
+  constexpr basic_string_view(const CharT *) {}
 
   // Not present in C++17 and C++20:
-  // basic_string_view(std::nullptr_t);
+  // constexpr basic_string_view(std::nullptr_t) {}
 
-  basic_string_view(const CharT *, size_t);
+  constexpr basic_string_view(const CharT *, size_t) {}
 
-  basic_string_view(const basic_string_view &);
+  constexpr basic_string_view(const basic_string_view &) {}
 
-  basic_string_view &operator=(const basic_string_view &);
+  constexpr basic_string_view &operator=(const basic_string_view &) {}
 };
 
 template 
-bool operator<(basic_string_view, basic_string_view);
+constexpr bool operator<(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<(type_identity_t>,
-   basic_string_view);
+constexpr bool operator<(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator<(basic_string_view,
-   type_identity_t>);
+constexpr bool operator<(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator<=(basic_string_view, basic_string_view);
+constexpr bool operator<=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(type_identity_t>,
-basic_string_view);
+constexpr bool operator<=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(basic_string_view,
-type_identity_t>);
+constexpr bool operator<=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>(basic_string_view, basic_string_view);
+constexpr bool operator>(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator>(type_identity_t>,
-   basic_string_view);
+constexpr bool operator>(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator>(basic_string_view,
-   type_identity_t>);
+constexpr bool operator>(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>=(basic_string_view, basic_string_view);
+constexpr bool operator>=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator>=(type_identity_t>,
-basic_string_view);
+constexpr bool operator>=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator>=(basic_string_view,
-type_identity_t>);
+constexpr bool operator>=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator==(basic_string_view, basic_string_view);
+constexpr bool operator==(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator==(type_identity_t>,
-basic_string_view);
+constexpr bool operator==(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator==(basic_string_view,
-type_identity_t>);
+constexpr bool operator==(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator!=(basic_string_view, basic_string_view);
+constexpr bool operator!=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(type_identity_t>,
-basic_string_view);
+constexpr bool operator!=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(basic_string_view,
-type_identity_t>);
+constexpr bool operator!=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 using string_view = basic_string_view;
 
 } // namespace std
 
+using SV = std::string_view; // Used in some places for shorter line length
+
 void function(std::string_view);
 void function(std::string_view, std::string_view)

[clang-tools-extra] 81c330e - Filter string_view from the nullptr diagnosis of bugprone-string-constructor to prevent duplicate warnings with bugprone-stringview-nullptr

2022-01-12 Thread CJ Johnson via cfe-commits

Author: CJ Johnson
Date: 2022-01-12T17:04:44-05:00
New Revision: 81c330e23dd4a14736b977e246bdca25be9b5770

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

LOG: Filter string_view from the nullptr diagnosis of 
bugprone-string-constructor to prevent duplicate warnings with 
bugprone-stringview-nullptr

Updates the check and tests to not diagnose the null case for string_view (but 
retains it for string). This prevents the check from giving duplicate warnings 
that are caught by bugprone-stringview-nullptr ([[ 
https://reviews.llvm.org/D113148 | D113148 ]]).

Reviewed By: ymandel

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
index beca3933bcd2..b55b282c41aa 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
@@ -43,6 +43,8 @@ removeNamespaces(const std::vector &Names) {
 StringConstructorCheck::StringConstructorCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
+  IsStringviewNullptrCheckEnabled(
+  Context->isCheckEnabled("bugprone-stringview-nullptr")),
   WarnOnLargeLength(Options.get("WarnOnLargeLength", true)),
   LargeLengthThreshold(Options.get("LargeLengthThreshold", 0x80)),
   StringNames(utils::options::parseStringList(
@@ -121,17 +123,20 @@ void StringConstructorCheck::registerMatchers(MatchFinder 
*Finder) {
   // Check the literal string constructor with char pointer.
   // [i.e. string (const char* s);]
   Finder->addMatcher(
-  traverse(TK_AsIs,
-   cxxConstructExpr(
-   hasDeclaration(cxxConstructorDecl(ofClass(cxxRecordDecl(
-   hasAnyName(removeNamespaces(StringNames)),
-   hasArgument(0, expr().bind("from-ptr")),
-   // do not match std::string(ptr, int)
-   // match std::string(ptr, alloc)
-   // match std::string(ptr)
-   anyOf(hasArgument(1, unless(hasType(isInteger(,
- argumentCountIs(1)))
-   .bind("constructor")),
+  traverse(
+  TK_AsIs,
+  cxxConstructExpr(
+  hasDeclaration(cxxConstructorDecl(ofClass(anyOf(
+  cxxRecordDecl(hasName("basic_string_view"))
+  .bind("basic_string_view_decl"),
+  cxxRecordDecl(hasAnyName(removeNamespaces(StringNames))),
+  hasArgument(0, expr().bind("from-ptr")),
+  // do not match std::string(ptr, int)
+  // match std::string(ptr, alloc)
+  // match std::string(ptr)
+  anyOf(hasArgument(1, unless(hasType(isInteger(,
+argumentCountIs(1)))
+  .bind("constructor")),
   this);
 }
 
@@ -167,6 +172,12 @@ void StringConstructorCheck::check(const 
MatchFinder::MatchResult &Result) {
 Ptr->EvaluateAsRValue(ConstPtr, Ctx) &&
 ((ConstPtr.Val.isInt() && ConstPtr.Val.getInt().isZero()) ||
  (ConstPtr.Val.isLValue() && ConstPtr.Val.isNullPointer( {
+  if (IsStringviewNullptrCheckEnabled &&
+  Result.Nodes.getNodeAs("basic_string_view_decl")) {
+// Filter out `basic_string_view` to avoid conflicts with
+// `bugprone-stringview-nullptr`
+return;
+  }
   diag(Loc, "constructing string from nullptr is undefined behaviour");
 }
   }

diff  --git a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
index 50338f8abead..d4877fbaa235 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
@@ -30,6 +30,7 @@ class StringConstructorCheck : public ClangTidyCheck {
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
+  const bool IsStringviewNullptrCheckEnabled;
   const bool WarnOnLargeLength;
   const unsigned int LargeLengthThreshold;
   std::vector StringNames;



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


[PATCH] D114823: Filter string_view from the nullptr diagnosis of bugprone-string-constructor to prevent duplicate warnings with bugprone-stringview-nullptr

2022-01-12 Thread CJ Johnson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG81c330e23dd4: Filter string_view from the nullptr diagnosis 
of bugprone-string-constructor to… (authored by CJ-Johnson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114823

Files:
  clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h


Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
@@ -30,6 +30,7 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
+  const bool IsStringviewNullptrCheckEnabled;
   const bool WarnOnLargeLength;
   const unsigned int LargeLengthThreshold;
   std::vector StringNames;
Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
@@ -43,6 +43,8 @@
 StringConstructorCheck::StringConstructorCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
+  IsStringviewNullptrCheckEnabled(
+  Context->isCheckEnabled("bugprone-stringview-nullptr")),
   WarnOnLargeLength(Options.get("WarnOnLargeLength", true)),
   LargeLengthThreshold(Options.get("LargeLengthThreshold", 0x80)),
   StringNames(utils::options::parseStringList(
@@ -121,17 +123,20 @@
   // Check the literal string constructor with char pointer.
   // [i.e. string (const char* s);]
   Finder->addMatcher(
-  traverse(TK_AsIs,
-   cxxConstructExpr(
-   hasDeclaration(cxxConstructorDecl(ofClass(cxxRecordDecl(
-   hasAnyName(removeNamespaces(StringNames)),
-   hasArgument(0, expr().bind("from-ptr")),
-   // do not match std::string(ptr, int)
-   // match std::string(ptr, alloc)
-   // match std::string(ptr)
-   anyOf(hasArgument(1, unless(hasType(isInteger(,
- argumentCountIs(1)))
-   .bind("constructor")),
+  traverse(
+  TK_AsIs,
+  cxxConstructExpr(
+  hasDeclaration(cxxConstructorDecl(ofClass(anyOf(
+  cxxRecordDecl(hasName("basic_string_view"))
+  .bind("basic_string_view_decl"),
+  cxxRecordDecl(hasAnyName(removeNamespaces(StringNames))),
+  hasArgument(0, expr().bind("from-ptr")),
+  // do not match std::string(ptr, int)
+  // match std::string(ptr, alloc)
+  // match std::string(ptr)
+  anyOf(hasArgument(1, unless(hasType(isInteger(,
+argumentCountIs(1)))
+  .bind("constructor")),
   this);
 }
 
@@ -167,6 +172,12 @@
 Ptr->EvaluateAsRValue(ConstPtr, Ctx) &&
 ((ConstPtr.Val.isInt() && ConstPtr.Val.getInt().isZero()) ||
  (ConstPtr.Val.isLValue() && ConstPtr.Val.isNullPointer( {
+  if (IsStringviewNullptrCheckEnabled &&
+  Result.Nodes.getNodeAs("basic_string_view_decl")) {
+// Filter out `basic_string_view` to avoid conflicts with
+// `bugprone-stringview-nullptr`
+return;
+  }
   diag(Loc, "constructing string from nullptr is undefined behaviour");
 }
   }


Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
@@ -30,6 +30,7 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
+  const bool IsStringviewNullptrCheckEnabled;
   const bool WarnOnLargeLength;
   const unsigned int LargeLengthThreshold;
   std::vector StringNames;
Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
@@ -43,6 +43,8 @@
 StringConstructorCheck::StringConstructorCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
+  IsStringviewNullptrCheckEnabled(
+  Context->isCheckEnabled("bugprone-stringview-nullptr")),
   WarnOnLargeLength(Options.get("WarnOnLargeLength", true)),
   LargeLengthThreshold(Options.get("Lar

[clang] 2db4cf5 - clang support for Armv8.8/9.3 HBC

2022-01-12 Thread via cfe-commits

Author: Tomas Matheson
Date: 2022-01-12T22:07:35Z
New Revision: 2db4cf5962ded48c7a5c3ec3c6051f64c8e7e376

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

LOG: clang support for Armv8.8/9.3 HBC

This introduces clang command line support for new Armv8.8-A and
Armv9.3-A Hinted Conditional Branches feature, previously introduced
into LLVM in https://reviews.llvm.org/D116156.

Patch by Tomas Matheson and Son Tuan Vu.

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

Added: 
clang/test/Driver/aarch64-hbc.c

Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
llvm/include/llvm/Support/AArch64TargetParser.def
llvm/include/llvm/Support/AArch64TargetParser.h
llvm/lib/Support/AArch64TargetParser.cpp
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index cbaeabd20692e..4a2d2a8f7f04d 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -543,6 +543,7 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
   HasMatmulFP64 = false;
   HasMatmulFP32 = false;
   HasLSE = false;
+  HasHBC = false;
 
   ArchKind = llvm::AArch64::ArchKind::INVALID;
 
@@ -658,6 +659,8 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
   HasRandGen = true;
 if (Feature == "+flagm")
   HasFlagM = true;
+if (Feature == "+hbc")
+  HasHBC = true;
   }
 
   setDataLayout();

diff  --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 43e5b6fe2de09..aa1ee7708b0d9 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -53,6 +53,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   bool HasMatmulFP32;
   bool HasLSE;
   bool HasFlagM;
+  bool HasHBC;
 
   llvm::AArch64::ArchKind ArchKind;
 

diff  --git a/clang/test/Driver/aarch64-hbc.c b/clang/test/Driver/aarch64-hbc.c
new file mode 100644
index 0..3681542ace471
--- /dev/null
+++ b/clang/test/Driver/aarch64-hbc.c
@@ -0,0 +1,6 @@
+// Test that target feature hbc is implemented and available correctly
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a+hbc %s 
2>&1 | FileCheck %s
+// CHECK: "-target-feature" "+hbc"
+
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.8-a+nohbc %s 
2>&1 | FileCheck %s --check-prefix=NO_HBC
+// NO_HBC: "-target-feature" "-hbc"

diff  --git a/llvm/include/llvm/Support/AArch64TargetParser.def 
b/llvm/include/llvm/Support/AArch64TargetParser.def
index 9d45f6abae6be..2b2b519a5c1b9 100644
--- a/llvm/include/llvm/Support/AArch64TargetParser.def
+++ b/llvm/include/llvm/Support/AArch64TargetParser.def
@@ -103,47 +103,48 @@ AARCH64_ARCH("armv8-r", ARMV8R, "8-R", "v8r",
 #define AARCH64_ARCH_EXT_NAME(NAME, ID, FEATURE, NEGFEATURE)
 #endif
 // FIXME: This would be nicer were it tablegen
-AARCH64_ARCH_EXT_NAME("invalid",  AArch64::AEK_INVALID, nullptr,  
nullptr)
-AARCH64_ARCH_EXT_NAME("none", AArch64::AEK_NONE,nullptr,  
nullptr)
-AARCH64_ARCH_EXT_NAME("crc",  AArch64::AEK_CRC, "+crc",   
"-crc")
-AARCH64_ARCH_EXT_NAME("lse",  AArch64::AEK_LSE, "+lse",   
"-lse")
-AARCH64_ARCH_EXT_NAME("rdm",  AArch64::AEK_RDM, "+rdm",   
"-rdm")
-AARCH64_ARCH_EXT_NAME("crypto",   AArch64::AEK_CRYPTO,  
"+crypto","-crypto")
-AARCH64_ARCH_EXT_NAME("sm4",  AArch64::AEK_SM4, "+sm4",   
"-sm4")
-AARCH64_ARCH_EXT_NAME("sha3", AArch64::AEK_SHA3,"+sha3",  
"-sha3")
-AARCH64_ARCH_EXT_NAME("sha2", AArch64::AEK_SHA2,"+sha2",  
"-sha2")
-AARCH64_ARCH_EXT_NAME("aes",  AArch64::AEK_AES, "+aes",   
"-aes")
-AARCH64_ARCH_EXT_NAME("dotprod",  AArch64::AEK_DOTPROD, 
"+dotprod","-dotprod")
-AARCH64_ARCH_EXT_NAME("fp",   AArch64::AEK_FP,  "+fp-armv8",  
"-fp-armv8")
-AARCH64_ARCH_EXT_NAME("simd", AArch64::AEK_SIMD,"+neon",  
"-neon")
-AARCH64_ARCH_EXT_NAME("fp16", AArch64::AEK_FP16,"+fullfp16",  
"-fullfp16")
-AARCH64_ARCH_EXT_NAME("fp16fml",  AArch64::AEK_FP16FML, "+fp16fml", 
"-fp16fml")
-AARCH64_ARCH_EXT_NAME("profile",  AArch64::AEK_PROFILE, "+spe",  
"-spe")
-AARCH64_ARCH_EXT_NAME("ras",  AArch64::AEK_RAS, "+ras",  
"-ras")
-AARCH64_ARCH_EXT_NAME("sve",  AArch64::AEK_SVE, "+sve",  
"-sve")
-AARCH64_ARCH_EXT_NAME("sve2", AArch64::AEK_SVE2,"+sve2", 
"-sve2")
-AARCH64_ARCH_EXT_NAME("sve2-aes", AArch64::AEK_SVE2AES, "+sve2-aes", 
"-sve2-aes")
-AARCH64_ARCH_EXT_NAME("sve2-sm4", AArch64::AEK_SVE2SM4, "+sve2-sm4", 
"-sve2-sm4")
-AARC

[PATCH] D116939: [AArch64] clang support for Armv8.8/9.3 HBC

2022-01-12 Thread Son Tuan Vu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
tyb0807 marked an inline comment as done.
Closed by commit rG2db4cf5962de: clang support for Armv8.8/9.3 HBC (authored by 
tmatheson, committed by tyb0807).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116939

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/test/Driver/aarch64-hbc.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1485,43 +1485,41 @@
 }
 
 TEST(TargetParserTest, AArch64ArchExtFeature) {
-  const char *ArchExt[][4] = {{"crc", "nocrc", "+crc", "-crc"},
-  {"crypto", "nocrypto", "+crypto", "-crypto"},
-  {"flagm", "noflagm", "+flagm", "-flagm"},
-  {"fp", "nofp", "+fp-armv8", "-fp-armv8"},
-  {"simd", "nosimd", "+neon", "-neon"},
-  {"fp16", "nofp16", "+fullfp16", "-fullfp16"},
-  {"fp16fml", "nofp16fml", "+fp16fml", "-fp16fml"},
-  {"profile", "noprofile", "+spe", "-spe"},
-  {"ras", "noras", "+ras", "-ras"},
-  {"lse", "nolse", "+lse", "-lse"},
-  {"rdm", "nordm", "+rdm", "-rdm"},
-  {"sve", "nosve", "+sve", "-sve"},
-  {"sve2", "nosve2", "+sve2", "-sve2"},
-  {"sve2-aes", "nosve2-aes", "+sve2-aes",
-   "-sve2-aes"},
-  {"sve2-sm4", "nosve2-sm4", "+sve2-sm4",
-   "-sve2-sm4"},
-  {"sve2-sha3", "nosve2-sha3", "+sve2-sha3",
-   "-sve2-sha3"},
-  {"sve2-bitperm", "nosve2-bitperm",
-   "+sve2-bitperm", "-sve2-bitperm"},
-  {"dotprod", "nodotprod", "+dotprod", "-dotprod"},
-  {"rcpc", "norcpc", "+rcpc", "-rcpc" },
-  {"rng", "norng", "+rand", "-rand"},
-  {"memtag", "nomemtag", "+mte", "-mte"},
-  {"tme", "notme", "+tme", "-tme"},
-  {"pauth", "nopauth", "+pauth", "-pauth"},
-  {"ssbs", "nossbs", "+ssbs", "-ssbs"},
-  {"sb", "nosb", "+sb", "-sb"},
-  {"predres", "nopredres", "+predres", "-predres"},
-  {"i8mm", "noi8mm", "+i8mm", "-i8mm"},
-  {"f32mm", "nof32mm", "+f32mm", "-f32mm"},
-  {"f64mm", "nof64mm", "+f64mm", "-f64mm"},
-  {"sme", "nosme", "+sme", "-sme"},
-  {"sme-f64", "nosme-f64", "+sme-f64", "-sme-f64"},
-  {"sme-i64", "nosme-i64", "+sme-i64", "-sme-i64"},
-};
+  const char *ArchExt[][4] = {
+  {"crc", "nocrc", "+crc", "-crc"},
+  {"crypto", "nocrypto", "+crypto", "-crypto"},
+  {"flagm", "noflagm", "+flagm", "-flagm"},
+  {"fp", "nofp", "+fp-armv8", "-fp-armv8"},
+  {"simd", "nosimd", "+neon", "-neon"},
+  {"fp16", "nofp16", "+fullfp16", "-fullfp16"},
+  {"fp16fml", "nofp16fml", "+fp16fml", "-fp16fml"},
+  {"profile", "noprofile", "+spe", "-spe"},
+  {"ras", "noras", "+ras", "-ras"},
+  {"lse", "nolse", "+lse", "-lse"},
+  {"rdm", "nordm", "+rdm", "-rdm"},
+  {"sve", "nosve", "+sve", "-sve"},
+  {"sve2", "nosve2", "+sve2", "-sve2"},
+  {"sve2-aes", "nosve2-aes", "+sve2-aes", "-sve2-aes"},
+  {"sve2-sm4", "nosve2-sm4", "+sve2-sm4", "-sve2-sm4"},
+  {"sve2-sha3", "nosve2-sha3", "+sve2-sha3", "-sve2-sha3"},
+  {"sve2-bitperm", "nosve2-bitperm", "+sve2-bitperm", "-sve2-bitperm"},
+  {"dotprod", "nodotprod", "+dotprod", "-dotprod"},
+  {"rcpc", "norcpc", "+rcpc", "-rcpc"},
+  {"rng", "norng", "+rand", "-rand"},
+  {"memtag", "nomemtag", "+mte", "-mte"},
+  {"tme", "notme", "+tme", "-tme"},
+  {"pauth", "nopauth", "+pauth", "-pauth"},
+  {"ssbs", "nossbs", "+ssbs", "-ssbs"},
+  {"sb", "nosb", "+sb", "-sb"},
+  {"predres", "nopredres", "+predres", "-predres"},
+  {"i8mm", "noi8mm", "+i8mm", "-i8mm"},
+  {"f32mm", "nof32mm", "+f32mm", "-f32mm"},
+  {"f64mm", "nof64mm", "+f64mm", "-f64mm"},
+  {"sme", "n

[PATCH] D117049: [OpenMP] Add support for embedding bitcode images in wrapper tool

2022-01-12 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 399460.
jhuber6 added a comment.

Forgot to use hook.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117049

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -76,12 +76,18 @@
cl::desc("Path for the target bitcode library"),
cl::cat(ClangLinkerWrapperCategory));
 
+static cl::opt EmbedBC(
+"target-embed-bc", cl::ZeroOrMore,
+cl::desc("Embed linked bitcode instead of an executable device image."),
+cl::init(false), cl::cat(ClangLinkerWrapperCategory));
+
 // Do not parse linker options.
 static cl::list
-HostLinkerArgs(cl::Sink, cl::desc("..."));
+HostLinkerArgs(cl::Positional,
+   cl::desc("..."));
 
 /// Path of the current binary.
-static std::string LinkerExecutable;
+static const char *LinkerExecutable;
 
 /// Temporary files created by the linker wrapper.
 static SmallVector TempFiles;
@@ -422,8 +428,8 @@
 
   std::unique_ptr Buffer =
   MemoryBuffer::getMemBuffer(Library.getMemoryBufferRef(), false);
-  if (Error Err = writeArchive(TempFile, Members, true, Library.kind(),
-true, Library.isThin(), std::move(Buffer)))
+  if (Error Err = writeArchive(TempFile, Members, true, Library.kind(), true,
+   Library.isThin(), std::move(Buffer)))
 return std::move(Err);
 
   return static_cast(TempFile);
@@ -500,7 +506,7 @@
   return static_cast(TempFile);
 }
 
-Expected link(ArrayRef InputFiles,
+Expected link(ArrayRef InputFiles,
ArrayRef LinkerArgs, Triple TheTriple,
StringRef Arch) {
   // NVPTX uses the nvlink binary to link device object files.
@@ -534,7 +540,7 @@
   CmdArgs.push_back(Arg);
 
   // Add extracted input files.
-  for (auto Input : InputFiles)
+  for (StringRef Input : InputFiles)
 CmdArgs.push_back(Input);
 
   if (sys::ExecuteAndWait(*NvlinkPath, CmdArgs))
@@ -544,7 +550,7 @@
 }
 } // namespace nvptx
 
-Expected linkDevice(ArrayRef InputFiles,
+Expected linkDevice(ArrayRef InputFiles,
  ArrayRef LinkerArgs,
  Triple TheTriple, StringRef Arch) {
   switch (TheTriple.getArch()) {
@@ -611,8 +617,10 @@
   llvm_unreachable("Invalid optimization level");
 }
 
-std::unique_ptr createLTO(const Triple &TheTriple, StringRef Arch,
-bool WholeProgram) {
+template >
+std::unique_ptr createLTO(
+const Triple &TheTriple, StringRef Arch, bool WholeProgram,
+ModuleHook Hook = [](size_t, const Module &) { return true; }) {
   lto::Config Conf;
   lto::ThinBackend Backend;
   // TODO: Handle index-only thin-LTO
@@ -631,7 +639,7 @@
   Conf.PTO.LoopVectorization = Conf.OptLevel > 1;
   Conf.PTO.SLPVectorization = Conf.OptLevel > 1;
 
-  // TODO: Handle outputting bitcode using a module hook.
+  Conf.PostInternalizeModuleHook = Hook;
   if (TheTriple.isNVPTX())
 Conf.CGFileType = CGFT_AssemblyFile;
   else
@@ -651,11 +659,11 @@
  [](char C) { return C == '_' || isAlnum(C); });
 }
 
-Expected> linkBitcodeFiles(ArrayRef InputFiles,
- const Triple &TheTriple,
- StringRef Arch) {
+Error linkBitcodeFiles(SmallVectorImpl &InputFiles,
+   const Triple &TheTriple, StringRef Arch) {
   SmallVector, 4> SavedBuffers;
   SmallVector, 4> BitcodeFiles;
+  SmallVector NewInputFiles;
   StringMap UsedInRegularObj;
 
   // Search for bitcode files in the input and create an LTO input file. If it
@@ -674,6 +682,7 @@
   if (!ObjFile)
 return ObjFile.takeError();
 
+  NewInputFiles.push_back(File.str());
   for (auto &Sym : (*ObjFile)->symbols()) {
 Expected Name = Sym.getName();
 if (!Name)
@@ -693,12 +702,36 @@
   }
 
   if (BitcodeFiles.empty())
-return None;
+return Error::success();
+
+  auto HandleError = [&](std::error_code EC) {
+logAllUnhandledErrors(errorCodeToError(EC),
+  WithColor::error(errs(), LinkerExecutable));
+exit(1);
+  };
+
+  // LTO Module hook to output bitcode without running the backend.
+  auto LinkOnly = [&](size_t Task, const Module &M) {
+SmallString<128> TempFile;
+if (std::error_code EC = sys::fs::createTemporaryFile(
+"jit-" + TheTriple.getTriple(), "bc", TempFile))
+  HandleError(EC);
+std::error_code EC;
+raw_fd_ostream Li

[PATCH] D117156: [OpenMP] Add extra flag handling to linker wrapper

2022-01-12 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield, ronlieb.
Herald added subscribers: guansong, yaxunl.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

This patch adds support for a few extra flags in the linker wrapper,
such as debugging flags, verbose output, and passing arguments to ptxas. We also
now forward pass remarks to the LLVM backend so they will show up in the LTO
passes.

Depends on D117049 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117156

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -48,6 +48,12 @@
 
 static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
 
+enum DebugKind {
+  NoDebugInfo,
+  DirectivesOnly,
+  FullDebugInfo,
+};
+
 // Mark all our options with this category, everything else (except for -help)
 // will be hidden.
 static cl::OptionCategory
@@ -58,29 +64,53 @@
 cl::desc("Strip offloading sections from the host object file."),
 cl::init(true), cl::cat(ClangLinkerWrapperCategory));
 
-static cl::opt LinkerUserPath("linker-path",
+static cl::opt LinkerUserPath("linker-path", cl::Required,
cl::desc("Path of linker binary"),
cl::cat(ClangLinkerWrapperCategory));
 
 static cl::opt
-TargetFeatures("target-feature", cl::desc("Target features for triple"),
+TargetFeatures("target-feature", cl::ZeroOrMore,
+   cl::desc("Target features for triple"),
cl::cat(ClangLinkerWrapperCategory));
 
-static cl::opt OptLevel("opt-level",
+static cl::opt OptLevel("opt-level", cl::ZeroOrMore,
  cl::desc("Optimization level for LTO"),
  cl::init("O2"),
  cl::cat(ClangLinkerWrapperCategory));
 
 static cl::opt
-BitcodeLibrary("target-library",
+BitcodeLibrary("target-library", cl::ZeroOrMore,
cl::desc("Path for the target bitcode library"),
cl::cat(ClangLinkerWrapperCategory));
 
 static cl::opt EmbedBC(
 "target-embed-bc", cl::ZeroOrMore,
-cl::desc("Embed linked bitcode instead of an executable device image."),
+cl::desc("Embed linked bitcode instead of an executable device image"),
 cl::init(false), cl::cat(ClangLinkerWrapperCategory));
 
+static cl::opt
+HostTriple("host-triple", cl::ZeroOrMore,
+   cl::desc("Triple to use for the host compilation"),
+   cl::init(sys::getDefaultTargetTriple()),
+   cl::cat(ClangLinkerWrapperCategory));
+
+static cl::opt
+PtxasOption("ptxas-option", cl::ZeroOrMore,
+cl::desc("Argument to pass to the ptxas invocation"),
+cl::cat(ClangLinkerWrapperCategory));
+
+static cl::opt Verbose("v", cl::ZeroOrMore,
+ cl::desc("Verbose output from tools"),
+ cl::init(false),
+ cl::cat(ClangLinkerWrapperCategory));
+
+static cl::opt DebugInfo(
+cl::desc("Choose debugging level:"), cl::init(NoDebugInfo),
+cl::values(clEnumValN(NoDebugInfo, "g0", "No debug information"),
+   clEnumValN(DirectivesOnly, "gline-directives-only",
+  "Direction information"),
+   clEnumValN(FullDebugInfo, "g", "Full debugging support")));
+
 // Do not parse linker options.
 static cl::list
 HostLinkerArgs(cl::Positional,
@@ -491,6 +521,14 @@
   std::string Opt = "-" + OptLevel;
   CmdArgs.push_back(*PtxasPath);
   CmdArgs.push_back(TheTriple.isArch64Bit() ? "-m64" : "-m32");
+  if (Verbose)
+CmdArgs.push_back("-v");
+  if (DebugInfo == DirectivesOnly && OptLevel[1] == '0')
+CmdArgs.push_back("-lineinfo");
+  else if (DebugInfo == FullDebugInfo && OptLevel[1] == '0')
+CmdArgs.push_back("-g");
+  if (!PtxasOption.empty())
+CmdArgs.push_back(PtxasOption);
   CmdArgs.push_back("-o");
   CmdArgs.push_back(TempFile);
   CmdArgs.push_back(Opt);
@@ -525,10 +563,13 @@
 return createFileError(TempFile, EC);
   TempFiles.push_back(static_cast(TempFile));
 
-  // TODO: Pass in arguments like `-g` and `-v` from the driver.
   SmallVector CmdArgs;
   CmdArgs.push_back(*NvlinkPath);
   CmdArgs.push_back(TheTriple.isArch64Bit() ? "-m64" : "-m32");
+  if (Verbose)
+CmdArgs.push_back("-v");
+  if (DebugInfo != NoDebugInfo)
+CmdArgs.push_back("-g");
   CmdArgs.push_back("-o");
   CmdArgs.push_back(TempFile);
   CmdArgs.push_back("-arch");
@@ -577,16 +618,16 @@
 
   switch (DI.getSeverit

[PATCH] D115031: [AST] Print NTTP args as string-literals when possible

2022-01-12 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/include/clang/AST/PrettyPrinter.h:288
+  /// template parameters, no matter how many elements there are.
+  unsigned EntireContentsOfLargeArray : 1;
+

lichray wrote:
> rsmith wrote:
> > It looks like nothing is setting this to `true` yet, so that part of this 
> > patch seems untested. The places I think we want to set this to `true` are:
> > 
> > 1) When forming types in a diagnostic, if we have two types that differ 
> > only in the contents of large arrays. That's checked in here: 
> > https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/ASTDiagnostic.cpp#L259
> > 
> > I think what we'd want is: if we still have a collision between type 
> > names after comparing the canonical strings 
> > (https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/ASTDiagnostic.cpp#L291),
> >  then set this policy to `true` for the rest of the function, and recompute 
> > `S` and `CanS`.
> > 
> > This should be detectable in a case such as:
> > 
> > ```
> > void f(X<{"some very long string that differs here: x"}>);
> > void g() {
> >   f(X<{"some very long string that differs here: y"}>());
> > }
> > ```
> > 
> > ... where the diagnostic should include the whole string, not elide the 
> > differing portion at the end.
> > 
> > 2) In the `-ast-print` output: when pretty-printing as code, we want to 
> > produce correct, non-elided template arguments. I think this will require 
> > passing a printing policy into `TemplateParamObjectDecl::printAsInit` and 
> > `::printAsExpr` 
> > (https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/DeclTemplate.cpp#L1509).
> >  This should be detectable in the output of `-ast-print`, where we do not 
> > want to elide any part of template arguments. Perhaps `StmtPrinter` and 
> > `DeclPrinter` should enable this `PrintingPolicy` flag?
> > 
> > 3) When generating debug information: 
> > https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGDebugInfo.cpp#L230
> > 
> > It's generally important that debug information has complete type names.
> Added `PrintingPolicy` parameter to `TemplateParamObjectDecl::printAsInit` 
> and `printAsExpr`, fixed the implementation, and added tests for the effect 
> of the new `EntireContentsOfLargeArray` bit.
> 
> Whether how diagnosis, codegen, and higher-level printers should make use of 
> them, I think they're outside the scope of this patch.
Generally I agree, we don't need to fix all the places that should be setting 
this new flag as part of the same patch, but I think at least `-ast-print` 
should be fixed here, given how obviously broken it currently is. That would 
also remove the need to add a unit test for the new flag.



Comment at: clang/test/SemaTemplate/temp_arg_string_printing.cpp:1
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -ast-print %s | FileCheck %s
+

Please use something like diagnostics to test that elision happens, rather than 
`-ast-print`, because `-ast-print` aims to produce valid C++ code that has the 
same meaning as the input -- this is a canonical example of a case that should 
*not* elide large array contents.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115031

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


[PATCH] D111566: [SYCL] Fix function pointer address space

2022-01-12 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 399484.
eandrews added a comment.
Herald added a subscriber: Jim.

Implemented review comments

- Remove unnecessary set method and set default value during construction 
instead
- Changed default address space for function pointer for avr target to 1.


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

https://reviews.llvm.org/D111566

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/AVR.h
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/test/CodeGen/avr/functionptr-addrspace.c
  clang/test/CodeGenSYCL/functionptr-addrspace.cpp

Index: clang/test/CodeGenSYCL/functionptr-addrspace.cpp
===
--- /dev/null
+++ clang/test/CodeGenSYCL/functionptr-addrspace.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsycl-is-device -emit-llvm -triple spir64 -verify -emit-llvm %s -o - | FileCheck %s
+
+// expected-no-diagnostics
+
+template 
+__attribute__((sycl_kernel)) void kernel_single_task(const Func &kernelFunc) {
+  kernelFunc();
+}
+
+// CHECK: define dso_local spir_func{{.*}}invoke_function{{.*}}(i32 ()* %fptr, i32 addrspace(4)* %ptr)
+void invoke_function(int (*fptr)(), int *ptr) {}
+
+int f() { return 0; }
+
+int main() {
+  kernel_single_task([=]() {
+int (*p)() = f;
+int (&r)() = *p;
+int a = 10;
+invoke_function(p, &a);
+invoke_function(r, &a);
+invoke_function(f, &a);
+  });
+  return 0;
+}
Index: clang/test/CodeGen/avr/functionptr-addrspace.c
===
--- /dev/null
+++ clang/test/CodeGen/avr/functionptr-addrspace.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple avr -emit-llvm %s -o - | FileCheck %s
+
+int main() {
+  int (*p)();
+  return 0;
+}
+
+// CHECK: %p = alloca i16 (...) addrspace(1)*
Index: clang/lib/CodeGen/CodeGenTypes.cpp
===
--- clang/lib/CodeGen/CodeGenTypes.cpp
+++ clang/lib/CodeGen/CodeGenTypes.cpp
@@ -643,11 +643,7 @@
 llvm::Type *PointeeType = ConvertTypeForMem(ETy);
 if (PointeeType->isVoidTy())
   PointeeType = llvm::Type::getInt8Ty(getLLVMContext());
-
-unsigned AS = PointeeType->isFunctionTy()
-  ? getDataLayout().getProgramAddressSpace()
-  : Context.getTargetAddressSpace(ETy);
-
+unsigned AS = Context.getTargetAddressSpace(ETy);
 ResultType = llvm::PointerType::get(PointeeType, AS);
 break;
   }
@@ -748,7 +744,13 @@
 llvm::Type *PointeeType = CGM.getLangOpts().OpenCL
   ? CGM.getGenericBlockLiteralType()
   : ConvertTypeForMem(FTy);
-unsigned AS = Context.getTargetAddressSpace(FTy);
+// Block pointers lower to function type. For function type,
+// getTargetAddressSpace() returns default address space for
+// function pointer i.e. program address space. Therefore, for block
+// pointers, it is important to pass qualifiers when calling
+// getTargetAddressSpace(), to ensure that we get the address space
+// for data pointers and not function pointers.
+unsigned AS = Context.getTargetAddressSpace(FTy.getQualifiers());
 ResultType = llvm::PointerType::get(PointeeType, AS);
 break;
   }
Index: clang/lib/Basic/Targets/AVR.h
===
--- clang/lib/Basic/Targets/AVR.h
+++ clang/lib/Basic/Targets/AVR.h
@@ -55,6 +55,7 @@
 Int16Type = SignedInt;
 Char32Type = UnsignedLong;
 SigAtomicType = SignedChar;
+ProgramAddrSpace = 1;
 resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8");
   }
 
Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -148,6 +148,7 @@
   PlatformMinVersion = VersionTuple();
 
   MaxOpenCLWorkGroupSize = 1024;
+  ProgramAddrSpace = 0;
 }
 
 // Out of line virtual dtor for TargetInfo.
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -11488,6 +11488,15 @@
   return getTargetInfo().getNullPointerValue(AS);
 }
 
+unsigned ASTContext::getTargetAddressSpace(QualType T) const {
+  return T->isFunctionType() ? getTargetInfo().getProgramAddressSpace()
+ : getTargetAddressSpace(T.getQualifiers());
+}
+
+unsigned ASTContext::getTargetAddressSpace(Qualifiers Q) const {
+  return getTargetAddressSpace(Q.getAddressSpace());
+}
+
 unsigned ASTContext::getTargetAddressSpace(LangAS AS) const {
   if (isTargetAddressSpace(AS))
 return toTargetAddressSpace(AS);
Index: clang/include/clang/Basic/TargetInfo.h
===
--- 

[PATCH] D114732: [clang] Mark `trivial_abi` types as "trivially relocatable".

2022-01-12 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114732

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


[PATCH] D111566: [SYCL] Fix function pointer address space

2022-01-12 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added inline comments.



Comment at: clang/test/CodeGen/avr/functionptr-addrspace.c:3
+
+int main() {
+  int (*p)();

When writing the test I noticed an existing crash in the compiler. I am not 
sure if I am doing something wrong but if you try to assign to the pointer, you 
will hit the following assert - 
https://llvm.org/doxygen/Constants_8cpp_source.html#l02280

```
int f() { return 0; }

int main() {
  int (*p)() = f;
  return 0;
}
```

I briefly debugged this and I think the crash is because in `GetAddrOfFunction` 
we call `ConvertType` which returns type without the address space here - 
https://clang.llvm.org/doxygen/CodeGenTypes_8cpp_source.html#l00419.

I didn't fix this or debug this further since it is outside the scope of this 
patch but I can look into it as a followup PR


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

https://reviews.llvm.org/D111566

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


[PATCH] D117129: [clang-tidy] Extract Class IncluderClangTidyCheck

2022-01-12 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D117129#3238441 , 
@LegalizeAdulthood wrote:

> Another option would be to migrate this to `ClangTidyCheck` itself
> and add a flag/option passed to the ClangTidyCheck c'tor to opt-in
> to the feature?

I feel that this direction is much better, Its something I wanted to introduce 
a while back, but my work was getting in the way.
My proposed idea was putting the `IncludeInserter` instance inside the 
`ClangTidyContext`, but then only registering it if any checks actually want to 
use it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117129

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


  1   2   3   >