[PATCH] D71880: [clangd] Implement Decl canonicalization rules for rename

2020-11-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

didn't finish all parts (looked at the FunctionDecl and RecordDecl), I think we 
need more documentation/comments in the code to specify the canonical behavior 
(templates are tricky).




Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:239
+  if (const auto *Template = D->getPrimaryTemplate())
+return canonicalRenameDecl(Template);
+  return D;

the `auto` + varies `canonicalRenameDecl` overrides make the code hard to 
follow.

since these functions are small, I think we can inline them into the main 
`canonicalRenameDecl(const NamedDecl *D)`



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:246
+  if (const auto *Primary = TemplatedDecl->getPrimaryTemplate())
+return Primary;
+  return TemplatedDecl;

didn't quite follow the code here, the code looks like we get the 
FunctionTemplateDecl back via the code path (FunctionTemplateDecl -> 
FunctionDecl -> FunctionTemplateDecl), and it looks like we're not using the 
specialized declaration as the canonical decl.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:255
+const NamedDecl *canonicalRenameDecl(const ClassTemplateSpecializationDecl *D) 
{
+  return D->getSpecializedTemplate()->getTemplatedDecl();
+}

want to confirm my understanding:

given the example below:

```
template
class Foo {};

template<>
class Foo {};
```

the AST is like:

```
ClassTemplateDecl
  |-CXXRecordDecl (Foo definition) -> (1)
  |-ClassTemplateSpecialization. 

ClassTemplateSpecializationDecl -> call canonicalRenameDecl on it.
  |-Template Argument int
  |-CXXRecordDecl -> (2)
```

if we pass `ClassTemplateSpecializationDecl` to this function, this function 
will return (2)?



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:261
+//   CXXRecordDecl
+// - Specializations should point to the specialized declaration.
+// - Instantiations should point to instantiated declaration.

I think the motivation is for merely renaming the explicit template 
specialization, but not the primary template?



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:610
   const auto &RenameDecl =
   llvm::cast(*(*DeclsUnderCursor.begin())->getCanonicalDecl());
   if (RenameDecl.getName() == RInputs.NewName)

 `getCanonicalDecl` is not needed now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71880

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


[PATCH] D91519: [AST][Mach0] Fix unused-variable warnings

2020-11-16 Thread Gabriel Hjort Åkerlund via Phabricator via cfe-commits
ehjogab created this revision.
ehjogab added reviewers: dsanders, arsenm, qcolombet, ab, bjope, rovka.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
ehjogab requested review of this revision.
Herald added a subscriber: wdng.

Change-Id: Id37948be57aad3551eb14fc16b2aea2441a45e7d


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91519

Files:
  clang/lib/AST/APValue.cpp
  lld/MachO/SymbolTable.cpp


Index: lld/MachO/SymbolTable.cpp
===
--- lld/MachO/SymbolTable.cpp
+++ lld/MachO/SymbolTable.cpp
@@ -134,7 +134,7 @@
 // FIXME: Make every symbol (including absolute symbols) contain a
 // reference to their originating file, then add that file name to this
 // error message.
-if (auto *defined = dyn_cast(s))
+if (dyn_cast(s))
   error("found defined symbol with illegal name " + DSOHandle::name);
   }
   replaceSymbol(s, header);
Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -1062,7 +1062,7 @@
   }
 
   case APValue::Union:
-if (const auto *FD = V.getUnionField())
+if (V.getUnionField())
   Merge(V.getUnionValue());
 break;
 


Index: lld/MachO/SymbolTable.cpp
===
--- lld/MachO/SymbolTable.cpp
+++ lld/MachO/SymbolTable.cpp
@@ -134,7 +134,7 @@
 // FIXME: Make every symbol (including absolute symbols) contain a
 // reference to their originating file, then add that file name to this
 // error message.
-if (auto *defined = dyn_cast(s))
+if (dyn_cast(s))
   error("found defined symbol with illegal name " + DSOHandle::name);
   }
   replaceSymbol(s, header);
Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -1062,7 +1062,7 @@
   }
 
   case APValue::Union:
-if (const auto *FD = V.getUnionField())
+if (V.getUnionField())
   Merge(V.getUnionValue());
 break;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83071: Add support for options with two flags for controlling the same field.

