r361710 - [Driver][RISCV] Simplify. NFC

2019-05-26 Thread Fangrui Song via cfe-commits
Author: maskray
Date: Sun May 26 00:43:45 2019
New Revision: 361710

URL: http://llvm.org/viewvc/llvm-project?rev=361710&view=rev
Log:
[Driver][RISCV] Simplify. NFC

Modified:
cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp?rev=361710&r1=361709&r2=361710&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp Sun May 26 00:43:45 2019
@@ -54,20 +54,14 @@ static bool isSupportedExtension(StringR
 static bool getExtensionVersion(const Driver &D, StringRef MArch,
 StringRef Ext, StringRef In,
 std::string &Major, std::string &Minor) {
-  auto I = In.begin();
-  auto E = In.end();
-
-  while (I != E && isDigit(*I))
-Major.append(1, *I++);
-
+  Major = In.take_while(isDigit);
+  In = In.substr(Major.size());
   if (Major.empty())
 return true;
 
-  if (I != E && *I == 'p') {
-++I;
-
-while (I != E && isDigit(*I))
-  Minor.append(1, *I++);
+  if (In.consume_front("p")) {
+Minor = In.take_while(isDigit);
+In = In.substr(Major.size());
 
 // Expected 'p' to be followed by minor version number.
 if (Minor.empty()) {
@@ -110,17 +104,13 @@ static void getExtensionFeatures(const D
   SmallVector Split;
   Exts.split(Split, StringRef("_"));
 
-  SmallVector Prefix;
-  Prefix.push_back("x");
-  Prefix.push_back("s");
-  Prefix.push_back("sx");
+  SmallVector Prefix{"x", "s", "sx"};
   auto I = Prefix.begin();
   auto E = Prefix.end();
 
   SmallVector AllExts;
 
   for (StringRef Ext : Split) {
-
 if (Ext.empty()) {
   D.Diag(diag::err_drv_invalid_riscv_arch_name) << MArch
 << "extension name missing after separator '_'";
@@ -205,11 +195,9 @@ void riscv::getRISCVTargetFeatures(const
 StringRef MArch = A->getValue();
 
 // RISC-V ISA strings must be lowercase.
-if (std::any_of(std::begin(MArch), std::end(MArch),
-[](char c) { return isupper(c); })) {
-
-  D.Diag(diag::err_drv_invalid_riscv_arch_name) << MArch
-<< "string must be lowercase";
+if (llvm::any_of(MArch, [](char c) { return isupper(c); })) {
+  D.Diag(diag::err_drv_invalid_riscv_arch_name)
+  << MArch << "string must be lowercase";
   return;
 }
 
@@ -221,7 +209,7 @@ void riscv::getRISCVTargetFeatures(const
   return;
 }
 
-bool HasRV64 = MArch.startswith("rv64") ? true : false;
+bool HasRV64 = MArch.startswith("rv64");
 
 // The canonical order specified in ISA manual.
 // Ref: Table 22.1 in RISC-V User-Level ISA V2.2
@@ -365,16 +353,10 @@ void riscv::getRISCVTargetFeatures(const
   }
 
   // -mrelax is default, unless -mno-relax is specified.
-  bool Relax = true;
-  if (auto *A = Args.getLastArg(options::OPT_mrelax, options::OPT_mno_relax)) {
-if (A->getOption().matches(options::OPT_mno_relax)) {
-  Relax = false;
-  Features.push_back("-relax");
-}
-  }
-
-  if (Relax)
+  if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true))
 Features.push_back("+relax");
+  else
+Features.push_back("-relax");
 
   // Now add any that the user explicitly requested on the command line,
   // which may override the defaults.


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


[PATCH] D61989: [clang-tidy] enable modernize-concat-nested-namespaces on header files

2019-05-26 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

Could you please run this check over LLVM and give a short report of your 
finding? I would imagine that there is a lot of duplication, given the 
include-heavy nature of big c++ code bases.




Comment at: 
clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp:70
+  if (!utils::parseHeaderFileExtensions(RawStringHeaderFileExtensions,
+HeaderFileExtensions, ','))
+llvm::errs() << "Invalid header file extension: "

Can we use the semicolon instead for the options list? Other options in checks 
use that character for separating lists instead and I would like to go for 
consistency.

What happens for the error case here? Is the default list used?



Comment at: 
clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h:23
+///   - `HeaderFileExtensions`: a comma-separated list of filename extensions 
of
+/// header files (The filename extensions should not contain "." prefix).
+/// "h,hh,hpp,hxx" by default.

` prefix), "h,hh,hpp,hxx" by default.` (Note the comma after paren)



Comment at: 
clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h:25
+/// "h,hh,hpp,hxx" by default.
+/// For extension-less header files, using an empty string or leaving an
+/// empty string between "," if there are other filename extensions.

Maybe `To enable extension-less header files use an empty string or leave an 
empty section between to commas like in "h,hxx,,hpp".`?
I think the sentence reads a bit weird right now.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:143
+  ` now supports
+  `HeaderFileExtensions` option and issues warnings for transitively included
+  header files that passes the header filter.

I think the sentence is a bit off.

- `now supports _the_ ...`
- `header files that _pass_ the header filter`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61989



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


[PATCH] D62363: [X86] Enable intrinsics that convert float and bf16 data to each other

2019-05-26 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: lib/Headers/avx512bf16intrin.h:52
+///
+/// \headerfile
+///

\headerfile 



Comment at: lib/Headers/avx512bf16intrin.h:54
+///
+/// This intrinsic is lowered to  LLVM IR.
+///

Please can you write a better description?



Comment at: lib/Headers/avx512bf16intrin.h:66
+///
+/// \headerfile
+///

\headerfile 



Comment at: lib/Headers/avx512bf16intrin.h:98
+  return (__m512bh)__builtin_ia32_selectw_512(
+  (__mmask32)__U, (__v32hi)_mm512_cvtne2ps_pbh(__A, __B), (__v32hi)__W);
 }

style/clang-format changes like these should be separated into their own patch


Repository:
  rC Clang

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

https://reviews.llvm.org/D62363



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


[PATCH] D62131: [ASTImporter] Remove NonEquivalentDecls from ASTImporter

2019-05-26 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin added a comment.

Hi Gabor,
Could you provide an example of an import sequence leading to this behavior? 
It's hard for me to imagine such a situation.




Comment at: clang/test/ASTMerge/struct/test.c:37
 // CHECK: struct2.c:53:37: note: field 'f' has type 'float' here
-// CHECK: struct1.c:54:8: warning: type 'struct DeepError' has incompatible 
definitions in different translation units
-// CHECK: struct1.c:56:41: note: field 'Deeper' has type 'struct DeeperError 
*' here

It looks strange to me that these warnings are gone.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62131



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


[clang-tools-extra] r361735 - DeleteNullPointerCheck now deletes until the end brace of the condition.

2019-05-26 Thread Mads Ravn via cfe-commits
Author: madsravn
Date: Sun May 26 10:00:38 2019
New Revision: 361735

URL: http://llvm.org/viewvc/llvm-project?rev=361735&view=rev
Log:
DeleteNullPointerCheck now deletes until the end brace of the condition.

Patch by Jonathan Camilleri

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

Modified:
clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp?rev=361735&r1=361734&r2=361735&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp 
Sun May 26 10:00:38 2019
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "DeleteNullPointerCheck.h"
+#include "../utils/LexerUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/Lexer.h"
@@ -62,9 +63,11 @@ void DeleteNullPointerCheck::check(const
 
   Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
   IfWithDelete->getBeginLoc(),
-  Lexer::getLocForEndOfToken(IfWithDelete->getCond()->getEndLoc(), 0,
- *Result.SourceManager,
- Result.Context->getLangOpts(;
+  utils::lexer::getPreviousToken(IfWithDelete->getThen()->getBeginLoc(),
+ *Result.SourceManager,
+ Result.Context->getLangOpts())
+  .getLocation()));
+
   if (Compound) {
 Diag << FixItHint::CreateRemoval(
 CharSourceRange::getTokenRange(Compound->getLBracLoc()));

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp?rev=361735&r1=361734&r2=361735&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp 
Sun May 26 10:00:38 2019
@@ -3,6 +3,15 @@
 #define NULL 0
 
 void f() {
+  int *ps = 0;
+  if (ps /**/) // #0
+delete ps;
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: 'if' statement is unnecessary; 
deleting null pointer has no effect [readability-delete-null-pointer]
+
+  // CHECK-FIXES: int *ps = 0;
+  // CHECK-FIXES-NEXT: {{^  }}// #0
+  // CHECK-FIXES-NEXT: delete ps;
+
   int *p = 0;
 
   // #1


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


[PATCH] D62064: [ASTImporter] Fix unhandled cases in ASTImporterLookupTable

2019-05-26 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin accepted this revision.
a_sidorin added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:4259
 static const RecordDecl * getRecordDeclOfFriend(FriendDecl *FD) {
   QualType Ty = FD->getFriendType()->getType();
+  if (auto *Inner = dyn_cast(Ty.getTypePtr())) {

martong wrote:
> a_sidorin wrote:
> > Will getCanonicalType() do the job?
> That's a good catch! Thank you for pointing out.
Can we replace the whole function with:
```
QualType Ty = FD->getFriendType()->getType().getCanonicalType();
return cast(Ty)->getDecl();
```
?



Comment at: clang/unittests/AST/ASTImporterTest.cpp:4249
 
 static const RecordDecl * getRecordDeclOfFriend(FriendDecl *FD) {
   QualType Ty = FD->getFriendType()->getType();

Redundant space after '*'.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62064



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


[PATCH] D62329: [ASTImporter] Structural eq: handle DependentScopeDeclRefExpr

2019-05-26 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin added a comment.

Hello Gabor,
I have a few questions inline.




Comment at: clang/lib/AST/ASTStructuralEquivalence.cpp:124
+  case DeclarationName::CXXConversionFunctionName:
+return true;
+

Should we check the equivalence of getCXXNameType() in such cases?



Comment at: clang/lib/AST/ASTStructuralEquivalence.cpp:127
+  case DeclarationName::CXXDeductionGuideName:
+return IsStructurallyEquivalent(
+Name1.getCXXDeductionGuideTemplate()->getDeclName(),

Should we check the equivalence of the whole 
Name1.getCXXDeductionGuideTemplate() (with the template arguments)?



Comment at: clang/lib/AST/ASTStructuralEquivalence.cpp:147
+
+  return true;
+}

llvm_unreachable()?



Comment at: clang/lib/AST/ASTStructuralEquivalence.cpp:163
+return IsStructurallyEquivalent(Context, DE1->getQualifier(),
+DE2->getQualifier());
+  }

Should we compare TemplateArgs (getTemplateArgs) somehow?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62329



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


[PATCH] D62440: [analyzer] NFC: Change evalCall() to provide a CallEvent.

2019-05-26 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin accepted this revision.
a_sidorin added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:372
   CheckerContext &C) const {
-  const FunctionDecl *FD = dyn_cast_or_null(CE->getCalleeDecl());
+  const auto *FD = dyn_cast_or_null(Call.getDecl());
   if (!FD)

Should we create helpers similar to getDecl() and getOriginExpr 
(getFunctionDecl/getCallExpr)?


Repository:
  rC Clang

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

https://reviews.llvm.org/D62440



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


[PATCH] D62373: [ASTImporter] Store import errors for Decls

2019-05-26 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin added a comment.

Hi Gabor,
The idea looks fine to me, but I have some questions inline.




Comment at: clang/lib/AST/ASTImporter.cpp:5109
 } else { // ODR violation.
   // FIXME HandleNameConflict
+  return make_error(ImportError::NameConflict);

Is this FIXME obsolete now?



Comment at: clang/lib/AST/ASTImporter.cpp:7823
+auto Pos = ImportedDecls.find(FromD);
+if (Pos != ImportedDecls.end()) {
+  // Import failed after the object was created.

I see the enabled test case, but does it cover the logic in this block?



Comment at: clang/lib/AST/ASTImporter.cpp:7851
+if (!getImportDeclErrorIfAny(FromD)) {
+  // Error encountered for the first time.
+  // After takeError the error is not usable any more in ToDOrErr.

Is it possible to get this error more than once?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62373



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


[PATCH] D62375: [ASTImporter] Mark erroneous nodes in from ctx

2019-05-26 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin added a comment.

Hi Gabor,
Could you please provide any test for the import itself?




Comment at: clang/lib/AST/ASTImporter.cpp:8668
+
+bool ASTImporter::ImportPathTy::hasCycleAtBack() {
+  return Aux[Nodes.back()] > 1;

const?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62375



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


[PATCH] D62376: [ASTImporter] Mark erroneous nodes in shared st

2019-05-26 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin added a comment.

Hi Gabor!
I haven't find the import sequence examples we try to fix these ways in any of 
the three patches these change consists of. Could you please provide some (or 
point if I missed them)?




Comment at: clang/include/clang/AST/ASTImporterSharedState.h:46
+public:
+  ASTImporterSharedState() {}
+

`= default?`



Comment at: clang/lib/AST/ASTImporter.cpp:7724
 void ASTImporter::AddToLookupTable(Decl *ToD) {
-  if (LookupTable)
+  if (SharedState->getLookupTable())
 if (auto *ToND = dyn_cast(ToD))

```
if (auto* LookupTable = ..._)
  ...
LookupTable->add();
```
looks a bit cleaner to me.



Comment at: clang/lib/AST/ASTImporter.cpp:7830
   if (ToD) {
+// Already imported (possibly from another TU) and with an error.
+if (auto Error = SharedState->getImportDeclErrorIfAny(ToD))

I'm not sure if it is safe to compare declarations from different TUs by 
pointers because they belong to different allocators.



Comment at: clang/lib/AST/ASTImporter.cpp:7831
+// Already imported (possibly from another TU) and with an error.
+if (auto Error = SharedState->getImportDeclErrorIfAny(ToD))
+  return make_error(*Error);

getImportDeclErrorIfAny() is usually called for FromD, not for ToD. Is it 
intentional?



Comment at: clang/lib/AST/ASTImporter.cpp:7867
   if (PosF != ImportedFromDecls.end()) {
-if (LookupTable)
+if (SharedState->getLookupTable())
   if (auto *ToND = dyn_cast(ToD))

I think we can encapsulate these conditions into 
`SharedState::[add/remove]Decl[To/From]Lookup methods.



Comment at: clang/lib/AST/ASTImporter.cpp:7924
+  if (auto Error = SharedState->getImportDeclErrorIfAny(ToD))
+return make_error(*Error);
+

I don' think that an import failure from another TU means that the import from 
the current TU will fail.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62376



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


[PATCH] D62470: Clarify when fix-it hints on warnings are appropriate

2019-05-26 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert created this revision.
aaronpuchert added reviewers: rsmith, aaron.ballman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is not a change in the rules, it's meant as a clarification about
warnings. Since the recovery from warnings is a no-op, the fix-it hints
on warnings shouldn't change anything. Anything that doesn't just
suppress the warning and changes the meaning of the code (even if it's
for the better) should be on an additional note.


Repository:
  rC Clang

https://reviews.llvm.org/D62470

Files:
  docs/InternalsManual.rst


Index: docs/InternalsManual.rst
===
--- docs/InternalsManual.rst
+++ docs/InternalsManual.rst
@@ -423,6 +423,9 @@
   driver, they should only be used when it's very likely they match the user's
   intent.
 * Clang must recover from errors as if the fix-it had been applied.
+* Fix-it hints on a warning should only clarify the meaning of the existing
+  code, not change it. Examples for such hints are added parentheses in cases
+  of counter-intuitive precedence, when they clarify the order of operations.
 
 If a fix-it can't obey these rules, put the fix-it on a note.  Fix-its on notes
 are not applied automatically.


Index: docs/InternalsManual.rst
===
--- docs/InternalsManual.rst
+++ docs/InternalsManual.rst
@@ -423,6 +423,9 @@
   driver, they should only be used when it's very likely they match the user's
   intent.
 * Clang must recover from errors as if the fix-it had been applied.
+* Fix-it hints on a warning should only clarify the meaning of the existing
+  code, not change it. Examples for such hints are added parentheses in cases
+  of counter-intuitive precedence, when they clarify the order of operations.
 
 If a fix-it can't obey these rules, put the fix-it on a note.  Fix-its on notes
 are not applied automatically.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62470: Clarify when fix-it hints on warnings are appropriate

2019-05-26 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

Feel free to suggest better wording, I'm not a native speaker.


Repository:
  rC Clang

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

https://reviews.llvm.org/D62470



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


[PATCH] D60974: Clang IFSO driver action.

2019-05-26 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 201471.
plotfi added a comment.

virtual function test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/InterfaceStubs/bad-format.cpp
  clang/test/InterfaceStubs/class-template-specialization.cpp
  clang/test/InterfaceStubs/externstatic.c
  clang/test/InterfaceStubs/function-template-specialization.cpp
  clang/test/InterfaceStubs/inline.c
  clang/test/InterfaceStubs/inline.h
  clang/test/InterfaceStubs/object.cpp
  clang/test/InterfaceStubs/template-namespace-function.cpp
  clang/test/InterfaceStubs/virtual.cpp
  clang/test/InterfaceStubs/visibility.cpp
  clang/test/InterfaceStubs/weak.cpp

Index: clang/test/InterfaceStubs/weak.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/weak.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck %s
+
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-YAML %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// CHECK: Symbols:
+// CHECK-NEXT:  _Z8weakFuncv: { Type: Func, Weak: true }
+// CHECK-NEXT:  _Z10strongFuncv: { Type: Func }
+
+// CHECK-YAML: Symbols:
+// CHECK-YAML-NEXT:   - Name:_Z8weakFuncv
+// CHECK-YAML-NEXT: Type:STT_FUNC
+// CHECK-YAML-NEXT: Binding: STB_WEAK
+// CHECK-YAML-NEXT:   - Name:_Z10strongFuncv
+// CHECK-YAML-NEXT: Type:STT_FUNC
+// CHECK-YAML-NEXT: Binding: STB_GLOBAL
+
+// CHECK-SYMBOLS: _Z10strongFuncv
+// CHECK-SYMBOLS: _Z8weakFuncv
+__attribute__((weak)) void weakFunc() {}
+int strongFunc() { return 42; }
Index: clang/test/InterfaceStubs/visibility.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/visibility.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-readelf -s - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// Always Be Hidden:
+// CHECK-CMD-HIDDEN-NOT: _Z6hiddenv
+// CHECK-NOT: _Z6hiddenv
+__attribute__((visibility("hidden"))) void hidden() {}
+
+// Always Be Visible:
+// CHECK-CMD-HIDDEN: _Z9nothiddenv
+// CHECK: _Z9nothiddenv
+__attribute__((visibility("default"))) void nothidden() {}
+
+// Do Whatever -fvisibility says:
+// CHECK-CMD-HIDDEN-NOT: _Z10cmdVisiblev
+// CHECK: _Z10cmdVisiblev
+void cmdVisible() {}
+
+// CHECK-SYMBOLS: DEFAULT{{.*}} _Z10cmdVisiblev
+// CHECK-SYMBOLS: HIDDEN {{.*}} _Z6hiddenv
+// CHECK-SYMBOLS: DEFAULT{{.*}} _Z9nothiddenv
Index: clang/test/InterfaceStubs/virtual.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/virtual.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck -check-prefix=CHECK-TAPI %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | \
+// RUN: llvm-readelf -s - 2>&1 | FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+#define HIDDEN  __attribute__((__visibility__(("hidden"
+#define DEFAULT __attribute__((__visibility__(("default"
+
+// CHECK-TAPI-NOT: _ZNK1Q5func1Ev
+// CHECK-TAPI-NOT: _ZNK1Q5func2Ev
+// CHECK-SYMBOLS: NOTYPE  GLOBAL HIDDEN   {{.*}} _ZNK1Q5func1Ev
+// CHECK-SYMBOLS: NOTYPE  GLOBAL DEFAULT  {{.*}} _ZNK1Q5func2Ev
+struct Q {
+  virtual HIDDEN  int func1() cons

[PATCH] D62469: [Driver] Change layout of per-target runtimes to resemble multiarch

2019-05-26 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: jdenny, beanz, smeenai, mcgrathr, saugustine.
Herald added subscribers: llvm-commits, Sanitizers, cfe-commits, cryptoad, 
javed.absar, mgorny, kubamracek.
Herald added projects: clang, Sanitizers, LLVM.

This is a follow up to r361432, changing the layout of per-target
runtimes to more closely resemble multiarch. While before, we used
the following layout:

//lib/libclang_rt..

Now we use the following layout:

/lib//libclang_rt..

This also more closely resembles the existing "non-per-target" layout:

/lib//libclang_rt.-.

This change will enable further simplification of the driver logic
in follow up changes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62469

Files:
  clang/lib/Driver/ToolChain.cpp
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/.keep
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.asan-preinit.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.asan.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.fuzzer.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.xray-basic.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.xray.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/i386-linux-gnu/lib/.keep
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/i386-linux-gnu/lib/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-fuchsia/.keep
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-fuchsia/asan/.keep
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-fuchsia/libclang_rt.asan-preinit.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-fuchsia/libclang_rt.asan.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-fuchsia/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-fuchsia/libclang_rt.fuzzer.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-fuchsia/libclang_rt.xray-basic.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-fuchsia/libclang_rt.xray.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-fuchsia/noexcept/.keep
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/i386-linux-gnu/.keep
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/i386-linux-gnu/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-fuchsia/.keep
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-fuchsia/asan/.keep
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-fuchsia/libclang_rt.asan-preinit.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-fuchsia/libclang_rt.asan.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-fuchsia/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-fuchsia/libclang_rt.fuzzer.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-fuchsia/libclang_rt.xray-basic.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-fuchsia/libclang_rt.xray.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-fuchsia/noexcept/.keep
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-linux-gnu/.keep
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-linux-gnu/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/.keep
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.asan-preinit.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.asan.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.fuzzer.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.xray-basic.a
  
clang/test/Drive

[PATCH] D62471: [clangd] SymbolCollector support for relations

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

The only relation currently collected is RelationBaseOf, because this is
all we need for type hierarchy subtypes. Additional relations can be
collected in the future as the need arises.

This patch builds on D59407  and D62459 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62471

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

Index: clang-tools-extra/clangd/index/SymbolCollector.h
===
--- clang-tools-extra/clangd/index/SymbolCollector.h
+++ clang-tools-extra/clangd/index/SymbolCollector.h
@@ -110,6 +110,7 @@
 
   SymbolSlab takeSymbols() { return std::move(Symbols).build(); }
   RefSlab takeRefs() { return std::move(Refs).build(); }
+  RelationSlab takeRelations() { return std::move(Relations).build(); }
 
   void finish() override;
 
@@ -117,6 +118,8 @@
   const Symbol *addDeclaration(const NamedDecl &, SymbolID,
bool IsMainFileSymbol);
   void addDefinition(const NamedDecl &, const Symbol &DeclSymbol);
+  void processRelations(const NamedDecl &ND, const SymbolID &ID,
+ArrayRef Relations);
 
   llvm::Optional getIncludeHeader(llvm::StringRef QName, FileID);
   bool isSelfContainedHeader(FileID);
@@ -135,6 +138,8 @@
   // Only symbols declared in preamble (from #include) and referenced from the
   // main file will be included.
   RefSlab::Builder Refs;
+  // All relations collected from the AST.
+  RelationSlab::Builder Relations;
   ASTContext *ASTCtx;
   std::shared_ptr PP;
   std::shared_ptr CompletionAllocator;
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -291,6 +291,12 @@
   SM.getFileID(SpellingLoc) == SM.getMainFileID())
 ReferencedDecls.insert(ND);
 
+  auto ID = getSymbolID(ND);
+  if (!ID)
+return true;
+
+  processRelations(*ND, *ID, Relations);
+
   bool CollectRef = static_cast(Opts.RefFilter) & Roles;
   bool IsOnlyRef =
   !(Roles & (static_cast(index::SymbolRole::Declaration) |
@@ -315,10 +321,6 @@
   if (IsOnlyRef)
 return true;
 
-  auto ID = getSymbolID(ND);
-  if (!ID)
-return true;
-
   // FIXME: ObjCPropertyDecl are not properly indexed here:
   // - ObjCPropertyDecl may have an OrigD of ObjCPropertyImplDecl, which is
   // not a NamedDecl.
@@ -338,6 +340,7 @@
 
   if (Roles & static_cast(index::SymbolRole::Definition))
 addDefinition(*OriginalDecl, *BasicSymbol);
+
   return true;
 }
 
@@ -416,8 +419,43 @@
   return true;
 }
 
-void SymbolCollector::setIncludeLocation(const Symbol &S,
- SourceLocation Loc) {
+void SymbolCollector::processRelations(
+const NamedDecl &ND, const SymbolID &ID,
+ArrayRef Relations) {
+  // Store subtype relations.
+  const CXXRecordDecl *RD = dyn_cast(&ND);
+  if (!RD)
+return;
+
+  for (const auto &R : Relations) {
+if (!(R.Roles & static_cast(index::SymbolRole::RelationBaseOf))) {
+  continue;
+}
+const Decl *Parent = R.RelatedSymbol;
+
+if (const auto *CTSD = dyn_cast(Parent)) {
+  if (!CTSD->isExplicitSpecialization()) {
+Parent = CTSD->getSpecializedTemplate();
+  }
+}
+if (auto ParentID = getSymbolID(Parent)) {
+  // We are a subtype to each of our parents.
+  // TODO: There may be cases where the parent type is not indexed for some
+  // reason (e.g. currently we don't index explicit class template
+  // specializations). Those cases should probably be removed in due course,
+  // but for now there are two possible ways to handle it:
+  //   (A) Avoid storing the relationship in such cases.
+  //   (B) Store it anyways. Clients will likely lookup() the SymbolID
+  //   in the index and find nothing, but that's a situation they
+  //   probably need to handle for other reasons anyways.
+  // We currently do (B) because it's simpler.
+  this->Relations.insert(
+  Relation{ID, index::SymbolRole::RelationBaseOf, *ParentID});
+}
+  }
+}
+
+void SymbolCollector::setIncludeLocation(const Symbol &S, SourceLocation Loc) {
   if (Opts.CollectIncludePath)
 if (shouldCollectIncludePath(S.SymInfo.Kind))
   // Use the expansion location to get the #include header since this is
@@ -681,7 +719,7 @@
   if (!Line.consume_front("#"))
 return false;
   Line = Line.ltrim();
-  if (! Line.startswith("error"))
+  if (!Line.startswith("error"))
 return false;
   return Line.contains_lower("includ"); // Matches "include" or "including".