[PATCH] D72114: [MS] Overhaul how clang passes overaligned args on x86_32

2020-01-07 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/test/CodeGen/x86_32-arguments-win32.c:77
+// CHECK-LABEL: define dso_local void @receive_vec_256(<8 x float> inreg %x, 
<8 x float> inreg %y, <8 x float> inreg %z, <8 x float>* %0, <8 x float>* %1)
+// CHECK-LABEL: define dso_local void @receive_vec_512(<16 x float> inreg %x, 
<16 x float> inreg %y, <16 x float> inreg %z, <16 x float>* %0, <16 x float>* 
%1)
+// CHECK-LABEL: define dso_local void @receive_vec_1024(<32 x float>* %0, <32 
x float>* %1, <32 x float>* %2, <32 x float>* %3, <32 x float>* %4)

AntonYudintsev wrote:
> rjmccall wrote:
> > rnk wrote:
> > > rjmccall wrote:
> > > > rnk wrote:
> > > > > craig.topper wrote:
> > > > > > What happens in the backend with inreg if 512-bit vectors aren't 
> > > > > > legal?
> > > > > LLVM splits the vector up using the largest legal vector size. As 
> > > > > many pieces as possible are passed in available XMM/YMM registers, 
> > > > > and the rest are passed in memory. MSVC, of course, assumes the user 
> > > > > wanted the larger vector size, and uses whatever vector instructions 
> > > > > it needs to move the arguments around.
> > > > > 
> > > > > Previously, I advocated for a model where calling an Intel intrinsic 
> > > > > function had the effect of implicitly marking the caller with the 
> > > > > target attributes of the intrinsic. This falls down if the user tries 
> > > > > to write a single function that conditionally branches between code 
> > > > > that uses different instruction set extensions. You can imagine the 
> > > > > SSE2 codepath accidentally using AVX instructions because the 
> > > > > compiler thinks they are better. I'm told that ICC models CPU 
> > > > > micro-architectural features in the CFG, but I don't ever expect that 
> > > > > LLVM will do that. If we're stuck with per-function CPU feature 
> > > > > settings, it seems like it would be nice to try to do what the user 
> > > > > asked by default, and warn the user if we see them doing a cpuid 
> > > > > check in a function that has been implicitly blessed with some target 
> > > > > attributes. You could imagine doing a similar thing when large vector 
> > > > > type variables are used: if a large vector argument or local is used, 
> > > > > implicitly enable the appropriate target features to move vectors of 
> > > > > that size around.
> > > > > 
> > > > > This idea didn't get anywhere, and the current situation has 
> > > > > persisted.
> > > > > 
> > > > > ---
> > > > > 
> > > > > You know, maybe we should just keep clang the way it is, and just set 
> > > > > up a warning in the backend that says "hey, I split your large 
> > > > > vector. You probably didn't want that." And then we just continue 
> > > > > doing what we do now. Nobody likes backend warnings, but it seems 
> > > > > better than the current direction of the frontend knowing every 
> > > > > detail of x86 vector extensions.
> > > > If target attributes affect ABI, it seems really dangerous to 
> > > > implicitly set attributes based on what intrinsics are called.
> > > > 
> > > > The local CPU-testing problem seems similar to the problems with local 
> > > > `#pragma STDC FENV_ACCESS` blocks that the constrained-FP people are 
> > > > looking into.  They both have a "this operation is normally fully 
> > > > optimizable, but we might need to be more careful in specific 
> > > > functions" aspect to them.  I wonder if there's a reasonable way to 
> > > > unify the approaches, or at least benefit from lessons learned.
> > > I agree, we wouldn't want intrinsic usage to change ABI. But, does 
> > > anybody actually want the behavior that LLVM implements today where large 
> > > vectors get split across registers and memory? I think most users who 
> > > pass a 512 bit vector want it to either be passed in ZMM registers or 
> > > fail to compile. Why do we even support passing 1024 bit vectors? Could 
> > > we make that an error?
> > > 
> > > Anyway, major redesigns aside, should clang do something when large 
> > > vectors are passed? Maybe we should warn here? Passing by address is 
> > > usually the safest way to pass something, so that's an option. 
> > > Implementing splitting logic in clang doesn't seem worth it.
> > > I agree, we wouldn't want intrinsic usage to change ABI. But, does 
> > > anybody actually want the behavior that LLVM implements today where large 
> > > vectors get split across registers and memory?
> > 
> > I take it you're implying that the actual (Windows-only?) platform ABI 
> > doesn't say anything about this because other compilers don't allow large 
> > vectors.  How large are the vectors we do have ABI rules for?  Do they have 
> > the problem as the SysV ABI where the ABI rules are sensitive to compiler 
> > flags?
> > 
> > Anyway, I didn't realize the i386 Windows ABI *ever* used registers for 
> > arguments.  (Whether you can convince LLVM to do so  for a function 
> > signature that Clang 

[PATCH] D71510: [clang][checkers] Added new checker 'error-return-checker'. (WIP)

2020-01-07 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked 3 inline comments as done.
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/ErrorReturnChecker.cpp:77
+// This should work with any type of null value.
+// FIXME: Is this different from the ValueErrorResultChecker with 0 as value?
+class NullErrorResultChecker : public CheckForErrorResultChecker {

gamesh411 wrote:
> I think the current implementation is slightly different. The 
> ValueErrorResultChecker uses symbolic evaluation of the equation with a 
> ConcreteInt 0 value, while the ProgramState::isNull checks if the value is a 
> constant and if it is not a zero constant (also calls further to 
> ConstraintManager::isNull).
I think if there is a method for a special purpose (`isNull`) it is better to 
use that, it can be more efficient.



Comment at: clang/lib/StaticAnalyzer/Checkers/ErrorReturnChecker.cpp:158
+// value < 0" check too.
+class NegativeOrEofErrorResultChecker : public CheckForErrorResultChecker {
+public:

gamesh411 wrote:
> Maybe only checking for negative value is enough? My gut feeling is that the 
> equality check is redundant. I would argue:
> let A be: Value is negative
> let B be: Value is equal to -1
> 
> since B implies A, (A or B) can be simplified to just A.
> This presupposes that every time B can reasoned about A can be too.
> This seems to be the case for here as well, as the definiteness of being 
> equal to -1 is stronger than being lower than 0.
> 
The test
```
void test_NegativeOrEofCorrectCheck1() {
  int X = fputs("", NULL);
  if (X == -1) {
  }
}
```
fails when only the check for negative value is there.

The problem is with the negated part: If there is a "X==-1" statement in the 
code to check then the "X<0" assumption is true but "X>=0" is not known because 
X can be less than -1. This check should accept the "X==-1" and "X<0" type of 
code.



Comment at: clang/test/Analysis/error-return.c:270
+
+These are OK if not checked:
+

gamesh411 wrote:
> just for the sake of completeness; mention all the cases where error checking 
> is deemed unnecessary as per ERR-33-EX1
> 
> https://wiki.sei.cmu.edu/confluence/display/c/ERR33-C.+Detect+and+handle+standard+library+errors#ERR33-C.Detectandhandlestandardlibraryerrors-Exceptions
It seems that the better solution is to check for those functions too, and add 
a feature to the checker that ignores functions that are casted to `void`. The 
exception list says that even in these exceptions the `(void)` cast is needed. 
(Probably a other kind of warning message can be used for these functions.) The 
"function can not fail" and "return value is inconsequential" cases are not 
detectable by the checker (these cases depend on the context of the function 
call, not on the function itself, otherwise the function should appear in the 
list of functions to be ignored).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71510



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


[PATCH] D67224: [clangd] Enable completions with fixes in VSCode

2020-01-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D67224#1804513 , @nridge wrote:

> Just throwing a wild idea out there: what if we used 
> `textDocument/onTypeFormatting` to replace the `.` with `->` as soon as it's 
> typed?


There is no way we can do this with proper latency. `onTypeFormatting` can't 
wait for the parsing to complete and we need the parsing to complete in order 
to determine the type of expression to the left of `.` or `->`.
Moreover, in cases like `unique_ptr().` we can't know whether the user wants 
`.` or `->` before we pick the completion item. Both `.` and `->` are allowed 
in this context.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67224



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


[PATCH] D71406: [clangd] Add xref for macros to FileIndex.

2020-01-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:350
+  const auto *MainFileEntry = SM.getFileEntryForID(SM.getMainFileID());
+  if (!MainFileEntry)
+return;

Does this ever happen?
Maybe `assert` it's not null instead?



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:362
+  R.Location.End.setColumn(Range.end.character);
+  R.Location.FileURI = MainFileURI.c_str();
+  // FIXME: Add correct RefKind information to MainFileMacros.

Won't we get a dangling pointer inside `Refs` after leaving this function?
MainFileURI gets deallocated at the end, right?




Comment at: clang-tools-extra/clangd/index/SymbolCollector.h:108
 
+  void handleMacroOccurence(const MainFileMacros &MacroRefsToIndex);
+

NIT: could you name it in plural? `handleMacros` or `handleMacroOccurences`?

It's different from the other version in this regard, which adds only a single 
occurrence.
It's also a good practice to avoid adding overloads to virtual/overriden 
methods, might get confusing at times.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71406



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


[PATCH] D72276: [clang-format] Add IndentCaseBlocks option

2020-01-07 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Could you add an entry into the clang-format section of the clang release notes




Comment at: clang/unittests/Format/FormatTest.cpp:1235
+   "}",
+   Style));
 }

Could you add a test with indented case labels and indented case blocks?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72276



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


[PATCH] D72320: [NFC] Use isX86() instead of getArch()

2020-01-07 Thread Jim Lin via Phabricator via cfe-commits
Jim created this revision.
Jim added reviewers: MaskRay, craig.topper.
Herald added subscribers: llvm-commits, cfe-commits, rupprecht, hiraditya.
Herald added a reviewer: jhenderson.
Herald added projects: clang, LLVM.

This is a clean up for https://reviews.llvm.org/D72247.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72320

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/AST/Mangle.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Driver/ToolChains/Arch/X86.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Sema/SemaExpr.cpp
  llvm/lib/Analysis/TargetLibraryInfo.cpp
  llvm/lib/MC/MCObjectFileInfo.cpp
  llvm/tools/llvm-objdump/MachODump.cpp