2020-11-16 Thread Jan Svoboda 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 rG2f3055c543f8: [clang][cli] Add support for options with two 
flags for controlling the same… (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D83071?vs=304491&id=305428#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83071

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -63,8 +63,9 @@
 
 class MarshallingInfo {
 public:
-  static constexpr const char *MacroName = "OPTION_WITH_MARSHALLING";
+  using Ptr = std::unique_ptr;
 
+  const char *MacroName;
   const Record &R;
   bool ShouldAlwaysEmit;
   StringRef KeyPath;
@@ -80,6 +81,8 @@
   std::vector NormalizedValues;
   std::string ValueTableName;
 
+  static size_t NextTableIndex;
+
   static constexpr const char *ValueTablePreamble = R"(
 struct SimpleEnumValue {
   const char *Name;
@@ -95,7 +98,14 @@
   static constexpr const char *ValueTablesDecl =
   "static const SimpleEnumValueTable SimpleEnumValueTables[] = ";
 
-  void emit(raw_ostream &OS) const {
+  MarshallingInfo(const Record &R)
+  : MacroName("OPTION_WITH_MARSHALLING"), R(R) {}
+  MarshallingInfo(const char *MacroName, const Record &R)
+  : MacroName(MacroName), R(R){};
+
+  virtual ~MarshallingInfo() = default;
+
+  virtual void emit(raw_ostream &OS) const {
 write_cstring(OS, StringRef(getOptionSpelling(R)));
 OS << ", ";
 OS << ShouldAlwaysEmit;
@@ -133,53 +143,6 @@
 return StringRef(ValueTableName);
   }
 
-  static MarshallingInfo create(const Record &R) {
-assert(!isa(R.getValueInit("KeyPath")) &&
-   !isa(R.getValueInit("DefaultValue")) &&
-   !isa(R.getValueInit("NormalizerRetTy")) &&
-   !isa(R.getValueInit("ValueMerger")) &&
-   "MarshallingInfo must have a type");
-
-MarshallingInfo Ret(R);
-Ret.ShouldAlwaysEmit = R.getValueAsBit("ShouldAlwaysEmit");
-Ret.KeyPath = R.getValueAsString("KeyPath");
-Ret.DefaultValue = R.getValueAsString("DefaultValue");
-Ret.NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope");
-Ret.NormalizerRetTy = R.getValueAsString("NormalizerRetTy");
-
-Ret.Normalizer = R.getValueAsString("Normalizer");
-Ret.Denormalizer = R.getValueAsString("Denormalizer");
-Ret.ValueMerger = R.getValueAsString("ValueMerger");
-Ret.ValueExtractor = R.getValueAsString("ValueExtractor");
-
-if (!isa(R.getValueInit("NormalizedValues"))) {
-  assert(!isa(R.getValueInit("Values")) &&
- "Cannot provide normalized values for value-less options");
-  Ret.TableIndex = NextTableIndex++;
-  Ret.NormalizedValues = R.getValueAsListOfStrings("NormalizedValues");
-  Ret.Values.reserve(Ret.NormalizedValues.size());
-  Ret.ValueTableName = getOptionName(R) + "ValueTable";
-
-  StringRef ValuesStr = R.getValueAsString("Values");
-  for (;;) {
-size_t Idx = ValuesStr.find(',');
-if (Idx == StringRef::npos)
-  break;
-if (Idx > 0)
-  Ret.Values.push_back(ValuesStr.slice(0, Idx));
-ValuesStr = ValuesStr.slice(Idx + 1, StringRef::npos);
-  }
-  if (!ValuesStr.empty())
-Ret.Values.push_back(ValuesStr);
-
-  assert(Ret.Values.size() == Ret.NormalizedValues.size() &&
- "The number of normalized values doesn't match the number of "
- "values");
-}
-
-return Ret;
-  }
-
 private:
   void emitScopedNormalizedValue(raw_ostream &OS,
  StringRef NormalizedValue) const {
@@ -187,13 +150,85 @@
   OS << NormalizedValuesScope << "::";
 OS << NormalizedValue;
   }
+};
+
+size_t MarshallingInfo::NextTableIndex = 0;
 
-  MarshallingInfo(const Record &R) : R(R){};
+class MarshallingInfoBooleanFlag : public MarshallingInfo {
+public:
+  const Record &NegOption;
 
-  static size_t NextTableIndex;
+  MarshallingInfoBooleanFlag(const Record &Option, const Record &NegOption)
+  : MarshallingInfo("OPTION_WITH_MARSHALLING_BOOLEAN", Option),
+NegOption(NegOption) {}
+
+  void emit(raw_ostream &OS) const override {
+MarshallingInfo::emit(OS);
+OS << ", ";
+OS << getOptionName(NegOption);
+OS << ", ";
+write_cstring(OS, getOptionSpelling(NegOption));
+  }
 };
 
-size_t MarshallingInfo::NextTableIndex = 0;
+static MarshallingInfo::Ptr createMarshallingInfo(const Record &R) {
+  assert(!isa(R.getValueInit("KeyPath")) &&
+ !isa(R.getValueInit("DefaultValue")) &&
+ !isa(R.getValueInit("Normal

[clang] 2f3055c - [clang][cli] Add support for options with two flags for controlling the same field.

2020-11-16 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2020-11-16T10:21:54+01:00
New Revision: 2f3055c543f8f5e8cd975350fae5f4b0ac4871c3

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

LOG: [clang][cli] Add support for options with two flags for controlling the 
same field.

This enables automatically parsing and generating CC1 arguments for options 
where two flags control the same field, e.g. -fexperimental-new-pass-manager 
and -fno-experimental new pass manager.

Reviewed By: Bigcheese, dexonsmith

Original patch by Daniel Grumberg.

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
llvm/include/llvm/Option/OptParser.td
llvm/utils/TableGen/OptParserEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0b0def564cf3..ec86c5e07ab6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -266,6 +266,12 @@ multiclass OptOutFFlag;
 }
 
+multiclass BooleanMarshalledFFlag {
+  def fno_#NAME : Flag<["-"], "fno-"#name>, HelpText;
+  def f#NAME : Flag<["-"], "f"#name>, HelpText,
+MarshallingInfoBooleanFlag("fno_"#NAME)>;
+}
+
 /
 // Options
 
@@ -1320,9 +1326,9 @@ def fglobal_isel : Flag<["-"], "fglobal-isel">, 
Group,
   HelpText<"Enables the global instruction selector">;
 def fexperimental_isel : Flag<["-"], "fexperimental-isel">, 
Group,
   Alias;
-def fexperimental_new_pass_manager : Flag<["-"], 
"fexperimental-new-pass-manager">,
-  Group, Flags<[CC1Option]>,
-  HelpText<"Enables an experimental new pass manager in LLVM.">;
+defm experimental_new_pass_manager : 
BooleanMarshalledFFlag<"experimental-new-pass-manager", 
"CodeGenOpts.ExperimentalNewPassManager",
+  "static_cast(ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER)", "Enables an 
experimental new pass manager in LLVM.",
+  "Disables an experimental new pass manager in LLVM.">, Group, 
Flags<[CC1Option]>;
 def fexperimental_strict_floating_point : Flag<["-"], 
"fexperimental-strict-floating-point">,
   Group, Flags<[CC1Option]>,
   HelpText<"Enables experimental strict floating point in LLVM.">,
@@ -1624,9 +1630,6 @@ def fno_global_isel : Flag<["-"], "fno-global-isel">, 
Group,
   HelpText<"Disables the global instruction selector">;
 def fno_experimental_isel : Flag<["-"], "fno-experimental-isel">, 
Group,
   Alias;
-def fno_experimental_new_pass_manager : Flag<["-"], 
"fno-experimental-new-pass-manager">,
-  Group, Flags<[CC1Option]>,
-  HelpText<"Disables an experimental new pass manager in LLVM.">;
 def fveclib : Joined<["-"], "fveclib=">, Group, Flags<[CC1Option]>,
 HelpText<"Use the given vector functions library">, 
Values<"Accelerate,libmvec,MASSV,SVML,none">;
 def fno_lax_vector_conversions : Flag<["-"], "fno-lax-vector-conversions">, 
Group,

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2e20ecea3334..c4133ec1bcd8 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -134,6 +134,13 @@ static llvm::Optional 
normalizeSimpleFlag(OptSpecifier Opt,
   return None;
 }
 
+void denormalizeSimpleFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  Args.push_back(Spelling);
+}
+
 template 
 static llvm::Optional
 normalizeFlagToValue(OptSpecifier Opt, unsigned TableIndex, const ArgList 
&Args,
@@ -143,6 +150,27 @@ normalizeFlagToValue(OptSpecifier Opt, unsigned 
TableIndex, const ArgList &Args,
   return None;
 }
 
+static Optional normalizeBooleanFlag(OptSpecifier PosOpt,
+   OptSpecifier NegOpt,
+   unsigned TableIndex,
+   const ArgList &Args,
+   DiagnosticsEngine &Diags) {
+  if (const Arg *A = Args.getLastArg(PosOpt, NegOpt))
+return A->getOption().matches(PosOpt);
+  return None;
+}
+
+static void denormalizeBooleanFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   const char *NegSpelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  if (Value)
+Args.push_back(Spelling);
+  else
+Args.push_back(NegSpelling);
+}
+
 static llvm::Optional normalizeSimpleEnum(OptSpecifier Opt,
 unsigned TableIndex,

[PATCH] D83211: Factor out call to EXTRACTOR in generateCC1CommandLine

2020-11-16 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 commandeered this revision.
jansvoboda11 added a reviewer: dang.
jansvoboda11 added a comment.

Taking over this patch as Daniel is no longer involved.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83211

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


[PATCH] D91055: [clang-tidy] Introduce misc No Integer To Pointer Cast check

2020-11-16 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91055

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


[PATCH] D83211: Factor out call to EXTRACTOR in generateCC1CommandLine

2020-11-16 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 305437.
jansvoboda11 added a comment.

Rebase and add documenting possible reference lifetime extension issue


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83211

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -236,6 +236,9 @@
   return KeyPath | Value;
 }
 
+// The value returned by an extractor is stored as a constant reference.
+// Watch out for missed reference lifetime extension.
+
 template  static T extractForwardValue(T KeyPath) {
   return KeyPath;
 }
@@ -4040,9 +4043,10 @@
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,
\
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  
\
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)
\
-  if (((FLAGS) & options::CC1Option) &&
\
-  (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != (DEFAULT_VALUE))) {  
\
-DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, EXTRACTOR(this->KEYPATH));   
\
+  if ((FLAGS)&options::CC1Option) {
\
+const auto &Extracted = EXTRACTOR(this->KEYPATH);  
\
+if (ALWAYS_EMIT || Extracted != (DEFAULT_VALUE))   
\
+  DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, Extracted);
\
   }
 
 #define OPTION_WITH_MARSHALLING_BOOLEAN(   
\
@@ -4050,10 +4054,10 @@
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  
\
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX, NEG_ID,
\
 NEG_SPELLING)  
\
-  if (((FLAGS)&options::CC1Option) &&  
\
-  (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {
\
-DENORMALIZER(Args, SPELLING, NEG_SPELLING, SA, TABLE_INDEX,
\
- EXTRACTOR(this->KEYPATH));
\
+  if ((FLAGS)&options::CC1Option) {
\
+const auto &Extracted = EXTRACTOR(this->KEYPATH);  
\
+if (ALWAYS_EMIT || Extracted != (DEFAULT_VALUE))   
\
+  DENORMALIZER(Args, SPELLING, NEG_SPELLING, SA, TABLE_INDEX, Extracted);  
\
   }
 
 #include "clang/Driver/Options.inc"


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -236,6 +236,9 @@
   return KeyPath | Value;
 }
 
+// The value returned by an extractor is stored as a constant reference.
+// Watch out for missed reference lifetime extension.
+
 template  static T extractForwardValue(T KeyPath) {
   return KeyPath;
 }
@@ -4040,9 +4043,10 @@
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,\
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  \
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)\
-  if (((FLAGS) & options::CC1Option) &&\
-  (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != (DEFAULT_VALUE))) {  \
-DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, EXTRACTOR(this->KEYPATH));   \
+  if ((FLAGS)&options::CC1Option) {\
+const auto &Extracted = EXTRACTOR(this->KEYPATH);  \
+if (ALWAYS_EMIT || Extracted != (DEFAULT_VALUE))   \
+  DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, Extracted);\
   }
 
 #define OPTION_WITH_MARSHALLING_BOOLEAN(   \
@@ -4050,10 +4054,10 @@
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  \
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX, NEG_ID,\
 NEG_SPELLING)  \
-  if (((FLAGS)&options::CC1Option) &&  \
-  (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {\
-DENORMALIZER(Args, SPELLING, NEG_SPELLING, SA, TABLE_INDEX,\
- EXTRACTOR(this->KEYPATH));\
+  if ((FLAGS)&options::CC1Option) {\
+const auto &Extracted = EXTRACTOR(this->KEYPATH);  \
+if (ALWAYS_EMIT || Extracted != (DEFAULT_VALUE))   \
+  DENORMALIZ

[PATCH] D90691: [analyzer] Add new checker for unchecked return value.

2020-11-16 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90691

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


[PATCH] D89031: [SVE] Add support to vectorize_width loop pragma for scalable vectors

2020-11-16 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added a comment.

> This approach should be fully complementary to `vectorize_with` so that it 
> would be possible to have:
>
>   // Use scalable vectors, but leave it to the cost-model to choose the most 
> efficient N in .
>   // If the pragma is not specified, it defaults to vectorize_style(fixed).
>   #pragma clang loop vectorize_style(scalable)
>   
>   // Use <4 x eltty>
>   #pragma clang loop vectorize_width(4, fixed)
>   
>   // Use 
>   #pragma clang loop vectorize_width(4, scalable)
>   
>   // If vectorize_style(scalable) is specified, then use  eltty>, otherwise <4 x eltty>
>   #pragma clang loop vectorize_width(4)   // uses <4 
> x eltty>
>   #pragma clang loop vectorize_width(4) vectorize_style(scalable) // uses 
> 
>   
>   // Conflicting options, clang should print diagnostic and error or ignore 
> the hint.
>   #pragma clang loop vectorize_width(4, fixed) vectorize_style(scalable)
>
> I hope that gives a bit more context.

Ok, thanks for clarifying that!

If:

  // Use 
  #pragma clang loop vectorize_width(4, scalable)

is equivalent to:

  // uses 
  #pragma clang loop vectorize_width(4) vectorize_style(scalable)

then I think that illustrates that I don't see the point of extending 
`vectorize_width` because we still can't express scalable vectorisation for:

  // 
  #pragma clang loop vectorize_predicate(enable)

and also for `interleave_count(4)`?

Again, when the idea is to have vectorize_style anyway, wouldn't it be easier 
not to bother extending vectorize_width and just go for vectorize_style? It 
allows you to specify fixed/scalable vectorisation in one way, and avoids 
having conflicting options.

The other thing I thought about: this is extending an existing user-facing 
pragma, and notifying the list would probably be best thing to do.


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

https://reviews.llvm.org/D89031

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


[PATCH] D75229: [clang-tidy] Add signal-in-multithreaded-program check

2020-11-16 Thread Kocsis Ábel via Phabricator via cfe-commits
abelkocsis updated this revision to Diff 305439.
abelkocsis added a comment.

Fixes


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D75229

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/SignalInMultithreadedProgramCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SignalInMultithreadedProgramCheck.h
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-signal-in-multithreaded-program.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-con37-c.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-config-std_thread.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-config-thrd_create.c
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-noconfig-std_thread.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-noconfig-thrd_create.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-noconfig-thrd_create.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-noconfig-thrd_create.c
@@ -0,0 +1,36 @@
+// RUN: %check_clang_tidy %s bugprone-signal-in-multithreaded-program %t
+
+typedef unsigned long int thrd_t;
+typedef int (*thrd_start_t)(void *);
+typedef int sig_atomic_t;
+#define SIGUSR1 30
+#define NULL 0
+
+void (*signal(int sig, void (*handler)(int)))(int);
+
+int thrd_create(thrd_t *thr, thrd_start_t func, void *arg) { return 0; };
+enum {
+  thrd_success = 0,
+};
+
+volatile sig_atomic_t flag = 0;
+
+void handler(int signum) {
+  flag = 1;
+}
+
+int func(void *data) {
+  while (!flag) {
+  }
+  return 0;
+}
+
+int main(void) {
+  signal(SIGUSR1, handler);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: signal function should not be called in a multithreaded program [bugprone-signal-in-multithreaded-program]
+  thrd_t tid;
+
+  if (thrd_success != thrd_create(&tid, func, NULL)) {
+  }
+  return 0;
+}
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-noconfig-std_thread.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-noconfig-std_thread.cpp
@@ -0,0 +1,35 @@
+// RUN: %check_clang_tidy %s bugprone-signal-in-multithreaded-program %t
+
+typedef int sig_atomic_t;
+#define SIGUSR1 30
+#define NULL 0
+
+void (*signal(int sig, void (*handler)(int)))(int);
+
+volatile sig_atomic_t flag = 0;
+
+void handler(int signum) {
+  flag = 1;
+}
+
+void threadFunction() {}
+
+namespace std {
+class thread {
+public:
+  thread() noexcept;
+  template 
+  explicit thread(Function &&f, Args &&... args);
+  thread(const thread &) = delete;
+  thread(thread &&) noexcept;
+};
+} // namespace std
+
+int main() {
+  signal(SIGUSR1, handler);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: signal function should not be called in a multithreaded program [bugprone-signal-in-multithreaded-program]
+
+  std::thread threadObj(threadFunction);
+
+  return 0;
+}
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-config-thrd_create.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-config-thrd_create.c
@@ -0,0 +1,38 @@
+// RUN: %check_clang_tidy %s bugprone-signal-in-multithreaded-program %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: bugprone-signal-in-multithreaded-program.ThreadList, value: "thrd_create"}]}'
+
+typedef unsigned long int thrd_t;
+typedef int (*thrd_start_t)(void *);
+typedef int sig_atomic_t;
+#define SIGUSR1 30
+#define NULL 0
+
+void (*signal(int sig, void (*handler)(int)))(int);
+
+int thrd_create(thrd_t *thr, thrd_start_t func, void *arg) { return 0; };
+enum {
+  thrd_success = 0,
+};
+
+volatile sig_atomic_t flag = 0;
+
+void handler(int signum) {
+  flag = 1;
+}
+
+int func(void *data) {
+  while (!flag) {
+  }
+  return 0;
+}
+
+int main(void) {
+  signal(SIGUSR1, handler);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: signal function should not be called in a multithreaded program [bugprone-signal-in-multithreaded-program]
+  thrd_t tid;
+
+  if (thrd_success != thrd_create(&tid, func, NULL)) {
+  }
+  return 0;
+}
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-config-std_thread.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tid

[PATCH] D83211: Factor out call to EXTRACTOR in generateCC1CommandLine

2020-11-16 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Addressed review feedback. WDYT @Bigcheese?




Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3938
+  if ((FLAGS)&options::CC1Option) {
\
+const auto &Extracted = EXTRACTOR(this->KEYPATH);  
\
+if (ALWAYS_EMIT || Extracted != DEFAULT_VALUE) 
\

Bigcheese wrote:
> Will this ever have an issue with lifetime? I can see various values for 
> `EXTRACTOR` causing issues here. https://abseil.io/tips/107
> 
> 
> It would be good to at least document somewhere the restrictions on 
> `EXTRACTOR`.
Mentioned the reference lifetime extension in a comment near extractor 
definitions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83211

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


[PATCH] D75229: [clang-tidy] Add signal-in-multithreaded-program check

2020-11-16 Thread Kocsis Ábel via Phabricator via cfe-commits
abelkocsis added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SignalInMultithreadedProgramCheck.cpp:68
+const SourceManager &SM, Preprocessor *pp, Preprocessor *ModuleExpanderPP) 
{
+  PP = pp;
+}

whisperity wrote:
> Global state is always a potential problem. Are you sure this is the right 
> way to do things? Most other tidy checks that actively use this function 
> define their own `PPCallback` subclass and use the existing preprocessor here 
> to ensure the preprocessor executes the callback.
I've used the same way in another check (https://reviews.llvm.org/D69181). I'm 
not entirely sure which is the better way to do.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D75229

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


[PATCH] D91262: [AArch64][SVE] Allow C-style casts between fixed-size and scalable vectors

2020-11-16 Thread Peter Waller via Phabricator via cfe-commits
peterwaller-arm added inline comments.



Comment at: clang/lib/Sema/SemaCast.cpp:
   if (srcIsVector || destIsVector) {
+// We can bitcast between SVE VLATs and VLSTs, and vice-versa.
+if (Self.isValidSveBitcast(SrcType, DestType)) {

It's good to avoid use of pronouns such as "We" in comments like this, since a 
different reader might take a different interpretation of the word "We". Is 
"We" the software itself? Is it the company who wrote the condition? Better to 
rewrite it in a more direct way; in my suggestion it is written so that it's 
clearer the following statements are what allow it. Even better if you can 
include a reference to a spec indicating the background on why it is allowed.



Comment at: clang/lib/Sema/SemaCast.cpp:2762
+  // If either the src or dest are a vector, it's possible that we want to do 
an
+  // SVE bitcast. We can bitcast between SVE VLATs and VLSTs, and vice-versa.
+  if (SrcType->isVectorType() || DestType->isVectorType())

Another couple of uses of the word "we". Suggest taking Cullen's suggestion to 
combine the conditions and say:

"Allow bitcasting between compatible SVE vector types".



Comment at: clang/lib/Sema/SemaCast.cpp:2763
+  // SVE bitcast. We can bitcast between SVE VLATs and VLSTs, and vice-versa.
+  if (SrcType->isVectorType() || DestType->isVectorType())
+if (Self.isValidSveBitcast(SrcType, DestType)) {

c-rhodes wrote:
> I think braces are recommended on the outer if as well, see: 
> https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements
> 
> Although I suppose it could also be written as:
> 
> ```
> if ((SrcType->isVectorType() || DestType->isVectorType()) &&
> Self.isValidSveBitcast(SrcType, DestType)) {
>   Kind = CK_BitCast;
>   return;
> }```
I don't understand why this is an || rather than an &&, please can you clarify? 
I would have expected they must both be vectors.



Comment at: clang/lib/Sema/SemaExpr.cpp:7200
 
+/// Are the two types SVE-bitcast-compatible types? I.e. can we bitcast from 
the
+/// first SVE type (e.g. an SVE VLAT) to the second type (e.g. an SVE VLST)?

Use of "we".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91262

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


[PATCH] D91417: [IRGen] Add !annotation metadata for auto-init stores.

2020-11-16 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:1267
   assert(!isa(constant));
-  emitStoresForConstant(CGM, D, Loc, isVolatile, Builder, constant);
+  emitStoresForConstant(CGM, D, Loc, isVolatile, Builder, constant, true);
 }

jdoerfert wrote:
> Nit: `/* AutoInit */` also other places
Thanks, I added a comment to all places where constants are passed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91417

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


[PATCH] D91417: [IRGen] Add !annotation metadata for auto-init stores.

2020-11-16 Thread Florian Hahn 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 rGca2e7e59994d: [IRGen] Add !annotation metadata for auto-init 
stores. (authored by fhahn).

Changed prior to commit:
  https://reviews.llvm.org/D91417?vs=305110&id=305443#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91417

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGenCXX/auto-var-init.cpp
  clang/test/CodeGenCXX/trivial-auto-var-init-attribute.cpp
  clang/test/CodeGenCXX/trivial-auto-var-init.cpp
  llvm/include/llvm/IR/Instruction.h
  llvm/lib/IR/Metadata.cpp

Index: llvm/lib/IR/Metadata.cpp
===
--- llvm/lib/IR/Metadata.cpp
+++ llvm/lib/IR/Metadata.cpp
@@ -10,6 +10,7 @@
 //
 //===--===//
 
+#include "llvm/IR/Metadata.h"
 #include "LLVMContextImpl.h"
 #include "MetadataImpl.h"
 #include "SymbolTableListTraitsImpl.h"
@@ -38,7 +39,7 @@
 #include "llvm/IR/GlobalVariable.h"
 #include "llvm/IR/Instruction.h"
 #include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/Metadata.h"
+#include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/TrackingMDRef.h"
 #include "llvm/IR/Type.h"
@@ -1305,6 +1306,27 @@
   Value::setMetadata(KindID, Node);
 }
 
+void Instruction::addAnnotationMetadata(StringRef Name) {
+  MDBuilder MDB(getContext());
+
+  auto *Existing = getMetadata(LLVMContext::MD_annotation);
+  SmallVector Names;
+  bool AppendName = true;
+  if (Existing) {
+auto *Tuple = cast(Existing);
+for (auto &N : Tuple->operands()) {
+  if (cast(N.get())->getString() == Name)
+AppendName = false;
+  Names.push_back(N.get());
+}
+  }
+  if (AppendName)
+Names.push_back(MDB.createString(Name));
+
+  MDNode *MD = MDTuple::get(getContext(), Names);
+  setMetadata(LLVMContext::MD_annotation, MD);
+}
+
 void Instruction::setAAMetadata(const AAMDNodes &N) {
   setMetadata(LLVMContext::MD_tbaa, N.TBAA);
   setMetadata(LLVMContext::MD_tbaa_struct, N.TBAAStruct);
Index: llvm/include/llvm/IR/Instruction.h
===
--- llvm/include/llvm/IR/Instruction.h
+++ llvm/include/llvm/IR/Instruction.h
@@ -340,6 +340,11 @@
   }
   /// @}
 
+  /// Adds an !annotation metadata node with \p Annotation to this instruction.
+  /// If this instruction already has !annotation metadata, append \p Annotation
+  /// to the existing node.
+  void addAnnotationMetadata(StringRef Annotation);
+
   /// Sets the metadata on this instruction from the AAMDNodes structure.
   void setAAMetadata(const AAMDNodes &N);
 
Index: clang/test/CodeGenCXX/trivial-auto-var-init.cpp
===
--- clang/test/CodeGenCXX/trivial-auto-var-init.cpp
+++ clang/test/CodeGenCXX/trivial-auto-var-init.cpp
@@ -12,9 +12,9 @@
 
 // UNINIT-LABEL:  test_selfinit(
 // ZERO-LABEL:test_selfinit(
-// ZERO: store i32 0, i32* %self, align 4
+// ZERO: store i32 0, i32* %self, align 4, !annotation [[AUTO_INIT:!.+]]
 // PATTERN-LABEL: test_selfinit(
-// PATTERN: store i32 -1431655766, i32* %self, align 4
+// PATTERN: store i32 -1431655766, i32* %self, align 4, !annotation [[AUTO_INIT:!.+]]
 void test_selfinit() {
   int self = self + 1;
   used(self);
@@ -22,9 +22,9 @@
 
 // UNINIT-LABEL:  test_block(
 // ZERO-LABEL:test_block(
-// ZERO: store i32 0, i32* %block
+// ZERO: store i32 0, i32* %block, align 4, !annotation [[AUTO_INIT:!.+]]
 // PATTERN-LABEL: test_block(
-// PATTERN: store i32 -1431655766, i32* %block
+// PATTERN: store i32 -1431655766, i32* %block, align 4, !annotation [[AUTO_INIT:!.+]]
 void test_block() {
   __block int block;
   used(block);
@@ -38,12 +38,12 @@
 // ZERO-LABEL:test_block_self_init(
 // ZERO:  %block = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, align 8
 // ZERO:  %captured1 = getelementptr inbounds %struct.__block_byref_captured, %struct.__block_byref_captured* %captured, i32 0, i32 4
-// ZERO-NEXT: store %struct.XYZ* null, %struct.XYZ** %captured1, align 8
+// ZERO-NEXT: store %struct.XYZ* null, %struct.XYZ** %captured1, align 8, !annotation [[AUTO_INIT:!.+]]
 // ZERO:  %call = call %struct.XYZ* @create(
 // PATTERN-LABEL: test_block_self_init(
 // PATTERN:   %block = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, align 8
 // PATTERN:   %captured1 = getelementptr inbounds %struct.__block_byref_captured, %struct.__block_byref_captured* %captured, i32 0, i32 4
-// PATTERN-NEXT:  store %struct.XYZ* inttoptr (i64 -6148914691236517206 to %struct.XYZ*), %struct.XYZ** %captured1, align 8
+// PATTERN-NEXT:  store %struct.XYZ* inttoptr (i64 -6148914691236517206 to %struct.XYZ*), %struct.XYZ** %captured1, al

[PATCH] D89909: [SYCL] Implement SYCL address space attributes handling

2020-11-16 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D89909#2388622 , @bader wrote:

> In D89909#2353931 , @Anastasia wrote:
>
>> In the RFC it has been discussed to either use target address spaces or 
>> perhaps to introduce a new attribute to reflect a semantic needed for SYCL, 
>> but it seems to me in this change you are building on top of the existing 
>> language address space attribute with new entries for SYCL.
>>
>> http://lists.llvm.org/pipermail/cfe-dev/2020-August/066632.html
>
> Right, this patch adds new semantic attributes for SYCL and I left a comment 
> to decide whether we need a separate representation for parsed attribute and 
> spelling as well. Do you suggest adding SYCL specific spelling for these 
> attributes?
>
> WRT to a solution built on top of https://reviews.llvm.org/D62574, I'm 
> hesitate investing into this direction as it's not clear to me when we can 
> get this patch in (it's on review for 17 months already). I'd like to make 
> some progress with address space attributes to unblock upstreaming of other 
> changes depending on this change.
>
>> Has there been any other discussion regarding the approach which is not 
>> captured in the cfe-dev thread I have linked?
>
> I think everything is captured in the mailing list thread.

Did anyone conclude there that the language address spaces should be added for 
SYCL? I can't see any of this. In fact I don't even think there was any 
conclusion on the RFC. You should first make your design clear and agreed 
before going ahead with the implementation. I personally still think that 
address space AST attribute is not the right path for SYCL. And I haven't seen 
any evidence that it is the best solution to what you are trying to achieve.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89909

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


[PATCH] D90944: [clang-tidy] implement misc-mt-unsafe

2020-11-16 Thread Vasily Kulikov via Phabricator via cfe-commits
segoon updated this revision to Diff 305460.
segoon added a comment.

- minor changes to docs


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

https://reviews.llvm.org/D90944

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.cpp
  clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-mt-unsafe.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe-any.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe-glibc.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe-posix.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe-posix.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe-posix.cpp
@@ -0,0 +1,22 @@
+// RUN: %check_clang_tidy %s misc-mt-unsafe %t -- -config='{CheckOptions: [{key: "misc-mt-unsafe.Libc", value: "posix"}]}'
+
+extern unsigned int sleep (unsigned int __seconds);
+extern int *gmtime (const int *__timer);
+extern int *gmtime_r (const int *__timer, char*);
+extern char *dirname (char *__path);
+
+void foo() {
+  sleep(2);
+  ::sleep(2);
+
+  auto tm = gmtime(nullptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function is not thread safe [misc-mt-unsafe]
+  tm = ::gmtime(nullptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: function is not thread safe [misc-mt-unsafe]
+
+  tm = gmtime_r(nullptr, nullptr);
+  tm = ::gmtime_r(nullptr, nullptr);
+
+  dirname(nullptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function is not thread safe [misc-mt-unsafe]
+}
Index: clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe-glibc.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe-glibc.cpp
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s misc-mt-unsafe %t -- -config='{CheckOptions: [{key: "misc-mt-unsafe.Libc", value: "glibc"}]}'
+
+extern unsigned int sleep (unsigned int __seconds);
+extern int *gmtime (const int *__timer);
+extern char *dirname (char *__path);
+
+void foo() {
+  sleep(2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function is not thread safe [misc-mt-unsafe]
+
+  ::sleep(2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function is not thread safe [misc-mt-unsafe]
+
+  dirname(nullptr);
+}
Index: clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe-any.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-mt-unsafe-any.cpp
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s misc-mt-unsafe %t
+
+extern unsigned int sleep (unsigned int __seconds);
+extern int *gmtime (const int *__timer);
+extern int *gmtime_r (const int *__timer, char*);
+extern char *dirname (char *__path);
+
+void foo() {
+  sleep(2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function is not thread safe [misc-mt-unsafe]
+  ::sleep(2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function is not thread safe [misc-mt-unsafe]
+
+  auto tm = gmtime(nullptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function is not thread safe [misc-mt-unsafe]
+  tm = ::gmtime(nullptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: function is not thread safe [misc-mt-unsafe]
+
+  tm = gmtime_r(nullptr, nullptr);
+  tm = ::gmtime_r(nullptr, nullptr);
+
+  dirname(nullptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function is not thread safe [misc-mt-unsafe]
+}
Index: clang-tools-extra/docs/clang-tidy/checks/misc-mt-unsafe.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/misc-mt-unsafe.rst
@@ -0,0 +1,36 @@
+.. title:: clang-tidy - misc-mt-unsafe
+
+misc-mt-unsafe
+==
+
+Checks for some thread-unsafe functions against a black list of
+known-to-be-unsafe functions. Usually they access static variables without
+synchronization (e.g. gmtime(3)) or utilize signals in a racy way.
+The set of functions to check is specified with the `Libc` option.
+
+Examples:
+
+.. code-block:: c++
+
+tm = gmtime(timep); // uses a global buffer
+
+sleep(1); // implementation may use SIGALRM
+
+.. option:: Libc
+
+  Specifies which functions in libc should be considered thread-safe,
+  possible values are `posix`, `glibc`, or `any`.
+
+  `posix` means POSIX defined thread-unsafe functions. POSIX.1-2001
+  in "2.9.1 Thread-Safety" defines that all functions specified in the
+  standard are thread-safe except a predefined list of thread-unsafe
+  functions.
+
+  Glibc defines some of them as thread-safe (e.g. dirname(3)), but adds
+  non-POSIX thread-unsafe ones (e.g. getopt_long(3)). Glibc's list is
+  compiled from GNU web documentation wi

[PATCH] D90944: [clang-tidy] implement misc-mt-unsafe

2020-11-16 Thread Vasily Kulikov via Phabricator via cfe-commits
segoon added a comment.

In D90944#2380910 , @lebedev.ri wrote:

> What i would however like to be improved, is better docs.

I hope I'll addressed your questions in documentation. Please tell me whether 
you still have any unanswered questions.


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

https://reviews.llvm.org/D90944

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


[PATCH] D90944: [clang-tidy] implement misc-mt-unsafe

2020-11-16 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Just a general drive by point, is it wise to add a new tidy module to 
clang-tidy called `threads` (or similar). 
We have got a few other checks related to multi-threaded code in the pipeline 
(D77493 , D75229 
) that would fit perfectly for the same module.
Not to mention it would make it a lot easier to find checks specifically 
designed for multi-threaded workloads.


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

https://reviews.llvm.org/D90944

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


[PATCH] D91509: [clangd] Add AST config to prebuild ASTs

2020-11-16 Thread Daan De Meyer via Phabricator via cfe-commits
DaanDeMeyer updated this revision to Diff 305468.
DaanDeMeyer added a comment.

Fix tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91509

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/GlobalCompilationDatabase.h
  clang-tools-extra/clangd/QueryDriverDatabase.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
  clang-tools-extra/clangd/unittests/TestFS.cpp
  clang-tools-extra/clangd/unittests/TestFS.h

Index: clang-tools-extra/clangd/unittests/TestFS.h
===
--- clang-tools-extra/clangd/unittests/TestFS.h
+++ clang-tools-extra/clangd/unittests/TestFS.h
@@ -65,6 +65,8 @@
   llvm::Optional
   getCompileCommand(PathRef File) const override;
 
+  tooling::CompilationDatabase *lookupCDB(PathRef File) const override;
+
   llvm::Optional getProjectInfo(PathRef File) const override;
 
   std::vector ExtraClangFlags;
Index: clang-tools-extra/clangd/unittests/TestFS.cpp
===
--- clang-tools-extra/clangd/unittests/TestFS.cpp
+++ clang-tools-extra/clangd/unittests/TestFS.cpp
@@ -71,6 +71,11 @@
   FileName, std::move(CommandLine), "")};
 }
 
+tooling::CompilationDatabase *
+MockCompilationDatabase::lookupCDB(PathRef File) const {
+  return nullptr;
+}
+
 const char *testRoot() {
 #ifdef _WIN32
   return "C:\\clangd-test";
Index: clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
===
--- clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
+++ clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
@@ -70,6 +70,10 @@
   return None;
 }
 
+tooling::CompilationDatabase *lookupCDB(PathRef File) const override {
+  return nullptr;
+}
+
 tooling::CompileCommand
 getFallbackCommand(llvm::StringRef File) const override {
   return cmd(File, "-DA=2");
Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -1123,6 +1123,10 @@
   FileName, std::move(CommandLine), "")};
 }
 
+tooling::CompilationDatabase *lookupCDB(PathRef File) const override {
+  return nullptr;
+}
+
 std::vector ExtraClangFlags;
 
   private:
Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -231,6 +231,8 @@
   /// Returns true if the file was not previously tracked.
   bool update(PathRef File, ParseInputs Inputs, WantDiagnostics WD);
 
+  bool hasFile(PathRef File);
+
   /// Remove \p File from the list of tracked files and schedule removal of its
   /// resources. Pending diagnostics for closed files may not be delivered, even
   /// if requested with WantDiags::Auto or WantDiags::Yes.
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -1289,6 +1289,8 @@
   return NewFile;
 }
 
+bool TUScheduler::hasFile(PathRef File) { return Files[File] == nullptr; }
+
 void TUScheduler::remove(PathRef File) {
   bool Removed = Files.erase(File);
   if (!Removed)
Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -277,6 +277,10 @@
 return addSystemIncludes(*Cmd, SystemIncludes);
   }
 
+  tooling::CompilationDatabase *lookupCDB(PathRef File) const override {
+return Base->lookupCDB(File);
+  }
+
   llvm::Optional getProjectInfo(PathRef File) const override {
 return Base->getProjectInfo(File);
   }
Index: clang-tools-extra/clangd/GlobalCompilationDatabase.h
===
--- clang-tools-extra/clangd/GlobalCompilationDatabase.h
+++ clang-tools-extra/clangd/GlobalCompilationDatabase.h
@@ -40,6 +40,8 @@
   virtual llvm::Optional
   getCompileCommand(PathRef File) const = 0;
 
+  virtual tooling::CompilationDatabase *lookupCDB(PathRef File) const = 0;
+
  

[clang] 6c185ac - Revert "Move the test compiler setup in a common place. NFCI"

2020-11-16 Thread Vitaly Buka via cfe-commits

Author: Vitaly Buka
Date: 2020-11-16T04:21:28-08:00
New Revision: 6c185acfffc1f7cdf2a6e785cb4a422140c34f06

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

LOG: Revert "Move the test compiler setup in a common place. NFCI"

There is memory leaks

This reverts commit 23cc838099e10b13a32e54105f4db0f1b7e3a842.
This reverts commit 888d06dfb8b55c4fd41fa4febe22c6fc4111c118.

Added: 


Modified: 
clang/unittests/CodeGen/BufferSourceTest.cpp
clang/unittests/CodeGen/CodeGenExternalTest.cpp
clang/unittests/CodeGen/IncrementalProcessingTest.cpp
clang/unittests/CodeGen/TBAAMetadataTest.cpp

Removed: 
clang/unittests/CodeGen/TestCompiler.h



diff  --git a/clang/unittests/CodeGen/BufferSourceTest.cpp 
b/clang/unittests/CodeGen/BufferSourceTest.cpp
index 3ed688a72185..c1c2bf818c02 100644
--- a/clang/unittests/CodeGen/BufferSourceTest.cpp
+++ b/clang/unittests/CodeGen/BufferSourceTest.cpp
@@ -6,8 +6,7 @@
 //
 
//===--===//
 
-#include "TestCompiler.h"
-
+#include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/TargetInfo.h"
@@ -27,11 +26,10 @@ using namespace clang;
 
 namespace {
 
-TEST(BufferSourceTest, EmitCXXGlobalInitFunc) {
-  // Emitting constructors for global objects involves looking
-  // at the source file name. This makes sure that we don't crash
-  // if the source file is a memory buffer.
-  const char TestProgram[] =
+// Emitting constructors for global objects involves looking
+// at the source file name. This makes sure that we don't crash
+// if the source file is a memory buffer.
+const char TestProgram[] =
 "class EmitCXXGlobalInitFunc"
 "{  "
 "public:"
@@ -39,13 +37,43 @@ TEST(BufferSourceTest, EmitCXXGlobalInitFunc) {
 "}; "
 "EmitCXXGlobalInitFunc test;";
 
-  clang::LangOptions LO;
-  LO.CPlusPlus = 1;
-  LO.CPlusPlus11 = 1;
-  TestCompiler Compiler(LO);
-  Compiler.init(TestProgram);
+TEST(BufferSourceTest, EmitCXXGlobalInitFunc) {
+LLVMContext Context;
+CompilerInstance compiler;
+
+compiler.createDiagnostics();
+compiler.getLangOpts().CPlusPlus = 1;
+compiler.getLangOpts().CPlusPlus11 = 1;
+
+compiler.getTargetOpts().Triple = llvm::Triple::normalize(
+llvm::sys::getProcessTriple());
+compiler.setTarget(clang::TargetInfo::CreateTargetInfo(
+  compiler.getDiagnostics(),
+  std::make_shared(
+compiler.getTargetOpts(;
+
+compiler.createFileManager();
+compiler.createSourceManager(compiler.getFileManager());
+compiler.createPreprocessor(clang::TU_Prefix);
+
+compiler.createASTContext();
+
+compiler.setASTConsumer(std::unique_ptr(
+CreateLLVMCodeGen(
+compiler.getDiagnostics(),
+"EmitCXXGlobalInitFuncTest",
+compiler.getHeaderSearchOpts(),
+compiler.getPreprocessorOpts(),
+compiler.getCodeGenOpts(),
+Context)));
+
+compiler.createSema(clang::TU_Prefix, nullptr);
+
+clang::SourceManager &sm = compiler.getSourceManager();
+sm.setMainFileID(sm.createFileID(
+llvm::MemoryBuffer::getMemBuffer(TestProgram), clang::SrcMgr::C_User));
 
-  clang::ParseAST(Compiler.compiler.getSema(), false, false);
+clang::ParseAST(compiler.getSema(), false, false);
 }
 
 } // end anonymous namespace

diff  --git a/clang/unittests/CodeGen/CodeGenExternalTest.cpp 
b/clang/unittests/CodeGen/CodeGenExternalTest.cpp
index bb5f7463e9b1..255b8c3e9d8c 100644
--- a/clang/unittests/CodeGen/CodeGenExternalTest.cpp
+++ b/clang/unittests/CodeGen/CodeGenExternalTest.cpp
@@ -6,8 +6,6 @@
 //
 
//===--===//
 
-#include "TestCompiler.h"
-
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/GlobalDecl.h"
@@ -52,11 +50,11 @@ static bool test_codegen_fns_ran;
 // before forwarding that function to the CodeGenerator.
 
 struct MyASTConsumer : public ASTConsumer {
-  CodeGenerator* Builder;
+  std::unique_ptr Builder;
   std::vector toplevel_decls;
 
-  MyASTConsumer(CodeGenerator* Builder_in)
-: ASTConsumer(), Builder(Builder_in)
+  MyASTConsumer(std::unique_ptr Builder_in)
+: ASTConsumer(), Builder(std::move(Builder_in))
   {
   }
 
@@ -259,17 +257,45 @@ static void test_codegen_fns(MyASTConsumer *my) {
 }
 
 TEST(CodeGenExternalTest, CodeGenExternalTest) {
-  clang::LangOptions LO;
-  LO.CPlusPlus = 1;
-  LO.CPlusPlus11 = 1;
-  TestCompiler Compiler(LO);
-  auto CustomASTConsumer = std::make_unique(Compiler.CG);
+LLVMContext Context;
+CompilerInstance 

[PATCH] D91061: Move the test compiler setup in a common place. NFCI

2020-11-16 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka reopened this revision.
vitalybuka added a comment.
This revision is now accepted and ready to land.

Reverted because of memory leaks: 
http://lab.llvm.org:8011/#/builders/5/builds/1262


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91061

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


[PATCH] D90944: [clang-tidy] implement misc-mt-unsafe

2020-11-16 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

`Libc` option name doesn't really make sense to me, maybe `FunctionSet` would 
fit better.




Comment at: clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.cpp:32-33
+
+// Initial list was extracted from gcc documentation
+static const StringRef glibcFunctions[] = {
+"::argp_error",

I would expect this can be outside of all the namespaces right after `using 
namespace clang::ast_matchers;`



Comment at: clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.cpp:287-288
+
+static ast_matchers::internal::Matcher
+hasAnyMtUnsafeNames(MtUnsafeCheck::LibcType libc) {
+  switch (libc) {

Likewise, i would expect this can be outside of namespaces



Comment at: clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.cpp:295
+  case MtUnsafeCheck::LibcType::Any:
+return hasAnyName(anyFunctions);
+  }

return anyOf(hasAnyName(posixFunctions), hasAnyName(glibcFunctions));



Comment at: clang-tools-extra/clang-tidy/misc/MtUnsafeCheck.cpp:309-310
+void MtUnsafeCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(callExpr(callee(functionDecl(hasAnyMtUnsafeNames(Libc
+ .bind("mt-unsafe"),
+ this);

Is there any way to invert the direction of this matcher,
instead of checking each call that it's callee isn't one of the bad ones,
look through all function decls, and for all the bad ones, diagnose all calls 
to them?



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:111
+
+  Finds thread-unsafe functions usage.
+

<...>, Currently knows about POSIX and GLIBC.

or something along those lines


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

https://reviews.llvm.org/D90944

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


[PATCH] D91506: [NFC, Refactor] Convert TypeSpecifiersPipe from Specifiers.h to a scoped enum (tiny)

2020-11-16 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! Would you like me to commit this one on your behalf or would you like to 
request your own commit access 
(https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91506

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


[PATCH] D91506: [NFC, Refactor] Convert TypeSpecifiersPipe from Specifiers.h to a scoped enum (tiny)

2020-11-16 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

I am happy, if you could commit this for me. I am still learning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91506

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


[PATCH] D91061: Move the test compiler setup in a common place. NFCI

2020-11-16 Thread Vassil Vassilev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG54e655b3f8dc: Reland "Move the test compiler setup in a 
common place. NFCI" (authored by v.g.vassilev).

Changed prior to commit:
  https://reviews.llvm.org/D91061?vs=305327&id=305483#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91061

Files:
  clang/unittests/CodeGen/BufferSourceTest.cpp
  clang/unittests/CodeGen/CodeGenExternalTest.cpp
  clang/unittests/CodeGen/IncrementalProcessingTest.cpp
  clang/unittests/CodeGen/TBAAMetadataTest.cpp
  clang/unittests/CodeGen/TestCompiler.h

Index: clang/unittests/CodeGen/TestCompiler.h
===
--- /dev/null
+++ clang/unittests/CodeGen/TestCompiler.h
@@ -0,0 +1,111 @@
+//=== unittests/CodeGen/TestCompiler.h - Match on the LLVM IR ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef CLANG_UNITTESTS_CODEGEN_TESTCOMPILER_H
+#define CLANG_UNITTESTS_CODEGEN_TESTCOMPILER_H
+
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "clang/CodeGen/ModuleBuilder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Parse/ParseAST.h"
+
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/Host.h"
+
+namespace llvm {
+
+struct TestCompiler {
+  LLVMContext Context;
+  clang::CompilerInstance compiler;
+  std::unique_ptr CG;
+  llvm::Module *M = nullptr;
+  unsigned PtrSize = 0;
+
+  TestCompiler(clang::LangOptions LO,
+   clang::CodeGenOptions CGO = clang::CodeGenOptions()) {
+compiler.getLangOpts() = LO;
+compiler.getCodeGenOpts() = CGO;
+compiler.createDiagnostics();
+
+std::string TrStr = llvm::Triple::normalize(llvm::sys::getProcessTriple());
+llvm::Triple Tr(TrStr);
+Tr.setOS(Triple::Linux);
+Tr.setVendor(Triple::VendorType::UnknownVendor);
+Tr.setEnvironment(Triple::EnvironmentType::UnknownEnvironment);
+compiler.getTargetOpts().Triple = Tr.getTriple();
+compiler.setTarget(clang::TargetInfo::CreateTargetInfo(
+compiler.getDiagnostics(),
+std::make_shared(compiler.getTargetOpts(;
+
+const clang::TargetInfo &TInfo = compiler.getTarget();
+PtrSize = TInfo.getPointerWidth(0) / 8;
+
+compiler.createFileManager();
+compiler.createSourceManager(compiler.getFileManager());
+compiler.createPreprocessor(clang::TU_Prefix);
+
+compiler.createASTContext();
+
+CG.reset(CreateLLVMCodeGen(compiler.getDiagnostics(),
+   "main-module",
+   compiler.getHeaderSearchOpts(),
+   compiler.getPreprocessorOpts(),
+   compiler.getCodeGenOpts(),
+   Context));
+  }
+
+  void init(const char *TestProgram,
+std::unique_ptr Consumer = nullptr) {
+if (!Consumer)
+  Consumer = std::move(CG);
+
+compiler.setASTConsumer(std::move(Consumer));
+
+compiler.createSema(clang::TU_Prefix, nullptr);
+
+clang::SourceManager &sm = compiler.getSourceManager();
+sm.setMainFileID(sm.createFileID(
+llvm::MemoryBuffer::getMemBuffer(TestProgram), clang::SrcMgr::C_User));
+  }
+
+  const BasicBlock *compile() {
+clang::ParseAST(compiler.getSema(), false, false);
+M =
+  static_cast(compiler.getASTConsumer()).GetModule();
+
+// Do not expect more than one function definition.
+auto FuncPtr = M->begin();
+for (; FuncPtr != M->end(); ++FuncPtr)
+  if (!FuncPtr->isDeclaration())
+break;
+assert(FuncPtr != M->end());
+const llvm::Function &Func = *FuncPtr;
+++FuncPtr;
+for (; FuncPtr != M->end(); ++FuncPtr)
+  if (!FuncPtr->isDeclaration())
+break;
+assert(FuncPtr == M->end());
+
+// The function must consist of single basic block.
+auto BBPtr = Func.begin();
+assert(Func.begin() != Func.end());
+const BasicBlock &BB = *BBPtr;
+++BBPtr;
+assert(BBPtr == Func.end());
+
+return &BB;
+  }
+};
+
+} // namespace llvm
+#endif // CLANG_UNITTESTS_CODEGEN_TESTCOMPILER_H
Index: clang/unittests/CodeGen/TBAAMetadataTest.cpp
===
--- clang/unittests/CodeGen/TBAAMetadataTest.cpp
+++ clang/unittests/CodeGen/TBAAMetadataTest.cpp
@@ -7,18 +7,12 @@
 //===--===//
 
 #include "IRMatchers.h"
+#include "TestCompiler.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "

[clang] 54e655b - Reland "Move the test compiler setup in a common place. NFCI"

2020-11-16 Thread Vassil Vassilev via cfe-commits

Author: Vassil Vassilev
Date: 2020-11-16T13:22:10Z
New Revision: 54e655b3f8dc1d005655d9138880f3823d58224f

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

LOG: Reland "Move the test compiler setup in a common place. NFCI"

Original commit message: "
Move the test compiler setup in a common place. NFCI

This patch reduces the copy paste in the unittest/CodeGen folder by moving the
common compiler setup phase in a header file.

Differential revision: https://reviews.llvm.org/D91061
"

This patch includes a fix for the memory leaks pointed out by @vitalybuka

Added: 
clang/unittests/CodeGen/TestCompiler.h

Modified: 
clang/unittests/CodeGen/BufferSourceTest.cpp
clang/unittests/CodeGen/CodeGenExternalTest.cpp
clang/unittests/CodeGen/IncrementalProcessingTest.cpp
clang/unittests/CodeGen/TBAAMetadataTest.cpp

Removed: 




diff  --git a/clang/unittests/CodeGen/BufferSourceTest.cpp 
b/clang/unittests/CodeGen/BufferSourceTest.cpp
index c1c2bf818c02..3ed688a72185 100644
--- a/clang/unittests/CodeGen/BufferSourceTest.cpp
+++ b/clang/unittests/CodeGen/BufferSourceTest.cpp
@@ -6,7 +6,8 @@
 //
 
//===--===//
 
-#include "clang/AST/ASTConsumer.h"
+#include "TestCompiler.h"
+
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/TargetInfo.h"
@@ -26,10 +27,11 @@ using namespace clang;
 
 namespace {
 
-// Emitting constructors for global objects involves looking
-// at the source file name. This makes sure that we don't crash
-// if the source file is a memory buffer.
-const char TestProgram[] =
+TEST(BufferSourceTest, EmitCXXGlobalInitFunc) {
+  // Emitting constructors for global objects involves looking
+  // at the source file name. This makes sure that we don't crash
+  // if the source file is a memory buffer.
+  const char TestProgram[] =
 "class EmitCXXGlobalInitFunc"
 "{  "
 "public:"
@@ -37,43 +39,13 @@ const char TestProgram[] =
 "}; "
 "EmitCXXGlobalInitFunc test;";
 
-TEST(BufferSourceTest, EmitCXXGlobalInitFunc) {
-LLVMContext Context;
-CompilerInstance compiler;
-
-compiler.createDiagnostics();
-compiler.getLangOpts().CPlusPlus = 1;
-compiler.getLangOpts().CPlusPlus11 = 1;
-
-compiler.getTargetOpts().Triple = llvm::Triple::normalize(
-llvm::sys::getProcessTriple());
-compiler.setTarget(clang::TargetInfo::CreateTargetInfo(
-  compiler.getDiagnostics(),
-  std::make_shared(
-compiler.getTargetOpts(;
-
-compiler.createFileManager();
-compiler.createSourceManager(compiler.getFileManager());
-compiler.createPreprocessor(clang::TU_Prefix);
-
-compiler.createASTContext();
-
-compiler.setASTConsumer(std::unique_ptr(
-CreateLLVMCodeGen(
-compiler.getDiagnostics(),
-"EmitCXXGlobalInitFuncTest",
-compiler.getHeaderSearchOpts(),
-compiler.getPreprocessorOpts(),
-compiler.getCodeGenOpts(),
-Context)));
-
-compiler.createSema(clang::TU_Prefix, nullptr);
-
-clang::SourceManager &sm = compiler.getSourceManager();
-sm.setMainFileID(sm.createFileID(
-llvm::MemoryBuffer::getMemBuffer(TestProgram), clang::SrcMgr::C_User));
+  clang::LangOptions LO;
+  LO.CPlusPlus = 1;
+  LO.CPlusPlus11 = 1;
+  TestCompiler Compiler(LO);
+  Compiler.init(TestProgram);
 
-clang::ParseAST(compiler.getSema(), false, false);
+  clang::ParseAST(Compiler.compiler.getSema(), false, false);
 }
 
 } // end anonymous namespace

diff  --git a/clang/unittests/CodeGen/CodeGenExternalTest.cpp 
b/clang/unittests/CodeGen/CodeGenExternalTest.cpp
index 255b8c3e9d8c..4358a9f285b2 100644
--- a/clang/unittests/CodeGen/CodeGenExternalTest.cpp
+++ b/clang/unittests/CodeGen/CodeGenExternalTest.cpp
@@ -6,6 +6,8 @@
 //
 
//===--===//
 
+#include "TestCompiler.h"
+
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/GlobalDecl.h"
@@ -257,45 +259,18 @@ static void test_codegen_fns(MyASTConsumer *my) {
 }
 
 TEST(CodeGenExternalTest, CodeGenExternalTest) {
-LLVMContext Context;
-CompilerInstance compiler;
-
-compiler.createDiagnostics();
-compiler.getLangOpts().CPlusPlus = 1;
-compiler.getLangOpts().CPlusPlus11 = 1;
-
-compiler.getTargetOpts().Triple = llvm::Triple::normalize(
-llvm::sys::getProcessTriple());
-compiler.setTarget(clang::TargetInfo::CreateTargetInfo(
-  compiler.getDiagnostics(),
-  std::make_shared(
-compiler.getTargetOpts(;
-
-compiler.createFileManage

[PATCH] D91506: [NFC, Refactor] Convert TypeSpecifiersPipe from Specifiers.h to a scoped enum (tiny)

2020-11-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D91506#2397158 , @tschuett wrote:

> I am happy, if you could commit this for me. I am still learning.

I'm happy to do so -- how would you like me to attribute the patch? Is 
`Thorsten ` what you'd like me to use?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91506

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


[PATCH] D91506: [NFC, Refactor] Convert TypeSpecifiersPipe from Specifiers.h to a scoped enum (tiny)

2020-11-16 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

Yes. Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91506

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


[clang] a6ac2b3 - Convert TypeSpecifiersPipe from Specifiers.h to a scoped enum; NFC

2020-11-16 Thread Aaron Ballman via cfe-commits

Author: Thorsten
Date: 2020-11-16T08:28:21-05:00
New Revision: a6ac2b32fbab9679c8f2fa97a3b1123e3a9654c8

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

LOG: Convert TypeSpecifiersPipe from Specifiers.h to a scoped enum; NFC

Added: 


Modified: 
clang/include/clang/Basic/Specifiers.h
clang/lib/Sema/DeclSpec.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Specifiers.h 
b/clang/include/clang/Basic/Specifiers.h
index cdd67a688283..ed468db1dc8a 100644
--- a/clang/include/clang/Basic/Specifiers.h
+++ b/clang/include/clang/Basic/Specifiers.h
@@ -46,10 +46,7 @@ namespace clang {
 TSS_unsigned
   };
 
-  enum TypeSpecifiersPipe {
-TSP_unspecified,
-TSP_pipe
-  };
+  enum class TypeSpecifiersPipe { Unspecified, Pipe };
 
   /// Specifies the kind of type.
   enum TypeSpecifierType {

diff  --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 012479356122..73a6137ce897 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -877,7 +877,7 @@ bool DeclSpec::SetTypePipe(bool isPipe, SourceLocation Loc,
   }
 
   if (isPipe) {
-TypeSpecPipe = TSP_pipe;
+TypeSpecPipe = static_cast(TypeSpecifiersPipe::Pipe);
   }
   return false;
 }



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


[PATCH] D91506: [NFC, Refactor] Convert TypeSpecifiersPipe from Specifiers.h to a scoped enum (tiny)

2020-11-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

In D91506#2397181 , @tschuett wrote:

> Yes. Thank you!

You're welcome! I've commit on your behalf in 
a6ac2b32fbab9679c8f2fa97a3b1123e3a9654c8 
, thank 
you for the patch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91506

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


[PATCH] D91498: [NFC, Refactor] Convert TypeSpecifierSign from Specifiers.h to a scoped enum

2020-11-16 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! I'll land on your behalf momentarily.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91498

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


[PATCH] D91498: [NFC, Refactor] Convert TypeSpecifierSign from Specifiers.h to a scoped enum

2020-11-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D91498#2397187 , @aaron.ballman 
wrote:

> LGTM! I'll land on your behalf momentarily.

I lied. The patch doesn't apply cleanly for me -- can you rebase and upload a 
new diff?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91498

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


[PATCH] D91428: Add support for multiple program address spaces

2020-11-16 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 305488.
pmatos added a comment.

Ensure the program address spaces vector doesn't contain duplicates.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91428

Files:
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  llvm/docs/LangRef.rst
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/include/llvm/IR/DataLayout.h
  llvm/include/llvm/Target/TargetMachine.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLParser.h
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/DataLayout.cpp
  llvm/lib/IR/Function.cpp
  llvm/lib/IR/Module.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/Assembler/function-address_spaces.ll

Index: llvm/test/Assembler/function-address_spaces.ll
===
--- /dev/null
+++ llvm/test/Assembler/function-address_spaces.ll
@@ -0,0 +1,30 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck  %s
+
+; specifying explicitly P:0 (although it's the default)
+; P:1 specifies an extra address space for code where funcrefs live
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1-P0-P1"
+
+; square and double_square are in addrspace(0)
+define i32 @square(i32 %0) {
+; CHECK: define i32 @square(i32 %0) addrspace(0) {
+   %2 = mul nsw i32 %0, %0
+   ret i32 %2
+}
+
+define i32 @double_square(i32 %0) {
+; CHECK: define i32 @double_square(i32 %0) addrspace(0) {
+   %2 = shl i32 %0, 1
+   %3 = mul i32 %2, %0
+   ret i32 %3
+}
+
+; funcref is a pointer to a function in addrspace(1)
+; called in call_funcref
+%func = type void ()
+%funcref = type %func addrspace(1)*
+
+define void @call_funcref(%funcref %ref) {
+; CHECK: define void @call_funcref(void () addrspace(1)* %ref) addrspace(0) {
+   call void %ref()
+   ret void
+}
Index: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
===
--- llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -1220,12 +1220,12 @@
   Function *JT;
   if (isa(Slot.TypeID)) {
 JT = Function::Create(FT, Function::ExternalLinkage,
-  M.getDataLayout().getProgramAddressSpace(),
+  M.getDataLayout().getDefaultProgramAddressSpace(),
   getGlobalName(Slot, {}, "branch_funnel"), &M);
 JT->setVisibility(GlobalValue::HiddenVisibility);
   } else {
 JT = Function::Create(FT, Function::InternalLinkage,
-  M.getDataLayout().getProgramAddressSpace(),
+  M.getDataLayout().getDefaultProgramAddressSpace(),
   "branch_funnel", &M);
   }
   JT->addAttribute(1, Attribute::Nest);
Index: llvm/lib/Transforms/IPO/LowerTypeTests.cpp
===
--- llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -1276,12 +1276,12 @@
 void LowerTypeTestsModule::moveInitializerToModuleConstructor(
 GlobalVariable *GV) {
   if (WeakInitializerFn == nullptr) {
-WeakInitializerFn = Function::Create(
-FunctionType::get(Type::getVoidTy(M.getContext()),
-  /* IsVarArg */ false),
-GlobalValue::InternalLinkage,
-M.getDataLayout().getProgramAddressSpace(),
-"__cfi_global_var_init", &M);
+WeakInitializerFn =
+Function::Create(FunctionType::get(Type::getVoidTy(M.getContext()),
+   /* IsVarArg */ false),
+ GlobalValue::InternalLinkage,
+ M.getDataLayout().getDefaultProgramAddressSpace(),
+ "__cfi_global_var_init", &M);
 BasicBlock *BB =
 BasicBlock::Create(M.getContext(), "entry", WeakInitializerFn);
 ReturnInst::Create(M.getContext(), BB);
@@ -1517,12 +1517,11 @@
   for (unsigned I = 0; I != Functions.size(); ++I)
 GlobalLayout[Functions[I]] = I * EntrySize;
 
-  Function *JumpTableFn =
-  Function::Create(FunctionType::get(Type::getVoidTy(M.getContext()),
- /* IsVarArg */ false),
-   GlobalValue::PrivateLinkage,
-   M.getDataLayout().getProgramAddressSpace(),
-   ".cfi.jumptable", &M);
+  Function *JumpTableFn = Function::Create(
+  FunctionType::get(Type::getVoidTy(M.getContext()),
+/* IsVarArg */ false),
+  GlobalValue::PrivateLinkage,
+  M.getDataLayout().getDefaultProgramAddressSpace(), ".cfi.jumptable", &M);
   ArrayType *JumpTableType =
   ArrayType::get(getJumpTableEntryType(), Functions.size());
   auto JumpTable =
@@ -1962,

[PATCH] D91509: [clangd] Add AST config to prebuild ASTs

2020-11-16 Thread Daan De Meyer via Phabricator via cfe-commits
DaanDeMeyer updated this revision to Diff 305489.
DaanDeMeyer added a comment.

Fix all the bugs after doing some proper testing.

One thing we don't handle yet is header files since those don't appear in the 
compilation database. Maybe we need to add prebuilding for those as well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91509

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/GlobalCompilationDatabase.h
  clang-tools-extra/clangd/QueryDriverDatabase.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
  clang-tools-extra/clangd/unittests/TestFS.cpp
  clang-tools-extra/clangd/unittests/TestFS.h

Index: clang-tools-extra/clangd/unittests/TestFS.h
===
--- clang-tools-extra/clangd/unittests/TestFS.h
+++ clang-tools-extra/clangd/unittests/TestFS.h
@@ -65,6 +65,8 @@
   llvm::Optional
   getCompileCommand(PathRef File) const override;
 
+  tooling::CompilationDatabase *lookupCDB(PathRef File) const override;
+
   llvm::Optional getProjectInfo(PathRef File) const override;
 
   std::vector ExtraClangFlags;
Index: clang-tools-extra/clangd/unittests/TestFS.cpp
===
--- clang-tools-extra/clangd/unittests/TestFS.cpp
+++ clang-tools-extra/clangd/unittests/TestFS.cpp
@@ -71,6 +71,11 @@
   FileName, std::move(CommandLine), "")};
 }
 
+tooling::CompilationDatabase *
+MockCompilationDatabase::lookupCDB(PathRef File) const {
+  return nullptr;
+}
+
 const char *testRoot() {
 #ifdef _WIN32
   return "C:\\clangd-test";
Index: clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
===
--- clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
+++ clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
@@ -70,6 +70,10 @@
   return None;
 }
 
+tooling::CompilationDatabase *lookupCDB(PathRef File) const override {
+  return nullptr;
+}
+
 tooling::CompileCommand
 getFallbackCommand(llvm::StringRef File) const override {
   return cmd(File, "-DA=2");
Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -1123,6 +1123,10 @@
   FileName, std::move(CommandLine), "")};
 }
 
+tooling::CompilationDatabase *lookupCDB(PathRef File) const override {
+  return nullptr;
+}
+
 std::vector ExtraClangFlags;
 
   private:
Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -231,6 +231,8 @@
   /// Returns true if the file was not previously tracked.
   bool update(PathRef File, ParseInputs Inputs, WantDiagnostics WD);
 
+  bool hasFile(PathRef File);
+
   /// Remove \p File from the list of tracked files and schedule removal of its
   /// resources. Pending diagnostics for closed files may not be delivered, even
   /// if requested with WantDiags::Auto or WantDiags::Yes.
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -627,11 +627,15 @@
   FileInputs = Inputs;
 }
 
-log("ASTWorker building file {0} version {1} with command {2}\n[{3}]\n{4}",
+log("ASTWorker building file {0} version {1}", FileName, Inputs.Version);
+vlog("ASTWorker building file {0} version {1} with command {2}\n[{3}]\n{4}",
 FileName, Inputs.Version, Inputs.CompileCommand.Heuristic,
 Inputs.CompileCommand.Directory,
 llvm::join(Inputs.CompileCommand.CommandLine, " "));
 
+if (!InputsAreTheSame)
+  log("ASTWorker inputs are not the same, cached AST is invalidated");
+
 StoreDiags CompilerInvocationDiagConsumer;
 std::vector CC1Args;
 std::unique_ptr Invocation = buildCompilerInvocation(
@@ -1289,6 +1293,8 @@
   return NewFile;
 }
 
+bool TUScheduler::hasFile(PathRef File) { return Files[File] != nullptr; }
+
 void TUScheduler::remove(PathRef File) {
   bool Removed = Files.erase(File);
   if (!Removed)
Index: clang-tools-extra/clangd/QueryDrive

[PATCH] D91498: [NFC, Refactor] Convert TypeSpecifierSign from Specifiers.h to a scoped enum

2020-11-16 Thread Thorsten via Phabricator via cfe-commits
tschuett updated this revision to Diff 305490.
tschuett added a comment.

rebased


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

https://reviews.llvm.org/D91498

Files:
  clang/include/clang/AST/TypeLoc.h
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -198,7 +198,7 @@
   Record.AddSourceLocation(TL.getBuiltinLoc());
   if (TL.needsExtraLocalData()) {
 Record.push_back(TL.getWrittenTypeSpec());
-Record.push_back(TL.getWrittenSignSpec());
+Record.push_back(static_cast(TL.getWrittenSignSpec()));
 Record.push_back(static_cast(TL.getWrittenWidthSpec()));
 Record.push_back(TL.hasModeAttr());
   }
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -6457,7 +6457,7 @@
   TL.setBuiltinLoc(readSourceLocation());
   if (TL.needsExtraLocalData()) {
 TL.setWrittenTypeSpec(static_cast(Reader.readInt()));
-TL.setWrittenSignSpec(static_cast(Reader.readInt()));
+TL.setWrittenSignSpec(static_cast(Reader.readInt()));
 TL.setWrittenWidthSpec(static_cast(Reader.readInt()));
 TL.setModeAttr(Reader.readInt());
   }
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1300,27 +1300,27 @@
 Result = Context.VoidTy;
 break;
   case DeclSpec::TST_char:
-if (DS.getTypeSpecSign() == DeclSpec::TSS_unspecified)
+if (DS.getTypeSpecSign() == TypeSpecifierSign::Unspecified)
   Result = Context.CharTy;
-else if (DS.getTypeSpecSign() == DeclSpec::TSS_signed)
+else if (DS.getTypeSpecSign() == TypeSpecifierSign::Signed)
   Result = Context.SignedCharTy;
 else {
-  assert(DS.getTypeSpecSign() == DeclSpec::TSS_unsigned &&
+  assert(DS.getTypeSpecSign() == TypeSpecifierSign::Unsigned &&
  "Unknown TSS value");
   Result = Context.UnsignedCharTy;
 }
 break;
   case DeclSpec::TST_wchar:
-if (DS.getTypeSpecSign() == DeclSpec::TSS_unspecified)
+if (DS.getTypeSpecSign() == TypeSpecifierSign::Unspecified)
   Result = Context.WCharTy;
-else if (DS.getTypeSpecSign() == DeclSpec::TSS_signed) {
+else if (DS.getTypeSpecSign() == TypeSpecifierSign::Signed) {
   S.Diag(DS.getTypeSpecSignLoc(), diag::ext_wchar_t_sign_spec)
 << DS.getSpecifierName(DS.getTypeSpecType(),
Context.getPrintingPolicy());
   Result = Context.getSignedWCharType();
 } else {
-  assert(DS.getTypeSpecSign() == DeclSpec::TSS_unsigned &&
-"Unknown TSS value");
+  assert(DS.getTypeSpecSign() == TypeSpecifierSign::Unsigned &&
+ "Unknown TSS value");
   S.Diag(DS.getTypeSpecSignLoc(), diag::ext_wchar_t_sign_spec)
 << DS.getSpecifierName(DS.getTypeSpecType(),
Context.getPrintingPolicy());
@@ -1328,19 +1328,19 @@
 }
 break;
   case DeclSpec::TST_char8:
-  assert(DS.getTypeSpecSign() == DeclSpec::TSS_unspecified &&
-"Unknown TSS value");
-  Result = Context.Char8Ty;
+assert(DS.getTypeSpecSign() == TypeSpecifierSign::Unspecified &&
+   "Unknown TSS value");
+Result = Context.Char8Ty;
 break;
   case DeclSpec::TST_char16:
-  assert(DS.getTypeSpecSign() == DeclSpec::TSS_unspecified &&
-"Unknown TSS value");
-  Result = Context.Char16Ty;
+assert(DS.getTypeSpecSign() == TypeSpecifierSign::Unspecified &&
+   "Unknown TSS value");
+Result = Context.Char16Ty;
 break;
   case DeclSpec::TST_char32:
-  assert(DS.getTypeSpecSign() == DeclSpec::TSS_unspecified &&
-"Unknown TSS value");
-  Result = Context.Char32Ty;
+assert(DS.getTypeSpecSign() == TypeSpecifierSign::Unspecified &&
+   "Unknown TSS value");
+Result = Context.Char32Ty;
 break;
   case DeclSpec::TST_unspecified:
 // If this is a missing declspec in a block literal return context, then it
@@ -1401,7 +1401,7 @@
 
 LLVM_FALLTHROUGH;
   case DeclSpec::TST_int: {
-if (DS.getTypeSpecSign() != DeclSpec::TSS_unsigned) {
+if (DS.getTypeSpecSign() != TypeSpecifierSign::Unsigned) {
   switch (DS.getTypeSpecWidth()) {
   case TypeSpecifierWidth::Unspecified:
 Result = Context.IntTy;
@@ -1458,8 +1458,9 @@
 if (!S.Context.getTargetInfo().hasExtIntType())
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsuppo

[clang] 7c6412e - Convert TypeSpecifierSign from Specifiers.h to a scoped enum; NFC

2020-11-16 Thread Aaron Ballman via cfe-commits

Author: Thorsten
Date: 2020-11-16T09:08:08-05:00
New Revision: 7c6412e0ccf5e00a9f59c5805df9df6ff6720ed2

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

LOG: Convert TypeSpecifierSign from Specifiers.h to a scoped enum; NFC

Added: 


Modified: 
clang/include/clang/AST/TypeLoc.h
clang/include/clang/Basic/Specifiers.h
clang/include/clang/Sema/DeclSpec.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/DeclSpec.cpp
clang/lib/Sema/SemaCodeComplete.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/include/clang/AST/TypeLoc.h 
b/clang/include/clang/AST/TypeLoc.h
index 4d3d4a94cbf3..4c320ce26e4f 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -603,16 +603,16 @@ class BuiltinTypeLoc : public 
ConcreteTypeLoc(getWrittenBuiltinSpecs().Sign);
 else
-  return TSS_unspecified;
+  return TypeSpecifierSign::Unspecified;
   }
 
   bool hasWrittenSignSpec() const {
-return getWrittenSignSpec() != TSS_unspecified;
+return getWrittenSignSpec() != TypeSpecifierSign::Unspecified;
   }
 
   void setWrittenSignSpec(TypeSpecifierSign written) {
 if (needsExtraLocalData())
-  getWrittenBuiltinSpecs().Sign = written;
+  getWrittenBuiltinSpecs().Sign = static_cast(written);
   }
 
   TypeSpecifierWidth getWrittenWidthSpec() const {
@@ -658,7 +658,7 @@ class BuiltinTypeLoc : public ConcreteTypeLoc(TypeSpecifierSign::Unspecified);
   wbs.Width = static_cast(TypeSpecifierWidth::Unspecified);
   wbs.Type = TST_unspecified;
   wbs.ModeAttr = false;

diff  --git a/clang/include/clang/Basic/Specifiers.h 
b/clang/include/clang/Basic/Specifiers.h
index ed468db1dc8a..41537672283d 100644
--- a/clang/include/clang/Basic/Specifiers.h
+++ b/clang/include/clang/Basic/Specifiers.h
@@ -40,11 +40,7 @@ namespace clang {
   enum class TypeSpecifierWidth { Unspecified, Short, Long, LongLong };
 
   /// Specifies the signedness of a type, e.g., signed or unsigned.
-  enum TypeSpecifierSign {
-TSS_unspecified,
-TSS_signed,
-TSS_unsigned
-  };
+  enum class TypeSpecifierSign { Unspecified, Signed, Unsigned };
 
   enum class TypeSpecifiersPipe { Unspecified, Pipe };
 

diff  --git a/clang/include/clang/Sema/DeclSpec.h 
b/clang/include/clang/Sema/DeclSpec.h
index 290384b13df1..6a961bc026b0 100644
--- a/clang/include/clang/Sema/DeclSpec.h
+++ b/clang/include/clang/Sema/DeclSpec.h
@@ -255,12 +255,6 @@ class DeclSpec {
 TSC_complex
   };
 
-  // Import type specifier sign enumeration and constants.
-  typedef TypeSpecifierSign TSS;
-  static const TSS TSS_unspecified = clang::TSS_unspecified;
-  static const TSS TSS_signed = clang::TSS_signed;
-  static const TSS TSS_unsigned = clang::TSS_unsigned;
-
   // Import type specifier type enumeration and constants.
   typedef TypeSpecifierType TST;
   static const TST TST_unspecified = clang::TST_unspecified;
@@ -429,7 +423,8 @@ class DeclSpec {
 ThreadStorageClassSpec(TSCS_unspecified),
 SCS_extern_in_linkage_spec(false),
 TypeSpecWidth(static_cast(TypeSpecifierWidth::Unspecified)),
-TypeSpecComplex(TSC_unspecified), TypeSpecSign(TSS_unspecified),
+TypeSpecComplex(TSC_unspecified),
+TypeSpecSign(static_cast(TypeSpecifierSign::Unspecified)),
 TypeSpecType(TST_unspecified), TypeAltiVecVector(false),
 TypeAltiVecPixel(false), TypeAltiVecBool(false), TypeSpecOwned(false),
 TypeSpecPipe(false), TypeSpecSat(false), ConstrainedAuto(false),
@@ -473,7 +468,9 @@ class DeclSpec {
 return static_cast(TypeSpecWidth);
   }
   TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; }
-  TSS getTypeSpecSign() const { return (TSS)TypeSpecSign; }
+  TypeSpecifierSign getTypeSpecSign() const {
+return static_cast(TypeSpecSign);
+  }
   TST getTypeSpecType() const { return (TST)TypeSpecType; }
   bool isTypeAltiVecVector() const { return TypeAltiVecVector; }
   bool isTypeAltiVecPixel() const { return TypeAltiVecPixel; }
@@ -535,7 +532,7 @@ class DeclSpec {
   static const char *getSpecifierName(DeclSpec::TST T,
   const PrintingPolicy &Policy);
   static const char *getSpecifierName(DeclSpec::TQ Q);
-  static const char *getSpecifierName(DeclSpec::TSS S);
+  static const char *getSpecifierName(TypeSpecifierSign S);
   static const char *getSpecifierName(DeclSpec::TSC C);
   static const char *getSpecifierName(TypeSpecifierWidth W);
   static const char *getSpecifierName(DeclSpec::SCS S);
@@ -623,7 +620,7 @@ class DeclSpec {
 return getTypeSpecType() != DeclSpec::TST_unspecified ||
getTypeSpecWidth() != TypeSpecif

[PATCH] D91498: [NFC, Refactor] Convert TypeSpecifierSign from Specifiers.h to a scoped enum

2020-11-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

In D91498#2397251 , @tschuett wrote:

> rebased

Thanks! I've commit on your behalf in 7c6412e0ccf5e00a9f59c5805df9df6ff6720ed2 



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

https://reviews.llvm.org/D91498

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


[clang] f7c881b - Adding some explicit casts to appease build bots; NFC

2020-11-16 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2020-11-16T09:13:24-05:00
New Revision: f7c881b89eabec1af65073ede344da818292d62b

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

LOG: Adding some explicit casts to appease build bots; NFC

Added: 


Modified: 
clang/lib/Sema/DeclSpec.cpp

Removed: 




diff  --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index b0281540d066..7cef6553237e 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -1094,8 +1094,8 @@ bool DeclSpec::SetConstexprSpec(ConstexprSpecKind 
ConstexprKind,
 }
 
 void DeclSpec::SaveWrittenBuiltinSpecs() {
-  writtenBS.Sign = getTypeSpecSign();
-  writtenBS.Width = getTypeSpecWidth();
+  writtenBS.Sign = static_cast(getTypeSpecSign());
+  writtenBS.Width = static_cast(getTypeSpecWidth());
   writtenBS.Type = getTypeSpecType();
   // Search the list of attributes for the presence of a mode attribute.
   writtenBS.ModeAttr = getAttributes().hasAttribute(ParsedAttr::AT_Mode);



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


[clang] f9e639e - Fix bots that are running with assertions enabled; NFC.

2020-11-16 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2020-11-16T09:23:10-05:00
New Revision: f9e639efda4aa391a2f247abf69912ca2d29217f

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

LOG: Fix bots that are running with assertions enabled; NFC.

Added: 


Modified: 
clang/lib/Sema/SemaType.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index cf82ae7bd4d4..6c4475f6a624 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1582,7 +1582,8 @@ static QualType ConvertDeclSpecToType(TypeProcessingState 
&state) {
 S.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeNameLoc());
 
 assert(DS.getTypeSpecWidth() == TypeSpecifierWidth::Unspecified &&
-   DS.getTypeSpecComplex() == 0 && DS.getTypeSpecSign() == 0 &&
+   DS.getTypeSpecComplex() == 0 &&
+   DS.getTypeSpecSign() == TypeSpecifierSign::Unspecified &&
"No qualifiers on tag names!");
 
 // TypeQuals handled by caller.
@@ -1598,7 +1599,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState 
&state) {
   case DeclSpec::TST_typename: {
 assert(DS.getTypeSpecWidth() == TypeSpecifierWidth::Unspecified &&
DS.getTypeSpecComplex() == 0 &&
-   DS.getTypeSpecSign() == 0 &&
+   DS.getTypeSpecSign() == TypeSpecifierSign::Unspecified &&
"Can't handle qualifiers on typedef names yet!");
 Result = S.GetTypeFromParser(DS.getRepAsType());
 if (Result.isNull()) {



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


[PATCH] D89869: [OpenCL] Define OpenCL feature macros for all versions

2020-11-16 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D89869#2392032 , @Anastasia wrote:

> In D89869#2388499 , @azabaznov wrote:
>
>> Addressed all concerns except replacing //__opencl_c_int64 //definition into 
>> header. The reason for this as follows: this macro should be predefined 
>> regardless if clang includes default header or not.
>
> FYI clang doesn't provide full support of OpenCL without the header. In fact, 
> there is ongoing work on making the header included by default without any 
> flag. But I can see that this functionality is related to the frontend and 
> not something that is simply added via libraries so I don't have strong 
> objections for adding it in the clang source code. However, the macro can be 
> added without registering the new extension (see how `__IMAGE_SUPPORT__` is 
> added for example). Right now you are adding a pragma and a target setting 
> that targets can modify without any effect, so I would like to avoid these.
>
> My preference would be if you prepare a separate patch for this. Smaller 
> selfcontained patches are easier and faster to review and also it reduces 
> gaps in testing.

FYI I have added `__opencl_c_int64` in my patch mainly for the demonstration 
purposed as it is an RFC patch I am not sure when this will be committed. In 
case you prefer to commit this earlier I will rebase my change in necessary.


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

https://reviews.llvm.org/D89869

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


[PATCH] D91540: [preprocessor] Assertions on the inferrable null pointers in Preprocessor befere dereference

2020-11-16 Thread Ella Ma via Phabricator via cfe-commits
OikawaKirie created this revision.
OikawaKirie added reviewers: dnsampaio, rsmith, lattner, ilya-biryukov.
OikawaKirie added a project: clang.
Herald added a subscriber: cfe-commits.
OikawaKirie requested review of this revision.

This patch asserts on some smart pointers that can be statically inferred to be 
null pointers. For a smart pointer, when its nullability is checked, and the 
null branch can reach a dereference, we think it is a potential null pointer 
dereference. In this patch, I added an assertion before each reported 
dereference.

- clang/lib/Lex/PPDirectives.cpp:441, inferred from the loop body: e.g. line 
481, check and continue
- clang/lib/Lex/PPDirectives.cpp:1385, inferred from line 911: check `CurLexer`
- clang/lib/Lex/PPDirectives.cpp:1723, inferred from line 911: check `CurLexer`
- clang/lib/Lex/PPDirectives.cpp:2540, inferred from line 911: check `CurLexer`
- clang/lib/Lex/PPLexerChange.cpp:320, inferred from line 311: check `CurLexer`
- clang/lib/Lex/Preprocessor.cpp:1226, inferred from recomputeCurLexerKind line 
383: check `CurLexer`

Besides, the analyzer also reports the dereference in function 
SkipTokensWhileUsingPCH and Lex. I think these two reported dereference cannot 
actually happen, but I also add the asserts to make sure the value is correct.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91540

Files:
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Lex/Preprocessor.cpp


Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -637,9 +637,12 @@
 (CurLexer && CurLexer->getFileID() == getPredefinesFileID());
 switch (CurLexerKind) {
 case CLK_Lexer:
+  assert(CurLexer && "CurLexer is empty while CurLexerKind is CLK_Lexer.");
   CurLexer->Lex(Tok);
  break;
 case CLK_TokenLexer:
+  assert(CurTokenLexer &&
+  "CurTokenLexer is empty while CurLexerKind is CLK_TokenLexer.");
   CurTokenLexer->Lex(Tok);
   break;
 case CLK_CachingLexer:
@@ -895,9 +898,12 @@
   do {
 switch (CurLexerKind) {
 case CLK_Lexer:
+  assert(CurLexer && "CurLexer is empty while CurLexerKind is CLK_Lexer.");
   ReturnedToken = CurLexer->Lex(Result);
   break;
 case CLK_TokenLexer:
+  assert(CurTokenLexer &&
+  "CurTokenLexer is empty while CurLexerKind is CLK_TokenLexer.");
   ReturnedToken = CurTokenLexer->Lex(Result);
   break;
 case CLK_CachingLexer:
@@ -1217,6 +1223,7 @@
   assert(TheModuleLoader.HadFatalFailure &&
  "This should be an early exit only to a fatal error");
   Result.setKind(tok::eof);
+  assert(CurLexer);
   CurLexer->cutOffLexing();
   EnterTokens(Suffix);
   return true;
Index: clang/lib/Lex/PPLexerChange.cpp
===
--- clang/lib/Lex/PPLexerChange.cpp
+++ clang/lib/Lex/PPLexerChange.cpp
@@ -317,6 +317,7 @@
 Module *M = LeaveSubmodule(/*ForPragma*/true);
 
 Result.startToken();
+assert(CurLexer && "Got EOF but no current lexer set!");
 const char *EndPos = getCurLexerEndPos();
 CurLexer->BufferPtr = EndPos;
 CurLexer->FormTokenWithChars(Result, EndPos, tok::annot_module_end);
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -438,6 +438,7 @@
   }
   SourceLocation endLoc;
   while (true) {
+assert(CurLexer);
 CurLexer->Lex(Tok);
 
 if (Tok.is(tok::code_completion)) {
@@ -1381,6 +1382,8 @@
 ///
 void Preprocessor::HandleUserDiagnosticDirective(Token &Tok,
  bool isWarning) {
+  assert(CurLexer);
+
   // Read the rest of the line raw.  We do this because we don't want macros
   // to be expanded and we don't require that the tokens be valid preprocessing
   // tokens.  For example, this is allowed: "#warning `   'foo".  GCC does
@@ -1717,6 +1720,7 @@
"This should be an early exit only to a fatal error");
 TheModuleLoader.HadFatalFailure = true;
 IncludeTok.setKind(tok::eof);
+assert(CurLexer);
 CurLexer->cutOffLexing();
 return;
   }
@@ -2533,6 +2537,7 @@
   // Ensure we consume the rest of the macro body if errors occur.
   auto _ = llvm::make_scope_exit([&]() {
 // The flag indicates if we are still waiting for 'eod'.
+assert(CurLexer);
 if (CurLexer->ParsingPreprocessorDirective)
   DiscardUntilEndOfDirective();
   });


Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -637,9 +637,12 @@
 (CurLexer && CurLexer->getFileID() == getPredefinesFileID());
 switch (CurLexerKind) {
 case CLK_Lexer:
+  assert(CurLexer &

[PATCH] D91311: Add new 'preferred_name' attribute.

2020-11-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: libcxx/include/regex:2520
+_LIBCPP_PREFERRED_NAME(wregex)
+basic_regex
 {

rsmith wrote:
> Quuxplusone wrote:
> > Why does this attribute go on the class template? Shouldn't it be an 
> > attribute on the typedef, so that you don't have to repeat yourself? I 
> > mean, I'd much rather see
> > 
> > template class BasicFoo { };
> > using [[preferred]] Foo = BasicFoo;
> > using [[preferred]] WFoo = BasicFoo;
> > 
> > than
> > 
> > template class BasicFoo;
> > using Foo = BasicFoo;
> > using WFoo = BasicFoo;
> > template class [[preferred(Foo, WFoo)]] BasicFoo { };
> > 
> > The latter repeats every identifier one extra time, compared to the former.
> > 
> > And then, in fact, couldn't you go one step further and say that typedefs 
> > in the same scope as the class template itself should //always// implicitly 
> > have this attribute? Even if the attribute doesn't appear in the source 
> > code, we still want to print `basic_regex` as `regex`, right? It 
> > shouldn't cost any additional work for the compiler to figure that out.
> I don't think we want arbitrary typedefs to be able to declare themselves to 
> be names for the class template after the fact: this is a decision that the 
> (author of the) template itself should be making, not a decision for the 
> (author of the) typedef. Also, we need the information when looking at the 
> class template, not when looking at the typedef, so attaching it to the 
> typedef would require us to internally attach it to the class template 
> instead anyway, and generally it's undesirable and problematic to mutate an 
> existing declaration -- it's much cleaner to introduce new properties of a 
> declaration by redeclaring it. It's certainly not ideal that this results in 
> extra forward declarations in some cases, but given that this attribute is 
> only expected to be written a few dozen times in total, it doesn't seem worth 
> worrying about too much.
> 
> I don't think we want typedefs to automatically get this behavior, even if 
> they're in the same namespace. I think it would be problematic if, for 
> example:
> 
> ```
> namespace absl {
>   template struct basic_string_view;
>   using format_arg = basic_string_view;
>   std::string format(format_arg, ...);
> }
> ```
> 
> ... resulted in `absl::string_view` sometimes displaying as the (to a user) 
> unrelated type `absl::format_arg` depending on (presumably) `#include` order, 
> and I don't think we want to be in the business of inventing heuristics to 
> pick the "right" typedef.
> I don't think we want arbitrary typedefs to be able to declare themselves to 
> be names for the class template after the fact: this is a decision that the 
> (author of the) template itself should be making, not a decision for the 
> (author of the) typedef. 

+1




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91311

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


[PATCH] D91519: [AST][Mach0] Fix unused-variable warnings

2020-11-16 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: lld/MachO/SymbolTable.cpp:137
 // error message.
-if (auto *defined = dyn_cast(s))
+if (dyn_cast(s))
   error("found defined symbol with illegal name " + DSOHandle::name);

Should use isa


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91519

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


[PATCH] D87981: [X86] AMX programming model prototype.

2020-11-16 Thread Wei Xiao via Phabricator via cfe-commits
wxiao3 added inline comments.



Comment at: llvm/include/llvm/CodeGen/LiveRegMatrix.h:44
   VirtRegMap *VRM;
+  MachineRegisterInfo *MRI;
 

what's the purpose of this member?



Comment at: llvm/lib/Target/X86/X86RegisterInfo.cpp:917
+  }
+  for (MCPhysReg PhysReg : Order) {
+if (!MRI->isReserved(PhysReg))

Don't need to add PhysReg again if PhysReg is already in Hints.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87981

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


[PATCH] D91067: [AArch64][SVE] Support implicit lax vector conversions for SVE types

2020-11-16 Thread Joe Ellis via Phabricator via cfe-commits
joechrisellis updated this revision to Diff 305494.
joechrisellis added a comment.

Remove failing test; it was checking that a conversion _failed_, although the 
conversion should now _pass_ given the changes in this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91067

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/Sema/aarch64-sve-lax-vector-conversions.c
  clang/test/Sema/attr-arm-sve-vector-bits.c
  clang/test/SemaCXX/aarch64-sve-lax-vector-conversions.cpp

Index: clang/test/SemaCXX/aarch64-sve-lax-vector-conversions.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/aarch64-sve-lax-vector-conversions.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -msve-vector-bits=512 -flax-vector-conversions=none -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify=lax-vector-none %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -msve-vector-bits=512 -flax-vector-conversions=integer -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify=lax-vector-integer %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -msve-vector-bits=512 -flax-vector-conversions=all -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify=lax-vector-all %s
+
+// lax-vector-all-no-diagnostics
+
+#include 
+
+#define N __ARM_FEATURE_SVE_BITS
+#define FIXED_ATTR __attribute__((arm_sve_vector_bits(N)))
+
+typedef svfloat32_t fixed_float32_t FIXED_ATTR;
+typedef svint32_t fixed_int32_t FIXED_ATTR;
+
+void allowed_with_integer_lax_conversions() {
+  fixed_int32_t fi32;
+  svint64_t si64;
+
+  // The implicit cast here should fail if -flax-vector-conversions=none, but pass if
+  // -flax-vector-conversions={integer,all}.
+  fi32 = si64;
+  // lax-vector-none-error@-1 {{assigning to 'fixed_int32_t' (vector of 16 'int' values) from incompatible type}}
+}
+
+void allowed_with_all_lax_conversions() {
+  fixed_float32_t ff32;
+  svfloat64_t sf64;
+
+  // The implicit cast here should fail if -flax-vector-conversions={none,integer}, but pass if
+  // -flax-vector-conversions=all.
+  ff32 = sf64;
+  // lax-vector-none-error@-1 {{assigning to 'fixed_float32_t' (vector of 16 'float' values) from incompatible type}}
+  // lax-vector-integer-error@-2 {{assigning to 'fixed_float32_t' (vector of 16 'float' values) from incompatible type}}
+}
Index: clang/test/Sema/attr-arm-sve-vector-bits.c
===
--- clang/test/Sema/attr-arm-sve-vector-bits.c
+++ clang/test/Sema/attr-arm-sve-vector-bits.c
@@ -270,7 +270,6 @@
 TEST_CAST_COMMON(bool)
 
 // Test the implicit conversion only applies to valid types
-fixed_int8_t to_fixed_int8_t__from_svuint8_t(svuint8_t x) { return x; } // expected-error-re {{returning 'svuint8_t' (aka '__SVUint8_t') from a function with incompatible result type 'fixed_int8_t' (vector of {{[0-9]+}} 'signed char' values)}}
 fixed_bool_t to_fixed_bool_t__from_svint32_t(svint32_t x) { return x; } // expected-error-re {{returning 'svint32_t' (aka '__SVInt32_t') from a function with incompatible result type 'fixed_bool_t' (vector of {{[0-9]+}} 'unsigned char' values)}}
 
 svint64_t to_svint64_t__from_gnu_int32_t(gnu_int32_t x) { return x; } // expected-error-re {{returning 'gnu_int32_t' (vector of {{[0-9]+}} 'int32_t' values) from a function with incompatible result type 'svint64_t' (aka '__SVInt64_t')}}
Index: clang/test/Sema/aarch64-sve-lax-vector-conversions.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve-lax-vector-conversions.c
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -msve-vector-bits=512 -flax-vector-conversions=none -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify=lax-vector-none %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -msve-vector-bits=512 -flax-vector-conversions=integer -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify=lax-vector-integer %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -msve-vector-bits=512 -flax-vector-conversions=all -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify=lax-vector-all %s
+
+// lax-vector-all-no-diagnostics
+
+#include 
+
+#define N __ARM_FEATURE_SVE_BITS
+#define FIXED_ATTR __attribute__((arm_sve_vector_bits(N)))
+
+typedef svfloat32_t fixed_float32_t FIXED_ATTR;
+typedef svint32_t fixed_int32_t FIXED_ATTR;
+
+void allowed_with_integer_lax_conversions() {
+  fixed_int32_t fi32;
+  svint64_t si64;
+
+  // The implicit cast here should fail if -flax-vector-conversions=none, but pass if
+  // -flax-vector-conversions={i

[PATCH] D87981: [X86] AMX programming model prototype.

2020-11-16 Thread Wei Xiao via Phabricator via cfe-commits
wxiao3 added a comment.

Please add register allocation code owner: "qcolombet" to the reviewer list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87981

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


[clang] 02bdbdc - [clang][SveEmitter] Fix enum declarations. [NFCI]

2020-11-16 Thread Francesco Petrogalli via cfe-commits

Author: Francesco Petrogalli
Date: 2020-11-16T14:49:45Z
New Revision: 02bdbdc76021fcfb8cae465363b362cb889406d2

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

LOG: [clang][SveEmitter] Fix enum declarations. [NFCI]

Adapt the declarations of `svpattern` and `svprfop` to the most recent
one defined in section "5. Enum declarations" of the SVE ACLE
specifications [1].

The signature of the intrinsics using these enums have been changed
accordingly.

A test has been added to make sure that `svpattern` and `svprfop` are
not typedefs.

[1] https://developer.arm.com/documentation/100987/latest, version
00bet6

Reviewed By: joechrisellis

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

Added: 
clang/test/Sema/aarch64-sve-enums.c

Modified: 
clang/utils/TableGen/SveEmitter.cpp

Removed: 




diff  --git a/clang/test/Sema/aarch64-sve-enums.c 
b/clang/test/Sema/aarch64-sve-enums.c
new file mode 100644
index ..01b110645f1f
--- /dev/null
+++ b/clang/test/Sema/aarch64-sve-enums.c
@@ -0,0 +1,19 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 %s -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns  -fsyntax-only -verify
+// expected-no-diagnostics
+
+// This test makes sure that the enum declarations in section "5. Enum
+// declarations" of the SVE ACLE [1] are not presented as typedefs in
+// `arm_sve.h`. It does so by creating a typedef'd struct with the
+// same identifier as the one defined in `arm_sve.h`, then checking that
+// it does not overload the enum defined in `arm_sve.h`.
+//
+// [1] https://developer.arm.com/documentation/100987/latest version 00bet6
+
+typedef struct { float f; } svpattern;
+typedef struct { float f; } svprfop;
+#include 
+enum svpattern a1 = SV_ALL;
+svpattern b1 = {1.0f};
+enum svprfop a2 = SV_PLDL1KEEP;
+svprfop b2 = {1.0f};

diff  --git a/clang/utils/TableGen/SveEmitter.cpp 
b/clang/utils/TableGen/SveEmitter.cpp
index 1d42edd8a94a..8a705bc4b5b8 100644
--- a/clang/utils/TableGen/SveEmitter.cpp
+++ b/clang/utils/TableGen/SveEmitter.cpp
@@ -416,10 +416,10 @@ std::string SVEType::builtin_str() const {
 
 std::string SVEType::str() const {
   if (isPredicatePattern())
-return "sv_pattern";
+return "enum svpattern";
 
   if (isPrefetchOp())
-return "sv_prfop";
+return "enum svprfop";
 
   std::string S;
   if (Void)
@@ -1163,7 +1163,7 @@ void SVEEmitter::createHeader(raw_ostream &OS) {
   OS << "typedef __clang_svbfloat16x4_t svbfloat16x4_t;\n";
   OS << "#endif\n";
 
-  OS << "typedef enum\n";
+  OS << "enum svpattern\n";
   OS << "{\n";
   OS << "  SV_POW2 = 0,\n";
   OS << "  SV_VL1 = 1,\n";
@@ -1182,9 +1182,9 @@ void SVEEmitter::createHeader(raw_ostream &OS) {
   OS << "  SV_MUL4 = 29,\n";
   OS << "  SV_MUL3 = 30,\n";
   OS << "  SV_ALL = 31\n";
-  OS << "} sv_pattern;\n\n";
+  OS << "};\n\n";
 
-  OS << "typedef enum\n";
+  OS << "enum svprfop\n";
   OS << "{\n";
   OS << "  SV_PLDL1KEEP = 0,\n";
   OS << "  SV_PLDL1STRM = 1,\n";
@@ -1198,7 +1198,7 @@ void SVEEmitter::createHeader(raw_ostream &OS) {
   OS << "  SV_PSTL2STRM = 11,\n";
   OS << "  SV_PSTL3KEEP = 12,\n";
   OS << "  SV_PSTL3STRM = 13\n";
-  OS << "} sv_prfop;\n\n";
+  OS << "};\n\n";
 
   OS << "/* Function attributes */\n";
   OS << "#define __aio static inline __attribute__((__always_inline__, "



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


[PATCH] D91333: [clang][SveEmitter] Fix enum declarations. [NFCI]

2020-11-16 Thread Francesco Petrogalli 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 rG02bdbdc76021: [clang][SveEmitter] Fix enum declarations. 
[NFCI] (authored by fpetrogalli).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91333

Files:
  clang/test/Sema/aarch64-sve-enums.c
  clang/utils/TableGen/SveEmitter.cpp


Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -416,10 +416,10 @@
 
 std::string SVEType::str() const {
   if (isPredicatePattern())
-return "sv_pattern";
+return "enum svpattern";
 
   if (isPrefetchOp())
-return "sv_prfop";
+return "enum svprfop";
 
   std::string S;
   if (Void)
@@ -1163,7 +1163,7 @@
   OS << "typedef __clang_svbfloat16x4_t svbfloat16x4_t;\n";
   OS << "#endif\n";
 
-  OS << "typedef enum\n";
+  OS << "enum svpattern\n";
   OS << "{\n";
   OS << "  SV_POW2 = 0,\n";
   OS << "  SV_VL1 = 1,\n";
@@ -1182,9 +1182,9 @@
   OS << "  SV_MUL4 = 29,\n";
   OS << "  SV_MUL3 = 30,\n";
   OS << "  SV_ALL = 31\n";
-  OS << "} sv_pattern;\n\n";
+  OS << "};\n\n";
 
-  OS << "typedef enum\n";
+  OS << "enum svprfop\n";
   OS << "{\n";
   OS << "  SV_PLDL1KEEP = 0,\n";
   OS << "  SV_PLDL1STRM = 1,\n";
@@ -1198,7 +1198,7 @@
   OS << "  SV_PSTL2STRM = 11,\n";
   OS << "  SV_PSTL3KEEP = 12,\n";
   OS << "  SV_PSTL3STRM = 13\n";
-  OS << "} sv_prfop;\n\n";
+  OS << "};\n\n";
 
   OS << "/* Function attributes */\n";
   OS << "#define __aio static inline __attribute__((__always_inline__, "
Index: clang/test/Sema/aarch64-sve-enums.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve-enums.c
@@ -0,0 +1,19 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 %s -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns  -fsyntax-only -verify
+// expected-no-diagnostics
+
+// This test makes sure that the enum declarations in section "5. Enum
+// declarations" of the SVE ACLE [1] are not presented as typedefs in
+// `arm_sve.h`. It does so by creating a typedef'd struct with the
+// same identifier as the one defined in `arm_sve.h`, then checking that
+// it does not overload the enum defined in `arm_sve.h`.
+//
+// [1] https://developer.arm.com/documentation/100987/latest version 00bet6
+
+typedef struct { float f; } svpattern;
+typedef struct { float f; } svprfop;
+#include 
+enum svpattern a1 = SV_ALL;
+svpattern b1 = {1.0f};
+enum svprfop a2 = SV_PLDL1KEEP;
+svprfop b2 = {1.0f};


Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -416,10 +416,10 @@
 
 std::string SVEType::str() const {
   if (isPredicatePattern())
-return "sv_pattern";
+return "enum svpattern";
 
   if (isPrefetchOp())
-return "sv_prfop";
+return "enum svprfop";
 
   std::string S;
   if (Void)
@@ -1163,7 +1163,7 @@
   OS << "typedef __clang_svbfloat16x4_t svbfloat16x4_t;\n";
   OS << "#endif\n";
 
-  OS << "typedef enum\n";
+  OS << "enum svpattern\n";
   OS << "{\n";
   OS << "  SV_POW2 = 0,\n";
   OS << "  SV_VL1 = 1,\n";
@@ -1182,9 +1182,9 @@
   OS << "  SV_MUL4 = 29,\n";
   OS << "  SV_MUL3 = 30,\n";
   OS << "  SV_ALL = 31\n";
-  OS << "} sv_pattern;\n\n";
+  OS << "};\n\n";
 
-  OS << "typedef enum\n";
+  OS << "enum svprfop\n";
   OS << "{\n";
   OS << "  SV_PLDL1KEEP = 0,\n";
   OS << "  SV_PLDL1STRM = 1,\n";
@@ -1198,7 +1198,7 @@
   OS << "  SV_PSTL2STRM = 11,\n";
   OS << "  SV_PSTL3KEEP = 12,\n";
   OS << "  SV_PSTL3STRM = 13\n";
-  OS << "} sv_prfop;\n\n";
+  OS << "};\n\n";
 
   OS << "/* Function attributes */\n";
   OS << "#define __aio static inline __attribute__((__always_inline__, "
Index: clang/test/Sema/aarch64-sve-enums.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve-enums.c
@@ -0,0 +1,19 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 %s -triple aarch64-none-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns  -fsyntax-only -verify
+// expected-no-diagnostics
+
+// This test makes sure that the enum declarations in section "5. Enum
+// declarations" of the SVE ACLE [1] are not presented as typedefs in
+// `arm_sve.h`. It does so by creating a typedef'd struct with the
+// same identifier as the one defined in `arm_sve.h`, then checking that
+// it does not overload the enum defined in `arm_sve.h`.
+//
+// [1] https://developer.arm.com/documentation/100987/latest version 00bet6
+
+typedef struct { float f; } svpattern;
+typedef struct { float f; } svprfop;
+#include 
+enum svpattern a1 = SV_ALL;
+svpattern b1 = {1.0f};
+enum svprfop a2 = SV_PLDL1KEEP;

[PATCH] D91311: Add new 'preferred_name' attribute.

2020-11-16 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: libcxx/include/regex:2520
+_LIBCPP_PREFERRED_NAME(wregex)
+basic_regex
 {

aaron.ballman wrote:
> rsmith wrote:
> > Quuxplusone wrote:
> > > Why does this attribute go on the class template? Shouldn't it be an 
> > > attribute on the typedef, so that you don't have to repeat yourself? I 
> > > mean, I'd much rather see
> > > 
> > > template class BasicFoo { };
> > > using [[preferred]] Foo = BasicFoo;
> > > using [[preferred]] WFoo = BasicFoo;
> > > 
> > > than
> > > 
> > > template class BasicFoo;
> > > using Foo = BasicFoo;
> > > using WFoo = BasicFoo;
> > > template class [[preferred(Foo, WFoo)]] BasicFoo { };
> > > 
> > > The latter repeats every identifier one extra time, compared to the 
> > > former.
> > > 
> > > And then, in fact, couldn't you go one step further and say that typedefs 
> > > in the same scope as the class template itself should //always// 
> > > implicitly have this attribute? Even if the attribute doesn't appear in 
> > > the source code, we still want to print `basic_regex` as `regex`, 
> > > right? It shouldn't cost any additional work for the compiler to figure 
> > > that out.
> > I don't think we want arbitrary typedefs to be able to declare themselves 
> > to be names for the class template after the fact: this is a decision that 
> > the (author of the) template itself should be making, not a decision for 
> > the (author of the) typedef. Also, we need the information when looking at 
> > the class template, not when looking at the typedef, so attaching it to the 
> > typedef would require us to internally attach it to the class template 
> > instead anyway, and generally it's undesirable and problematic to mutate an 
> > existing declaration -- it's much cleaner to introduce new properties of a 
> > declaration by redeclaring it. It's certainly not ideal that this results 
> > in extra forward declarations in some cases, but given that this attribute 
> > is only expected to be written a few dozen times in total, it doesn't seem 
> > worth worrying about too much.
> > 
> > I don't think we want typedefs to automatically get this behavior, even if 
> > they're in the same namespace. I think it would be problematic if, for 
> > example:
> > 
> > ```
> > namespace absl {
> >   template struct basic_string_view;
> >   using format_arg = basic_string_view;
> >   std::string format(format_arg, ...);
> > }
> > ```
> > 
> > ... resulted in `absl::string_view` sometimes displaying as the (to a user) 
> > unrelated type `absl::format_arg` depending on (presumably) `#include` 
> > order, and I don't think we want to be in the business of inventing 
> > heuristics to pick the "right" typedef.
> > I don't think we want arbitrary typedefs to be able to declare themselves 
> > to be names for the class template after the fact: this is a decision that 
> > the (author of the) template itself should be making, not a decision for 
> > the (author of the) typedef. 
> 
> +1
> 
> 
> generally it's undesirable and problematic to mutate an existing declaration 
> -- it's much cleaner to introduce new properties of a declaration by 
> redeclaring it

Well, I can't argue with that one. :)

I see your point about the author of the typedef vs. the author of the 
template, but actually I'm ambivalent about your `format_arg` example. I could 
vaguely imagine that someone might want to see `absl::format_arg` in an error 
message, in the context of a call to `absl::format`, at least. But, I can see 
the point that hypotheticals aren't relevant; this attribute is specifically 
tailored for the STL's idiom of "class template with a bunch of closely 
associated typedefs," and the STL is monolithic enough that the class template 
always knows the exact names of those typedefs (I mean, in the STL, it's 
reasonable for a human to say that `basic_string_view` //is// `string_view`, in 
a way that it //is// not `format_arg`)... plus what you said above about 
Clang's internal implementation; so that's a good reason to stick with putting 
the attribute on the template.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91311

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


[PATCH] D91047: Add a call super attribute plugin example

2020-11-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/docs/ClangPlugins.rst:117
+Defining CallSuperAttr
+===
+

psionic12 wrote:
> aaron.ballman wrote:
> > psionic12 wrote:
> > > aaron.ballman wrote:
> > > > aaron.ballman wrote:
> > > > > The number of underlines here looks off -- can you verify it's 
> > > > > correct?
> > > > This still appears to be incorrect and will cause build errors for the 
> > > > documentation.
> > > Do you mean that there's a command to build the documentation and 
> > > currently my patch will cause a failure on it?
> > > 
> > > I thought this ClangPlugins.rst is only an documentation with markdown, 
> > > but seems that it's not what I thought?
> > > 
> > > Currently I will make sure there's no build error on the plugin itself 
> > > and the regression test case, and make sure the
> > > regression test will pass. Seems that's not enough, right?
> > > Do you mean that there's a command to build the documentation and 
> > > currently my patch will cause a failure on it?
> > 
> > Yes, we have a bot that builds docs: http://lab.llvm.org:8011/#/builders/92
> > 
> > > I thought this ClangPlugins.rst is only an documentation with markdown, 
> > > but seems that it's not what I thought?
> > 
> > It is a documentation file with markdown, but the markdown bots will 
> > complain if a markdown file cannot be built (they treat markdown warnings 
> > as errors).
> > 
> > > Currently I will make sure there's no build error on the plugin itself 
> > > and the regression test case, and make sure the regression test will 
> > > pass. Seems that's not enough, right?
> > 
> > Most of the time that's enough because the markdown usage is pretty trivial 
> > and can be inspected by sight for obvious issues (so people don't typically 
> > have to set up their build environments to generate documentation and test 
> > it with every patch).
> > 
> > In this case, the issue is with the underlines under the title. The number 
> > of underlines needs to match the number of characters in the title, but in 
> > this case there are 20 `=` characters but 23 title characters.
> It seems that only a committee member can trigger this bot, any way I can 
> test on my own environment? So that I can make sure the doc will compile 
> successfully before uploading patches?
> 
> As I mentioned before, using `make doxygen-clang` will succeed even the `=` 
> characters are not match with title characters, so it seems that the bot 
> doesn't use this way.
You can test in your own environment (if a build bot can do it, so can anyone 
else). I don't typically build docs locally so my instructions are untested, 
but I think you need to set the following cmake variables:

```
LLVM_BUILD_DOCS=YES ' enables building docs
LLVM_ENABLE_SPHINX=YES ' enable building sphinx docs (.rst files)
```
You also have to have Sphinx installed (you can do this using `pip install -U 
Sphinx`) and on the PATH before you configure cmake for Clang.

Doxygen is a different documentation format than Sphinx. Doxygen handles 
building the docs from comments in the source files. Sphinx is what turns these 
.rst files into HTML. If you enable Sphinx builds from cmake there should be a 
target added that lets you build those docs.



Comment at: clang/test/Frontend/plugin-call-super.cpp:5
+
+// expected-no-diagnostics
+struct Base1 { [[clang::call_super]] virtual void Test() {} };

Hmm, this seems wrong to me -- we do expect diagnostics from this file.



Comment at: clang/test/Frontend/plugin-call-super.cpp:18-19
+struct Derive2 : public Base1, public Base2 { void Test() override {  
Base1::Test();  Base2::Test();}};
+// BADCALLSUPER: warning: virtual function 'Base2::Test' is marked as 
'call_super' but this overriding method does not call the base version
+// BADCALLSUPER: note: function marked 'call_super' here
+#endif

These warnings and notes (and the warning a few lines up) are ones I would have 
expected to catch using `// expected-warning {{virtual function 'Base2::Test' 
is marked as 'call_super' but this overriding method does not call the base 
version}}` style checks instead of needing to use FileCheck.

Do plugin-based diagnostics not get caught by `-verify`? I expect this test 
file to fail as currently written because of the `expected-no-diagnostics`, but 
I've not done a whole lot of testing of plugins before.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91047

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


[clang] 8dbe44c - Add pass to add !annotate metadata from @llvm.global.annotations.

2020-11-16 Thread Florian Hahn via cfe-commits

Author: Florian Hahn
Date: 2020-11-16T14:57:11Z
New Revision: 8dbe44cb2936ecafea4b26ef16d1727371ad203f

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

LOG: Add pass to add !annotate metadata from @llvm.global.annotations.

This patch adds a new pass to add !annotation metadata for entries in
@llvm.global.anotations, which is generated  using
__attribute__((annotate("_name"))) on functions in Clang.

This has been discussed on llvm-dev as part of
RFC: Combining Annotation Metadata and Remarks
http://lists.llvm.org/pipermail/llvm-dev/2020-November/146393.html

Reviewed By: thegameg

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

Added: 
llvm/include/llvm/Transforms/IPO/Annotation2Metadata.h
llvm/lib/Transforms/IPO/Annotation2Metadata.cpp
llvm/test/Transforms/Util/annotation2metadata.ll

Modified: 
clang/test/CodeGen/code-coverage.c
llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h
llvm/include/llvm/InitializePasses.h
llvm/include/llvm/Transforms/IPO.h
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassRegistry.def
llvm/lib/Transforms/IPO/CMakeLists.txt
llvm/lib/Transforms/IPO/IPO.cpp
llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
llvm/test/CodeGen/AMDGPU/opt-pipeline.ll
llvm/test/Other/new-pm-defaults.ll
llvm/test/Other/new-pm-lto-defaults.ll
llvm/test/Other/new-pm-thinlto-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
llvm/test/Other/opt-O0-pipeline.ll
llvm/test/Other/opt-O2-pipeline.ll
llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
llvm/test/Other/opt-O3-pipeline.ll
llvm/test/Other/opt-Os-pipeline.ll

Removed: 




diff  --git a/clang/test/CodeGen/code-coverage.c 
b/clang/test/CodeGen/code-coverage.c
index 200f3650b752..02e9482d4b4a 100644
--- a/clang/test/CodeGen/code-coverage.c
+++ b/clang/test/CodeGen/code-coverage.c
@@ -18,10 +18,10 @@
 // NEWPM: Running pass: GCOVProfilerPass
 
 // NEWPM-O3-NOT: Running pass
+// NEWPM-O3: Running pass: Annotation2MetadataPass
 // NEWPM-O3: Running pass: ForceFunctionAttrsPass
 // NEWPM-O3: Running pass: GCOVProfilerPass
 
-
 int test1(int a) {
   switch (a % 2) {
   case 0:

diff  --git a/llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h 
b/llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h
index 4ac8eb8be906..9815dd05cd1c 100644
--- a/llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h
+++ b/llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h
@@ -90,10 +90,12 @@ class OptimizationRemarkEmitter {
   bool allowExtraAnalysis(StringRef PassName) const {
 return OptimizationRemarkEmitter::allowExtraAnalysis(*F, PassName);
   }
-
   static bool allowExtraAnalysis(const Function &F, StringRef PassName) {
-return F.getContext().getLLVMRemarkStreamer() ||
-   F.getContext().getDiagHandlerPtr()->isAnyRemarkEnabled(PassName);
+return allowExtraAnalysis(F.getContext(), PassName);
+  }
+  static bool allowExtraAnalysis(LLVMContext &Ctx, StringRef PassName) {
+return Ctx.getLLVMRemarkStreamer() ||
+   Ctx.getDiagHandlerPtr()->isAnyRemarkEnabled(PassName);
   }
 
 private:

diff  --git a/llvm/include/llvm/InitializePasses.h 
b/llvm/include/llvm/InitializePasses.h
index 139c4a84d9ef..0d0eaf0bca83 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -73,6 +73,7 @@ void initializeAlignmentFromAssumptionsPass(PassRegistry&);
 void initializeAlwaysInlinerLegacyPassPass(PassRegistry&);
 void initializeAssumeSimplifyPassLegacyPassPass(PassRegistry &);
 void initializeAssumeBuilderPassLegacyPassPass(PassRegistry &);
+void initializeAnnotation2MetadataLegacyPass(PassRegistry &);
 void initializeAnnotationRemarksLegacyPass(PassRegistry &);
 void initializeOpenMPOptLegacyPassPass(PassRegistry &);
 void initializeArgPromotionPass(PassRegistry&);

diff  --git a/llvm/include/llvm/Transforms/IPO.h 
b/llvm/include/llvm/Transforms/IPO.h
index 7b73eeaf8e45..1918ad76a270 100644
--- a/llvm/include/llvm/Transforms/IPO.h
+++ b/llvm/include/llvm/Transforms/IPO.h
@@ -29,6 +29,13 @@ class BasicBlock;
 class GlobalValue;
 class raw_ostream;
 
+//===--===//
+//
+// This pass adds !annotation metadata to entries in the
+// @llvm.global.annotations global constant.
+//
+ModulePass *createAnnotation2MetadataLegacyPass();
+
 
//===--===//
 //
 // These functions removes symbols from functions and modules.  If 
OnlyDebugInfo

diff  --git a/llvm/includ

[PATCH] D91195: Add Annotation2MD pass to add !annotate metadata from llvm.global.annotations

2020-11-16 Thread Florian Hahn 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 rG8dbe44cb2936: Add pass to add !annotate metadata from 
@llvm.global.annotations. (authored by fhahn).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D91195?vs=304277&id=305499#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91195

Files:
  clang/test/CodeGen/code-coverage.c
  llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/Transforms/IPO.h
  llvm/include/llvm/Transforms/IPO/Annotation2Metadata.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/IPO/Annotation2Metadata.cpp
  llvm/lib/Transforms/IPO/CMakeLists.txt
  llvm/lib/Transforms/IPO/IPO.cpp
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/test/CodeGen/AMDGPU/opt-pipeline.ll
  llvm/test/Other/new-pm-defaults.ll
  llvm/test/Other/new-pm-lto-defaults.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
  llvm/test/Other/opt-O0-pipeline.ll
  llvm/test/Other/opt-O2-pipeline.ll
  llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
  llvm/test/Other/opt-O3-pipeline.ll
  llvm/test/Other/opt-Os-pipeline.ll
  llvm/test/Transforms/Util/annotation2metadata.ll

Index: llvm/test/Transforms/Util/annotation2metadata.ll
===
--- /dev/null
+++ llvm/test/Transforms/Util/annotation2metadata.ll
@@ -0,0 +1,61 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -annotation2metadata -pass-remarks-analysis='annotation-remarks' -S %s | FileCheck %s
+; RUN: opt -passes='annotation2metadata' -pass-remarks-analysis='annotation-remarks' -S %s | FileCheck %s
+
+@.str = private unnamed_addr constant [10 x i8] c"_remarks1\00", section "llvm.metadata"
+@.str.1 = private unnamed_addr constant [6 x i8] c"ann.c\00", section "llvm.metadata"
+@.str.2 = private unnamed_addr constant [10 x i8] c"_remarks2\00", section "llvm.metadata"
+@llvm.global.annotations = appending global [8 x { i8*, i8*, i8*, i32 }] [
+{ i8*, i8*, i8*, i32 } { i8* bitcast (void (float*)* @test1 to i8*), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i32 2 },
+{ i8*, i8*, i8*, i32 } { i8* bitcast (void (float*)* @test1 to i8*), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i32 2 },
+{ i8*, i8*, i8*, i32 } { i8* bitcast (void (float*)* @test3 to i8*), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* undef, i32 4 }, ; Invalid entry, make sure we do not crash.
+{ i8*, i8*, i8*, i32 } { i8* bitcast (void (float*)* @test3 to i8*), i8* undef, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i32 4 }, ; Invalid entry, make sure we do not crash.
+{ i8*, i8*, i8*, i32 } { i8* undef, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i32 4 }, ; Invalid entry, make sure we do not crash.
+{ i8*, i8*, i8*, i32 } { i8* bitcast (void (float*)* undef to i8*), i8* undef, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i32 4 }, ; Invalid entry, make sure we do not crash.
+{ i8*, i8*, i8*, i32 } { i8* undef, i8* undef, i8* undef, i32 300 },  ; Invalid entry, make sure we do not crash.
+{ i8*, i8*, i8*, i32 } { i8* bitcast (void (float*)* @test3 to i8*), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i32 4 }
+], section "llvm.metadata"
+
+
+
+define void @test1(float* %a) {
+; CHECK-LABEL: @test1(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[A_ADDR:%.*]] = alloca float*, align 8, !annotation [[GROUP1:!.+]]
+; CHECK-NEXT:store float* [[A:%.*]], float** [[A_ADDR]], align 8, !annotation [[GROUP1]]
+; CHECK-NEXT:ret void, !annotation [[GROUP1]]
+;
+entry:
+  %a.addr = alloca float*, align 8
+  store float* %a, float** %a.addr, align 8
+  ret void
+}
+
+define void @test2(float* %a) {
+; CHECK-LABEL: @test2(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[A_ADDR:%.*]] = alloca float*, align 8
+; CHECK-NEXT:store float* [[A:%.*]], float** [[A_ADDR]], align 8
+; CHECK-NEXT:ret void
+;
+entry:
+  %a.addr = alloca float*, align 8
+  store float* %a, float** %a.addr, align 8
+  ret void
+}
+
+define void 

[clang] 9e407af - [AIX][driver] Include crti[_64].o and -bcdtors also for C language link invocations by default

2020-11-16 Thread Xiangling Liao via cfe-commits

Author: Xiangling Liao
Date: 2020-11-16T10:07:57-05:00
New Revision: 9e407afd9bd3b5181db24b08f78cb43344bd8292

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

LOG: [AIX][driver] Include crti[_64].o and -bcdtors also for C language link 
invocations by default

In order to support attribute((constructor)) and attribute((destructor)),
which is used by various LLVM non-C++ runtime components, AIX will include
crti[_64].o and -bcdtors for C language link invocations by default.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/AIX.cpp
clang/test/Driver/aix-ld.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index 47ce99a7c625..7b5d7da8c873 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -134,16 +134,15 @@ void aix::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back(
 Args.MakeArgString(ToolChain.GetFilePath(getCrt0Basename(;
 
-if (D.CCCIsCXX())
-  CmdArgs.push_back(Args.MakeArgString(
-  ToolChain.GetFilePath(IsArch32Bit ? "crti.o" : "crti_64.o")));
+CmdArgs.push_back(Args.MakeArgString(
+ToolChain.GetFilePath(IsArch32Bit ? "crti.o" : "crti_64.o")));
   }
 
-  // Collect all static constructor and destructor functions in CXX mode. This
-  // has to come before AddLinkerInputs as the implied option needs to precede
-  // any other '-bcdtors' settings or '-bnocdtors' that '-Wl' might forward.
-  if (D.CCCIsCXX())
-CmdArgs.push_back("-bcdtors:all:0:s");
+  // Collect all static constructor and destructor functions in both C and CXX
+  // language link invocations. This has to come before AddLinkerInputs as the
+  // implied option needs to precede any other '-bcdtors' settings or
+  // '-bnocdtors' that '-Wl' might forward.
+  CmdArgs.push_back("-bcdtors:all:0:s");
 
   // Specify linker input file(s).
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);

diff  --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c
index 89959d851b93..6abfa10c92f6 100644
--- a/clang/test/Driver/aix-ld.c
+++ b/clang/test/Driver/aix-ld.c
@@ -16,7 +16,7 @@
 // CHECK-LD32: "-b32"
 // CHECK-LD32: "-bpT:0x1000" "-bpD:0x2000"
 // CHECK-LD32: "[[SYSROOT]]/usr/lib{{/|}}crt0.o"
-// CHECK-LD32-NOT: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
+// CHECK-LD32: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
 // CHECK-LD32: "-L[[SYSROOT]]/usr/lib"
 // CHECK-LD32-NOT: "-lc++"
 // CHECK-LD32: 
"[[RESOURCE_DIR]]{{/|}}lib{{/|}}aix{{/|}}libclang_rt.builtins-powerpc.a"
@@ -38,7 +38,7 @@
 // CHECK-LD64: "-b64"
 // CHECK-LD64: "-bpT:0x1" "-bpD:0x11000"
 // CHECK-LD64: "[[SYSROOT]]/usr/lib{{/|}}crt0_64.o"
-// CHECK-LD64-NOT: "[[SYSROOT]]/usr/lib{{/|}}crti_64.o"
+// CHECK-LD64: "[[SYSROOT]]/usr/lib{{/|}}crti_64.o"
 // CHECK-LD64: "-L[[SYSROOT]]/usr/lib"
 // CHECK-LD64-NOT: "-lc++"
 // CHECK-LD64: 
"[[RESOURCE_DIR]]{{/|}}lib{{/|}}aix{{/|}}libclang_rt.builtins-powerpc64.a"
@@ -61,7 +61,7 @@
 // CHECK-LD32-PTHREAD: "-b32"
 // CHECK-LD32-PTHREAD: "-bpT:0x1000" "-bpD:0x2000"
 // CHECK-LD32-PTHREAD: "[[SYSROOT]]/usr/lib{{/|}}crt0.o"
-// CHECK-LD32-PTHREAD-NOT: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
+// CHECK-LD32-PTHREAD: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
 // CHECK-LD32-PTHREAD: "-L[[SYSROOT]]/usr/lib"
 // CHECK-LD32-PTHREAD-NOT: "-lc++"
 // CHECK-LD32-PTHREAD: 
"[[RESOURCE_DIR]]{{/|}}lib{{/|}}aix{{/|}}libclang_rt.builtins-powerpc.a"
@@ -85,7 +85,7 @@
 // CHECK-LD64-PTHREAD: "-b64"
 // CHECK-LD64-PTHREAD: "-bpT:0x1" "-bpD:0x11000"
 // CHECK-LD64-PTHREAD: "[[SYSROOT]]/usr/lib{{/|}}crt0_64.o"
-// CHECK-LD64-PTHREAD-NOT: "[[SYSROOT]]/usr/lib{{/|}}crti_64.o"
+// CHECK-LD64-PTHREAD: "[[SYSROOT]]/usr/lib{{/|}}crti_64.o"
 // CHECK-LD64-PTHREAD: "-L[[SYSROOT]]/usr/lib"
 // CHECK-LD64-PTHREAD-NOT: "-lc++"
 // CHECK-LD64-PTHREAD: 
"[[RESOURCE_DIR]]{{/|}}lib{{/|}}aix{{/|}}libclang_rt.builtins-powerpc64.a"
@@ -109,7 +109,7 @@
 // CHECK-LD32-PROF: "-b32"
 // CHECK-LD32-PROF: "-bpT:0x1000" "-bpD:0x2000"
 // CHECK-LD32-PROF: "[[SYSROOT]]/usr/lib{{/|}}mcrt0.o"
-// CHECK-LD32-PROF-NOT: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
+// CHECK-LD32-PROF: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
 // CHECK-LD32-PROF: "-L[[SYSROOT]]/usr/lib"
 // CHECK-LD32-PROF-NOT: "-lc++"
 // CHECK-LD32-PROF: 
"[[RESOURCE_DIR]]{{/|}}lib{{/|}}aix{{/|}}libclang_rt.builtins-powerpc.a"
@@ -132,7 +132,7 @@
 // CHECK-LD64-GPROF: "-b64"
 // CHECK-LD64-GPROF: "-bpT:0x1" "-bpD:

[PATCH] D91361: [AIX][driver] Include crti[_64].o and -bcdtors also for C language link invocations by default

2020-11-16 Thread Xiangling Liao via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9e407afd9bd3: [AIX][driver] Include crti[_64].o and -bcdtors 
also for C language link… (authored by Xiangling_L).

Changed prior to commit:
  https://reviews.llvm.org/D91361?vs=305160&id=305501#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91361

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/test/Driver/aix-ld.c

Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -16,7 +16,7 @@
 // CHECK-LD32: "-b32"
 // CHECK-LD32: "-bpT:0x1000" "-bpD:0x2000"
 // CHECK-LD32: "[[SYSROOT]]/usr/lib{{/|}}crt0.o"
-// CHECK-LD32-NOT: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
+// CHECK-LD32: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
 // CHECK-LD32: "-L[[SYSROOT]]/usr/lib"
 // CHECK-LD32-NOT: "-lc++"
 // CHECK-LD32: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}aix{{/|}}libclang_rt.builtins-powerpc.a"
@@ -38,7 +38,7 @@
 // CHECK-LD64: "-b64"
 // CHECK-LD64: "-bpT:0x1" "-bpD:0x11000"
 // CHECK-LD64: "[[SYSROOT]]/usr/lib{{/|}}crt0_64.o"
-// CHECK-LD64-NOT: "[[SYSROOT]]/usr/lib{{/|}}crti_64.o"
+// CHECK-LD64: "[[SYSROOT]]/usr/lib{{/|}}crti_64.o"
 // CHECK-LD64: "-L[[SYSROOT]]/usr/lib"
 // CHECK-LD64-NOT: "-lc++"
 // CHECK-LD64: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}aix{{/|}}libclang_rt.builtins-powerpc64.a"
@@ -61,7 +61,7 @@
 // CHECK-LD32-PTHREAD: "-b32"
 // CHECK-LD32-PTHREAD: "-bpT:0x1000" "-bpD:0x2000"
 // CHECK-LD32-PTHREAD: "[[SYSROOT]]/usr/lib{{/|}}crt0.o"
-// CHECK-LD32-PTHREAD-NOT: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
+// CHECK-LD32-PTHREAD: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
 // CHECK-LD32-PTHREAD: "-L[[SYSROOT]]/usr/lib"
 // CHECK-LD32-PTHREAD-NOT: "-lc++"
 // CHECK-LD32-PTHREAD: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}aix{{/|}}libclang_rt.builtins-powerpc.a"
@@ -85,7 +85,7 @@
 // CHECK-LD64-PTHREAD: "-b64"
 // CHECK-LD64-PTHREAD: "-bpT:0x1" "-bpD:0x11000"
 // CHECK-LD64-PTHREAD: "[[SYSROOT]]/usr/lib{{/|}}crt0_64.o"
-// CHECK-LD64-PTHREAD-NOT: "[[SYSROOT]]/usr/lib{{/|}}crti_64.o"
+// CHECK-LD64-PTHREAD: "[[SYSROOT]]/usr/lib{{/|}}crti_64.o"
 // CHECK-LD64-PTHREAD: "-L[[SYSROOT]]/usr/lib"
 // CHECK-LD64-PTHREAD-NOT: "-lc++"
 // CHECK-LD64-PTHREAD: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}aix{{/|}}libclang_rt.builtins-powerpc64.a"
@@ -109,7 +109,7 @@
 // CHECK-LD32-PROF: "-b32"
 // CHECK-LD32-PROF: "-bpT:0x1000" "-bpD:0x2000"
 // CHECK-LD32-PROF: "[[SYSROOT]]/usr/lib{{/|}}mcrt0.o"
-// CHECK-LD32-PROF-NOT: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
+// CHECK-LD32-PROF: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
 // CHECK-LD32-PROF: "-L[[SYSROOT]]/usr/lib"
 // CHECK-LD32-PROF-NOT: "-lc++"
 // CHECK-LD32-PROF: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}aix{{/|}}libclang_rt.builtins-powerpc.a"
@@ -132,7 +132,7 @@
 // CHECK-LD64-GPROF: "-b64"
 // CHECK-LD64-GPROF: "-bpT:0x1" "-bpD:0x11000"
 // CHECK-LD64-GPROF: "[[SYSROOT]]/usr/lib{{/|}}gcrt0_64.o"
-// CHECK-LD64-GPROF-NOT: "[[SYSROOT]]/usr/lib{{/|}}crti_64.o"
+// CHECK-LD64-GPROF: "[[SYSROOT]]/usr/lib{{/|}}crti_64.o"
 // CHECK-LD64-GPROF: "-L[[SYSROOT]]/usr/lib"
 // CHECK-LD64-GPROF-NOT: "-lc++"
 // CHECK-LD64-GPROF: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}aix{{/|}}libclang_rt.builtins-powerpc64.a"
@@ -155,7 +155,7 @@
 // CHECK-LD32-STATIC: "-b32"
 // CHECK-LD32-STATIC: "-bpT:0x1000" "-bpD:0x2000"
 // CHECK-LD32-STATIC: "[[SYSROOT]]/usr/lib{{/|}}crt0.o"
-// CHECK-LD32-STATIC-NOT: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
+// CHECK-LD32-STATIC: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
 // CHECK-LD32-STATIC: "-L[[SYSROOT]]/usr/lib"
 // CHECK-LD32-STATIC-NOT: "-lc++"
 // CHECK-LD32-STATIC: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}aix{{/|}}libclang_rt.builtins-powerpc.a"
@@ -178,7 +178,7 @@
 // CHECK-LD32-LIBP: "-b32"
 // CHECK-LD32-LIBP: "-bpT:0x1000" "-bpD:0x2000"
 // CHECK-LD32-LIBP: "[[SYSROOT]]/usr/lib{{/|}}crt0.o"
-// CHECK-LD32-LIBP-NOT: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
+// CHECK-LD32-LIBP: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
 // CHECK-LD32-LIBP: "-L[[SYSROOT]]/powerpc-ibm-aix7.1.0.0"
 // CHECK-LD32-LIBP: "-L[[SYSROOT]]/usr/lib"
 // CHECK-LD32-LIBP-NOT: "-lc++"
@@ -228,7 +228,7 @@
 // CHECK-LD64-NO-DEFAULT-LIBS: "-b64"
 // CHECK-LD64-NO-DEFAULT-LIBS: "-bpT:0x1" "-bpD:0x11000"
 // CHECK-LD64-NO-DEFAULT-LIBS: "[[SYSROOT]]/usr/lib{{/|}}crt0_64.o"
-// CHECK-LD64-NO-DEFAULT-LIBS-NOT: "[[SYSROOT]]/usr/lib{{/|}}crti_64.o"
+// CHECK-LD64-NO-DEFAULT-LIBS: "[[SYSROOT]]/usr/lib{{/|}}crti_64.o"
 // CHECK-LD64-NO-DEFAULT-LIBS

[clang] 4369223 - BPF: make __builtin_btf_type_id() return 64bit int

2020-11-16 Thread Yonghong Song via cfe-commits

Author: Yonghong Song
Date: 2020-11-16T07:08:41-08:00
New Revision: 4369223ea73c4b8a3fa9a8a84533125c7d0eea98

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

LOG: BPF: make __builtin_btf_type_id() return 64bit int

Linux kernel recently added support for kernel modules
  https://lore.kernel.org/bpf/20201110011932.3201430-5-and...@kernel.org/

In such cases, a type id in the kernel needs to be presented
as (btf id for modules, btf type id for this module).
Change __builtin_btf_type_id() to return 64bit value
so libbpf can do the above encoding.

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsBPF.def
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/builtin-bpf-btf-type-id.c
llvm/include/llvm/IR/IntrinsicsBPF.td
llvm/lib/Target/BPF/BPFPreserveDIType.cpp
llvm/lib/Target/BPF/BTFDebug.cpp
llvm/test/CodeGen/BPF/BTF/builtin-btf-type-id.ll
llvm/test/CodeGen/BPF/CORE/btf-id-duplicate.ll
llvm/test/CodeGen/BPF/optnone-2.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsBPF.def 
b/clang/include/clang/Basic/BuiltinsBPF.def
index 04b45a52cbe7..190062645ec4 100644
--- a/clang/include/clang/Basic/BuiltinsBPF.def
+++ b/clang/include/clang/Basic/BuiltinsBPF.def
@@ -21,7 +21,7 @@
 TARGET_BUILTIN(__builtin_preserve_field_info, "Ui.", "t", "")
 
 // Get BTF type id.
-TARGET_BUILTIN(__builtin_btf_type_id, "Ui.", "t", "")
+TARGET_BUILTIN(__builtin_btf_type_id, "LUi.", "t", "")
 
 // Get type information.
 TARGET_BUILTIN(__builtin_preserve_type_info, "Ui.", "t", "")

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index eacf00c93015..8d4c90c7812f 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2696,6 +2696,8 @@ bool Sema::CheckBPFBuiltinFunctionCall(unsigned BuiltinID,
   kind = diag::err_preserve_enum_value_invalid;
 }
 ReturnUnsignedInt = false;
+  } else if (BuiltinID == BPF::BI__builtin_btf_type_id) {
+ReturnUnsignedInt = false;
   }
 
   if (InvalidArg) {

diff  --git a/clang/test/CodeGen/builtin-bpf-btf-type-id.c 
b/clang/test/CodeGen/builtin-bpf-btf-type-id.c
index bbfbbb877aa7..c8f29ee5fe4a 100644
--- a/clang/test/CodeGen/builtin-bpf-btf-type-id.c
+++ b/clang/test/CodeGen/builtin-bpf-btf-type-id.c
@@ -12,12 +12,12 @@ unsigned test3() {
 }
 
 // CHECK: define dso_local i32 @test1
-// CHECK: call i32 @llvm.bpf.btf.type.id(i32 0, i64 0), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[INT:[0-9]+]]
+// CHECK: call i64 @llvm.bpf.btf.type.id(i32 0, i64 0), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[INT:[0-9]+]]
 // CHECK: define dso_local i32 @test2
-// CHECK: call i32 @llvm.bpf.btf.type.id(i32 1, i64 0), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[INT_POINTER:[0-9]+]]
+// CHECK: call i64 @llvm.bpf.btf.type.id(i32 1, i64 0), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[INT_POINTER:[0-9]+]]
 // CHECK: define dso_local i32 @test3
-// CHECK: call i32 @llvm.bpf.btf.type.id(i32 2, i64 1), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[STRUCT_T1:[0-9]+]]
-// CHECK: call i32 @llvm.bpf.btf.type.id(i32 3, i64 1), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[TYPEDEF_T1:[0-9]+]]
+// CHECK: call i64 @llvm.bpf.btf.type.id(i32 2, i64 1), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[STRUCT_T1:[0-9]+]]
+// CHECK: call i64 @llvm.bpf.btf.type.id(i32 3, i64 1), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[TYPEDEF_T1:[0-9]+]]
 //
 // CHECK: ![[INT]] = !DIBasicType(name: "int", size: 32, encoding: 
DW_ATE_signed
 // CHECK: ![[INT_POINTER]] = !DIDerivedType(tag: DW_TAG_pointer_type, 
baseType: ![[INT]], size: 64

diff  --git a/llvm/include/llvm/IR/IntrinsicsBPF.td 
b/llvm/include/llvm/IR/IntrinsicsBPF.td
index 651b28748cd3..4b4dd94b1599 100644
--- a/llvm/include/llvm/IR/IntrinsicsBPF.td
+++ b/llvm/include/llvm/IR/IntrinsicsBPF.td
@@ -24,7 +24,7 @@ let TargetPrefix = "bpf" in {  // All intrinsics start with 
"llvm.bpf."
   Intrinsic<[llvm_i32_ty], [llvm_anyptr_ty, llvm_i64_ty],
   [IntrNoMem, ImmArg>]>;
   def int_bpf_btf_type_id : GCCBuiltin<"__builtin_bpf_btf_type_id">,
-  Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i64_ty],
+  Intrinsic<[llvm_i64_ty], [llvm_i32_ty, llvm_i64_ty],
   [IntrNoMem]>;
   def int_bpf_preserve_type_info : 
GCCBuiltin<"__builtin_bpf_preserve_type_info">,
   Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i64_ty],

diff  --git a/llvm/lib/Target/BPF/BPFPreserveDIType.cpp 
b/llvm/lib/Target/BPF/BPFPreserveDIType.cpp
index 75febbe4b138..18a4f60c171a 100644
--- a/llvm/lib/Target/BPF/BPFPreserveDIType.cpp
+++ b/llvm/lib/Target/BPF/BPFPreserveDIType.cpp
@@ -90,7 +90,7 @@ static bool BPFPreserveDIType

[PATCH] D91489: BPF: make __builtin_btf_type_id() return 64bit int

2020-11-16 Thread Yonghong Song 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 rG4369223ea73c: BPF: make __builtin_btf_type_id() return 64bit 
int (authored by yonghong-song).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91489

Files:
  clang/include/clang/Basic/BuiltinsBPF.def
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtin-bpf-btf-type-id.c
  llvm/include/llvm/IR/IntrinsicsBPF.td
  llvm/lib/Target/BPF/BPFPreserveDIType.cpp
  llvm/lib/Target/BPF/BTFDebug.cpp
  llvm/test/CodeGen/BPF/BTF/builtin-btf-type-id.ll
  llvm/test/CodeGen/BPF/CORE/btf-id-duplicate.ll
  llvm/test/CodeGen/BPF/optnone-2.ll

Index: llvm/test/CodeGen/BPF/optnone-2.ll
===
--- llvm/test/CodeGen/BPF/optnone-2.ll
+++ llvm/test/CodeGen/BPF/optnone-2.ll
@@ -12,14 +12,16 @@
 ; Function Attrs: noinline nounwind optnone
 define dso_local i32 @foo() #0 !dbg !9 {
 entry:
-  %0 = call i32 @llvm.bpf.btf.type.id(i32 0, i64 0), !dbg !12, !llvm.preserve.access.index !4
-  %1 = call i32 @llvm.bpf.preserve.type.info(i32 1, i64 0), !dbg !13, !llvm.preserve.access.index !14
-  %add = add i32 %0, %1, !dbg !17
-  ret i32 %add, !dbg !18
+  %0 = call i64 @llvm.bpf.btf.type.id(i32 0, i64 0), !dbg !11, !llvm.preserve.access.index !4
+  %1 = call i32 @llvm.bpf.preserve.type.info(i32 1, i64 0), !dbg !12, !llvm.preserve.access.index !13
+  %conv = zext i32 %1 to i64, !dbg !12
+  %add = add i64 %0, %conv, !dbg !16
+  %conv1 = trunc i64 %add to i32, !dbg !11
+  ret i32 %conv1, !dbg !17
 }
 
 ; Function Attrs: nounwind readnone
-declare i32 @llvm.bpf.btf.type.id(i32, i64) #1
+declare i64 @llvm.bpf.btf.type.id(i32, i64) #1
 
 ; Function Attrs: nounwind readnone
 declare i32 @llvm.bpf.preserve.type.info(i32, i64) #1
@@ -40,13 +42,12 @@
 !6 = !{i32 2, !"Debug Info Version", i32 3}
 !7 = !{i32 1, !"wchar_size", i32 4}
 !8 = !{!"clang version 12.0.0"}
-!9 = distinct !DISubprogram(name: "foo", scope: !10, file: !10, line: 2, type: !11, scopeLine: 2, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
-!10 = !DIFile(filename: "C:/src/tmp/a.c", directory: "")
-!11 = !DISubroutineType(types: !3)
-!12 = !DILocation(line: 2, column: 21, scope: !9)
-!13 = !DILocation(line: 2, column: 51, scope: !9)
-!14 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "ss", file: !10, line: 1, size: 32, elements: !15)
-!15 = !{!16}
-!16 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !14, file: !10, line: 1, baseType: !4, size: 32)
-!17 = !DILocation(line: 2, column: 49, scope: !9)
-!18 = !DILocation(line: 2, column: 14, scope: !9)
+!9 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !10, scopeLine: 2, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!10 = !DISubroutineType(types: !3)
+!11 = !DILocation(line: 2, column: 20, scope: !9)
+!12 = !DILocation(line: 2, column: 50, scope: !9)
+!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "ss", file: !1, line: 1, size: 32, elements: !14)
+!14 = !{!15}
+!15 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !13, file: !1, line: 1, baseType: !4, size: 32)
+!16 = !DILocation(line: 2, column: 48, scope: !9)
+!17 = !DILocation(line: 2, column: 13, scope: !9)
Index: llvm/test/CodeGen/BPF/CORE/btf-id-duplicate.ll
===
--- llvm/test/CodeGen/BPF/CORE/btf-id-duplicate.ll
+++ llvm/test/CodeGen/BPF/CORE/btf-id-duplicate.ll
@@ -18,15 +18,16 @@
   %arg.addr = alloca %struct.s1*, align 8
   store %struct.s1* %arg, %struct.s1** %arg.addr, align 8, !tbaa !18
   call void @llvm.dbg.declare(metadata %struct.s1** %arg.addr, metadata !17, metadata !DIExpression()), !dbg !22
-  %0 = call i32 @llvm.bpf.btf.type.id(i32 0, i64 0), !dbg !23, !llvm.preserve.access.index !12
-  ret i32 %0, !dbg !24
+  %0 = call i64 @llvm.bpf.btf.type.id(i32 0, i64 0), !dbg !23, !llvm.preserve.access.index !12
+  %conv = trunc i64 %0 to i32, !dbg !23
+  ret i32 %conv, !dbg !24
 }
 
-; Function Attrs: nounwind readnone speculatable willreturn
+; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
 
 ; Function Attrs: nounwind readnone
-declare i32 @llvm.bpf.btf.type.id(i32, i64) #2
+declare i64 @llvm.bpf.btf.type.id(i32, i64) #2
 
 ; Function Attrs: nounwind
 define dso_local i32 @bar(%struct.s1* %arg) #0 !dbg !25 {
@@ -34,8 +35,9 @@
   %arg.addr = alloca %struct.s1*, align 8
   store %struct.s1* %arg, %struct.s1** %arg.addr, align 8, !tbaa !18
   call void @llvm.dbg.declare(metadata %struct.s1** %arg.addr, metadata !27, metadata !DIExpression()), !dbg !28
-  %0 = call i32 @llvm.bpf.btf.type.id(i32 1, i64 0), !dbg !29, !llvm.preserve.access.index !12
-  ret i32 %0, !dbg !30
+  %0 = call i64 @llvm.bpf.btf.type.id(i32 1, i64 0), !dbg !29, !llvm.

[PATCH] D91195: Add Annotation2MD pass to add !annotate metadata from llvm.global.annotations

2020-11-16 Thread Florian Hahn via Phabricator via cfe-commits
fhahn marked an inline comment as done.
fhahn added a comment.

Thanks Jessica & Francis! I committed the initial version, with a small change 
to only run if the `!annotation` remarks are enabled.




Comment at: llvm/include/llvm/Transforms/IPO/Annotation2Metadata.h:1
+//===- SCCP.h - Sparse Conditional Constant Propagation -*- C++ 
-*-===//
+//

paquette wrote:
> Fix filename in comment?
Done in the final version, thanks!



Comment at: llvm/include/llvm/Transforms/IPO/Annotation2Metadata.h:20
+
+/// Pass to perform interprocedural constant propagation.
+class Annotation2MetadataPass : public PassInfoMixin {

paquette wrote:
> Fix comment
Done in the final version, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91195

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


[PATCH] D91438: [AArch64] Define __ARM_FEATURE_{CRC32,ATOMICS}

2020-11-16 Thread Andre Vieira via Phabricator via cfe-commits
avieira updated this revision to Diff 305504.
avieira added a comment.

Rebased on top of trunk.


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

https://reviews.llvm.org/D91438

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/test/Preprocessor/aarch64-target-features.c


Index: clang/test/Preprocessor/aarch64-target-features.c
===
--- clang/test/Preprocessor/aarch64-target-features.c
+++ clang/test/Preprocessor/aarch64-target-features.c
@@ -62,6 +62,8 @@
 // RUN: %clang -target arm64-none-linux-gnu -mcrc -x c -E -dM %s -o - | 
FileCheck --check-prefix=CHECK-CRC32 %s
 // RUN: %clang -target aarch64-none-linux-gnu -march=armv8-a+crc -x c -E -dM 
%s -o - | FileCheck --check-prefix=CHECK-CRC32 %s
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+crc -x c -E -dM %s 
-o - | FileCheck --check-prefix=CHECK-CRC32 %s
+// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.1-a -x c -E -dM %s 
-o - | FileCheck --check-prefix=CHECK-CRC32 %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8.1-a -x c -E -dM %s -o 
- | FileCheck --check-prefix=CHECK-CRC32 %s
 // CHECK-CRC32: __ARM_FEATURE_CRC32 1
 
 // RUN: %clang -target aarch64-none-linux-gnu -fno-math-errno 
-fno-signed-zeros\
@@ -451,3 +453,10 @@
 // CHECK-SVE-VECTOR-BITS-512: __ARM_FEATURE_SVE_BITS 512
 // CHECK-SVE-VECTOR-BITS-1024: __ARM_FEATURE_SVE_BITS 1024
 // CHECK-SVE-VECTOR-BITS-2048: __ARM_FEATURE_SVE_BITS 2048
+
+// == Check Largse System Extensions (LSE)
+// RUN: %clang -target aarch64-none-linux-gnu -march=armv8-a+lse -x c -E -dM 
%s -o - | FileCheck --check-prefix=CHECK-LSE %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+lse -x c -E -dM %s 
-o - | FileCheck --check-prefix=CHECK-LSE %s
+// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.1-a -x c -E -dM %s 
-o - | FileCheck --check-prefix=CHECK-LSE %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8.1-a -x c -E -dM %s -o 
- | FileCheck --check-prefix=CHECK-LSE %s
+// CHECK-LSE: __ARM_FEATURE_ATOMICS 1
Index: clang/lib/Basic/Targets/AArch64.h
===
--- clang/lib/Basic/Targets/AArch64.h
+++ clang/lib/Basic/Targets/AArch64.h
@@ -44,6 +44,7 @@
   bool HasSVE2BitPerm;
   bool HasMatmulFP64;
   bool HasMatmulFP32;
+  bool HasLSE;
 
   llvm::AArch64::ArchKind ArchKind;
 
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -155,8 +155,9 @@
 
 void AArch64TargetInfo::getTargetDefinesARMV81A(const LangOptions &Opts,
 MacroBuilder &Builder) const {
-  // FIXME: Armv8.1 makes __ARM_FEATURE_CRC32 mandatory. Handle it here.
   Builder.defineMacro("__ARM_FEATURE_QRDMX", "1");
+  Builder.defineMacro("__ARM_FEATURE_ATOMICS", "1");
+  Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
 }
 
 void AArch64TargetInfo::getTargetDefinesARMV82A(const LangOptions &Opts,
@@ -176,8 +177,6 @@
 void AArch64TargetInfo::getTargetDefinesARMV84A(const LangOptions &Opts,
 MacroBuilder &Builder) const {
   // Also include the Armv8.3 defines
-  // FIXME: Armv8.4 makes __ARM_FEATURE_ATOMICS, defined in GCC, mandatory.
-  // Add and handle it here.
   getTargetDefinesARMV83A(Opts, Builder);
 }
 
@@ -304,6 +303,9 @@
   if (HasMatMul)
 Builder.defineMacro("__ARM_FEATURE_MATMUL_INT8", "1");
 
+  if (HasLSE)
+Builder.defineMacro("__ARM_FEATURE_ATOMICS", "1");
+
   if (HasBFloat16) {
 Builder.defineMacro("__ARM_FEATURE_BF16", "1");
 Builder.defineMacro("__ARM_FEATURE_BF16_VECTOR_ARITHMETIC", "1");
@@ -416,6 +418,7 @@
   HasSVE2BitPerm = false;
   HasMatmulFP64 = false;
   HasMatmulFP32 = false;
+  HasLSE = false;
 
   ArchKind = llvm::AArch64::ArchKind::ARMV8A;
 
@@ -497,6 +500,8 @@
   HasMatMul = true;
 if (Feature == "+bf16")
   HasBFloat16 = true;
+if (Feature == "+lse")
+  HasLSE = true;
   }
 
   setDataLayout();


Index: clang/test/Preprocessor/aarch64-target-features.c
===
--- clang/test/Preprocessor/aarch64-target-features.c
+++ clang/test/Preprocessor/aarch64-target-features.c
@@ -62,6 +62,8 @@
 // RUN: %clang -target arm64-none-linux-gnu -mcrc -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-CRC32 %s
 // RUN: %clang -target aarch64-none-linux-gnu -march=armv8-a+crc -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-CRC32 %s
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+crc -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-CRC32 %s
+// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.1-a -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-CRC32 %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8.1-a -x c -E -dM %s -o -

[PATCH] D90871: [Sema] Fold VLAs to constant arrays in a few more contexts

2020-11-16 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington updated this revision to Diff 305506.
erik.pilkington added a comment.

Use a bit on Declarator instead of an ad-hoc bool parameter.


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

https://reviews.llvm.org/D90871

Files:
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/decl-in-prototype.c
  clang/test/Sema/vla.c
  clang/test/SemaObjC/variable-size-ivar.m

Index: clang/test/SemaObjC/variable-size-ivar.m
===
--- /dev/null
+++ clang/test/SemaObjC/variable-size-ivar.m
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+
+const int ksize = 42;
+int size = 42;
+
+@interface X
+{
+  int arr1[ksize]; // expected-warning{{variable length array folded to constant array}}
+  int arr2[size]; // expected-error{{instance variables must have a constant size}}
+  int arr3[ksize-43]; // expected-error{{array size is negative}}
+}
+@end
Index: clang/test/Sema/vla.c
===
--- clang/test/Sema/vla.c
+++ clang/test/Sema/vla.c
@@ -100,3 +100,29 @@
 typedef struct {
   char c[pr44406_a]; // expected-warning {{folded to constant array as an extension}}
 } pr44406_s;
+
+void test_fold_to_constant_array() {
+  const int ksize = 4;
+
+  goto jump_over_a1; // expected-error{{cannot jump from this goto statement to its label}}
+  char a1[ksize]; // expected-note{{variable length array}}
+ jump_over_a1:;
+
+  char a2[ksize] = "foo"; // expected-warning{{variable length array folded to constant array as an extension}}
+
+  char a3[ksize] = {}; // expected-warning {{variable length array folded to constant array as an extension}} expected-warning{{use of GNU empty initializer}}
+
+  goto jump_over_a4; // expected-error{{cannot jump from this goto statement to its label}}
+  char a4[ksize][2]; // expected-note{{variable length array}}
+ jump_over_a4:;
+
+  char a5[ksize][2] = {}; // expected-warning {{variable length array folded to constant array as an extension}} expected-warning{{use of GNU empty initializer}}
+
+  int a6[ksize] = {1,2,3,4}; // expected-warning{{variable length array folded to constant array as an extension}}
+
+  // expected-warning@+1{{variable length array folded to constant array as an extension}}
+  int a7[ksize] __attribute__((annotate("foo"))) = {1,2,3,4};
+
+  // expected-warning@+1{{variable length array folded to constant array as an extension}}
+  char a8[2][ksize] = {{1,2,3,4},{4,3,2,1}};
+}
Index: clang/test/Sema/decl-in-prototype.c
===
--- clang/test/Sema/decl-in-prototype.c
+++ clang/test/Sema/decl-in-prototype.c
@@ -49,7 +49,7 @@
 // function.
 enum { BB = 0 };
 void enum_in_fun_in_fun(void (*fp)(enum { AA, BB } e)) { // expected-warning {{will not be visible}}
-  SA(1, AA == 5); // expected-error {{variable-sized object may not be initialized}}
+  SA(1, AA == 5); // expected-warning{{variable length array folded to constant array as an extension}}
   SA(2, BB == 0);
 }
 
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -6023,6 +6023,31 @@
   return FixedTInfo;
 }
 
+/// Attempt to fold a variable-sized type to a constant-sized type, returning
+/// true if it we were successful.
+static bool tryToFixVariablyModifiedVarType(Sema &S, TypeSourceInfo *&TInfo,
+QualType &T, SourceLocation Loc,
+unsigned FailedFoldDiagID) {
+  bool SizeIsNegative;
+  llvm::APSInt Oversized;
+  TypeSourceInfo *FixedTInfo = TryToFixInvalidVariablyModifiedTypeSourceInfo(
+  TInfo, S.Context, SizeIsNegative, Oversized);
+  if (FixedTInfo) {
+S.Diag(Loc, diag::ext_vla_folded_to_constant);
+TInfo = FixedTInfo;
+T = FixedTInfo->getType();
+return true;
+  }
+
+  if (SizeIsNegative)
+S.Diag(Loc, diag::err_typecheck_negative_array_size);
+  else if (Oversized.getBoolValue())
+S.Diag(Loc, diag::err_array_too_large) << Oversized.toString(10);
+  else if (FailedFoldDiagID)
+S.Diag(Loc, FailedFoldDiagID);
+  return false;
+}
+
 /// Register the given locally-scoped extern "C" declaration so
 /// that it can be found later for redeclarations. We include any extern "C"
 /// declaration that is not visible in the translation unit here, not just
@@ -6871,6 +6896,10 @@
   VarTemplateDecl *NewTemplate = nullptr;
   TemplateParameterList *TemplateParams = nullptr;
   if (!getLangOpts().CPlusPlus) {
+if (D.hasInitializer() && R->isVariablyModifiedType())
+  tryToFixVariablyModifiedVarType(*this, TInfo, R, D.getIdentifierLoc(),
+  /*DiagID=*/0);
+
 NewVD = VarDecl::Create(Context, DC, D.getBeginLoc(), D.getIdentifierLoc(),
 II, R, TInfo,

[PATCH] D91543: [clang-tidy] Improving bugprone-sizeof-expr check.

2020-11-16 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: cfe-commits, martong, gamesh411, Szelethus, dkrupp, 
xazax.hun, whisperity.
Herald added a project: clang.
balazske requested review of this revision.

Do not warn for "pointer to aggregate" in a `sizeof(A) / sizeof(A[0])`
expression if `A` is an array of pointers. This is the usual way of
calculating the array length even if the array is of pointers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91543

Files:
  clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-sizeof-expression.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-sizeof-expression.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-sizeof-expression.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-sizeof-expression.cpp
@@ -276,6 +276,10 @@
   int A[] = {1, 2, 3, 4};
   static const char str[] = "hello";
   static const char* ptr[] { "aaa", "bbb", "ccc" };
+  typedef C *CA10[10];
+  C *PtrArray[10];
+  CA10 PtrArray1;
+
   int sum = 0;
   if (sizeof(A) < 10)
 sum += sizeof(A);
@@ -293,5 +297,7 @@
   sum += sizeof(str) / sizeof(str[0]);
   sum += sizeof(ptr) / sizeof(ptr[0]);
   sum += sizeof(ptr) / sizeof(*(ptr));
+  sum += sizeof(PtrArray) / sizeof(PtrArray[0]);
+  sum += sizeof(PtrArray) / sizeof(PtrArray1[0]);
   return sum;
 }
Index: clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -132,6 +132,7 @@
  this);
 
   // Detect sizeof(ptr) where ptr points to an aggregate (i.e. sizeof(&S)).
+  // Do not find it if RHS of a 'sizeof(arr) / sizeof(arr[0])' expression.
   const auto ArrayExpr = expr(ignoringParenImpCasts(
   expr(hasType(qualType(hasCanonicalType(arrayType()));
   const auto ArrayCastExpr = expr(anyOf(
@@ -151,13 +152,31 @@
   hasType(qualType(hasCanonicalType(PointerToStructType))),
   unless(cxxThisExpr();
 
-  Finder->addMatcher(
-  expr(anyOf(sizeOfExpr(has(expr(ignoringParenImpCasts(
-   anyOf(ArrayCastExpr, PointerToArrayExpr, StructAddrOfExpr,
- PointerToStructExpr),
-sizeOfExpr(has(PointerToStructType
-  .bind("sizeof-pointer-to-aggregate"),
-  this);
+  const auto ArrayOfPointersExpr = expr(ignoringParenImpCasts(expr(hasType(
+  qualType(hasCanonicalType(arrayType(hasElementType(pointerType()))
+.bind("type-of-array-of-pointers")));
+  const auto ArrayOfSamePointersExpr =
+  expr(ignoringParenImpCasts(expr(hasType(qualType(hasCanonicalType(
+  arrayType(equalsBoundNode("type-of-array-of-pointers";
+  const auto ZeroLiteral =
+  expr(ignoringParenImpCasts(integerLiteral(equals(0;
+  const auto ArrayOfSamePointersZeroSubscriptExpr =
+  expr(ignoringParenImpCasts(arraySubscriptExpr(
+  hasBase(ArrayOfSamePointersExpr), hasIndex(ZeroLiteral;
+  const auto ArrayLengthExprDenom =
+  expr(hasParent(expr(ignoringParenImpCasts(
+   binaryOperator(hasOperatorName("/"),
+  hasLHS(expr(ignoringParenImpCasts(expr(
+  sizeOfExpr(has(ArrayOfPointersExpr)),
+   sizeOfExpr(has(ArrayOfSamePointersZeroSubscriptExpr)));
+
+  
Finder->addMatcher(expr(anyOf(sizeOfExpr(has(expr(ignoringParenImpCasts(anyOf(
+ArrayCastExpr, PointerToArrayExpr,
+StructAddrOfExpr, PointerToStructExpr),
+sizeOfExpr(has(PointerToStructType))),
+  unless(ArrayLengthExprDenom))
+ .bind("sizeof-pointer-to-aggregate"),
+ this);
 
   // Detect expression like: sizeof(epxr) <= k for a suspicious constant 'k'.
   if (WarnOnSizeOfCompareToConstant) {


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-sizeof-expression.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-sizeof-expression.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-sizeof-expression.cpp
@@ -276,6 +276,10 @@
   int A[] = {1, 2, 3, 4};
   static const char str[] = "hello";
   static const char* ptr[] { "aaa", "bbb", "ccc" };
+  typedef C *CA10[10];
+  C *PtrArray[10];
+  CA10 PtrArray1;
+
   int sum = 0;
   if (sizeof(A) < 10)
 sum += sizeof(A);
@@ -293,5 +297,7 @@
   sum += sizeof(str) / sizeof(str[0]);
   sum += sizeof(ptr) / sizeof(ptr[0]);
   sum += sizeof(ptr) / sizeof(*(ptr));
+  sum += sizeof(PtrArray) / sizeof(PtrArray[0]);
+  sum += sizeof(PtrArray) / sizeof(PtrAr

[PATCH] D90984: Update matchers to be traverse-aware

2020-11-16 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:3115
+
+  if (!Finder->isTraversalAsIs() && (*MatchIt)->isImplicit())
+return false;

aaron.ballman wrote:
> If the traversal is not `AsIs`, that doesn't mean it's 
> `IgnoreUnlessSpelledInSource` -- it could be 
> `IgnoreImplicitCastsAndParentheses`, right? So I think the logic for some of 
> these AST matchers is incorrect when in `IgnoreImplicitCastsAndParentheses` 
> traversal mode and should be double-checked. We should probably add some 
> extra test coverage for that mode.
As far as I know, the problem of implicit nodes has been known for a long time. 
Adding calls to `IgnoreParenImpCasts()` in certain places like `hasArgument` 
was one attempt at making the implicit nodes less convenient for users. As far 
as I know, `IgnoreImplicitCastsAndParentheses` was just another attempt at the 
same thing. I must have discovered that by reading code history at some point. 
Both previous attempts didn't go far enough to actually solve the problem, but 
`IgnoreUnlessSpelledInSource` does go all the way, and `traverse` puts control 
in the hands of the user. D20801 at least seems to have been an attempt to put 
control back in the hands of the user. And it was a follow-up to D18243.

So, once this and D90982 are merged, I think it makes sense to start to remove 
`IgnoreImplicitCastsAndParentheses` entirely. It is legacy, incompletely useful 
and just causes some mess in the code. 

Two modes aught to be enough for anybody.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4084
+return false;
+  return InnerMatcher.matches(*Arg->IgnoreParenImpCasts(), Finder, Builder);
 }

aaron.ballman wrote:
> Huh, I never noticed that we implicitly are ignoring parens and implicit 
> casts for this (without checking the traversal mode or documenting the 
> behavior!). That seems less-than-ideal in some ways. (No change required, I 
> only noticed it because it made me think through whether we need it on the 
> `isa<>` check above, which we don't.)
Yes, I think calls to `ignore*` like this within matcher implementations should 
be removed, giving the user control instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90984

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


[PATCH] D90188: Add support for attribute 'using_if_exists'

2020-11-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D90188#2394361 , @erik.pilkington 
wrote:

> Add support for C++11-style attributes on using-declarations.

FWIW, it'd be a bit easier if those changes were split off into their own 
patch, as they're orthogonal to `using_if_exists`.




Comment at: clang/include/clang/Basic/AttrDocs.td:5351
+the availability of those declarations is difficult or impossible to detect at
+compile time with the preprocessor.
+  }];

Do you think the docs should call out that using the C++ spelling on a `using` 
declaration is currently a Clang extension? It's a bit of an odd place to put 
that information, but I don't know of where else to mention that this attribute 
is nonportable in a few different ways.



Comment at: clang/include/clang/Basic/DiagnosticParseKinds.td:689
 def err_attributes_not_allowed : Error<"an attribute list cannot appear here">;
+def ext_cxx11_attr_placement : Extension<
+  "C++ does not allow an attribute list to appear here">,

I'm not certain what @rsmith thinks, but I think this should be `ExtWarn` and 
have the `DefaultIgnore` removed -- this is a conforming extension of something 
that's nonportable even in the absence of any attributes in the attribute list. 
e.g., `[[]] using foo::bar;``` is not portable to parse.



Comment at: clang/include/clang/Basic/DiagnosticParseKinds.td:690
+def ext_cxx11_attr_placement : Extension<
+  "C++ does not allow an attribute list to appear here">,
+  InGroup>, DefaultIgnore;

I think that should say `ISO C++` instead of just `C++` to make it clear that 
this is a standards thing, not a C++-as-it-really-is thing.



Comment at: clang/include/clang/Serialization/ASTBitCodes.h:1364
+  /// An UnresolvedUsingIfExistsDecl record.
+  DECL_UNRESOLVED_USING_IF_EXISTS,
+

Does this mean you need to bump `VERSION_MAJOR` as well?



Comment at: clang/test/Parser/cxx0x-attributes.cpp:160
 template using U [[]] = T;
-using ns::i [[]]; // expected-error {{an attribute list cannot appear here}}
+using ns::i [[]];
 using [[]] ns::i; // expected-error {{an attribute list cannot appear here}}

Can you also add a test for `using foo [[]], bar []]];` syntax?



Comment at: clang/test/SemaCXX/using-if-exists-attr.cpp:9-17
+using NS::x [[clang::using_if_exists]]; // expected-warning{{C++ does not 
allow an attribute list to appear here}}
+
+[[clang::using_if_exists]] // expected-warning{{C++ does not allow an 
attribute list to appear here}}
+using NS::not_there, NS::not_there2;
+
+using NS::not_there3, // expected-error {{no member named 'not_there3' in 
namespace 'NS'}}
+  NS::not_there4 [[clang::using_if_exists]]; // expected-warning{{C++ does 
not allow an attribute list to appear here}}

These test cases look like they belong in a `Parser` test not a `SemaCXX` test.


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

https://reviews.llvm.org/D90188

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


[PATCH] D91544: [clang-tidy] Allow `TransformerClangTidyCheck` clients to set the rule directly.

2020-11-16 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added a reviewer: gribozavr2.
Herald added a subscriber: xazax.hun.
Herald added a project: clang.
ymandel requested review of this revision.

Adds support for setting the `Rule` field. In the process, refactors the code 
that accesses that field and adds a constructor that doesn't require a rule 
argument.

This feature is needed by checks that must set the rule *after* the check class
is constructed. For example, any check that maintains state to be accessed from
the rule needs this support. Since the object's fields are not initialized when
the superclass constructor is called, they can't be (safely) captured by a rule
passed to the existing constructor.  This patch allows constructing the check
superclass fully before setting the rule.

As a driveby fix, removed the "optional" from the rule, since rules are just a
set of cases, so empty rules are evident.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91544

Files:
  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
@@ -38,6 +38,8 @@
 //  includes.
 class TransformerClangTidyCheck : public ClangTidyCheck {
 public:
+  TransformerClangTidyCheck(StringRef Name, ClangTidyContext *Context);
+
   // \p MakeRule generates the rewrite rule to be used by the check, based on
   // the given language and clang-tidy options. It can return \c None to handle
   // cases where the options disable the check.
@@ -68,8 +70,11 @@
   /// the overridden method.
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
 
+  /// Set the rule that this check implements.
+  void setRule(transformer::RewriteRule R);
+
 private:
-  Optional Rule;
+  transformer::RewriteRule Rule;
   IncludeInserter Inserter;
 };
 
Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
===
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
@@ -21,6 +21,18 @@
 }
 #endif
 
+static void verifyRule(const RewriteRule &Rule) {
+  assert(llvm::all_of(Rule.Cases, hasExplanation) &&
+ "clang-tidy checks must have an explanation by default;"
+ " explicitly provide an empty explanation if none is desired");
+}
+
+TransformerClangTidyCheck::TransformerClangTidyCheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Inserter(
+  Options.getLocalOrGlobal("IncludeStyle", IncludeSorter::IS_LLVM)) {}
+
 // This constructor cannot dispatch to the simpler one (below), because, in
 // order to get meaningful results from `getLangOpts` and `Options`, we need the
 // `ClangTidyCheck()` constructor to have been called. If we were to dispatch,
@@ -31,24 +43,21 @@
 const OptionsView &)>
 MakeRule,
 StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context), Rule(MakeRule(getLangOpts(), Options)),
-  Inserter(
-  Options.getLocalOrGlobal("IncludeStyle", IncludeSorter::IS_LLVM)) {
-  if (Rule)
-assert(llvm::all_of(Rule->Cases, hasExplanation) &&
-   "clang-tidy checks must have an explanation by default;"
-   " explicitly provide an empty explanation if none is desired");
+: TransformerClangTidyCheck(Name, Context) {
+  if (Optional R = MakeRule(getLangOpts(), Options))
+setRule(std::move(*R));
 }
 
 TransformerClangTidyCheck::TransformerClangTidyCheck(RewriteRule R,
  StringRef Name,
  ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context), Rule(std::move(R)),
-  Inserter(
-  Options.getLocalOrGlobal("IncludeStyle", IncludeSorter::IS_LLVM)) {
-  assert(llvm::all_of(Rule->Cases, hasExplanation) &&
- "clang-tidy checks must have an explanation by default;"
- " explicitly provide an empty explanation if none is desired");
+: TransformerClangTidyCheck(Name, Context) {
+  setRule(std::move(R));
+}
+
+void TransformerClangTidyCheck::setRule(transformer::RewriteRule R) {
+  verifyRule(R);
+  Rule = std::move(R);
 }
 
 void TransformerClangTidyCheck::registerPPCallbacks(
@@ -58,8 +67,8 @@
 
 void TransformerClangTidyCheck::registerMatchers(
 ast_matchers::MatchFinder *Finder) {
-  if (Rule)
-for (auto &Matcher : transformer::detail::buildMatchers(*Rule))
+  if (!Rule.Cases.empty())
+for (auto &Matcher : transformer::detail::buildMatchers(Rule))
   Finder->addDynamic

[PATCH] D91428: Add support for multiple program address spaces

2020-11-16 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 305521.
pmatos added a comment.

Fix type check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91428

Files:
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  llvm/docs/LangRef.rst
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/include/llvm/IR/DataLayout.h
  llvm/include/llvm/Target/TargetMachine.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLParser.h
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/DataLayout.cpp
  llvm/lib/IR/Function.cpp
  llvm/lib/IR/Module.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/Assembler/function-address_spaces.ll

Index: llvm/test/Assembler/function-address_spaces.ll
===
--- /dev/null
+++ llvm/test/Assembler/function-address_spaces.ll
@@ -0,0 +1,30 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck  %s
+
+; specifying explicitly P:0 (although it's the default)
+; P:1 specifies an extra address space for code where funcrefs live
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1-P0-P1"
+
+; square and double_square are in addrspace(0)
+define i32 @square(i32 %0) {
+; CHECK: define i32 @square(i32 %0) addrspace(0) {
+   %2 = mul nsw i32 %0, %0
+   ret i32 %2
+}
+
+define i32 @double_square(i32 %0) {
+; CHECK: define i32 @double_square(i32 %0) addrspace(0) {
+   %2 = shl i32 %0, 1
+   %3 = mul i32 %2, %0
+   ret i32 %3
+}
+
+; funcref is a pointer to a function in addrspace(1)
+; called in call_funcref
+%func = type void ()
+%funcref = type %func addrspace(1)*
+
+define void @call_funcref(%funcref %ref) {
+; CHECK: define void @call_funcref(void () addrspace(1)* %ref) addrspace(0) {
+   call void %ref()
+   ret void
+}
Index: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
===
--- llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -1220,12 +1220,12 @@
   Function *JT;
   if (isa(Slot.TypeID)) {
 JT = Function::Create(FT, Function::ExternalLinkage,
-  M.getDataLayout().getProgramAddressSpace(),
+  M.getDataLayout().getDefaultProgramAddressSpace(),
   getGlobalName(Slot, {}, "branch_funnel"), &M);
 JT->setVisibility(GlobalValue::HiddenVisibility);
   } else {
 JT = Function::Create(FT, Function::InternalLinkage,
-  M.getDataLayout().getProgramAddressSpace(),
+  M.getDataLayout().getDefaultProgramAddressSpace(),
   "branch_funnel", &M);
   }
   JT->addAttribute(1, Attribute::Nest);
Index: llvm/lib/Transforms/IPO/LowerTypeTests.cpp
===
--- llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -1276,12 +1276,12 @@
 void LowerTypeTestsModule::moveInitializerToModuleConstructor(
 GlobalVariable *GV) {
   if (WeakInitializerFn == nullptr) {
-WeakInitializerFn = Function::Create(
-FunctionType::get(Type::getVoidTy(M.getContext()),
-  /* IsVarArg */ false),
-GlobalValue::InternalLinkage,
-M.getDataLayout().getProgramAddressSpace(),
-"__cfi_global_var_init", &M);
+WeakInitializerFn =
+Function::Create(FunctionType::get(Type::getVoidTy(M.getContext()),
+   /* IsVarArg */ false),
+ GlobalValue::InternalLinkage,
+ M.getDataLayout().getDefaultProgramAddressSpace(),
+ "__cfi_global_var_init", &M);
 BasicBlock *BB =
 BasicBlock::Create(M.getContext(), "entry", WeakInitializerFn);
 ReturnInst::Create(M.getContext(), BB);
@@ -1517,12 +1517,11 @@
   for (unsigned I = 0; I != Functions.size(); ++I)
 GlobalLayout[Functions[I]] = I * EntrySize;
 
-  Function *JumpTableFn =
-  Function::Create(FunctionType::get(Type::getVoidTy(M.getContext()),
- /* IsVarArg */ false),
-   GlobalValue::PrivateLinkage,
-   M.getDataLayout().getProgramAddressSpace(),
-   ".cfi.jumptable", &M);
+  Function *JumpTableFn = Function::Create(
+  FunctionType::get(Type::getVoidTy(M.getContext()),
+/* IsVarArg */ false),
+  GlobalValue::PrivateLinkage,
+  M.getDataLayout().getDefaultProgramAddressSpace(), ".cfi.jumptable", &M);
   ArrayType *JumpTableType =
   ArrayType::get(getJumpTableEntryType(), Functions.size());
   auto JumpTable =
@@ -1962,7 +1961,8 @@
   F = Function::Create(
   

[PATCH] D91546: [AMDGPU] Add option -munsafe-fp-atomics

2020-11-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: tra, rjmccall, arsenm.
Herald added subscribers: dang, kerbowa, jfb, t-tye, tpr, dstuttard, nhaehnle, 
jvesely, kzhuravl.
yaxunl requested review of this revision.
Herald added a subscriber: wdng.

Add an option -munsafe-fp-atomics for AMDGPU target.

When enabled, clang adds function attribute "amdgpu-unsafe-fp-atomics"
to any functions for amdgpu target. This allows amdgpu backend to use
unsafe fp atomic instructions in these functions.


https://reviews.llvm.org/D91546

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Basic/TargetOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGenCUDA/amdgpu-func-attrs.cu
  clang/test/Driver/hip-options.hip

Index: clang/test/Driver/hip-options.hip
===
--- clang/test/Driver/hip-options.hip
+++ clang/test/Driver/hip-options.hip
@@ -31,3 +31,7 @@
 // HOST-NOT: clang{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}"
 // HOST-NOT: clang{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}"
 // HOST: clang{{.*}} "-debug-info-kind={{.*}}"
+
+// RUN: %clang -### -nogpuinc -nogpulib -munsafe-fp-atomics \
+// RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefix=UNSAFE-FP-ATOMICS %s
+// UNSAFE-FP-ATOMICS: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} "-munsafe-fp-atomics"
Index: clang/test/CodeGenCUDA/amdgpu-func-attrs.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/amdgpu-func-attrs.cu
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa \
+// RUN: -fcuda-is-device -emit-llvm -o - -x hip %s \
+// RUN: | FileCheck -check-prefixes=NO-UNSAFE-FP-ATOMICS %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa \
+// RUN: -fcuda-is-device -emit-llvm -o - -x hip %s \
+// RUN: -munsafe-fp-atomics \
+// RUN: | FileCheck -check-prefixes=UNSAFE-FP-ATOMICS %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm \
+// RUN: -o - -x hip %s -munsafe-fp-atomics \
+// RUN: | FileCheck -check-prefix=NO-UNSAFE-FP-ATOMICS %s
+
+#include "Inputs/cuda.h"
+
+__device__ void test() {
+// UNSAFE-FP-ATOMICS: define void @_Z4testv() [[ATTR:#[0-9]+]]
+}
+
+
+// Make sure this is silently accepted on other targets.
+// NO-UNSAFE-FP-ATOMICS-NOT: "amdgpu-unsafe-fp-atomics"
+
+// UNSAFE-FP-ATOMICS-DAG: attributes [[ATTR]] = {{.*}}"amdgpu-unsafe-fp-atomics"="true"
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3719,6 +3719,9 @@
   Opts.ForceEnableInt128 = Args.hasArg(OPT_fforce_enable_int128);
   Opts.NVPTXUseShortPointers = Args.hasFlag(
   options::OPT_fcuda_short_ptr, options::OPT_fno_cuda_short_ptr, false);
+  Opts.AllowAMDGPUUnsafeFPAtomics =
+  Args.hasFlag(options::OPT_munsafe_fp_atomics,
+   options::OPT_mno_unsafe_fp_atomics, false);
   if (Arg *A = Args.getLastArg(options::OPT_target_sdk_version_EQ)) {
 llvm::VersionTuple Version;
 if (Version.tryParse(A->getValue()))
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6217,6 +6217,11 @@
   }
 
   HandleAmdgcnLegacyOptions(D, Args, CmdArgs);
+  if (Triple.isAMDGPU()) {
+if (Args.hasFlag(options::OPT_munsafe_fp_atomics,
+ options::OPT_mno_unsafe_fp_atomics))
+  CmdArgs.push_back("-munsafe-fp-atomics");
+  }
 
   // For all the host OpenMP offloading compile jobs we need to pass the targets
   // information using -fopenmp-targets= option.
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -9080,6 +9080,9 @@
 if (NumVGPR != 0)
   F->addFnAttr("amdgpu-num-vgpr", llvm::utostr(NumVGPR));
   }
+
+  if (M.getContext().getTargetInfo().allowAMDGPUUnsafeFPAtomics())
+F->addFnAttr("amdgpu-unsafe-fp-atomics", "true");
 }
 
 unsigned AMDGPUTargetCodeGenInfo::getOpenCLKernelCallingConv() const {
Index: clang/lib/Basic/Targets/AMDGPU.cpp
===
--- clang/lib/Basic/Targets/AMDGPU.cpp
+++ clang/lib/Basic/Targets/AMDGPU.cpp
@@ -323,6 +323,7 @@
   HasLegalHalfType = true;
   HasFloat16 = true;
   WavefrontSize = GPUFeatures & llvm::AMDGPU::FEATURE_WAVE32 ? 32 : 64;
+  AllowAMDGPUUnsafeFPAtomics = Opts.AllowAMDGPUUnsafeFPAtomics;
 
   // Set pointer width and alignment for target address space 0.
   PointerWidth = PointerAlign = Da

[PATCH] D90892: [AIX][FE] Support constructor/destructor attribute

2020-11-16 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L marked 5 inline comments as done.
Xiangling_L added inline comments.



Comment at: clang/test/CodeGen/aix-constructor-attribute.cpp:8
 
-int foo() __attribute__((constructor(180)));
+// CHECK: @llvm.global_ctors = appending global [3 x { i32, void ()*, i8* }] 
[{ i32, void ()*, i8* } { i32 65535, void ()* bitcast (i32 ()* @foo3 to void 
()*), i8* null }, { i32, void ()*, i8* } { i32 180, void ()* bitcast (i32 ()* 
@foo2 to void ()*), i8* null }, { i32, void ()*, i8* } { i32 180, void ()* 
bitcast (i32 ()* @foo to void ()*), i8* null }]
 

sfertile wrote:
> Did you mean for this test to be a C or C++ test? If it is meant to be C++ it 
> needs to mangle the function names, but considering the director it is in and 
> the fact we have the same test in CodeGenCXX directory I expect this was 
> meant to be C in which case it needs a `.c` extension and lose the `-x c++` 
> in the run steps.
Thanks for pointing this out to me, I should've changed the file extension when 
I copied this testcase from CXX testcases.



Comment at: clang/test/CodeGenCXX/aix-destructor-attribute.cpp:1
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -x c++ -emit-llvm \
+// RUN: -fno-use-cxa-atexit < %s | \

sfertile wrote:
> Can I ask why this is added as a new file? Its the same test as 
> `aix-sinit-register-global-dtors-with-atexit.cpp` but without using 
> `-fregister-global-dtors-with-atexit`. I suggest combining the 2.
Agree, it makes more sense to combine two. I tried to make testcases look 
cleaner by splitting them.


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

https://reviews.llvm.org/D90892

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


[PATCH] D91428: Add support for multiple program address spaces

2020-11-16 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a subscriber: tianshilei1992.
jdoerfert requested changes to this revision.
jdoerfert added a comment.
This revision now requires changes to proceed.

I'll be on the lookout for the RFC. There, and in an updated commit message, 
you have to provide more details.

http://lists.llvm.org/pipermail/llvm-dev/2020-July/143808.html is related as 
well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91428

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


[PATCH] D91104: APINotes: add property models for YAML attributes

2020-11-16 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

Ping; I'd let to get this sorted out so I can continue to make progress towards 
serialization and deserialization.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91104

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


[PATCH] D90892: [AIX][FE] Support constructor/destructor attribute

2020-11-16 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L updated this revision to Diff 305526.
Xiangling_L marked 2 inline comments as done.
Xiangling_L added a comment.

Update testcases;


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

https://reviews.llvm.org/D90892

Files:
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/aix-constructor-attribute.c
  clang/test/CodeGen/aix-constructor-attribute.cpp
  clang/test/CodeGen/aix-destructor-attribute.c
  clang/test/CodeGen/aix-destructor-attribute.cpp
  clang/test/CodeGenCXX/aix-constructor-attribute.cpp
  clang/test/CodeGenCXX/aix-destructor-attribute.cpp
  clang/test/CodeGenCXX/aix-sinit-register-global-dtors-with-atexit.cpp

Index: clang/test/CodeGenCXX/aix-sinit-register-global-dtors-with-atexit.cpp
===
--- clang/test/CodeGenCXX/aix-sinit-register-global-dtors-with-atexit.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-// RUN: not %clang_cc1 -triple powerpc-ibm-aix-xcoff -S -emit-llvm -x c++ \
-// RUN: -fregister-global-dtors-with-atexit < %s 2>&1 | \
-// RUN:   FileCheck %s
-
-// RUN: not %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ \
-// RUN: -fregister-global-dtors-with-atexit < %s 2>&1 | \
-// RUN:   FileCheck %s
-
-struct T {
-  T();
-  ~T();
-} t;
-
-// CHECK: error in backend: register global dtors with atexit() is not supported yet
Index: clang/test/CodeGenCXX/aix-destructor-attribute.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/aix-destructor-attribute.cpp
@@ -0,0 +1,90 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -x c++ -emit-llvm \
+// RUN: -fno-use-cxa-atexit < %s | \
+// RUN:   FileCheck --check-prefix=NO-REGISTER %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -x c++ -emit-llvm \
+// RUN: -fno-use-cxa-atexit < %s | \
+// RUN:   FileCheck --check-prefix=NO-REGISTER %s
+
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -x c++ -emit-llvm \
+// RUN: -fno-use-cxa-atexit -fregister-global-dtors-with-atexit < %s | \
+// RUN:   FileCheck --check-prefix=REGISTER %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -x c++ -emit-llvm \
+// RUN: -fno-use-cxa-atexit -fregister-global-dtors-with-atexit < %s | \
+// RUN:   FileCheck --check-prefix=REGISTER %s
+
+struct test {
+  test();
+  ~test();
+} t;
+
+int bar() __attribute__((destructor(100)));
+int bar2() __attribute__((destructor(65535)));
+int bar3(int) __attribute__((destructor(65535)));
+
+int bar() {
+  return 1;
+}
+
+int bar2() {
+  return 2;
+}
+
+int bar3(int a) {
+  return a;
+}
+
+// NO-REGISTER: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I__, i8* null }]
+// NO-REGISTER: @llvm.global_dtors = appending global [4 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 100, void ()* bitcast (i32 ()* @_Z3barv to void ()*), i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* bitcast (i32 ()* @_Z4bar2v to void ()*), i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* bitcast (i32 (i32)* @_Z4bar3i to void ()*), i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__D_a, i8* null }]
+
+// REGISTER: @llvm.global_ctors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I__, i8* null }, { i32, void ()*, i8* } { i32 100, void ()* @__GLOBAL_init_100, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @__GLOBAL_init_65535, i8* null }]
+// REGISTER: @llvm.global_dtors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__D_a, i8* null }, { i32, void ()*, i8* } { i32 100, void ()* @__GLOBAL_cleanup_100, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @__GLOBAL_cleanup_65535, i8* null }]
+
+// REGISTER: define internal void @__GLOBAL_init_100() [[ATTR:#[0-9]+]] {
+// REGISTER: entry:
+// REGISTER:   %0 = call i32 @atexit(void ()* bitcast (i32 ()* @_Z3barv to void ()*))
+// REGISTER:   ret void
+// REGISTER: }
+
+// REGISTER: define internal void @__GLOBAL_init_65535() [[ATTR:#[0-9]+]] {
+// REGISTER: entry:
+// REGISTER:   %0 = call i32 @atexit(void ()* bitcast (i32 ()* @_Z4bar2v to void ()*))
+// REGISTER:   %1 = call i32 @atexit(void ()* bitcast (i32 (i32)* @_Z4bar3i to void ()*))
+// REGISTER:   ret void
+// REGISTER: }
+
+// REGISTER: define internal void @__GLOBAL_cleanup_100() [[ATTR:#[0-9]+]] {
+// REGISTER: entry:
+// REGISTER:   %0 = call i32 @unatexit(void ()* bitcast (i32 ()* @_Z3barv to void ()*))
+// REGISTER:   %needs_destruct = icmp eq i32 %0, 0
+// REGISTER:   br i1 %needs_destruct, label %destruct.call, label %destruct.end
+
+// REGISTER: destruct.call:
+// REGISTER:   call void bitcast (i32 ()* @_Z3barv to void ()*)()
+// REG

[PATCH] D91121: [InferAddrSpace] Teach to handle assumed address space.

2020-11-16 Thread Michael Liao via Phabricator via cfe-commits
hliao marked 3 inline comments as done.
hliao added a comment.

Kindly ping for review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91121

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


[PATCH] D90984: Update matchers to be traverse-aware

2020-11-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:3115
+
+  if (!Finder->isTraversalAsIs() && (*MatchIt)->isImplicit())
+return false;

steveire wrote:
> aaron.ballman wrote:
> > If the traversal is not `AsIs`, that doesn't mean it's 
> > `IgnoreUnlessSpelledInSource` -- it could be 
> > `IgnoreImplicitCastsAndParentheses`, right? So I think the logic for some 
> > of these AST matchers is incorrect when in 
> > `IgnoreImplicitCastsAndParentheses` traversal mode and should be 
> > double-checked. We should probably add some extra test coverage for that 
> > mode.
> As far as I know, the problem of implicit nodes has been known for a long 
> time. Adding calls to `IgnoreParenImpCasts()` in certain places like 
> `hasArgument` was one attempt at making the implicit nodes less convenient 
> for users. As far as I know, `IgnoreImplicitCastsAndParentheses` was just 
> another attempt at the same thing. I must have discovered that by reading 
> code history at some point. Both previous attempts didn't go far enough to 
> actually solve the problem, but `IgnoreUnlessSpelledInSource` does go all the 
> way, and `traverse` puts control in the hands of the user. D20801 at least 
> seems to have been an attempt to put control back in the hands of the user. 
> And it was a follow-up to D18243.
> 
> So, once this and D90982 are merged, I think it makes sense to start to 
> remove `IgnoreImplicitCastsAndParentheses` entirely. It is legacy, 
> incompletely useful and just causes some mess in the code. 
> 
> Two modes aught to be enough for anybody.
> As far as I know, IgnoreImplicitCastsAndParentheses was just another attempt 
> at the same thing. I must have discovered that by reading code history at 
> some point. 

I don't recall the history of this traversal mode, but I think you're correct.

> So, once this and D90982 are merged, I think it makes sense to start to 
> remove IgnoreImplicitCastsAndParentheses entirely. It is legacy, incompletely 
> useful and just causes some mess in the code.

I agree. I see at least two ways to proceed:

1) Change this patch to handle three modes so that we can land it without 
incorrect behavior, then do a follow-up patch to rip out the 
`IgnoreImplicitCastsAndParentheses` mode.
2) Rip out `IgnoreImplicitCastsAndParentheses` first and then land this patch 
as-is.

My preference is for #1 so that we don't land this patch in an awkward state 
(in case the removal of the other mode gets delayed for some reason). Given 
what I mention below, that shouldn't result in any undue churn, I'd hope.

> Two modes aught to be enough for anybody.

Heh, I would like to think that, but given that this enumeration is used for 
generic traversal of ASTs, I'm less convinced that two modes will be all we 
ever want to support. I think it's a bit more future-proof to add a helper 
method along the lines of `isTraversalIgnoringImplicitNodes()` rather than 
using `!isTraversalAsIs()`.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4054
   unsigned, N) {
-  return Node.getNumArgs() == N;
+  auto NumArgs = Node.getNumArgs();
+  if (Finder->isTraversalAsIs())

`auto` -> `unsigned` please



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4058
+  while (NumArgs) {
+const auto *Arg = Node.getArg(NumArgs - 1);
+if (!isa(Arg))

`auto` -> `const Expr *`  or just get rid of the local variable entirely by 
sinking the initialization into the `isa<>`.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4081
+return false;
+  const auto *Arg = Node.getArg(N);
+  if (!Finder->isTraversalAsIs() && isa(Arg))

`const auto *` -> `const Expr *`



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4084
+return false;
+  return InnerMatcher.matches(*Arg->IgnoreParenImpCasts(), Finder, Builder);
 }

steveire wrote:
> aaron.ballman wrote:
> > Huh, I never noticed that we implicitly are ignoring parens and implicit 
> > casts for this (without checking the traversal mode or documenting the 
> > behavior!). That seems less-than-ideal in some ways. (No change required, I 
> > only noticed it because it made me think through whether we need it on the 
> > `isa<>` check above, which we don't.)
> Yes, I think calls to `ignore*` like this within matcher implementations 
> should be removed, giving the user control instead.
I agree. I'm a little bit worried about what will break when we make the 
change, but I think that model is the more defensible one. (It looks like there 
are a handful of similar cases in ASTMatchers.h, so we should try to hit them 
all).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90984

___
cf

[PATCH] D72184: [BPF] support atomic instructions

2020-11-16 Thread Brendan Jackman via Phabricator via cfe-commits
jackmanb added a comment.

Sorry I was disrupted and not able to work on this last week! I've just got 
started trying to integrate this with my kernel patches.




Comment at: llvm/lib/Target/BPF/BPFInstrInfo.td:666
+def XADDD : XADD;
+  }
+}

FYI - I just spotted some stray `\t` in here (is it helpful to point this out? 
If not let me know, I will ignore in future)



Comment at: llvm/lib/Target/BPF/BPFInstrInfo.td:684
+  let Inst{47-32} = addr{15-0}; // offset
+  let Inst{11-8} = val;
+  let Inst{7-4} = Opc.Value;

Sorry I'm a beginner with the LLVM code, could you explain what `val` does? I 
didn't notice this when I looked through here before.

To try and get a clue I tried just removing this line and then compiling the 
following code:

```C
// SPDX-License-Identifier: GPL-2.0
#include 

#include 
#include 
#include 

__u64 test_data_64 = 0;
__u64 test1_result = 0;

SEC("fentry/bpf_fentry_test1")
int BPF_PROG(test1, int a)
{
/* atomic_fetch_add(&test_data_64, 1); */
test1_result = __sync_fetch_and_add(&test_data_64, 1);
return 0;
}
```

And I was able to load and run the program, with the kernel on my WIP branch: 
https://github.com/bjackman/linux-bpf/tree/wips/bpf-atomics-v0

The result looks like this:

```shell
$ llvm-objdump -d atomics_test.o

atomics_test.o: file format elf64-bpf


Disassembly of section fentry/bpf_fentry_test1:

 :
   0:   b7 01 00 00 01 00 00 00 r1 = 1
   1:   18 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r2 = 0 ll
   3:   db 12 00 00 01 00 00 00 r1 = atomic_fetch_add((u64 *)(r2 + 0), 
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash 
backtrace.
Stack dump:
0.  Program arguments: llvm-objdump -d atomics_test.o 
Segmentation fault
```

Aside from the fact that llvm-objdump crashed, the encoding `db 12 00 00 01 00 
00 00` seems correct to me. If I add the `let Inst{11-8} = val` back in I get 
`db 12 00 00 01 01 00 00` which I don't understand.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72184

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


[PATCH] D91121: [InferAddrSpace] Teach to handle assumed address space.

2020-11-16 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp:533
+  if (!LD)
+return -1;
+

Is there a suitable constant for `don't know` result?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91121

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


[PATCH] D91546: [AMDGPU] Add option -munsafe-fp-atomics

2020-11-16 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

LGTM.

Patch description could use a pointer to more details about the unsafe atomics.




Comment at: clang/include/clang/Basic/TargetOptions.h:78
 
+  /// \brief If enabled, allow AMDGPU unsafe floating point atomics.
+  bool AllowAMDGPUUnsafeFPAtomics = false;

I'm curious -- what does `unsafe` mean here?


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

https://reviews.llvm.org/D91546

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


[PATCH] D72184: [BPF] support atomic instructions

2020-11-16 Thread Brendan Jackman via Phabricator via cfe-commits
jackmanb added inline comments.



Comment at: llvm/lib/Target/BPF/BPFInstrInfo.td:684
+  let Inst{47-32} = addr{15-0}; // offset
+  let Inst{11-8} = val;
+  let Inst{7-4} = Opc.Value;

jackmanb wrote:
> Sorry I'm a beginner with the LLVM code, could you explain what `val` does? I 
> didn't notice this when I looked through here before.
> 
> To try and get a clue I tried just removing this line and then compiling the 
> following code:
> 
> ```C
> // SPDX-License-Identifier: GPL-2.0
> #include 
> 
> #include 
> #include 
> #include 
> 
> __u64 test_data_64 = 0;
> __u64 test1_result = 0;
> 
> SEC("fentry/bpf_fentry_test1")
> int BPF_PROG(test1, int a)
> {
> /* atomic_fetch_add(&test_data_64, 1); */
> test1_result = __sync_fetch_and_add(&test_data_64, 1);
> return 0;
> }
> ```
> 
> And I was able to load and run the program, with the kernel on my WIP branch: 
> https://github.com/bjackman/linux-bpf/tree/wips/bpf-atomics-v0
> 
> The result looks like this:
> 
> ```shell
> $ llvm-objdump -d atomics_test.o
> 
> atomics_test.o: file format elf64-bpf
> 
> 
> Disassembly of section fentry/bpf_fentry_test1:
> 
>  :
>0:   b7 01 00 00 01 00 00 00 r1 = 1
>1:   18 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r2 = 0 ll
>3:   db 12 00 00 01 00 00 00 r1 = atomic_fetch_add((u64 *)(r2 + 
> 0), PLEASE submit a bug report to https://bugs.llvm.org/ and include the 
> crash backtrace.
> Stack dump:
> 0.  Program arguments: llvm-objdump -d atomics_test.o 
> Segmentation fault
> ```
> 
> Aside from the fact that llvm-objdump crashed, the encoding `db 12 00 00 01 
> 00 00 00` seems correct to me. If I add the `let Inst{11-8} = val` back in I 
> get `db 12 00 00 01 01 00 00` which I don't understand.
Ah wait, I guess this is adding a 3rd operand register? In my example it's 
unclear because it is R1 which is also the dst operand. I was envisaging we 
just have semantics like `src = atomic_fetch_add(dst+off, src)` but you are 
instead proposing `dst = atomic_fetch_add(dst+off, val)`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72184

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


[PATCH] D72184: [BPF] support atomic instructions

2020-11-16 Thread Brendan Jackman via Phabricator via cfe-commits
jackmanb added inline comments.



Comment at: llvm/lib/Target/BPF/BPFInstrInfo.td:684
+  let Inst{47-32} = addr{15-0}; // offset
+  let Inst{11-8} = val;
+  let Inst{7-4} = Opc.Value;

jackmanb wrote:
> jackmanb wrote:
> > Sorry I'm a beginner with the LLVM code, could you explain what `val` does? 
> > I didn't notice this when I looked through here before.
> > 
> > To try and get a clue I tried just removing this line and then compiling 
> > the following code:
> > 
> > ```C
> > // SPDX-License-Identifier: GPL-2.0
> > #include 
> > 
> > #include 
> > #include 
> > #include 
> > 
> > __u64 test_data_64 = 0;
> > __u64 test1_result = 0;
> > 
> > SEC("fentry/bpf_fentry_test1")
> > int BPF_PROG(test1, int a)
> > {
> > /* atomic_fetch_add(&test_data_64, 1); */
> > test1_result = __sync_fetch_and_add(&test_data_64, 1);
> > return 0;
> > }
> > ```
> > 
> > And I was able to load and run the program, with the kernel on my WIP 
> > branch: https://github.com/bjackman/linux-bpf/tree/wips/bpf-atomics-v0
> > 
> > The result looks like this:
> > 
> > ```shell
> > $ llvm-objdump -d atomics_test.o
> > 
> > atomics_test.o: file format elf64-bpf
> > 
> > 
> > Disassembly of section fentry/bpf_fentry_test1:
> > 
> >  :
> >0:   b7 01 00 00 01 00 00 00 r1 = 1
> >1:   18 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r2 = 0 ll
> >3:   db 12 00 00 01 00 00 00 r1 = atomic_fetch_add((u64 *)(r2 + 
> > 0), PLEASE submit a bug report to https://bugs.llvm.org/ and include the 
> > crash backtrace.
> > Stack dump:
> > 0.  Program arguments: llvm-objdump -d atomics_test.o 
> > Segmentation fault
> > ```
> > 
> > Aside from the fact that llvm-objdump crashed, the encoding `db 12 00 00 01 
> > 00 00 00` seems correct to me. If I add the `let Inst{11-8} = val` back in 
> > I get `db 12 00 00 01 01 00 00` which I don't understand.
> Ah wait, I guess this is adding a 3rd operand register? In my example it's 
> unclear because it is R1 which is also the dst operand. I was envisaging we 
> just have semantics like `src = atomic_fetch_add(dst+off, src)` but you are 
> instead proposing `dst = atomic_fetch_add(dst+off, val)`?
Sorry I mean `dst = atomic_fetch_add(src+off, val)`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72184

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


[PATCH] D72184: [BPF] support atomic instructions

2020-11-16 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added inline comments.



Comment at: llvm/lib/Target/BPF/BPFInstrInfo.td:666
+def XADDD : XADD;
+  }
+}

jackmanb wrote:
> FYI - I just spotted some stray `\t` in here (is it helpful to point this 
> out? If not let me know, I will ignore in future)
\t is not allowed. I will run clang-format next time to catch such violations. 
Thanks for letting me know.



Comment at: llvm/lib/Target/BPF/BPFInstrInfo.td:684
+  let Inst{47-32} = addr{15-0}; // offset
+  let Inst{11-8} = val;
+  let Inst{7-4} = Opc.Value;

jackmanb wrote:
> jackmanb wrote:
> > jackmanb wrote:
> > > Sorry I'm a beginner with the LLVM code, could you explain what `val` 
> > > does? I didn't notice this when I looked through here before.
> > > 
> > > To try and get a clue I tried just removing this line and then compiling 
> > > the following code:
> > > 
> > > ```C
> > > // SPDX-License-Identifier: GPL-2.0
> > > #include 
> > > 
> > > #include 
> > > #include 
> > > #include 
> > > 
> > > __u64 test_data_64 = 0;
> > > __u64 test1_result = 0;
> > > 
> > > SEC("fentry/bpf_fentry_test1")
> > > int BPF_PROG(test1, int a)
> > > {
> > > /* atomic_fetch_add(&test_data_64, 1); */
> > > test1_result = __sync_fetch_and_add(&test_data_64, 1);
> > > return 0;
> > > }
> > > ```
> > > 
> > > And I was able to load and run the program, with the kernel on my WIP 
> > > branch: https://github.com/bjackman/linux-bpf/tree/wips/bpf-atomics-v0
> > > 
> > > The result looks like this:
> > > 
> > > ```shell
> > > $ llvm-objdump -d atomics_test.o
> > > 
> > > atomics_test.o: file format elf64-bpf
> > > 
> > > 
> > > Disassembly of section fentry/bpf_fentry_test1:
> > > 
> > >  :
> > >0:   b7 01 00 00 01 00 00 00 r1 = 1
> > >1:   18 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r2 = 0 ll
> > >3:   db 12 00 00 01 00 00 00 r1 = atomic_fetch_add((u64 *)(r2 
> > > + 0), PLEASE submit a bug report to https://bugs.llvm.org/ and include 
> > > the crash backtrace.
> > > Stack dump:
> > > 0.  Program arguments: llvm-objdump -d atomics_test.o 
> > > Segmentation fault
> > > ```
> > > 
> > > Aside from the fact that llvm-objdump crashed, the encoding `db 12 00 00 
> > > 01 00 00 00` seems correct to me. If I add the `let Inst{11-8} = val` 
> > > back in I get `db 12 00 00 01 01 00 00` which I don't understand.
> > Ah wait, I guess this is adding a 3rd operand register? In my example it's 
> > unclear because it is R1 which is also the dst operand. I was envisaging we 
> > just have semantics like `src = atomic_fetch_add(dst+off, src)` but you are 
> > instead proposing `dst = atomic_fetch_add(dst+off, val)`?
> Sorry I mean `dst = atomic_fetch_add(src+off, val)`
> Sorry I'm a beginner with the LLVM code, could you explain what `val` does? I 
> didn't notice this when I looked through here before.

For the below statement:
  test1_result = __sync_fetch_and_add(&test_data_64, 1);

'val' represents the register which holds the value '1'.

bit 4-7 is also used in compare-and-exchange insn as you need a memory 
location, in-register old/new values.

> 
> To try and get a clue I tried just removing this line and then compiling the 
> following code:
> 
> ```C
> // SPDX-License-Identifier: GPL-2.0
> #include 
> 
> #include 
> #include 
> #include 
> 
> __u64 test_data_64 = 0;
> __u64 test1_result = 0;
> 
> SEC("fentry/bpf_fentry_test1")
> int BPF_PROG(test1, int a)
> {
> /* atomic_fetch_add(&test_data_64, 1); */
> test1_result = __sync_fetch_and_add(&test_data_64, 1);
> return 0;
> }
> ```
> 
> And I was able to load and run the program, with the kernel on my WIP branch: 
> https://github.com/bjackman/linux-bpf/tree/wips/bpf-atomics-v0
> 
> The result looks like this:
> 
> ```shell
> $ llvm-objdump -d atomics_test.o
> 
> atomics_test.o: file format elf64-bpf
> 
> 
> Disassembly of section fentry/bpf_fentry_test1:
> 
>  :
>0:   b7 01 00 00 01 00 00 00 r1 = 1
>1:   18 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r2 = 0 ll
>3:   db 12 00 00 01 00 00 00 r1 = atomic_fetch_add((u64 *)(r2 + 
> 0), PLEASE submit a bug report to https://bugs.llvm.org/ and include the 
> crash backtrace.
> Stack dump:
> 0.  Program arguments: llvm-objdump -d atomics_test.o 
> Segmentation fault
> ```
> 

the crash may come from that the 'val' is not encoded properly. I will double 
check.

> Aside from the fact that llvm-objdump crashed, the encoding `db 12 00 00 01 
> 00 00 00` seems correct to me. If I add the `let Inst{11-8} = val` back in I 
> get `db 12 00 00 01 01 00 00` which I don't understand.

in this particular case, yes, as final asm code looks like
   r1 = atomic_fetch_add((u64 *)(r2 + 0), r1)
where the value "r1" and the result "r1" shared the same register. A little bit 
compiler work is need to enforce "val" register and result register always the 
same.

M

[PATCH] D88394: [Driver][M68k] (Patch 8/8) Add driver support for M68k

2020-11-16 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

Some very minor nits - the 68060 omission is the biggest one (apple might not 
have used it but commodore did!)




Comment at: clang/include/clang/Driver/Options.td:155
+def m_m68k_Features_Group: OptionGroup<"">,
+ Group, DocName<"M68k">;
 def m_ppc_Features_Group : OptionGroup<"">,

(sorting) put this before mips?



Comment at: clang/lib/Driver/ToolChains/Arch/M68k.cpp:44
+
+llvm::Regex CPUPattern("m?680([01234]{1})0");
+llvm::SmallVector Matches;

Why no 68060 ?



Comment at: clang/lib/Driver/ToolChains/Arch/M68k.cpp:64
+return "M68040";
+  }
+

(style) remove unnecessary braces?



Comment at: clang/lib/Driver/ToolChains/Arch/M68k.cpp:72
+ const ArgList &Args,
+ std::vector &Features) {
+

(clang-format) indentation?



Comment at: clang/lib/Driver/ToolChains/Arch/M68k.cpp:94
+ABI = m68k::FloatABI::Hard;
+  }
+

remove braces



Comment at: clang/lib/Driver/ToolChains/Arch/M68k.h:35
+ const llvm::opt::ArgList &Args,
+ std::vector &Features);
+

(clang-format) indentation?



Comment at: clang/lib/Driver/ToolChains/Arch/M68k.h:38
+} // end namespace m68k
+} // namespace tools
+} // end namespace driver

(clang-tidy) end namespace tools




Comment at: clang/lib/Driver/ToolChains/Clang.cpp:380
+m68k::getM68kTargetFeatures(D, Triple, Args, Features);
+break;
   }

(sorting) move before msp430 ?



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:297
+  case llvm::Triple::m68k:
+return m68k::getM68kTargetCPU(Args);
+

(sorting) move down to before mips ?


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

https://reviews.llvm.org/D88394

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


[PATCH] D91121: [InferAddrSpace] Teach to handle assumed address space.

2020-11-16 Thread Michael Liao via Phabricator via cfe-commits
hliao added inline comments.



Comment at: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp:533
+  if (!LD)
+return -1;
+

tra wrote:
> Is there a suitable constant for `don't know` result?
I would say all generic pointers loaded from the constant memory are safe to be 
assumed as global ones (for AMDGPU). I explained the reason in the usage 
document. The constant memory could be modified by the host, where only global 
memory objects are visible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91121

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


[PATCH] D91546: [AMDGPU] Add option -munsafe-fp-atomics

2020-11-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: clang/include/clang/Basic/TargetOptions.h:78
 
+  /// \brief If enabled, allow AMDGPU unsafe floating point atomics.
+  bool AllowAMDGPUUnsafeFPAtomics = false;

tra wrote:
> I'm curious -- what does `unsafe` mean here?
unsafe means it does not follow requirements of other floating point options, 
e.g. it may flush denormals even if other fp options requires denormals not 
flushed. This allows user to relax fp restrictions on fp atomic instructions 
without relaxing fp requirements on other instructions.


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

https://reviews.llvm.org/D91546

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


[PATCH] D88138: [NPM] Add target specific hook to add passes for New Pass Manager

2020-11-16 Thread Jameson Nash via Phabricator via cfe-commits
vtjnash added a comment.

I think this, and similar recent commits, are causing the shared library builds 
to fail some tests if this code gets linked into libLLVM.so: 
https://bugs.llvm.org/show_bug.cgi?id=48181. I assume it might actually a bug 
in ld (GNU Binutils for Ubuntu 2.34), as I don't understand the linker behavior 
there?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88138

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


[PATCH] D78903: [Driver] Add option -fproc-stat-report

2020-11-16 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

Could you add quotation marks around the executable name to make the CSV file 
easier to parse?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78903

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


[clang] 41b65f1 - Convert ConstexprKind from Specifiers.h to a scoped enum; NFC

2020-11-16 Thread Aaron Ballman via cfe-commits

Author: Thorsten
Date: 2020-11-16T14:10:19-05:00
New Revision: 41b65f166b51760f77d0f9e465b3858f46e101f0

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

LOG: Convert ConstexprKind from Specifiers.h to a scoped enum; NFC

Added: 


Modified: 
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclCXX.h
clang/include/clang/Basic/Specifiers.h
clang/include/clang/Sema/DeclSpec.h
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/DeclSpec.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Serialization/ASTWriterDecl.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 71896c0db086..7f6f143aa866 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -1978,7 +1978,7 @@ class FunctionDecl : public DeclaratorDecl,
  SourceLocation NLoc, DeclarationName N, QualType T,
  TypeSourceInfo *TInfo, StorageClass SC, bool isInlineSpecified = 
false,
  bool hasWrittenPrototype = true,
- ConstexprSpecKind ConstexprKind = CSK_unspecified,
+ ConstexprSpecKind ConstexprKind = ConstexprSpecKind::Unspecified,
  Expr *TrailingRequiresClause = nullptr) {
 DeclarationNameInfo NameInfo(N, NLoc);
 return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo, SC,
@@ -2230,19 +2230,19 @@ class FunctionDecl : public DeclaratorDecl,
 
   /// Whether this is a (C++11) constexpr function or constexpr constructor.
   bool isConstexpr() const {
-return FunctionDeclBits.ConstexprKind != CSK_unspecified;
+return getConstexprKind() != ConstexprSpecKind::Unspecified;
   }
   void setConstexprKind(ConstexprSpecKind CSK) {
-FunctionDeclBits.ConstexprKind = CSK;
+FunctionDeclBits.ConstexprKind = static_cast(CSK);
   }
   ConstexprSpecKind getConstexprKind() const {
 return static_cast(FunctionDeclBits.ConstexprKind);
   }
   bool isConstexprSpecified() const {
-return FunctionDeclBits.ConstexprKind == CSK_constexpr;
+return getConstexprKind() == ConstexprSpecKind::Constexpr;
   }
   bool isConsteval() const {
-return FunctionDeclBits.ConstexprKind == CSK_consteval;
+return getConstexprKind() == ConstexprSpecKind::Consteval;
   }
 
   /// Whether the instantiation of this function is pending.

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 496caf871a91..36f42c06a300 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1887,7 +1887,7 @@ class CXXDeductionGuideDecl : public FunctionDecl {
 const DeclarationNameInfo &NameInfo, QualType T,
 TypeSourceInfo *TInfo, SourceLocation EndLocation)
   : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo,
- SC_None, false, CSK_unspecified),
+ SC_None, false, ConstexprSpecKind::Unspecified),
 ExplicitSpec(ES) {
 if (EndLocation.isValid())
   setRangeEnd(EndLocation);

diff  --git a/clang/include/clang/Basic/Specifiers.h 
b/clang/include/clang/Basic/Specifiers.h
index 41537672283d..03de6ea6a434 100644
--- a/clang/include/clang/Basic/Specifiers.h
+++ b/clang/include/clang/Basic/Specifiers.h
@@ -29,12 +29,7 @@ namespace clang {
   };
 
   /// Define the kind of constexpr specifier.
-  enum ConstexprSpecKind {
-CSK_unspecified,
-CSK_constexpr,
-CSK_consteval,
-CSK_constinit
-  };
+  enum class ConstexprSpecKind { Unspecified, Constexpr, Consteval, Constinit 
};
 
   /// Specifies the width of a type, e.g., short, long, or long long.
   enum class TypeSpecifierWidth { Unspecified, Short, Long, LongLong };

diff  --git a/clang/include/clang/Sema/DeclSpec.h 
b/clang/include/clang/Sema/DeclSpec.h
index 6a961bc026b0..d2acafc2e4b3 100644
--- a/clang/include/clang/Sema/DeclSpec.h
+++ b/clang/include/clang/Sema/DeclSpec.h
@@ -431,8 +431,10 @@ class DeclSpec {
 TypeQualifiers(TQ_unspecified), FS_inline_specified(false),
 FS_forceinline_specified(false), FS_virtual_specified(false),
 FS_noreturn_specified(false), Friend_specified(false),
-ConstexprSpecifier(CSK_unspecified), FS_explicit_specifier(),
-Attrs(attrFactory), writtenBS(), ObjCQualifiers(nullptr) {}
+ConstexprSpecifier(
+static_cast(ConstexprSpecKind::Unspecified)),
+FS_explicit_specifier(), Attrs(attrFactory), writtenBS(),
+ObjCQualifiers(nullptr) {}
 
   // storage-

[PATCH] D90042: [clang-tidy] performance-unnecessary-copy-initialization: Check for const reference arguments that are replaced template parameter type.

2020-11-16 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, thank you for the fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90042

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


[PATCH] D91552: [OPENMP]Fix PR48076: mapping of data member pointer.

2020-11-16 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 accepted this revision.
jhuber6 added a comment.
This revision is now accepted and ready to land.

LGTM, fixed the problem on my machine and passes the unit tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91552

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


[PATCH] D91507: [clang-format] Add option for case sensitive regexes for sorted includes

2020-11-16 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

Do I have to do something? For me it doesn't look like the build failure is due 
to my changes. 
Locally I've only build and run the FormatTests target.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91507

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


[PATCH] D90982: Ignore implicit nodes in IgnoreUnlessSpelledInSource mode

2020-11-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for this, I think it's mostly looking good!




Comment at: clang/include/clang/AST/ASTNodeTraverser.h:88
   void Visit(const Decl *D) {
+if (Traversal != TK_AsIs && D->isImplicit())
+  return;

Similar to the feedback on D90984, I think this will do the wrong thing for the 
weird traversal mode for ignoring parens and implicit casts. It should probably 
be checking for `Traversal == TK_IgnoreUnlessSpelledInSource` here.



Comment at: clang/include/clang/AST/ASTNodeTraverser.h:192
   void Visit(const CXXCtorInitializer *Init) {
+if (Traversal != TK_AsIs && !Init->isWritten())
+  return;

Same issue here.



Comment at: clang/include/clang/AST/ASTNodeTraverser.h:410
 
+if (Traversal != TK_AsIs && D->isDefaulted())
+  return;

Same here. I'll stop calling these out -- can you double check all the uses of 
`Traversal != TK_AsIs`?



Comment at: clang/include/clang/AST/ASTNodeTraverser.h:733
+  void VisitCXXForRangeStmt(const CXXForRangeStmt *Node) {
+if (Traversal != TK_AsIs) {
+  Visit(Node->getInit());

If we're in AsIs mode, don't we still want to match on some parts of the 
range-based for loop because they are spelled in source (like the body of the 
loop or the range-expression, etc)? 

The test behavior looks reasonable around this, so I suspect I'm just 
misunderstanding this change.



Comment at: clang/include/clang/AST/ASTNodeTraverser.h:742
+  void VisitCallExpr(const CallExpr *Node) {
+for (auto Child :
+ make_filter_range(Node->children(), [this](const Stmt *Child) {

This be `const auto *` or at least `auto *`.



Comment at: clang/lib/ASTMatchers/ASTMatchFinder.cpp:152
+
+if (DeclNode && DeclNode->isImplicit() && !Finder->isTraversalAsIs())
+  return baseTraverse(*DeclNode);

Similar issue here about traversal mode.



Comment at: clang/lib/ASTMatchers/ASTMatchFinder.cpp:1083
+
+  auto ScopedTraversal =
+  TraversingASTNodeNotSpelledInSource || DeclNode->isImplicit();

Spelling this as `bool` would not be amiss (same below, given how trivial it is 
to spell the type out).



Comment at: clang/lib/ASTMatchers/ASTMatchFinder.cpp:1108
   }
+  auto ScopedTraversal = TraversingASTNodeNotSpelledInSource ||
+ TraversingASTChildrenNotSpelledInSource;

`bool` here as well, please.



Comment at: clang/lib/ASTMatchers/ASTMatchFinder.cpp:1157
 
+  auto ScopedTraversal = TraversingASTNodeNotSpelledInSource ||
+ TraversingASTChildrenNotSpelledInSource;

Here too.



Comment at: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:2503
+EXPECT_TRUE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
+

Can you add one more test for the body like 
`cxxForRangeStmt(hasBody(compoundStmt()))` which should match in both modes?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90982

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


[PATCH] D91559: Add sysroot/lib to library search path of baremetal toolchain.

2020-11-16 Thread Hafiz Abid Qadeer via Phabricator via cfe-commits
abidh created this revision.
abidh added reviewers: jroelofs, clang.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
abidh requested review of this revision.

Baremetal toolchain is not adding sysroot/lib to the library
search path. This is forcing the user to do it manually. This commit
fixes this shortcoming by adding the sysroot/lib to library search path
if sysroot is not empty.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91559

Files:
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/test/Driver/baremetal.cpp


Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -12,6 +12,7 @@
 // CHECK-V6M-C-SAME: "-x" "c++" "{{.*}}baremetal.cpp"
 // CHECK-V6M-C-NEXT: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" 
"{{.*}}.o" "-Bstatic"
 // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-V6M-C-SAME: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-V6M-C-SAME: "-T" "semihosted.lds" 
"-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for"
 // CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m"
 // CHECK-V6M-C-SAME: "-o" "{{.*}}.o"
@@ -34,6 +35,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-V6M-DEFAULTCXX %s
 // CHECK-V6M-DEFAULTCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" 
"{{.*}}.o" "-Bstatic"
 // CHECK-V6M-DEFAULTCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-V6M-DEFAULTCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-DEFAULTCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
 // CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m"
 // CHECK-V6M-DEFAULTCXX-SAME: "-o" "{{.*}}.o"
@@ -47,6 +49,7 @@
 // CHECK-V6M-LIBCXX: "-internal-isystem" 
"{{[^"]+}}{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
 // CHECK-V6M-LIBCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" 
"{{.*}}.o" "-Bstatic"
 // CHECK-V6M-LIBCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-V6M-LIBCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
 // CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m"
 // CHECK-V6M-LIBCXX-SAME: "-o" "{{.*}}.o"
@@ -60,6 +63,7 @@
 // CHECK-V6M-LIBSTDCXX: "-internal-isystem" 
"{{[^"]+}}{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}6.0.0"
 // CHECK-V6M-LIBSTDCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" 
"{{.*}}.o" "-Bstatic"
 // CHECK-V6M-LIBSTDCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-V6M-LIBSTDCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBSTDCXX-SAME: "-lstdc++" "-lsupc++" "-lunwind"
 // CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m"
 // CHECK-V6M-LIBSTDCXX-SAME: "-o" "{{.*}}.o"
@@ -70,7 +74,8 @@
 // RUN: -nodefaultlibs \
 // RUN:   | FileCheck --check-prefix=CHECK-V6M-NDL %s
 // CHECK-V6M-NDL: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" 
"-Bstatic"
-// CHECK-V6M-NDL-SAME: 
"-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal"
 "-o" "{{.*}}.o"
+// CHECK-V6M-NDL-SAME: 
"-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-V6M-NDL-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib" "-o" 
"{{.*}}.o"
 
 // RUN: %clangxx -target arm-none-eabi -v 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-THREAD-MODEL
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -33,6 +33,11 @@
   getProgramPaths().push_back(getDriver().getInstalledDir());
   if (getDriver().getInstalledDir() != getDriver().Dir)
 getProgramPaths().push_back(getDriver().Dir);
+  SmallString<128> SysRoot(getDriver().SysRoot);
+  if (!SysRoot.empty()) {
+llvm::sys::path::append(SysRoot, "lib");
+getFilePaths().push_back(std::string(SysRoot.str()));
+  }
 }
 
 /// Is the triple {arm,thumb}-none-none-{eabi,eabihf} ?
@@ -189,6 +194,7 @@
 
   CmdArgs.push_back(Args.MakeArgString("-L" + TC.getRuntimesDir()));
 
+  TC.AddFilePathLibArgs(Args, CmdArgs);
   Args.AddAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_e, options::OPT_s, options::OPT_t,
 options::OPT_Z_Flag, options::OPT_r});


Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -12,6 +12,7 @@
 // CHECK-V6M-C-SAME: "-x" "c++" "{{.*}}bareme

[PATCH] D91442: [clang][Driver] Handle risvc in Baremetal.cpp.

2020-11-16 Thread Hafiz Abid Qadeer via Phabricator via cfe-commits
abidh updated this revision to Diff 305573.
abidh added a comment.

Made the condition consistent in both places where Baremetal toolchain is 
instantiated as suggested in review.


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

https://reviews.llvm.org/D91442

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/test/Driver/baremetal.cpp
  clang/test/Driver/riscv-gnutools.c
  clang/test/Driver/riscv32-toolchain.c
  clang/test/Driver/riscv64-toolchain.c

Index: clang/test/Driver/riscv64-toolchain.c
===
--- clang/test/Driver/riscv64-toolchain.c
+++ clang/test/Driver/riscv64-toolchain.c
@@ -1,11 +1,13 @@
 // A basic clang -cc1 command-line, and simple environment check.
 // REQUIRES: platform-linker
 
-// RUN: %clang %s -### -no-canonical-prefixes -target riscv64 2>&1 | FileCheck -check-prefix=CC1 %s
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv64 \
+// RUN: --gcc-toolchain=%S/Inputs/basic_riscv64_tree 2>&1 | FileCheck -check-prefix=CC1 %s
 // CC1: clang{{.*}} "-cc1" "-triple" "riscv64"
 
 // Test interaction with -fuse-ld=lld, if lld is available.
-// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 -fuse-ld=lld 2>&1 | FileCheck -check-prefix=LLD %s
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 -fuse-ld=lld \
+// RUN: --gcc-toolchain=%S/Inputs/basic_riscv64_tree 2>&1 | FileCheck -check-prefix=LLD %s
 // LLD: {{(error: invalid linker name in argument '-fuse-ld=lld')|(ld.lld)}}
 
 // In the below tests, --rtlib=platform is used so that the driver ignores
@@ -133,6 +135,7 @@
 
 // Check that --rtlib can be used to override the used runtime library
 // RUN: %clang %s -### -no-canonical-prefixes \
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk \
 // RUN:   -target riscv64-unknown-elf --rtlib=libgcc 2>&1 \
 // RUN:   | FileCheck -check-prefix=C-RV64-RTLIB-LIBGCC-LP64 %s
 // C-RV64-RTLIB-LIBGCC-LP64: "{{.*}}crt0.o"
@@ -141,6 +144,7 @@
 // C-RV64-RTLIB-LIBGCC-LP64: "{{.*}}crtend.o"
 
 // RUN: %clang %s -### -no-canonical-prefixes \
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk \
 // RUN:   -target riscv64-unknown-elf --rtlib=compiler-rt 2>&1 \
 // RUN:   | FileCheck -check-prefix=C-RV64-RTLIB-COMPILERRT-LP64 %s
 // C-RV64-RTLIB-COMPILERRT-LP64: "{{.*}}crt0.o"
Index: clang/test/Driver/riscv32-toolchain.c
===
--- clang/test/Driver/riscv32-toolchain.c
+++ clang/test/Driver/riscv32-toolchain.c
@@ -1,11 +1,13 @@
 // A basic clang -cc1 command-line, and simple environment check.
 // REQUIRES: platform-linker
 
-// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 2>&1 | FileCheck -check-prefix=CC1 %s
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 \
+// RUN: --gcc-toolchain=%S/Inputs/basic_riscv32_tree 2>&1 | FileCheck -check-prefix=CC1 %s
 // CC1: clang{{.*}} "-cc1" "-triple" "riscv32"
 
 // Test interaction with -fuse-ld=lld, if lld is available.
-// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 -fuse-ld=lld 2>&1 | FileCheck -check-prefix=LLD %s
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 \
+// RUN: --gcc-toolchain=%S/Inputs/basic_riscv32_tree -fuse-ld=lld 2>&1 | FileCheck -check-prefix=LLD %s
 // LLD: {{(error: invalid linker name in argument '-fuse-ld=lld')|(ld.lld)}}
 
 // In the below tests, --rtlib=platform is used so that the driver ignores
@@ -177,6 +179,7 @@
 
 // Check that --rtlib can be used to override the used runtime library
 // RUN: %clang %s -### -no-canonical-prefixes \
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk \
 // RUN:   -target riscv32-unknown-elf --rtlib=libgcc 2>&1 \
 // RUN:   | FileCheck -check-prefix=C-RV32-RTLIB-LIBGCC-ILP32 %s
 // C-RV32-RTLIB-LIBGCC-ILP32: "{{.*}}crt0.o"
@@ -185,6 +188,7 @@
 // C-RV32-RTLIB-LIBGCC-ILP32: "{{.*}}crtend.o"
 
 // RUN: %clang %s -### -no-canonical-prefixes \
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk \
 // RUN:   -target riscv32-unknown-elf --rtlib=compiler-rt 2>&1 \
 // RUN:   | FileCheck -check-prefix=C-RV32-RTLIB-COMPILERRT-ILP32 %s
 // C-RV32-RTLIB-COMPILERRT-ILP32: "{{.*}}crt0.o"
Index: clang/test/Driver/riscv-gnutools.c
===
--- clang/test/Driver/riscv-gnutools.c
+++ clang/test/Driver/riscv-gnutools.c
@@ -5,15 +5,15 @@
 // 32-bit checks
 
 // Check default on riscv32-unknown-elf
-// RUN: %clang -target riscv32-unknown-elf -fno-integrated-as %s -### -c \
+// RUN: %clang -target riscv32-unknown-elf --gcc-toolchain=%S/Inputs/basic_riscv32_tree -fno-integrated-as %s -### -c \
 // RUN: 2>&1 | FileCheck -check-prefix=CHECK-RV32IMAC-ILP32 %s
 
 // Check default on riscv32-unknown-linux-gnu
-// RUN: %clang -target riscv32-unknown-linux-gnu -fno-integrated-as %s -### -c \
+// RUN: %clang -target riscv32-unknown-linux-gnu --gcc-toolchain=%S/Inputs/basic_riscv32_tree 

[PATCH] D90173: [PowerPC] Exploit splat instruction xxsplti32dx in Power10

2020-11-16 Thread Albion Fung via Phabricator via cfe-commits
Conanap updated this revision to Diff 305575.
Conanap added a comment.

clang format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90173

Files:
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCInstrPrefix.td
  llvm/test/CodeGen/PowerPC/p10-splatImm-CPload-pcrel.ll
  llvm/test/CodeGen/PowerPC/p10-splatImm32.ll

Index: llvm/test/CodeGen/PowerPC/p10-splatImm32.ll
===
--- llvm/test/CodeGen/PowerPC/p10-splatImm32.ll
+++ llvm/test/CodeGen/PowerPC/p10-splatImm32.ll
@@ -118,3 +118,25 @@
   %vecins1 = shufflevector <4 x i32> , <4 x i32> %a, <4 x i32> 
   ret <4 x i32> %vecins1
 }
+
+define dso_local <2 x double> @test_xxsplti32dx_8() {
+; CHECK-LABEL: test_xxsplti32dx_8
+; CHECK-LE: xxlxor vs34, vs34, vs34
+; CHECK-LE: xxsplti32dx vs34, 1, 1082660167
+; CHECK-BE: xxlxor vs34, vs34, vs34
+; CHECK-BE: xxsplti32dx vs34, 0, 1082660167
+; CHECK: blr
+entry:
+  ret <2 x double> 
+}
+
+define dso_local <8 x i16> @test_xxsplti32dx_9() {
+; CHECK-LABEL: test_xxsplti32dx_9
+; CHECK-LE: xxlxor vs34, vs34, vs34
+; CHECK-LE: xxsplti32dx vs34, 1, 23855277
+; CHECK-BE: xxlxor vs34, vs34, vs34
+; CHECK-BE: xxsplti32dx vs34, 0, 19070977
+; CHECK: blr
+entry:
+  ret <8 x i16> 
+}
Index: llvm/test/CodeGen/PowerPC/p10-splatImm-CPload-pcrel.ll
===
--- llvm/test/CodeGen/PowerPC/p10-splatImm-CPload-pcrel.ll
+++ llvm/test/CodeGen/PowerPC/p10-splatImm-CPload-pcrel.ll
@@ -1,27 +1,29 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -O2 \
-; RUN: -ppc-asm-full-reg-names -mcpu=pwr10 < %s | FileCheck %s
+; RUN: -ppc-asm-full-reg-names -mcpu=pwr10 < %s | FileCheck %s --check-prefixes=CHECK,CHECK-LE
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu -O2 \
 ; RUN: -ppc-asm-full-reg-names -mcpu=pwr10 < %s | FileCheck %s \
-; RUN: --check-prefix=CHECK-NOPCREL
+; RUN: --check-prefixes=CHECK-NOPCREL-BE,CHECK-NOPCREL
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -O2 \
 ; RUN: -mattr=-pcrelative-memops -ppc-asm-full-reg-names -mcpu=pwr10 < %s | \
-; RUN: FileCheck %s --check-prefix=CHECK-NOPCREL
+; RUN: FileCheck %s --check-prefixes=CHECK-NOPCREL-LE,CHECK-NOPCREL
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu -O2 \
 ; RUN: -ppc-asm-full-reg-names -target-abi=elfv2 -mcpu=pwr10 < %s | \
-; RUN: FileCheck %s
+; RUN: FileCheck %s --check-prefixes=CHECK,CHECK-BE
 
 define dso_local <2 x double> @testDoubleToDoubleFail() local_unnamed_addr {
 ; CHECK-LABEL: testDoubleToDoubleFail:
 ; CHECK:   # %bb.0: # %entry
-; CHECK-NEXT:plxv vs34, .LCPI0_0@PCREL(0), 1
+; CHECK-NEXT:xxlxor vs34, vs34, vs34
+; CHECK-LE-NEXT:xxsplti32dx vs34, 1, 1081435463
+; CHECK-BE-NEXT: xxsplti32dx vs34, 0, 1081435463
 ; CHECK-NEXT:blr
 ;
 ; CHECK-NOPCREL-LABEL: testDoubleToDoubleFail:
 ; CHECK-NOPCREL:   # %bb.0: # %entry
-; CHECK-NOPCREL-NEXT:addis r3, r2, .LCPI0_0@toc@ha
-; CHECK-NOPCREL-NEXT:addi r3, r3, .LCPI0_0@toc@l
-; CHECK-NOPCREL-NEXT:lxvx vs34, 0, r3
+; CHECK-NOPCREL-NEXT:xxlxor vs34, vs34, vs34
+; CHECK-NOPCREL-LE-NEXT: xxsplti32dx vs34, 1, 1081435463
+; CHECK-NOPCREL-BE-NEXT: xxsplti32dx vs34, 0, 1081435463
 ; CHECK-NOPCREL-NEXT:blr
 
 entry:
@@ -31,14 +33,16 @@
 define dso_local <2 x double> @testFloatDenormToDouble() local_unnamed_addr {
 ; CHECK-LABEL: testFloatDenormToDouble:
 ; CHECK:   # %bb.0: # %entry
-; CHECK-NEXT:plxv vs34, .LCPI1_0@PCREL(0), 1
+; CHECK-NEXT:xxlxor vs34, vs34, vs34
+; CHECK-LE-NEXT: xxsplti32dx vs34, 1, 940259579
+; CHECK-BE-NEXT: xxsplti32dx vs34, 0, 940259579
 ; CHECK-NEXT:blr
 ;
 ; CHECK-NOPCREL-LABEL: testFloatDenormToDouble:
 ; CHECK-NOPCREL:   # %bb.0: # %entry
-; CHECK-NOPCREL-NEXT:addis r3, r2, .LCPI1_0@toc@ha
-; CHECK-NOPCREL-NEXT:addi r3, r3, .LCPI1_0@toc@l
-; CHECK-NOPCREL-NEXT:lxvx vs34, 0, r3
+; CHECK-NOPCREL-NEXT:xxlxor vs34, vs34, vs34
+; CHECK-NOPCREL-LE-NEXT:xxsplti32dx vs34, 1, 940259579
+; CHECK-NOPCREL-BE-NEXT:xxsplti32dx vs34, 0, 940259579
 ; CHECK-NOPCREL-NEXT:blr
 
 entry:
@@ -48,14 +52,16 @@
 define dso_local <2 x double> @testDoubleToDoubleNaNFail() local_unnamed_addr {
 ; CHECK-LABEL: testDoubleToDoubleNaNFail:
 ; CHECK:   # %bb.0: # %entry
-; CHECK-NEXT:plxv vs34, .LCPI2_0@PCREL(0), 1
+; CHECK-NEXT:xxlxor vs34, vs34, vs34
+; CHECK-LE-NEXT:xxsplti32dx vs34, 1, -1
+; CHECK-BE-NEXT:xxsplti32dx vs34, 0, -1
 ; CHECK-NEXT:blr
 ;
 ; CHECK-NOPCREL-LABEL: testDoubleToDoubleNaNFail:
 ; CHECK-NOPCREL:   # %bb.0: # %entry
-; CHECK-NOPCREL-NEXT:addis r3, r2, .LCPI2_0@toc@ha
-; CHECK-NOPCREL-NEXT:addi r3, r3, .LCPI2_0@toc@l
-; CHECK-NOPCREL-NEXT:lxvx v

[PATCH] D91559: Add sysroot/lib to library search path of baremetal toolchain.

2020-11-16 Thread Jon Roelofs via Phabricator via cfe-commits
jroelofs accepted this revision.
jroelofs added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Driver/ToolChains/BareMetal.cpp:39
+llvm::sys::path::append(SysRoot, "lib");
+getFilePaths().push_back(std::string(SysRoot.str()));
+  }

Is the explicit `std::string` ctor call necessary here? Since `SmallString` has 
an `operator std::string() const`, I think this can just be:

```
getFilePaths().push_back(SysRoot);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91559

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


[PATCH] D91442: [clang][Driver] Handle risvc in Baremetal.cpp.

2020-11-16 Thread Hafiz Abid Qadeer via Phabricator via cfe-commits
abidh marked an inline comment as done.
abidh added a comment.

In D91442#2394501 , @jroelofs wrote:

> Seems reasonable.
>
> I could see someone wanting to use `--gcc-toolchain` to point at the 
> baremetal toolchain for their target, but that's unlikely to work out of the 
> box anyway. I'd love to know where the Generic_GCC toolchain is used in 
> practice, since that's always seemed quite fragile to me.

Thanks for the review. I have handled the comment in updated diff. I will give 
it a few more days in case anyone else wants to comment before landing.


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

https://reviews.llvm.org/D91442

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


[PATCH] D91442: [clang][Driver] Handle risvc in Baremetal.cpp.

2020-11-16 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: clang/test/Driver/riscv64-toolchain.c:5
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv64 \
+// RUN: --gcc-toolchain=%S/Inputs/basic_riscv64_tree 2>&1 | FileCheck 
-check-prefix=CC1 %s
 // CC1: clang{{.*}} "-cc1" "-triple" "riscv64"

(repeated below and in riscv32-toolchain.c)


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

https://reviews.llvm.org/D91442

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


[PATCH] D90042: [clang-tidy] performance-unnecessary-copy-initialization: Check for const reference arguments that are replaced template parameter type.

2020-11-16 Thread Felix Berger via Phabricator via cfe-commits
flx added a comment.

In D90042#2397885 , @aaron.ballman 
wrote:

> LGTM, thank you for the fix!

Thanks for helping track down the difference in our definition of std::function 
:)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90042

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


[PATCH] D67112: [Sema] Introduce function reference conversion, NFC

2020-11-16 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67112

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


[PATCH] D91121: [InferAddrSpace] Teach to handle assumed address space.

2020-11-16 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm accepted this revision.
arsenm added a comment.
This revision is now accepted and ready to land.

LGTM with nits




Comment at: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp:533
+  if (!LD)
+return -1;
+

hliao wrote:
> tra wrote:
> > Is there a suitable constant for `don't know` result?
> I would say all generic pointers loaded from the constant memory are safe to 
> be assumed as global ones (for AMDGPU). I explained the reason in the usage 
> document. The constant memory could be modified by the host, where only 
> global memory objects are visible.
AMDGPUAS::UNKNOWN_ADDRESS_SPACE



Comment at: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp:540
+  const auto *Ptr = LD->getPointerOperand();
+  if (Ptr->getType()->getPointerAddressSpace() != AMDGPUAS::CONSTANT_ADDRESS)
+return -1;

This could be a bit broader but is fine for now



Comment at: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp:541
+  if (Ptr->getType()->getPointerAddressSpace() != AMDGPUAS::CONSTANT_ADDRESS)
+return -1;
+  // For a generic pointer loaded from the constant memory, it could be assumed

Ditto


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91121

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


[PATCH] D91121: [InferAddrSpace] Teach to handle assumed address space.

2020-11-16 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp:483
+// Skip values with an assumed address space.
+if (TTI->getAssumedAddrSpace(TopVal) == UninitializedAddressSpace) {
+  for (Value *PtrOperand : getPointerOperands(*TopVal, *DL, TTI)) {

Checking this here looks strange, since it is also catching values that weren't 
processed as assumed address space


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91121

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


[clang] f375885 - [InferAddrSpace] Teach to handle assumed address space.

2020-11-16 Thread Michael Liao via cfe-commits

Author: Michael Liao
Date: 2020-11-16T17:06:33-05:00
New Revision: f375885ab86d1b3e82269725c8e9aa49f347b4a7

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

LOG: [InferAddrSpace] Teach to handle assumed address space.

- In certain cases, a generic pointer could be assumed as a pointer to
  the global memory space or other spaces. With a dedicated target hook
  to query that address space from a given value, infer-address-space
  pass could infer and propagate that to all its users.

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

Added: 
llvm/test/Transforms/InferAddressSpaces/AMDGPU/assumed-addrspace.ll

Modified: 
clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu
llvm/docs/AMDGPUUsage.rst
llvm/include/llvm/Analysis/TargetTransformInfo.h
llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
llvm/include/llvm/CodeGen/BasicTTIImpl.h
llvm/include/llvm/Target/TargetMachine.h
llvm/lib/Analysis/TargetTransformInfo.cpp
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h
llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
llvm/test/CodeGen/AMDGPU/GlobalISel/divergent-control-flow.ll

Removed: 




diff  --git a/clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu 
b/clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu
index dc4659856026..da1f4b65f719 100644
--- a/clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu
+++ b/clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu
@@ -56,20 +56,24 @@ struct S {
   int *x;
   float *y;
 };
-// `by-val` struct will be coerced into a similar struct with all generic
-// pointers lowerd into global ones.
+// `by-val` struct is passed by-indirect-alias (a mix of by-ref and indirect
+// by-val). However, the enhanced address inferring pass should be able to
+// assume they are global pointers.
+//
 // HOST: define void @_Z22__device_stub__kernel41S(i32* %s.coerce0, float* 
%s.coerce1)
 // COMMON-LABEL: define amdgpu_kernel void @_Z7kernel41S(%struct.S 
addrspace(4)*{{.*}} byref(%struct.S) align 8 %0)
 // OPT: [[R0:%.*]] = getelementptr inbounds %struct.S, %struct.S addrspace(4)* 
%0, i64 0, i32 0
 // OPT: [[P0:%.*]] = load i32*, i32* addrspace(4)* [[R0]], align 8
+// OPT: [[G0:%.*]] = addrspacecast i32* [[P0]] to i32 addrspace(1)*
 // OPT: [[R1:%.*]] = getelementptr inbounds %struct.S, %struct.S addrspace(4)* 
%0, i64 0, i32 1
 // OPT: [[P1:%.*]] = load float*, float* addrspace(4)* [[R1]], align 8
-// OPT: [[V0:%.*]] = load i32, i32* [[P0]], align 4
+// OPT: [[G1:%.*]] = addrspacecast float* [[P1]] to float addrspace(1)*
+// OPT: [[V0:%.*]] = load i32, i32 addrspace(1)* [[G0]], align 4
 // OPT: [[INC:%.*]] = add nsw i32 [[V0]], 1
-// OPT: store i32 [[INC]], i32* [[P0]], align 4
-// OPT: [[V1:%.*]] = load float, float* [[P1]], align 4
+// OPT: store i32 [[INC]], i32 addrspace(1)* [[G0]], align 4
+// OPT: [[V1:%.*]] = load float, float addrspace(1)* [[G1]], align 4
 // OPT: [[ADD:%.*]] = fadd contract float [[V1]], 1.00e+00
-// OPT: store float [[ADD]], float* [[P1]], align 4
+// OPT: store float [[ADD]], float addrspace(1)* [[G1]], align 4
 // OPT: ret void
 __global__ void kernel4(struct S s) {
   s.x[0]++;
@@ -87,19 +91,24 @@ __global__ void kernel5(struct S *s) {
 struct T {
   float *x[2];
 };
-// `by-val` array is also coerced.
+// `by-val` array is passed by-indirect-alias (a mix of by-ref and indirect
+// by-val). However, the enhanced address inferring pass should be able to
+// assume they are global pointers.
+//
 // HOST: define void @_Z22__device_stub__kernel61T(float* %t.coerce0, float* 
%t.coerce1)
 // COMMON-LABEL: define amdgpu_kernel void @_Z7kernel61T(%struct.T 
addrspace(4)*{{.*}} byref(%struct.T) align 8 %0)
 // OPT: [[R0:%.*]] = getelementptr inbounds %struct.T, %struct.T addrspace(4)* 
%0, i64 0, i32 0, i64 0
 // OPT: [[P0:%.*]] = load float*, float* addrspace(4)* [[R0]], align 8
+// OPT: [[G0:%.*]] = addrspacecast float* [[P0]] to float addrspace(1)*
 // OPT: [[R1:%.*]] = getelementptr inbounds %struct.T, %struct.T addrspace(4)* 
%0, i64 0, i32 0, i64 1
 // OPT: [[P1:%.*]] = load float*, float* addrspace(4)* [[R1]], align 8
-// OPT: [[V0:%.*]] = load float, float* [[P0]], align 4
+// OPT: [[G1:%.*]] = addrspacecast float* [[P1]] to float addrspace(1)*
+// OPT: [[V0:%.*]] = load float, float addrspace(1)* [[G0]], align 4
 // OPT: [[ADD0:%.*]] = fadd contract float [[V0]], 1.00e+00
-// OPT: store float [[ADD0]], float* [[P0]], align 4
-// OPT: [[V1:%.*]] = load float, float* [[P1]], align 4
+// OPT: store float [[ADD0]], float addrspace(1)* [[G0]], align 4
+// OPT: [[V1:%.*]] = load float, float addrspace(1)* [[G1]], align 4
 // OPT: [[ADD1:%.*]] = fadd contract float [[V1]], 2.00e+00
-// OPT: store float [[AD

[PATCH] D91121: [InferAddrSpace] Teach to handle assumed address space.

2020-11-16 Thread Michael Liao 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 rGf375885ab86d: [InferAddrSpace] Teach to handle assumed 
address space. (authored by hliao).

Changed prior to commit:
  https://reviews.llvm.org/D91121?vs=305250&id=305592#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91121

Files:
  clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu
  llvm/docs/AMDGPUUsage.rst
  llvm/include/llvm/Analysis/TargetTransformInfo.h
  llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
  llvm/include/llvm/CodeGen/BasicTTIImpl.h
  llvm/include/llvm/Target/TargetMachine.h
  llvm/lib/Analysis/TargetTransformInfo.cpp
  llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
  llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h
  llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
  llvm/test/CodeGen/AMDGPU/GlobalISel/divergent-control-flow.ll
  llvm/test/Transforms/InferAddressSpaces/AMDGPU/assumed-addrspace.ll

Index: llvm/test/Transforms/InferAddressSpaces/AMDGPU/assumed-addrspace.ll
===
--- /dev/null
+++ llvm/test/Transforms/InferAddressSpaces/AMDGPU/assumed-addrspace.ll
@@ -0,0 +1,31 @@
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -infer-address-spaces -o - %s | FileCheck %s
+
+@c0 = addrspace(4) global float* undef
+
+; CHECK-LABEL: @generic_ptr_from_constant
+; CHECK: addrspacecast float* %p to float addrspace(1)*
+; CHECK-NEXT: load float, float addrspace(1)*
+define float @generic_ptr_from_constant() {
+  %p = load float*, float* addrspace(4)* @c0
+  %v = load float, float* %p
+  ret float %v
+}
+
+%struct.S = type { i32*, float* }
+
+; CHECK-LABEL: @generic_ptr_from_aggregate_argument
+; CHECK: addrspacecast i32* %p0 to i32 addrspace(1)*
+; CHECK: addrspacecast float* %p1 to float addrspace(1)*
+; CHECK: load i32, i32 addrspace(1)*
+; CHECK: store float %v1, float addrspace(1)*
+; CHECK: ret
+define amdgpu_kernel void @generic_ptr_from_aggregate_argument(%struct.S addrspace(4)* byref(%struct.S) align 8 %0) {
+  %f0 = getelementptr inbounds %struct.S, %struct.S addrspace(4)* %0, i64 0, i32 0
+  %p0 = load i32*, i32* addrspace(4)* %f0
+  %f1 = getelementptr inbounds %struct.S, %struct.S addrspace(4)* %0, i64 0, i32 1
+  %p1 = load float*, float* addrspace(4)* %f1
+  %v0 = load i32, i32* %p0
+  %v1 = sitofp i32 %v0 to float
+  store float %v1, float* %p1
+  ret void
+}
Index: llvm/test/CodeGen/AMDGPU/GlobalISel/divergent-control-flow.ll
===
--- llvm/test/CodeGen/AMDGPU/GlobalISel/divergent-control-flow.ll
+++ llvm/test/CodeGen/AMDGPU/GlobalISel/divergent-control-flow.ll
@@ -138,35 +138,34 @@
 ; CHECK-NEXT:s_cselect_b32 s4, 1, 0
 ; CHECK-NEXT:s_and_b32 s4, s4, 1
 ; CHECK-NEXT:s_cmp_lg_u32 s4, 0
-; CHECK-NEXT:s_cbranch_scc1 BB4_6
+; CHECK-NEXT:s_cbranch_scc1 BB4_4
 ; CHECK-NEXT:  ; %bb.1: ; %bb2
 ; CHECK-NEXT:s_getpc_b64 s[6:7]
 ; CHECK-NEXT:s_add_u32 s6, s6, const.ptr@gotpcrel32@lo+4
 ; CHECK-NEXT:s_addc_u32 s7, s7, const.ptr@gotpcrel32@hi+12
 ; CHECK-NEXT:s_load_dwordx2 s[6:7], s[6:7], 0x0
+; CHECK-NEXT:v_mov_b32_e32 v0, 0
 ; CHECK-NEXT:s_mov_b32 s4, -1
 ; CHECK-NEXT:s_waitcnt lgkmcnt(0)
 ; CHECK-NEXT:s_load_dwordx2 s[6:7], s[6:7], 0x0
 ; CHECK-NEXT:s_waitcnt lgkmcnt(0)
-; CHECK-NEXT:v_mov_b32_e32 v0, s6
-; CHECK-NEXT:v_mov_b32_e32 v1, s7
-; CHECK-NEXT:flat_load_dword v0, v[0:1]
-; CHECK-NEXT:s_waitcnt vmcnt(0) lgkmcnt(0)
-; CHECK-NEXT:v_cmp_ngt_f32_e32 vcc, 1.0, v0
-; CHECK-NEXT:s_and_saveexec_b64 s[6:7], vcc
+; CHECK-NEXT:global_load_dword v0, v0, s[6:7]
+; CHECK-NEXT:s_waitcnt vmcnt(0)
+; CHECK-NEXT:v_cmp_gt_f32_e32 vcc, 1.0, v0
+; CHECK-NEXT:s_cbranch_vccnz BB4_3
 ; CHECK-NEXT:  ; %bb.2: ; %bb7
 ; CHECK-NEXT:s_mov_b32 s4, 0
-; CHECK-NEXT:  ; %bb.3: ; %bb8
-; CHECK-NEXT:s_or_b64 exec, exec, s[6:7]
-; CHECK-NEXT:v_cmp_eq_u32_e64 s[6:7], s4, 0
-; CHECK-NEXT:s_and_saveexec_b64 s[4:5], s[6:7]
-; CHECK-NEXT:s_cbranch_execz BB4_5
-; CHECK-NEXT:  ; %bb.4: ; %bb11
+; CHECK-NEXT:  BB4_3: ; %bb8
+; CHECK-NEXT:s_cmp_lg_u32 s4, 0
+; CHECK-NEXT:s_cselect_b32 s4, 1, 0
+; CHECK-NEXT:s_and_b32 s4, s4, 1
+; CHECK-NEXT:s_cmp_lg_u32 s4, 0
+; CHECK-NEXT:s_cbranch_scc0 BB4_5
+; CHECK-NEXT:  BB4_4: ; %bb12
+; CHECK-NEXT:s_setpc_b64 s[30:31]
+; CHECK-NEXT:  BB4_5: ; %bb11
 ; CHECK-NEXT:v_mov_b32_e32 v0, 4.0
 ; CHECK-NEXT:buffer_store_dword v0, v0, s[0:3], 0 offen
-; CHECK-NEXT:  BB4_5: ; %Flow
-; CHECK-NEXT:s_or_b64 exec, exec, s[4:5]
-; CHECK-NEXT:  BB4_6: ; %bb12
 ; CHECK-NEXT:s_waitcnt vmcnt(0)
 ; CHECK-NEXT:s_setpc_b64 s[30:31]
 bb:
Index: llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
===
--- llvm/lib/Transforms/Scalar/In

  1   2   >