Index: llvm/tools/llvm-objdump/MachODump.cpp
===
--- llvm/tools/llvm-objdump/MachODump.cpp
+++ llvm/tools/llvm-objdump/MachODump.cpp
@@ -7650,8 +7650,7 @@
   }
   outs() << "\n";
 } else {
-  unsigned int Arch = MachOOF->getArch();
-  if (Arch == Triple::x86_64 || Arch == Triple::x86) {
+  if (MachOOF->getArchTriple().isX86()) {
 outs() << format("\t.byte 0x%02x #bad opcode\n",
  *(Bytes.data() + Index) & 0xff);
 Size = 1; // skip exactly one illegible byte and move on.
@@ -7716,8 +7715,7 @@
   IP->printInst(&Inst, PC, AnnotationsStr, *STI, outs());
   outs() << "\n";
 } else {
-  unsigned int Arch = MachOOF->getArch();
-  if (Arch == Triple::x86_64 || Arch == Triple::x86) {
+  if (MachOOF->getArchTriple().isX86()) {
 outs() << format("\t.byte 0x%02x #bad opcode\n",
  *(Bytes.data() + Index) & 0xff);
 InstSize = 1; // skip exactly one illegible byte and move on.
Index: llvm/lib/MC/MCObjectFileInfo.cpp
===
--- llvm/lib/MC/MCObjectFileInfo.cpp
+++ llvm/lib/MC/MCObjectFileInfo.cpp
@@ -40,8 +40,7 @@
 return true;
 
   // And the iOS simulator.
-  if (T.isiOS() &&
-  (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86))
+  if (T.isiOS() && T.isX86())
 return true;
 
   return false;
@@ -192,7 +191,7 @@
 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
  SectionKind::getReadOnly());
 
-if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
+if (T.isX86())
   CompactUnwindDwarfEHFrameOnly = 0x0400;  // UNWIND_X86_64_MODE_DWARF
 else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
   CompactUnwindDwarfEHFrameOnly = 0x0300;  // UNWIND_ARM64_MODE_DWARF
Index: llvm/lib/Analysis/TargetLibraryInfo.cpp
===
--- llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -379,10 +379,8 @@
   case Triple::TvOS:
   case Triple::WatchOS:
 TLI.setUnavailable(LibFunc_exp10l);
-if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) ||
-   (T.isOSVersionLT(9, 0) &&
-(T.getArch() == Triple::x86 ||
- T.getArch() == Triple::x86_64 {
+if (!T.isWatchOS() &&
+(T.isOSVersionLT(7, 0) || (T.isOSVersionLT(9, 0) && T.isX86( {
   TLI.setUnavailable(LibFunc_exp10);
   TLI.setUnavailable(LibFunc_exp10f);
 } else {
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15359,8 +15359,7 @@
   // These manglings don't do anything on non-Windows or non-x86 platforms, so
   // we don't need parameter type sizes.
   const llvm::Triple &TT = S.Context.getTargetInfo().getTriple();
-  if (!TT.isOSWindows() || (TT.getArch() != llvm::Triple::x86 &&
-TT.getArch() != llvm::Triple::x86_64))
+  if (!TT.isOSWindows() || !TT.isX86())
 return false;
 
   // If this is C++ and this isn't an extern "C" function, parameters do not
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -124,8 +124,7 @@
   AddMachOArch(Args, CmdArgs);
 
   // Use -force_cpusubtype_ALL on x86 by default.
-  if (getToolChain().getArch() == llvm::Triple::x86 ||
-  getToolChain().getArch() == llvm::Triple::x86_64 ||
+  if (getToolChain().getTriple().isX86() ||
   Args.hasArg(options::OPT_force__cpusubtype__ALL))
 CmdArgs.push_back("-force_cpusubtype_ALL");
 
@@ -1836,9 +1835,7 @@
   DarwinEnvironmentKind Environment = OSTarget->getEnvironment();
   // Recognize iOS targets with an x86 architecture as the iOS simulator.
   if (Environment == NativeEnvironment && Pla

[clang] ab1bcda - [NFC] Use isX86() instead of getArch()

2020-01-07 Thread Jim Lin via cfe-commits

Author: Jim Lin
Date: 2020-01-07T17:35:44+08:00
New Revision: ab1bcda851d95aeec03ffc1218bf9cae261a9280

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

LOG: [NFC] Use isX86() instead of getArch()

Summary: This is a clean up for https://reviews.llvm.org/D72247.

Reviewers: MaskRay, craig.topper, jhenderson

Reviewed By: MaskRay

Subscribers: hiraditya, rupprecht, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/AST/Mangle.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/Driver/ToolChains/Arch/X86.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/Darwin.cpp
clang/lib/Sema/SemaExpr.cpp
llvm/lib/Analysis/TargetLibraryInfo.cpp
llvm/lib/MC/MCObjectFileInfo.cpp
llvm/tools/llvm-objdump/MachODump.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index a32b30f5b7e9..3a8e35524695 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1146,10 +1146,7 @@ class TargetInfo : public virtual 
TransferrableTargetInfo,
 
   /// Identify whether this target supports multiversioning of functions,
   /// which requires support for cpu_supports and cpu_is functionality.
-  bool supportsMultiVersioning() const {
-return getTriple().getArch() == llvm::Triple::x86 ||
-   getTriple().getArch() == llvm::Triple::x86_64;
-  }
+  bool supportsMultiVersioning() const { return getTriple().isX86(); }
 
   /// Identify whether this target supports IFuncs.
   bool supportsIFunc() const { return getTriple().isOSBinFormatELF(); }
@@ -1214,8 +1211,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   /// Whether the target supports SEH __try.
   bool isSEHTrySupported() const {
 return getTriple().isOSWindows() &&
-   (getTriple().getArch() == llvm::Triple::x86 ||
-getTriple().getArch() == llvm::Triple::x86_64 ||
+   (getTriple().isX86() ||
 getTriple().getArch() == llvm::Triple::aarch64);
   }
 

diff  --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp
index 32d466cb5718..e106b31f59f0 100644
--- a/clang/lib/AST/Mangle.cpp
+++ b/clang/lib/AST/Mangle.cpp
@@ -63,9 +63,7 @@ static CCMangling getCallingConvMangling(const ASTContext 
&Context,
  const NamedDecl *ND) {
   const TargetInfo &TI = Context.getTargetInfo();
   const llvm::Triple &Triple = TI.getTriple();
-  if (!Triple.isOSWindows() ||
-  !(Triple.getArch() == llvm::Triple::x86 ||
-Triple.getArch() == llvm::Triple::x86_64))
+  if (!Triple.isOSWindows() || !Triple.isX86())
 return CCM_Other;
 
   if (Context.getLangOpts().CPlusPlus && !isExternC(ND) &&

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index b3b16befeea4..b71756f2449f 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -10829,8 +10829,7 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const 
FunctionDecl *FD,
 ExprLoc = VLENExpr->getExprLoc();
   }
   OMPDeclareSimdDeclAttr::BranchStateTy State = Attr->getBranchState();
-  if (CGM.getTriple().getArch() == llvm::Triple::x86 ||
-  CGM.getTriple().getArch() == llvm::Triple::x86_64) {
+  if (CGM.getTriple().isX86()) {
 emitX86DeclareSimdFunction(FD, Fn, VLENVal, ParamAttrs, State);
   } else if (CGM.getTriple().getArch() == llvm::Triple::aarch64) {
 unsigned VLEN = VLENVal.getExtValue();

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 448b70de9714..a717f43e3efd 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2378,10 +2378,7 @@ static void 
CreateMultiVersionResolverReturn(CodeGenModule &CGM,
 
 void CodeGenFunction::EmitMultiVersionResolver(
 llvm::Function *Resolver, ArrayRef Options) {
-  assert((getContext().getTargetInfo().getTriple().getArch() ==
-  llvm::Triple::x86 ||
-  getContext().getTargetInfo().getTriple().getArch() ==
-  llvm::Triple::x86_64) &&
+  assert(getContext().getTargetInfo().getTriple().isX86() &&
  "Only implemented for x86 targets");
 
   bool SupportsIFunc = getContext().getTargetInfo().supportsIFunc();

diff  --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp 
b/clang/lib/Driver/ToolChains/Arch/X86.cpp
index d2b97bf6ad71..d1e0c8253b79 100644
--- a/clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -63,8 +63,7 @@ const char *x86::getX86Targe

[PATCH] D72320: [NFC] Use isX86() instead of getArch()

2020-01-07 Thread Jim Lin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGab1bcda851d9: [NFC] Use isX86() instead of getArch() 
(authored by Jim).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72320

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/AST/Mangle.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Driver/ToolChains/Arch/X86.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Sema/SemaExpr.cpp
  llvm/lib/Analysis/TargetLibraryInfo.cpp
  llvm/lib/MC/MCObjectFileInfo.cpp
  llvm/tools/llvm-objdump/MachODump.cpp

Index: llvm/tools/llvm-objdump/MachODump.cpp
===
--- llvm/tools/llvm-objdump/MachODump.cpp
+++ llvm/tools/llvm-objdump/MachODump.cpp
@@ -7650,8 +7650,7 @@
   }
   outs() << "\n";
 } else {
-  unsigned int Arch = MachOOF->getArch();
-  if (Arch == Triple::x86_64 || Arch == Triple::x86) {
+  if (MachOOF->getArchTriple().isX86()) {
 outs() << format("\t.byte 0x%02x #bad opcode\n",
  *(Bytes.data() + Index) & 0xff);
 Size = 1; // skip exactly one illegible byte and move on.
@@ -7716,8 +7715,7 @@
   IP->printInst(&Inst, PC, AnnotationsStr, *STI, outs());
   outs() << "\n";
 } else {
-  unsigned int Arch = MachOOF->getArch();
-  if (Arch == Triple::x86_64 || Arch == Triple::x86) {
+  if (MachOOF->getArchTriple().isX86()) {
 outs() << format("\t.byte 0x%02x #bad opcode\n",
  *(Bytes.data() + Index) & 0xff);
 InstSize = 1; // skip exactly one illegible byte and move on.
Index: llvm/lib/MC/MCObjectFileInfo.cpp
===
--- llvm/lib/MC/MCObjectFileInfo.cpp
+++ llvm/lib/MC/MCObjectFileInfo.cpp
@@ -40,8 +40,7 @@
 return true;
 
   // And the iOS simulator.
-  if (T.isiOS() &&
-  (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86))
+  if (T.isiOS() && T.isX86())
 return true;
 
   return false;
@@ -192,7 +191,7 @@
 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
  SectionKind::getReadOnly());
 
-if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
+if (T.isX86())
   CompactUnwindDwarfEHFrameOnly = 0x0400;  // UNWIND_X86_64_MODE_DWARF
 else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
   CompactUnwindDwarfEHFrameOnly = 0x0300;  // UNWIND_ARM64_MODE_DWARF
Index: llvm/lib/Analysis/TargetLibraryInfo.cpp
===
--- llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -379,10 +379,8 @@
   case Triple::TvOS:
   case Triple::WatchOS:
 TLI.setUnavailable(LibFunc_exp10l);
-if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) ||
-   (T.isOSVersionLT(9, 0) &&
-(T.getArch() == Triple::x86 ||
- T.getArch() == Triple::x86_64 {
+if (!T.isWatchOS() &&
+(T.isOSVersionLT(7, 0) || (T.isOSVersionLT(9, 0) && T.isX86( {
   TLI.setUnavailable(LibFunc_exp10);
   TLI.setUnavailable(LibFunc_exp10f);
 } else {
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15359,8 +15359,7 @@
   // These manglings don't do anything on non-Windows or non-x86 platforms, so
   // we don't need parameter type sizes.
   const llvm::Triple &TT = S.Context.getTargetInfo().getTriple();
-  if (!TT.isOSWindows() || (TT.getArch() != llvm::Triple::x86 &&
-TT.getArch() != llvm::Triple::x86_64))
+  if (!TT.isOSWindows() || !TT.isX86())
 return false;
 
   // If this is C++ and this isn't an extern "C" function, parameters do not
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -124,8 +124,7 @@
   AddMachOArch(Args, CmdArgs);
 
   // Use -force_cpusubtype_ALL on x86 by default.
-  if (getToolChain().getArch() == llvm::Triple::x86 ||
-  getToolChain().getArch() == llvm::Triple::x86_64 ||
+  if (getToolChain().getTriple().isX86() ||
   Args.hasArg(options::OPT_force__cpusubtype__ALL))
 CmdArgs.push_back("-force_cpusubtype_ALL");
 
@@ -1836,9 +1835,7 @@
   DarwinEnvironmentKind Environment = OSTarget->getEnvironment();
   // Recognize iOS targets with an x86 architecture as the iOS simulator.
   if (Environment == NativeEnvironment && Platform != MacOS &&
-  OSTarget->canInferSi

Re: [clang] 24ab9b5 - Generalize the pass registration mechanism used by Polly to any third-party tool

2020-01-07 Thread Serge Guelton via cfe-commits
On Mon, Jan 06, 2020 at 03:45:15PM -0800, Eric Christopher wrote:
> Hi Serge,

Hi Eric,

> I have a few questions here about this:
> 
> In general this appears to be a lot more complex than the existing plugin
> solutions and requires quite a lot of custom cmake rules that are difficult to
> maintain. Why do we want this in general for the project? I understand the
> desire to make polly less of a special case, but I don't think that the 
> overall
> complexity is worth the added ability to register polly plugins. Perhaps
> disabling the polly plugin registration scheme is a better option?

Indeed, the cmake machinery is now more generic (making Polly an application of
it, instead of an exception), at the expense of being more complex.

Why would we want that? When trying to write a custom pass, the usual process,
is to write a plugin that works correctly with opt, and that step is relatively
easy. To achieve a decent clang integration, it gets more difficult, and if one
still take the external plugin approach, one ends up with very long and non
standard command line like -Xclang -load -Xclang MyPlugin.so etc. So one need
another step to integrate the plugin into the static build, which means forking
llvm-project, rebasing every now and then etc.

The proposed infrastructure makes this process smoother and non intrusive to the
llvm-project codebase: all development can be done in a separate git repo,
integration is controlled through cmake flags, and integration to
clang/opt/bugpoint is built-in.

> That being said, perhaps it is worth it? But I think we need to call out why 
> we
> want it. I would also have expected something to llvm-dev for a change of this
> magnitude. I didn't see anyone from the pass manager hierarchy on the reviews
> and the final reviewer wasn't someone who contributes to these areas 
> typically.

I've (obviously) mentioned this development on llvm-dev, see

http://lists.llvm.org/pipermail/llvm-dev/2019-September/135326.html

Is there anything I should have done? Probably reaching llvm-dev before
commiting. Reaching the right reviewers has always been a challenge to me, I had
hoped that the mail to llvm-dev would trigger some subscription :-)

> In addition, what's with the OSX failure? It's currently turned off and was
> breaking the bots, but does it mean that you don't expect this machinery to
> work on OSX? That seems like a severely limiting factor for the project.

I've setup github actions to test many configurations before merging [0], but 
missed one of
them. I'm currently working on fixing that part.

> +One first needs to create an independent project and add it to either 
> ``tools/
> ``
> +or, using the MonoRepo layout, at the root of the repo alongside other
> projects.
> 
> This appears to be from an earlier incarnation of the patch? There's only one
> layout now.

Correct! I'll fix that.

> 
>  ; CHECK-EP-VECTORIZER-START-NEXT: Running pass: NoOpFunctionPass
> +; CHECK-EXT: Running pass: {{.*}}::Bye on foo
> 
> Why is this running on every test of the pass manager? It should be an example
> run in the examples directory and not on by default? Same for every other PM
> test. This seems like a bug?

It's not. When the examples are active and if the appropriate cmake flag is set
(which is not the case by default), the pass is linked in statically, and is run
in the default pipeline. The CHECK-EXT prefix is disabled otherwise. That's one
of the configuration I did test :-)

> Thanks!

Thanks for giving me the opportunity to clarify some obscure points, hope it
helps !


[0] 
https://github.com/serge-sans-paille/llvm-project/commit/37c9b5080acd3d7543347de109e44c402626d504/checks?check_suite_id=346849887

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


[PATCH] D71406: [clangd] Add xref for macros to FileIndex.

2020-01-07 Thread UTKARSH SAXENA via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 236541.
usaxena95 marked 3 inline comments as done.
usaxena95 added a comment.

Addressed comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71406

Files:
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/FileIndex.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/SymbolCollector.h
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/FileIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/FileIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/FileIndexTests.cpp
@@ -345,6 +345,41 @@
  FileURI("unittest:///test2.cc"))}));
 }
 
+TEST(FileIndexTest, MacroRefs) {
+  Annotations HeaderCode(R"cpp(
+#define $macro[[MACRO]](X) (X+1)
+  )cpp");
+  Annotations MainCode(R"cpp(
+  void f() {
+int a = $macro[[MACRO]](1);
+  }
+  )cpp");
+
+  auto Macro = findSymbol(
+  TestTU::withHeaderCode(HeaderCode.code()).headerSymbols(), "MACRO");
+  FileIndex Index;
+  // Add test.cc
+  TestTU Test;
+  Test.HeaderCode = HeaderCode.code();
+  Test.Code = MainCode.code();
+  Test.Filename = "test.cc";
+  auto AST = Test.build();
+  Index.updateMain(Test.Filename, AST);
+  // Add test2.cc
+  TestTU Test2;
+  Test2.HeaderCode = HeaderCode.code();
+  Test2.Code = MainCode.code();
+  Test2.Filename = "test2.cc";
+  AST = Test2.build();
+  Index.updateMain(Test2.Filename, AST);
+
+  EXPECT_THAT(getRefs(Index, Macro.ID),
+  RefsAre({AllOf(RefRange(MainCode.range("macro")),
+ FileURI("unittest:///test.cc")),
+   AllOf(RefRange(MainCode.range("macro")),
+ FileURI("unittest:///test2.cc"))}));
+}
+
 TEST(FileIndexTest, CollectMacros) {
   FileIndex M;
   update(M, "f", "#define CLANGD 1");
Index: clang-tools-extra/clangd/index/SymbolCollector.h
===
--- clang-tools-extra/clangd/index/SymbolCollector.h
+++ clang-tools-extra/clangd/index/SymbolCollector.h
@@ -9,6 +9,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOL_COLLECTOR_H
 
 #include "CanonicalIncludes.h"
+#include "CollectMacros.h"
 #include "Index.h"
 #include "SymbolOrigin.h"
 #include "clang/AST/ASTContext.h"
@@ -104,6 +105,8 @@
   SourceLocation Loc,
   index::IndexDataConsumer::ASTNodeInfo ASTNode) override;
 
+  void handleMacros(const MainFileMacros &MacroRefsToIndex);
+
   bool handleMacroOccurence(const IdentifierInfo *Name, const MacroInfo *MI,
 index::SymbolRoleSet Roles,
 SourceLocation Loc) override;
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -342,6 +342,29 @@
   return true;
 }
 
+void SymbolCollector::handleMacros(const MainFileMacros &MacroRefsToIndex) {
+  assert(PP.get());
+  const auto &SM = PP->getSourceManager();
+  const auto *MainFileEntry = SM.getFileEntryForID(SM.getMainFileID());
+  assert(MainFileEntry);
+
+  const auto MainFileURI = toURI(SM, MainFileEntry->getName(), Opts);
+  // Add macro references.
+  for (const auto &IDToRefs : MacroRefsToIndex.MacroRefs) {
+for (const auto &Range : IDToRefs.second) {
+  Ref R;
+  R.Location.Start.setLine(Range.start.line);
+  R.Location.Start.setColumn(Range.start.character);
+  R.Location.End.setLine(Range.end.line);
+  R.Location.End.setColumn(Range.end.character);
+  R.Location.FileURI = MainFileURI.c_str();
+  // FIXME: Add correct RefKind information to MainFileMacros.
+  R.Kind = RefKind::Reference;
+  Refs.insert(IDToRefs.first, R);
+}
+  }
+}
+
 bool SymbolCollector::handleMacroOccurence(const IdentifierInfo *Name,
const MacroInfo *MI,
index::SymbolRoleSet Roles,
Index: clang-tools-extra/clangd/index/FileIndex.h
===
--- clang-tools-extra/clangd/index/FileIndex.h
+++ clang-tools-extra/clangd/index/FileIndex.h
@@ -140,7 +140,7 @@
 /// Exposed to assist in unit tests.
 SlabTuple indexMainDecls(ParsedAST &AST);
 
-/// Idex declarations from \p AST and macros from \p PP that are declared in
+/// Index declarations from \p AST and macros from \p PP that are declared in
 /// included headers.
 SlabTuple indexHeaderSymbols(ASTContext &AST, std::shared_ptr PP,
  const CanonicalIncludes &Includes);
Index: clang-tools-extra/clangd/index/FileIndex.cpp
=

[PATCH] D71406: [clangd] Add xref for macros to FileIndex.

2020-01-07 Thread UTKARSH SAXENA via Phabricator via cfe-commits
usaxena95 marked 2 inline comments as done.
usaxena95 added inline comments.



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:362
+  R.Location.End.setColumn(Range.end.character);
+  R.Location.FileURI = MainFileURI.c_str();
+  // FIXME: Add correct RefKind information to MainFileMacros.

ilya-biryukov wrote:
> Won't we get a dangling pointer inside `Refs` after leaving this function?
> MainFileURI gets deallocated at the end, right?
> 
Yeah I also thought the same when I saw this at other places too. But the 
`Refs.insert(IDToRefs.first, R);` actually does a copy of this string and owns 
the copy.



Comment at: clang-tools-extra/clangd/index/SymbolCollector.h:108
 
+  void handleMacroOccurence(const MainFileMacros &MacroRefsToIndex);
+

ilya-biryukov wrote:
> NIT: could you name it in plural? `handleMacros` or `handleMacroOccurences`?
> 
> It's different from the other version in this regard, which adds only a 
> single occurrence.
> It's also a good practice to avoid adding overloads to virtual/overriden 
> methods, might get confusing at times.
> 
Renamed to `handleMacros` to avoid confusion with the virtual method.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71406



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


[PATCH] D64305: [clangd] Add path mappings functionality

2020-01-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks! The latest snapshot looks good. Landing it now with a few minor tweaks 
mentioned below.

(And trivial local style things, we generally prefer to drop braces on simple 
if statements etc.)




Comment at: clang-tools-extra/clangd/PathMapping.cpp:26
+void recursivelyMap(llvm::json::Value &V, PathMapping::Direction Dir,
+const PathMappings &Mappings, const MapperFunc &MF) {
+  using Kind = llvm::json::Value::Kind;

Removed the MapperFunc argument here as it's always doPathMapping.

Then this is just applyPathMappings, so merged the two.



Comment at: clang-tools-extra/clangd/PathMapping.h:40
+
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const PathMapping &M);
+

changed to client=server to match the flag syntax



Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:358
+llvm::cl::desc(
+"Comma separated list of '=' pairs "
+"that can be used to map between file locations on the client "

I extended this doc a bit to clarify what "client" and "server" paths mean, and 
explain the first-match-wins.
(I don't think the example reflects first-match-wins, so I reversed the order)



Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:675
+  auto Err = Mappings.takeError();
+  llvm::errs() << llvm::toString(std::move(Err)) << "\n";
+  return 1;

changed to elog("{0}", Mappings.takeError());


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

https://reviews.llvm.org/D64305



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


[PATCH] D71406: [clangd] Add xref for macros to FileIndex.

2020-01-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov marked an inline comment as done.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:362
+  R.Location.End.setColumn(Range.end.character);
+  R.Location.FileURI = MainFileURI.c_str();
+  // FIXME: Add correct RefKind information to MainFileMacros.

usaxena95 wrote:
> ilya-biryukov wrote:
> > Won't we get a dangling pointer inside `Refs` after leaving this function?
> > MainFileURI gets deallocated at the end, right?
> > 
> Yeah I also thought the same when I saw this at other places too. But the 
> `Refs.insert(IDToRefs.first, R);` actually does a copy of this string and 
> owns the copy.
Ah, makes sense. Thanks for explaining this.



Comment at: clang-tools-extra/clangd/unittests/FileIndexTests.cpp:368
+  Index.updateMain(Test.Filename, AST);
+  // Add test2.cc
+  TestTU Test2;

Why do we need two tests? To test the file URI?
Setting a custom filename ("test.cc" in our case) should be enough for this.

I suggest removing `Test2` completely, it does not seem to test anything new 
and creates noise. Unless there are things I'm missing that it test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71406



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


[PATCH] D70765: LTOVisibility.rst: fix up syntax in example

2020-01-07 Thread Nick Black via Phabricator via cfe-commits
dankamongmen added a comment.

> Typically the author commits the patch, unless they don't have commit access 
> and request the reviewer to commit for them, but I don't see a request for 
> that here.

Thanks, Teresa. I indeed do not have commit access (so far as I know or can 
tell, anyway), so please consider this comment to be such a request.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70765



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


[PATCH] D71406: [clangd] Add xref for macros to FileIndex.

2020-01-07 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 60496 tests passed, 0 failed 
and 726 were skipped.

{icon check-circle color=green} clang-tidy: pass.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71406



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


[PATCH] D64305: [clangd] Add path mappings functionality

2020-01-07 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc69ae835d0e0: [clangd] Add path mappings functionality 
(authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D64305?vs=236295&id=236548#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64305

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/PathMapping.cpp
  clang-tools-extra/clangd/PathMapping.h
  clang-tools-extra/clangd/test/Inputs/path-mappings/server/foo.h
  clang-tools-extra/clangd/test/path-mappings.test
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/PathMappingTests.cpp

Index: clang-tools-extra/clangd/unittests/PathMappingTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/PathMappingTests.cpp
@@ -0,0 +1,216 @@
+//===-- PathMappingTests.cpp  *- 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
+//
+//===--===//
+
+#include "PathMapping.h"
+#include "llvm/Support/JSON.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+namespace clang {
+namespace clangd {
+namespace {
+using ::testing::ElementsAre;
+MATCHER_P2(Mapping, ClientPath, ServerPath, "") {
+  return arg.ClientPath == ClientPath && arg.ServerPath == ServerPath;
+}
+
+bool failedParse(llvm::StringRef RawMappings) {
+  llvm::Expected Mappings = parsePathMappings(RawMappings);
+  if (!Mappings) {
+consumeError(Mappings.takeError());
+return true;
+  }
+  return false;
+}
+
+TEST(ParsePathMappingTests, WindowsPath) {
+  // Relative path to C drive
+  EXPECT_TRUE(failedParse(R"(C:a=/root)"));
+  EXPECT_TRUE(failedParse(R"(\C:a=/root)"));
+  // Relative path to current drive.
+  EXPECT_TRUE(failedParse(R"(\a=/root)"));
+  // Absolute paths
+  llvm::Expected ParsedMappings =
+  parsePathMappings(R"(C:\a=/root)");
+  ASSERT_TRUE(bool(ParsedMappings));
+  EXPECT_THAT(*ParsedMappings, ElementsAre(Mapping("/C:/a", "/root")));
+  // Absolute UNC path
+  ParsedMappings = parsePathMappings(R"(\\Server\C$=/root)");
+  ASSERT_TRUE(bool(ParsedMappings));
+  EXPECT_THAT(*ParsedMappings, ElementsAre(Mapping("//Server/C$", "/root")));
+}
+
+TEST(ParsePathMappingTests, UnixPath) {
+  // Relative unix path
+  EXPECT_TRUE(failedParse("a/b=/root"));
+  // Absolute unix path
+  llvm::Expected ParsedMappings = parsePathMappings("/A/b=/root");
+  ASSERT_TRUE(bool(ParsedMappings));
+  EXPECT_THAT(*ParsedMappings, ElementsAre(Mapping("/A/b", "/root")));
+  // Aboslute unix path w/ backslash
+  ParsedMappings = parsePathMappings(R"(/a/b\\ar=/root)");
+  ASSERT_TRUE(bool(ParsedMappings));
+  EXPECT_THAT(*ParsedMappings, ElementsAre(Mapping(R"(/a/b\\ar)", "/root")));
+}
+
+TEST(ParsePathMappingTests, ImproperFormat) {
+  // uneven mappings
+  EXPECT_TRUE(failedParse("/home/myuser1="));
+  // mappings need to be absolute
+  EXPECT_TRUE(failedParse("home/project=/workarea/project"));
+  // duplicate delimiter
+  EXPECT_TRUE(failedParse("/home==/workarea"));
+  // no delimiter
+  EXPECT_TRUE(failedParse("/home"));
+  // improper delimiter
+  EXPECT_TRUE(failedParse("/home,/workarea"));
+}
+
+TEST(ParsePathMappingTests, ParsesMultiple) {
+  std::string RawPathMappings =
+  "/home/project=/workarea/project,/home/project/.includes=/opt/include";
+  auto Parsed = parsePathMappings(RawPathMappings);
+  ASSERT_TRUE(bool(Parsed));
+  EXPECT_THAT(*Parsed,
+  ElementsAre(Mapping("/home/project", "/workarea/project"),
+  Mapping("/home/project/.includes", "/opt/include")));
+}
+
+bool mapsProperly(llvm::StringRef Orig, llvm::StringRef Expected,
+  llvm::StringRef RawMappings, PathMapping::Direction Dir) {
+  llvm::Expected Mappings = parsePathMappings(RawMappings);
+  if (!Mappings)
+return false;
+  llvm::Optional MappedPath = doPathMapping(Orig, Dir, *Mappings);
+  std::string Actual = MappedPath ? *MappedPath : Orig.str();
+  EXPECT_STREQ(Expected.str().c_str(), Actual.c_str());
+  return Expected == Actual;
+}
+
+TEST(DoPathMappingTests, PreservesOriginal) {
+  // Preserves original path when no mapping
+  EXPECT_TRUE(mapsProperly("file:///home", "file:///home", "",
+   PathMapping::Direction::ClientToServer));
+}
+
+TEST(DoPathMappingTests, UsesFirstMatch) {
+  EXPECT_TRUE(mapsProperly("file:///home/foo.cpp", "file:///workarea1/foo.cpp",
+   "/home=/workarea1,/home=/workarea2",
+   PathMapping::Direction::ClientToServer));
+}
+
+TEST(DoPathMappingTests, IgnoresSu

[clang-tools-extra] c69ae83 - [clangd] Add path mappings functionality

2020-01-07 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-01-07T12:40:51+01:00
New Revision: c69ae835d0e0dc493eb09e75f0687a1390525440

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

LOG: [clangd] Add path mappings functionality

Summary: Add path mappings to clangd which translate file URIs on inbound and 
outbound LSP messages. This mapping allows clangd to run in a remote 
environment (e.g. docker), where the source files and dependencies may be at 
different locations than the host. See 
http://lists.llvm.org/pipermail/clangd-dev/2019-January/000231.htm for more.

Patch by William Wagner!

Reviewers: sammccall, ilya-biryukov

Reviewed By: sammccall

Subscribers: usaxena95, ormris, mgorny, MaskRay, jkorous, arphaman, kadircet, 
cfe-commits

Tags: #clang

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

Added: 
clang-tools-extra/clangd/PathMapping.cpp
clang-tools-extra/clangd/PathMapping.h
clang-tools-extra/clangd/test/Inputs/path-mappings/server/foo.h
clang-tools-extra/clangd/test/path-mappings.test
clang-tools-extra/clangd/unittests/PathMappingTests.cpp

Modified: 
clang-tools-extra/clangd/CMakeLists.txt
clang-tools-extra/clangd/tool/ClangdMain.cpp
clang-tools-extra/clangd/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clangd/CMakeLists.txt 
b/clang-tools-extra/clangd/CMakeLists.txt
index c0ad99dd6b69..e3eccb50a496 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -62,6 +62,7 @@ add_clang_library(clangDaemon
   IncludeFixer.cpp
   JSONTransport.cpp
   Logger.cpp
+  PathMapping.cpp
   Protocol.cpp
   Quality.cpp
   ParsedAST.cpp

diff  --git a/clang-tools-extra/clangd/PathMapping.cpp 
b/clang-tools-extra/clangd/PathMapping.cpp
new file mode 100644
index ..e130f3865c64
--- /dev/null
+++ b/clang-tools-extra/clangd/PathMapping.cpp
@@ -0,0 +1,199 @@
+//===--- PathMapping.cpp - apply path mappings to LSP messages -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "PathMapping.h"
+#include "Transport.h"
+#include "URI.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/Path.h"
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+llvm::Optional doPathMapping(llvm::StringRef S,
+  PathMapping::Direction Dir,
+  const PathMappings &Mappings) {
+  // Retrun early to optimize for the common case, wherein S is not a file URI
+  if (!S.startswith("file://"))
+return llvm::None;
+  auto Uri = URI::parse(S);
+  if (!Uri) {
+llvm::consumeError(Uri.takeError());
+return llvm::None;
+  }
+  for (const auto &Mapping : Mappings) {
+const std::string &From = Dir == PathMapping::Direction::ClientToServer
+  ? Mapping.ClientPath
+  : Mapping.ServerPath;
+const std::string &To = Dir == PathMapping::Direction::ClientToServer
+? Mapping.ServerPath
+: Mapping.ClientPath;
+llvm::StringRef Body = Uri->body();
+if (Body.consume_front(From) && (Body.empty() || Body.front() == '/')) {
+  std::string MappedBody = (To + Body).str();
+  return URI(Uri->scheme(), Uri->authority(), MappedBody.c_str())
+  .toString();
+}
+  }
+  return llvm::None;
+}
+
+void applyPathMappings(llvm::json::Value &V, PathMapping::Direction Dir,
+   const PathMappings &Mappings) {
+  using Kind = llvm::json::Value::Kind;
+  Kind K = V.kind();
+  if (K == Kind::Object) {
+llvm::json::Object *Obj = V.getAsObject();
+llvm::json::Object MappedObj;
+// 1. Map all the Keys
+for (auto &KV : *Obj) {
+  if (llvm::Optional MappedKey =
+  doPathMapping(KV.first.str(), Dir, Mappings)) {
+MappedObj.try_emplace(std::move(*MappedKey), std::move(KV.second));
+  } else {
+MappedObj.try_emplace(std::move(KV.first), std::move(KV.second));
+  }
+}
+*Obj = std::move(MappedObj);
+// 2. Map all the values
+for (auto &KV : *Obj)
+  applyPathMappings(KV.second, Dir, Mappings);
+  } else if (K == Kind::Array) {
+for (llvm::json::Value &Val : *V.getAsArray())
+  applyPathMappings(Val, Dir, Mappings);
+  } else if (K == Kind::String) {
+if (llvm::Optional Mapped =
+doPathMapping(*V.getAsString(), Dir, Mappings))
+  V = std::move(

[PATCH] D72227: Add options for clang to align branches within 32B boundary

2020-01-07 Thread Kan Shengchen via Phabricator via cfe-commits
skan updated this revision to Diff 236547.

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

https://reviews.llvm.org/D72227

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/intel-align-branch.c

Index: clang/test/Driver/intel-align-branch.c
===
--- /dev/null
+++ clang/test/Driver/intel-align-branch.c
@@ -0,0 +1,37 @@
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch-boundary=32 -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-BOUNDARY
+// CHECK-BOUNDARY: "-mllvm" "-x86-align-branch-boundary=32"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=jcc -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-JCC
+// CHECK-JCC: "-mllvm" "-x86-align-branch=jcc"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=fused -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-FUSED
+// CHECK-FUSED: "-mllvm" "-x86-align-branch=fused"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=jmp -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-JMP
+// CHECK-JMP: "-mllvm" "-x86-align-branch=jmp"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=call -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-CALL
+// CHECK-CALL: "-mllvm" "-x86-align-branch=call"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=ret -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-RET
+// CHECK-RET: "-mllvm" "-x86-align-branch=ret"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=indirect -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-INDIRECT
+// CHECK-INDIRECT: "-mllvm" "-x86-align-branch=indirect"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=fused+jcc+jmp+ret+call+indirect -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-BRANCH
+// CHECK-BRANCH: "-mllvm" "-x86-align-branch=fused+jcc+jmp+ret+call+indirect"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch-prefix-size=4 -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-PREFIX
+// CHECK-PREFIX: "-mllvm" "-x86-align-branch-prefix-size=4"
+//
+// RUN: %clang -target x86_64-unknown-unknown -mno-branches-within-32B-boundaries -mbranches-within-32B-boundaries -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-TOTAL1
+// CHECK-TOTAL1: "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" "-x86-align-branch=fused+jcc+jmp" "-mllvm" "-x86-align-branch-prefix-size=5"
+//
+// RUN: %clang -target x86_64-unknown-unknown -mbranches-within-32B-boundaries -mno-branches-within-32B-boundaries -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-TOTAL2
+// CHECK-TOTAL2-NOT: "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" "-x86-align-branch=fused+jcc+jmp" "-mllvm" "-x86-align-branch-prefix-size=5"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch-boundary=7 -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=jump -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch-prefix-size=15 -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
+// CHECK-ERROR: error: unsupported argument
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2007,8 +2007,64 @@
 CmdArgs.push_back("-mpacked-stack");
 }
 
+static void alignBranchesOptions(const Driver &D, const ArgList &Args,
+ ArgStringList &CmdArgs) {
+  if (const Arg *A = Args.getLastArg(options::OPT_malign_branch_boundary_EQ)) {
+StringRef Value = A->getValue();
+uint64_t Num;
+if (!Value.getAsInteger(10, Num) && Num >= 32 && llvm::isPowerOf2_64(Num)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back(
+  Args.MakeArgString("-x86-align-branch-boundary=" + Value));
+} else {
+  D.Diag(diag::err_drv_unsupported_option_argument)
+  << A->getOption().getName() << Value;
+}
+  }
+
+  if (const Arg *A = Args.getLastArg(options::OPT_malign_branch_EQ)) {
+StringRef Value = A->getValue();
+SmallVector BranchTypes;
+Value.split(BranchTypes, '+', -1, false);
+for (auto BranchType : BranchTypes) {
+  if (BranchType != "fused" && BranchType != "jcc" && BranchType != "jmp" &&
+  BranchType != "call" && BranchType != "ret" &&
+  BranchType != "indirect")
+D.Diag(diag::err_drv_unsupported_option_argument)
+<< A->getOption().getName() << Value;
+}
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(Args.MakeArgString("-x86-align-branch=" + Value));
+  }
+
+  if (const Arg *A =
+  Args.getLastArg(options::OPT_malign_branch_prefix_size_EQ)) {
+StringRef Value = A->getValue();
+uint8_t Num;
+if (!Value.getAsInteger(10, Num) && Num <= 5) {
+  Cmd

[PATCH] D72227: Add options for clang to align branches within 32B boundary

2020-01-07 Thread Kan Shengchen via Phabricator via cfe-commits
skan marked 5 inline comments as done.
skan added inline comments.



Comment at: clang/include/clang/Driver/Options.td:2217
+  HelpText<"Specify the maximum number of prefixes on an instruction to "
+   "align branches. The number should be between 0 and 4.">;
+def mbranches_within_32B_boundaries

annita.zhang wrote:
> Is there an upbound for this parameter?
yes, both upbound and default value is 5


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

https://reviews.llvm.org/D72227



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


[PATCH] D71422: [clangd] Introduce bulletlists

2020-01-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/FormattedString.cpp:156
+// indented.
+std::string indentLines(llvm::StringRef Input) {
+  std::string IndentedR;

assert that there's no trailing newlines?



Comment at: clang-tools-extra/clangd/FormattedString.h:75
+private:
+  std::vector Documents;
+};

"items" rather than "documents" would capture the semantics better I think



Comment at: clang-tools-extra/clangd/FormattedString.h:92
+
   std::string asMarkdown() const;
   std::string asPlainText() const;

can we document that it *doesn't* render its own trailing newlines? This is a 
divergence from Block and more important to the implementation now


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71422



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


[PATCH] D72233: Add a new AST matcher 'optionally'.

2020-01-07 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 aside from a minor nit. Do you need someone to commit on your behalf?




Comment at: clang/lib/ASTMatchers/Dynamic/Registry.cpp:282
   REGISTER_MATCHER(hasInitStatement);
+  REGISTER_MATCHER(hasInitializer);
   REGISTER_MATCHER(hasKeywordSelector);

Why did this one move? Please keep the list sorted alphabetically.


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

https://reviews.llvm.org/D72233



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


[PATCH] D72306: [PowerPC] FreeBSD >= 13 default ABI is ELFv2

2020-01-07 Thread Alfredo Dal'Ava Júnior via Phabricator via cfe-commits
adalava marked an inline comment as done.
adalava added a comment.

In D72306#1807097 , @MaskRay wrote:

> Are you still using -target powerpc64-unknown-freebsd12.0-elfv2 or -target 
> powerpc64-unknown-freebsd12.0-elfv1 added in 
> https://reviews.llvm.org/rL361355 ?


No, we are not using this triplet anymore after decision to OS version to 
change ABI, nobody is relying on it.
Are you willing to remove it? User can add "-mabi=[elfv1|elfv2]" to override 
the default ABI for that OS version, anyway.




Comment at: clang/lib/Basic/Targets/PPC.h:389
+if (Triple.getEnvironment() != llvm::Triple::UnknownEnvironment) {
+  switch (Triple.getEnvironment()){
+case llvm::Triple::ELFv1:

MaskRay wrote:
> Which ABI does `powerpc64le-linux-gnu` use after this change?
It should be using ELFv2:

[alfredo.junior@FreeBSD_x86 ~/src/llvm-project/build-release-master]$ 
./bin/clang -target powerpc64le-linux-gnu -dM -E - < /dev/null | grep CALL_ELF
#define _CALL_ELF 2

Is it ok?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72306



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


[clang] 3b417b7 - Fix "pointer is null" static analyzer warning. NFCI.

2020-01-07 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2020-01-07T13:41:52Z
New Revision: 3b417b7cf73b6b5a2953ad4c8178b4394ea4f20e

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

LOG: Fix "pointer is null" static analyzer warning. NFCI.

Added: 


Modified: 
clang/lib/AST/Comment.cpp

Removed: 




diff  --git a/clang/lib/AST/Comment.cpp b/clang/lib/AST/Comment.cpp
index 23dc7ba93591..a02cc9d119fe 100644
--- a/clang/lib/AST/Comment.cpp
+++ b/clang/lib/AST/Comment.cpp
@@ -379,11 +379,11 @@ StringRef TParamCommandComment::getParamName(const 
FullComment *FC) const {
   assert(isPositionValid());
   const TemplateParameterList *TPL = FC->getDeclInfo()->TemplateParameters;
   for (unsigned i = 0, e = getDepth(); i != e; ++i) {
-if (i == e-1)
+assert(TPL && "Unknown TemplateParameterList");
+if (i == e - 1)
   return TPL->getParam(getIndex(i))->getName();
 const NamedDecl *Param = TPL->getParam(getIndex(i));
-if (const TemplateTemplateParmDecl *TTP =
-  dyn_cast(Param))
+if (auto *TTP = dyn_cast(Param))
   TPL = TTP->getTemplateParameters();
   }
   return "";



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


[PATCH] D72271: [Clang] Handle target-specific builtins returning aggregates.

2020-01-07 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham updated this revision to Diff 236564.
simon_tatham added a comment.

Thanks for the helpful advice!

Here's a revised version that checks `getEvaluationKind`. I've also added a 
test for the `vld2q(...).val[0]` construction you mentioned: you're right, of 
course, that that also crashed existing clang, and it still crashed with my 
previous patch applied. This version seems to work in both cases.

> and then we can just require EmitTargetBuiltinExpr to return null or 
> something else that makes it clear that they've done the right thing with the 
> slot that was passed in

The current return value of `EmitTargetBuiltinExpr` will be the `llvm::Value *` 
corresponding to the last of a sequence of store instructions that writes the 
constructed aggregate into the return value slot. There's no need to actually 
use that `Value` for anything in this case, but we can still test that it's 
non-null, to find out whether `EmitTargetBuiltinExpr` has successfully 
recognized a builtin and generated some code, or whether we have to fall 
through to the `ErrorUnsupported`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72271

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/arm-mve-intrinsics/vld24.c


Index: clang/test/CodeGen/arm-mve-intrinsics/vld24.c
===
--- clang/test/CodeGen/arm-mve-intrinsics/vld24.c
+++ clang/test/CodeGen/arm-mve-intrinsics/vld24.c
@@ -98,3 +98,45 @@
 vst2q_f16(addr, value);
 #endif /* POLYMORPHIC */
 }
+
+// CHECK-LABEL: @load_into_variable(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call { <8 x i16>, <8 x i16> } 
@llvm.arm.mve.vld2q.v8i16.p0i16(i16* [[ADDR:%.*]])
+// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { <8 x i16>, <8 x i16> } 
[[TMP0]], 0
+// CHECK-NEXT:[[TMP2:%.*]] = insertvalue [[STRUCT_UINT16X8X2_T:%.*]] 
undef, <8 x i16> [[TMP1]], 0, 0
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { <8 x i16>, <8 x i16> } 
[[TMP0]], 1
+// CHECK-NEXT:[[TMP4:%.*]] = insertvalue [[STRUCT_UINT16X8X2_T]] [[TMP2]], 
<8 x i16> [[TMP3]], 0, 1
+// CHECK-NEXT:store <8 x i16> [[TMP1]], <8 x i16>* [[VALUES:%.*]], align 8
+// CHECK-NEXT:[[ARRAYIDX4:%.*]] = getelementptr inbounds <8 x i16>, <8 x 
i16>* [[VALUES]], i32 1
+// CHECK-NEXT:store <8 x i16> [[TMP3]], <8 x i16>* [[ARRAYIDX4]], align 8
+// CHECK-NEXT:ret void
+//
+void load_into_variable(const uint16_t *addr, uint16x8_t *values)
+{
+uint16x8x2_t v;
+#ifdef POLYMORPHIC
+v = vld2q(addr);
+#else /* POLYMORPHIC */
+v = vld2q_u16(addr);
+#endif /* POLYMORPHIC */
+values[0] = v.val[0];
+values[1] = v.val[1];
+}
+
+// CHECK-LABEL: @extract_one_vector(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call { <4 x i32>, <4 x i32> } 
@llvm.arm.mve.vld2q.v4i32.p0i32(i32* [[ADDR:%.*]])
+// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { <4 x i32>, <4 x i32> } 
[[TMP0]], 0
+// CHECK-NEXT:[[TMP2:%.*]] = insertvalue [[STRUCT_INT32X4X2_T:%.*]] undef, 
<4 x i32> [[TMP1]], 0, 0
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { <4 x i32>, <4 x i32> } 
[[TMP0]], 1
+// CHECK-NEXT:[[TMP4:%.*]] = insertvalue [[STRUCT_INT32X4X2_T]] [[TMP2]], 
<4 x i32> [[TMP3]], 0, 1
+// CHECK-NEXT:ret <4 x i32> [[TMP1]]
+//
+int32x4_t extract_one_vector(const int32_t *addr)
+{
+#ifdef POLYMORPHIC
+return vld2q(addr).val[0];
+#else /* POLYMORPHIC */
+return vld2q_s32(addr).val[0];
+#endif /* POLYMORPHIC */
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -4328,8 +4328,26 @@
   }
 
   // See if we have a target specific builtin that needs to be lowered.
-  if (Value *V = EmitTargetBuiltinExpr(BuiltinID, E, ReturnValue))
-return RValue::get(V);
+  switch (getEvaluationKind(E->getType())) {
+  case TEK_Scalar:
+if (Value *V = EmitTargetBuiltinExpr(BuiltinID, E, ReturnValue))
+  return RValue::get(V);
+break;
+  case TEK_Aggregate: {
+if (ReturnValue.isNull()) {
+  Address DestPtr = CreateMemTemp(E->getType(), "agg.tmp");
+  ReturnValue = ReturnValueSlot(DestPtr, false);
+}
+if (EmitTargetBuiltinExpr(BuiltinID, E, ReturnValue))
+return RValue::getAggregate(ReturnValue.getValue(),
+ReturnValue.isVolatile());
+break;
+  }
+  case TEK_Complex:
+llvm_unreachable("No currently supported builtin returns complex");
+  default:
+llvm_unreachable("Bad evaluation kind in EmitBuiltinExpr");
+  }
 
   ErrorUnsupported(E, "builtin function");
 


Index: clang/test/CodeGen/arm-mve-intrinsics/vld24.c
===
--- clang/test/CodeGen/arm-mve-intrinsics/vld24.c
+++ clang/test/CodeGen/arm-mve-intrinsics/vld24.c
@@ -98,3 +98,45 @@
 vst2q_f16(addr, value);
 #endif /* POLYM

[PATCH] D71406: [clangd] Add xref for macros to FileIndex.

2020-01-07 Thread UTKARSH SAXENA via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 236569.
usaxena95 marked an inline comment as done.
usaxena95 added a comment.

Removed extra tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71406

Files:
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/FileIndex.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/SymbolCollector.h
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/FileIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/FileIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/FileIndexTests.cpp
@@ -345,6 +345,31 @@
  FileURI("unittest:///test2.cc"))}));
 }
 
+TEST(FileIndexTest, MacroRefs) {
+  Annotations HeaderCode(R"cpp(
+#define $macro[[MACRO]](X) (X+1)
+  )cpp");
+  Annotations MainCode(R"cpp(
+  void f() {
+int a = $macro[[MACRO]](1);
+  }
+  )cpp");
+
+  auto Macro = findSymbol(
+  TestTU::withHeaderCode(HeaderCode.code()).headerSymbols(), "MACRO");
+  FileIndex Index;
+  // Add test.cc
+  TestTU Test;
+  Test.HeaderCode = HeaderCode.code();
+  Test.Code = MainCode.code();
+  Test.Filename = "test.cc";
+  auto AST = Test.build();
+  Index.updateMain(Test.Filename, AST);
+  EXPECT_THAT(getRefs(Index, Macro.ID),
+  RefsAre({AllOf(RefRange(MainCode.range("macro")),
+ FileURI("unittest:///test.cc"))}));
+}
+
 TEST(FileIndexTest, CollectMacros) {
   FileIndex M;
   update(M, "f", "#define CLANGD 1");
Index: clang-tools-extra/clangd/index/SymbolCollector.h
===
--- clang-tools-extra/clangd/index/SymbolCollector.h
+++ clang-tools-extra/clangd/index/SymbolCollector.h
@@ -9,6 +9,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOL_COLLECTOR_H
 
 #include "CanonicalIncludes.h"
+#include "CollectMacros.h"
 #include "Index.h"
 #include "SymbolOrigin.h"
 #include "clang/AST/ASTContext.h"
@@ -104,6 +105,8 @@
   SourceLocation Loc,
   index::IndexDataConsumer::ASTNodeInfo ASTNode) override;
 
+  void handleMacros(const MainFileMacros &MacroRefsToIndex);
+
   bool handleMacroOccurence(const IdentifierInfo *Name, const MacroInfo *MI,
 index::SymbolRoleSet Roles,
 SourceLocation Loc) override;
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -342,6 +342,29 @@
   return true;
 }
 
+void SymbolCollector::handleMacros(const MainFileMacros &MacroRefsToIndex) {
+  assert(PP.get());
+  const auto &SM = PP->getSourceManager();
+  const auto *MainFileEntry = SM.getFileEntryForID(SM.getMainFileID());
+  assert(MainFileEntry);
+
+  const auto MainFileURI = toURI(SM, MainFileEntry->getName(), Opts);
+  // Add macro references.
+  for (const auto &IDToRefs : MacroRefsToIndex.MacroRefs) {
+for (const auto &Range : IDToRefs.second) {
+  Ref R;
+  R.Location.Start.setLine(Range.start.line);
+  R.Location.Start.setColumn(Range.start.character);
+  R.Location.End.setLine(Range.end.line);
+  R.Location.End.setColumn(Range.end.character);
+  R.Location.FileURI = MainFileURI.c_str();
+  // FIXME: Add correct RefKind information to MainFileMacros.
+  R.Kind = RefKind::Reference;
+  Refs.insert(IDToRefs.first, R);
+}
+  }
+}
+
 bool SymbolCollector::handleMacroOccurence(const IdentifierInfo *Name,
const MacroInfo *MI,
index::SymbolRoleSet Roles,
Index: clang-tools-extra/clangd/index/FileIndex.h
===
--- clang-tools-extra/clangd/index/FileIndex.h
+++ clang-tools-extra/clangd/index/FileIndex.h
@@ -140,7 +140,7 @@
 /// Exposed to assist in unit tests.
 SlabTuple indexMainDecls(ParsedAST &AST);
 
-/// Idex declarations from \p AST and macros from \p PP that are declared in
+/// Index declarations from \p AST and macros from \p PP that are declared in
 /// included headers.
 SlabTuple indexHeaderSymbols(ASTContext &AST, std::shared_ptr PP,
  const CanonicalIncludes &Includes);
Index: clang-tools-extra/clangd/index/FileIndex.cpp
===
--- clang-tools-extra/clangd/index/FileIndex.cpp
+++ clang-tools-extra/clangd/index/FileIndex.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "FileIndex.h"
+#include "CollectMacros.h"
 #include "Logger.h"
 #include "ParsedAST.h"
 #include "SymbolCollector.h"
@@ -32

[PATCH] D71406: [clangd] Add xref for macros to FileIndex.

2020-01-07 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 60496 tests passed, 0 failed 
and 726 were skipped.

{icon check-circle color=green} clang-tidy: pass.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71406



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


[PATCH] D72167: Add support for __declspec(guard(nocf))

2020-01-07 Thread Andrew Paverd via Phabricator via cfe-commits
ajpaverd updated this revision to Diff 236572.
ajpaverd marked 5 inline comments as done.
ajpaverd added a comment.

Make guard_nocf an attribute of individual call instructions

Instead of using "guard_nocf" as a function attribute, make this an attribute 
on individual call instructions for which Control Flow Guard checks should not 
be added. This allows the attribute (or lack thereof) to be propagated with the 
call instructions if they are inlined into another function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72167

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/guard_nocf.c
  clang/test/CodeGenCXX/guard_nocf.cpp
  clang/test/Sema/attr-guard_nocf.c
  clang/test/Sema/attr-guard_nocf.cpp
  llvm/docs/LangRef.rst
  llvm/lib/Transforms/CFGuard/CFGuard.cpp
  llvm/test/CodeGen/AArch64/cfguard-checks.ll
  llvm/test/CodeGen/ARM/cfguard-checks.ll
  llvm/test/CodeGen/X86/cfguard-checks.ll

Index: llvm/test/CodeGen/X86/cfguard-checks.ll
===
--- llvm/test/CodeGen/X86/cfguard-checks.ll
+++ llvm/test/CodeGen/X86/cfguard-checks.ll
@@ -8,13 +8,13 @@
 declare i32 @target_func()
 
 
-; Test that Control Flow Guard checks are not added to functions with the "guard_nocf" attribute.
-define i32 @func_guard_nocf() #0 {
+; Test that Control Flow Guard checks are not added on calls with the "guard_nocf" attribute.
+define i32 @func_guard_nocf() {
 entry:
   %func_ptr = alloca i32 ()*, align 8
   store i32 ()* @target_func, i32 ()** %func_ptr, align 8
   %0 = load i32 ()*, i32 ()** %func_ptr, align 8
-  %1 = call i32 %0()
+  %1 = call i32 %0() #0
   ret i32 %1
 
   ; X32-LABEL: func_guard_nocf
Index: llvm/test/CodeGen/ARM/cfguard-checks.ll
===
--- llvm/test/CodeGen/ARM/cfguard-checks.ll
+++ llvm/test/CodeGen/ARM/cfguard-checks.ll
@@ -7,13 +7,13 @@
 declare i32 @target_func()
 
 
-; Test that Control Flow Guard checks are not added to functions with the "guard_nocf" attribute.
+; Test that Control Flow Guard checks are not added on calls with the "guard_nocf" attribute.
 define i32 @func_guard_nocf() #0 {
 entry:
   %func_ptr = alloca i32 ()*, align 8
   store i32 ()* @target_func, i32 ()** %func_ptr, align 8
   %0 = load i32 ()*, i32 ()** %func_ptr, align 8
-  %1 = call arm_aapcs_vfpcc i32 %0()
+  %1 = call arm_aapcs_vfpcc i32 %0() #1
   ret i32 %1
 
   ; CHECK-LABEL: func_guard_nocf
@@ -22,11 +22,12 @@
   ; CHECK-NOT:   __guard_check_icall_fptr
 	; CHECK:   blx r0
 }
-attributes #0 = { "guard_nocf" "target-cpu"="cortex-a9" "target-features"="+armv7-a,+dsp,+fp16,+neon,+strict-align,+thumb-mode,+vfp3"}
+attributes #0 = { "target-cpu"="cortex-a9" "target-features"="+armv7-a,+dsp,+fp16,+neon,+strict-align,+thumb-mode,+vfp3"}
+attributes #1 = { "guard_nocf" }
 
 
 ; Test that Control Flow Guard checks are added even at -O0.
-define i32 @func_optnone_cf() #1 {
+define i32 @func_optnone_cf() #2 {
 entry:
   %func_ptr = alloca i32 ()*, align 8
   store i32 ()* @target_func, i32 ()** %func_ptr, align 8
@@ -47,11 +48,11 @@
 	; CHECK:   blx r1
 	; CHECK-NEXT:  blx r4
 }
-attributes #1 = { noinline optnone "target-cpu"="cortex-a9" "target-features"="+armv7-a,+dsp,+fp16,+neon,+strict-align,+thumb-mode,+vfp3"}
+attributes #2 = { noinline optnone "target-cpu"="cortex-a9" "target-features"="+armv7-a,+dsp,+fp16,+neon,+strict-align,+thumb-mode,+vfp3"}
 
 
 ; Test that Control Flow Guard checks are correctly added in optimized code (common case).
-define i32 @func_cf() #2 {
+define i32 @func_cf() #0 {
 entry:
   %func_ptr = alloca i32 ()*, align 8
   store i32 ()* @target_func, i32 ()** %func_ptr, align 8
@@ -70,11 +71,10 @@
 	; CHECK:   blx r1
 	; CHECK-NEXT:  blx r4
 }
-attributes #2 = { "target-cpu"="cortex-a9" "target-features"="+armv7-a,+dsp,+fp16,+neon,+strict-align,+thumb-mode,+vfp3"}
 
 
 ; Test that Control Flow Guard checks are correctly added on invoke instructions.
-define i32 @func_cf_invoke() #2 personality i8* bitcast (void ()* @h to i8*) {
+define i32 @func_cf_invoke() #0 personality i8* bitcast (void ()* @h to i8*) {
 entry:
   %0 = alloca i32, align 4
   %func_ptr = alloca i32 ()*, align 8
@@ -112,7 +112,7 @@
 %struct._SETJMP_FLOAT128 = type { [2 x i64] }
 @buf1 = internal global [16 x %struct._SETJMP_FLOAT128] zeroinitializer, align 16
 
-define i32 @func_cf_setjmp() #2 {
+define i32 @func_cf_setjmp() #0 {
   %1 = alloca i32, align 4
   %2 = alloca i32, align 4
   store i32 0, i32* %1, align 4
Index: llvm/test/CodeGen/AArch64/cfguard-checks.ll
===
--- llvm/test/CodeGen/AArch64/cfguard-checks.ll
+++ llvm/test/CodeGen/AArch64/cfguard-checks.ll
@@ -7,13 +7,13 @@
 declare i32 @ta

[clang-tools-extra] a000f2e - [clangd] Introduce bulletlists

2020-01-07 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-01-07T15:21:11+01:00
New Revision: a000f2e53f5c3433608f6097c3f4096e313b5f56

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

LOG: [clangd] Introduce bulletlists

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/FormattedString.cpp
clang-tools-extra/clangd/FormattedString.h
clang-tools-extra/clangd/unittests/FormattedStringTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/FormattedString.cpp 
b/clang-tools-extra/clangd/FormattedString.cpp
index a7a63a476c3c..cfa1210a2ee6 100644
--- a/clang-tools-extra/clangd/FormattedString.cpp
+++ b/clang-tools-extra/clangd/FormattedString.cpp
@@ -149,6 +149,21 @@ class CodeBlock : public Block {
   std::string Contents;
   std::string Language;
 };
+
+// Inserts two spaces after each `\n` to indent each line. First line is not
+// indented.
+std::string indentLines(llvm::StringRef Input) {
+  assert(!Input.endswith("\n") && "Input should've been trimmed.");
+  std::string IndentedR;
+  // We'll add 2 spaces after each new line.
+  IndentedR.reserve(Input.size() + Input.count('\n') * 2);
+  for (char C : Input) {
+IndentedR += C;
+if (C == '\n')
+  IndentedR.append("  ");
+  }
+  return IndentedR;
+}
 } // namespace
 
 std::string Block::asMarkdown() const {
@@ -193,6 +208,24 @@ void Paragraph::renderPlainText(llvm::raw_ostream &OS) 
const {
   OS << '\n';
 }
 
+void BulletList::renderMarkdown(llvm::raw_ostream &OS) const {
+  for (auto &D : Items) {
+// Instead of doing this we might prefer passing Indent to children to get
+// rid of the copies, if it turns out to be a bottleneck.
+OS << "- " << indentLines(D.asMarkdown()) << '\n';
+  }
+  // We need a new line after list to terminate it in markdown.
+  OS << '\n';
+}
+
+void BulletList::renderPlainText(llvm::raw_ostream &OS) const {
+  for (auto &D : Items) {
+// Instead of doing this we might prefer passing Indent to children to get
+// rid of the copies, if it turns out to be a bottleneck.
+OS << "- " << indentLines(D.asPlainText()) << '\n';
+  }
+}
+
 Paragraph &Paragraph::appendText(std::string Text) {
   Text = canonicalizeSpaces(std::move(Text));
   if (Text.empty())
@@ -215,6 +248,11 @@ Paragraph &Paragraph::appendCode(std::string Code) {
   return *this;
 }
 
+class Document &BulletList::addItem() {
+  Items.emplace_back();
+  return Items.back();
+}
+
 Paragraph &Document::addParagraph() {
   Children.push_back(std::make_unique());
   return *static_cast(Children.back().get());
@@ -234,6 +272,11 @@ std::string Document::asMarkdown() const {
 std::string Document::asPlainText() const {
   return renderBlocks(Children, &Block::renderPlainText);
 }
+
+BulletList &Document::addBulletList() {
+  Children.emplace_back(std::make_unique());
+  return *static_cast(Children.back().get());
+}
 } // namespace markup
 } // namespace clangd
 } // namespace clang

diff  --git a/clang-tools-extra/clangd/FormattedString.h 
b/clang-tools-extra/clangd/FormattedString.h
index 4ded2fdee315..2d1f681e7ebe 100644
--- a/clang-tools-extra/clangd/FormattedString.h
+++ b/clang-tools-extra/clangd/FormattedString.h
@@ -62,6 +62,19 @@ class Paragraph : public Block {
   std::vector Chunks;
 };
 
+/// Represents a sequence of one or more documents. Knows how to print them in 
a
+/// list like format, e.g. by prepending with "- " and indentation.
+class BulletList : public Block {
+public:
+  void renderMarkdown(llvm::raw_ostream &OS) const override;
+  void renderPlainText(llvm::raw_ostream &OS) const override;
+
+  class Document &addItem();
+
+private:
+  std::vector Items;
+};
+
 /// A format-agnostic representation for structured text. Allows rendering into
 /// markdown and plaintext.
 class Document {
@@ -74,13 +87,16 @@ class Document {
   /// text representation, the code block will be surrounded by newlines.
   void addCodeBlock(std::string Code, std::string Language = "cpp");
 
+  BulletList &addBulletList();
+
+  /// Doesn't contain any trailing newlines.
   std::string asMarkdown() const;
+  /// Doesn't contain any trailing newlines.
   std::string asPlainText() const;
 
 private:
   std::vector> Children;
 };
-
 } // namespace markup
 } // namespace clangd
 } // namespace clang

diff  --git a/clang-tools-extra/clangd/unittests/FormattedStringTests.cpp 
b/clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
index 06f43d390349..3093ba2ce50d 100644
--- a/clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
@@ -186,6 +186,71 @@ foo)pt";
   EXPECT_EQ(D.asPlainText(), Ex

[PATCH] D72167: Add support for __declspec(guard(nocf))

2020-01-07 Thread Andrew Paverd via Phabricator via cfe-commits
ajpaverd added a comment.

In D72167#1803395 , @aaron.ballman 
wrote:

> Can you please add some Sema tests that verify the attribute only appertains 
> to functions, accepts the right number of arguments, etc? Also, some tests 
> showing how this attribute works for things like redelcarations and virtual 
> functions would help.


Thanks for the feedback @aaron.ballman! I've added tests that should match the 
behaviour of MSVC for each of the cases you suggested (as well as function 
inlining).  Any other test cases we should add?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72167



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


[PATCH] D71365: expand printf when compiling HIP to AMDGPU

2020-01-07 Thread Brian Sumner via Phabricator via cfe-commits
b-sumner added a comment.

Should this be looking forward to also handling OpenCL, which does require 
vector support?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71365



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


[PATCH] D71422: [clangd] Introduce bulletlists

2020-01-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
kadircet marked 3 inline comments as done.
Closed by commit rGa000f2e53f5c: [clangd] Introduce bulletlists (authored by 
kadircet).

Changed prior to commit:
  https://reviews.llvm.org/D71422?vs=234059&id=236574#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71422

Files:
  clang-tools-extra/clangd/FormattedString.cpp
  clang-tools-extra/clangd/FormattedString.h
  clang-tools-extra/clangd/unittests/FormattedStringTests.cpp

Index: clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
===
--- clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
+++ clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
@@ -186,6 +186,71 @@
   EXPECT_EQ(D.asPlainText(), ExpectedPlainText);
 }
 
+TEST(BulletList, Render) {
+  BulletList L;
+  // Flat list
+  L.addItem().addParagraph().appendText("foo");
+  EXPECT_EQ(L.asMarkdown(), "- foo");
+  EXPECT_EQ(L.asPlainText(), "- foo");
+
+  L.addItem().addParagraph().appendText("bar");
+  EXPECT_EQ(L.asMarkdown(), R"md(- foo
+- bar)md");
+  EXPECT_EQ(L.asPlainText(), R"pt(- foo
+- bar)pt");
+
+  // Nested list, with a single item.
+  Document &D = L.addItem();
+  // First item with foo\nbaz
+  D.addParagraph().appendText("foo");
+  D.addParagraph().appendText("baz");
+
+  // Nest one level.
+  Document &Inner = D.addBulletList().addItem();
+  Inner.addParagraph().appendText("foo");
+
+  // Nest one more level.
+  BulletList &InnerList = Inner.addBulletList();
+  // Single item, baz\nbaz
+  Document &DeepDoc = InnerList.addItem();
+  DeepDoc.addParagraph().appendText("baz");
+  DeepDoc.addParagraph().appendText("baz");
+  EXPECT_EQ(L.asMarkdown(), R"md(- foo
+- bar
+- foo
+  baz
+  - foo
+- baz
+  baz)md");
+  EXPECT_EQ(L.asPlainText(), R"pt(- foo
+- bar
+- foo
+  baz
+  - foo
+- baz
+  baz)pt");
+
+  // Termination
+  Inner.addParagraph().appendText("after");
+  EXPECT_EQ(L.asMarkdown(), R"md(- foo
+- bar
+- foo
+  baz
+  - foo
+- baz
+  baz
+
+after)md");
+  EXPECT_EQ(L.asPlainText(), R"pt(- foo
+- bar
+- foo
+  baz
+  - foo
+- baz
+  baz
+after)pt");
+}
+
 } // namespace
 } // namespace markup
 } // namespace clangd
Index: clang-tools-extra/clangd/FormattedString.h
===
--- clang-tools-extra/clangd/FormattedString.h
+++ clang-tools-extra/clangd/FormattedString.h
@@ -62,6 +62,19 @@
   std::vector Chunks;
 };
 
+/// Represents a sequence of one or more documents. Knows how to print them in a
+/// list like format, e.g. by prepending with "- " and indentation.
+class BulletList : public Block {
+public:
+  void renderMarkdown(llvm::raw_ostream &OS) const override;
+  void renderPlainText(llvm::raw_ostream &OS) const override;
+
+  class Document &addItem();
+
+private:
+  std::vector Items;
+};
+
 /// A format-agnostic representation for structured text. Allows rendering into
 /// markdown and plaintext.
 class Document {
@@ -74,13 +87,16 @@
   /// text representation, the code block will be surrounded by newlines.
   void addCodeBlock(std::string Code, std::string Language = "cpp");
 
+  BulletList &addBulletList();
+
+  /// Doesn't contain any trailing newlines.
   std::string asMarkdown() const;
+  /// Doesn't contain any trailing newlines.
   std::string asPlainText() const;
 
 private:
   std::vector> Children;
 };
-
 } // namespace markup
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/FormattedString.cpp
===
--- clang-tools-extra/clangd/FormattedString.cpp
+++ clang-tools-extra/clangd/FormattedString.cpp
@@ -149,6 +149,21 @@
   std::string Contents;
   std::string Language;
 };
+
+// Inserts two spaces after each `\n` to indent each line. First line is not
+// indented.
+std::string indentLines(llvm::StringRef Input) {
+  assert(!Input.endswith("\n") && "Input should've been trimmed.");
+  std::string IndentedR;
+  // We'll add 2 spaces after each new line.
+  IndentedR.reserve(Input.size() + Input.count('\n') * 2);
+  for (char C : Input) {
+IndentedR += C;
+if (C == '\n')
+  IndentedR.append("  ");
+  }
+  return IndentedR;
+}
 } // namespace
 
 std::string Block::asMarkdown() const {
@@ -193,6 +208,24 @@
   OS << '\n';
 }
 
+void BulletList::renderMarkdown(llvm::raw_ostream &OS) const {
+  for (auto &D : Items) {
+// Instead of doing this we might prefer passing Indent to children to get
+// rid of the copies, if it turns out to be a bottleneck.
+OS << "- " << indentLines(D.asMarkdown()) << '\n';
+  }
+  // We need a new line after list to terminate it in markdown.
+  OS << '\n';
+}
+
+void BulletList::renderPlainText(llvm::raw_ostream &OS) const {
+  for (auto &D : Items) {
+// Instead of doing this we migh

[PATCH] D72167: Add support for __declspec(guard(nocf))

2020-01-07 Thread Andrew Paverd via Phabricator via cfe-commits
ajpaverd added a comment.

In D72167#180 , @dmajor wrote:

> Thanks for doing this!
>
> When I applied this patch and added `__declspec(guard(nocf))` to the function 
> that was giving us trouble 
> ,
>  I still crashed with a CFG failure in the caller, since the `nocf` function 
> was inlined. When I additionally marked that function as `noinline`, then the 
> CFG checks were omitted, as desired. Is this behavior with respect to 
> inlining expected?
>
> You may want to mention "PR44096" in the commit message.


Thanks for testing this @dmajor! I think the expected behaviour is that the 
modifier (or lack thereof) should be preserved even if the function is inlined. 
The latest changes should achieve this by placing the `"guard_nocf"` attribute 
on the individual indirect call instructions rather than the function itself. 
Does this now work for your function without having to add `noinline`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72167



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


[PATCH] D72333: [clang-tidy] Disable match on `if constexpr` statements in template instantiation for `readability-misleading-indentation` check.

2020-01-07 Thread Andi via Phabricator via cfe-commits
Abpostelnicu created this revision.
Abpostelnicu added a reviewer: alexfh.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

Fixes fixes `readability-misleading-identation` for `if constexpr`. This is 
very similar to D71980 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72333

Files:
  clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
@@ -2,6 +2,7 @@
 
 void foo1();
 void foo2();
+void foo3();
 
 #define BLOCK \
   if (cond1)  \
@@ -118,3 +119,14 @@
   #pragma unroll
   for (int k = 0; k < 1; ++k) {}
 }
+
+void shouldPassNoTemplate() {
+  constexpr unsigned Value = 1;
+  if constexpr (Value == 0) {
+foo1();
+  } else if constexpr (Value == 1) {
+foo2();
+  } else {
+foo3();
+  }
+}
Index: clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -106,7 +106,11 @@
 }
 
 void MisleadingIndentationCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(ifStmt(hasElse(stmt())).bind("if"), this);
+  Finder->addMatcher(
+  ifStmt(allOf(hasElse(stmt()),
+   unless(allOf(isConstexpr(), isInTemplateInstantiation()
+  .bind("if"),
+  this);
   Finder->addMatcher(
   compoundStmt(has(stmt(anyOf(ifStmt(), forStmt(), whileStmt()
   .bind("compound"),


Index: clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
@@ -2,6 +2,7 @@
 
 void foo1();
 void foo2();
+void foo3();
 
 #define BLOCK \
   if (cond1)  \
@@ -118,3 +119,14 @@
   #pragma unroll
   for (int k = 0; k < 1; ++k) {}
 }
+
+void shouldPassNoTemplate() {
+  constexpr unsigned Value = 1;
+  if constexpr (Value == 0) {
+foo1();
+  } else if constexpr (Value == 1) {
+foo2();
+  } else {
+foo3();
+  }
+}
Index: clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -106,7 +106,11 @@
 }
 
 void MisleadingIndentationCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(ifStmt(hasElse(stmt())).bind("if"), this);
+  Finder->addMatcher(
+  ifStmt(allOf(hasElse(stmt()),
+   unless(allOf(isConstexpr(), isInTemplateInstantiation()
+  .bind("if"),
+  this);
   Finder->addMatcher(
   compoundStmt(has(stmt(anyOf(ifStmt(), forStmt(), whileStmt()
   .bind("compound"),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3f2e3dc - [OPENMP]Do not diagnose references to non-integral types for ref in

2020-01-07 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-01-07T09:28:50-05:00
New Revision: 3f2e3dc44b42fab2e991222e74248b7006f1091e

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

LOG: [OPENMP]Do not diagnose references to non-integral types for ref in
declare simd.

According to the standard, a list-item that appears in a linear clause without 
the ref modifier must be of integral or pointer type, or must be a reference to 
an integral or pointer type. Added check that this restriction is applied only 
to non-ref items.

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/declare_simd_messages.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index d2393c17bcc8..9298a7f0d645 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -14354,8 +14354,8 @@ bool Sema::CheckOpenMPLinearDecl(const ValueDecl *D, 
SourceLocation ELoc,
   // A list item must be of integral or pointer type.
   Type = Type.getUnqualifiedType().getCanonicalType();
   const auto *Ty = Type.getTypePtrOrNull();
-  if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) &&
-  !Ty->isPointerType())) {
+  if (!Ty || (LinKind != OMPC_LINEAR_ref && !Ty->isDependentType() &&
+  !Ty->isIntegralType(Context) && !Ty->isPointerType())) {
 Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type;
 if (D) {
   bool IsDecl =

diff  --git a/clang/test/OpenMP/declare_simd_messages.cpp 
b/clang/test/OpenMP/declare_simd_messages.cpp
index d5451aba4f80..44cf41541f50 100644
--- a/clang/test/OpenMP/declare_simd_messages.cpp
+++ b/clang/test/OpenMP/declare_simd_messages.cpp
@@ -197,7 +197,8 @@ void test() {
 #pragma omp declare simd linear(ref(b))
 // expected-error@+1 {{expected one of 'ref', val' or 'uval' modifiers}} 
expected-warning@+1 {{extra tokens at the end of '#pragma omp declare simd' are 
ignored}}
 #pragma omp declare simd linear(uref(b)) allocate(b)
-void bar(int a, int *b);
+#pragma omp declare simd linear(ref(c))
+void bar(int a, int *b, float &c);
 
 template 
 struct St {



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


[PATCH] D72333: [clang-tidy] Disable match on `if constexpr` statements in template instantiation for `readability-misleading-indentation` check.

2020-01-07 Thread Andi via Phabricator via cfe-commits
Abpostelnicu updated this revision to Diff 236580.
Abpostelnicu added a comment.

Updated the test case to better reflect the changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72333

Files:
  clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
@@ -2,6 +2,7 @@
 
 void foo1();
 void foo2();
+void foo3();
 
 #define BLOCK \
   if (cond1)  \
@@ -118,3 +119,52 @@
   #pragma unroll
   for (int k = 0; k < 1; ++k) {}
 }
+
+template
+void mustPass() {
+  if constexpr (b) {
+foo1();
+  } else {
+foo2();
+  }
+}
+
+void mustPassNonTemplate() {
+  constexpr unsigned Value = 1;
+  if constexpr (Value == 0) {
+foo1();
+  } else if constexpr (Value == 1) {
+foo2();
+  } else {
+foo3();
+  }
+}
+
+template
+void mustFail() {
+  if constexpr (b) {
+foo1();
+  }
+else {
+  foo2();
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: different indentation for 
'if' and corresponding 'else' [readability-misleading-indentation]
+  }
+}
+
+void mustFailNonTemplate() {
+  constexpr unsigned Value = 1;
+  if constexpr (Value == 0) {
+foo1();
+  }
+else {
+  foo2();
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: different indentation for 'if' 
and corresponding 'else' [readability-misleading-indentation]
+  }
+}
+
+void call() {
+  mustPass();
+  mustPass();
+  mustFail();
+  mustFail();
+}
Index: clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -106,7 +106,11 @@
 }
 
 void MisleadingIndentationCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(ifStmt(hasElse(stmt())).bind("if"), this);
+  Finder->addMatcher(
+  ifStmt(allOf(hasElse(stmt()),
+   unless(allOf(isConstexpr(), isInTemplateInstantiation()
+  .bind("if"),
+  this);
   Finder->addMatcher(
   compoundStmt(has(stmt(anyOf(ifStmt(), forStmt(), whileStmt()
   .bind("compound"),


Index: clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
@@ -2,6 +2,7 @@
 
 void foo1();
 void foo2();
+void foo3();
 
 #define BLOCK \
   if (cond1)  \
@@ -118,3 +119,52 @@
   #pragma unroll
   for (int k = 0; k < 1; ++k) {}
 }
+
+template
+void mustPass() {
+  if constexpr (b) {
+foo1();
+  } else {
+foo2();
+  }
+}
+
+void mustPassNonTemplate() {
+  constexpr unsigned Value = 1;
+  if constexpr (Value == 0) {
+foo1();
+  } else if constexpr (Value == 1) {
+foo2();
+  } else {
+foo3();
+  }
+}
+
+template
+void mustFail() {
+  if constexpr (b) {
+foo1();
+  }
+else {
+  foo2();
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: different indentation for 'if' and corresponding 'else' [readability-misleading-indentation]
+  }
+}
+
+void mustFailNonTemplate() {
+  constexpr unsigned Value = 1;
+  if constexpr (Value == 0) {
+foo1();
+  }
+else {
+  foo2();
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: different indentation for 'if' and corresponding 'else' [readability-misleading-indentation]
+  }
+}
+
+void call() {
+  mustPass();
+  mustPass();
+  mustFail();
+  mustFail();
+}
Index: clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -106,7 +106,11 @@
 }
 
 void MisleadingIndentationCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(ifStmt(hasElse(stmt())).bind("if"), this);
+  Finder->addMatcher(
+  ifStmt(allOf(hasElse(stmt()),
+   unless(allOf(isConstexpr(), isInTemplateInstantiation()
+  .bind("if"),
+  this);
   Finder->addMatcher(
   compoundStmt(has(stmt(anyOf(ifStmt(), forStmt(), whileStmt()
   .bind("compound"),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72217: [clang-tidy] Added readability-qualified-auto check

2020-01-07 Thread Nathan James via Phabricator via cfe-commits
njames93 marked 7 inline comments as done.
njames93 added a comment.

What do you think about volatile qualifiers. Personally I don't think its 
important to qualify an volatile on a pointer that is volatile, but i should 
adhere to the decl being declared as volatile

  volatile auto X = getPointer();
  //transform to
  auto *X volatile = getPointer();
  
  auto X = getVolatilePointer();
  //transform to
  auto *X = getVolatilePointer();




Comment at: clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp:61
+  Diag << FixItHint::CreateReplacement(
+  FixItRange, IsPtrConst ? "const auto *const " : "auto *const ");
+} else {

JonasToth wrote:
> the outer const might be debatable. some code-bases don't want the `* const`, 
> i think neither does LLVM. maybe that could be configurable?
The outer const is only there if the vardecl was already declared as const

```
const auto X = getPointer();
auto *const X = getPointer();
```
Those 2 decls are functionally identical, both mean that the pointer X can't 
change but X is pointing to data that can change


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

https://reviews.llvm.org/D72217



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


[PATCH] D72334: [Syntax] Build nodes for template declarations.

2020-01-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added a reviewer: gribozavr2.
Herald added a project: clang.
ilya-biryukov added a parent revision: D72089: [Syntax] Build declarator nodes.
ilya-biryukov updated this revision to Diff 236583.
ilya-biryukov added a comment.

- Cosmetics


Handles template declaration of all kinds.

Also builds template declaration nodes for specializations and explicit
instantiations of classes.

Some missing things will be addressed in the follow-up patches:

- specializations of functions and variables,
- template parameters.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72334

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -677,6 +677,212 @@
   `-;
 )txt"},
   {R"cpp(
+template  struct cls {};
+template  int var = 10;
+template  int fun() {}
+)cpp",
+   R"txt(
+*: TranslationUnit
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-cls
+|   |-{
+|   |-}
+|   `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-int
+|   |-SimpleDeclarator
+|   | |-var
+|   | |-=
+|   | `-UnknownExpression
+|   |   `-10
+|   `-;
+`-TemplateDeclaration
+  |-template
+  |-<
+  |-UnknownDeclaration
+  | |-class
+  | `-T
+  |->
+  `-SimpleDeclaration
+|-int
+|-SimpleDeclarator
+| |-fun
+| `-ParametersAndQualifiers
+|   |-(
+|   `-)
+`-CompoundStatement
+  |-{
+  `-}
+)txt"},
+  {R"cpp(
+template 
+struct X {
+  template 
+  U foo();
+};
+)cpp",
+   R"txt(
+*: TranslationUnit
+`-TemplateDeclaration
+  |-template
+  |-<
+  |-UnknownDeclaration
+  | |-class
+  | `-T
+  |->
+  `-SimpleDeclaration
+|-struct
+|-X
+|-{
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-U
+| |->
+| `-SimpleDeclaration
+|   |-U
+|   |-SimpleDeclarator
+|   | |-foo
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   `-)
+|   `-;
+|-}
+`-;
+)txt"},
+  {R"cpp(
+template  struct X {};
+template  struct X {};
+template <> struct X {};
+
+template struct X;
+extern template struct X;
+)cpp",
+   R"txt(
+*: TranslationUnit
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-X
+|   |-{
+|   |-}
+|   `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-X
+|   |-<
+|   |-T
+|   |-*
+|   |->
+|   |-{
+|   |-}
+|   `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-X
+|   |-<
+|   |-int
+|   |->
+|   |-{
+|   |-}
+|   `-;
+|-ExplicitTemplateInstantiation
+| |-template
+| `-SimpleDeclaration
+|   |-struct
+|   |-X
+|   |-<
+|   |-double
+|   |->
+|   `-;
+`-ExplicitTemplateInstantiation
+  |-extern
+  |-template
+  `-SimpleDeclaration
+|-struct
+|-X
+|-<
+|-float
+|->
+`-;
+)txt"},
+  {R"cpp(
+template  struct X { struct Y; };
+template  struct X::Y {};
+)cpp",
+   R"txt(
+*: TranslationUnit
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-X
+|   |-{
+|   |-SimpleDeclaration
+|   | |-struct
+|   | |-Y
+|   | `-;
+|   |-}
+|   `-;
+`-TemplateDeclaration
+  |-template
+  |-<
+  |-UnknownDeclaration
+  | |-class
+  | `-T
+  |->
+  `-SimpleDeclaration
+|-struct
+|-X
+|-<
+|-T
+|->
+|-::
+|-Y
+|-{
+|-}
+`-;
+   )txt"},
+  {R"cpp(
 namespace ns {}
 using namespace ::ns;
 )cpp",
@@ -725,7 +931,7 @@
 )cpp",
R"txt(
 *: TranslationUnit
-`-UnknownDeclaration
+`-TemplateDeclaration
   |-template
   |-<
   |-UnknownDeclaration
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -58,6 +58,10 @@
 return OS << "LinkageSpecificationDeclaration";
   case NodeKind::SimpleDeclaration:
 return OS << "SimpleDeclaration";
+  case NodeKind::TemplateDeclaration:
+return OS << "TemplateDeclaration";
+  case NodeKind::ExplicitTemplateInstantiation:
+return OS << "ExplicitTemplateInstantiation";
   case NodeKind::NamespaceDefinition:
 return OS << "NamespaceDefinition";
   case NodeKind::NamespaceAliasDefinition:
@@ -118,6 +122,12 @@
 return OS << "StaticAssertDeclaration_mess

[PATCH] D72334: [Syntax] Build nodes for template declarations.

2020-01-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 236583.
ilya-biryukov added a comment.

- Cosmetics


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72334

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -677,6 +677,212 @@
   `-;
 )txt"},
   {R"cpp(
+template  struct cls {};
+template  int var = 10;
+template  int fun() {}
+)cpp",
+   R"txt(
+*: TranslationUnit
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-cls
+|   |-{
+|   |-}
+|   `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-int
+|   |-SimpleDeclarator
+|   | |-var
+|   | |-=
+|   | `-UnknownExpression
+|   |   `-10
+|   `-;
+`-TemplateDeclaration
+  |-template
+  |-<
+  |-UnknownDeclaration
+  | |-class
+  | `-T
+  |->
+  `-SimpleDeclaration
+|-int
+|-SimpleDeclarator
+| |-fun
+| `-ParametersAndQualifiers
+|   |-(
+|   `-)
+`-CompoundStatement
+  |-{
+  `-}
+)txt"},
+  {R"cpp(
+template 
+struct X {
+  template 
+  U foo();
+};
+)cpp",
+   R"txt(
+*: TranslationUnit
+`-TemplateDeclaration
+  |-template
+  |-<
+  |-UnknownDeclaration
+  | |-class
+  | `-T
+  |->
+  `-SimpleDeclaration
+|-struct
+|-X
+|-{
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-U
+| |->
+| `-SimpleDeclaration
+|   |-U
+|   |-SimpleDeclarator
+|   | |-foo
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   `-)
+|   `-;
+|-}
+`-;
+)txt"},
+  {R"cpp(
+template  struct X {};
+template  struct X {};
+template <> struct X {};
+
+template struct X;
+extern template struct X;
+)cpp",
+   R"txt(
+*: TranslationUnit
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-X
+|   |-{
+|   |-}
+|   `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-X
+|   |-<
+|   |-T
+|   |-*
+|   |->
+|   |-{
+|   |-}
+|   `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-X
+|   |-<
+|   |-int
+|   |->
+|   |-{
+|   |-}
+|   `-;
+|-ExplicitTemplateInstantiation
+| |-template
+| `-SimpleDeclaration
+|   |-struct
+|   |-X
+|   |-<
+|   |-double
+|   |->
+|   `-;
+`-ExplicitTemplateInstantiation
+  |-extern
+  |-template
+  `-SimpleDeclaration
+|-struct
+|-X
+|-<
+|-float
+|->
+`-;
+)txt"},
+  {R"cpp(
+template  struct X { struct Y; };
+template  struct X::Y {};
+)cpp",
+   R"txt(
+*: TranslationUnit
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-X
+|   |-{
+|   |-SimpleDeclaration
+|   | |-struct
+|   | |-Y
+|   | `-;
+|   |-}
+|   `-;
+`-TemplateDeclaration
+  |-template
+  |-<
+  |-UnknownDeclaration
+  | |-class
+  | `-T
+  |->
+  `-SimpleDeclaration
+|-struct
+|-X
+|-<
+|-T
+|->
+|-::
+|-Y
+|-{
+|-}
+`-;
+   )txt"},
+  {R"cpp(
 namespace ns {}
 using namespace ::ns;
 )cpp",
@@ -725,7 +931,7 @@
 )cpp",
R"txt(
 *: TranslationUnit
-`-UnknownDeclaration
+`-TemplateDeclaration
   |-template
   |-<
   |-UnknownDeclaration
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -58,6 +58,10 @@
 return OS << "LinkageSpecificationDeclaration";
   case NodeKind::SimpleDeclaration:
 return OS << "SimpleDeclaration";
+  case NodeKind::TemplateDeclaration:
+return OS << "TemplateDeclaration";
+  case NodeKind::ExplicitTemplateInstantiation:
+return OS << "ExplicitTemplateInstantiation";
   case NodeKind::NamespaceDefinition:
 return OS << "NamespaceDefinition";
   case NodeKind::NamespaceAliasDefinition:
@@ -118,6 +122,12 @@
 return OS << "StaticAssertDeclaration_message";
   case syntax::NodeRole::SimpleDeclaration_declarator:
 return OS << "SimpleDeclaration_declarator";
+  case syntax::NodeRole::TemplateDeclaration_declaration:
+return OS << "TemplateDeclaration_declaration";
+  case syntax::NodeRole::ExplicitTemplateInstantiation_externKeyword:
+return OS << "ExplicitTemplateInstantiation_externKeyword";
+  case syntax::NodeRole::ExplicitTemplateInst

[PATCH] D72334: [Syntax] Build nodes for template declarations.

2020-01-07 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon question-circle color=gray} Unit tests: unknown.

{icon question-circle color=gray} clang-tidy: unknown.

{icon question-circle color=gray} clang-format: unknown.

Build artifacts 
: 
diff.json 
,
 console-log.txt 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72334



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


[PATCH] D72334: [Syntax] Build nodes for template declarations.

2020-01-07 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon question-circle color=gray} Unit tests: unknown.

{icon question-circle color=gray} clang-tidy: unknown.

{icon question-circle color=gray} clang-format: unknown.

Build artifacts 
: 
diff.json 
,
 console-log.txt 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72334



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


[PATCH] D72114: [MS] Overhaul how clang passes overaligned args on x86_32

2020-01-07 Thread Anton Yudintsev via Phabricator via cfe-commits
AntonYudintsev added inline comments.



Comment at: clang/test/CodeGen/x86_32-arguments-win32.c:77
+// CHECK-LABEL: define dso_local void @receive_vec_256(<8 x float> inreg %x, 
<8 x float> inreg %y, <8 x float> inreg %z, <8 x float>* %0, <8 x float>* %1)
+// CHECK-LABEL: define dso_local void @receive_vec_512(<16 x float> inreg %x, 
<16 x float> inreg %y, <16 x float> inreg %z, <16 x float>* %0, <16 x float>* 
%1)
+// CHECK-LABEL: define dso_local void @receive_vec_1024(<32 x float>* %0, <32 
x float>* %1, <32 x float>* %2, <32 x float>* %3, <32 x float>* %4)

rjmccall wrote:
> AntonYudintsev wrote:
> > rjmccall wrote:
> > > rnk wrote:
> > > > rjmccall wrote:
> > > > > rnk wrote:
> > > > > > craig.topper wrote:
> > > > > > > What happens in the backend with inreg if 512-bit vectors aren't 
> > > > > > > legal?
> > > > > > LLVM splits the vector up using the largest legal vector size. As 
> > > > > > many pieces as possible are passed in available XMM/YMM registers, 
> > > > > > and the rest are passed in memory. MSVC, of course, assumes the 
> > > > > > user wanted the larger vector size, and uses whatever vector 
> > > > > > instructions it needs to move the arguments around.
> > > > > > 
> > > > > > Previously, I advocated for a model where calling an Intel 
> > > > > > intrinsic function had the effect of implicitly marking the caller 
> > > > > > with the target attributes of the intrinsic. This falls down if the 
> > > > > > user tries to write a single function that conditionally branches 
> > > > > > between code that uses different instruction set extensions. You 
> > > > > > can imagine the SSE2 codepath accidentally using AVX instructions 
> > > > > > because the compiler thinks they are better. I'm told that ICC 
> > > > > > models CPU micro-architectural features in the CFG, but I don't 
> > > > > > ever expect that LLVM will do that. If we're stuck with 
> > > > > > per-function CPU feature settings, it seems like it would be nice 
> > > > > > to try to do what the user asked by default, and warn the user if 
> > > > > > we see them doing a cpuid check in a function that has been 
> > > > > > implicitly blessed with some target attributes. You could imagine 
> > > > > > doing a similar thing when large vector type variables are used: if 
> > > > > > a large vector argument or local is used, implicitly enable the 
> > > > > > appropriate target features to move vectors of that size around.
> > > > > > 
> > > > > > This idea didn't get anywhere, and the current situation has 
> > > > > > persisted.
> > > > > > 
> > > > > > ---
> > > > > > 
> > > > > > You know, maybe we should just keep clang the way it is, and just 
> > > > > > set up a warning in the backend that says "hey, I split your large 
> > > > > > vector. You probably didn't want that." And then we just continue 
> > > > > > doing what we do now. Nobody likes backend warnings, but it seems 
> > > > > > better than the current direction of the frontend knowing every 
> > > > > > detail of x86 vector extensions.
> > > > > If target attributes affect ABI, it seems really dangerous to 
> > > > > implicitly set attributes based on what intrinsics are called.
> > > > > 
> > > > > The local CPU-testing problem seems similar to the problems with 
> > > > > local `#pragma STDC FENV_ACCESS` blocks that the constrained-FP 
> > > > > people are looking into.  They both have a "this operation is 
> > > > > normally fully optimizable, but we might need to be more careful in 
> > > > > specific functions" aspect to them.  I wonder if there's a reasonable 
> > > > > way to unify the approaches, or at least benefit from lessons learned.
> > > > I agree, we wouldn't want intrinsic usage to change ABI. But, does 
> > > > anybody actually want the behavior that LLVM implements today where 
> > > > large vectors get split across registers and memory? I think most users 
> > > > who pass a 512 bit vector want it to either be passed in ZMM registers 
> > > > or fail to compile. Why do we even support passing 1024 bit vectors? 
> > > > Could we make that an error?
> > > > 
> > > > Anyway, major redesigns aside, should clang do something when large 
> > > > vectors are passed? Maybe we should warn here? Passing by address is 
> > > > usually the safest way to pass something, so that's an option. 
> > > > Implementing splitting logic in clang doesn't seem worth it.
> > > > I agree, we wouldn't want intrinsic usage to change ABI. But, does 
> > > > anybody actually want the behavior that LLVM implements today where 
> > > > large vectors get split across registers and memory?
> > > 
> > > I take it you're implying that the actual (Windows-only?) platform ABI 
> > > doesn't say anything about this because other compilers don't allow large 
> > > vectors.  How large are the vectors we do have ABI rules for?  Do they 
> > > have the problem as the SysV ABI where the ABI rules are sensitive to 
> > > compiler flags?
> > > 
> > > Any

[PATCH] D72333: [clang-tidy] Disable match on `if constexpr` statements in template instantiation for `readability-misleading-indentation` check.

2020-01-07 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

I could never seem to get the tests to handle differently in templated and non 
templated code. Maybe i was just being stupid. Think the root cause is that the 
check detects if the if column appears on a different column to either the else 
or the closing brace if its on the same line as the else.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72333



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


[PATCH] D72282: [clang-tidy] Add `bugprone-unintended-adl`

2020-01-07 Thread Logan Smith via Phabricator via cfe-commits
logan-5 updated this revision to Diff 236593.
logan-5 added a comment.

Clean up some false positives in macro expansions and in expressions with 
nested potential ADL usages (e.g. in lambdas passed as function parameters).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72282

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/UnintendedADLCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnintendedADLCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-unintended-adl.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-unintended-adl.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-unintended-adl.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-unintended-adl.cpp
@@ -0,0 +1,111 @@
+// RUN: %check_clang_tidy -std=c++14-or-later %s bugprone-unintended-adl %t
+
+namespace aspace {
+struct A {};
+void func(const A &);
+} // namespace aspace
+
+namespace bspace {
+void func(int);
+void test() {
+  aspace::A a;
+  func(5);
+  func(a);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: expression calls 'aspace::func' through ADL [bugprone-unintended-adl]
+}
+} // namespace bspace
+
+namespace ops {
+struct Stream {
+} stream;
+Stream &operator<<(Stream &s, int) {
+  return s;
+}
+void smooth_operator(Stream);
+} // namespace ops
+
+void test() {
+  ops::stream << 5;
+  operator<<(ops::stream, 5);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: expression calls 'ops::operator<<' through ADL [bugprone-unintended-adl]
+  smooth_operator(ops::stream);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: expression calls 'ops::smooth_operator' through ADL [bugprone-unintended-adl]
+}
+
+namespace ns {
+struct Swappable {};
+void swap(Swappable &a, Swappable &b); // whitelisted by default
+
+void move(Swappable) {} // non-whitelisted
+template 
+void forward(T) {} // non-whitelisted
+
+struct Swappable2 {};
+} // namespace ns
+
+void move(ns::Swappable2);
+auto ref = [](ns::Swappable2) {};
+
+void test2() {
+  ns::Swappable a, b;
+  using namespace std;
+  swap(a, b);
+  move(a);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: expression calls 'ns::move' through ADL [bugprone-unintended-adl]
+  forward(a);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: expression calls 'ns::forward' through ADL [bugprone-unintended-adl]
+}
+
+template 
+void templateFunction(T t) {
+  swap(t, t);
+
+  move(t);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: unqualified call to 'move' may be resolved through ADL [bugprone-unintended-adl]
+
+  ns::move(t);
+  ::move(t);
+
+  ref(t);
+  ::ref(t);
+
+  t << 5;
+  operator<<(t, 5);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: unqualified call to 'operator<<' may be resolved through ADL [bugprone-unintended-adl]
+}
+
+namespace std {
+template 
+It find_if(It begin, It end, Pred pred) {
+  for (; begin != end; ++begin) {
+if (pred(*begin))
+  break;
+  }
+  return begin;
+}
+} // namespace std
+
+void test3() {
+  int x = 0;
+  auto l = [&](auto &c) { std::find_if(c.begin(), c.end(),
+   [&](auto &e) { return e.first == x; }); };
+
+  auto m = [&](auto &c) { std::find_if(c.begin(), c.end(),
+   [&](auto &e) { return find_if(e, e, x); }); };
+  // CHECK-MESSAGES: [[@LINE-1]]:62: warning: unqualified call to 'find_if' may be resolved through ADL [bugprone-unintended-adl]
+}
+
+template 
+void test4(T t) {
+#define MACRO(x) find_if(x, x, x)
+
+  MACRO(t);
+
+#undef MACRO
+
+#define MACRO(x) func(x)
+
+  MACRO(aspace::A());
+
+#undef MACRO
+}
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-unintended-adl.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-unintended-adl.rst
@@ -0,0 +1,47 @@
+.. title:: clang-tidy - bugprone-unintended-adl
+
+bugprone-unintended-adl
+===
+
+Finds usages of ADL (argument-dependent lookup), or potential ADL in the case 
+of templates, that are not on the provided whitelist.
+
+.. code-block:: c++
+
+  namespace aspace {
+  struct A {};
+  void func(const A &);
+  } // namespace aspace
+  
+  namespace bspace {
+  void func(int);
+  void test() {
+aspace::A a;
+func(5);
+func(a); // calls 'aspace::func' through ADL
+  }
+  } // namespace bspace
+
+(Example respectfully borrowed from `Abseil TotW #49 `_.)
+
+ADL can be surprising, and can lead to `subtle bugs 
+`_ without the utmost attention. 
+However, it very is useful for lookup of overloaded operators, and for 
+customization points within libraries (e.g. ``swap`` in the C++ standard 
+library). As

[clang] 9f2d8b5 - [HIP] Add option --gpu-max-threads-per-block=n

2020-01-07 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2020-01-07T11:18:00-05:00
New Revision: 9f2d8b5c0cdb31c5617476575c03826274ecbd25

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

LOG: [HIP] Add option --gpu-max-threads-per-block=n

Add this option to change the default launch bounds.

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

Added: 
clang/test/Driver/hip-options.hip

Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/Driver/ToolChains/HIP.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 82372b098991..068f206f4484 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -227,6 +227,7 @@ LANGOPT(CUDAHostDeviceConstexpr, 1, 1, "treating 
unattributed constexpr function
 LANGOPT(CUDADeviceApproxTranscendentals, 1, 0, "using approximate 
transcendental functions")
 LANGOPT(GPURelocatableDeviceCode, 1, 0, "generate relocatable device code")
 LANGOPT(GPUAllowDeviceInit, 1, 0, "allowing device side global init functions 
for HIP")
+LANGOPT(GPUMaxThreadsPerBlock, 32, 256, "default max threads per block for 
kernel launch bounds for HIP")
 
 LANGOPT(SYCLIsDevice  , 1, 0, "Generate code for SYCL device")
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 808cca76c6be..e48817931efd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -606,6 +606,9 @@ def fno_hip_new_launch_api : Flag<["-"], 
"fno-hip-new-launch-api">;
 def fgpu_allow_device_init : Flag<["-"], "fgpu-allow-device-init">,
   Flags<[CC1Option]>, HelpText<"Allow device side init function in HIP">;
 def fno_gpu_allow_device_init : Flag<["-"], "fno-gpu-allow-device-init">;
+def gpu_max_threads_per_block_EQ : Joined<["--"], 
"gpu-max-threads-per-block=">,
+  Flags<[CC1Option]>,
+  HelpText<"Default max threads per block for kernel launch bounds for HIP">;
 def libomptarget_nvptx_path_EQ : Joined<["--"], "libomptarget-nvptx-path=">, 
Group,
   HelpText<"Path to libomptarget-nvptx libraries">;
 def dD : Flag<["-"], "dD">, Group, Flags<[CC1Option]>,

diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 6c6400652a6d..7068fa0fcc69 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -8072,8 +8072,11 @@ void AMDGPUTargetCodeGenInfo::setTargetAttributes(
 } else
   assert(Max == 0 && "Max must be zero");
   } else if (IsOpenCLKernel || IsHIPKernel) {
-// By default, restrict the maximum size to 256.
-F->addFnAttr("amdgpu-flat-work-group-size", "1,256");
+// By default, restrict the maximum size to a value specified by
+// --gpu-max-threads-per-block=n or its default value.
+std::string AttrVal =
+std::string("1,") + 
llvm::utostr(M.getLangOpts().GPUMaxThreadsPerBlock);
+F->addFnAttr("amdgpu-flat-work-group-size", AttrVal);
   }
 
   if (const auto *Attr = FD->getAttr()) {

diff  --git a/clang/lib/Driver/ToolChains/HIP.cpp 
b/clang/lib/Driver/ToolChains/HIP.cpp
index f68b5cd68184..f89e648948ab 100644
--- a/clang/lib/Driver/ToolChains/HIP.cpp
+++ b/clang/lib/Driver/ToolChains/HIP.cpp
@@ -307,6 +307,14 @@ void HIPToolChain::addClangTargetOptions(
  false))
 CC1Args.push_back("-fgpu-rdc");
 
+  StringRef MaxThreadsPerBlock =
+  DriverArgs.getLastArgValue(options::OPT_gpu_max_threads_per_block_EQ);
+  if (!MaxThreadsPerBlock.empty()) {
+std::string ArgStr =
+std::string("--gpu-max-threads-per-block=") + MaxThreadsPerBlock.str();
+CC1Args.push_back(DriverArgs.MakeArgStringRef(ArgStr));
+  }
+
   if (DriverArgs.hasFlag(options::OPT_fgpu_allow_device_init,
  options::OPT_fno_gpu_allow_device_init, false))
 CC1Args.push_back("-fgpu-allow-device-init");

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 5f332aff75c2..6f6f43ca284b 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2559,6 +2559,12 @@ static void ParseLangArgs(LangOptions &Opts, ArgList 
&Args, InputKind IK,
   << Args.getLastArg(OPT_fgpu_allow_device_init)->getAsString(Args);
   }
   Opts.HIPUseNewLaunchAPI = Args.hasArg(OPT_fhip_new_launch_api);
+  if (Opts.HIP)
+Opts.GPUMaxThreadsPerBlock = getLastArgIntValue(
+Args, OPT_gpu_max_threads_per_block_EQ, Opts.GPUMaxThreadsPerBlock);
+  else if (Args.hasArg(OPT_gpu_max_threads_per_block_EQ))
+Diags.Report(diag::

[PATCH] D71221: [HIP] Add option --gpu-max-threads-per-block=n

2020-01-07 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9f2d8b5c0cdb: [HIP] Add option --gpu-max-threads-per-block=n 
(authored by yaxunl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71221

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
  clang/test/Driver/hip-options.hip

Index: clang/test/Driver/hip-options.hip
===
--- /dev/null
+++ clang/test/Driver/hip-options.hip
@@ -0,0 +1,10 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang -### -x hip --gpu-max-threads-per-block=1024 %s 2>&1 | FileCheck %s
+
+// Check that there are commands for both host- and device-side compilations.
+//
+// CHECK: clang{{.*}}" "-cc1" {{.*}} "-fcuda-is-device"
+// CHECK-SAME: "--gpu-max-threads-per-block=1024"
Index: clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
===
--- clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
+++ clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
@@ -1,13 +1,21 @@
 // RUN: %clang_cc1 -triple amdgcn-amd-amdhsa \
-// RUN: -fcuda-is-device -emit-llvm -o - %s | FileCheck %s
+// RUN: -fcuda-is-device -emit-llvm -o - -x hip %s \
+// RUN: | FileCheck -check-prefixes=CHECK,DEFAULT %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa --gpu-max-threads-per-block=1024 \
+// RUN: -fcuda-is-device -emit-llvm -o - -x hip %s \
+// RUN: | FileCheck -check-prefixes=CHECK,MAX1024 %s
 // RUN: %clang_cc1 -triple nvptx \
 // RUN: -fcuda-is-device -emit-llvm -o - %s | FileCheck %s \
 // RUN: -check-prefix=NAMD
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm \
-// RUN: -verify -o - %s | FileCheck -check-prefix=NAMD %s
+// RUN: -verify -o - -x hip %s | FileCheck -check-prefix=NAMD %s
 
 #include "Inputs/cuda.h"
 
+__global__ void flat_work_group_size_default() {
+// CHECK: define amdgpu_kernel void @_Z28flat_work_group_size_defaultv() [[FLAT_WORK_GROUP_SIZE_DEFAULT:#[0-9]+]]
+}
+
 __attribute__((amdgpu_flat_work_group_size(32, 64))) // expected-no-diagnostics
 __global__ void flat_work_group_size_32_64() {
 // CHECK: define amdgpu_kernel void @_Z26flat_work_group_size_32_64v() [[FLAT_WORK_GROUP_SIZE_32_64:#[0-9]+]]
@@ -31,7 +39,9 @@
 // NAMD-NOT: "amdgpu-num-vgpr"
 // NAMD-NOT: "amdgpu-num-sgpr"
 
-// CHECK-DAG: attributes [[FLAT_WORK_GROUP_SIZE_32_64]] = { convergent noinline nounwind optnone "amdgpu-flat-work-group-size"="32,64" 
-// CHECK-DAG: attributes [[WAVES_PER_EU_2]] = { convergent noinline nounwind optnone "amdgpu-waves-per-eu"="2"
-// CHECK-DAG: attributes [[NUM_SGPR_32]] = { convergent noinline nounwind optnone "amdgpu-num-sgpr"="32" 
-// CHECK-DAG: attributes [[NUM_VGPR_64]] = { convergent noinline nounwind optnone "amdgpu-num-vgpr"="64" 
+// DEFAULT-DAG: attributes [[FLAT_WORK_GROUP_SIZE_DEFAULT]] = {{.*}}"amdgpu-flat-work-group-size"="1,256"
+// MAX1024-DAG: attributes [[FLAT_WORK_GROUP_SIZE_DEFAULT]] = {{.*}}"amdgpu-flat-work-group-size"="1,1024"
+// CHECK-DAG: attributes [[FLAT_WORK_GROUP_SIZE_32_64]] = {{.*}}"amdgpu-flat-work-group-size"="32,64"
+// CHECK-DAG: attributes [[WAVES_PER_EU_2]] = {{.*}}"amdgpu-waves-per-eu"="2"
+// CHECK-DAG: attributes [[NUM_SGPR_32]] = {{.*}}"amdgpu-num-sgpr"="32"
+// CHECK-DAG: attributes [[NUM_VGPR_64]] = {{.*}}"amdgpu-num-vgpr"="64"
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2559,6 +2559,12 @@
   << Args.getLastArg(OPT_fgpu_allow_device_init)->getAsString(Args);
   }
   Opts.HIPUseNewLaunchAPI = Args.hasArg(OPT_fhip_new_launch_api);
+  if (Opts.HIP)
+Opts.GPUMaxThreadsPerBlock = getLastArgIntValue(
+Args, OPT_gpu_max_threads_per_block_EQ, Opts.GPUMaxThreadsPerBlock);
+  else if (Args.hasArg(OPT_gpu_max_threads_per_block_EQ))
+Diags.Report(diag::warn_ignored_hip_only_option)
+<< Args.getLastArg(OPT_gpu_max_threads_per_block_EQ)->getAsString(Args);
 
   if (Opts.ObjC) {
 if (Arg *arg = Args.getLastArg(OPT_fobjc_runtime_EQ)) {
Index: clang/lib/Driver/ToolChains/HIP.cpp
===
--- clang/lib/Driver/ToolChains/HIP.cpp
+++ clang/lib/Driver/ToolChains/HIP.cpp
@@ -307,6 +307,14 @@
  false))
 CC1Args.push_back("-fgpu-rdc");
 
+  StringRef MaxThreadsPerBlock =
+  DriverArgs.getLastArgValue(options::OPT_gpu_max_threads_per_block_EQ);
+  if (!MaxThreadsPerBlock.empty()) {
+std::string ArgStr =
+  

[PATCH] D72333: [clang-tidy] Disable match on `if constexpr` statements in template instantiation for `readability-misleading-indentation` check.

2020-01-07 Thread Andi via Phabricator via cfe-commits
Abpostelnicu updated this revision to Diff 236596.
Abpostelnicu added a comment.

Updated test with match without compound statement.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72333

Files:
  clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
@@ -2,6 +2,7 @@
 
 void foo1();
 void foo2();
+void foo3();
 
 #define BLOCK \
   if (cond1)  \
@@ -118,3 +119,58 @@
   #pragma unroll
   for (int k = 0; k < 1; ++k) {}
 }
+
+template
+void mustPass() {
+  if constexpr (b) {
+foo1();
+  } else {
+foo2();
+  }
+}
+
+void mustPassNonTemplate() {
+  constexpr unsigned Value = 1;
+  if constexpr (Value == 0) {
+foo1();
+  } else if constexpr (Value == 1) {
+foo2();
+  } else {
+foo3();
+  }
+}
+
+template
+void mustFail() {
+  if constexpr (b) {
+foo1();
+  }
+else {
+  foo2();
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: different indentation for 
'if' and corresponding 'else' [readability-misleading-indentation]
+  }
+}
+
+void mustFailNonTemplate() {
+  constexpr unsigned Value = 1;
+  if constexpr (Value == 0) {
+foo1();
+  }
+else {
+  foo2();
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: different indentation for 'if' 
and corresponding 'else' [readability-misleading-indentation]
+  }
+
+  if constexpr (Value == 0)
+foo1();
+else
+  foo2();
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: different indentation for 'if' 
and corresponding 'else' [readability-misleading-indentation]
+}
+
+void call() {
+  mustPass();
+  mustPass();
+  mustFail();
+  mustFail();
+}
Index: clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -106,7 +106,11 @@
 }
 
 void MisleadingIndentationCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(ifStmt(hasElse(stmt())).bind("if"), this);
+  Finder->addMatcher(
+  ifStmt(allOf(hasElse(stmt()),
+   unless(allOf(isConstexpr(), isInTemplateInstantiation()
+  .bind("if"),
+  this);
   Finder->addMatcher(
   compoundStmt(has(stmt(anyOf(ifStmt(), forStmt(), whileStmt()
   .bind("compound"),


Index: clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
@@ -2,6 +2,7 @@
 
 void foo1();
 void foo2();
+void foo3();
 
 #define BLOCK \
   if (cond1)  \
@@ -118,3 +119,58 @@
   #pragma unroll
   for (int k = 0; k < 1; ++k) {}
 }
+
+template
+void mustPass() {
+  if constexpr (b) {
+foo1();
+  } else {
+foo2();
+  }
+}
+
+void mustPassNonTemplate() {
+  constexpr unsigned Value = 1;
+  if constexpr (Value == 0) {
+foo1();
+  } else if constexpr (Value == 1) {
+foo2();
+  } else {
+foo3();
+  }
+}
+
+template
+void mustFail() {
+  if constexpr (b) {
+foo1();
+  }
+else {
+  foo2();
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: different indentation for 'if' and corresponding 'else' [readability-misleading-indentation]
+  }
+}
+
+void mustFailNonTemplate() {
+  constexpr unsigned Value = 1;
+  if constexpr (Value == 0) {
+foo1();
+  }
+else {
+  foo2();
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: different indentation for 'if' and corresponding 'else' [readability-misleading-indentation]
+  }
+
+  if constexpr (Value == 0)
+foo1();
+else
+  foo2();
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: different indentation for 'if' and corresponding 'else' [readability-misleading-indentation]
+}
+
+void call() {
+  mustPass();
+  mustPass();
+  mustFail();
+  mustFail();
+}
Index: clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -106,7 +106,11 @@
 }
 
 void MisleadingIndentationCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(ifStmt(hasElse(stmt())).bind("if"), this);
+  Finder->addMatcher(
+  ifStmt(allOf(hasElse(stmt()),
+   unless(allOf

[PATCH] D72284: [clang-tidy] Factor out renaming logic from readability-identifier-naming

2020-01-07 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp:272
+  if (const auto *Typedef =
+  Value->getReturnType().getTypePtr()->getAs()) {
+addUsage(NamingCheckFailures, Typedef->getDecl(),

aaron.ballman wrote:
> logan-5 wrote:
> > Eugene.Zelenko wrote:
> > > Please elide braces.
> > Would you mind pointing me toward a resource for these formatting nits? I 
> > don't see anything about requiring omitting braces for single-statement 
> > if()s in the official LLVM coding standards (and I happen to think the 
> > braces actually help readability here). If this stuff is explicitly 
> > documented somewhere and painstakingly enforced like this, I'd rather get 
> > it right the first time.
> I looked through the coding standard and it does not suggest this, which I am 
> really surprised to see (I feel like the standard used to say it at some 
> point, but it likely got removed and I did not notice). This is a common 
> pattern that's used all over the code base (likely from fairly consistent 
> review guidance over the years), and so it's best to be consistent with the 
> style used locally, but that's a pretty weak argument for new code.
Did it maybe get dropped? Wasn't there are overhaul a few weeks ago? But I am 
surprised as well, as this was at one point explicitly stated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72284



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


[PATCH] D72217: [clang-tidy] Added readability-qualified-auto check

2020-01-07 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp:61
+  Diag << FixItHint::CreateReplacement(
+  FixItRange, IsPtrConst ? "const auto *const " : "auto *const ");
+} else {

njames93 wrote:
> JonasToth wrote:
> > the outer const might be debatable. some code-bases don't want the `* 
> > const`, i think neither does LLVM. maybe that could be configurable?
> The outer const is only there if the vardecl was already declared as const
> 
> ```
> const auto X = getPointer();
> auto *const X = getPointer();
> ```
> Those 2 decls are functionally identical, both mean that the pointer X can't 
> change but X is pointing to data that can change
I see. That is ok then, but might be surprising to some users, as they might 
think the pointee itself is const (which it isn't). I think thats something 
worth to write in the documentation.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp:183
+
+  auto LambdaTest = [] { return 0; };
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: 'auto LambdaTest' can be 
declared as 'auto *LambdaTest'

How does that beatiful code-construct get handled?

```
auto * function_ptr = +[](int) {};
```
The lambda is actually converted to a function pointer through the 
`+`-operator. Not sure this happens anywhere, but it can happen.
So the case:
```
auto unnotice_ptr = +[](int) {};
```
should be transformed.


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

https://reviews.llvm.org/D72217



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


[clang] 247a603 - [LifetimeAnalysis] Do not forbid void deref type in gsl::Pointer/gsl::Owner annotations

2020-01-07 Thread Gabor Horvath via cfe-commits

Author: Gabor Horvath
Date: 2020-01-07T08:32:40-08:00
New Revision: 247a6032549efb03c14b79c035a47c660b75263e

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

LOG: [LifetimeAnalysis] Do not forbid void deref type in 
gsl::Pointer/gsl::Owner annotations

It turns out it is useful to be able to define the deref type as void.
In case we have a type erased owner, we want to express that the pointee
can be basically any type. It should not be unnatural to have a void
deref type as we already familiar with "pointers to void".

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

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/SemaCXX/attr-gsl-owner-pointer.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 9b4afa8f128e..515476df3fdd 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4590,7 +4590,7 @@ object of type ``T``:
 
 The argument ``T`` is optional and is ignored.
 This attribute may be used by analysis tools and has no effect on code
-generation.
+generation. A ``void`` argument means that the class can own any type.
 
 See Pointer_ for an example.
 }];
@@ -4616,7 +4616,7 @@ like pointers to an object of type ``T``:
 
 The argument ``T`` is optional and is ignored.
 This attribute may be used by analysis tools and has no effect on code
-generation.
+generation. A ``void`` argument means that the pointer can point to any type.
 
 Example:
 When constructing an instance of a class annotated like this (a Pointer) from

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a8f49fef9f1f..dd9649bcb5c3 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2631,7 +2631,7 @@ def err_nsobject_attribute : Error<
 def err_attributes_are_not_compatible : Error<
   "%0 and %1 attributes are not compatible">;
 def err_attribute_invalid_argument : Error<
-  "%select{'void'|a reference type|an array type|a non-vector or "
+  "%select{a reference type|an array type|a non-vector or "
   "non-vectorizable scalar type}0 is an invalid argument to attribute %1">;
 def err_attribute_wrong_number_arguments : Error<
   "%0 attribute %plural{0:takes no arguments|1:takes one argument|"

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 50951ad60228..02aebbea4a8b 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2913,7 +2913,7 @@ static void handleVecTypeHint(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   if (!ParmType->isExtVectorType() && !ParmType->isFloatingType() &&
   (ParmType->isBooleanType() ||
!ParmType->isIntegralType(S.getASTContext( {
-S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument) << 3 << AL;
+S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument) << 2 << AL;
 return;
   }
 
@@ -4454,12 +4454,10 @@ static void handleLifetimeCategoryAttr(Sema &S, Decl 
*D, const ParsedAttr &AL) {
 ParmType = S.GetTypeFromParser(AL.getTypeArg(), &DerefTypeLoc);
 
 unsigned SelectIdx = ~0U;
-if (ParmType->isVoidType())
+if (ParmType->isReferenceType())
   SelectIdx = 0;
-else if (ParmType->isReferenceType())
-  SelectIdx = 1;
 else if (ParmType->isArrayType())
-  SelectIdx = 2;
+  SelectIdx = 1;
 
 if (SelectIdx != ~0U) {
   S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument)

diff  --git a/clang/test/SemaCXX/attr-gsl-owner-pointer.cpp 
b/clang/test/SemaCXX/attr-gsl-owner-pointer.cpp
index 5b438822ba21..6c1bfe405e86 100644
--- a/clang/test/SemaCXX/attr-gsl-owner-pointer.cpp
+++ b/clang/test/SemaCXX/attr-gsl-owner-pointer.cpp
@@ -31,9 +31,11 @@ class [[gsl::Owner(int)]] [[gsl::Pointer(int)]] 
BothOwnerPointer{};
 // CHECK: OwnerAttr {{.*}} int
 
 class [[gsl::Owner(void)]] OwnerVoidDerefType{};
-// expected-error@-1 {{'void' is an invalid argument to attribute 'Owner'}}
+// CHECK: CXXRecordDecl {{.*}} OwnerVoidDerefType
+// CHECK: OwnerAttr {{.*}} void
 class [[gsl::Pointer(void)]] PointerVoidDerefType{};
-// expected-error@-1 {{'void' is an invalid argument to attribute 'Pointer'}}
+// CHECK: CXXRecordDecl {{.*}} PointerVoidDerefType
+// CHECK: PointerAttr {{.*}} void
 
 class [[gsl::Pointer(int)]] AddConflictLater{};
 // CHECK: CXXRecordDecl {{.*}} AddConflictLater



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


[PATCH] D72284: [clang-tidy] Factor out renaming logic from readability-identifier-naming

2020-01-07 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

i am still fine with the patch. if no one else has objections, i think this can 
land.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72284



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


[PATCH] D62686: [RISCV] Add support for save/restore of callee-saved registers via libcalls

2020-01-07 Thread Ana Pazos via Phabricator via cfe-commits
apazos added a comment.

Lewis, is the patch final? It would be good to merge it before the 10.0 release 
branch creation on Jan 15th


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62686



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


[PATCH] D72097: [LifetimeAnalysis] Do not forbid void deref type in gsl::Pointer/gsl::Owner annotations

2020-01-07 Thread Gábor Horváth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
xazax.hun marked an inline comment as done.
Closed by commit rG247a6032549e: [LifetimeAnalysis] Do not forbid void deref 
type in gsl::Pointer/gsl::Owner… (authored by xazax.hun).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72097

Files:
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaCXX/attr-gsl-owner-pointer.cpp


Index: clang/test/SemaCXX/attr-gsl-owner-pointer.cpp
===
--- clang/test/SemaCXX/attr-gsl-owner-pointer.cpp
+++ clang/test/SemaCXX/attr-gsl-owner-pointer.cpp
@@ -31,9 +31,11 @@
 // CHECK: OwnerAttr {{.*}} int
 
 class [[gsl::Owner(void)]] OwnerVoidDerefType{};
-// expected-error@-1 {{'void' is an invalid argument to attribute 'Owner'}}
+// CHECK: CXXRecordDecl {{.*}} OwnerVoidDerefType
+// CHECK: OwnerAttr {{.*}} void
 class [[gsl::Pointer(void)]] PointerVoidDerefType{};
-// expected-error@-1 {{'void' is an invalid argument to attribute 'Pointer'}}
+// CHECK: CXXRecordDecl {{.*}} PointerVoidDerefType
+// CHECK: PointerAttr {{.*}} void
 
 class [[gsl::Pointer(int)]] AddConflictLater{};
 // CHECK: CXXRecordDecl {{.*}} AddConflictLater
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2913,7 +2913,7 @@
   if (!ParmType->isExtVectorType() && !ParmType->isFloatingType() &&
   (ParmType->isBooleanType() ||
!ParmType->isIntegralType(S.getASTContext( {
-S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument) << 3 << AL;
+S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument) << 2 << AL;
 return;
   }
 
@@ -4454,12 +4454,10 @@
 ParmType = S.GetTypeFromParser(AL.getTypeArg(), &DerefTypeLoc);
 
 unsigned SelectIdx = ~0U;
-if (ParmType->isVoidType())
+if (ParmType->isReferenceType())
   SelectIdx = 0;
-else if (ParmType->isReferenceType())
-  SelectIdx = 1;
 else if (ParmType->isArrayType())
-  SelectIdx = 2;
+  SelectIdx = 1;
 
 if (SelectIdx != ~0U) {
   S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument)
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2631,7 +2631,7 @@
 def err_attributes_are_not_compatible : Error<
   "%0 and %1 attributes are not compatible">;
 def err_attribute_invalid_argument : Error<
-  "%select{'void'|a reference type|an array type|a non-vector or "
+  "%select{a reference type|an array type|a non-vector or "
   "non-vectorizable scalar type}0 is an invalid argument to attribute %1">;
 def err_attribute_wrong_number_arguments : Error<
   "%0 attribute %plural{0:takes no arguments|1:takes one argument|"
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -4590,7 +4590,7 @@
 
 The argument ``T`` is optional and is ignored.
 This attribute may be used by analysis tools and has no effect on code
-generation.
+generation. A ``void`` argument means that the class can own any type.
 
 See Pointer_ for an example.
 }];
@@ -4616,7 +4616,7 @@
 
 The argument ``T`` is optional and is ignored.
 This attribute may be used by analysis tools and has no effect on code
-generation.
+generation. A ``void`` argument means that the pointer can point to any type.
 
 Example:
 When constructing an instance of a class annotated like this (a Pointer) from


Index: clang/test/SemaCXX/attr-gsl-owner-pointer.cpp
===
--- clang/test/SemaCXX/attr-gsl-owner-pointer.cpp
+++ clang/test/SemaCXX/attr-gsl-owner-pointer.cpp
@@ -31,9 +31,11 @@
 // CHECK: OwnerAttr {{.*}} int
 
 class [[gsl::Owner(void)]] OwnerVoidDerefType{};
-// expected-error@-1 {{'void' is an invalid argument to attribute 'Owner'}}
+// CHECK: CXXRecordDecl {{.*}} OwnerVoidDerefType
+// CHECK: OwnerAttr {{.*}} void
 class [[gsl::Pointer(void)]] PointerVoidDerefType{};
-// expected-error@-1 {{'void' is an invalid argument to attribute 'Pointer'}}
+// CHECK: CXXRecordDecl {{.*}} PointerVoidDerefType
+// CHECK: PointerAttr {{.*}} void
 
 class [[gsl::Pointer(int)]] AddConflictLater{};
 // CHECK: CXXRecordDecl {{.*}} AddConflictLater
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2913,7 +2913,7 @@
   if (!ParmType->isExtVectorType() && !ParmType->isFloatingType() &&
   (ParmType->isBooleanType()

[PATCH] D72289: [analyzer] Update help text to reflect sarif support

2020-01-07 Thread Gábor Horváth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG46ac6a4dcd9b: [analyzer] Update help text to reflect sarif 
support (authored by xazax.hun).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72289

Files:
  clang/include/clang/Driver/Options.td


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2862,7 +2862,7 @@
 def _all_warnings : Flag<["--"], "all-warnings">, Alias;
 def _analyzer_no_default_checks : Flag<["--"], "analyzer-no-default-checks">, 
Flags<[DriverOption]>;
 def _analyzer_output : JoinedOrSeparate<["--"], "analyzer-output">, 
Flags<[DriverOption]>,
-  HelpText<"Static analyzer report output format 
(html|plist|plist-multi-file|plist-html|text).">;
+  HelpText<"Static analyzer report output format 
(html|plist|plist-multi-file|plist-html|sarif|text).">;
 def _analyze : Flag<["--"], "analyze">, Flags<[DriverOption, CoreOption]>,
   HelpText<"Run the static analyzer">;
 def _assemble : Flag<["--"], "assemble">, Alias;


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2862,7 +2862,7 @@
 def _all_warnings : Flag<["--"], "all-warnings">, Alias;
 def _analyzer_no_default_checks : Flag<["--"], "analyzer-no-default-checks">, Flags<[DriverOption]>;
 def _analyzer_output : JoinedOrSeparate<["--"], "analyzer-output">, Flags<[DriverOption]>,
-  HelpText<"Static analyzer report output format (html|plist|plist-multi-file|plist-html|text).">;
+  HelpText<"Static analyzer report output format (html|plist|plist-multi-file|plist-html|sarif|text).">;
 def _analyze : Flag<["--"], "analyze">, Flags<[DriverOption, CoreOption]>,
   HelpText<"Run the static analyzer">;
 def _assemble : Flag<["--"], "assemble">, Alias;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 46ac6a4 - [analyzer] Update help text to reflect sarif support

2020-01-07 Thread Gabor Horvath via cfe-commits

Author: Gabor Horvath
Date: 2020-01-07T08:37:49-08:00
New Revision: 46ac6a4dcd9b629188b75fafbe04008c24d1fb55

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

LOG: [analyzer] Update help text to reflect sarif support

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e48817931efd..33b331fd8777 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2862,7 +2862,7 @@ def _CLASSPATH : Separate<["--"], "CLASSPATH">, 
Alias;
 def _all_warnings : Flag<["--"], "all-warnings">, Alias;
 def _analyzer_no_default_checks : Flag<["--"], "analyzer-no-default-checks">, 
Flags<[DriverOption]>;
 def _analyzer_output : JoinedOrSeparate<["--"], "analyzer-output">, 
Flags<[DriverOption]>,
-  HelpText<"Static analyzer report output format 
(html|plist|plist-multi-file|plist-html|text).">;
+  HelpText<"Static analyzer report output format 
(html|plist|plist-multi-file|plist-html|sarif|text).">;
 def _analyze : Flag<["--"], "analyze">, Flags<[DriverOption, CoreOption]>,
   HelpText<"Run the static analyzer">;
 def _assemble : Flag<["--"], "assemble">, Alias;



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


[PATCH] D72284: [clang-tidy] Factor out renaming logic from readability-identifier-naming

2020-01-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp:272
+  if (const auto *Typedef =
+  Value->getReturnType().getTypePtr()->getAs()) {
+addUsage(NamingCheckFailures, Typedef->getDecl(),

JonasToth wrote:
> aaron.ballman wrote:
> > logan-5 wrote:
> > > Eugene.Zelenko wrote:
> > > > Please elide braces.
> > > Would you mind pointing me toward a resource for these formatting nits? I 
> > > don't see anything about requiring omitting braces for single-statement 
> > > if()s in the official LLVM coding standards (and I happen to think the 
> > > braces actually help readability here). If this stuff is explicitly 
> > > documented somewhere and painstakingly enforced like this, I'd rather get 
> > > it right the first time.
> > I looked through the coding standard and it does not suggest this, which I 
> > am really surprised to see (I feel like the standard used to say it at some 
> > point, but it likely got removed and I did not notice). This is a common 
> > pattern that's used all over the code base (likely from fairly consistent 
> > review guidance over the years), and so it's best to be consistent with the 
> > style used locally, but that's a pretty weak argument for new code.
> Did it maybe get dropped? Wasn't there are overhaul a few weeks ago? But I am 
> surprised as well, as this was at one point explicitly stated.
I went as far back as the 4.0 coding standards and it wasn't listed in there, 
but I'm with you on remembering this being explicitly stated somewhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72284



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


[PATCH] D68578: [HIP] Fix device stub name

2020-01-07 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

ping


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

https://reviews.llvm.org/D68578



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


[PATCH] D72217: [clang-tidy] Added readability-qualified-auto check

2020-01-07 Thread Nathan James via Phabricator via cfe-commits
njames93 marked an inline comment as done.
njames93 added a comment.

Would you say this behaviour is better?

  void baz() {
auto MyFunctionPtr = getPtrFunction();
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: 'auto MyFunctionPtr' can be 
declared as 'auto *MyFunctionPtr'
// CHECK-FIXES-NOT: {{^}}  auto *MyFunctionPtr = getPtrFunction();
auto MyFunctionVal = getValFunction();
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: 'auto MyFunctionVal' can be 
declared as 'auto *MyFunctionVal'
// CHECK-FIXES-NOT: {{^}}  auto *MyFunctionVal = getValFunction();
  
auto LambdaTest = [] { return 0; };
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: 'auto LambdaTest' can be 
declared as 'auto *LambdaTest'
// CHECK-FIXES-NOT: {{^}}  auto *LambdaTest = [] { return 0; };#
  
auto LambdaTest2 = +[] { return 0; };
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: 'auto LambdaTest2' can be 
declared as 'auto *LambdaTest2'
// CHECK-FIXES-NOT: {{^}}  auto *LambdaTest2 = +[] { return 0; };
  }




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp:183
+
+  auto LambdaTest = [] { return 0; };
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: 'auto LambdaTest' can be 
declared as 'auto *LambdaTest'

JonasToth wrote:
> How does that beatiful code-construct get handled?
> 
> ```
> auto * function_ptr = +[](int) {};
> ```
> The lambda is actually converted to a function pointer through the 
> `+`-operator. Not sure this happens anywhere, but it can happen.
> So the case:
> ```
> auto unnotice_ptr = +[](int) {};
> ```
> should be transformed.
It gets handled the same as retty (*)(params), I should probably make function 
pointers in general not be converted


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

https://reviews.llvm.org/D72217



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


[PATCH] D72233: Add a new AST matcher 'optionally'.

2020-01-07 Thread Rihan Yang via Phabricator via cfe-commits
air20 marked an inline comment as done.
air20 added a comment.

In D72233#1806483 , @aaron.ballman 
wrote:

> Just to make sure I understand the purpose -- the goal here is to optionally 
> match one or more inner matchers without failing even if none of the inner 
> matchers match anything, and this is a different use case than `anyOf()` 
> because that would fail when none of the inner matchers match?


That’s exactly right.

In D72233#1807698 , @aaron.ballman 
wrote:

> LGTM aside from a minor nit. Do you need someone to commit on your behalf?


How do I submit a patch from here?




Comment at: clang/lib/ASTMatchers/Dynamic/Registry.cpp:282
   REGISTER_MATCHER(hasInitStatement);
+  REGISTER_MATCHER(hasInitializer);
   REGISTER_MATCHER(hasKeywordSelector);

aaron.ballman wrote:
> Why did this one move? Please keep the list sorted alphabetically.
I think this wasn’t sorted correctly before.


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

https://reviews.llvm.org/D72233



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


[PATCH] D70764: build: reduce CMake handling for zlib

2020-01-07 Thread Khem Raj via Phabricator via cfe-commits
raj.khem added a comment.

In D70764#1807405 , @smeenai wrote:

> In D70764#1803559 , @raj.khem wrote:
>
> > this is now in master, and I am seeing build failures in cross-building 
> > clang, e.g. when building clang for arm on a x86_64 host. its resorting to 
> > finding, libz from buildhost instead of target sysroot ( using --sysroot) 
> > and failing in link step. e.g.
> >
> > FAILED: bin/llvm-config
> >  ...
> >   -o bin/llvm-config  -Wl,-rpath,"\$ORIGIN/../lib"  
> > lib/libLLVMSupport.a  /usr/lib/libz.so  -lrt  -ldl  -ltinfo  -lm  
> > lib/libLLVMDemangle.a
> >  ...
> >
> > aarch64-yoe-linux-musl/aarch64-yoe-linux-musl-ld: /usr/lib/libz.so: error 
> > adding symbols: file in wrong format
> >  clang-10: error: linker command failed with exit code 1 (use -v to see 
> > invocation)
> >
> > you can see that its adding /usr/lib/libz.so to linker cmdline while cross 
> > linking.
>
>
> Have you set `CMAKE_SYSROOT` appropriately?


That is not the problem. Since in cases of target its finding is properly.
there are multiple pieces where some are being built for native( build host) 
some for target so it thinks its building for
buildhost (native) llvm-config e.g. is one such case. Replacing it with -lz 
fixes it becasue compile environment is providing
right --sysroot for native or cross cases and it always links with correct libs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70764



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


[PATCH] D72066: [clangd] Assert that the testcases in LocateSymbol.All have no diagnostics

2020-01-07 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 236608.
nridge marked an inline comment as done.
nridge added a comment.

Address nits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72066

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

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -253,7 +253,7 @@
   )cpp",
 
   R"cpp(// Function definition via pointer
-int [[foo]](int) {}
+void [[foo]](int) {}
 int main() {
   auto *X = &^foo;
 }
@@ -270,7 +270,7 @@
 struct Foo { int [[x]]; };
 int main() {
   Foo bar;
-  bar.^x;
+  (void)bar.^x;
 }
   )cpp",
 
@@ -281,13 +281,6 @@
 };
   )cpp",
 
-  R"cpp(// Field, GNU old-style field designator
-struct Foo { int [[x]]; };
-int main() {
-  Foo bar = { ^x : 1 };
-}
-  )cpp",
-
   R"cpp(// Field, field designator
 struct Foo { int [[x]]; };
 int main() {
@@ -322,19 +315,11 @@
 
   R"cpp(// Namespace
 namespace $decl[[ns]] {
-struct Foo { static void bar(); }
+struct Foo { static void bar(); };
 } // namespace ns
 int main() { ^ns::Foo::bar(); }
   )cpp",
 
-  R"cpp(// Macro
-#define MACRO 0
-#define [[MACRO]] 1
-int main() { return ^MACRO; }
-#define MACRO 2
-#undef macro
-  )cpp",
-
   R"cpp(// Macro
class TTT { public: int a; };
#define [[FF]](S) if (int b = S.a) {}
@@ -352,7 +337,7 @@
 
   R"cpp(// Symbol concatenated inside macro (not supported)
int *pi;
-   #define POINTER(X) p # X;
+   #define POINTER(X) p ## X;
int i = *POINTER(^i);
   )cpp",
 
@@ -433,10 +418,10 @@
   )cpp",
 
   R"cpp(// No implicit constructors
-class X {
+struct X {
   X(X&& x) = default;
 };
-X [[makeX]]() {}
+X $decl[[makeX]]();
 void foo() {
   auto x = m^akeX();
 }
@@ -444,7 +429,7 @@
 
   R"cpp(
 struct X {
-  X& [[operator]]++() {}
+  X& $decl[[operator]]++();
 };
 void foo(X& x) {
   +^+x;
@@ -529,6 +514,61 @@
 // parsing.
 TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
 
+auto AST = TU.build();
+for (auto &D : AST.getDiagnostics())
+  ADD_FAILURE() << D;
+ASSERT_TRUE(AST.getDiagnostics().empty()) << Test;
+
+auto Results = locateSymbolAt(AST, T.point());
+
+if (!WantDecl) {
+  EXPECT_THAT(Results, IsEmpty()) << Test;
+} else {
+  ASSERT_THAT(Results, ::testing::SizeIs(1)) << Test;
+  EXPECT_EQ(Results[0].PreferredDeclaration.range, *WantDecl) << Test;
+  llvm::Optional GotDef;
+  if (Results[0].Definition)
+GotDef = Results[0].Definition->range;
+  EXPECT_EQ(WantDef, GotDef) << Test;
+}
+  }
+}
+
+// LocateSymbol test cases that produce warnings.
+// These are separated out from All so that in All we can assert
+// that there are no diagnostics.
+TEST(LocateSymbol, Warnings) {
+  const char *Tests[] = {
+  R"cpp(// Field, GNU old-style field designator
+struct Foo { int [[x]]; };
+int main() {
+  Foo bar = { ^x : 1 };
+}
+  )cpp",
+
+  R"cpp(// Macro
+#define MACRO 0
+#define [[MACRO]] 1
+int main() { return ^MACRO; }
+#define MACRO 2
+#undef macro
+  )cpp",
+  };
+
+  for (const char *Test : Tests) {
+Annotations T(Test);
+llvm::Optional WantDecl;
+llvm::Optional WantDef;
+if (!T.ranges().empty())
+  WantDecl = WantDef = T.range();
+if (!T.ranges("decl").empty())
+  WantDecl = T.range("decl");
+if (!T.ranges("def").empty())
+  WantDef = T.range("def");
+
+TestTU TU;
+TU.Code = T.code();
+
 auto AST = TU.build();
 auto Results = locateSymbolAt(AST, T.point());
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72282: [clang-tidy] Add `bugprone-unintended-adl`

2020-01-07 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/UnintendedADLCheck.cpp:43
+  Whitelist(
+  utils::options::parseStringList(Options.get("Whitelist", "swap"))) {}
+

logan-5 wrote:
> JonasToth wrote:
> > do you mean `std::swap`? If you it should be fully qualified.
> > Doesn't `std::error_code` rely on adl, too? I think `std::cout <<` and 
> > other streams of the STL rely on it too, and probably many more 
> > code-constructs that are commonly used.
> > 
> > That means, the list should be extended to at least all standard-library 
> > facilities that basically required ADL to work. And then we need data on 
> > different code bases (e.g. LLVM is a good start) how much noise gets 
> > generated.
> I distinctly //don't// mean `std::swap` -- I want to whitelist any 
> unqualified function call spelled simply `swap`.
> 
> Overloaded operators are the poster child for ADL's usefulness, so that's why 
> this check has a special default-on `IgnoreOverloadedOperators` option. That 
> whitelists a whole ton of legitimate stuff including `std::cout << x` and 
> friends.
> 
> I don't see a ton of discussion online about `error_code`/`make_error_code` 
> and ADL being very much intertwined. I'm not particularly familiar with those 
> constructs myself though, and I could just be out of the loop. I do see a 
> fair number of unqualified calls to `make_error_code` within LLVM, though 
> most of those resolve to `llvm::make_error_code`, the documentation for which 
> says it exists because `std::make_error_code` can't be reliably/portably used 
> with ADL. That makes me think `make_error_code` would belong in LLVM's 
> project-specific whitelist configuration, not the check's default.
> 
> Speaking of which, I did run this check over LLVM while developing and found 
> it not particularly noisy as written. That is, it generated a fair number of 
> warnings, but only on constructs that, when examined closely, //were// a 
> little suspicious or non-obvious.
I don't have a solid understanding of the `error_code` world as well. All I 
know is, that you specialize some templates with your own types in order to use 
the generic `error_code`-world.
AFAIK that needs some form of ADL at some point, but that could even happen 
through the overloaded operators (`==` and `!=`), in which case that would 
already be handled. (maybe @aaron.ballman knows more?)

But overloaded operators being ignored by default is good and that point is 
gone :)



Comment at: clang-tools-extra/clang-tidy/bugprone/UnintendedADLCheck.cpp:83
+Call = Result.Nodes.getNodeAs("templateADLcall");
+assert(Call);
+

please add a message to the assertion to describe why you are asserting this 
condition, to better understand the cause of the error, e.g. `assert(Call && 
"Matcher should only match for two distinct cases");` or something like this.



Comment at: clang-tools-extra/clang-tidy/bugprone/UnintendedADLCheck.cpp:89
+
+const auto *Lookup =
+Result.Nodes.getNodeAs("templateADLexpr");

Can't you just bind directly to the `unresolvedExpr`?



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-unintended-adl.cpp:1
+// RUN: %check_clang_tidy -std=c++14-or-later %s bugprone-unintended-adl %t
+

why 14 or later? `ADL` exists in the prior standards, too.

Additionally we need a test for where overloaded operators are not ignored and 
create the warnings.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-unintended-adl.cpp:29
+  ops::stream << 5;
+  operator<<(ops::stream, 5);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: expression calls 
'ops::operator<<' through ADL [bugprone-unintended-adl]

Templated overloaded operators should be tested, too, e.g.:
```
template 
OStream &operator>>(IStream& is, MyClass foo);
```



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-unintended-adl.cpp:60
+template 
+void templateFunction(T t) {
+  swap(t, t);

This function is not instantiated right now, is it?
Can you please write a function that would resolve to ADL for one instantiation 
and wouldn't for another one?
That should create multiple diagnostics for the same source-location and would 
be confusing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72282



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


[clang-tools-extra] 751d4da - [clangd] Assert that the testcases in LocateSymbol.All have no diagnostics

2020-01-07 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2020-01-07T12:13:32-05:00
New Revision: 751d4dae3284c466481ed20ec0b76e894527d2c6

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

LOG: [clangd] Assert that the testcases in LocateSymbol.All have no diagnostics

Summary: Also fix some bugs in the testcases which this exposed.

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, 
cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/XRefsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index a08d117fc2f8..a37b80a99c43 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -253,7 +253,7 @@ TEST(LocateSymbol, All) {
   )cpp",
 
   R"cpp(// Function definition via pointer
-int [[foo]](int) {}
+void [[foo]](int) {}
 int main() {
   auto *X = &^foo;
 }
@@ -270,7 +270,7 @@ TEST(LocateSymbol, All) {
 struct Foo { int [[x]]; };
 int main() {
   Foo bar;
-  bar.^x;
+  (void)bar.^x;
 }
   )cpp",
 
@@ -281,13 +281,6 @@ TEST(LocateSymbol, All) {
 };
   )cpp",
 
-  R"cpp(// Field, GNU old-style field designator
-struct Foo { int [[x]]; };
-int main() {
-  Foo bar = { ^x : 1 };
-}
-  )cpp",
-
   R"cpp(// Field, field designator
 struct Foo { int [[x]]; };
 int main() {
@@ -322,19 +315,11 @@ TEST(LocateSymbol, All) {
 
   R"cpp(// Namespace
 namespace $decl[[ns]] {
-struct Foo { static void bar(); }
+struct Foo { static void bar(); };
 } // namespace ns
 int main() { ^ns::Foo::bar(); }
   )cpp",
 
-  R"cpp(// Macro
-#define MACRO 0
-#define [[MACRO]] 1
-int main() { return ^MACRO; }
-#define MACRO 2
-#undef macro
-  )cpp",
-
   R"cpp(// Macro
class TTT { public: int a; };
#define [[FF]](S) if (int b = S.a) {}
@@ -352,7 +337,7 @@ TEST(LocateSymbol, All) {
 
   R"cpp(// Symbol concatenated inside macro (not supported)
int *pi;
-   #define POINTER(X) p # X;
+   #define POINTER(X) p ## X;
int i = *POINTER(^i);
   )cpp",
 
@@ -433,10 +418,10 @@ TEST(LocateSymbol, All) {
   )cpp",
 
   R"cpp(// No implicit constructors
-class X {
+struct X {
   X(X&& x) = default;
 };
-X [[makeX]]() {}
+X $decl[[makeX]]();
 void foo() {
   auto x = m^akeX();
 }
@@ -444,7 +429,7 @@ TEST(LocateSymbol, All) {
 
   R"cpp(
 struct X {
-  X& [[operator]]++() {}
+  X& $decl[[operator]]++();
 };
 void foo(X& x) {
   +^+x;
@@ -529,6 +514,61 @@ TEST(LocateSymbol, All) {
 // parsing.
 TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
 
+auto AST = TU.build();
+for (auto &D : AST.getDiagnostics())
+  ADD_FAILURE() << D;
+ASSERT_TRUE(AST.getDiagnostics().empty()) << Test;
+
+auto Results = locateSymbolAt(AST, T.point());
+
+if (!WantDecl) {
+  EXPECT_THAT(Results, IsEmpty()) << Test;
+} else {
+  ASSERT_THAT(Results, ::testing::SizeIs(1)) << Test;
+  EXPECT_EQ(Results[0].PreferredDeclaration.range, *WantDecl) << Test;
+  llvm::Optional GotDef;
+  if (Results[0].Definition)
+GotDef = Results[0].Definition->range;
+  EXPECT_EQ(WantDef, GotDef) << Test;
+}
+  }
+}
+
+// LocateSymbol test cases that produce warnings.
+// These are separated out from All so that in All we can assert
+// that there are no diagnostics.
+TEST(LocateSymbol, Warnings) {
+  const char *Tests[] = {
+  R"cpp(// Field, GNU old-style field designator
+struct Foo { int [[x]]; };
+int main() {
+  Foo bar = { ^x : 1 };
+}
+  )cpp",
+
+  R"cpp(// Macro
+#define MACRO 0
+#define [[MACRO]] 1
+int main() { return ^MACRO; }
+#define MACRO 2
+#undef macro
+  )cpp",
+  };
+
+  for (const char *Test : Tests) {
+Annotations T(Test);
+llvm::Optional WantDecl;
+llvm::Optional WantDef;
+if (!T.ranges().empty())
+  WantDecl = WantDef = T.range();
+if (!T.ranges("decl").empty())
+  WantDecl = T.range("decl");
+if (!T.ranges("def").empty())
+  WantDef = T.range("def");
+
+TestTU TU;
+TU.Code = T.code();
+
 auto AST = TU.build();
 auto Results = locateSymbolAt(AST, T.point());
 



___
cfe-commits mailing list
cfe-commits@lists.

[PATCH] D72066: [clangd] Assert that the testcases in LocateSymbol.All have no diagnostics

2020-01-07 Thread Nathan Ridge via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG751d4dae3284: [clangd] Assert that the testcases in 
LocateSymbol.All have no diagnostics (authored by nridge).

Changed prior to commit:
  https://reviews.llvm.org/D72066?vs=236608&id=236612#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72066

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

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -253,7 +253,7 @@
   )cpp",
 
   R"cpp(// Function definition via pointer
-int [[foo]](int) {}
+void [[foo]](int) {}
 int main() {
   auto *X = &^foo;
 }
@@ -270,7 +270,7 @@
 struct Foo { int [[x]]; };
 int main() {
   Foo bar;
-  bar.^x;
+  (void)bar.^x;
 }
   )cpp",
 
@@ -281,13 +281,6 @@
 };
   )cpp",
 
-  R"cpp(// Field, GNU old-style field designator
-struct Foo { int [[x]]; };
-int main() {
-  Foo bar = { ^x : 1 };
-}
-  )cpp",
-
   R"cpp(// Field, field designator
 struct Foo { int [[x]]; };
 int main() {
@@ -322,20 +315,12 @@
 
   R"cpp(// Namespace
 namespace $decl[[ns]] {
-struct Foo { static void bar(); }
+struct Foo { static void bar(); };
 } // namespace ns
 int main() { ^ns::Foo::bar(); }
   )cpp",
 
   R"cpp(// Macro
-#define MACRO 0
-#define [[MACRO]] 1
-int main() { return ^MACRO; }
-#define MACRO 2
-#undef macro
-  )cpp",
-
-  R"cpp(// Macro
class TTT { public: int a; };
#define [[FF]](S) if (int b = S.a) {}
void f() {
@@ -352,7 +337,7 @@
 
   R"cpp(// Symbol concatenated inside macro (not supported)
int *pi;
-   #define POINTER(X) p # X;
+   #define POINTER(X) p ## X;
int i = *POINTER(^i);
   )cpp",
 
@@ -433,10 +418,10 @@
   )cpp",
 
   R"cpp(// No implicit constructors
-class X {
+struct X {
   X(X&& x) = default;
 };
-X [[makeX]]() {}
+X $decl[[makeX]]();
 void foo() {
   auto x = m^akeX();
 }
@@ -444,7 +429,7 @@
 
   R"cpp(
 struct X {
-  X& [[operator]]++() {}
+  X& $decl[[operator]]++();
 };
 void foo(X& x) {
   +^+x;
@@ -530,6 +515,61 @@
 TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
 
 auto AST = TU.build();
+for (auto &D : AST.getDiagnostics())
+  ADD_FAILURE() << D;
+ASSERT_TRUE(AST.getDiagnostics().empty()) << Test;
+
+auto Results = locateSymbolAt(AST, T.point());
+
+if (!WantDecl) {
+  EXPECT_THAT(Results, IsEmpty()) << Test;
+} else {
+  ASSERT_THAT(Results, ::testing::SizeIs(1)) << Test;
+  EXPECT_EQ(Results[0].PreferredDeclaration.range, *WantDecl) << Test;
+  llvm::Optional GotDef;
+  if (Results[0].Definition)
+GotDef = Results[0].Definition->range;
+  EXPECT_EQ(WantDef, GotDef) << Test;
+}
+  }
+}
+
+// LocateSymbol test cases that produce warnings.
+// These are separated out from All so that in All we can assert
+// that there are no diagnostics.
+TEST(LocateSymbol, Warnings) {
+  const char *Tests[] = {
+  R"cpp(// Field, GNU old-style field designator
+struct Foo { int [[x]]; };
+int main() {
+  Foo bar = { ^x : 1 };
+}
+  )cpp",
+
+  R"cpp(// Macro
+#define MACRO 0
+#define [[MACRO]] 1
+int main() { return ^MACRO; }
+#define MACRO 2
+#undef macro
+  )cpp",
+  };
+
+  for (const char *Test : Tests) {
+Annotations T(Test);
+llvm::Optional WantDecl;
+llvm::Optional WantDef;
+if (!T.ranges().empty())
+  WantDecl = WantDef = T.range();
+if (!T.ranges("decl").empty())
+  WantDecl = T.range("decl");
+if (!T.ranges("def").empty())
+  WantDef = T.range("def");
+
+TestTU TU;
+TU.Code = T.code();
+
+auto AST = TU.build();
 auto Results = locateSymbolAt(AST, T.point());
 
 if (!WantDecl) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72333: [clang-tidy] Disable match on `if constexpr` statements in template instantiation for `readability-misleading-indentation` check.

2020-01-07 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp:172
+void call() {
+  mustPass();
+  mustPass();

please add an case that does not get instantiated, with both bad and good 
indentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72333



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


[PATCH] D72066: [clangd] Assert that the testcases in LocateSymbol.All have no diagnostics

2020-01-07 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61301 tests passed, 0 failed 
and 736 were skipped.

{icon check-circle color=green} clang-tidy: pass.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72066



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


[PATCH] D72114: [MS] Overhaul how clang passes overaligned args on x86_32

2020-01-07 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/test/CodeGen/x86_32-arguments-win32.c:77
+// CHECK-LABEL: define dso_local void @receive_vec_256(<8 x float> inreg %x, 
<8 x float> inreg %y, <8 x float> inreg %z, <8 x float>* %0, <8 x float>* %1)
+// CHECK-LABEL: define dso_local void @receive_vec_512(<16 x float> inreg %x, 
<16 x float> inreg %y, <16 x float> inreg %z, <16 x float>* %0, <16 x float>* 
%1)
+// CHECK-LABEL: define dso_local void @receive_vec_1024(<32 x float>* %0, <32 
x float>* %1, <32 x float>* %2, <32 x float>* %3, <32 x float>* %4)

AntonYudintsev wrote:
> rjmccall wrote:
> > AntonYudintsev wrote:
> > > rjmccall wrote:
> > > > rnk wrote:
> > > > > rjmccall wrote:
> > > > > > rnk wrote:
> > > > > > > craig.topper wrote:
> > > > > > > > What happens in the backend with inreg if 512-bit vectors 
> > > > > > > > aren't legal?
> > > > > > > LLVM splits the vector up using the largest legal vector size. As 
> > > > > > > many pieces as possible are passed in available XMM/YMM 
> > > > > > > registers, and the rest are passed in memory. MSVC, of course, 
> > > > > > > assumes the user wanted the larger vector size, and uses whatever 
> > > > > > > vector instructions it needs to move the arguments around.
> > > > > > > 
> > > > > > > Previously, I advocated for a model where calling an Intel 
> > > > > > > intrinsic function had the effect of implicitly marking the 
> > > > > > > caller with the target attributes of the intrinsic. This falls 
> > > > > > > down if the user tries to write a single function that 
> > > > > > > conditionally branches between code that uses different 
> > > > > > > instruction set extensions. You can imagine the SSE2 codepath 
> > > > > > > accidentally using AVX instructions because the compiler thinks 
> > > > > > > they are better. I'm told that ICC models CPU micro-architectural 
> > > > > > > features in the CFG, but I don't ever expect that LLVM will do 
> > > > > > > that. If we're stuck with per-function CPU feature settings, it 
> > > > > > > seems like it would be nice to try to do what the user asked by 
> > > > > > > default, and warn the user if we see them doing a cpuid check in 
> > > > > > > a function that has been implicitly blessed with some target 
> > > > > > > attributes. You could imagine doing a similar thing when large 
> > > > > > > vector type variables are used: if a large vector argument or 
> > > > > > > local is used, implicitly enable the appropriate target features 
> > > > > > > to move vectors of that size around.
> > > > > > > 
> > > > > > > This idea didn't get anywhere, and the current situation has 
> > > > > > > persisted.
> > > > > > > 
> > > > > > > ---
> > > > > > > 
> > > > > > > You know, maybe we should just keep clang the way it is, and just 
> > > > > > > set up a warning in the backend that says "hey, I split your 
> > > > > > > large vector. You probably didn't want that." And then we just 
> > > > > > > continue doing what we do now. Nobody likes backend warnings, but 
> > > > > > > it seems better than the current direction of the frontend 
> > > > > > > knowing every detail of x86 vector extensions.
> > > > > > If target attributes affect ABI, it seems really dangerous to 
> > > > > > implicitly set attributes based on what intrinsics are called.
> > > > > > 
> > > > > > The local CPU-testing problem seems similar to the problems with 
> > > > > > local `#pragma STDC FENV_ACCESS` blocks that the constrained-FP 
> > > > > > people are looking into.  They both have a "this operation is 
> > > > > > normally fully optimizable, but we might need to be more careful in 
> > > > > > specific functions" aspect to them.  I wonder if there's a 
> > > > > > reasonable way to unify the approaches, or at least benefit from 
> > > > > > lessons learned.
> > > > > I agree, we wouldn't want intrinsic usage to change ABI. But, does 
> > > > > anybody actually want the behavior that LLVM implements today where 
> > > > > large vectors get split across registers and memory? I think most 
> > > > > users who pass a 512 bit vector want it to either be passed in ZMM 
> > > > > registers or fail to compile. Why do we even support passing 1024 bit 
> > > > > vectors? Could we make that an error?
> > > > > 
> > > > > Anyway, major redesigns aside, should clang do something when large 
> > > > > vectors are passed? Maybe we should warn here? Passing by address is 
> > > > > usually the safest way to pass something, so that's an option. 
> > > > > Implementing splitting logic in clang doesn't seem worth it.
> > > > > I agree, we wouldn't want intrinsic usage to change ABI. But, does 
> > > > > anybody actually want the behavior that LLVM implements today where 
> > > > > large vectors get split across registers and memory?
> > > > 
> > > > I take it you're implying that the actual (Windows-only?) platform ABI 
> > > > doesn't say anything about this because other compilers don't allow 
> > > > large vec

[PATCH] D72217: [clang-tidy] Added readability-qualified-auto check

2020-01-07 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 236615.
njames93 added a comment.

adhere to coding guidelines, added check for local volatile qualifiers, 
disregard pointer addition on function pointer types


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

https://reviews.llvm.org/D72217

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
  clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.h
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/readability-qualified-auto.rst
  clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp
@@ -0,0 +1,205 @@
+// RUN: %check_clang_tidy %s readability-qualified-auto %t -- -- -std=c++17
+
+namespace typedefs {
+typedef int *MyPtr;
+typedef int &MyRef;
+typedef const int *CMyPtr;
+typedef const int &CMyRef;
+
+MyPtr getPtr();
+MyRef getRef();
+CMyPtr getCPtr();
+CMyRef getCRef();
+
+void foo() {
+  auto TdNakedPtr = getPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto TdNakedPtr' can be declared as 'auto *TdNakedPtr'
+  // CHECK-FIXES: {{^}}  auto *TdNakedPtr = getPtr();
+  auto &TdNakedRef = getRef();
+  auto TdNakedRefDeref = getRef();
+  auto TdNakedCPtr = getCPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto TdNakedCPtr' can be declared as 'const auto *TdNakedCPtr'
+  // CHECK-FIXES: {{^}}  const auto *TdNakedCPtr = getCPtr();
+  auto &TdNakedCRef = getCRef();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto &TdNakedCRef' can be declared as 'const auto &TdNakedCRef'
+  // CHECK-FIXES: {{^}}  const auto &TdNakedCRef = getCRef();
+  auto TdNakedCRefDeref = getCRef();
+}
+
+}; // namespace typedefs
+
+namespace usings {
+using MyPtr = int *;
+using MyRef = int &;
+using CMyPtr = const int *;
+using CMyRef = const int &;
+
+MyPtr getPtr();
+MyRef getRef();
+CMyPtr getCPtr();
+CMyRef getCRef();
+
+void foo() {
+  auto UNakedPtr = getPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto UNakedPtr' can be declared as 'auto *UNakedPtr'
+  // CHECK-FIXES: {{^}}  auto *UNakedPtr = getPtr();
+  auto &UNakedRef = getRef();
+  auto UNakedRefDeref = getRef();
+  auto UNakedCPtr = getCPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto UNakedCPtr' can be declared as 'const auto *UNakedCPtr'
+  // CHECK-FIXES: {{^}}  const auto *UNakedCPtr = getCPtr();
+  auto &UNakedCRef = getCRef();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto &UNakedCRef' can be declared as 'const auto &UNakedCRef'
+  // CHECK-FIXES: {{^}}  const auto &UNakedCRef = getCRef();
+  auto UNakedCRefDeref = getCRef();
+}
+
+}; // namespace usings
+
+int getInt();
+int *getIntPtr();
+const int *getCIntPtr();
+
+void foo() {
+  // make sure check disregards named types
+  int TypedInt = getInt();
+  int *TypedPtr = getIntPtr();
+  const int *TypedConstPtr = getCIntPtr();
+  int &TypedRef = *getIntPtr();
+  const int &TypedConstRef = *getCIntPtr();
+
+  // make sure check disregards auto types that aren't pointers or references
+  auto AutoInt = getInt();
+
+  auto NakedPtr = getIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto NakedPtr' can be declared as 'auto *NakedPtr'
+  // CHECK-FIXES: {{^}}  auto *NakedPtr = getIntPtr();
+  auto NakedCPtr = getCIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto NakedCPtr' can be declared as 'const auto *NakedCPtr'
+  // CHECK-FIXES: {{^}}  const auto *NakedCPtr = getCIntPtr();
+
+  const auto ConstPtr = getIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'const auto ConstPtr' can be declared as 'auto *const ConstPtr'
+  // CHECK-FIXES: {{^}}  auto *const ConstPtr = getIntPtr();
+  const auto ConstCPtr = getCIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'const auto ConstCPtr' can be declared as 'const auto *const ConstCPtr'
+  // CHECK-FIXES: {{^}}  const auto *const ConstCPtr = getCIntPtr();
+
+
+  volatile auto VolatilePtr = getIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'volatile auto VolatilePtr' can be declared as 'auto *volatile VolatilePtr'
+  // CHECK-FIXES: {{^}}  auto *volatile VolatilePtr = getIntPtr();
+  volatile auto VolatileCPtr = getCIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'volatile auto VolatileCPtr' can be declared as 'const auto *volatile VolatileCPtr'
+  // CHECK-FIXES: {{^}}  const auto *volatile VolatileCPtr = getCIntPtr();
+
+
+  auto *QualPtr = getIntPtr();
+  auto *QualCPtr = getCIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto *QualCPtr' can be declared as 'const auto *QualCPtr'
+  // CHECK-FIXES: {{^}}  const auto *Qual

[PATCH] D72217: [clang-tidy] Added readability-qualified-auto check

2020-01-07 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 236617.
njames93 added a comment.

Added docs for const and volatile qualifiers


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

https://reviews.llvm.org/D72217

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
  clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.h
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/readability-qualified-auto.rst
  clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp
@@ -0,0 +1,205 @@
+// RUN: %check_clang_tidy %s readability-qualified-auto %t -- -- -std=c++17
+
+namespace typedefs {
+typedef int *MyPtr;
+typedef int &MyRef;
+typedef const int *CMyPtr;
+typedef const int &CMyRef;
+
+MyPtr getPtr();
+MyRef getRef();
+CMyPtr getCPtr();
+CMyRef getCRef();
+
+void foo() {
+  auto TdNakedPtr = getPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto TdNakedPtr' can be declared as 'auto *TdNakedPtr'
+  // CHECK-FIXES: {{^}}  auto *TdNakedPtr = getPtr();
+  auto &TdNakedRef = getRef();
+  auto TdNakedRefDeref = getRef();
+  auto TdNakedCPtr = getCPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto TdNakedCPtr' can be declared as 'const auto *TdNakedCPtr'
+  // CHECK-FIXES: {{^}}  const auto *TdNakedCPtr = getCPtr();
+  auto &TdNakedCRef = getCRef();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto &TdNakedCRef' can be declared as 'const auto &TdNakedCRef'
+  // CHECK-FIXES: {{^}}  const auto &TdNakedCRef = getCRef();
+  auto TdNakedCRefDeref = getCRef();
+}
+
+}; // namespace typedefs
+
+namespace usings {
+using MyPtr = int *;
+using MyRef = int &;
+using CMyPtr = const int *;
+using CMyRef = const int &;
+
+MyPtr getPtr();
+MyRef getRef();
+CMyPtr getCPtr();
+CMyRef getCRef();
+
+void foo() {
+  auto UNakedPtr = getPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto UNakedPtr' can be declared as 'auto *UNakedPtr'
+  // CHECK-FIXES: {{^}}  auto *UNakedPtr = getPtr();
+  auto &UNakedRef = getRef();
+  auto UNakedRefDeref = getRef();
+  auto UNakedCPtr = getCPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto UNakedCPtr' can be declared as 'const auto *UNakedCPtr'
+  // CHECK-FIXES: {{^}}  const auto *UNakedCPtr = getCPtr();
+  auto &UNakedCRef = getCRef();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto &UNakedCRef' can be declared as 'const auto &UNakedCRef'
+  // CHECK-FIXES: {{^}}  const auto &UNakedCRef = getCRef();
+  auto UNakedCRefDeref = getCRef();
+}
+
+}; // namespace usings
+
+int getInt();
+int *getIntPtr();
+const int *getCIntPtr();
+
+void foo() {
+  // make sure check disregards named types
+  int TypedInt = getInt();
+  int *TypedPtr = getIntPtr();
+  const int *TypedConstPtr = getCIntPtr();
+  int &TypedRef = *getIntPtr();
+  const int &TypedConstRef = *getCIntPtr();
+
+  // make sure check disregards auto types that aren't pointers or references
+  auto AutoInt = getInt();
+
+  auto NakedPtr = getIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto NakedPtr' can be declared as 'auto *NakedPtr'
+  // CHECK-FIXES: {{^}}  auto *NakedPtr = getIntPtr();
+  auto NakedCPtr = getCIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto NakedCPtr' can be declared as 'const auto *NakedCPtr'
+  // CHECK-FIXES: {{^}}  const auto *NakedCPtr = getCIntPtr();
+
+  const auto ConstPtr = getIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'const auto ConstPtr' can be declared as 'auto *const ConstPtr'
+  // CHECK-FIXES: {{^}}  auto *const ConstPtr = getIntPtr();
+  const auto ConstCPtr = getCIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'const auto ConstCPtr' can be declared as 'const auto *const ConstCPtr'
+  // CHECK-FIXES: {{^}}  const auto *const ConstCPtr = getCIntPtr();
+
+
+  volatile auto VolatilePtr = getIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'volatile auto VolatilePtr' can be declared as 'auto *volatile VolatilePtr'
+  // CHECK-FIXES: {{^}}  auto *volatile VolatilePtr = getIntPtr();
+  volatile auto VolatileCPtr = getCIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'volatile auto VolatileCPtr' can be declared as 'const auto *volatile VolatileCPtr'
+  // CHECK-FIXES: {{^}}  const auto *volatile VolatileCPtr = getCIntPtr();
+
+
+  auto *QualPtr = getIntPtr();
+  auto *QualCPtr = getCIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto *QualCPtr' can be declared as 'const auto *QualCPtr'
+  // CHECK-FIXES: {{^}}  const auto *QualCPtr = getCIntPtr();
+  auto *const ConstantQualCPtr = getCIntPtr();
+  // CHECK-

[PATCH] D72271: [Clang] Handle target-specific builtins returning aggregates.

2020-01-07 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D72271#1807790 , @simon_tatham 
wrote:

> The current return value of `EmitTargetBuiltinExpr` will be the `llvm::Value 
> *` corresponding to the last of a sequence of store instructions that writes 
> the constructed aggregate into the return value slot. There's no need to 
> actually use that `Value` for anything in this case, but we can still test 
> that it's non-null, to find out whether `EmitTargetBuiltinExpr` has 
> successfully recognized a builtin and generated some code, or whether we have 
> to fall through to the `ErrorUnsupported`.


Ah, yes, good point.




Comment at: clang/lib/CodeGen/CGBuiltin.cpp:4350
+llvm_unreachable("Bad evaluation kind in EmitBuiltinExpr");
+  }
 

I would just structure this as:

```
  // If the result is an aggregate, force ReturnValue to be non-null so that
  // the target-specific emission code can always just emit into it.
  TypeEvaluationKind EvalKind = getEvaluationKind(E->getType());
  if (EvalKind == TEK_Aggregate && ReturnValue.isNull()) { ... }

  // Try to emit a target builtin.
  if (Value *V = EmitTargetBuiltinExpr(BuiltinID, E, ReturnValue)) {
   // Turn the result into the appropriate kind of RValue.
   switch (EvalKind) { ... }
  }
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72271



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


[PATCH] D71406: [clangd] Add xref for macros to FileIndex.

2020-01-07 Thread UTKARSH SAXENA via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 236618.
usaxena95 added a comment.

Added tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71406

Files:
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/FileIndex.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/SymbolCollector.h
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/FileIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/FileIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/FileIndexTests.cpp
@@ -345,6 +345,40 @@
  FileURI("unittest:///test2.cc"))}));
 }
 
+TEST(FileIndexTest, MacroRefs) {
+  Annotations HeaderCode(R"cpp(
+#define $def1[[HEADER_MACRO]](X) (X+1)
+  )cpp");
+  Annotations MainCode(R"cpp(
+  #define $def2[[MAINFILE_MACRO]](X) (X+1)
+  void f() {
+int a = $ref1[[HEADER_MACRO]](2);
+int b = $ref2[[MAINFILE_MACRO]](1);
+  }
+  )cpp");
+
+  FileIndex Index;
+  // Add test.cc
+  TestTU Test;
+  Test.HeaderCode = HeaderCode.code();
+  Test.Code = MainCode.code();
+  Test.Filename = "test.cc";
+  auto AST = Test.build();
+  Index.updateMain(Test.Filename, AST);
+
+  auto HeaderMacro = findSymbol(Test.headerSymbols(), "HEADER_MACRO");
+  EXPECT_THAT(getRefs(Index, HeaderMacro.ID),
+  RefsAre({AllOf(RefRange(MainCode.range("ref1")),
+ FileURI("unittest:///test.cc"))}));
+
+  auto MainFileMacro = findSymbol(Test.headerSymbols(), "MAINFILE_MACRO");
+  EXPECT_THAT(getRefs(Index, MainFileMacro.ID),
+  RefsAre({AllOf(RefRange(MainCode.range("def2")),
+ FileURI("unittest:///test.cc")),
+   AllOf(RefRange(MainCode.range("ref2")),
+ FileURI("unittest:///test.cc"))}));
+}
+
 TEST(FileIndexTest, CollectMacros) {
   FileIndex M;
   update(M, "f", "#define CLANGD 1");
Index: clang-tools-extra/clangd/index/SymbolCollector.h
===
--- clang-tools-extra/clangd/index/SymbolCollector.h
+++ clang-tools-extra/clangd/index/SymbolCollector.h
@@ -9,6 +9,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOL_COLLECTOR_H
 
 #include "CanonicalIncludes.h"
+#include "CollectMacros.h"
 #include "Index.h"
 #include "SymbolOrigin.h"
 #include "clang/AST/ASTContext.h"
@@ -108,6 +109,8 @@
  index::SymbolRoleSet Roles,
  SourceLocation Loc) override;
 
+  void handleMacros(const MainFileMacros &MacroRefsToIndex);
+
   SymbolSlab takeSymbols() { return std::move(Symbols).build(); }
   RefSlab takeRefs() { return std::move(Refs).build(); }
   RelationSlab takeRelations() { return std::move(Relations).build(); }
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -346,6 +346,29 @@
   return true;
 }
 
+void SymbolCollector::handleMacros(const MainFileMacros &MacroRefsToIndex) {
+  assert(PP.get());
+  const auto &SM = PP->getSourceManager();
+  const auto *MainFileEntry = SM.getFileEntryForID(SM.getMainFileID());
+  assert(MainFileEntry);
+
+  const auto MainFileURI = toURI(SM, MainFileEntry->getName(), Opts);
+  // Add macro references.
+  for (const auto &IDToRefs : MacroRefsToIndex.MacroRefs) {
+for (const auto &Range : IDToRefs.second) {
+  Ref R;
+  R.Location.Start.setLine(Range.start.line);
+  R.Location.Start.setColumn(Range.start.character);
+  R.Location.End.setLine(Range.end.line);
+  R.Location.End.setColumn(Range.end.character);
+  R.Location.FileURI = MainFileURI.c_str();
+  // FIXME: Add correct RefKind information to MainFileMacros.
+  R.Kind = RefKind::Reference;
+  Refs.insert(IDToRefs.first, R);
+}
+  }
+}
+
 bool SymbolCollector::handleMacroOccurrence(const IdentifierInfo *Name,
 const MacroInfo *MI,
 index::SymbolRoleSet Roles,
Index: clang-tools-extra/clangd/index/FileIndex.h
===
--- clang-tools-extra/clangd/index/FileIndex.h
+++ clang-tools-extra/clangd/index/FileIndex.h
@@ -140,7 +140,7 @@
 /// Exposed to assist in unit tests.
 SlabTuple indexMainDecls(ParsedAST &AST);
 
-/// Idex declarations from \p AST and macros from \p PP that are declared in
+/// Index declarations from \p AST and macros from \p PP that are declared in
 /// included headers.
 SlabTuple indexHeaderSymbols(ASTContext &AST, std::shared_ptr PP,
  const CanonicalIncludes &Includes);
Index: clang-tools-extra/clangd/index/FileInd

[PATCH] D72217: [clang-tidy] Added readability-qualified-auto check

2020-01-07 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp:183
+
+  auto LambdaTest = [] { return 0; };
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: 'auto LambdaTest' can be 
declared as 'auto *LambdaTest'

njames93 wrote:
> JonasToth wrote:
> > How does that beatiful code-construct get handled?
> > 
> > ```
> > auto * function_ptr = +[](int) {};
> > ```
> > The lambda is actually converted to a function pointer through the 
> > `+`-operator. Not sure this happens anywhere, but it can happen.
> > So the case:
> > ```
> > auto unnotice_ptr = +[](int) {};
> > ```
> > should be transformed.
> It gets handled the same as retty (*)(params), I should probably make 
> function pointers in general not be converted
Ok.
There exist function references, too  `int (&my_reference) (int);` ( i think 
that was the syntax).
They should then follow this as well (+ user-facing documentation).


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

https://reviews.llvm.org/D72217



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


[clang-tools-extra] 16f47cf - [clangd] Heuristically resolve dependent call through smart pointer type

2020-01-07 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2020-01-07T12:52:03-05:00
New Revision: 16f47cf607c7193e888de4c1774c46367a5bedf4

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

LOG: [clangd] Heuristically resolve dependent call through smart pointer type

Summary: Fixes https://github.com/clangd/clangd/issues/227

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, 
cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/FindTarget.cpp 
b/clang-tools-extra/clangd/FindTarget.cpp
index 75ea78c44a4e..fb3001fca94c 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -27,6 +27,7 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/AST/TypeLocVisitor.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
@@ -61,9 +62,14 @@ nodeToString(const ast_type_traits::DynTypedNode &N) {
 // (e.g. an overloaded method in the primary template).
 // This heuristic will give the desired answer in many cases, e.g.
 // for a call to vector::size().
-std::vector
-getMembersReferencedViaDependentName(const Type *T, const DeclarationName 
&Name,
- bool IsNonstaticMember) {
+// The name to look up is provided in the form of a factory that takes
+// an ASTContext, because an ASTContext may be needed to obtain the
+// name (e.g. if it's an operator name), but the caller may not have
+// access to an ASTContext.
+std::vector getMembersReferencedViaDependentName(
+const Type *T,
+llvm::function_ref NameFactory,
+bool IsNonstaticMember) {
   if (!T)
 return {};
   if (auto *ICNT = T->getAs()) {
@@ -80,12 +86,54 @@ getMembersReferencedViaDependentName(const Type *T, const 
DeclarationName &Name,
   if (!RD->hasDefinition())
 return {};
   RD = RD->getDefinition();
+  DeclarationName Name = NameFactory(RD->getASTContext());
   return RD->lookupDependentName(Name, [=](const NamedDecl *D) {
 return IsNonstaticMember ? D->isCXXInstanceMember()
  : !D->isCXXInstanceMember();
   });
 }
 
+// Given the type T of a dependent expression that appears of the LHS of a 
"->",
+// heuristically find a corresponding pointee type in whose scope we could look
+// up the name appearing on the RHS.
+const Type *getPointeeType(const Type *T) {
+  if (!T)
+return nullptr;
+
+  if (T->isPointerType()) {
+return T->getAs()->getPointeeType().getTypePtrOrNull();
+  }
+
+  // Try to handle smart pointer types.
+
+  // Look up operator-> in the primary template. If we find one, it's probably 
a
+  // smart pointer type.
+  auto ArrowOps = getMembersReferencedViaDependentName(
+  T,
+  [](ASTContext &Ctx) {
+return Ctx.DeclarationNames.getCXXOperatorName(OO_Arrow);
+  },
+  /*IsNonStaticMember=*/true);
+  if (ArrowOps.empty())
+return nullptr;
+
+  // Getting the return type of the found operator-> method decl isn't useful,
+  // because we discarded template arguments to perform lookup in the primary
+  // template scope, so the return type would just have the form U* where U is 
a
+  // template parameter type.
+  // Instead, just handle the common case where the smart pointer type has the
+  // form of SmartPtr, and assume X is the pointee type.
+  auto *TST = T->getAs();
+  if (!TST)
+return nullptr;
+  if (TST->getNumArgs() == 0)
+return nullptr;
+  const TemplateArgument &FirstArg = TST->getArg(0);
+  if (FirstArg.getKind() != TemplateArgument::Type)
+return nullptr;
+  return FirstArg.getAsType().getTypePtrOrNull();
+}
+
 // TargetFinder locates the entities that an AST node refers to.
 //
 // Typically this is (possibly) one declaration and (possibly) one type, but
@@ -251,24 +299,18 @@ struct TargetFinder {
   VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
 const Type *BaseType = E->getBaseType().getTypePtrOrNull();
 if (E->isArrow()) {
-  // FIXME: Handle smart pointer types by looking up operator->
-  // in the primary template.
-  if (!BaseType || !BaseType->isPointerType()) {
-return;
-  }
-  BaseType = BaseType->getAs()
- ->getPointeeType()
- .getTypePtrOrNull();
+  BaseType = getPointeeType(BaseType);
 }
-for (const NamedDecl *D :
- getMembersReferencedViaDependentName(BaseType, E->getMember(),
-   

[PATCH] D71644: [clangd] Heuristically resolve dependent call through smart pointer type

2020-01-07 Thread Nathan Ridge via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG16f47cf607c7: [clangd] Heuristically resolve dependent call 
through smart pointer type (authored by nridge).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71644

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -485,9 +485,9 @@
 }
   )cpp",
 
-  R"cpp(// FIXME: Heuristic resolution of dependent method
+  R"cpp(// Heuristic resolution of dependent method
 // invoked via smart pointer
-template  struct S { void foo(); };
+template  struct S { void [[foo]]() {} };
 template  struct unique_ptr {
   T* operator->();
 };
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -27,6 +27,7 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/AST/TypeLocVisitor.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
@@ -61,9 +62,14 @@
 // (e.g. an overloaded method in the primary template).
 // This heuristic will give the desired answer in many cases, e.g.
 // for a call to vector::size().
-std::vector
-getMembersReferencedViaDependentName(const Type *T, const DeclarationName &Name,
- bool IsNonstaticMember) {
+// The name to look up is provided in the form of a factory that takes
+// an ASTContext, because an ASTContext may be needed to obtain the
+// name (e.g. if it's an operator name), but the caller may not have
+// access to an ASTContext.
+std::vector getMembersReferencedViaDependentName(
+const Type *T,
+llvm::function_ref NameFactory,
+bool IsNonstaticMember) {
   if (!T)
 return {};
   if (auto *ICNT = T->getAs()) {
@@ -80,12 +86,54 @@
   if (!RD->hasDefinition())
 return {};
   RD = RD->getDefinition();
+  DeclarationName Name = NameFactory(RD->getASTContext());
   return RD->lookupDependentName(Name, [=](const NamedDecl *D) {
 return IsNonstaticMember ? D->isCXXInstanceMember()
  : !D->isCXXInstanceMember();
   });
 }
 
+// Given the type T of a dependent expression that appears of the LHS of a "->",
+// heuristically find a corresponding pointee type in whose scope we could look
+// up the name appearing on the RHS.
+const Type *getPointeeType(const Type *T) {
+  if (!T)
+return nullptr;
+
+  if (T->isPointerType()) {
+return T->getAs()->getPointeeType().getTypePtrOrNull();
+  }
+
+  // Try to handle smart pointer types.
+
+  // Look up operator-> in the primary template. If we find one, it's probably a
+  // smart pointer type.
+  auto ArrowOps = getMembersReferencedViaDependentName(
+  T,
+  [](ASTContext &Ctx) {
+return Ctx.DeclarationNames.getCXXOperatorName(OO_Arrow);
+  },
+  /*IsNonStaticMember=*/true);
+  if (ArrowOps.empty())
+return nullptr;
+
+  // Getting the return type of the found operator-> method decl isn't useful,
+  // because we discarded template arguments to perform lookup in the primary
+  // template scope, so the return type would just have the form U* where U is a
+  // template parameter type.
+  // Instead, just handle the common case where the smart pointer type has the
+  // form of SmartPtr, and assume X is the pointee type.
+  auto *TST = T->getAs();
+  if (!TST)
+return nullptr;
+  if (TST->getNumArgs() == 0)
+return nullptr;
+  const TemplateArgument &FirstArg = TST->getArg(0);
+  if (FirstArg.getKind() != TemplateArgument::Type)
+return nullptr;
+  return FirstArg.getAsType().getTypePtrOrNull();
+}
+
 // TargetFinder locates the entities that an AST node refers to.
 //
 // Typically this is (possibly) one declaration and (possibly) one type, but
@@ -251,24 +299,18 @@
   VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
 const Type *BaseType = E->getBaseType().getTypePtrOrNull();
 if (E->isArrow()) {
-  // FIXME: Handle smart pointer types by looking up operator->
-  // in the primary template.
-  if (!BaseType || !BaseType->isPointerType()) {
-return;
-  }
-  BaseType = BaseType->getAs()
- ->getPointeeType()
- .getTypePtrOrNull();
+  BaseType = getPointeeType(BaseType);
 }
-for (const NamedDecl *D :
- getMembersReferencedViaDependentName(BaseType, E-

[PATCH] D71644: [clangd] Heuristically resolve dependent call through smart pointer type

2020-01-07 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 236621.
nridge added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71644

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -500,9 +500,9 @@
 }
   )cpp",
 
-  R"cpp(// FIXME: Heuristic resolution of dependent method
+  R"cpp(// Heuristic resolution of dependent method
 // invoked via smart pointer
-template  struct S { void foo(); };
+template  struct S { void [[foo]]() {} };
 template  struct unique_ptr {
   T* operator->();
 };
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -27,6 +27,7 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/AST/TypeLocVisitor.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
@@ -61,9 +62,14 @@
 // (e.g. an overloaded method in the primary template).
 // This heuristic will give the desired answer in many cases, e.g.
 // for a call to vector::size().
-std::vector
-getMembersReferencedViaDependentName(const Type *T, const DeclarationName &Name,
- bool IsNonstaticMember) {
+// The name to look up is provided in the form of a factory that takes
+// an ASTContext, because an ASTContext may be needed to obtain the
+// name (e.g. if it's an operator name), but the caller may not have
+// access to an ASTContext.
+std::vector getMembersReferencedViaDependentName(
+const Type *T,
+llvm::function_ref NameFactory,
+bool IsNonstaticMember) {
   if (!T)
 return {};
   if (auto *ICNT = T->getAs()) {
@@ -80,12 +86,54 @@
   if (!RD->hasDefinition())
 return {};
   RD = RD->getDefinition();
+  DeclarationName Name = NameFactory(RD->getASTContext());
   return RD->lookupDependentName(Name, [=](const NamedDecl *D) {
 return IsNonstaticMember ? D->isCXXInstanceMember()
  : !D->isCXXInstanceMember();
   });
 }
 
+// Given the type T of a dependent expression that appears of the LHS of a "->",
+// heuristically find a corresponding pointee type in whose scope we could look
+// up the name appearing on the RHS.
+const Type *getPointeeType(const Type *T) {
+  if (!T)
+return nullptr;
+
+  if (T->isPointerType()) {
+return T->getAs()->getPointeeType().getTypePtrOrNull();
+  }
+
+  // Try to handle smart pointer types.
+
+  // Look up operator-> in the primary template. If we find one, it's probably a
+  // smart pointer type.
+  auto ArrowOps = getMembersReferencedViaDependentName(
+  T,
+  [](ASTContext &Ctx) {
+return Ctx.DeclarationNames.getCXXOperatorName(OO_Arrow);
+  },
+  /*IsNonStaticMember=*/true);
+  if (ArrowOps.empty())
+return nullptr;
+
+  // Getting the return type of the found operator-> method decl isn't useful,
+  // because we discarded template arguments to perform lookup in the primary
+  // template scope, so the return type would just have the form U* where U is a
+  // template parameter type.
+  // Instead, just handle the common case where the smart pointer type has the
+  // form of SmartPtr, and assume X is the pointee type.
+  auto *TST = T->getAs();
+  if (!TST)
+return nullptr;
+  if (TST->getNumArgs() == 0)
+return nullptr;
+  const TemplateArgument &FirstArg = TST->getArg(0);
+  if (FirstArg.getKind() != TemplateArgument::Type)
+return nullptr;
+  return FirstArg.getAsType().getTypePtrOrNull();
+}
+
 // TargetFinder locates the entities that an AST node refers to.
 //
 // Typically this is (possibly) one declaration and (possibly) one type, but
@@ -251,24 +299,18 @@
   VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
 const Type *BaseType = E->getBaseType().getTypePtrOrNull();
 if (E->isArrow()) {
-  // FIXME: Handle smart pointer types by looking up operator->
-  // in the primary template.
-  if (!BaseType || !BaseType->isPointerType()) {
-return;
-  }
-  BaseType = BaseType->getAs()
- ->getPointeeType()
- .getTypePtrOrNull();
+  BaseType = getPointeeType(BaseType);
 }
-for (const NamedDecl *D :
- getMembersReferencedViaDependentName(BaseType, E->getMember(),
-  /*IsNonstaticMember=*/true)) {
+for

[PATCH] D61634: [clang/llvm] Allow efficient implementation of libc's memory functions in C/C++

2020-01-07 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D61634#1515176 , @tejohnson wrote:

> In D61634#1512020 , @gchatelet wrote:
>
> > AFAIU here is a coarse plan of what needs to happen
>


I've listed below what I believe is the status:

>> 
>> 
>> 1. Add a `no-builtin` clang function attribute that has the same semantic as 
>> the `no-builtin` cmd line argument 
>> 

Done (D68028  committed at bd8791610948).

>> 2. Propagate it to the IR.
>>   - In the light of recent discussions and as @theraven suggested it seems 
>> more appropriate to encode them as individual IR attributes (e.g. 
>> `"no-builtin-memcpy"`, `"no-builtin-sqrt"`, etc..)

Done (also in D68028  committed at 
bd8791610948).
Additionally the -fno-builtin* options were translated to the IR attributes in 
D71193  (committed at 0508c994f0b1 
).

>> 3. Propagate/merge the `no-builtin` IR attribute for LTO by "updating 
>> `AttributeFuncs::areInlineCompatible` and/or 
>> `AttributeFuncs::mergeAttributesForInlining` and adding a new MergeRule in 
>> `include/llvm/IR/Attributes.td` and writing a function like 
>> `adjustCallerStackProbeSize`."
> 
> This one isn't about LTO, but rather the inliner. You could have different 
> functions in the same module even without LTO that have incompatible 
> no-builtin attributes. There isn't any propagation required for LTO.

Not done yet - I can work on this.

> 
> 
>> 4. Get inspiration from `TargetTransformInfo` to get `TargetLibraryInfo` on 
>> a per function basis for all passes and respect the IR attribute.

Done (D67923  was the last patch in the series 
to enable this, committed at 878ab6df033d 
).

I'm not quite sure where D71710  
([instrinsics] Add @llvm.memcpy.inline instrinsics) fits in to the above list.

Anything else missing?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61634



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


[PATCH] D71406: [clangd] Add xref for macros to FileIndex.

2020-01-07 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61298 tests passed, 0 failed 
and 736 were skipped.

{icon times-circle color=red} clang-tidy: fail. Please fix clang-tidy findings 
.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71406



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


[PATCH] D71433: [analyzer] CERT: POS34-C

2020-01-07 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso accepted this revision.
Charusso added a comment.
This revision is now accepted and ready to land.

I have created a `notes.cpp` test-file to test the notes in my checkers, but I 
think this checker is fine without that test file. @NoQ, what do you think?


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

https://reviews.llvm.org/D71433



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


[PATCH] D71572: [ItaniumCXXABI] Make tls wrappers comdat on Windows

2020-01-07 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

Ping @rsmith


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

https://reviews.llvm.org/D71572



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


[PATCH] D71433: [analyzer] CERT: POS34-C

2020-01-07 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

In D71433#1784238 , @NoQ wrote:

> Currently the check may warn on non-bugs of the following kind:
>
>   void foo() {
> char env[] = "NAME=value";
> putenv(env);
> doStuff();
> putenv("NAME=anothervalue");
>   }
>


That could be the next round as a follow-up patch as the next semester starts 
in February after the 10.0.0 release-tag has been set, so both of the patches 
could land in LLVM 11. We have not seen any `putenv()` in the wild yet.


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

https://reviews.llvm.org/D71433



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


[PATCH] D67774: [Mangle] Add flag to asm labels to disable '\01' prefixing

2020-01-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: cfe/trunk/lib/AST/Mangle.cpp:127
+// do not add a "\01" prefix.
+if (!ALA->getIsLiteralLabel() || ALA->getLabel().startswith("llvm.")) {
+  Out << ALA->getLabel();

Sorry to dredge up an old review, but I recently ran into a bug in this area 
and am not certain of how to fix it. What should happen if the asm label is a 
literal which is empty? e.g.,
```
void foo(void) __asm__("");
void foo(void) {}
```
Currently, that seems to get through this code path and stream an empty string 
into the output stream. However, `writeFuncOrVarName()` doesn't check that it 
actually wrote anything into the stream when calling `mangleName()` and returns 
success to the caller. This causes `writeName()` to eventually call 
`llvm::Mangler::getNameWithPrefix()`, which asserts that the passed `StringRef` 
is not an empty string and we crash. The typical LLVM code path seems to treat 
unnamed symbols as being mangled with `__unnamed_N` (where N is replaced), but 
this relies on having a `GlobalValue*` available to get the next mangling ID.

I'm not certain of where to fix the bug. Should the LLVM side be able to accept 
an empty string and try to gin up a `GlobalValue*` to mangle it properly? 
Should the FE side not generate an empty name here? Should empty asm labels be 
rejected at the source level?

Thanks for any insights you can provide!


Repository:
  rL LLVM

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

https://reviews.llvm.org/D67774



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


[PATCH] D71572: [ItaniumCXXABI] Make tls wrappers comdat on Windows

2020-01-07 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:2551
+  // actually handle multiple TUs defining the same wrapper.
+  if (CGM.getTriple().isOSWindows() && CGM.supportsCOMDAT() &&
+  Wrapper->isWeakForLinker())

mstorsjo wrote:
> mstorsjo wrote:
> > rnk wrote:
> > > IMO we should be doing the same thing on ELF, you can see the code 
> > > pattern used elsewhere:
> > > http://llvm-cs.pcc.me.uk/?q=setComdat
> > > 
> > > Before comdats were made explicit in the IR and we stopped implicitly 
> > > making comdat groups for odr things on ELF, these wrappers would've been 
> > > in a comdat group.
> > Ok, so remove the `isOSWindows()` and maybe remove the comment altogether 
> > as it isn't windows specific any longer?
> In the current tests, for linux there's explicit checks that these aren't 
> marked as comdat, see e.g. 
> https://github.com/llvm/llvm-project/blob/master/clang/test/CodeGenCXX/cxx11-thread-local.cpp#L208.
>  Is there a specific reason for that, or should it be changed?
The test is intending to check that the wrapper is not in a comdat keyed off 
the variable. Putting it in a trivial comdat is fine and correct; please update 
the tests to check that it's in the right comdat, not just that it's in some 
comdat. (I seem to regularly forget that `weak` / `linkonce` / `weak_odr` / 
`linkonce_odr` don't actually work as documented any more...)


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

https://reviews.llvm.org/D71572



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


[clang-tools-extra] 75eacbf - Fix issues reported by -Wrange-loop-analysis when building with latest Clang (trunk). NFC.

2020-01-07 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2020-01-07T13:58:26-05:00
New Revision: 75eacbf1a9fbc29432a6e0c5627e6c8e95683956

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

LOG: Fix issues reported by -Wrange-loop-analysis when building with latest 
Clang (trunk). NFC.

Fixes warning: loop variable 'E' of type 'const llvm::StringRef' creates a copy 
from type 'const llvm::StringRef' [-Wrange-loop-analysis]

Added: 


Modified: 
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
clang-tools-extra/clangd/unittests/RenameTests.cpp
llvm/lib/Support/Windows/Program.inc

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp 
b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
index d7100980367d..85b8f436dd05 100644
--- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -56,7 +56,7 @@ MATCHER_P(WithTemplateArgs, ArgName, "") {
   LangOptions LO;
   PrintingPolicy Policy(LO);
   Policy.adjustForCPlusPlus();
-  for (const auto Arg : Args->asArray()) {
+  for (const auto &Arg : Args->asArray()) {
 if (SpecializationArgs.size() > 0)
   SpecializationArgs += ",";
 SpecializationArgs += Arg.getAsType().getAsString(Policy);

diff  --git a/clang-tools-extra/clangd/unittests/RenameTests.cpp 
b/clang-tools-extra/clangd/unittests/RenameTests.cpp
index be491546aca8..6ced22bf3515 100644
--- a/clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ b/clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -404,7 +404,7 @@ TEST(RenameTest, WithinFileRename) {
 template <> struct Bar<[[Foo]]> {};
   )cpp",
   };
-  for (const auto T : Tests) {
+  for (llvm::StringRef T : Tests) {
 Annotations Code(T);
 auto TU = TestTU::withCode(Code.code());
 TU.ExtraArgs.push_back("-fno-delayed-template-parsing");

diff  --git a/llvm/lib/Support/Windows/Program.inc 
b/llvm/lib/Support/Windows/Program.inc
index a23ed95fc390..a1482bf17c60 100644
--- a/llvm/lib/Support/Windows/Program.inc
+++ b/llvm/lib/Support/Windows/Program.inc
@@ -197,7 +197,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program,
 // An environment block consists of a null-terminated block of
 // null-terminated strings. Convert the array of environment variables to
 // an environment block by concatenating them.
-for (const auto E : *Env) {
+for (StringRef E : *Env) {
   SmallVector EnvString;
   if (std::error_code ec = windows::UTF8ToUTF16(E, EnvString)) {
 SetLastError(ec.value());



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


[clang] c972f6f - [OPENMP]Allow using of members in standalone declaration pragmas.

2020-01-07 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-01-07T13:44:10-05:00
New Revision: c972f6fd7919b737f4c991d27249b9a947011c8e

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

LOG: [OPENMP]Allow using of members in standalone declaration pragmas.

If standalone OpenMP declaration pragma, like declare mapper or declare
reduction, is declared in the class context, it may reference a member
(data or function) in its internal expressions/statements. So, the
parsing of such pragmas must be dalayed just like the parsing of the
member initializers/definitions before the completion of the class
declaration.

Added: 


Modified: 
clang/include/clang/Parse/Parser.h
clang/lib/Parse/ParseCXXInlineMethods.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/test/OpenMP/declare_mapper_messages.cpp
clang/test/OpenMP/declare_reduction_codegen.cpp
clang/test/OpenMP/declare_reduction_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 4778dc9d3df8..e7130d2fe68e 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1153,6 +1153,7 @@ class Parser : public CodeCompletionHandler {
 virtual void ParseLexedMemberInitializers();
 virtual void ParseLexedMethodDefs();
 virtual void ParseLexedAttributes();
+virtual void ParseLexedPragmas();
   };
 
   /// Inner node of the LateParsedDeclaration tree that parses
@@ -1166,6 +1167,7 @@ class Parser : public CodeCompletionHandler {
 void ParseLexedMemberInitializers() override;
 void ParseLexedMethodDefs() override;
 void ParseLexedAttributes() override;
+void ParseLexedPragmas() override;
 
   private:
 Parser *Self;
@@ -1195,6 +1197,26 @@ class Parser : public CodeCompletionHandler {
 void addDecl(Decl *D) { Decls.push_back(D); }
   };
 
+  /// Contains the lexed tokens of a pragma with arguments that
+  /// may reference member variables and so need to be parsed at the
+  /// end of the class declaration after parsing all other member
+  /// member declarations.
+  class LateParsedPragma : public LateParsedDeclaration {
+Parser *Self = nullptr;
+AccessSpecifier AS = AS_none;
+CachedTokens Toks;
+
+  public:
+explicit LateParsedPragma(Parser *P, AccessSpecifier AS)
+: Self(P), AS(AS) {}
+
+void takeToks(CachedTokens &Cached) { Toks.swap(Cached); }
+const CachedTokens &toks() const { return Toks; }
+AccessSpecifier getAccessSpecifier() const { return AS; }
+
+void ParseLexedPragmas() override;
+  };
+
   // A list of late-parsed attributes.  Used by ParseGNUAttributes.
   class LateParsedAttrList: public SmallVector {
   public:
@@ -1454,6 +1476,8 @@ class Parser : public CodeCompletionHandler {
   void ParseLexedMemberInitializers(ParsingClass &Class);
   void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
   void ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod);
+  void ParseLexedPragmas(ParsingClass &Class);
+  void ParseLexedPragma(LateParsedPragma &LP);
   bool ConsumeAndStoreFunctionPrologue(CachedTokens &Toks);
   bool ConsumeAndStoreInitializer(CachedTokens &Toks, CachedInitKind CIK);
   bool ConsumeAndStoreConditional(CachedTokens &Toks);
@@ -2875,7 +2899,7 @@ class Parser : public CodeCompletionHandler {
   /// Parses declarative OpenMP directives.
   DeclGroupPtrTy ParseOpenMPDeclarativeDirectiveWithExtDecl(
   AccessSpecifier &AS, ParsedAttributesWithRange &Attrs,
-  DeclSpec::TST TagType = DeclSpec::TST_unspecified,
+  bool Delayed = false, DeclSpec::TST TagType = DeclSpec::TST_unspecified,
   Decl *TagDecl = nullptr);
   /// Parse 'omp declare reduction' construct.
   DeclGroupPtrTy ParseOpenMPDeclareReductionDirective(AccessSpecifier AS);

diff  --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp 
b/clang/lib/Parse/ParseCXXInlineMethods.cpp
index aa314da8e5b4..f8b5fec43800 100644
--- a/clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ b/clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -223,6 +223,7 @@ Parser::LateParsedDeclaration::~LateParsedDeclaration() {}
 void Parser::LateParsedDeclaration::ParseLexedMethodDeclarations() {}
 void Parser::LateParsedDeclaration::ParseLexedMemberInitializers() {}
 void Parser::LateParsedDeclaration::ParseLexedMethodDefs() {}
+void Parser::LateParsedDeclaration::ParseLexedPragmas() {}
 
 Parser::LateParsedClass::LateParsedClass(Parser *P, ParsingClass *C)
   : Self(P), Class(C) {}
@@ -243,6 +244,10 @@ void Parser::LateParsedClass::ParseLexedMethodDefs() {
   Self->ParseLexedMethodDefs(*Class);
 }
 
+void Parser::LateParsedClass::ParseLexedPragmas() {
+  Self->ParseLexedPragmas(*Class);
+}
+
 void Parser::LateParsedMethodDeclaration::ParseLexedMethodDeclarations() {

[PATCH] D72352: [Triple] Use elfv2 on freebsd>=13 and linux-musl

2020-01-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: Bdragon28, dim, adalava.
Herald added subscribers: llvm-commits, cfe-commits, steven.zhang, jsji, 
dexonsmith, kbarton, hiraditya, krytarowski, arichardson, nemanjai, emaste.
Herald added projects: clang, LLVM.

The environments "elfv1" and "elfv2" were added for FreeBSD powerpc64
ELFv1->ELFv2 migration.  FreeBSD developers have decided to use OS
versions to change ABI, and no one is relying on it.

Users can always use -mabi=elfv1 and -mabi=elfv2 to override the default
ABI.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72352

Files:
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ppc-abi.c
  clang/test/Preprocessor/init-ppc64.c
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/Support/Triple.cpp
  llvm/lib/Target/PowerPC/PPCTargetMachine.cpp

Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
===
--- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -215,8 +215,6 @@
   case Triple::ppc64le:
 return PPCTargetMachine::PPC_ABI_ELFv2;
   case Triple::ppc64:
-if (TT.getEnvironment() == llvm::Triple::ELFv2)
-  return PPCTargetMachine::PPC_ABI_ELFv2;
 return PPCTargetMachine::PPC_ABI_ELFv1;
   default:
 return PPCTargetMachine::PPC_ABI_UNKNOWN;
Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -228,8 +228,6 @@
   case CODE16: return "code16";
   case EABI: return "eabi";
   case EABIHF: return "eabihf";
-  case ELFv1: return "elfv1";
-  case ELFv2: return "elfv2";
   case Android: return "android";
   case Musl: return "musl";
   case MuslEABI: return "musleabi";
@@ -524,8 +522,6 @@
   return StringSwitch(EnvironmentName)
 .StartsWith("eabihf", Triple::EABIHF)
 .StartsWith("eabi", Triple::EABI)
-.StartsWith("elfv1", Triple::ELFv1)
-.StartsWith("elfv2", Triple::ELFv2)
 .StartsWith("gnuabin32", Triple::GNUABIN32)
 .StartsWith("gnuabi64", Triple::GNUABI64)
 .StartsWith("gnueabihf", Triple::GNUEABIHF)
Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -203,8 +203,6 @@
 CODE16,
 EABI,
 EABIHF,
-ELFv1,
-ELFv2,
 Android,
 Musl,
 MuslEABI,
Index: clang/test/Preprocessor/init-ppc64.c
===
--- clang/test/Preprocessor/init-ppc64.c
+++ clang/test/Preprocessor/init-ppc64.c
@@ -1056,6 +1056,11 @@
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv2 %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu -target-abi elfv1 < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv1 %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu -target-abi elfv2 < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv2 %s
+
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd12 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv1 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd13 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv2 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-linux-musl -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv2 %s
+
 // PPC64-ELFv1:#define _CALL_ELF 1
 // PPC64-ELFv2:#define _CALL_ELF 2
 //
Index: clang/test/Driver/ppc-abi.c
===
--- clang/test/Driver/ppc-abi.c
+++ clang/test/Driver/ppc-abi.c
@@ -24,6 +24,11 @@
 // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
 // RUN:   -mabi=altivec | FileCheck -check-prefix=CHECK-ELFv2 %s
 
+// RUN: %clang -target powerpc64-unknown-freebsd12 %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv1 %s
+// RUN: %clang -target powerpc64-unknown-freebsd13 %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv2-BE %s
+// RUN: %clang -target powerpc64-unknown-freebsd14 %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv2-BE %s
+// RUN: %clang -target powerpc64-linux-musl %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv2-BE %s
+
 // CHECK-ELFv1: "-mrelocation-model" "pic" "-pic-level" "2"
 // CHECK-ELFv1: "-target-abi" "elfv1"
 // CHECK-ELFv1-LE: "-mrelocation-model" "static"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -1900,7 +1900,9 @@
  ArgStringList &CmdArgs) const {
   // Select the ABI to use.
   const char *A

[PATCH] D72352: [Triple] Use elfv2 on freebsd>=13 and linux-musl

2020-01-07 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.
Herald added a subscriber: wuzish.

{icon question-circle color=gray} Unit tests: unknown.

{icon question-circle color=gray} clang-tidy: unknown.

{icon question-circle color=gray} clang-format: unknown.

Build artifacts 
: 
diff.json 
,
 console-log.txt 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72352



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


[PATCH] D69779: -fmodules-codegen should not emit extern templates

2020-01-07 Thread Luboš Luňák via Phabricator via cfe-commits
llunak added a comment.

In D69779#1801771 , @dblaikie wrote:

> Ah, if I mark the standalone function template 'inline' (the implicit linkage 
> of member functions) then I get the same failure for both. Haven't tested 
> whether the fix is the same fix for both yet.


With my patch there are no errors with your testcase, even with the 'inline' 
added.


Repository:
  rC Clang

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

https://reviews.llvm.org/D69779



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


[PATCH] D72352: [Triple] Use elfv2 on freebsd>=13 and linux-musl

2020-01-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 236640.
MaskRay added a comment.

Simplify


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72352

Files:
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ppc-abi.c
  clang/test/Preprocessor/init-ppc64.c
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/Support/Triple.cpp
  llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
  llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll

Index: llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
===
--- llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
+++ llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
@@ -8,8 +8,6 @@
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd < %s | FileCheck %s -check-prefix=CHECK-ELFv1
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd -target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd -target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd-elfv1  < %s | FileCheck %s -check-prefix=CHECK-ELFv1
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd-elfv2  < %s | FileCheck %s -check-prefix=CHECK-ELFv2
 
 ; CHECK-ELFv2: .abiversion 2
 ; CHECK-ELFv1-NOT: .abiversion 2
Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
===
--- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -215,8 +215,6 @@
   case Triple::ppc64le:
 return PPCTargetMachine::PPC_ABI_ELFv2;
   case Triple::ppc64:
-if (TT.getEnvironment() == llvm::Triple::ELFv2)
-  return PPCTargetMachine::PPC_ABI_ELFv2;
 return PPCTargetMachine::PPC_ABI_ELFv1;
   default:
 return PPCTargetMachine::PPC_ABI_UNKNOWN;
Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -228,8 +228,6 @@
   case CODE16: return "code16";
   case EABI: return "eabi";
   case EABIHF: return "eabihf";
-  case ELFv1: return "elfv1";
-  case ELFv2: return "elfv2";
   case Android: return "android";
   case Musl: return "musl";
   case MuslEABI: return "musleabi";
@@ -524,8 +522,6 @@
   return StringSwitch(EnvironmentName)
 .StartsWith("eabihf", Triple::EABIHF)
 .StartsWith("eabi", Triple::EABI)
-.StartsWith("elfv1", Triple::ELFv1)
-.StartsWith("elfv2", Triple::ELFv2)
 .StartsWith("gnuabin32", Triple::GNUABIN32)
 .StartsWith("gnuabi64", Triple::GNUABI64)
 .StartsWith("gnueabihf", Triple::GNUEABIHF)
Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -203,8 +203,6 @@
 CODE16,
 EABI,
 EABIHF,
-ELFv1,
-ELFv2,
 Android,
 Musl,
 MuslEABI,
Index: clang/test/Preprocessor/init-ppc64.c
===
--- clang/test/Preprocessor/init-ppc64.c
+++ clang/test/Preprocessor/init-ppc64.c
@@ -1056,6 +1056,11 @@
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv2 %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu -target-abi elfv1 < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv1 %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu -target-abi elfv2 < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv2 %s
+
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd12 -target-abi elfv1 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv1 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd13 -target-abi elfv2 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv2 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-linux-musl -target-abi elfv2 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv2 %s
+
 // PPC64-ELFv1:#define _CALL_ELF 1
 // PPC64-ELFv2:#define _CALL_ELF 2
 //
Index: clang/test/Driver/ppc-abi.c
===
--- clang/test/Driver/ppc-abi.c
+++ clang/test/Driver/ppc-abi.c
@@ -24,6 +24,11 @@
 // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
 // RUN:   -mabi=altivec | FileCheck -check-prefix=CHECK-ELFv2 %s
 
+// RUN: %clang -target powerpc64-unknown-freebsd12 %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv1 %s
+// RUN: %clang -target powerpc64-unknown-freebsd13 %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv2-BE %s
+// RUN: %clang -target powerpc64-unknown-freebsd14 %s -### 2>&

[PATCH] D72352: [Triple] Use elfv2 on freebsd>=13 and linux-musl

2020-01-07 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon question-circle color=gray} Unit tests: unknown.

{icon question-circle color=gray} clang-tidy: unknown.

{icon question-circle color=gray} clang-format: unknown.

Build artifacts 
: 
diff.json 
,
 console-log.txt 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72352



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


[PATCH] D72212: [Sema] Improve -Wrange-loop-analysis warnings

2020-01-07 Thread Mark de Wever via Phabricator via cfe-commits
Mordante marked an inline comment as done.
Mordante added a comment.

You're welcome. It would be nice if we can get this one in the release.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72212



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


[PATCH] D72352: [Triple] Use elfv2 on freebsd>=13 and linux-musl

2020-01-07 Thread Alfredo Dal'Ava Júnior via Phabricator via cfe-commits
adalava accepted this revision.
adalava added a comment.
This revision is now accepted and ready to land.

LGTM. Just a comment regarding FreeBSD 11.x.




Comment at: clang/test/Driver/ppc-abi.c:27
 
+// RUN: %clang -target powerpc64-unknown-freebsd12 %s -### 2>&1 | FileCheck 
--check-prefix=CHECK-ELFv1 %s
+// RUN: %clang -target powerpc64-unknown-freebsd13 %s -### 2>&1 | FileCheck 
--check-prefix=CHECK-ELFv2-BE %s

 FreeBSD 11.x (ELFv1) should be supported[1] until 2021. Maybe you would like 
to add a check for it too.

[1]https://www.freebsd.org/security/security.html#sup



Comment at: clang/test/Preprocessor/init-ppc64.c:1060
+
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd12 
-target-abi elfv1 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv1 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd13 
-target-abi elfv2 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv2 %s

same as above


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72352



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


[clang] 4558842 - [OPENMP]Reduce calls for the mangled names.

2020-01-07 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-01-07T14:28:17-05:00
New Revision: 45588428910a7cbcf58317b874dad18b580c9ce5

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

LOG: [OPENMP]Reduce calls for the mangled names.

Use canonical decls instead of mangled names in the set of already
emitted decls. This allows to reduce the number of function calls for
getting declarations mangled names and speedup the compilation.

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntime.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index b71756f2449f..05d29fbadfe8 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -9659,9 +9659,9 @@ bool CGOpenMPRuntime::emitTargetFunctions(GlobalDecl GD) {
   }
 
   const ValueDecl *VD = cast(GD.getDecl());
-  StringRef Name = CGM.getMangledName(GD);
   // Try to detect target regions in the function.
   if (const auto *FD = dyn_cast(VD)) {
+StringRef Name = CGM.getMangledName(GD);
 scanForTargetRegionsFunctions(FD->getBody(), Name);
 Optional DevTy =
 OMPDeclareTargetDeclAttr::getDeviceType(FD);
@@ -9672,7 +9672,7 @@ bool CGOpenMPRuntime::emitTargetFunctions(GlobalDecl GD) {
 
   // Do not to emit function if it is not marked as declare target.
   return !OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD) &&
- AlreadyEmittedTargetFunctions.count(Name) == 0;
+ AlreadyEmittedTargetDecls.count(VD) == 0;
 }
 
 bool CGOpenMPRuntime::emitTargetGlobalVariable(GlobalDecl GD) {
@@ -9903,20 +9903,20 @@ bool CGOpenMPRuntime::markAsGlobalTarget(GlobalDecl GD) 
{
   if (!CGM.getLangOpts().OpenMPIsDevice || !ShouldMarkAsGlobal)
 return true;
 
-  StringRef Name = CGM.getMangledName(GD);
   const auto *D = cast(GD.getDecl());
   // Do not to emit function if it is marked as declare target as it was 
already
   // emitted.
   if (OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(D)) {
-if (D->hasBody() && AlreadyEmittedTargetFunctions.count(Name) == 0) {
-  if (auto *F = dyn_cast_or_null(CGM.GetGlobalValue(Name)))
+if (D->hasBody() && AlreadyEmittedTargetDecls.count(D) == 0) {
+  if (auto *F = dyn_cast_or_null(
+  CGM.GetGlobalValue(CGM.getMangledName(GD
 return !F->isDeclaration();
   return false;
 }
 return true;
   }
 
-  return !AlreadyEmittedTargetFunctions.insert(Name).second;
+  return !AlreadyEmittedTargetDecls.insert(D).second;
 }
 
 llvm::Function *CGOpenMPRuntime::emitRequiresDirectiveRegFun() {

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.h 
b/clang/lib/CodeGen/CGOpenMPRuntime.h
index 4739be8a73b7..c40308ee7497 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.h
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.h
@@ -20,6 +20,7 @@
 #include "clang/Basic/OpenMPKinds.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
@@ -672,8 +673,8 @@ class CGOpenMPRuntime {
   OffloadEntriesInfoManagerTy OffloadEntriesInfoManager;
 
   bool ShouldMarkAsGlobal = true;
-  /// List of the emitted functions.
-  llvm::StringSet<> AlreadyEmittedTargetFunctions;
+  /// List of the emitted declarations.
+  llvm::DenseSet> AlreadyEmittedTargetDecls;
   /// List of the global variables with their addresses that should not be
   /// emitted for the target.
   llvm::StringMap EmittedNonTargetVariables;



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


[clang] fb6e80d - [test] Move ppc64 tests from test/Preprocessor/init.c to init-ppc64.c

2020-01-07 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2020-01-07T11:32:52-08:00
New Revision: fb6e80da446b94d42d484910ea28a82b4900f01f

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

LOG: [test] Move ppc64 tests from test/Preprocessor/init.c to init-ppc64.c

Added: 
clang/test/Preprocessor/init-ppc64.c

Modified: 
clang/test/Preprocessor/init.c

Removed: 




diff  --git a/clang/test/Preprocessor/init-ppc64.c 
b/clang/test/Preprocessor/init-ppc64.c
new file mode 100644
index ..7c3a635cd0a5
--- /dev/null
+++ b/clang/test/Preprocessor/init-ppc64.c
@@ -0,0 +1,1068 @@
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none 
-target-cpu pwr7 -fno-signed-char < /dev/null | FileCheck -match-full-lines 
-check-prefix PPC64 %s
+// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=powerpc64-none-none 
-target-cpu pwr7 -fno-signed-char < /dev/null | FileCheck -match-full-lines 
-check-prefix PPC64 -check-prefix PPC64-CXX %s
+//
+// PPC64:#define _ARCH_PPC 1
+// PPC64:#define _ARCH_PPC64 1
+// PPC64:#define _ARCH_PPCGR 1
+// PPC64:#define _ARCH_PPCSQ 1
+// PPC64:#define _ARCH_PWR4 1
+// PPC64:#define _ARCH_PWR5 1
+// PPC64:#define _ARCH_PWR6 1
+// PPC64:#define _ARCH_PWR7 1
+// PPC64:#define _BIG_ENDIAN 1
+// PPC64:#define _LP64 1
+// PPC64:#define __BIGGEST_ALIGNMENT__ 16
+// PPC64:#define __BIG_ENDIAN__ 1
+// PPC64:#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
+// PPC64:#define __CHAR16_TYPE__ unsigned short
+// PPC64:#define __CHAR32_TYPE__ unsigned int
+// PPC64:#define __CHAR_BIT__ 8
+// PPC64:#define __CHAR_UNSIGNED__ 1
+// PPC64:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324
+// PPC64:#define __DBL_DIG__ 15
+// PPC64:#define __DBL_EPSILON__ 2.2204460492503131e-16
+// PPC64:#define __DBL_HAS_DENORM__ 1
+// PPC64:#define __DBL_HAS_INFINITY__ 1
+// PPC64:#define __DBL_HAS_QUIET_NAN__ 1
+// PPC64:#define __DBL_MANT_DIG__ 53
+// PPC64:#define __DBL_MAX_10_EXP__ 308
+// PPC64:#define __DBL_MAX_EXP__ 1024
+// PPC64:#define __DBL_MAX__ 1.7976931348623157e+308
+// PPC64:#define __DBL_MIN_10_EXP__ (-307)
+// PPC64:#define __DBL_MIN_EXP__ (-1021)
+// PPC64:#define __DBL_MIN__ 2.2250738585072014e-308
+// PPC64:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__
+// PPC64:#define __FLT_DENORM_MIN__ 1.40129846e-45F
+// PPC64:#define __FLT_DIG__ 6
+// PPC64:#define __FLT_EPSILON__ 1.19209290e-7F
+// PPC64:#define __FLT_EVAL_METHOD__ 0
+// PPC64:#define __FLT_HAS_DENORM__ 1
+// PPC64:#define __FLT_HAS_INFINITY__ 1
+// PPC64:#define __FLT_HAS_QUIET_NAN__ 1
+// PPC64:#define __FLT_MANT_DIG__ 24
+// PPC64:#define __FLT_MAX_10_EXP__ 38
+// PPC64:#define __FLT_MAX_EXP__ 128
+// PPC64:#define __FLT_MAX__ 3.40282347e+38F
+// PPC64:#define __FLT_MIN_10_EXP__ (-37)
+// PPC64:#define __FLT_MIN_EXP__ (-125)
+// PPC64:#define __FLT_MIN__ 1.17549435e-38F
+// PPC64:#define __FLT_RADIX__ 2
+// PPC64:#define __HAVE_BSWAP__ 1
+// PPC64:#define __INT16_C_SUFFIX__
+// PPC64:#define __INT16_FMTd__ "hd"
+// PPC64:#define __INT16_FMTi__ "hi"
+// PPC64:#define __INT16_MAX__ 32767
+// PPC64:#define __INT16_TYPE__ short
+// PPC64:#define __INT32_C_SUFFIX__
+// PPC64:#define __INT32_FMTd__ "d"
+// PPC64:#define __INT32_FMTi__ "i"
+// PPC64:#define __INT32_MAX__ 2147483647
+// PPC64:#define __INT32_TYPE__ int
+// PPC64:#define __INT64_C_SUFFIX__ L
+// PPC64:#define __INT64_FMTd__ "ld"
+// PPC64:#define __INT64_FMTi__ "li"
+// PPC64:#define __INT64_MAX__ 9223372036854775807L
+// PPC64:#define __INT64_TYPE__ long int
+// PPC64:#define __INT8_C_SUFFIX__
+// PPC64:#define __INT8_FMTd__ "hhd"
+// PPC64:#define __INT8_FMTi__ "hhi"
+// PPC64:#define __INT8_MAX__ 127
+// PPC64:#define __INT8_TYPE__ signed char
+// PPC64:#define __INTMAX_C_SUFFIX__ L
+// PPC64:#define __INTMAX_FMTd__ "ld"
+// PPC64:#define __INTMAX_FMTi__ "li"
+// PPC64:#define __INTMAX_MAX__ 9223372036854775807L
+// PPC64:#define __INTMAX_TYPE__ long int
+// PPC64:#define __INTMAX_WIDTH__ 64
+// PPC64:#define __INTPTR_FMTd__ "ld"
+// PPC64:#define __INTPTR_FMTi__ "li"
+// PPC64:#define __INTPTR_MAX__ 9223372036854775807L
+// PPC64:#define __INTPTR_TYPE__ long int
+// PPC64:#define __INTPTR_WIDTH__ 64
+// PPC64:#define __INT_FAST16_FMTd__ "hd"
+// PPC64:#define __INT_FAST16_FMTi__ "hi"
+// PPC64:#define __INT_FAST16_MAX__ 32767
+// PPC64:#define __INT_FAST16_TYPE__ short
+// PPC64:#define __INT_FAST32_FMTd__ "d"
+// PPC64:#define __INT_FAST32_FMTi__ "i"
+// PPC64:#define __INT_FAST32_MAX__ 2147483647
+// PPC64:#define __INT_FAST32_TYPE__ int
+// PPC64:#define __INT_FAST64_FMTd__ "ld"
+// PPC64:#define __INT_FAST64_FMTi__ "li"
+// PPC64:#define __INT_FAST64_MAX__ 9223372036854775807L
+// PPC64:#define __INT_FAST64_TYPE__ long int
+// PPC64:#define __INT_FAST8_FMTd__ "hhd"
+// PPC64:#define __INT_FAST8_FMTi__ "hhi"
+// PPC64:#define __INT_FAST8_MAX__ 127
+// PPC64:#defi

[PATCH] D72352: [PowerPC][Triple] Use elfv2 on freebsd>=13 and linux-musl

2020-01-07 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8edf759ca7e1: [PowerPC][Triple] Use elfv2 on freebsd>=13 
and linux-musl (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72352

Files:
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ppc-abi.c
  clang/test/Preprocessor/init-ppc64.c
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/Support/Triple.cpp
  llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
  llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll

Index: llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
===
--- llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
+++ llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
@@ -8,8 +8,6 @@
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd < %s | FileCheck %s -check-prefix=CHECK-ELFv1
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd -target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd -target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd-elfv1  < %s | FileCheck %s -check-prefix=CHECK-ELFv1
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd-elfv2  < %s | FileCheck %s -check-prefix=CHECK-ELFv2
 
 ; CHECK-ELFv2: .abiversion 2
 ; CHECK-ELFv1-NOT: .abiversion 2
Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
===
--- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -215,8 +215,6 @@
   case Triple::ppc64le:
 return PPCTargetMachine::PPC_ABI_ELFv2;
   case Triple::ppc64:
-if (TT.getEnvironment() == llvm::Triple::ELFv2)
-  return PPCTargetMachine::PPC_ABI_ELFv2;
 return PPCTargetMachine::PPC_ABI_ELFv1;
   default:
 return PPCTargetMachine::PPC_ABI_UNKNOWN;
Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -228,8 +228,6 @@
   case CODE16: return "code16";
   case EABI: return "eabi";
   case EABIHF: return "eabihf";
-  case ELFv1: return "elfv1";
-  case ELFv2: return "elfv2";
   case Android: return "android";
   case Musl: return "musl";
   case MuslEABI: return "musleabi";
@@ -524,8 +522,6 @@
   return StringSwitch(EnvironmentName)
 .StartsWith("eabihf", Triple::EABIHF)
 .StartsWith("eabi", Triple::EABI)
-.StartsWith("elfv1", Triple::ELFv1)
-.StartsWith("elfv2", Triple::ELFv2)
 .StartsWith("gnuabin32", Triple::GNUABIN32)
 .StartsWith("gnuabi64", Triple::GNUABI64)
 .StartsWith("gnueabihf", Triple::GNUEABIHF)
Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -203,8 +203,6 @@
 CODE16,
 EABI,
 EABIHF,
-ELFv1,
-ELFv2,
 Android,
 Musl,
 MuslEABI,
Index: clang/test/Preprocessor/init-ppc64.c
===
--- clang/test/Preprocessor/init-ppc64.c
+++ clang/test/Preprocessor/init-ppc64.c
@@ -1056,6 +1056,12 @@
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv2 %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu -target-abi elfv1 < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv1 %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu -target-abi elfv2 < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv2 %s
+
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd11 -target-abi elfv1 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv1 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd12 -target-abi elfv1 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv1 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd13 -target-abi elfv2 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv2 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-linux-musl -target-abi elfv2 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv2 %s
+
 // PPC64-ELFv1:#define _CALL_ELF 1
 // PPC64-ELFv2:#define _CALL_ELF 2
 //
Index: clang/test/Driver/ppc-abi.c
===
--- clang/test/Driver/ppc-abi.c
+++ clang/test/Driver/ppc-abi.c
@@ -24,6 +24,12 @@
 // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
 // RUN:   -mabi=altivec | FileCheck -check-prefix=CHECK-ELFv2 %s
 
+// RUN: %clang -targ

[PATCH] D72352: [PowerPC][Triple] Use elfv2 on freebsd>=13 and linux-musl

2020-01-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 236647.
MaskRay added a comment.

Add powerpc64-unknown-freebsd11 (its expected EOL is September 30, 2021)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72352

Files:
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ppc-abi.c
  clang/test/Preprocessor/init-ppc64.c
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/Support/Triple.cpp
  llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
  llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll

Index: llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
===
--- llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
+++ llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
@@ -8,8 +8,6 @@
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd < %s | FileCheck %s -check-prefix=CHECK-ELFv1
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd -target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd -target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd-elfv1  < %s | FileCheck %s -check-prefix=CHECK-ELFv1
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd-elfv2  < %s | FileCheck %s -check-prefix=CHECK-ELFv2
 
 ; CHECK-ELFv2: .abiversion 2
 ; CHECK-ELFv1-NOT: .abiversion 2
Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
===
--- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -215,8 +215,6 @@
   case Triple::ppc64le:
 return PPCTargetMachine::PPC_ABI_ELFv2;
   case Triple::ppc64:
-if (TT.getEnvironment() == llvm::Triple::ELFv2)
-  return PPCTargetMachine::PPC_ABI_ELFv2;
 return PPCTargetMachine::PPC_ABI_ELFv1;
   default:
 return PPCTargetMachine::PPC_ABI_UNKNOWN;
Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -228,8 +228,6 @@
   case CODE16: return "code16";
   case EABI: return "eabi";
   case EABIHF: return "eabihf";
-  case ELFv1: return "elfv1";
-  case ELFv2: return "elfv2";
   case Android: return "android";
   case Musl: return "musl";
   case MuslEABI: return "musleabi";
@@ -524,8 +522,6 @@
   return StringSwitch(EnvironmentName)
 .StartsWith("eabihf", Triple::EABIHF)
 .StartsWith("eabi", Triple::EABI)
-.StartsWith("elfv1", Triple::ELFv1)
-.StartsWith("elfv2", Triple::ELFv2)
 .StartsWith("gnuabin32", Triple::GNUABIN32)
 .StartsWith("gnuabi64", Triple::GNUABI64)
 .StartsWith("gnueabihf", Triple::GNUEABIHF)
Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -203,8 +203,6 @@
 CODE16,
 EABI,
 EABIHF,
-ELFv1,
-ELFv2,
 Android,
 Musl,
 MuslEABI,
Index: clang/test/Preprocessor/init-ppc64.c
===
--- clang/test/Preprocessor/init-ppc64.c
+++ clang/test/Preprocessor/init-ppc64.c
@@ -1056,6 +1056,12 @@
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv2 %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu -target-abi elfv1 < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv1 %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu -target-abi elfv2 < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv2 %s
+
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd11 -target-abi elfv1 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv1 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd12 -target-abi elfv1 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv1 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd13 -target-abi elfv2 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv2 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-linux-musl -target-abi elfv2 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv2 %s
+
 // PPC64-ELFv1:#define _CALL_ELF 1
 // PPC64-ELFv2:#define _CALL_ELF 2
 //
Index: clang/test/Driver/ppc-abi.c
===
--- clang/test/Driver/ppc-abi.c
+++ clang/test/Driver/ppc-abi.c
@@ -24,6 +24,12 @@
 // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
 // RUN:   -mabi=altivec | FileCheck -check-prefix=CHECK-ELFv2 %s
 
+// RUN: %clang -target powerpc64-unknown-freebsd11 %s -### 2>&1

[PATCH] D72352: [PowerPC][Triple] Use elfv2 on freebsd>=13 and linux-musl

2020-01-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 236649.
MaskRay retitled this revision from "[Triple] Use elfv2 on freebsd>=13 and 
linux-musl" to "[PowerPC][Triple] Use elfv2 on freebsd>=13 and linux-musl".
MaskRay edited the summary of this revision.
MaskRay added a comment.
Herald added a subscriber: shchenz.

Better description


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72352

Files:
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ppc-abi.c
  clang/test/Preprocessor/init-ppc64.c
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/Support/Triple.cpp
  llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
  llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll

Index: llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
===
--- llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
+++ llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
@@ -8,8 +8,6 @@
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd < %s | FileCheck %s -check-prefix=CHECK-ELFv1
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd -target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd -target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd-elfv1  < %s | FileCheck %s -check-prefix=CHECK-ELFv1
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd-elfv2  < %s | FileCheck %s -check-prefix=CHECK-ELFv2
 
 ; CHECK-ELFv2: .abiversion 2
 ; CHECK-ELFv1-NOT: .abiversion 2
Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
===
--- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -215,8 +215,6 @@
   case Triple::ppc64le:
 return PPCTargetMachine::PPC_ABI_ELFv2;
   case Triple::ppc64:
-if (TT.getEnvironment() == llvm::Triple::ELFv2)
-  return PPCTargetMachine::PPC_ABI_ELFv2;
 return PPCTargetMachine::PPC_ABI_ELFv1;
   default:
 return PPCTargetMachine::PPC_ABI_UNKNOWN;
Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -228,8 +228,6 @@
   case CODE16: return "code16";
   case EABI: return "eabi";
   case EABIHF: return "eabihf";
-  case ELFv1: return "elfv1";
-  case ELFv2: return "elfv2";
   case Android: return "android";
   case Musl: return "musl";
   case MuslEABI: return "musleabi";
@@ -524,8 +522,6 @@
   return StringSwitch(EnvironmentName)
 .StartsWith("eabihf", Triple::EABIHF)
 .StartsWith("eabi", Triple::EABI)
-.StartsWith("elfv1", Triple::ELFv1)
-.StartsWith("elfv2", Triple::ELFv2)
 .StartsWith("gnuabin32", Triple::GNUABIN32)
 .StartsWith("gnuabi64", Triple::GNUABI64)
 .StartsWith("gnueabihf", Triple::GNUEABIHF)
Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -203,8 +203,6 @@
 CODE16,
 EABI,
 EABIHF,
-ELFv1,
-ELFv2,
 Android,
 Musl,
 MuslEABI,
Index: clang/test/Preprocessor/init-ppc64.c
===
--- clang/test/Preprocessor/init-ppc64.c
+++ clang/test/Preprocessor/init-ppc64.c
@@ -1056,6 +1056,12 @@
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv2 %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu -target-abi elfv1 < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv1 %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu -target-abi elfv2 < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv2 %s
+
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd11 -target-abi elfv1 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv1 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd12 -target-abi elfv1 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv1 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd13 -target-abi elfv2 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv2 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-linux-musl -target-abi elfv2 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv2 %s
+
 // PPC64-ELFv1:#define _CALL_ELF 1
 // PPC64-ELFv2:#define _CALL_ELF 2
 //
Index: clang/test/Driver/ppc-abi.c
===
--- clang/test/Driver/ppc-abi.c
+++ clang/test/Driver/ppc-abi.c
@@ -24,6 +24,12 @@
 // RUN: %clang -target powerp

[PATCH] D50119: P1144 "Trivially relocatable" (0/3): Compiler support for `__is_trivially_relocatable(T)`

2020-01-07 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

@rjmccall ping? any further thoughts on `[[maybe_trivially_relocatable]]`, in 
light of the followup libc++ patches? (Those patches do not use 
`[[maybe_trivially_relocatable]]`, although that may just be because I wrote 
them.)

How could one go about getting this patch into Clang?

Also, for those who haven't seen it, I gave a full-length talk on "trivially 
relocatable" at C++Now 2019: https://www.youtube.com/watch?v=SGdfPextuAU  The 
talk compares my fully implemented Clang/libc++ solution 
https://wg21.link/p1144 to other practical solutions such as Folly, BSL, and 
EASTL, and to other paper solutions such as https://wg21.link/n4158 and 
https://wg21.link/p1029.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D50119



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


[PATCH] D72119: [clangd] Handle DeducedTemplateSpecializationType in TargetFinder

2020-01-07 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 236653.
nridge added a comment.

Remove no longer used flag from XRefTests.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72119

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -315,6 +315,20 @@
   EXPECT_DECLS("TemplateSpecializationTypeLoc",
{"template<> class Foo", Rel::TemplateInstantiation},
{"template  class Foo", Rel::TemplatePattern});
+
+  Code = R"cpp(
+// Class template argument deduction
+template 
+struct Test {
+  Test(T);
+};
+void foo() {
+  [[Test]] a(5);
+}
+  )cpp";
+  Flags.push_back("-std=c++17");
+  EXPECT_DECLS("DeducedTemplateSpecializationTypeLoc",
+   {"struct Test", Rel::TemplatePattern});
 }
 
 TEST_F(TargetDeclTest, FunctionTemplate) {
@@ -549,6 +563,7 @@
 // FIXME: Auto-completion in a template requires disabling delayed template
 // parsing.
 TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
+TU.ExtraArgs.push_back("-std=c++17");
 
 auto AST = TU.build();
 
@@ -937,7 +952,20 @@
 };
 )cpp",
"0: targets = {size}, decl\n"
-   "1: targets = {E}\n"}};
+   "1: targets = {E}\n"},
+   // Class template argument deduction
+   {
+   R"cpp(
+template 
+struct Test {
+Test(T);
+  };
+  void foo() {
+$0^Test $1^a(5);
+  }
+)cpp",
+   "0: targets = {Test}\n"
+   "1: targets = {a}, decl\n"}};
 
   for (const auto &C : Cases) {
 llvm::StringRef ExpectedCode = C.first;
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -358,6 +358,18 @@
 // TypeLoc never has a deduced type. https://llvm.org/PR42914
 Outer.add(DT->getDeducedType(), Flags | Rel::Underlying);
   }
+  void VisitDeducedTemplateSpecializationType(
+  const DeducedTemplateSpecializationType *DTST) {
+// FIXME: This is a workaround for https://llvm.org/PR42914,
+// which is causing DTST->getDeducedType() to be empty. We
+// fall back to the template pattern and miss the instantiation
+// even when it's known in principle. Once that bug is fixed,
+// this method can be removed (the existing handling in
+// VisitDeducedType() is sufficient).
+if (auto *TD = DTST->getTemplateName().getAsTemplateDecl()) {
+  Outer.add(TD->getTemplatedDecl(), Flags | Rel::TemplatePattern);
+}
+  }
   void VisitTypedefType(const TypedefType *TT) {
 Outer.add(TT->getDecl(), Flags);
   }


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -315,6 +315,20 @@
   EXPECT_DECLS("TemplateSpecializationTypeLoc",
{"template<> class Foo", Rel::TemplateInstantiation},
{"template  class Foo", Rel::TemplatePattern});
+
+  Code = R"cpp(
+// Class template argument deduction
+template 
+struct Test {
+  Test(T);
+};
+void foo() {
+  [[Test]] a(5);
+}
+  )cpp";
+  Flags.push_back("-std=c++17");
+  EXPECT_DECLS("DeducedTemplateSpecializationTypeLoc",
+   {"struct Test", Rel::TemplatePattern});
 }
 
 TEST_F(TargetDeclTest, FunctionTemplate) {
@@ -549,6 +563,7 @@
 // FIXME: Auto-completion in a template requires disabling delayed template
 // parsing.
 TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
+TU.ExtraArgs.push_back("-std=c++17");
 
 auto AST = TU.build();
 
@@ -937,7 +952,20 @@
 };
 )cpp",
"0: targets = {size}, decl\n"
-   "1: targets = {E}\n"}};
+   "1: targets = {E}\n"},
+   // Class template argument deduction
+   {
+   R"cpp(
+template 
+struct Test {
+Test(T);
+  };
+  void foo() {
+$0^Test $1^a(5);
+  }
+)cpp",
+   "0: targets = {Test}\n"
+   "1: targets = {a}, decl\n"}};
 
   for (const auto &C : Cases) {
 llvm::StringRef ExpectedCode = C.first;
Index: clang-tools-extra/clangd/FindTarget.cpp
===

[PATCH] D72355: [clangd] Assert that the testcases in FindExplicitReferencesTest.All have no diagnostics

2020-01-07 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
nridge added a reviewer: kadircet.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72355

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


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -566,6 +566,9 @@
 TU.ExtraArgs.push_back("-std=c++17");
 
 auto AST = TU.build();
+for (auto &D : AST.getDiagnostics())
+  ADD_FAILURE() << D << Code;
+assert(AST.getDiagnostics().empty());
 
 auto *TestDecl = &findDecl(AST, "foo");
 if (auto *T = llvm::dyn_cast(TestDecl))
@@ -663,7 +666,7 @@
  void foo() {
$0^Struct $1^x;
$2^Typedef $3^y;
-   static_cast<$4^Struct*>(0);
+   (void)static_cast<$4^Struct*>(0);
  }
)cpp",
 "0: targets = {Struct}\n"
@@ -718,7 +721,7 @@
 "3: targets = {vb}, decl\n"},
// MemberExpr should know their using declaration.
{R"cpp(
-struct X { void func(int); }
+struct X { void func(int); };
 struct Y : X {
   using X::func;
 };
@@ -744,7 +747,7 @@
 #define BAR b
 
 void foo(int a, int b) {
-  $0^FOO+$1^BAR;
+  (void)($0^FOO+$1^BAR);
 }
 )cpp",
 "0: targets = {a}\n"
@@ -824,7 +827,7 @@
 void foo() {
   $0^TT $1^x;
   $2^foo<$3^TT>();
-  $4^foo<$5^vector>()
+  $4^foo<$5^vector>();
   $6^foo<$7^TP...>();
 }
 )cpp",
@@ -891,7 +894,7 @@
};
// delegating initializer
class $10^Foo {
- $11^Foo(int);
+ $11^Foo(int) {}
  $12^Foo(): $13^Foo(111) {}
};
  }
@@ -924,7 +927,7 @@
// Namespace aliases should be handled properly.
{
R"cpp(
-namespace ns { struct Type {} }
+namespace ns { struct Type {}; }
 namespace alias = ns;
 namespace rec_alias = alias;
 


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -566,6 +566,9 @@
 TU.ExtraArgs.push_back("-std=c++17");
 
 auto AST = TU.build();
+for (auto &D : AST.getDiagnostics())
+  ADD_FAILURE() << D << Code;
+assert(AST.getDiagnostics().empty());
 
 auto *TestDecl = &findDecl(AST, "foo");
 if (auto *T = llvm::dyn_cast(TestDecl))
@@ -663,7 +666,7 @@
  void foo() {
$0^Struct $1^x;
$2^Typedef $3^y;
-   static_cast<$4^Struct*>(0);
+   (void)static_cast<$4^Struct*>(0);
  }
)cpp",
 "0: targets = {Struct}\n"
@@ -718,7 +721,7 @@
 "3: targets = {vb}, decl\n"},
// MemberExpr should know their using declaration.
{R"cpp(
-struct X { void func(int); }
+struct X { void func(int); };
 struct Y : X {
   using X::func;
 };
@@ -744,7 +747,7 @@
 #define BAR b
 
 void foo(int a, int b) {
-  $0^FOO+$1^BAR;
+  (void)($0^FOO+$1^BAR);
 }
 )cpp",
 "0: targets = {a}\n"
@@ -824,7 +827,7 @@
 void foo() {
   $0^TT $1^x;
   $2^foo<$3^TT>();
-  $4^foo<$5^vector>()
+  $4^foo<$5^vector>();
   $6^foo<$7^TP...>();
 }
 )cpp",
@@ -891,7 +894,7 @@
};
// delegating initializer
class $10^Foo {
- $11^Foo(int);
+ $11^Foo(int) {}
  $12^Foo(): $13^Foo(111) {}
};
  }
@@ -924,7 +927,7 @@
// Namespace aliases should be handled properly.
{
R"cpp(
-namespace ns { struct Type {} }
+namespace ns { struct Type {}; }
 namespace alias = ns;
 namespace rec_alias = alias;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72119: [clangd] Handle DeducedTemplateSpecializationType in TargetFinder

2020-01-07 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 236652.
nridge marked an inline comment as done.
nridge added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72119

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -513,6 +513,7 @@
 // FIXME: Auto-completion in a template requires disabling delayed template
 // parsing.
 TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
+TU.ExtraArgs.push_back("-std=c++17");
 
 auto AST = TU.build();
 for (auto &D : AST.getDiagnostics())
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -315,6 +315,20 @@
   EXPECT_DECLS("TemplateSpecializationTypeLoc",
{"template<> class Foo", Rel::TemplateInstantiation},
{"template  class Foo", Rel::TemplatePattern});
+
+  Code = R"cpp(
+// Class template argument deduction
+template 
+struct Test {
+  Test(T);
+};
+void foo() {
+  [[Test]] a(5);
+}
+  )cpp";
+  Flags.push_back("-std=c++17");
+  EXPECT_DECLS("DeducedTemplateSpecializationTypeLoc",
+   {"struct Test", Rel::TemplatePattern});
 }
 
 TEST_F(TargetDeclTest, FunctionTemplate) {
@@ -549,6 +563,7 @@
 // FIXME: Auto-completion in a template requires disabling delayed template
 // parsing.
 TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
+TU.ExtraArgs.push_back("-std=c++17");
 
 auto AST = TU.build();
 
@@ -937,7 +952,20 @@
 };
 )cpp",
"0: targets = {size}, decl\n"
-   "1: targets = {E}\n"}};
+   "1: targets = {E}\n"},
+   // Class template argument deduction
+   {
+   R"cpp(
+template 
+struct Test {
+Test(T);
+  };
+  void foo() {
+$0^Test $1^a(5);
+  }
+)cpp",
+   "0: targets = {Test}\n"
+   "1: targets = {a}, decl\n"}};
 
   for (const auto &C : Cases) {
 llvm::StringRef ExpectedCode = C.first;
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -358,6 +358,18 @@
 // TypeLoc never has a deduced type. https://llvm.org/PR42914
 Outer.add(DT->getDeducedType(), Flags | Rel::Underlying);
   }
+  void VisitDeducedTemplateSpecializationType(
+  const DeducedTemplateSpecializationType *DTST) {
+// FIXME: This is a workaround for https://llvm.org/PR42914,
+// which is causing DTST->getDeducedType() to be empty. We
+// fall back to the template pattern and miss the instantiation
+// even when it's known in principle. Once that bug is fixed,
+// this method can be removed (the existing handling in
+// VisitDeducedType() is sufficient).
+if (auto *TD = DTST->getTemplateName().getAsTemplateDecl()) {
+  Outer.add(TD->getTemplatedDecl(), Flags | Rel::TemplatePattern);
+}
+  }
   void VisitTypedefType(const TypedefType *TT) {
 Outer.add(TT->getDecl(), Flags);
   }


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -513,6 +513,7 @@
 // FIXME: Auto-completion in a template requires disabling delayed template
 // parsing.
 TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
+TU.ExtraArgs.push_back("-std=c++17");
 
 auto AST = TU.build();
 for (auto &D : AST.getDiagnostics())
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -315,6 +315,20 @@
   EXPECT_DECLS("TemplateSpecializationTypeLoc",
{"template<> class Foo", Rel::TemplateInstantiation},
{"template  class Foo", Rel::TemplatePattern});
+
+  Code = R"cpp(
+// Class template argument deduction
+template 
+struct Test {
+  Test(T);
+};
+void foo() {
+  [[Test]] a(5);
+}
+  )cpp";
+  Flags.push_back("-std=c++17");
+  EXPECT_

Re: [PATCH] D67774: [Mangle] Add flag to asm labels to disable '\01' prefixing

2020-01-07 Thread John McCall via cfe-commits
On Tue, Jan 7, 2020 at 1:44 PM Aaron Ballman via Phabricator
 wrote:
> aaron.ballman added inline comments.
>
>
> 
> Comment at: cfe/trunk/lib/AST/Mangle.cpp:127
> +// do not add a "\01" prefix.
> +if (!ALA->getIsLiteralLabel() || ALA->getLabel().startswith("llvm.")) {
> +  Out << ALA->getLabel();
> 
> Sorry to dredge up an old review, but I recently ran into a bug in this area 
> and am not certain of how to fix it. What should happen if the asm label is a 
> literal which is empty?

The problems here are unique to empty labels, right?  Can we just
diagnose this as an error?  Is this bug occurring with real code, or
is LLDB constructing something bizarre?

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


  1   2   >