[PATCH] [libcxx] Ensure std::getline always 0-terminates string.

2017-09-08 Thread Reimar Döffinger via cfe-commits
If the sentinel failed (e.g. due to having reached
EOF before) or an exception was caught it failed to
do that.
While it seems (unfortunately!) not required by the
specification, libstdc++ does 0-terminate and not
doing so risks creating security issues in applications.
---
 include/istream | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/istream b/include/istream
index 0b8e05d95..5c73df38f 100644
--- a/include/istream
+++ b/include/istream
@@ -1069,16 +1069,18 @@ basic_istream<_CharT, _Traits>::getline(char_type* __s, 
streamsize __n, char_typ
 this->rdbuf()->sbumpc();
 ++__gc_;
 }
-if (__n > 0)
-*__s = char_type();
 if (__gc_ == 0)
__err |= ios_base::failbit;
 this->setstate(__err);
 }
+if (__n > 0)
+*__s = char_type();
 #ifndef _LIBCPP_NO_EXCEPTIONS
 }
 catch (...)
 {
+if (__n > 0)
+*__s = char_type();
 this->__set_badbit_and_consider_rethrow();
 }
 #endif  // _LIBCPP_NO_EXCEPTIONS
-- 
2.14.1

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


[PATCH] D36574: [refactor] add clang-refactor tool with initial testing support and local-rename action

2017-09-08 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 114309.
arphaman marked 2 inline comments as done.
arphaman added a comment.

- rename namespace
- try to further decouple SourceSelectionArgument


Repository:
  rL LLVM

https://reviews.llvm.org/D36574

Files:
  include/clang/Tooling/Refactoring/AtomicChange.h
  include/clang/Tooling/Refactoring/RefactoringAction.h
  include/clang/Tooling/Refactoring/RefactoringActionRegistry.def
  include/clang/Tooling/Refactoring/RefactoringActionRule.h
  include/clang/Tooling/Refactoring/RefactoringActionRuleRequirementsInternal.h
  include/clang/Tooling/Refactoring/RefactoringActionRules.h
  include/clang/Tooling/Refactoring/RefactoringActionRulesInternal.h
  include/clang/Tooling/Refactoring/RefactoringRuleContext.h
  include/clang/Tooling/Refactoring/Rename/USRFindingAction.h
  include/clang/Tooling/Refactoring/SourceSelectionConstraints.h
  include/clang/module.modulemap
  lib/Tooling/Refactoring/AtomicChange.cpp
  lib/Tooling/Refactoring/CMakeLists.txt
  lib/Tooling/Refactoring/RefactoringActions.cpp
  lib/Tooling/Refactoring/Rename/RenamingAction.cpp
  lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
  test/CMakeLists.txt
  test/Refactor/LocalRename/Field.cpp
  test/Refactor/tool-common-options.c
  test/Refactor/tool-test-support.c
  test/clang-rename/Field.cpp
  tools/CMakeLists.txt
  tools/clang-refactor/CMakeLists.txt
  tools/clang-refactor/ClangRefactor.cpp
  tools/clang-refactor/TestSupport.cpp
  tools/clang-refactor/TestSupport.h
  unittests/Tooling/RefactoringActionRulesTest.cpp

Index: unittests/Tooling/RefactoringActionRulesTest.cpp
===
--- unittests/Tooling/RefactoringActionRulesTest.cpp
+++ unittests/Tooling/RefactoringActionRulesTest.cpp
@@ -54,7 +54,8 @@
 
 TEST_F(RefactoringActionRulesTest, MyFirstRefactoringRule) {
   auto ReplaceAWithB =
-  [](std::pair Selection)
+  [](const RefactoringRuleContext &,
+ std::pair Selection)
   -> Expected {
 const SourceManager &SM = Selection.first.getSources();
 SourceLocation Loc = Selection.first.getRange().getBegin().getLocWithOffset(
@@ -68,7 +69,8 @@
   class SelectionRequirement : public selection::Requirement {
   public:
 std::pair
-evaluateSelection(selection::SourceSelectionRange Selection) const {
+evaluateSelection(const RefactoringRuleContext &,
+  selection::SourceSelectionRange Selection) const {
   return std::make_pair(Selection, 20);
 }
   };
@@ -124,8 +126,10 @@
 }
 
 TEST_F(RefactoringActionRulesTest, ReturnError) {
-  Expected (*Func)(selection::SourceSelectionRange) =
-  [](selection::SourceSelectionRange) -> Expected {
+  Expected (*Func)(const RefactoringRuleContext &,
+  selection::SourceSelectionRange) =
+  [](const RefactoringRuleContext &,
+ selection::SourceSelectionRange) -> Expected {
 return llvm::make_error(
 "Error", llvm::make_error_code(llvm::errc::invalid_argument));
   };
@@ -152,13 +156,14 @@
   class SelectionRequirement : public selection::Requirement {
   public:
 Expected>
-evaluateSelection(selection::SourceSelectionRange Selection) const {
+evaluateSelection(const RefactoringRuleContext &,
+  selection::SourceSelectionRange Selection) const {
   return llvm::make_error(
   "bad selection", llvm::make_error_code(llvm::errc::invalid_argument));
 }
   };
   auto Rule = createRefactoringRule(
-  [](int) -> Expected {
+  [](const RefactoringRuleContext &, int) -> Expected {
 llvm::report_fatal_error("Should not run!");
   },
   requiredSelection(SelectionRequirement()));
@@ -195,7 +200,8 @@
 
 TEST_F(RefactoringActionRulesTest, ReturnSymbolOccurrences) {
   auto Rule = createRefactoringRule(
-  [](selection::SourceSelectionRange Selection)
+  [](const RefactoringRuleContext &,
+ selection::SourceSelectionRange Selection)
   -> Expected {
 SymbolOccurrences Occurrences;
 Occurrences.push_back(SymbolOccurrence(
Index: tools/clang-refactor/TestSupport.h
===
--- /dev/null
+++ tools/clang-refactor/TestSupport.h
@@ -0,0 +1,107 @@
+//===--- TestSupport.h - Clang-based refactoring tool ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+///
+/// \file
+/// \brief Declares datatypes and routines that are used by test-specific code
+/// in clang-refactor.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_CLANG_REFACTOR_TEST_SUPPORT_H
+#define LLVM_CLANG_TOOLS_CLANG_REFACTOR_TEST_SUPPORT_H
+
+#include "clang/Basic/LLVM.h"
+#incl

[PATCH] D36574: [refactor] add clang-refactor tool with initial testing support and local-rename action

2017-09-08 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: tools/clang-refactor/ClangRefactor.cpp:62
+  /// \returns true if an error occurred, false otherwise.
+  virtual bool refactorForEachSelection(
+  RefactoringRuleContext &Context,

ioeric wrote:
> I would expect the `SourceSelectionArgument` to be more like a container of 
> ranges and further decoupled with the refactoring logic. Same for the 
> `TestSelectionRangesInFile`.
> 
> How about an interface like this?
> ```
> template 
> void ForAllRanges(T callback) const;
> ```
Not sure I fully understand your interface suggestion, but I've tried to 
decouple some more in the updated patch.


Repository:
  rL LLVM

https://reviews.llvm.org/D36574



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


[PATCH] D36574: [refactor] add clang-refactor tool with initial testing support and local-rename action

2017-09-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.
This revision is now accepted and ready to land.

I think this is ready to go.

@klimek Manuel, are all your concerns addressed?




Comment at: tools/clang-refactor/ClangRefactor.cpp:62
+  /// \returns true if an error occurred, false otherwise.
+  virtual bool refactorForEachSelection(
+  RefactoringRuleContext &Context,

arphaman wrote:
> ioeric wrote:
> > I would expect the `SourceSelectionArgument` to be more like a container of 
> > ranges and further decoupled with the refactoring logic. Same for the 
> > `TestSelectionRangesInFile`.
> > 
> > How about an interface like this?
> > ```
> > template 
> > void ForAllRanges(T callback) const;
> > ```
> Not sure I fully understand your interface suggestion, but I've tried to 
> decouple some more in the updated patch.
Sorry, I should've been more specific about what I had in mind, but what you 
have right now is close.  I think this can be further decoupled a bit by having 
`forAllRanges` take in `SourceManeger` instead of `RefactoringRuleContext` 
since source selection should only care about source ranges.



Comment at: tools/clang-refactor/ClangRefactor.cpp:62
+  virtual void print(raw_ostream &OS) = 0;
+
+  virtual std::unique_ptr createCustomConsumer() {

IIUC, `createCustomConsumer` is used to inject testing behavior into 
clang-refactor. I think this is fine, but please document the intention and the 
behavior. Thanks!


Repository:
  rL LLVM

https://reviews.llvm.org/D36574



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


[PATCH] D36574: [refactor] add clang-refactor tool with initial testing support and local-rename action

2017-09-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Please wait for Manuel's reply before landing the patch ;-)


Repository:
  rL LLVM

https://reviews.llvm.org/D36574



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


[PATCH] D36150: [clangd] LSP extension to switch between source/header file

2017-09-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov requested changes to this revision.
ilya-biryukov added a comment.
This revision now requires changes to proceed.

Just a few more comments. Should be easy to fix.
Could you also please `clang-format` the code?




Comment at: clangd/ClangdLSPServer.cpp:225
+  llvm::Optional Result = 
LangServer.Server.switchSourceHeader(Params.uri.file);
+  Path ResultString = *Result;
+

What if `Result` does not contain a value?



Comment at: clangd/ClangdLSPServer.cpp:225
+  llvm::Optional Result = 
LangServer.Server.switchSourceHeader(Params.uri.file);
+  Path ResultString = *Result;
+

ilya-biryukov wrote:
> What if `Result` does not contain a value?
Use `*Result` instead of introducing an extra variable?



Comment at: clangd/ClangdLSPServer.cpp:229
+R"({"jsonrpc":"2.0","id":)" + ID.str() +
+R"(,"result":)" + ResultString + R"(})");
+}

We should convert paths here. Convert to `URI` and use `unparse`.
```
Uri ResultUri = Uri::fromFile(*Result);
//
R"(,"result":)" + Uri::unparse(ResultUri) + R"(})");
//...
```



Comment at: clangd/ClangdServer.cpp:325
+  // Lookup in a list of known extensions.
+  auto SourceIter = std::find(std::begin(SourceExtensions), 
std::end(SourceExtensions), PathExt);
+  bool IsSource = SourceIter != std::end(SourceExtensions);

Instead of an `checkUpperCaseExtensions` and two iterations use a single 
`find_if` and `equals_lower`:
```
// Checks for both uppercase and lowercase matches in a single loop over 
extensions array.
std::find_if(std::begin(SourceExtensions), std::end(SourceExtensions), 
[](PathRef SourceExt) {
  return SourceExt.equals_lower(PathExt);
});
```





Comment at: clangd/ClangdServer.cpp:363
+{
+  std::string FileHandle = "file://";
+  return "\"" + FileHandle + NewPath.str().str() + "\""; // First str() to 
convert from SmallString to StringRef, second to convert from StringRef to 
std::string

Don't add `"file://"`  or quoting here, simply return `NewPath`.



Comment at: clangd/ClangdServer.h:186
+  /// If an extension hasn't been found in the lowercase array, try with 
uppercase.
+  bool checkUpperCaseExtensions(StringRef BaseArray[], int ArraySize, 
StringRef PathExt);
+

Any reason not to put it into anonymous namespace inside `.cpp` file?



Comment at: clangd/ProtocolHandlers.cpp:214
+if (!TDPP) {
+  return;
+}

Code style: we don't use braces around small single-statement control structures


https://reviews.llvm.org/D36150



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


[PATCH] D37378: [clang] [python] Move test_exception_specification_kind to correct subdir

2017-09-08 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Ping.


Repository:
  rL LLVM

https://reviews.llvm.org/D37378



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


[PATCH] D37150: [clangd] Command line arg to specify compile_commands.json path

2017-09-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Could you also `clang-format` the code please?




Comment at: clangd/ClangdServer.cpp:150
bool RunSynchronously,
+   llvm::Optional CompileCommandsDir,
llvm::Optional ResourceDir)

Remove `CompileCommandsDir` from ClangdServer parameters, it is hanlded by 
`DirectoryBasedGlobalCompilationDatabase`.



Comment at: clangd/GlobalCompilationDatabase.cpp:70
-
-  assert((path::is_absolute(File, path::Style::posix) ||
-  path::is_absolute(File, path::Style::windows)) &&

Restore this assertion, move it to `tryLoadDatabaseFromPath`.



Comment at: clangd/GlobalCompilationDatabase.cpp:84
   namespace path = llvm::sys::path;
-
-  assert((path::is_absolute(File, path::Style::posix) ||
-  path::is_absolute(File, path::Style::windows)) &&
- "path must be absolute");
+  std::string Error;
+  if (!CompileCommandsDir.empty()) {

Maybe move this local variable into `tryLoadDatabaseFromPath` and remove 
`Error` parameter from `tryLoadDatabaseFromPath`?
Please make sure to move the `TODO` about logging into 
`tryLoadDatabaseFromPath` as well.



Comment at: clangd/GlobalCompilationDatabase.cpp:87
+File = CompileCommandsDir;
+File = path::parent_path(File);
+auto CDB = tryLoadDatabaseFromPath(File, Error);

Why do we use `parent_path` of `CompilerCommandsDir`, not `CompilerCommandsDir` 
itself?
Why do we need to reassign the `File` parameter?

Maybe simply do
`auto CDB = tryLoadDatabaseFromPath(CompileCommandsDir, Error)`?



Comment at: clangd/GlobalCompilationDatabase.cpp:92
+  return CDB;
+else
+  return nullptr;

Code style: don't use `else` after `return`.
See https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return



Comment at: clangd/GlobalCompilationDatabase.h:48
 public:
+  DirectoryBasedGlobalCompilationDatabase(Path NewCompileCommandsDir): 
CompileCommandsDir(NewCompileCommandsDir){}
   std::vector

Rename parameter to `CompileCommandsDir`, change type to `llvm::Optional`.



Comment at: clangd/GlobalCompilationDatabase.h:53
   void setExtraFlagsForFile(PathRef File, std::vector ExtraFlags);
+  tooling::CompilationDatabase *tryLoadDatabaseFromPath(PathRef File, 
std::string &Error);
 

Make this function `private`.



Comment at: clangd/tool/ClangdMain.cpp:40
 
+  // If --CompileCommandsDir arg was invoked, check value and override default 
path.
+  namespace path = llvm::sys::path;

Replace `--CompileCommandsDir` with `--compile-commands-dir`.



Comment at: clangd/tool/ClangdMain.cpp:45
+  {
+Logs << "Path specified by --compile-commands-dir must be an absolute 
path. The argument will be ignored.\n";
+CompileCommandsDir = "";

Use `Out.log()` instead of `Logs <<` for consistency with other logging code.



Comment at: clangd/tool/ClangdMain.cpp:51
+  {
+Logs << "File does not exist. The argument will be ignored.\n";
+CompileCommandsDir = "";

Maybe also rephrase to mention the name of the flag? Something like:
`"Path specified by --compile-commands-dir does not exist. The argument will be 
ignored.\n"`



Comment at: clangd/tool/ClangdMain.cpp:58
 
-  ClangdLSPServer LSPServer(Out, RunSynchronously);
+  ClangdLSPServer LSPServer(Out, RunSynchronously, CompileCommandsDir);
   LSPServer.run(std::cin);

Accept `llvm::Optional` in ClangdLSPServer, pass `llvm::None` if 
`CompileCommandsDir == ""` here.


https://reviews.llvm.org/D37150



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


[PATCH] D37101: [clangd] Add support for snippet completions

2017-09-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

Thanks for the change! Looks good minus an outdated description of 
`enable-snippets` flag.
Do you have commit access to llvm repository?




Comment at: clangd/tool/ClangdMain.cpp:31
+EnableSnippets("enable-snippets",
+   llvm::cl::desc("Disable \"snippet\" completions and only "
+  "present plaintext completions."),

Description still mentions `disable-snippets`.


https://reviews.llvm.org/D37101



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


[PATCH] D37513: [clang-format] Fix documentation for AllowAllParametersOfDeclarationOnNextLine

2017-09-08 Thread Lucja Mazur via Phabricator via cfe-commits
LuMa closed this revision.
LuMa added a comment.

Thank you.


https://reviews.llvm.org/D37513



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


r312780 - Fix templated type alias completion when using global completion cache

2017-09-08 Thread Erik Verbruggen via cfe-commits
Author: erikjv
Date: Fri Sep  8 02:31:13 2017
New Revision: 312780

URL: http://llvm.org/viewvc/llvm-project?rev=312780&view=rev
Log:
Fix templated type alias completion when using global completion cache

When we have enabled cache for global completions we did not have
diagnostics for Bar and could not complete Ba as in provided code
example.

template 
struct Foo { T member; };

template using Bar = Foo;

int main() {
   Ba
}

(This is the fixed version of r 311442, which was reverted in r311445.)

Patch by Ivan Donchevskii!

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

Modified:
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Parse/ParseTemplate.cpp
cfe/trunk/test/Index/code-completion.cpp

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=312780&r1=312779&r2=312780&view=diff
==
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Fri Sep  8 02:31:13 2017
@@ -243,7 +243,8 @@ static unsigned getDeclShowContexts(cons
   
   uint64_t Contexts = 0;
   if (isa(ND) || isa(ND) || 
-  isa(ND) || isa(ND)) {
+  isa(ND) || isa(ND) ||
+  isa(ND)) {
 // Types can appear in these contexts.
 if (LangOpts.CPlusPlus || !isa(ND))
   Contexts |= (1LL << CodeCompletionContext::CCC_TopLevel)

Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=312780&r1=312779&r2=312780&view=diff
==
--- cfe/trunk/lib/Parse/ParseTemplate.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTemplate.cpp Fri Sep  8 02:31:13 2017
@@ -197,10 +197,11 @@ Parser::ParseSingleDeclarationAfterTempl
   MaybeParseCXX11Attributes(prefixAttrs);
 
   if (Tok.is(tok::kw_using)) {
-// FIXME: We should return the DeclGroup to the caller.
-ParseUsingDirectiveOrDeclaration(Context, TemplateInfo, DeclEnd,
- prefixAttrs);
-return nullptr;
+auto usingDeclPtr = ParseUsingDirectiveOrDeclaration(Context, 
TemplateInfo, DeclEnd,
+ prefixAttrs);
+if (!usingDeclPtr || !usingDeclPtr.get().isSingleDecl())
+  return nullptr;
+return usingDeclPtr.get().getSingleDecl();
   }
 
   // Parse the declaration specifiers, stealing any diagnostics from

Modified: cfe/trunk/test/Index/code-completion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/code-completion.cpp?rev=312780&r1=312779&r2=312780&view=diff
==
--- cfe/trunk/test/Index/code-completion.cpp (original)
+++ cfe/trunk/test/Index/code-completion.cpp Fri Sep  8 02:31:13 2017
@@ -37,6 +37,16 @@ Z::operator int() const {
   return 0;
 }
 
+template 
+struct Foo { T member; };
+
+template using Bar = Foo;
+
+void test_template_alias() {
+  // RUN: env CINDEXTEST_COMPLETION_CACHING=1 c-index-test 
-code-completion-at=%s:47:1 %s | FileCheck -check-prefix=CHECK-TEMPLATE-ALIAS %s
+
+}
+
 // CHECK-MEMBER: FieldDecl:{ResultType double}{TypedText member}
 // CHECK-MEMBER: FieldDecl:{ResultType int}{Text X::}{TypedText member}
 // CHECK-MEMBER: FieldDecl:{ResultType float}{Text Y::}{TypedText member}
@@ -88,3 +98,5 @@ Z::operator int() const {
 // CHECK-EXPR-NEXT: Class name
 // CHECK-EXPR-NEXT: Nested name specifier
 // CHECK-EXPR-NEXT: Objective-C interface
+
+// CHECK-TEMPLATE-ALIAS: AliasTemplateDecl:{TypedText Bar}{LeftAngle 
<}{Placeholder typename T}{RightAngle >} (50)


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


[PATCH] D33719: Add _Float16 as a C/C++ source language type

2017-09-08 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added a comment.

Many thanks for reviewing and your help!


https://reviews.llvm.org/D33719



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


[PATCH] D37378: [clang] [python] Move test_exception_specification_kind to correct subdir

2017-09-08 Thread Andrew J. Bennieston via Phabricator via cfe-commits
ajbennieston accepted this revision.
ajbennieston added a comment.
This revision is now accepted and ready to land.

Looks good to me.


Repository:
  rL LLVM

https://reviews.llvm.org/D37378



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


r312781 - Add _Float16 as a C/C++ source language type

2017-09-08 Thread Sjoerd Meijer via cfe-commits
Author: sjoerdmeijer
Date: Fri Sep  8 02:42:32 2017
New Revision: 312781

URL: http://llvm.org/viewvc/llvm-project?rev=312781&view=rev
Log:
Add _Float16 as a C/C++ source language type

This adds _Float16 as a source language type, which is a 16-bit floating point
type defined in C11 extension ISO/IEC TS 18661-3.

In follow up patches documentation and more tests will be added.

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

Added:
cfe/trunk/test/CodeGenCXX/float16-declarations.cpp
cfe/trunk/test/Frontend/float16.cpp
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/BuiltinTypes.def
cfe/trunk/include/clang/Basic/Specifiers.h
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/include/clang/Lex/LiteralSupport.h
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/lib/AST/NSAPI.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/AST/TypeLoc.cpp
cfe/trunk/lib/Analysis/PrintfFormatString.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/Format/FormatToken.cpp
cfe/trunk/lib/Index/USRGeneration.cpp
cfe/trunk/lib/Lex/LiteralSupport.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Serialization/ASTCommon.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/test/Lexer/half-literal.cpp
cfe/trunk/tools/libclang/CXType.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=312781&r1=312780&r2=312781&view=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Fri Sep  8 02:42:32 2017
@@ -3115,8 +3115,9 @@ enum CXTypeKind {
   CXType_ObjCSel = 29,
   CXType_Float128 = 30,
   CXType_Half = 31,
+  CXType_Float16 = 32,
   CXType_FirstBuiltin = CXType_Void,
-  CXType_LastBuiltin  = CXType_Half,
+  CXType_LastBuiltin  = CXType_Float16,
 
   CXType_Complex = 100,
   CXType_Pointer = 101,

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=312781&r1=312780&r2=312781&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Sep  8 02:42:32 2017
@@ -973,6 +973,7 @@ public:
   CanQualType UnsignedLongLongTy, UnsignedInt128Ty;
   CanQualType FloatTy, DoubleTy, LongDoubleTy, Float128Ty;
   CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
+  CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3
   CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
   CanQualType Float128ComplexTy;
   CanQualType VoidPtrTy, NullPtrTy;

Modified: cfe/trunk/include/clang/AST/BuiltinTypes.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/BuiltinTypes.def?rev=312781&r1=312780&r2=312781&view=diff
==
--- cfe/trunk/include/clang/AST/BuiltinTypes.def (original)
+++ cfe/trunk/include/clang/AST/BuiltinTypes.def Fri Sep  8 02:42:32 2017
@@ -133,6 +133,9 @@ FLOATING_TYPE(Double, DoubleTy)
 // 'long double'
 FLOATING_TYPE(LongDouble, LongDoubleTy)
 
+// '_Float16'
+FLOATING_TYPE(Float16, HalfTy)
+
 // '__float128'
 FLOATING_TYPE(Float128, Float128Ty)
 

Modified: cfe/trunk/include/clang/Basic/Specifiers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Specifiers.h?rev=312781&r1=312780&r2=312781&view=diff
==
--- cfe/trunk/include/clang/Basic/Specifiers.h (original)
+++ cfe/trunk/include/clang/Basic/Specifiers.h Fri Sep  8 02:42:32 2017
@@ -52,6 +52,7 @@ namespace clang {
 TST_int,
 TST_int128,
 TST_half, // OpenCL half, ARM NEON __fp16
+TST_Float16,  // C11 extension ISO/IEC TS 18661-3
 TST_float,
 TST_double,
 TST_float128,

Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=312781&r1=312780&r2=312781&view=diff
==
--- cfe/trunk

[PATCH] D33719: Add _Float16 as a C/C++ source language type

2017-09-08 Thread Sjoerd Meijer via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL312781: Add _Float16 as a C/C++ source language type 
(authored by SjoerdMeijer).

Changed prior to commit:
  https://reviews.llvm.org/D33719?vs=113218&id=114325#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33719

Files:
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/include/clang/AST/ASTContext.h
  cfe/trunk/include/clang/AST/BuiltinTypes.def
  cfe/trunk/include/clang/Basic/Specifiers.h
  cfe/trunk/include/clang/Basic/TokenKinds.def
  cfe/trunk/include/clang/Lex/LiteralSupport.h
  cfe/trunk/include/clang/Sema/DeclSpec.h
  cfe/trunk/include/clang/Serialization/ASTBitCodes.h
  cfe/trunk/lib/AST/ASTContext.cpp
  cfe/trunk/lib/AST/ItaniumMangle.cpp
  cfe/trunk/lib/AST/MicrosoftMangle.cpp
  cfe/trunk/lib/AST/NSAPI.cpp
  cfe/trunk/lib/AST/StmtPrinter.cpp
  cfe/trunk/lib/AST/Type.cpp
  cfe/trunk/lib/AST/TypeLoc.cpp
  cfe/trunk/lib/Analysis/PrintfFormatString.cpp
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/lib/CodeGen/CGExprScalar.cpp
  cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
  cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
  cfe/trunk/lib/Format/FormatToken.cpp
  cfe/trunk/lib/Index/USRGeneration.cpp
  cfe/trunk/lib/Lex/LiteralSupport.cpp
  cfe/trunk/lib/Parse/ParseDecl.cpp
  cfe/trunk/lib/Parse/ParseExpr.cpp
  cfe/trunk/lib/Parse/ParseExprCXX.cpp
  cfe/trunk/lib/Parse/ParseTentative.cpp
  cfe/trunk/lib/Sema/DeclSpec.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/lib/Serialization/ASTCommon.cpp
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/test/CodeGenCXX/float16-declarations.cpp
  cfe/trunk/test/Frontend/float16.cpp
  cfe/trunk/test/Lexer/half-literal.cpp
  cfe/trunk/tools/libclang/CXType.cpp

Index: cfe/trunk/include/clang-c/Index.h
===
--- cfe/trunk/include/clang-c/Index.h
+++ cfe/trunk/include/clang-c/Index.h
@@ -3115,8 +3115,9 @@
   CXType_ObjCSel = 29,
   CXType_Float128 = 30,
   CXType_Half = 31,
+  CXType_Float16 = 32,
   CXType_FirstBuiltin = CXType_Void,
-  CXType_LastBuiltin  = CXType_Half,
+  CXType_LastBuiltin  = CXType_Float16,
 
   CXType_Complex = 100,
   CXType_Pointer = 101,
Index: cfe/trunk/include/clang/Lex/LiteralSupport.h
===
--- cfe/trunk/include/clang/Lex/LiteralSupport.h
+++ cfe/trunk/include/clang/Lex/LiteralSupport.h
@@ -65,6 +65,7 @@
   bool isHalf : 1;  // 1.0h
   bool isFloat : 1; // 1.0f
   bool isImaginary : 1; // 1.0i
+  bool isFloat16 : 1;   // 1.0f16
   bool isFloat128 : 1;  // 1.0q
   uint8_t MicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64.
 
Index: cfe/trunk/include/clang/AST/BuiltinTypes.def
===
--- cfe/trunk/include/clang/AST/BuiltinTypes.def
+++ cfe/trunk/include/clang/AST/BuiltinTypes.def
@@ -133,6 +133,9 @@
 // 'long double'
 FLOATING_TYPE(LongDouble, LongDoubleTy)
 
+// '_Float16'
+FLOATING_TYPE(Float16, HalfTy)
+
 // '__float128'
 FLOATING_TYPE(Float128, Float128Ty)
 
Index: cfe/trunk/include/clang/AST/ASTContext.h
===
--- cfe/trunk/include/clang/AST/ASTContext.h
+++ cfe/trunk/include/clang/AST/ASTContext.h
@@ -973,6 +973,7 @@
   CanQualType UnsignedLongLongTy, UnsignedInt128Ty;
   CanQualType FloatTy, DoubleTy, LongDoubleTy, Float128Ty;
   CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
+  CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3
   CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
   CanQualType Float128ComplexTy;
   CanQualType VoidPtrTy, NullPtrTy;
Index: cfe/trunk/include/clang/Sema/DeclSpec.h
===
--- cfe/trunk/include/clang/Sema/DeclSpec.h
+++ cfe/trunk/include/clang/Sema/DeclSpec.h
@@ -280,6 +280,7 @@
   static const TST TST_half = clang::TST_half;
   static const TST TST_float = clang::TST_float;
   static const TST TST_double = clang::TST_double;
+  static const TST TST_float16 = clang::TST_Float16;
   static const TST TST_float128 = clang::TST_float128;
   static const TST TST_bool = clang::TST_bool;
   static const TST TST_decimal32 = clang::TST_decimal32;
Index: cfe/trunk/include/clang/Basic/TokenKinds.def
===
--- cfe/trunk/include/clang/Basic/TokenKinds.def
+++ cfe/trunk/include/clang/Basic/TokenKinds.def
@@ -379,6 +379,9 @@
 MODULES_KEYWORD(module)
 MODULES_KEYWORD(import)
 
+// C11 Extension
+KEYWORD(_Float16, KEYALL)
+
 // GNU Extensions (in impl-reserved namespace)
 KEYWORD(_Decimal32  , KEYALL)
 KEYWORD(_Decimal64  , KEYALL)
Index: cfe/trunk/include/clang/Basic/Specifiers.h
=

[PATCH] D37618: Use CommonOptionsParser in clang-refactor

2017-09-08 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.

This patch ensures that CommonOptionsParser works with subcommands. This allows 
clang-refactor to use the `CommonOptionsParser`.

Depends on https://reviews.llvm.org/D36574.


Repository:
  rL LLVM

https://reviews.llvm.org/D37618

Files:
  lib/Tooling/CommonOptionsParser.cpp
  test/Refactor/LocalRename/Field.cpp
  test/Refactor/tool-common-options.c
  tools/clang-refactor/ClangRefactor.cpp

Index: tools/clang-refactor/ClangRefactor.cpp
===
--- tools/clang-refactor/ClangRefactor.cpp
+++ tools/clang-refactor/ClangRefactor.cpp
@@ -15,6 +15,7 @@
 
 #include "TestSupport.h"
 #include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Refactoring.h"
 #include "clang/Tooling/Refactoring/RefactoringAction.h"
 #include "clang/Tooling/Refactoring/Rename/RenamingAction.h"
@@ -33,12 +34,6 @@
 
 static cl::OptionCategory CommonRefactorOptions("Common refactoring options");
 
-static cl::opt
-NoDatabases("no-dbs",
-cl::desc("Ignore external databases including Clang's "
- "compilation database and indexer stores"),
-cl::cat(CommonRefactorOptions), cl::sub(*cl::AllSubCommands));
-
 static cl::opt Verbose("v", cl::desc("Use verbose output"),
  cl::cat(CommonRefactorOptions),
  cl::sub(*cl::AllSubCommands));
@@ -122,10 +117,6 @@
   cl::OptionCategory &Category)
   : SubCommand(Action->getCommand(), Action->getDescription()),
 Action(std::move(Action)), ActionRules(std::move(ActionRules)) {
-Sources = llvm::make_unique>(
-cl::Positional, cl::ZeroOrMore, cl::desc(" [... ]"),
-cl::cat(Category), cl::sub(*this));
-
 // Check if the selection option is supported.
 bool HasSelection = false;
 for (const auto &Rule : this->ActionRules) {
@@ -162,13 +153,9 @@
 assert(Selection && "selection not supported!");
 return ParsedSelection.get();
   }
-
-  ArrayRef getSources() const { return *Sources; }
-
 private:
   std::unique_ptr Action;
   RefactoringActionRules ActionRules;
-  std::unique_ptr> Sources;
   std::unique_ptr> Selection;
   std::unique_ptr ParsedSelection;
 };
@@ -214,20 +201,9 @@
   /// Parses the translation units that were given to the subcommand using
   /// the 'sources' option and invokes the callback for each parsed
   /// translation unit.
-  bool foreachTranslationUnit(RefactoringActionSubcommand &Subcommand,
+  bool foreachTranslationUnit(const CompilationDatabase &DB,
+  ArrayRef Sources,
   TUCallbackType Callback) {
-std::unique_ptr Compilations;
-if (opts::NoDatabases) {
-  // FIXME (Alex L): Support compilation options.
-  Compilations =
-  llvm::make_unique(
-  ".", std::vector());
-} else {
-  // FIXME (Alex L): Support compilation database.
-  llvm::errs() << "compilation databases are not supported yet!\n";
-  return true;
-}
-
 class ToolASTConsumer : public ASTConsumer {
 public:
   TUCallbackType Callback;
@@ -247,7 +223,7 @@
   }
 };
 
-ClangTool Tool(*Compilations, Subcommand.getSources());
+ClangTool Tool(DB, Sources);
 ActionWrapper ToolAction(std::move(Callback));
 std::unique_ptr Factory =
 tooling::newFrontendActionFactory(&ToolAction);
@@ -270,7 +246,9 @@
 }
   }
 
-  bool invokeAction(RefactoringActionSubcommand &Subcommand) {
+  bool invokeAction(RefactoringActionSubcommand &Subcommand,
+const CompilationDatabase &DB,
+ArrayRef Sources) {
 // Find a set of matching rules.
 SmallVector MatchingRules;
 llvm::StringSet<> MissingOptions;
@@ -296,7 +274,7 @@
 
 bool HasFailed = false;
 ClangRefactorConsumer Consumer;
-if (foreachTranslationUnit(Subcommand, [&](ASTContext &AST) {
+if (foreachTranslationUnit(DB, Sources, [&](ASTContext &AST) {
   RefactoringRuleContext Context(AST.getSourceManager());
   Context.setASTContext(AST);
 
@@ -340,12 +318,9 @@
 int main(int argc, const char **argv) {
   ClangRefactorTool Tool;
 
-  // FIXME: Use LibTooling's CommonOptions parser when subcommands are supported
-  // by it.
-  cl::HideUnrelatedOptions(opts::CommonRefactorOptions);
-  cl::ParseCommandLineOptions(
-  argc, argv, "Clang-based refactoring tool for C, C++ and Objective-C");
-  cl::PrintOptionValues();
+  CommonOptionsParser Options(
+  argc, argv, opts::CommonRefactorOptions, cl::ZeroOrMore,
+  "Clang-based refactoring tool for C, C++ and Objective-C");
 
   // Figure out which action is specified by the user. The user must specify
   // the action using a command-line subcommand, e.g. the invocation
@@ -367,17 +342,10 @@
   }
   RefactoringActionSubcommand &ActionCommand = **It;
 
-  ArrayRef Sour

[PATCH] D34878: [ARM] Option for reading thread pointer from coprocessor register

2017-09-08 Thread Strahinja Petrovic via Phabricator via cfe-commits
spetrovic marked 3 inline comments as done.
spetrovic added inline comments.



Comment at: include/clang/Driver/Options.td:1664-1665
   HelpText<"Allow generation of data access to code sections (ARM only)">;
+def mtp_mode_EQ : Joined<["-"], "mtp=">, Group, 
Values<"soft, cp15">,
+  HelpText<"Read thread pointer from coprocessor register (ARM only)">;
 def mpure_code : Flag<["-"], "mpure-code">, Alias; // Alias for 
GCC compatibility

kristof.beyls wrote:
> Looking at the gcc documentation for this option 
> (https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html), gcc accepts 3 values: 
> 'soft', 'cp15' and 'auto', with the default setting being 'auto'.
> This patch implements just 2 of those values: 'soft' and 'cp15'.
> I think this is fine, as long as the default value is 'soft'.
> The 'auto' value should automatically pick 'cp15' if that's going to work on 
> what you're targeting. If I understood correctly, that depends both on the 
> architecture version you're targeting and the operating system/kernel you're 
> targeting. So, there could be a lot of details to go through to get 'auto' 
> right in all cases. Which is why I think it's fine to leave an implementation 
> of 'auto' for later.
> Is the default value 'soft'?
I agree with your opinion about 'auto'. If -mtp option is not specified, yes, 
default value is soft.



Comment at: lib/Driver/ToolChains/Arch/ARM.cpp:128
+  const Driver &D = TC.getDriver();
+  arm::ReadTPMode ThreadPointer = ReadTPMode::Invalid;
+  if (Arg *A =

kristof.beyls wrote:
> Wouldn't it be better to default to ReadTPMode::Soft when not -mtp command 
> line option is given? 
When there is no -mtp in command line ReadTPMode::Soft is default value, 
ReadTPMode::Invalid is in case when someone try to put in -mtp value that is 
not cp15 or soft (e.g. -mtp=x).



Comment at: lib/Driver/ToolChains/Arch/ARM.cpp:145-146
+  // choose soft mode.
+  if (ThreadPointer == ReadTPMode::Invalid)
+ThreadPointer = ReadTPMode::Soft;
+  return ThreadPointer;

kristof.beyls wrote:
>  and always give an error if an invalid mtp command line option was 
> given, rather than default back to soft mode?
If 'mtp' takes invalid value, error is always provided. This is the case when 
there is no -mtp option in command line, you can see how the case of invalid 
mtp argument is handled in the code above.



Comment at: lib/Driver/ToolChains/Clang.cpp:1348-1358
+  arm::ReadTPMode ThreadPointer = arm::getReadTPMode(getToolChain(), Args);
+  if (ThreadPointer == arm::ReadTPMode::Cp15) {
+CmdArgs.push_back("-mtp");
+CmdArgs.push_back("cp15");
+  } else {
+assert(ThreadPointer == arm::ReadTPMode::Soft &&
+   "Invalid mode for reading thread pointer");

kristof.beyls wrote:
> My inexperience in this part of the code base is probably showing, but why is 
> this needed at all?
> IIUC, in D34408, you modelled TPMode in the backend using a target feature, 
> and there isn't a custom -mtp option there?
> Maybe this is left-over code from an earlier revision of D34408, that's no 
> longer needed?
Well, actually you are right, we can remove this part of the code, I was 
thinking that maybe someone in future will need in backend that '-mtp' option 
also can be recgonized, so I added this, but you are right, I will remove this.



Comment at: test/Driver/clang-translation.c:78-82
+// RUN: %clang -target arm-linux -mtp=cp15 -### -S %s -arch armv7 2>&1 | \
+// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER %s
+// ARMv7_THREAD_POINTER: "-target-feature" "+read-tp-hard"
+// ARMv7_THREAD_POINTER: "-mtp" "cp15"
+// ARMv7_THREAD_POINTER-NOT: "mtp" "soft"

kristof.beyls wrote:
> It probably would be good to also have a test that when no mtp option is 
> given, the equivalent of when '-mtp soft' is specified would happen.
> Furthermore, my inexperience in this part of the code base probably shows, 
> but I'm puzzled as to why this test is looking for '-mtp' in the output. 
> Wouldn't the '-target-feature +read-tp-hard' be enough to convey the 
> information to the mid- and back-end?
Checks for '-mtp' in the output are unnecessary when we remove part of the code 
that you mentioned in previous comment.


Repository:
  rL LLVM

https://reviews.llvm.org/D34878



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


[PATCH] D34878: [ARM] Option for reading thread pointer from coprocessor register

2017-09-08 Thread Strahinja Petrovic via Phabricator via cfe-commits
spetrovic updated this revision to Diff 114329.
spetrovic marked 3 inline comments as done.

https://reviews.llvm.org/D34878

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Arch/ARM.cpp
  lib/Driver/ToolChains/Arch/ARM.h
  test/Driver/clang-translation.c

Index: test/Driver/clang-translation.c
===
--- test/Driver/clang-translation.c
+++ test/Driver/clang-translation.c
@@ -87,6 +87,18 @@
 // ARMV5E: "-cc1"
 // ARMV5E: "-target-cpu" "arm1022e"
 
+// RUN: %clang -target arm-linux -mtp=cp15 -### -S %s -arch armv7 2>&1 | \
+// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER-HARD %s
+// ARMv7_THREAD_POINTER-HARD: "-target-feature" "+read-tp-hard"
+
+// RUN: %clang -target arm-linux -mtp=soft -### -S %s -arch armv7 2>&1 | \
+// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_SOFT %s
+// ARMv7_THREAD_POINTER_SOFT-NOT: "-target-feature" "+read-tp-hard"
+
+// RUN: %clang -target arm-linux -### -S %s -arch armv7 2>&1 | \
+// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_NON %s
+// ARMv7_THREAD_POINTER_NON-NOT: "-target-feature" "+read-tp-hard"
+
 // RUN: %clang -target powerpc64-unknown-linux-gnu \
 // RUN: -### -S %s -mcpu=G5 2>&1 | FileCheck -check-prefix=PPCG5 %s
 // PPCG5: clang
Index: lib/Driver/ToolChains/Arch/ARM.h
===
--- lib/Driver/ToolChains/Arch/ARM.h
+++ lib/Driver/ToolChains/Arch/ARM.h
@@ -32,14 +32,21 @@
 void appendEBLinkFlags(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs,
const llvm::Triple &Triple);
+enum class ReadTPMode {
+  Invalid,
+  Soft,
+  Cp15,
+};
+
 enum class FloatABI {
   Invalid,
   Soft,
   SoftFP,
   Hard,
 };
 
 FloatABI getARMFloatABI(const ToolChain &TC, const llvm::opt::ArgList &Args);
+ReadTPMode getReadTPMode(const ToolChain &TC, const llvm::opt::ArgList &Args);
 
 bool useAAPCSForMachO(const llvm::Triple &T);
 void getARMArchCPUFromArgs(const llvm::opt::ArgList &Args,
Index: lib/Driver/ToolChains/Arch/ARM.cpp
===
--- lib/Driver/ToolChains/Arch/ARM.cpp
+++ lib/Driver/ToolChains/Arch/ARM.cpp
@@ -131,6 +131,31 @@
  T.getOS() == llvm::Triple::UnknownOS || isARMMProfile(T);
 }
 
+// Select mode for reading thread pointer (-mtp=soft/cp15).
+arm::ReadTPMode arm::getReadTPMode(const ToolChain &TC, const ArgList &Args) {
+  const Driver &D = TC.getDriver();
+  arm::ReadTPMode ThreadPointer = ReadTPMode::Invalid;
+  if (Arg *A =
+  Args.getLastArg(options::OPT_mtp_mode_EQ)) {
+ThreadPointer = llvm::StringSwitch(A->getValue())
+.Case("cp15", ReadTPMode::Cp15)
+.Case("soft", ReadTPMode::Soft)
+.Default(ReadTPMode::Invalid);
+if (ThreadPointer == ReadTPMode::Invalid) {
+  if (StringRef(A->getValue()).empty())
+D.Diag(diag::err_drv_missing_arg_mtp) << A->getAsString(Args);
+  else
+D.Diag(diag::err_drv_invalid_mtp) << A->getAsString(Args);
+}
+  }
+  
+  // If -mtp option not specified or takes invalid/empty argument 
+  // choose soft mode.
+  if (ThreadPointer == ReadTPMode::Invalid)
+ThreadPointer = ReadTPMode::Soft;
+  return ThreadPointer;
+}
+
 // Select the float ABI as determined by -msoft-float, -mhard-float, and
 // -mfloat-abi=.
 arm::FloatABI arm::getARMFloatABI(const ToolChain &TC, const ArgList &Args) {
@@ -262,6 +287,7 @@
   bool KernelOrKext =
   Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
   arm::FloatABI ABI = arm::getARMFloatABI(TC, Args);
+  arm::ReadTPMode ThreadPointer = arm::getReadTPMode(TC, Args);
   const Arg *WaCPU = nullptr, *WaFPU = nullptr;
   const Arg *WaHDiv = nullptr, *WaArch = nullptr;
 
@@ -303,6 +329,10 @@
 }
   }
 
+
+  if (ThreadPointer == arm::ReadTPMode::Cp15)
+Features.push_back("+read-tp-hard");
+
   // Check -march. ClangAs gives preference to -Wa,-march=.
   const Arg *ArchArg = Args.getLastArg(options::OPT_march_EQ);
   StringRef ArchName;
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1689,6 +1689,8 @@
   HelpText<"Disallow generation of data access to code sections (ARM only)">;
 def mno_execute_only : Flag<["-"], "mno-execute-only">, Group,
   HelpText<"Allow generation of data access to code sections (ARM only)">;
+def mtp_mode_EQ : Joined<["-"], "mtp=">, Group, Values<"soft, cp15">,
+  HelpText<"Read thread pointer from coprocessor register (ARM only)">;
 def mpure_code : Flag<["-"], "mpure-code">, Alias; // Alias for GCC compatibility
 def mno_pure_code : Flag<["-"], "mno-pure-code">, Alias;
 def mtvos_version_min_EQ : Joined<["-"], "mtvos-version-min=">, Group;
Index: include/clang/Driver/

[PATCH] D36390: Fix overloaded static functions in SemaCodeComplete

2017-09-08 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

one more ping :)


https://reviews.llvm.org/D36390



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


[PATCH] D37378: [clang] [python] Move test_exception_specification_kind to correct subdir

2017-09-08 Thread Michał Górny via Phabricator via cfe-commits
mgorny closed this revision.
mgorny added a comment.

It seems that somebody already moved the file in 
https://reviews.llvm.org/D37490.


Repository:
  rL LLVM

https://reviews.llvm.org/D37378



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


[PATCH] D37618: Use CommonOptionsParser in clang-refactor

2017-09-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.
This revision is now accepted and ready to land.

Lgtm


Repository:
  rL LLVM

https://reviews.llvm.org/D37618



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


r312784 - Revert "Add _Float16 as a C/C++ source language type"

2017-09-08 Thread Sjoerd Meijer via cfe-commits
Author: sjoerdmeijer
Date: Fri Sep  8 03:20:52 2017
New Revision: 312784

URL: http://llvm.org/viewvc/llvm-project?rev=312784&view=rev
Log:
Revert "Add _Float16 as a C/C++ source language type"

The clang-with-lto-ubuntu bot didn't like the new regression
test, revert while I investigate the issue.

Removed:
cfe/trunk/test/CodeGenCXX/float16-declarations.cpp
cfe/trunk/test/Frontend/float16.cpp
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/BuiltinTypes.def
cfe/trunk/include/clang/Basic/Specifiers.h
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/include/clang/Lex/LiteralSupport.h
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/lib/AST/NSAPI.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/AST/TypeLoc.cpp
cfe/trunk/lib/Analysis/PrintfFormatString.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/Format/FormatToken.cpp
cfe/trunk/lib/Index/USRGeneration.cpp
cfe/trunk/lib/Lex/LiteralSupport.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Serialization/ASTCommon.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/test/Lexer/half-literal.cpp
cfe/trunk/tools/libclang/CXType.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=312784&r1=312783&r2=312784&view=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Fri Sep  8 03:20:52 2017
@@ -3115,9 +3115,8 @@ enum CXTypeKind {
   CXType_ObjCSel = 29,
   CXType_Float128 = 30,
   CXType_Half = 31,
-  CXType_Float16 = 32,
   CXType_FirstBuiltin = CXType_Void,
-  CXType_LastBuiltin  = CXType_Float16,
+  CXType_LastBuiltin  = CXType_Half,
 
   CXType_Complex = 100,
   CXType_Pointer = 101,

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=312784&r1=312783&r2=312784&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Sep  8 03:20:52 2017
@@ -973,7 +973,6 @@ public:
   CanQualType UnsignedLongLongTy, UnsignedInt128Ty;
   CanQualType FloatTy, DoubleTy, LongDoubleTy, Float128Ty;
   CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
-  CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3
   CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
   CanQualType Float128ComplexTy;
   CanQualType VoidPtrTy, NullPtrTy;

Modified: cfe/trunk/include/clang/AST/BuiltinTypes.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/BuiltinTypes.def?rev=312784&r1=312783&r2=312784&view=diff
==
--- cfe/trunk/include/clang/AST/BuiltinTypes.def (original)
+++ cfe/trunk/include/clang/AST/BuiltinTypes.def Fri Sep  8 03:20:52 2017
@@ -133,9 +133,6 @@ FLOATING_TYPE(Double, DoubleTy)
 // 'long double'
 FLOATING_TYPE(LongDouble, LongDoubleTy)
 
-// '_Float16'
-FLOATING_TYPE(Float16, HalfTy)
-
 // '__float128'
 FLOATING_TYPE(Float128, Float128Ty)
 

Modified: cfe/trunk/include/clang/Basic/Specifiers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Specifiers.h?rev=312784&r1=312783&r2=312784&view=diff
==
--- cfe/trunk/include/clang/Basic/Specifiers.h (original)
+++ cfe/trunk/include/clang/Basic/Specifiers.h Fri Sep  8 03:20:52 2017
@@ -52,7 +52,6 @@ namespace clang {
 TST_int,
 TST_int128,
 TST_half, // OpenCL half, ARM NEON __fp16
-TST_Float16,  // C11 extension ISO/IEC TS 18661-3
 TST_float,
 TST_double,
 TST_float128,

Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=312784&r1=312783&r2=312784&view=diff
==
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Fri Sep  8 03:20:52 2017
@@ -379,9 +379

r312785 - Don't show deleted function (constructor) candidates for code completion

2017-09-08 Thread Erik Verbruggen via cfe-commits
Author: erikjv
Date: Fri Sep  8 03:23:08 2017
New Revision: 312785

URL: http://llvm.org/viewvc/llvm-project?rev=312785&view=rev
Log:
Don't show deleted function (constructor) candidates for code completion

In case of copy constructor is implicitly deleted it's still shown.
PR34402 describes a way to reproduce that.

Patch by Ivan Donchevskii!

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

Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/test/Index/complete-constructor-params.cpp

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=312785&r1=312784&r2=312785&view=diff
==
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Fri Sep  8 03:23:08 2017
@@ -4286,9 +4286,12 @@ static void mergeCandidatesWithResults(S
 });
 
 // Add the remaining viable overload candidates as code-completion results.
-for (auto &Candidate : CandidateSet)
+for (auto &Candidate : CandidateSet) {
+  if (Candidate.Function && Candidate.Function->isDeleted())
+continue;
   if (Candidate.Viable)
 Results.push_back(ResultCandidate(Candidate.Function));
+}
   }
 }
 

Modified: cfe/trunk/test/Index/complete-constructor-params.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-constructor-params.cpp?rev=312785&r1=312784&r2=312785&view=diff
==
--- cfe/trunk/test/Index/complete-constructor-params.cpp (original)
+++ cfe/trunk/test/Index/complete-constructor-params.cpp Fri Sep  8 03:23:08 
2017
@@ -18,6 +18,20 @@ int main() {
   int(42);
 }
 
+struct Foo {
+Foo() = default;
+Foo(const Foo&) = delete;
+};
+
+struct Bar {
+Foo f;
+};
+
+void function() {
+Bar b1;
+Bar b2(b1);
+}
+
 // RUN: c-index-test -code-completion-at=%s:11:10 %s | FileCheck 
-check-prefix=CHECK-CC1 %s
 // CHECK-CC1: OverloadCandidate:{Text S}{LeftParen (}{CurrentParameter const 
S &}{RightParen )} (1)
 // CHECK-CC1: OverloadCandidate:{Text S}{LeftParen (}{CurrentParameter 
int}{Comma , }{Placeholder U}{Comma , }{Placeholder U}{RightParen )} (1)
@@ -138,3 +152,6 @@ int main() {
 // CHECK-CC10-NEXT: Class name
 // CHECK-CC10-NEXT: Nested name specifier
 // CHECK-CC10-NEXT: Objective-C interface
+
+// RUN: c-index-test -code-completion-at=%s:32:12 -std=c++11 %s | FileCheck 
-check-prefix=CHECK-CC11 %s
+// CHECK-CC11-NOT: OverloadCandidate:{Text Bar}{LeftParen (}{CurrentParameter 
const Bar &}{RightParen )} (1)


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


[PATCH] D35082: [OpenCL] Add LangAS::opencl_private to represent private address space in AST

2017-09-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 6 inline comments as done.
yaxunl added inline comments.



Comment at: include/clang/AST/Type.h:332
 
+  bool getImplicitAddressSpaceFlag() const { return Mask & IMask; }
+  void setImplicitAddressSpaceFlag(bool Value) {

Anastasia wrote:
> Could we add a bit of comment somewhere explaining why we added implicit AS 
> flag please.
Will do.



Comment at: lib/AST/Expr.cpp:3254
+// Only (void*)0 or equivalent are treated as nullptr. If pointee type
+// has non-default address space it is not treated as nullptr.
+bool PointeeHasDefaultAS = false;

Anastasia wrote:
> Is this comment right wrt to named address spaces. So is `(private void*)0` 
> not a `nullptr`?
Yes this will be true.

Neither (private void*)0 nor (__generic void*)0 should be treated nullptr since 
they cannot be assigned to a constant pointer.

This need some change below to check implicity of the address space. I will do 
that. Also add more tests about this.



Comment at: lib/Sema/SemaType.cpp:6994
+  // OpenCL v1.2 s6.5:
+  // The generic address space name for arguments to a function in a
+  // program, or local variables of a function is __private. All function

Anastasia wrote:
> The generic address space -> The default address space
'The generic address space name for arguments' is literally from the OpenCL 1.2 
spec. Note it refers 'generic address space name', which is not the 'generic 
address space' defined by OpenCL 2.0 spec.


https://reviews.llvm.org/D35082



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


[PATCH] D35082: [OpenCL] Add LangAS::opencl_private to represent private address space in AST

2017-09-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 114337.
yaxunl marked 3 inline comments as done.
yaxunl edited the summary of this revision.
yaxunl added a comment.

Add comments for getImplicitAddressSpaceFlag and fix checking of null pointer.


https://reviews.llvm.org/D35082

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Type.h
  include/clang/Basic/AddressSpaces.h
  lib/AST/ASTContext.cpp
  lib/AST/Expr.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets/AMDGPU.cpp
  lib/Basic/Targets/NVPTX.h
  lib/Basic/Targets/SPIR.h
  lib/Basic/Targets/TCE.h
  lib/CodeGen/CGDecl.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCL/address-spaces-mangling.cl
  test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
  test/SemaOpenCL/address-spaces.cl
  test/SemaOpenCL/atomic-ops.cl
  test/SemaOpenCL/cl20-device-side-enqueue.cl
  test/SemaOpenCL/invalid-block.cl
  test/SemaOpenCL/invalid-pipes-cl2.0.cl
  test/SemaOpenCL/null_literal.cl

Index: test/SemaOpenCL/null_literal.cl
===
--- test/SemaOpenCL/null_literal.cl
+++ test/SemaOpenCL/null_literal.cl
@@ -1,29 +1,68 @@
 // RUN: %clang_cc1 -verify %s
-// RUN: %clang_cc1 -cl-std=CL2.0 -DCL20 -verify %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -verify %s
 
 #define NULL ((void*)0)
 
 void foo(){
+  global int *g1 = NULL;
+  global int *g2 = (global void *)0;
+  global int *g3 = (constant void *)0; // expected-error{{initializing '__global int *' with an expression of type '__constant void *' changes address space of pointer}}
+  global int *g4 = (local void *)0; // expected-error{{initializing '__global int *' with an expression of type '__local void *' changes address space of pointer}}
+  global int *g5 = (private void *)0; // expected-error{{initializing '__global int *' with an expression of type '__private void *' changes address space of pointer}}
 
-global int* ptr1 = NULL;
+  constant int *c1 = NULL;
+  constant int *c2 = (global void *)0; // expected-error{{initializing '__constant int *' with an expression of type '__global void *' changes address space of pointer}}
+  constant int *c3 = (constant void *)0;
+  constant int *c4 = (local void *)0; // expected-error{{initializing '__constant int *' with an expression of type '__local void *' changes address space of pointer}}
+  constant int *c5 = (private void *)0; // expected-error{{initializing '__constant int *' with an expression of type '__private void *' changes address space of pointer}}
 
-global int* ptr2 = (global void*)0;
+  local int *l1 = NULL;
+  local int *l2 = (global void *)0; // expected-error{{initializing '__local int *' with an expression of type '__global void *' changes address space of pointer}}
+  local int *l3 = (constant void *)0; // expected-error{{initializing '__local int *' with an expression of type '__constant void *' changes address space of pointer}}
+  local int *l4 = (local void *)0;
+  local int *l5 = (private void *)0; // expected-error{{initializing '__local int *' with an expression of type '__private void *' changes address space of pointer}}
 
-constant int* ptr3 = NULL;
+  private int *p1 = NULL;
+  private int *p2 = (global void *)0; // expected-error{{initializing '__private int *' with an expression of type '__global void *' changes address space of pointer}}
+  private int *p3 = (constant void *)0; // expected-error{{initializing '__private int *' with an expression of type '__constant void *' changes address space of pointer}}
+  private int *p4 = (local void *)0; // expected-error{{initializing '__private int *' with an expression of type '__local void *' changes address space of pointer}}
+  private int *p5 = (private void *)0;
 
-constant int* ptr4 = (global void*)0; // expected-error{{initializing '__constant int *' with an expression of type '__global void *' changes address space of pointer}}
+#if __OPENCL_C_VERSION__ >= 200
+  // Assigning a pointer to a pointer to narrower address space causes an error unless there is an valid explicit cast.
+  global int *g6 = (generic void *)0; // expected-error{{initializing '__global int *' with an expression of type '__generic void *' changes address space of pointer}}
+  constant int *c6 = (generic void *)0; // expected-error{{initializing '__constant int *' with an expression of type '__generic void *' changes address space of pointer}}
+  local int *l6 = (generic void *)0; // expected-error{{initializing '__local int *' with an expression of type '__generic void *' changes address space of pointer}}
+  private int *p6 = (generic void *)0; // expected-error{{initializing '__private int *' with an expression of type '__generic void *' changes address space of pointer}}
 
-#ifdef CL20
-// Accept explicitly pointer to generic address space in OpenCL v2.0.
-global int* ptr5 = (generic void*)0;
-#endif
-
-global int* ptr6 = (local void*)0; // expected-error{{initializing '__global int *' with an 

[PATCH] D37491: [Preamble] Fixed preamble breaking with BOM presence (and particularly, fluctuating BOM presence)

2017-09-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Parsing errors on preamble additions and removals are definitely bad and should 
be fixed. 
But I would argue that the right approach is to invalidate the preamble and 
rebuild it on BOM changes.

Current fix in `ASTUnit` just hides an error in the underlying APIs. For 
example, all other other clients of `PrecompiledPreamble` are still broken.




Comment at: lib/Frontend/ASTUnit.cpp:1262
+  // This ensures offsets within and past the preamble stay valid.
+  if (MainFileBuffer->getBuffer().startswith("\xEF\xBB\xBF")) {
+MainFileBuffer = llvm::MemoryBuffer::getMemBufferSlice(

It seems that having only this chunk would fix your issue.
Everything else is just a non-functional refactoring, maybe let's focus on that 
part (and tests) in this review and send the rest as a separate change?
To keep refactoring and functional changes logically separate.


https://reviews.llvm.org/D37491



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


[PATCH] D37254: [Sema] Disallow assigning record lvalues with nested const-qualified fields.

2017-09-08 Thread Bevin Hansson via Phabricator via cfe-commits
bevinh updated this revision to Diff 114340.
bevinh marked an inline comment as done.
bevinh added a comment.

Added a diag note for NestedConstMember.


https://reviews.llvm.org/D37254

Files:
  include/clang/AST/Expr.h
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/ExprClassification.cpp
  lib/AST/Type.cpp
  lib/Sema/SemaExpr.cpp
  test/Sema/assign.c

Index: test/Sema/assign.c
===
--- test/Sema/assign.c
+++ test/Sema/assign.c
@@ -16,3 +16,46 @@
   b[4] = 1; // expected-error {{read-only variable is not assignable}}
   b2[4] = 1; // expected-error {{read-only variable is not assignable}}
 }
+
+typedef struct I {
+  const int a; // expected-note 4{{nested data member 'a' declared const here}} \
+  expected-note 6{{data member 'a' declared const here}}
+} I;
+typedef struct J {
+  struct I i;
+} J;
+typedef struct K {
+  struct J *j;
+} K;
+
+void testI(struct I i1, struct I i2) {
+  i1 = i2; // expected-error {{cannot assign to variable 'i1' with const-qualified data member 'a'}}
+}
+void testJ1(struct J j1, struct J j2) {
+  j1 = j2; // expected-error {{cannot assign to variable 'j1' with nested const-qualified data member 'a'}}
+}
+void testJ2(struct J j, struct I i) {
+  j.i = i; // expected-error {{cannot assign to non-static data member 'i' with const-qualified data member 'a'}}
+}
+void testK1(struct K k, struct J j) {
+  *(k.j) = j; // expected-error {{cannot assign to lvalue with nested const-qualified data member 'a'}}
+}
+void testK2(struct K k, struct I i) {
+  k.j->i = i; // expected-error {{cannot assign to non-static data member 'i' with const-qualified data member 'a'}}
+}
+
+void testI_(I i1, I i2) {
+  i1 = i2; // expected-error {{cannot assign to variable 'i1' with const-qualified data member 'a'}}
+}
+void testJ1_(J j1, J j2) {
+  j1 = j2; // expected-error {{cannot assign to variable 'j1' with nested const-qualified data member 'a'}}
+}
+void testJ2_(J j, I i) {
+  j.i = i; // expected-error {{cannot assign to non-static data member 'i' with const-qualified data member 'a'}}
+}
+void testK1_(K k, J j) {
+  *(k.j) = j; // expected-error {{cannot assign to lvalue with nested const-qualified data member 'a'}}
+}
+void testK2_(K k, I i) {
+  k.j->i = i; // expected-error {{cannot assign to non-static data member 'i' with const-qualified data member 'a'}}
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10176,22 +10176,23 @@
   return !Ty.isConstQualified();
 }
 
+// Update err_typecheck_assign_const and note_typecheck_assign_const
+// when this enum is changed.
+enum {
+  ConstFunction,
+  ConstVariable,
+  ConstMember,
+  ConstMethod,
+  NestedConstMember,
+  ConstUnknown,  // Keep as last element
+};
+
 /// Emit the "read-only variable not assignable" error and print notes to give
 /// more information about why the variable is not assignable, such as pointing
 /// to the declaration of a const variable, showing that a method is const, or
 /// that the function is returning a const reference.
 static void DiagnoseConstAssignment(Sema &S, const Expr *E,
 SourceLocation Loc) {
-  // Update err_typecheck_assign_const and note_typecheck_assign_const
-  // when this enum is changed.
-  enum {
-ConstFunction,
-ConstVariable,
-ConstMember,
-ConstMethod,
-ConstUnknown,  // Keep as last element
-  };
-
   SourceRange ExprRange = E->getSourceRange();
 
   // Only emit one error on the first const found.  All other consts will emit
@@ -10301,6 +10302,66 @@
   S.Diag(Loc, diag::err_typecheck_assign_const) << ExprRange << ConstUnknown;
 }
 
+enum OriginalExprKind {
+  OEK_Variable,
+  OEK_Member,
+  OEK_LValue
+};
+
+static void DiagnoseRecursiveConstFields(Sema &S, const ValueDecl *VD,
+ const RecordType *Ty,
+ SourceLocation Loc, SourceRange Range,
+ OriginalExprKind OEK,
+ bool &DiagnosticEmitted,
+ bool IsNested = false) {
+  // We walk the record hierarchy breadth-first to ensure that we print
+  // diagnostics in field nesting order.
+  // First, check every field for constness.
+  for (const FieldDecl *Field : Ty->getDecl()->fields()) {
+if (Field->getType().isConstQualified()) {
+  if (!DiagnosticEmitted) {
+S.Diag(Loc, diag::err_typecheck_assign_const)
+<< Range << NestedConstMember << OEK << VD
+<< IsNested << Field;
+DiagnosticEmitted = true;
+  }
+  S.Diag(Field->getLocation(), diag::note_typecheck_assign_const)
+  << NestedConstMember << IsNested << Field
+  << Field->getType() << Field->getSourceRange();
+}
+  }
+  // Then, recurse.
+  for (con

Re: r312750 - [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

2017-09-08 Thread Sam McCall via cfe-commits
Nice fix! It catches a lot of new cases on our codebase, all technically
correct so far.

A couple of issues though:
A) Rollout - until we've completely cleaned up, we need to disable
-Wtautological-compare entirely, which is a valuable check. I imagine
anyone else using -Werror is in the same boat.
What do you think about putting the new warnings behind a subcategory?
(e.g. -Wtautological-compare-unsigned-zero, implied by
-Wtautological-compare)
It's an ugly artifact of the history here, but allows this fix to be rolled
out in a controlled way.

B) Enums (not new I guess). Typical case: if (enum < 0 || enum > MAX)
The warning strongly suggests that the enum < 0 check has no effect (for
enums with nonnegative ranges).
Clang doesn't seem to optimize such checks out though, and they seem likely
to catch bugs in some cases. Yes, only if there's UB elsewhere, but I
assume not optimizing out these checks indicates a deliberate decision to
stay somewhat compatible with a technically-incorrect mental model.
If this is the case, should we move these to a -Wtautological-compare-enum
subcategory?

On Fri, Sep 8, 2017 at 12:14 AM, Roman Lebedev via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: lebedevri
> Date: Thu Sep  7 15:14:25 2017
> New Revision: 312750
>
> URL: http://llvm.org/viewvc/llvm-project?rev=312750&view=rev
> Log:
> [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.
>
> Summary:
> This is a first half(?) of a fix for the following bug:
> https://bugs.llvm.org/show_bug.cgi?id=34147 (gcc -Wtype-limits)
>
> GCC's -Wtype-limits does warn on comparison of unsigned value
> with signed zero (as in, with 0), but clang only warns if the
> zero is unsigned (i.e. 0U).
>
> Also, be careful not to double-warn, or falsely warn on
> comparison of signed/fp variable and signed 0.
>
> Yes, all these testcases are needed.
>
> Testing: $ ninja check-clang-sema check-clang-semacxx
> Also, no new warnings for clang stage-2 build.
>
> Reviewers: rjmccall, rsmith, aaron.ballman
>
> Reviewed By: rjmccall
>
> Subscribers: cfe-commits
>
> Tags: #clang
>
> Differential Revision: https://reviews.llvm.org/D37565
>
> Modified:
> cfe/trunk/docs/ReleaseNotes.rst
> cfe/trunk/lib/Sema/SemaChecking.cpp
> cfe/trunk/test/Sema/compare.c
> cfe/trunk/test/Sema/outof-range-constant-compare.c
> cfe/trunk/test/SemaCXX/compare.cpp
>
> Modified: cfe/trunk/docs/ReleaseNotes.rst
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/
> ReleaseNotes.rst?rev=312750&r1=312749&r2=312750&view=diff
> 
> ==
> --- cfe/trunk/docs/ReleaseNotes.rst (original)
> +++ cfe/trunk/docs/ReleaseNotes.rst Thu Sep  7 15:14:25 2017
> @@ -71,6 +71,13 @@ Improvements to Clang's diagnostics
>errors/warnings, as the system frameworks might add a method with the
> same
>selector which could make the message send to ``id`` ambiguous.
>
> +- ``-Wtautological-compare`` now warns when comparing an unsigned integer
> and 0
> +  regardless of whether the constant is signed or unsigned."
> +
> +- ``-Wtautological-compare`` now warns about comparing a signed integer
> and 0
> +  when the signed integer is coerced to an unsigned type for the
> comparison.
> +  ``-Wsign-compare`` was adjusted not to warn in this case.
> +
>  Non-comprehensive list of changes in this release
>  -
>
>
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaChecking.cpp?rev=312750&r1=312749&r2=312750&view=diff
> 
> ==
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Sep  7 15:14:25 2017
> @@ -8567,32 +8567,51 @@ bool HasEnumType(Expr *E) {
>return E->getType()->isEnumeralType();
>  }
>
> -void CheckTrivialUnsignedComparison(Sema &S, BinaryOperator *E) {
> +bool isNonBooleanUnsignedValue(Expr *E) {
> +  // We are checking that the expression is not known to have boolean
> value,
> +  // is an integer type; and is either unsigned after implicit casts,
> +  // or was unsigned before implicit casts.
> +  return !E->isKnownToHaveBooleanValue() &&
> E->getType()->isIntegerType() &&
> + (!E->getType()->isSignedIntegerType() ||
> +  !E->IgnoreParenImpCasts()->getType()->isSignedIntegerType());
> +}
> +
> +bool CheckTautologicalComparisonWithZero(Sema &S, BinaryOperator *E) {
>// Disable warning in template instantiations.
>if (S.inTemplateInstantiation())
> -return;
> +return false;
> +
> +  // bool values are handled by DiagnoseOutOfRangeComparison().
>
>BinaryOperatorKind op = E->getOpcode();
>if (E->isValueDependent())
> -return;
> +return false;
>
> -  if (op == BO_LT && IsZero(S, E->getRHS())) {
> +  Expr *LHS = E->getLHS();
> +  Expr *RHS = E->getRHS();
> +
> +  bool Match = true;
> +
> 

[libcxx] r312774 - XFAIL tests on SLES11

2017-09-08 Thread Brian Cain via cfe-commits
Author: bcain
Date: Thu Sep  7 20:57:02 2017
New Revision: 312774

URL: http://llvm.org/viewvc/llvm-project?rev=312774&view=rev
Log:
XFAIL tests on SLES11

XFAIL some failing tests for SLES11 (older glibc), also replace spaces
in linux distro w/dashes.


Modified:
libcxx/trunk/test/std/depr/depr.c.headers/uchar_h.pass.cpp

libcxx/trunk/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/generic_category.pass.cpp

libcxx/trunk/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp
libcxx/trunk/utils/libcxx/test/target_info.py

Modified: libcxx/trunk/test/std/depr/depr.c.headers/uchar_h.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/depr/depr.c.headers/uchar_h.pass.cpp?rev=312774&r1=312773&r2=312774&view=diff
==
--- libcxx/trunk/test/std/depr/depr.c.headers/uchar_h.pass.cpp (original)
+++ libcxx/trunk/test/std/depr/depr.c.headers/uchar_h.pass.cpp Thu Sep  7 
20:57:02 2017
@@ -7,6 +7,7 @@
 //
 
//===--===//
 //
+// XFAIL: suse-linux-enterprise-server-11
 // XFAIL: apple-darwin
 // XFAIL: newlib
 

Modified: 
libcxx/trunk/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/generic_category.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/generic_category.pass.cpp?rev=312774&r1=312773&r2=312774&view=diff
==
--- 
libcxx/trunk/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/generic_category.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/generic_category.pass.cpp
 Thu Sep  7 20:57:02 2017
@@ -7,6 +7,7 @@
 //
 
//===--===//
 
+// XFAIL: suse-linux-enterprise-server-11
 // XFAIL: with_system_cxx_lib=macosx10.12
 // XFAIL: with_system_cxx_lib=macosx10.11
 // XFAIL: with_system_cxx_lib=macosx10.10

Modified: 
libcxx/trunk/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp?rev=312774&r1=312773&r2=312774&view=diff
==
--- 
libcxx/trunk/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp
 Thu Sep  7 20:57:02 2017
@@ -13,6 +13,7 @@
 
 // const error_category& system_category();
 
+// XFAIL: suse-linux-enterprise-server-11
 // XFAIL: with_system_cxx_lib=macosx10.12
 // XFAIL: with_system_cxx_lib=macosx10.11
 // XFAIL: with_system_cxx_lib=macosx10.10

Modified: libcxx/trunk/utils/libcxx/test/target_info.py
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/utils/libcxx/test/target_info.py?rev=312774&r1=312773&r2=312774&view=diff
==
--- libcxx/trunk/utils/libcxx/test/target_info.py (original)
+++ libcxx/trunk/utils/libcxx/test/target_info.py Thu Sep  7 20:57:02 2017
@@ -190,12 +190,14 @@ class LinuxLocalTI(DefaultTargetInfo):
 
 def platform_name(self):
 name, _, _ = platform.linux_distribution()
-name = name.lower().strip()
+# Some distros have spaces, e.g. 'SUSE Linux Enterprise Server'
+# lit features can't have spaces
+name = name.lower().strip().replace(' ', '-')
 return name # Permitted to be None
 
 def platform_ver(self):
 _, ver, _ = platform.linux_distribution()
-ver = ver.lower().strip()
+ver = ver.lower().strip().replace(' ', '-')
 return ver # Permitted to be None.
 
 def add_locale_features(self, features):


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


[PATCH] D31140: [LLVMbugs] [Bug 18710] Only generate .ARM.exidx and .ARM.extab when needed in EHABI

2017-09-08 Thread Christian Bruel via Phabricator via cfe-commits
chrib planned changes to this revision.
chrib added a comment.

Yes, I also tried to look into this direction, but I did not found a clean way 
from the driver to emit the attribute based on codegen options. Also 
unwind-tables must not be the default. (for C this is what I want to 
eliminate). In fact I haven't found an example of setting attributes in the 
driver. not sure it's even possible.

Also, setting this new uwtable attribute close to the existing NoUnwind 
attribute in CodeGen makes the orthogonality both attributes more obvious (or 
less obscure :-).

This said, testing for the Triple Arch here is not clean (I probably prefer a 
target overloads) but that was a conservative approach. to avoid that we would 
need to propose a follow up that simplifies the code as:

  // We might need an unwind table, even if the function cannot throw.  


   
  if (hasUnwindExceptions(LangOpts) || CodeGenOpts.UnwindTables)
B.addAttribute(llvm::Attribute::UWTable);
  
  // If the module doesn't support exceptions the function cannot throw.


   
  // We can have a nothrow function even if unwind tables are required. 


   
  if (!hasUnwindExceptions(LangOpts))
B.addAttribute(llvm::Attribute::NoUnwind);

but this will impact all targets and can cause other changes in the backend, so 
it's probably better to do this separately. Do you have an advice on that ?

thanks,


https://reviews.llvm.org/D31140



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


[PATCH] D37474: [PCH] Allow VFS to be used for tests that generate PCH files

2017-09-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In https://reviews.llvm.org/D37474#863335, @cameron314 wrote:

> Looking at the way remapped buffers are handled, I just remembered that they 
> must exist on the file system (at the very least, in a directory that exists) 
> or the remapping is not taken into account. So that pretty much rules out the 
> other approach, I think.


You are right, thanks for pointing this out. Fiddling with `VFS` seems like an 
only option.




Comment at: lib/Frontend/ASTUnit.cpp:1014
+/// with another virtual file system.
+class PCHOverlayFileSystem : public vfs::FileSystem
+{

Maybe create a combination of `InMemoryFileSystem` and `OverlayFileSystem` 
instead of custom filtering implementation?
We really need to read only a single file given that `ASTUnit` never creates 
directory PCHs.
I bet it would make the code simpler and less error-prone.



Comment at: lib/Frontend/ASTUnit.cpp:1090
+  IntrusiveRefCntPtr RealFS = vfs::getRealFileSystem();
+  if (OverrideMainBuffer && VFS && RealFS && VFS != RealFS) {
+// We have a slight inconsistency here -- we're using the VFS to

Maybe create a PCH overlay only when `!VFS->exists(/*PreamblePath...*/)`?
This seems like a good enough indication that `RealFS` is underneath the 
`vfs::FileSystem` instance, even if pointer equality does not hold (i.e. in 
case of overlays over `RealFS`).



Comment at: unittests/Frontend/CMakeLists.txt:9
   CodeGenActionTest.cpp
+  PchPreambleTest.cpp
   )

Maybe rename to `PCHPreambleTest`?
LLVM code generally capitalizes all letters in abbreviations.


https://reviews.llvm.org/D37474



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


Re: r312750 - [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

2017-09-08 Thread Roman Lebedev via cfe-commits
On Fri, Sep 8, 2017 at 2:48 PM, Sam McCall  wrote:
Hi.

> Nice fix!
Thank you!

> It catches a lot of new cases on our codebase, all technically
> correct so far.
>
> A couple of issues though:
> A) Rollout - until we've completely cleaned up, we need to disable
> -Wtautological-compare entirely, which is a valuable check. I imagine anyone
> else using -Werror is in the same boat.
> What do you think about putting the new warnings behind a subcategory? (e.g.
> -Wtautological-compare-unsigned-zero, implied by -Wtautological-compare)
> It's an ugly artifact of the history here, but allows this fix to be rolled
> out in a controlled way.
https://reviews.llvm.org/D37620

> B) Enums (not new I guess). Typical case: if (enum < 0 || enum > MAX)
> The warning strongly suggests that the enum < 0 check has no effect (for
> enums with nonnegative ranges).
> Clang doesn't seem to optimize such checks out though, and they seem likely
> to catch bugs in some cases. Yes, only if there's UB elsewhere, but I assume
> not optimizing out these checks indicates a deliberate decision to stay
> somewhat compatible with a technically-incorrect mental model.
> If this is the case, should we move these to a -Wtautological-compare-enum
> subcategory?
(Did not look at this yet)

Roman.

> On Fri, Sep 8, 2017 at 12:14 AM, Roman Lebedev via cfe-commits
>  wrote:
>>
>> Author: lebedevri
>> Date: Thu Sep  7 15:14:25 2017
>> New Revision: 312750
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=312750&view=rev
>> Log:
>> [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.
>>
>> Summary:
>> This is a first half(?) of a fix for the following bug:
>> https://bugs.llvm.org/show_bug.cgi?id=34147 (gcc -Wtype-limits)
>>
>> GCC's -Wtype-limits does warn on comparison of unsigned value
>> with signed zero (as in, with 0), but clang only warns if the
>> zero is unsigned (i.e. 0U).
>>
>> Also, be careful not to double-warn, or falsely warn on
>> comparison of signed/fp variable and signed 0.
>>
>> Yes, all these testcases are needed.
>>
>> Testing: $ ninja check-clang-sema check-clang-semacxx
>> Also, no new warnings for clang stage-2 build.
>>
>> Reviewers: rjmccall, rsmith, aaron.ballman
>>
>> Reviewed By: rjmccall
>>
>> Subscribers: cfe-commits
>>
>> Tags: #clang
>>
>> Differential Revision: https://reviews.llvm.org/D37565
>>
>> Modified:
>> cfe/trunk/docs/ReleaseNotes.rst
>> cfe/trunk/lib/Sema/SemaChecking.cpp
>> cfe/trunk/test/Sema/compare.c
>> cfe/trunk/test/Sema/outof-range-constant-compare.c
>> cfe/trunk/test/SemaCXX/compare.cpp
>>
>> Modified: cfe/trunk/docs/ReleaseNotes.rst
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=312750&r1=312749&r2=312750&view=diff
>>
>> ==
>> --- cfe/trunk/docs/ReleaseNotes.rst (original)
>> +++ cfe/trunk/docs/ReleaseNotes.rst Thu Sep  7 15:14:25 2017
>> @@ -71,6 +71,13 @@ Improvements to Clang's diagnostics
>>errors/warnings, as the system frameworks might add a method with the
>> same
>>selector which could make the message send to ``id`` ambiguous.
>>
>> +- ``-Wtautological-compare`` now warns when comparing an unsigned integer
>> and 0
>> +  regardless of whether the constant is signed or unsigned."
>> +
>> +- ``-Wtautological-compare`` now warns about comparing a signed integer
>> and 0
>> +  when the signed integer is coerced to an unsigned type for the
>> comparison.
>> +  ``-Wsign-compare`` was adjusted not to warn in this case.
>> +
>>  Non-comprehensive list of changes in this release
>>  -
>>
>>
>> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=312750&r1=312749&r2=312750&view=diff
>>
>> ==
>> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Sep  7 15:14:25 2017
>> @@ -8567,32 +8567,51 @@ bool HasEnumType(Expr *E) {
>>return E->getType()->isEnumeralType();
>>  }
>>
>> -void CheckTrivialUnsignedComparison(Sema &S, BinaryOperator *E) {
>> +bool isNonBooleanUnsignedValue(Expr *E) {
>> +  // We are checking that the expression is not known to have boolean
>> value,
>> +  // is an integer type; and is either unsigned after implicit casts,
>> +  // or was unsigned before implicit casts.
>> +  return !E->isKnownToHaveBooleanValue() && E->getType()->isIntegerType()
>> &&
>> + (!E->getType()->isSignedIntegerType() ||
>> +  !E->IgnoreParenImpCasts()->getType()->isSignedIntegerType());
>> +}
>> +
>> +bool CheckTautologicalComparisonWithZero(Sema &S, BinaryOperator *E) {
>>// Disable warning in template instantiations.
>>if (S.inTemplateInstantiation())
>> -return;
>> +return false;
>> +
>> +  // bool values are handled by DiagnoseOutOfRangeComparison().
>>
>>Binary

[PATCH] D37620: [Sema] Put tautological comparison of unsigned and zero into it's own flag

2017-09-08 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri created this revision.
lebedev.ri added a project: clang.

As requested by Sam McCall.

  $ /build/llvm-build-Clang-release/./bin/clang -c 
/build/clang/test/Sema/outof-range-constant-compare.c 
/build/clang/test/Sema/outof-range-constant-compare.c:40:11: warning: 
comparison of unsigned expression < 0 is always false 
[-Wtautological-unsigned-zero-compare]
  if (a < 0xUL) // expected-warning {{comparison of 
unsigned expression < 0 is always false}}
  ~ ^ 

Does this need test?


Repository:
  rL LLVM

https://reviews.llvm.org/D37620

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td


Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -5898,14 +5898,14 @@
   InGroup, DefaultIgnore;
 def warn_lunsigned_always_true_comparison : Warning<
   "comparison of unsigned%select{| enum}2 expression %0 is always %1">,
-  InGroup;
+  InGroup;
 def warn_out_of_range_compare : Warning<
   "comparison of %select{constant %0|true|false}1 with " 
   "%select{expression of type %2|boolean expression}3 is always "
   "%select{false|true}4">, InGroup;
 def warn_runsigned_always_true_comparison : Warning<
   "comparison of %0 unsigned%select{| enum}2 expression is always %1">,
-  InGroup;
+  InGroup;
 def warn_comparison_of_mixed_enum_types : Warning<
   "comparison of two values with different enumeration types"
   "%diff{ ($ and $)|}0,1">,
Index: include/clang/Basic/DiagnosticGroups.td
===
--- include/clang/Basic/DiagnosticGroups.td
+++ include/clang/Basic/DiagnosticGroups.td
@@ -427,12 +427,14 @@
 def StringPlusInt : DiagGroup<"string-plus-int">;
 def StringPlusChar : DiagGroup<"string-plus-char">;
 def StrncatSize : DiagGroup<"strncat-size">;
+def TautologicalUnsignedZeroCompare : 
DiagGroup<"tautological-unsigned-zero-compare">;
 def TautologicalOutOfRangeCompare : 
DiagGroup<"tautological-constant-out-of-range-compare">;
 def TautologicalPointerCompare : DiagGroup<"tautological-pointer-compare">;
 def TautologicalOverlapCompare : DiagGroup<"tautological-overlap-compare">;
 def TautologicalUndefinedCompare : DiagGroup<"tautological-undefined-compare">;
 def TautologicalCompare : DiagGroup<"tautological-compare",
-[TautologicalOutOfRangeCompare,
+[TautologicalUnsignedZeroCompare,
+ TautologicalOutOfRangeCompare,
  TautologicalPointerCompare,
  TautologicalOverlapCompare,
  TautologicalUndefinedCompare]>;


Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -5898,14 +5898,14 @@
   InGroup, DefaultIgnore;
 def warn_lunsigned_always_true_comparison : Warning<
   "comparison of unsigned%select{| enum}2 expression %0 is always %1">,
-  InGroup;
+  InGroup;
 def warn_out_of_range_compare : Warning<
   "comparison of %select{constant %0|true|false}1 with " 
   "%select{expression of type %2|boolean expression}3 is always "
   "%select{false|true}4">, InGroup;
 def warn_runsigned_always_true_comparison : Warning<
   "comparison of %0 unsigned%select{| enum}2 expression is always %1">,
-  InGroup;
+  InGroup;
 def warn_comparison_of_mixed_enum_types : Warning<
   "comparison of two values with different enumeration types"
   "%diff{ ($ and $)|}0,1">,
Index: include/clang/Basic/DiagnosticGroups.td
===
--- include/clang/Basic/DiagnosticGroups.td
+++ include/clang/Basic/DiagnosticGroups.td
@@ -427,12 +427,14 @@
 def StringPlusInt : DiagGroup<"string-plus-int">;
 def StringPlusChar : DiagGroup<"string-plus-char">;
 def StrncatSize : DiagGroup<"strncat-size">;
+def TautologicalUnsignedZeroCompare : DiagGroup<"tautological-unsigned-zero-compare">;
 def TautologicalOutOfRangeCompare : DiagGroup<"tautological-constant-out-of-range-compare">;
 def TautologicalPointerCompare : DiagGroup<"tautological-pointer-compare">;
 def TautologicalOverlapCompare : DiagGroup<"tautological-overlap-compare">;
 def TautologicalUndefinedCompare : DiagGroup<"tautological-undefined-compare">;
 def TautologicalCompare : DiagGroup<"tautological-compare",
-[TautologicalOutOfRangeCompare,
+[TautologicalUnsignedZeroCompare,
+ TautologicalOutOfRangeCompare,
  TautologicalPointerCompare,
  TautologicalOverlapCompare,

[PATCH] D37491: [Preamble] Fixed preamble breaking with BOM presence (and particularly, fluctuating BOM presence)

2017-09-08 Thread Erik Verbruggen via Phabricator via cfe-commits
erikjv added a comment.

Will this fix PR25023 and PR21144?


https://reviews.llvm.org/D37491



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


[PATCH] D37620: [Sema] Put tautological comparison of unsigned and zero into it's own flag

2017-09-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

> Does this need test?

Yes, it does -- I'd add one with two RUN lines, one with the flag and one 
without it to make sure you only get the diagnostics in one case.


Repository:
  rL LLVM

https://reviews.llvm.org/D37620



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


[PATCH] D36672: [clang-tidy] readability-non-const-parameter: fixit on all function declarations

2017-09-08 Thread Anders Rönnholm via Phabricator via cfe-commits
AndersRonnholm updated this revision to Diff 114346.
AndersRonnholm added a comment.
Herald added subscribers: xazax.hun, JDevlieghere.

Fixed comments


Repository:
  rL LLVM

https://reviews.llvm.org/D36672

Files:
  clang-tidy/readability/NonConstParameterCheck.cpp
  test/clang-tidy/readability-non-const-parameter.cpp


Index: test/clang-tidy/readability-non-const-parameter.cpp
===
--- test/clang-tidy/readability-non-const-parameter.cpp
+++ test/clang-tidy/readability-non-const-parameter.cpp
@@ -277,3 +277,26 @@
 int x = *p;
   }
 };
+
+int declarationFixit(int *i);
+// CHECK-FIXES: {{^}}int declarationFixit(const int *i);{{$}}
+int declarationFixit(int *i);
+// CHECK-FIXES: {{^}}int declarationFixit(const int *i);{{$}}
+// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: pointer parameter 'i' can be
+int declarationFixit(int *i) {
+  // CHECK-FIXES: {{^}}int declarationFixit(const int *i) {{{$}}
+  return *i;
+}
+
+
+class D {
+private:
+  int declarationFixit(int *i);
+  // CHECK-FIXES: {{^}}  int declarationFixit(const int *i);{{$}}
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'i' can be
+int D::declarationFixit(int *i) {
+  // CHECK-FIXES: {{^}}int declarationFixit(const int *i) {{{$}}
+  return *i;
+}
Index: clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tidy/readability/NonConstParameterCheck.cpp
@@ -138,9 +138,20 @@
 if (!ParamInfo.CanBeConst)
   continue;
 
-diag(Par->getLocation(), "pointer parameter '%0' can be pointer to const")
-<< Par->getName()
-<< FixItHint::CreateInsertion(Par->getLocStart(), "const ");
+auto D = diag(Par->getLocation(),
+  "pointer parameter '%0' can be pointer to const")
+ << Par->getName()
+ << FixItHint::CreateInsertion(Par->getLocStart(), "const ");
+
+const DeclContext *Parent = Par->getParentFunctionOrMethod();
+const auto *FD = dyn_cast(Parent);
+while (FD) {
+  const auto ParDecl = FD->getParamDecl(Par->getFunctionScopeIndex());
+  if (Par != ParDecl)
+D << ParDecl->getName()
+  << FixItHint::CreateInsertion(ParDecl->getLocStart(), "const ");
+  FD = FD->getPreviousDecl();
+}
   }
 }
 


Index: test/clang-tidy/readability-non-const-parameter.cpp
===
--- test/clang-tidy/readability-non-const-parameter.cpp
+++ test/clang-tidy/readability-non-const-parameter.cpp
@@ -277,3 +277,26 @@
 int x = *p;
   }
 };
+
+int declarationFixit(int *i);
+// CHECK-FIXES: {{^}}int declarationFixit(const int *i);{{$}}
+int declarationFixit(int *i);
+// CHECK-FIXES: {{^}}int declarationFixit(const int *i);{{$}}
+// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: pointer parameter 'i' can be
+int declarationFixit(int *i) {
+  // CHECK-FIXES: {{^}}int declarationFixit(const int *i) {{{$}}
+  return *i;
+}
+
+
+class D {
+private:
+  int declarationFixit(int *i);
+  // CHECK-FIXES: {{^}}  int declarationFixit(const int *i);{{$}}
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'i' can be
+int D::declarationFixit(int *i) {
+  // CHECK-FIXES: {{^}}int declarationFixit(const int *i) {{{$}}
+  return *i;
+}
Index: clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tidy/readability/NonConstParameterCheck.cpp
@@ -138,9 +138,20 @@
 if (!ParamInfo.CanBeConst)
   continue;
 
-diag(Par->getLocation(), "pointer parameter '%0' can be pointer to const")
-<< Par->getName()
-<< FixItHint::CreateInsertion(Par->getLocStart(), "const ");
+auto D = diag(Par->getLocation(),
+  "pointer parameter '%0' can be pointer to const")
+ << Par->getName()
+ << FixItHint::CreateInsertion(Par->getLocStart(), "const ");
+
+const DeclContext *Parent = Par->getParentFunctionOrMethod();
+const auto *FD = dyn_cast(Parent);
+while (FD) {
+  const auto ParDecl = FD->getParamDecl(Par->getFunctionScopeIndex());
+  if (Par != ParDecl)
+D << ParDecl->getName()
+  << FixItHint::CreateInsertion(ParDecl->getLocStart(), "const ");
+  FD = FD->getPreviousDecl();
+}
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36672: [clang-tidy] readability-non-const-parameter: fixit on all function declarations

2017-09-08 Thread Anders Rönnholm via Phabricator via cfe-commits
AndersRonnholm marked 2 inline comments as done.
AndersRonnholm added inline comments.



Comment at: clang-tidy/readability/NonConstParameterCheck.cpp:147
+if (const auto *Parent = Par->getParentFunctionOrMethod()) {
+  if (const auto *F = dyn_cast(Parent)) {
+const auto ParDecl =

aaron.ballman wrote:
> What if the parent is an `ObjCMethodDecl` instead?
I don't think this checker handles objective-c


Repository:
  rL LLVM

https://reviews.llvm.org/D36672



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


[PATCH] D37620: [Sema] Put tautological comparison of unsigned and zero into it's own flag

2017-09-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks!
Unless I'm missing something, the current patch just adds the category, but 
doesn't actually recategorize the warning, right?


Repository:
  rL LLVM

https://reviews.llvm.org/D37620



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


[PATCH] D37382: Fixed a crash in code completion.

2017-09-08 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

lg


https://reviews.llvm.org/D37382



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


[PATCH] D37620: [Sema] Put tautological comparison of unsigned and zero into it's own flag

2017-09-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D37620#864684, @sammccall wrote:

> Thanks!
>  Unless I'm missing something, the current patch just adds the category, but 
> doesn't actually recategorize the warning, right?


The diagnostics in DiagnosticSemaKinds.td are changed to be in the new group.


Repository:
  rL LLVM

https://reviews.llvm.org/D37620



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


[PATCH] D37620: [Sema] Put tautological comparison of unsigned and zero into it's own flag

2017-09-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Right, of course.

Thanks and LG, but clearly also get a review from someone more familiar with 
the code (I'm just a buildcop)


Repository:
  rL LLVM

https://reviews.llvm.org/D37620



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


[PATCH] D37620: [Sema] Put tautological comparison of unsigned and zero into it's own flag

2017-09-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

The bulk of the patch LGTM as well, but it should still have a test case.


Repository:
  rL LLVM

https://reviews.llvm.org/D37620



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


[PATCH] D31140: [LLVMbugs] [Bug 18710] Only generate .ARM.exidx and .ARM.extab when needed in EHABI

2017-09-08 Thread Christian Bruel via Phabricator via cfe-commits
chrib added a comment.

forgot to give the motivating figure.  this brings a code size reduction of 9.5 
% (geomean of text sections sizes) on coremarkpro -Oz for cortex-m3 eabi


https://reviews.llvm.org/D31140



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


[PATCH] D37382: Fixed a crash in code completion.

2017-09-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 114349.
ilya-biryukov added a comment.

- Fix to account for change in the interface of ParseExpressionList.


https://reviews.llvm.org/D37382

Files:
  lib/Parse/ParseDecl.cpp
  test/CodeCompletion/crash-func-init.cpp


Index: test/CodeCompletion/crash-func-init.cpp
===
--- /dev/null
+++ test/CodeCompletion/crash-func-init.cpp
@@ -0,0 +1,4 @@
+int (*foo(int a))(flo
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:1:21 %s -o - \
+// RUN:| FileCheck %s
+// CHECK: COMPLETION: float
Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -2264,11 +2264,23 @@
   Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl);
 }
 
-if (ParseExpressionList(Exprs, CommaLocs, [&] {
-  Actions.CodeCompleteConstructor(getCurScope(),
- 
cast(ThisDecl)->getType()->getCanonicalTypeInternal(),
-  ThisDecl->getLocation(), Exprs);
-   })) {
+llvm::function_ref ExprListCompleter;
+auto ThisVarDecl = dyn_cast_or_null(ThisDecl);
+auto ConstructorCompleter = [&, ThisVarDecl] {
+  Actions.CodeCompleteConstructor(
+  getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
+  ThisDecl->getLocation(), Exprs);
+};
+if (ThisVarDecl) {
+  // ParseExpressionList can sometimes succeed even when ThisDecl is not
+  // VarDecl. This is an error and it is reported in a call to
+  // Actions.ActOnInitializerError(). However, we call
+  // CodeCompleteConstructor only on VarDecls, falling back to default
+  // completer in other cases.
+  ExprListCompleter = ConstructorCompleter;
+}
+
+if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) {
   Actions.ActOnInitializerError(ThisDecl);
   SkipUntil(tok::r_paren, StopAtSemi);
 


Index: test/CodeCompletion/crash-func-init.cpp
===
--- /dev/null
+++ test/CodeCompletion/crash-func-init.cpp
@@ -0,0 +1,4 @@
+int (*foo(int a))(flo
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:1:21 %s -o - \
+// RUN:| FileCheck %s
+// CHECK: COMPLETION: float
Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -2264,11 +2264,23 @@
   Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl);
 }
 
-if (ParseExpressionList(Exprs, CommaLocs, [&] {
-  Actions.CodeCompleteConstructor(getCurScope(),
- cast(ThisDecl)->getType()->getCanonicalTypeInternal(),
-  ThisDecl->getLocation(), Exprs);
-   })) {
+llvm::function_ref ExprListCompleter;
+auto ThisVarDecl = dyn_cast_or_null(ThisDecl);
+auto ConstructorCompleter = [&, ThisVarDecl] {
+  Actions.CodeCompleteConstructor(
+  getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
+  ThisDecl->getLocation(), Exprs);
+};
+if (ThisVarDecl) {
+  // ParseExpressionList can sometimes succeed even when ThisDecl is not
+  // VarDecl. This is an error and it is reported in a call to
+  // Actions.ActOnInitializerError(). However, we call
+  // CodeCompleteConstructor only on VarDecls, falling back to default
+  // completer in other cases.
+  ExprListCompleter = ConstructorCompleter;
+}
+
+if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) {
   Actions.ActOnInitializerError(ThisDecl);
   SkipUntil(tok::r_paren, StopAtSemi);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r312788 - Fixed a crash in code completion.

2017-09-08 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Sep  8 06:36:38 2017
New Revision: 312788

URL: http://llvm.org/viewvc/llvm-project?rev=312788&view=rev
Log:
Fixed a crash in code completion.

Summary: The crash occured when FunctionDecl was parsed with an initializer.

Reviewers: bkramer, klimek, francisco.lopes

Reviewed By: bkramer

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/CodeCompletion/crash-func-init.cpp
Modified:
cfe/trunk/lib/Parse/ParseDecl.cpp

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=312788&r1=312787&r2=312788&view=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Sep  8 06:36:38 2017
@@ -2264,11 +2264,23 @@ Decl *Parser::ParseDeclarationAfterDecla
   Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl);
 }
 
-if (ParseExpressionList(Exprs, CommaLocs, [&] {
-  Actions.CodeCompleteConstructor(getCurScope(),
- 
cast(ThisDecl)->getType()->getCanonicalTypeInternal(),
-  ThisDecl->getLocation(), Exprs);
-   })) {
+llvm::function_ref ExprListCompleter;
+auto ThisVarDecl = dyn_cast_or_null(ThisDecl);
+auto ConstructorCompleter = [&, ThisVarDecl] {
+  Actions.CodeCompleteConstructor(
+  getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
+  ThisDecl->getLocation(), Exprs);
+};
+if (ThisVarDecl) {
+  // ParseExpressionList can sometimes succeed even when ThisDecl is not
+  // VarDecl. This is an error and it is reported in a call to
+  // Actions.ActOnInitializerError(). However, we call
+  // CodeCompleteConstructor only on VarDecls, falling back to default
+  // completer in other cases.
+  ExprListCompleter = ConstructorCompleter;
+}
+
+if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) {
   Actions.ActOnInitializerError(ThisDecl);
   SkipUntil(tok::r_paren, StopAtSemi);
 

Added: cfe/trunk/test/CodeCompletion/crash-func-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/crash-func-init.cpp?rev=312788&view=auto
==
--- cfe/trunk/test/CodeCompletion/crash-func-init.cpp (added)
+++ cfe/trunk/test/CodeCompletion/crash-func-init.cpp Fri Sep  8 06:36:38 2017
@@ -0,0 +1,4 @@
+int (*foo(int a))(flo
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:1:21 %s -o - \
+// RUN:| FileCheck %s
+// CHECK: COMPLETION: float


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


[PATCH] D37382: Fixed a crash in code completion.

2017-09-08 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL312788: Fixed a crash in code completion. (authored by 
ibiryukov).

Repository:
  rL LLVM

https://reviews.llvm.org/D37382

Files:
  cfe/trunk/lib/Parse/ParseDecl.cpp
  cfe/trunk/test/CodeCompletion/crash-func-init.cpp


Index: cfe/trunk/test/CodeCompletion/crash-func-init.cpp
===
--- cfe/trunk/test/CodeCompletion/crash-func-init.cpp
+++ cfe/trunk/test/CodeCompletion/crash-func-init.cpp
@@ -0,0 +1,4 @@
+int (*foo(int a))(flo
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:1:21 %s -o - \
+// RUN:| FileCheck %s
+// CHECK: COMPLETION: float
Index: cfe/trunk/lib/Parse/ParseDecl.cpp
===
--- cfe/trunk/lib/Parse/ParseDecl.cpp
+++ cfe/trunk/lib/Parse/ParseDecl.cpp
@@ -2264,11 +2264,23 @@
   Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl);
 }
 
-if (ParseExpressionList(Exprs, CommaLocs, [&] {
-  Actions.CodeCompleteConstructor(getCurScope(),
- 
cast(ThisDecl)->getType()->getCanonicalTypeInternal(),
-  ThisDecl->getLocation(), Exprs);
-   })) {
+llvm::function_ref ExprListCompleter;
+auto ThisVarDecl = dyn_cast_or_null(ThisDecl);
+auto ConstructorCompleter = [&, ThisVarDecl] {
+  Actions.CodeCompleteConstructor(
+  getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
+  ThisDecl->getLocation(), Exprs);
+};
+if (ThisVarDecl) {
+  // ParseExpressionList can sometimes succeed even when ThisDecl is not
+  // VarDecl. This is an error and it is reported in a call to
+  // Actions.ActOnInitializerError(). However, we call
+  // CodeCompleteConstructor only on VarDecls, falling back to default
+  // completer in other cases.
+  ExprListCompleter = ConstructorCompleter;
+}
+
+if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) {
   Actions.ActOnInitializerError(ThisDecl);
   SkipUntil(tok::r_paren, StopAtSemi);
 


Index: cfe/trunk/test/CodeCompletion/crash-func-init.cpp
===
--- cfe/trunk/test/CodeCompletion/crash-func-init.cpp
+++ cfe/trunk/test/CodeCompletion/crash-func-init.cpp
@@ -0,0 +1,4 @@
+int (*foo(int a))(flo
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:1:21 %s -o - \
+// RUN:| FileCheck %s
+// CHECK: COMPLETION: float
Index: cfe/trunk/lib/Parse/ParseDecl.cpp
===
--- cfe/trunk/lib/Parse/ParseDecl.cpp
+++ cfe/trunk/lib/Parse/ParseDecl.cpp
@@ -2264,11 +2264,23 @@
   Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl);
 }
 
-if (ParseExpressionList(Exprs, CommaLocs, [&] {
-  Actions.CodeCompleteConstructor(getCurScope(),
- cast(ThisDecl)->getType()->getCanonicalTypeInternal(),
-  ThisDecl->getLocation(), Exprs);
-   })) {
+llvm::function_ref ExprListCompleter;
+auto ThisVarDecl = dyn_cast_or_null(ThisDecl);
+auto ConstructorCompleter = [&, ThisVarDecl] {
+  Actions.CodeCompleteConstructor(
+  getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
+  ThisDecl->getLocation(), Exprs);
+};
+if (ThisVarDecl) {
+  // ParseExpressionList can sometimes succeed even when ThisDecl is not
+  // VarDecl. This is an error and it is reported in a call to
+  // Actions.ActOnInitializerError(). However, we call
+  // CodeCompleteConstructor only on VarDecls, falling back to default
+  // completer in other cases.
+  ExprListCompleter = ConstructorCompleter;
+}
+
+if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) {
   Actions.ActOnInitializerError(ThisDecl);
   SkipUntil(tok::r_paren, StopAtSemi);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37101: [clangd] Add support for snippet completions

2017-09-08 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added a comment.

Great!


https://reviews.llvm.org/D37101



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


[PATCH] D33852: Enable __declspec(selectany) on linux

2017-09-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/Basic/AttrDocs.td:3154
+
+def SelectAnyDocs : Documentation {
+   let Content = [{This attribute makes global symbol have a weak definition

Prazek wrote:
> aaron.ballman wrote:
> > Prazek wrote:
> > > aaron.ballman wrote:
> > > > I think you need to set the `Category` as well.
> > > > 
> > > > To test this you should run something like (replacing  and fixing 
> > > > up path separators as needed):
> > > > ```
> > > > clang-tblgen -gen-attr-docs -I \llvm\tools\clang\include 
> > > > \llvm\tools\clang\include\clang\Basic\Attr.td -o 
> > > > \llvm\tools\clang\docs\AttributeReference.rst
> > > > ```
> > > Thanks for the testing command. Should I do anything in order to check if 
> > > docs build?
> > > I enabled docs with -DLLVM_BUILD_DOCS=ON, and I have sphinx. Everything 
> > > builds, but I don't see docs anywhere.
> > > 
> > > the docs looks like this:
> > > +selectany (gnu::selectany)
> > > +--
> > > +.. csv-table:: Supported Syntaxes
> > > +   :header: "GNU", "C++11", "__declspec", "Keyword", "Pragma", "Pragma 
> > > clang attribute"
> > > +
> > > +   "X","X","X","", "", ""
> > > +
> > > +This attribute appertains to a global symbol, causing it to have a weak
> > > +definition (
> > > +.. _`linkonce`: https://llvm.org/docs/LangRef.html#linkage-types
> > > +), allowing the linker to select any definition.
> > > +
> > > +For more information see
> > > +.. `gcc documentation`: 
> > > https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Microsoft-Windows-Variable-Attributes.html
> > > +
> > > Thanks for the testing command. Should I do anything in order to check if 
> > > docs build?
> > 
> > On Windows, I use `make html` within the clang\docs directory to generate 
> > the actual sphinx docs -- that will tell you if there are sphinx issues. Be 
> > sure you do *not* commit the AttributeReference.rst file that it generates, 
> > however.
> I tried building docs but it doesn't seem that there is any target like 
> "html". Do you know if there is documentation on how to build docs? I 
> couldn't find any.
I don't know that we have any docs on that, but I believe the command you want 
to execute is `sphinx-build -b html -d _build/doctrees . _build/html` (I pulled 
this from make.bat in the docs directory.)


https://reviews.llvm.org/D33852



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


[PATCH] D37620: [Sema] Put tautological comparison of unsigned and zero into it's own flag

2017-09-08 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 114351.
lebedev.ri edited the summary of this revision.
lebedev.ri added a comment.

Added test.


Repository:
  rL LLVM

https://reviews.llvm.org/D37620

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  test/Sema/tautological-unsigned-zero-compare.c


Index: test/Sema/tautological-unsigned-zero-compare.c
===
--- /dev/null
+++ test/Sema/tautological-unsigned-zero-compare.c
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -fsyntax-only -DTEST -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare 
-verify %s
+
+unsigned value(void);
+
+int main()
+{
+unsigned un = value();
+
+#ifdef TEST
+if (un < 0) // expected-warning {{comparison of unsigned expression < 0 is 
always false}}
+return 0;
+if (un >= 0) // expected-warning {{comparison of unsigned expression >= 0 
is always true}}
+return 0;
+if (0 <= un) // expected-warning {{comparison of 0 <= unsigned expression 
is always true}}
+return 0;
+if (0 > un) // expected-warning {{comparison of 0 > unsigned expression is 
always false}}
+return 0;
+if (un < 0U) // expected-warning {{comparison of unsigned expression < 0 
is always false}}
+return 0;
+if (un >= 0U) // expected-warning {{comparison of unsigned expression >= 0 
is always true}}
+return 0;
+if (0U <= un) // expected-warning {{comparison of 0 <= unsigned expression 
is always true}}
+return 0;
+if (0U > un) // expected-warning {{comparison of 0 > unsigned expression 
is always false}}
+return 0;
+#else
+// expected-no-diagnostics
+if (un < 0)
+return 0;
+if (un >= 0)
+return 0;
+if (0 <= un)
+return 0;
+if (0 > un)
+return 0;
+if (un < 0U)
+return 0;
+if (un >= 0U)
+return 0;
+if (0U <= un)
+return 0;
+if (0U > un)
+return 0;
+#endif
+
+return 1;
+}
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -5898,14 +5898,14 @@
   InGroup, DefaultIgnore;
 def warn_lunsigned_always_true_comparison : Warning<
   "comparison of unsigned%select{| enum}2 expression %0 is always %1">,
-  InGroup;
+  InGroup;
 def warn_out_of_range_compare : Warning<
   "comparison of %select{constant %0|true|false}1 with " 
   "%select{expression of type %2|boolean expression}3 is always "
   "%select{false|true}4">, InGroup;
 def warn_runsigned_always_true_comparison : Warning<
   "comparison of %0 unsigned%select{| enum}2 expression is always %1">,
-  InGroup;
+  InGroup;
 def warn_comparison_of_mixed_enum_types : Warning<
   "comparison of two values with different enumeration types"
   "%diff{ ($ and $)|}0,1">,
Index: include/clang/Basic/DiagnosticGroups.td
===
--- include/clang/Basic/DiagnosticGroups.td
+++ include/clang/Basic/DiagnosticGroups.td
@@ -427,12 +427,14 @@
 def StringPlusInt : DiagGroup<"string-plus-int">;
 def StringPlusChar : DiagGroup<"string-plus-char">;
 def StrncatSize : DiagGroup<"strncat-size">;
+def TautologicalUnsignedZeroCompare : 
DiagGroup<"tautological-unsigned-zero-compare">;
 def TautologicalOutOfRangeCompare : 
DiagGroup<"tautological-constant-out-of-range-compare">;
 def TautologicalPointerCompare : DiagGroup<"tautological-pointer-compare">;
 def TautologicalOverlapCompare : DiagGroup<"tautological-overlap-compare">;
 def TautologicalUndefinedCompare : DiagGroup<"tautological-undefined-compare">;
 def TautologicalCompare : DiagGroup<"tautological-compare",
-[TautologicalOutOfRangeCompare,
+[TautologicalUnsignedZeroCompare,
+ TautologicalOutOfRangeCompare,
  TautologicalPointerCompare,
  TautologicalOverlapCompare,
  TautologicalUndefinedCompare]>;


Index: test/Sema/tautological-unsigned-zero-compare.c
===
--- /dev/null
+++ test/Sema/tautological-unsigned-zero-compare.c
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -fsyntax-only -DTEST -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare -verify %s
+
+unsigned value(void);
+
+int main()
+{
+unsigned un = value();
+
+#ifdef TEST
+if (un < 0) // expected-warning {{comparison of unsigned expression < 0 is always false}}
+return 0;
+if (un >= 0) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
+return 0;
+if (0 <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
+re

r312790 - Updated two annotations for Store.h and CodeGenFunction.h.

2017-09-08 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Fri Sep  8 06:44:51 2017
New Revision: 312790

URL: http://llvm.org/viewvc/llvm-project?rev=312790&view=rev
Log:
Updated two annotations for Store.h and CodeGenFunction.h.

Summary:
1.Updated annotations for 
include/clang/StaticAnalyzer/Core/PathSensitive/Store.h, which belong to the 
old version of clang.
2.Delete annotations for CodeGenFunction::getEvaluationKind() in 
clang/lib/CodeGen/CodeGenFunction.h, which belong to the old version of clang.

Reviewers: bkramer, krasimir, klimek

Reviewed By: bkramer

Subscribers: MTC

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

Contributed by @MTC!

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h?rev=312790&r1=312789&r2=312790&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h Fri Sep  
8 06:44:51 2017
@@ -51,7 +51,7 @@ public:
   virtual ~StoreManager() {}
 
   /// Return the value bound to specified location in a given state.
-  /// \param[in] store The analysis state.
+  /// \param[in] store The store in which to make the lookup.
   /// \param[in] loc The symbolic memory location.
   /// \param[in] T An optional type that provides a hint indicating the
   ///   expected type of the returned value.  This is used if the value is
@@ -83,12 +83,12 @@ public:
 return getDefaultBinding(lcv.getStore(), lcv.getRegion());
   }
 
-  /// Return a state with the specified value bound to the given location.
-  /// \param[in] store The analysis state.
+  /// Return a store with the specified value bound to the given location.
+  /// \param[in] store The store in which to make the binding.
   /// \param[in] loc The symbolic memory location.
   /// \param[in] val The value to bind to location \c loc.
-  /// \return A pointer to a ProgramState object that contains the same
-  ///   bindings as \c state with the addition of having the value specified
+  /// \return A StoreRef object that contains the same
+  ///   bindings as \c store with the addition of having the value specified
   ///   by \c val bound to the location given for \c loc.
   virtual StoreRef Bind(Store store, Loc loc, SVal val) = 0;
 

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=312790&r1=312789&r2=312790&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Sep  8 06:44:51 2017
@@ -1818,8 +1818,7 @@ public:
   /// TypeOfSelfObject - Return type of object that this self represents.
   QualType TypeOfSelfObject();
 
-  /// hasAggregateLLVMType - Return true if the specified AST type will map 
into
-  /// an aggregate LLVM type or is void.
+  /// getEvaluationKind - Return the TypeEvaluationKind of QualType \c T.
   static TypeEvaluationKind getEvaluationKind(QualType T);
 
   static bool hasScalarEvaluationKind(QualType T) {


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


[PATCH] D37620: [Sema] Put tautological comparison of unsigned and zero into it's own flag

2017-09-08 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.

Please run the test through clang-format, but otherwise LGTM!


Repository:
  rL LLVM

https://reviews.llvm.org/D37620



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


[PATCH] D37620: [Sema] Put tautological comparison of unsigned and zero into it's own flag

2017-09-08 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL312792: [Sema] Put tautological comparison of unsigned and 
zero into it's own flag (authored by lebedevri).

Changed prior to commit:
  https://reviews.llvm.org/D37620?vs=114351&id=114358#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37620

Files:
  cfe/trunk/include/clang/Basic/DiagnosticGroups.td
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/test/Sema/tautological-unsigned-zero-compare.c


Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5898,14 +5898,14 @@
   InGroup, DefaultIgnore;
 def warn_lunsigned_always_true_comparison : Warning<
   "comparison of unsigned%select{| enum}2 expression %0 is always %1">,
-  InGroup;
+  InGroup;
 def warn_out_of_range_compare : Warning<
   "comparison of %select{constant %0|true|false}1 with " 
   "%select{expression of type %2|boolean expression}3 is always "
   "%select{false|true}4">, InGroup;
 def warn_runsigned_always_true_comparison : Warning<
   "comparison of %0 unsigned%select{| enum}2 expression is always %1">,
-  InGroup;
+  InGroup;
 def warn_comparison_of_mixed_enum_types : Warning<
   "comparison of two values with different enumeration types"
   "%diff{ ($ and $)|}0,1">,
Index: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td
@@ -427,12 +427,14 @@
 def StringPlusInt : DiagGroup<"string-plus-int">;
 def StringPlusChar : DiagGroup<"string-plus-char">;
 def StrncatSize : DiagGroup<"strncat-size">;
+def TautologicalUnsignedZeroCompare : 
DiagGroup<"tautological-unsigned-zero-compare">;
 def TautologicalOutOfRangeCompare : 
DiagGroup<"tautological-constant-out-of-range-compare">;
 def TautologicalPointerCompare : DiagGroup<"tautological-pointer-compare">;
 def TautologicalOverlapCompare : DiagGroup<"tautological-overlap-compare">;
 def TautologicalUndefinedCompare : DiagGroup<"tautological-undefined-compare">;
 def TautologicalCompare : DiagGroup<"tautological-compare",
-[TautologicalOutOfRangeCompare,
+[TautologicalUnsignedZeroCompare,
+ TautologicalOutOfRangeCompare,
  TautologicalPointerCompare,
  TautologicalOverlapCompare,
  TautologicalUndefinedCompare]>;
Index: cfe/trunk/test/Sema/tautological-unsigned-zero-compare.c
===
--- cfe/trunk/test/Sema/tautological-unsigned-zero-compare.c
+++ cfe/trunk/test/Sema/tautological-unsigned-zero-compare.c
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -fsyntax-only -DTEST -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare 
-verify %s
+
+unsigned value(void);
+
+int main() {
+  unsigned un = value();
+
+#ifdef TEST
+  if (un < 0) // expected-warning {{comparison of unsigned expression < 0 is 
always false}}
+return 0;
+  if (un >= 0) // expected-warning {{comparison of unsigned expression >= 0 is 
always true}}
+return 0;
+  if (0 <= un) // expected-warning {{comparison of 0 <= unsigned expression is 
always true}}
+return 0;
+  if (0 > un) // expected-warning {{comparison of 0 > unsigned expression is 
always false}}
+return 0;
+  if (un < 0U) // expected-warning {{comparison of unsigned expression < 0 is 
always false}}
+return 0;
+  if (un >= 0U) // expected-warning {{comparison of unsigned expression >= 0 
is always true}}
+return 0;
+  if (0U <= un) // expected-warning {{comparison of 0 <= unsigned expression 
is always true}}
+return 0;
+  if (0U > un) // expected-warning {{comparison of 0 > unsigned expression is 
always false}}
+return 0;
+#else
+// expected-no-diagnostics
+  if (un < 0)
+return 0;
+  if (un >= 0)
+return 0;
+  if (0 <= un)
+return 0;
+  if (0 > un)
+return 0;
+  if (un < 0U)
+return 0;
+  if (un >= 0U)
+return 0;
+  if (0U <= un)
+return 0;
+  if (0U > un)
+return 0;
+#endif
+
+  return 1;
+}


Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5898,14 +5898,14 @@
   InGroup, DefaultIgnore;
 def warn_lunsigned_always_true_comparison : Warning<
   "comparison of unsigned%select{| enum}2 expression %0 is always %1">,
-  InGroup;
+  InGroup;
 def warn_out_of_range_compare : Warning<
   "comparison of %select{constant %0|true|false}1 with " 
   "%select{ex

[PATCH] D36354: [clang-tidy] Implement type-based check for `gsl::owner`

2017-09-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp:140
+
+  assert(CheckExecuted == true &&
+ "Non of the subroutines did execute, logic error in matcher!");

Can assert `CheckExecuted` and drop the explicit equality test.



Comment at: clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp:141
+  assert(CheckExecuted == true &&
+ "Non of the subroutines did execute, logic error in matcher!");
+}

did execute, -> executed;



Comment at: clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp:206
+diag(OwnerInitializer->getSourceLocation(),
+ "expected initializing of owner member variable with value of type "
+ "'gsl::owner<>'; got %0")

initializing -> intialization



Comment at: clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp:303-305
+// diag(DeclaredOwnerMember->getLocStart(), "declared owner as member 
here",
+// DiagnosticIDs::Note)
+//<< DeclaredOwnerMember->getSourceRange();

Please remove the commented-out lines.



Comment at: test/clang-tidy/cppcoreguidelines-owning-memory.cpp:39
+  return new int(42);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: returning a 'gsl::owner<>' from a 
function but not declaring it; return type is 'int *'
+}

This diagnostic confuses me -- there's no gsl::owner<> involved anywhere; am I 
missing something?


https://reviews.llvm.org/D36354



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


r312792 - [Sema] Put tautological comparison of unsigned and zero into it's own flag

2017-09-08 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Fri Sep  8 06:56:45 2017
New Revision: 312792

URL: http://llvm.org/viewvc/llvm-project?rev=312792&view=rev
Log:
[Sema] Put tautological comparison of unsigned and zero into it's own flag

Summary:
As requested by Sam McCall.

```
$ /build/llvm-build-Clang-release/./bin/clang -c 
/build/clang/test/Sema/outof-range-constant-compare.c 
/build/clang/test/Sema/outof-range-constant-compare.c:40:11: warning: 
comparison of unsigned expression < 0 is always false 
[-Wtautological-unsigned-zero-compare]
if (a < 0xUL) // expected-warning {{comparison of unsigned 
expression < 0 is always false}}
~ ^ 
```

Reviewers: sammccall, bkramer, djasper, rsmith, rjmccall, aaron.ballman

Reviewed By: sammccall, aaron.ballman

Subscribers: aaron.ballman, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/Sema/tautological-unsigned-zero-compare.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=312792&r1=312791&r2=312792&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Fri Sep  8 06:56:45 2017
@@ -427,12 +427,14 @@ def StringCompare : DiagGroup<"string-co
 def StringPlusInt : DiagGroup<"string-plus-int">;
 def StringPlusChar : DiagGroup<"string-plus-char">;
 def StrncatSize : DiagGroup<"strncat-size">;
+def TautologicalUnsignedZeroCompare : 
DiagGroup<"tautological-unsigned-zero-compare">;
 def TautologicalOutOfRangeCompare : 
DiagGroup<"tautological-constant-out-of-range-compare">;
 def TautologicalPointerCompare : DiagGroup<"tautological-pointer-compare">;
 def TautologicalOverlapCompare : DiagGroup<"tautological-overlap-compare">;
 def TautologicalUndefinedCompare : DiagGroup<"tautological-undefined-compare">;
 def TautologicalCompare : DiagGroup<"tautological-compare",
-[TautologicalOutOfRangeCompare,
+[TautologicalUnsignedZeroCompare,
+ TautologicalOutOfRangeCompare,
  TautologicalPointerCompare,
  TautologicalOverlapCompare,
  TautologicalUndefinedCompare]>;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=312792&r1=312791&r2=312792&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Sep  8 06:56:45 
2017
@@ -5898,14 +5898,14 @@ def warn_mixed_sign_comparison : Warning
   InGroup, DefaultIgnore;
 def warn_lunsigned_always_true_comparison : Warning<
   "comparison of unsigned%select{| enum}2 expression %0 is always %1">,
-  InGroup;
+  InGroup;
 def warn_out_of_range_compare : Warning<
   "comparison of %select{constant %0|true|false}1 with " 
   "%select{expression of type %2|boolean expression}3 is always "
   "%select{false|true}4">, InGroup;
 def warn_runsigned_always_true_comparison : Warning<
   "comparison of %0 unsigned%select{| enum}2 expression is always %1">,
-  InGroup;
+  InGroup;
 def warn_comparison_of_mixed_enum_types : Warning<
   "comparison of two values with different enumeration types"
   "%diff{ ($ and $)|}0,1">,

Added: cfe/trunk/test/Sema/tautological-unsigned-zero-compare.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/tautological-unsigned-zero-compare.c?rev=312792&view=auto
==
--- cfe/trunk/test/Sema/tautological-unsigned-zero-compare.c (added)
+++ cfe/trunk/test/Sema/tautological-unsigned-zero-compare.c Fri Sep  8 
06:56:45 2017
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -fsyntax-only -DTEST -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare 
-verify %s
+
+unsigned value(void);
+
+int main() {
+  unsigned un = value();
+
+#ifdef TEST
+  if (un < 0) // expected-warning {{comparison of unsigned expression < 0 is 
always false}}
+return 0;
+  if (un >= 0) // expected-warning {{comparison of unsigned expression >= 0 is 
always true}}
+return 0;
+  if (0 <= un) // expected-warning {{comparison of 0 <= unsigned expression is 
always true}}
+return 0;
+  if (0 > un) // expected-warning {{comparison of 0 > unsigned expression is 
always false}}
+return 0;
+  if (un < 0U) // expected-warning {{comparison of unsigned expression < 0 is 
always false}}
+return 0;
+  if (un >=

[PATCH] D37263: [clang-format] Ignore case when sorting using-declarations

2017-09-08 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

ping


https://reviews.llvm.org/D37263



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


[PATCH] D37140: [clang-format] Fixed one-line if statement

2017-09-08 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added a comment.
This revision is now accepted and ready to land.

Great! Would you like me to commit this for you?


https://reviews.llvm.org/D37140



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


[PATCH] D37413: [X86][MS-InlineAsm] Extended support for variables / identifiers on memory / immediate expressions

2017-09-08 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a reviewer: RKSimon.
RKSimon added a comment.

Tests?




Comment at: lib/Sema/SemaStmtAsm.cpp:71
+if (!Piece.isOperand())
+  continue;
 

This all looks like a clang-format NFC change - just commit it?



Comment at: lib/Sema/SemaStmtAsm.cpp:617
+return;
+  } else if (Res->isRValue()) {
+bool Enum = isa(T) && Res->EvaluateAsRValue(Eval, 
Context);

(style) Split these instead of an if-elseif chain


Repository:
  rL LLVM

https://reviews.llvm.org/D37413



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


[PATCH] D37308: Interface class with uuid base record

2017-09-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: lib/Sema/SemaDeclCXX.cpp:2385
+  return RD->isStruct() && RD->hasAttr() &&
+ RD->getName() == "IUnknown" &&
+ (RD->getAttr())->getGuid() ==

This should probably also ensure that the class is in the global namespace so 
we don't handle `foobar::IUnknown` improperly.



Comment at: lib/Sema/SemaDeclCXX.cpp:2386
+ RD->getName() == "IUnknown" &&
+ (RD->getAttr())->getGuid() ==
+ "---C000-0046" &&

Can remove the spurious parens. Also, rather than call `hasAttr<>` followed by 
`getAttr<>` on the same thing, you should factor out the call to `getAttr<>`.


https://reviews.llvm.org/D37308



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


[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.

2017-09-08 Thread kchoi via Phabricator via cfe-commits
choikwa created this revision.

Builds on previous Differential https://reviews.llvm.org/D2219

Changes include:

- Using unordered_map with SourceLocation.ID (raw encoding) as key
- Demangle only if !isExternC. Used dyn_cast((Decl*)CurFuncDecl) 
for this
- Modified an existing C testcase to test for options.


https://reviews.llvm.org/D37624

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/instrument-functions.c

Index: test/CodeGen/instrument-functions.c
===
--- test/CodeGen/instrument-functions.c
+++ test/CodeGen/instrument-functions.c
@@ -1,18 +1,66 @@
-// RUN: %clang_cc1 -S -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-functions | FileCheck %s
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions | FileCheck %s
+// RUN: %clang -S -emit-llvm -o - %s -fno-instrument-functions | FileCheck %s --check-prefix=NOINSTR
+
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-file-list=instrument | FileCheck %s --check-prefix=NOFILE
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=NOFUNC
 
 // CHECK: @test1
+// NOINSTR: @test1
+// NOFILE: @test1
+// NOFUNC: @test1
 int test1(int x) {
-// CHECK: call void @__cyg_profile_func_enter({{.*}}, !dbg
-// CHECK: call void @__cyg_profile_func_exit({{.*}}, !dbg
+// CHECK: __cyg_profile_func_enter
+// CHECK: __cyg_profile_func_exit
 // CHECK: ret
+// NOINSTR-NOT: __cyg_profile_func_enter
+// NOINSTR-NOT: __cyg_profile_func_exit
+// NOINSTR: ret
+// NOFILE-NOT: __cyg_profile_func_enter
+// NOFILE-NOT: __cyg_profile_func_exit
+// NOFILE: ret
+// NOFUNC: __cyg_profile_func_enter
+// NOFUNC: __cyg_profile_func_exit
+// NOFUNC: ret
   return x;
 }
 
 // CHECK: @test2
+// NOINSTR: @test2
+// NOFILE: @test2
+// NOFUNC: @test2
 int test2(int) __attribute__((no_instrument_function));
 int test2(int x) {
 // CHECK-NOT: __cyg_profile_func_enter
 // CHECK-NOT: __cyg_profile_func_exit
 // CHECK: ret
+// NOINSTR-NOT: __cyg_profile_func_enter
+// NOINSTR-NOT: __cyg_profile_func_exit
+// NOINSTR: ret
+// NOFILE-NOT: __cyg_profile_func_enter
+// NOFILE-NOT: __cyg_profile_func_exit
+// NOFILE: ret
+// NOFUNC-NOT: __cyg_profile_func_enter
+// NOFUNC-NOT: __cyg_profile_func_exit
+// NOFUNC: ret
+  return x;
+}
+
+// CHECK: @test3
+// NOINSTR: @test3
+// NOFILE: @test3
+// NOFUNC: @test3
+int test3(int x) {
+// CHECK: __cyg_profile_func_enter
+// CHECK: __cyg_profile_func_exit
+// CHECK: ret
+// NOINSTR-NOT: __cyg_profile_func_enter
+// NOINSTR-NOT: __cyg_profile_func_exit
+// NOINSTR: ret
+// NOFILE-NOT: __cyg_profile_func_enter
+// NOFILE-NOT: __cyg_profile_func_exit
+// NOFILE: ret
+// NOFUNC-NOT: __cyg_profile_func_enter
+// NOFUNC-NOT: __cyg_profile_func_exit
+// NOFUNC: ret
   return x;
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -771,6 +771,12 @@
 
   Opts.PreserveVec3Type = Args.hasArg(OPT_fpreserve_vec3_type);
   Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions);
+  if (Opts.InstrumentFunctions) {
+Opts.InstrumentFunctionExclusionsFunctions
+= Args.getAllArgValues(OPT_finstrument_functions_exclude_function_list);
+Opts.InstrumentFunctionExclusionsPathSegments
+= Args.getAllArgValues(OPT_finstrument_functions_exclude_file_list);
+  }
   Opts.XRayInstrumentFunctions = Args.hasArg(OPT_fxray_instrument);
   Opts.XRayInstructionThreshold =
   getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3519,7 +3519,14 @@
 options::OPT_fno_unique_section_names, true))
 CmdArgs.push_back("-fno-unique-section-names");
 
-  Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions);
+  if (Args.hasArg(options::OPT_finstrument_functions,
+  options::OPT_fno_instrument_functions, false)) {
+Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions);
+Args.AddAllArgs(CmdArgs,
+options::OPT_finstrument_functions_exclude_file_list);
+Args.AddAllArgs(CmdArgs,
+options::OPT_finstrument_functions_exclude_function_list);
+  }
 
   addPGOAndCoverageFlags(C, D, Output, Args, CmdArgs);
 
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -1762,7 +1762,7 @@
 
   /// Shoul

[PATCH] D36672: [clang-tidy] readability-non-const-parameter: fixit on all function declarations

2017-09-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/readability/NonConstParameterCheck.cpp:147
+if (const auto *Parent = Par->getParentFunctionOrMethod()) {
+  if (const auto *F = dyn_cast(Parent)) {
+const auto ParDecl =

AndersRonnholm wrote:
> aaron.ballman wrote:
> > What if the parent is an `ObjCMethodDecl` instead?
> I don't think this checker handles objective-c
I think it does -- it has a matcher for `ParmVarDecl`, which can be contained 
by an `ObjCMethodDecl`.



Comment at: clang-tidy/readability/NonConstParameterCheck.cpp:143
+  "pointer parameter '%0' can be pointer to const")
+ << Par->getName()
+ << FixItHint::CreateInsertion(Par->getLocStart(), "const ");

You should remove the quotes around %0 and drop the `getName()` -- the 
diagnostics engine automatically handled `NamedDecl` subclasses and properly 
quotes them.



Comment at: clang-tidy/readability/NonConstParameterCheck.cpp:149
+while (FD) {
+  const auto ParDecl = FD->getParamDecl(Par->getFunctionScopeIndex());
+  if (Par != ParDecl)

`const auto *`



Comment at: clang-tidy/readability/NonConstParameterCheck.cpp:151
+  if (Par != ParDecl)
+D << ParDecl->getName()
+  << FixItHint::CreateInsertion(ParDecl->getLocStart(), "const ");

You can drop the `getName()` call here as well.


Repository:
  rL LLVM

https://reviews.llvm.org/D36672



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


[PATCH] D37566: [clang-tidy] fixed misc-unused-parameters omitting parameters default value

2017-09-08 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Thank you for the fix!

LG with one nit.




Comment at: test/clang-tidy/misc-unused-parameters.cpp:73
+// CHECK-FIXES: staticFunctionE();
+  staticFunctionF(1);
+// CHECK-FIXES: staticFunctionF();

Please add an invocation of `staticFunctionF` without parameters.


Repository:
  rL LLVM

https://reviews.llvm.org/D37566



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


[PATCH] D37491: [Preamble] Fixed preamble breaking with BOM presence (and particularly, fluctuating BOM presence)

2017-09-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In https://reviews.llvm.org/D37491#864649, @erikjv wrote:

> Will this fix PR25023 and PR21144?


PR25023  should be fixed by this 
change. It is essentially a repro of the same bug.
Could we add a `c-index-test`-based test here to make sure we addressed that 
particular use-case?

The state of PR21144   won't be 
affected, as this change does not touch the code invoked during normal 
compilation without preambles.
If PR21144  is fixed in a way that 
would make `SourceLocation`s the same regardless if BOM was present or not, we 
might have a better guarantee that nothing will break in case we want to reuse 
preamble between BOM/non-BOM versions.


https://reviews.llvm.org/D37491



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


[PATCH] D37140: [clang-format] Fixed one-line if statement

2017-09-08 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a comment.

Yes, would be great :) Thank you!


https://reviews.llvm.org/D37140



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


[PATCH] D37572: [clang-tidy] SuspiciousEnumUsageCheck bugfix

2017-09-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/misc/SuspiciousEnumUsageCheck.cpp:46
+  return llvm::APSInt::compareValues(E1->getInitVal(),
+ E2->getInitVal()) == -1;
 });

I would test for `< 0` rather than a direct equality test (compare functions 
generally follow the C idioms).



Comment at: clang-tidy/misc/SuspiciousEnumUsageCheck.cpp:61-62
   ValueRange Range1(Enum1), Range2(Enum2);
-  return (Range1.MaxVal < Range2.MinVal) || (Range2.MaxVal < Range1.MinVal);
+  bool Less1 = llvm::APSInt::compareValues(Range1.MaxVal, Range2.MinVal) == -1;
+  bool Less2 = llvm::APSInt::compareValues(Range2.MaxVal, Range1.MinVal) == -1;
+  return Less1 || Less2;

Same here, though I would also get rid of the local variables and just perform 
the comparison in the return statement.



Comment at: test/clang-tidy/misc-suspicious-enum-usage.cpp:1
-// RUN: %check_clang_tidy %s misc-suspicious-enum-usage %t -- 
-config="{CheckOptions: [{key: misc-suspicious-enum-usage.StrictMode, value: 
0}]}" --
+// RUN: %check_clang_tidy %s misc-suspicious-enum-usage %t -- 
-config="{CheckOptions: [{key: misc-suspicious-enum-usage.StrictMode, value: 
0}]}" -- -std=c++11
 

I thought we built in C++11 mode by default these days?



Comment at: test/clang-tidy/misc-suspicious-enum-usage.cpp:122
+struct a> {
+  enum { ah = ad::m,
+ ai = ae::m,

This seems like a lot of complicated code for the test case -- can this be 
reduced further?


https://reviews.llvm.org/D37572



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


[PATCH] D37568: [AMDGPU] Allow flexible register names in inline asm constraints

2017-09-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 114367.
yaxunl edited the summary of this revision.
yaxunl added a comment.

Allow {v[n]} and {s[n]}. Add more tests.


https://reviews.llvm.org/D37568

Files:
  lib/Basic/Targets/AMDGPU.h
  test/CodeGenOpenCL/amdgcn-inline-asm.cl
  test/Sema/inline-asm-validate-amdgpu.cl

Index: test/Sema/inline-asm-validate-amdgpu.cl
===
--- test/Sema/inline-asm-validate-amdgpu.cl
+++ test/Sema/inline-asm-validate-amdgpu.cl
@@ -1,14 +1,76 @@
 // REQUIRES: amdgpu-registered-target
-// RUN: %clang_cc1 -x cl -triple amdgcn -fsyntax-only  %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -triple amdgcn -fsyntax-only -verify %s
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
 
 kernel void test () {
 
   int sgpr = 0, vgpr = 0, imm = 0;
 
   // sgpr constraints
   __asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "s" (imm) : );
 
+  __asm__ ("s_mov_b32 %0, %1" : "={s1}" (sgpr) : "{exec}" (imm) : );
+  __asm__ ("s_mov_b32 %0, %1" : "={s1}" (sgpr) : "{exe" (imm) : ); // expected-error {{invalid input constraint '{exe' in asm}}
+  __asm__ ("s_mov_b32 %0, %1" : "={s1}" (sgpr) : "{exec" (imm) : ); // expected-error {{invalid input constraint '{exec' in asm}}
+  __asm__ ("s_mov_b32 %0, %1" : "={s1}" (sgpr) : "{exec}a" (imm) : ); // expected-error {{invalid input constraint '{exec}a' in asm}}
+
   // vgpr constraints
   __asm__ ("v_mov_b32 %0, %1" : "=v" (vgpr) : "v" (imm) : );
 }
+
+__kernel void
+test_float(const __global float *a, const __global float *b, __global float *c, unsigned i)
+{
+float ai = a[i];
+float bi = b[i];
+float ci;
+
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}"(ci) : "{v2}"(ai), "{v3}"(bi) : );
+__asm("v_add_f32_e32 v1, v2, v3" : ""(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "="(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '=' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={a}"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={a}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={}"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={v' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1a}"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={v1a}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={va}"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={va}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}a"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={v1}a' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={v1' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "=v1}"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '=v1}' in asm}}
+
+__asm("v_add_f32_e32 v1, v2, v3" : "={v[1]}"(ci) : "{v[2]}"(ai), "{v[3]}"(bi) : );
+__asm("v_add_f32_e32 v1, v2, v3" : "={v[1}"(ci) : "{v[2]}"(ai), "{v[3]}"(bi) : ); // expected-error {{invalid output constraint '={v[1}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v[1]"(ci) : "{v[2]}"(ai), "{v[3]}"(bi) : ); // expected-error {{invalid output constraint '={v[1]' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v[a]}"(ci) : "{v[2]}"(ai), "{v[3]}"(bi) : ); // expected-error {{invalid output constraint '={v[a]}' in asm}}
+
+__asm("v_add_f32_e32 v1, v2, v3" : "=v"(ci) : "v"(ai), "v"(bi) : );
+__asm("v_add_f32_e32 v1, v2, v3" : "=v1"(ci) : "v2"(ai), "v3"(bi) : ); /// expected-error {{invalid output constraint '=v1' in asm}}
+
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}"(ci) : "{a}"(ai), "{v3}"(bi) : ); // expected-error {{invalid input constraint '{a}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}"(ci) : "{v2}"(ai), "{a}"(bi) : ); // expected-error {{invalid input constraint '{a}' in asm}}
+c[i] = ci;
+}
+
+__kernel void
+test_double(const __global double *a, const __global double *b, __global double *c, unsigned i)
+{
+double ai = a[i];
+double bi = b[i];
+double ci;
+
+__asm("v_add_f64_e64 v[1:2], v[3:4], v[5:6]" : "={v[1:2]}"(ci) : "{v[3:4]}"(ai), "{v[5:6]}"(bi) : );
+__asm("v_add_f64_e64 v[1:2], v[3:4], v[5:6]" : "=v{[1:2]}"(ci) : "{v[3:4]}"(ai), "{v[5:6]}"(bi) : ); //expected-error {{invalid output constraint '=v{[1:2]}' in asm}}
+__asm("v_add_f64_e64 v[1:2], v[3:4], v[5:6]" : "={v[1:2]a}"(ci) : "{v[3:4]}"(ai), "{v[5:6]}"(bi) : ); //expected-error {{invalid output constraint '={v[1:2]a}' in asm}}
+__asm("v_

r312794 - Recommit "Add _Float16 as a C/C++ source language type"

2017-09-08 Thread Sjoerd Meijer via cfe-commits
Author: sjoerdmeijer
Date: Fri Sep  8 08:15:00 2017
New Revision: 312794

URL: http://llvm.org/viewvc/llvm-project?rev=312794&view=rev
Log:
Recommit "Add _Float16 as a C/C++ source language type"

This is a recommit of r312781; in some build configurations
variable names are omitted, so changed the new regression
test accordingly.

Added:
cfe/trunk/test/CodeGenCXX/float16-declarations.cpp
cfe/trunk/test/Frontend/float16.cpp
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/BuiltinTypes.def
cfe/trunk/include/clang/Basic/Specifiers.h
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/include/clang/Lex/LiteralSupport.h
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/lib/AST/NSAPI.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/AST/TypeLoc.cpp
cfe/trunk/lib/Analysis/PrintfFormatString.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/Format/FormatToken.cpp
cfe/trunk/lib/Index/USRGeneration.cpp
cfe/trunk/lib/Lex/LiteralSupport.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Serialization/ASTCommon.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/test/Lexer/half-literal.cpp
cfe/trunk/tools/libclang/CXType.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=312794&r1=312793&r2=312794&view=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Fri Sep  8 08:15:00 2017
@@ -3115,8 +3115,9 @@ enum CXTypeKind {
   CXType_ObjCSel = 29,
   CXType_Float128 = 30,
   CXType_Half = 31,
+  CXType_Float16 = 32,
   CXType_FirstBuiltin = CXType_Void,
-  CXType_LastBuiltin  = CXType_Half,
+  CXType_LastBuiltin  = CXType_Float16,
 
   CXType_Complex = 100,
   CXType_Pointer = 101,

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=312794&r1=312793&r2=312794&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Sep  8 08:15:00 2017
@@ -973,6 +973,7 @@ public:
   CanQualType UnsignedLongLongTy, UnsignedInt128Ty;
   CanQualType FloatTy, DoubleTy, LongDoubleTy, Float128Ty;
   CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
+  CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3
   CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
   CanQualType Float128ComplexTy;
   CanQualType VoidPtrTy, NullPtrTy;

Modified: cfe/trunk/include/clang/AST/BuiltinTypes.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/BuiltinTypes.def?rev=312794&r1=312793&r2=312794&view=diff
==
--- cfe/trunk/include/clang/AST/BuiltinTypes.def (original)
+++ cfe/trunk/include/clang/AST/BuiltinTypes.def Fri Sep  8 08:15:00 2017
@@ -133,6 +133,9 @@ FLOATING_TYPE(Double, DoubleTy)
 // 'long double'
 FLOATING_TYPE(LongDouble, LongDoubleTy)
 
+// '_Float16'
+FLOATING_TYPE(Float16, HalfTy)
+
 // '__float128'
 FLOATING_TYPE(Float128, Float128Ty)
 

Modified: cfe/trunk/include/clang/Basic/Specifiers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Specifiers.h?rev=312794&r1=312793&r2=312794&view=diff
==
--- cfe/trunk/include/clang/Basic/Specifiers.h (original)
+++ cfe/trunk/include/clang/Basic/Specifiers.h Fri Sep  8 08:15:00 2017
@@ -52,6 +52,7 @@ namespace clang {
 TST_int,
 TST_int128,
 TST_half, // OpenCL half, ARM NEON __fp16
+TST_Float16,  // C11 extension ISO/IEC TS 18661-3
 TST_float,
 TST_double,
 TST_float128,

Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=312794&r1=312793&r2=312794&view=diff
==
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Fri Sep 

[PATCH] D35082: [OpenCL] Add LangAS::opencl_private to represent private address space in AST

2017-09-08 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/Sema/SemaType.cpp:6994
+  // OpenCL v1.2 s6.5:
+  // The generic address space name for arguments to a function in a
+  // program, or local variables of a function is __private. All function

yaxunl wrote:
> Anastasia wrote:
> > The generic address space -> The default address space
> 'The generic address space name for arguments' is literally from the OpenCL 
> 1.2 spec. Note it refers 'generic address space name', which is not the 
> 'generic address space' defined by OpenCL 2.0 spec.
True, but this spec was written before v2.0 was released. And I feel now it 
makes things confusing considering that we have v2.0 implementation too.


https://reviews.llvm.org/D35082



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


[PATCH] D35082: [OpenCL] Add LangAS::opencl_private to represent private address space in AST

2017-09-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 2 inline comments as done.
yaxunl added inline comments.



Comment at: lib/Sema/SemaType.cpp:6994
+  // OpenCL v1.2 s6.5:
+  // The generic address space name for arguments to a function in a
+  // program, or local variables of a function is __private. All function

Anastasia wrote:
> yaxunl wrote:
> > Anastasia wrote:
> > > The generic address space -> The default address space
> > 'The generic address space name for arguments' is literally from the OpenCL 
> > 1.2 spec. Note it refers 'generic address space name', which is not the 
> > 'generic address space' defined by OpenCL 2.0 spec.
> True, but this spec was written before v2.0 was released. And I feel now it 
> makes things confusing considering that we have v2.0 implementation too.
I can make the change. I just feel a little bit uneasy since this looks like a 
citation but actually is rephrased.


https://reviews.llvm.org/D35082



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


Re: Patch bug 27628

2017-09-08 Thread Krzysztof Parzyszek via cfe-commits

This should to to cfe-commits.  Redirecting.

-Krzysztof

On 9/8/2017 10:25 AM, Antoni Boucher via llvm-commits wrote:

Hello.
I've fixed the bug 27628:
https://bugs.llvm.org/show_bug.cgi?id=27628

I attached the patch.

Thanks.


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



--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
hosted by The Linux Foundation

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


[PATCH] D36327: [OpenCL] Allow targets emit optimized pipe functions for power of 2 type sizes

2017-09-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl abandoned this revision.
yaxunl added a comment.

We implemented this optimization through some target specific llvm pass.


https://reviews.llvm.org/D36327



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


Re: Patch bug 27628

2017-09-08 Thread Krzysztof Parzyszek via cfe-commits

Aaand the patch itself...

-K

On 9/8/2017 10:32 AM, Krzysztof Parzyszek via cfe-commits wrote:

This should to to cfe-commits.  Redirecting.

-Krzysztof

On 9/8/2017 10:25 AM, Antoni Boucher via llvm-commits wrote:

Hello.
I've fixed the bug 27628:
https://bugs.llvm.org/show_bug.cgi?id=27628

I attached the patch.

Thanks.


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





--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
hosted by The Linux Foundation
Index: clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tidy/tool/ClangTidyMain.cpp   (révision 312787)
+++ clang-tidy/tool/ClangTidyMain.cpp   (copie de travail)
@@ -449,6 +449,10 @@
 return WErrorCount;
   }
 
+  if (FoundErrors) {
+  return 1;
+  }
+
   return 0;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37572: [clang-tidy] SuspiciousEnumUsageCheck bugfix

2017-09-08 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG modulo comments. Thank you for the fix!




Comment at: test/clang-tidy/misc-suspicious-enum-usage.cpp:1
-// RUN: %check_clang_tidy %s misc-suspicious-enum-usage %t -- 
-config="{CheckOptions: [{key: misc-suspicious-enum-usage.StrictMode, value: 
0}]}" --
+// RUN: %check_clang_tidy %s misc-suspicious-enum-usage %t -- 
-config="{CheckOptions: [{key: misc-suspicious-enum-usage.StrictMode, value: 
0}]}" -- -std=c++11
 

aaron.ballman wrote:
> I thought we built in C++11 mode by default these days?
I'm not sure, but if we actually do, we could later remove `-std=c++11` from 
the test script and all tests.



Comment at: test/clang-tidy/misc-suspicious-enum-usage.cpp:92
+
+// Bug #34400
+template 

I'd suggest enclosing the test case in a `namespace PR34400 {}` for clarity and 
to avoid possible name conflicts.



Comment at: test/clang-tidy/misc-suspicious-enum-usage.cpp:122
+struct a> {
+  enum { ah = ad::m,
+ ai = ae::m,

aaron.ballman wrote:
> This seems like a lot of complicated code for the test case -- can this be 
> reduced further?
This is the best creduce could do. It should be possible to make this much 
shorter, but I wouldn't spend too much time on that.


https://reviews.llvm.org/D37572



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


[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.

2017-09-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: lib/CodeGen/CodeGenFunction.cpp:425
 /// instrumented with __cyg_profile_func_* calls
-bool CodeGenFunction::ShouldInstrumentFunction() {
+bool CodeGenFunction::ShouldInstrumentFunction(llvm::Function *Fn) {
+  typedef std::vector::const_iterator CIt;

This parameter can be `const`.



Comment at: lib/CodeGen/CodeGenFunction.cpp:436
+  // to resolve.
+  const FunctionDecl *ActualFuncDecl = dyn_cast(CurFuncDecl);
+  if (ActualFuncDecl &&

Can use `const auto *` here.



Comment at: lib/CodeGen/CodeGenFunction.cpp:444
+  SourceLocation SLoc = CurFuncDecl->getLocation();
+  static std::unordered_map cache;
+

This static has me worried. Does this data need to be cached across codegen 
modules? If not, perhaps this variable can be hung onto the CodeGenModule 
instead?

The variable should be named `Cache` instead of `cache`. Also, is an 
`unordered_map` the correct data structure to use? Would a `DenseMap` make more 
sense because the keys and values are both small (`PresumedLoc::getFilename()` 
returns a `const char *` that I believe can be used).



Comment at: lib/CodeGen/CodeGenFunction.cpp:447
+  if (SLoc.isFileID()) {
+unsigned key = SLoc.getRawEncoding();
+if (cache.find(key) == cache.end()) {

key -> Key



Comment at: lib/CodeGen/CodeGenFunction.cpp:449
+if (cache.find(key) == cache.end()) {
+  ASTContext &ctx = CurFuncDecl->getASTContext();
+  const SourceManager &SM = ctx.getSourceManager();

ctx -> CTX, and I think this can be a const ref.



Comment at: lib/CodeGen/CodeGenFunction.cpp:460-461
+
+for (CIt i = PathSearch.begin(), e = PathSearch.end(); i != e; ++i) {
+  if(FunctionDeclPath.find(*i) != std::string::npos) {
+return false;

You can use a range-based for loop here instead, and then get rid of the 
typedef for `CIt`.



Comment at: lib/CodeGen/CodeGenFunction.cpp:467
+
+  std::string FunctionName = Fn->getName();
+

You can avoid the copy here by assigning to a `StringRef` instead.



Comment at: lib/CodeGen/CodeGenFunction.cpp:472
+  if (ActualFuncDecl && !ActualFuncDecl->isExternC()) {
+int status = 0;
+char *result = __cxa_demangle(FunctionName.c_str(), 0, 0, &status);

status -> Status



Comment at: lib/CodeGen/CodeGenFunction.cpp:473
+int status = 0;
+char *result = __cxa_demangle(FunctionName.c_str(), 0, 0, &status);
+

result -> Result



Comment at: lib/CodeGen/CodeGenFunction.cpp:486
+CGM.getCodeGenOpts().InstrumentFunctionExclusionsFunctions;
+  for (CIt i = FunctionSearch.begin(), e = FunctionSearch.end(); i != e; ++i) {
+if(FunctionName.find(*i) != std::string::npos) {

Can use a range-based for loop here.


https://reviews.llvm.org/D37624



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


[PATCH] D37572: [clang-tidy] SuspiciousEnumUsageCheck bugfix

2017-09-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: test/clang-tidy/misc-suspicious-enum-usage.cpp:122
+struct a> {
+  enum { ah = ad::m,
+ ai = ae::m,

alexfh wrote:
> aaron.ballman wrote:
> > This seems like a lot of complicated code for the test case -- can this be 
> > reduced further?
> This is the best creduce could do. It should be possible to make this much 
> shorter, but I wouldn't spend too much time on that.
I'd appreciate the time spent because this is an almost-unintelligible test for 
anyone reading it -- it's hard to understand what's going on there.


https://reviews.llvm.org/D37572



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


[PATCH] D37150: [clangd] Command line arg to specify compile_commands.json path

2017-09-08 Thread William Enright via Phabricator via cfe-commits
Nebiroth updated this revision to Diff 114371.
Nebiroth marked 10 inline comments as done.
Nebiroth added a comment.

Ran clang-format on modified files.
More minor refactoring.


https://reviews.llvm.org/D37150

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/GlobalCompilationDatabase.cpp
  clangd/GlobalCompilationDatabase.h
  clangd/tool/ClangdMain.cpp

Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -11,8 +11,8 @@
 #include "JSONRPCDispatcher.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
-
 #include 
 #include 
 #include 
@@ -25,16 +25,43 @@
  llvm::cl::desc("parse on main thread"),
  llvm::cl::init(false), llvm::cl::Hidden);
 
+static llvm::cl::opt CompileCommandsDir(
+"compile-commands-dir",
+llvm::cl::desc("Specify a path to look for compile_commands.json. If path "
+   "is invalid, clangd will look in the current directory and "
+   "parent paths of each source file."));
+
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "clangd");
 
   llvm::raw_ostream &Outs = llvm::outs();
   llvm::raw_ostream &Logs = llvm::errs();
   JSONOutput Out(Outs, Logs);
 
+  // If --compile-commands-dir arg was invoked, check value and override default
+  // path.
+  namespace path = llvm::sys::path;
+
+  if (!llvm::sys::path::is_absolute(CompileCommandsDir)) {
+Out.log("Path specified by --compile-commands-dir must be an absolute "
+"path. The argument will be ignored.\n");
+CompileCommandsDir = "";
+  }
+
+  if (!llvm::sys::fs::exists(CompileCommandsDir)) {
+Out.log("Path specified by --compile-commands-dir. The argument will be "
+"ignored.\n");
+CompileCommandsDir = "";
+  }
+  llvm::Optional CompileCommandsDirPath;
+
   // Change stdin to binary to not lose \r\n on windows.
   llvm::sys::ChangeStdinToBinary();
+  if (CompileCommandsDir.empty())
+CompileCommandsDirPath = llvm::None;
+  else
+CompileCommandsDirPath = CompileCommandsDir;
 
-  ClangdLSPServer LSPServer(Out, RunSynchronously);
+  ClangdLSPServer LSPServer(Out, RunSynchronously, CompileCommandsDirPath);
   LSPServer.run(std::cin);
 }
Index: clangd/GlobalCompilationDatabase.h
===
--- clangd/GlobalCompilationDatabase.h
+++ clangd/GlobalCompilationDatabase.h
@@ -45,13 +45,18 @@
 class DirectoryBasedGlobalCompilationDatabase
 : public GlobalCompilationDatabase {
 public:
+  DirectoryBasedGlobalCompilationDatabase(
+  llvm::Optional NewCompileCommandsDir)
+  : CompileCommandsDir(NewCompileCommandsDir.getValue()) {}
   std::vector
   getCompileCommands(PathRef File) override;
 
   void setExtraFlagsForFile(PathRef File, std::vector ExtraFlags);
 
 private:
   tooling::CompilationDatabase *getCompilationDatabase(PathRef File);
+  Path CompileCommandsDir;
+  tooling::CompilationDatabase *tryLoadDatabaseFromPath(PathRef File);
 
   std::mutex Mutex;
   /// Caches compilation databases loaded from directories(keys are
Index: clangd/GlobalCompilationDatabase.cpp
===
--- clangd/GlobalCompilationDatabase.cpp
+++ clangd/GlobalCompilationDatabase.cpp
@@ -62,43 +62,55 @@
 }
 
 tooling::CompilationDatabase *
-DirectoryBasedGlobalCompilationDatabase::getCompilationDatabase(PathRef File) {
-  std::lock_guard Lock(Mutex);
-
+DirectoryBasedGlobalCompilationDatabase::tryLoadDatabaseFromPath(PathRef File) {
   namespace path = llvm::sys::path;
+  auto CachedIt = CompilationDatabases.find(File);
+  std::string Error = "";
 
   assert((path::is_absolute(File, path::Style::posix) ||
   path::is_absolute(File, path::Style::windows)) &&
  "path must be absolute");
 
-  for (auto Path = path::parent_path(File); !Path.empty();
-   Path = path::parent_path(Path)) {
-
-auto CachedIt = CompilationDatabases.find(Path);
-if (CachedIt != CompilationDatabases.end())
-  return CachedIt->second.get();
-std::string Error;
-auto CDB = tooling::CompilationDatabase::loadFromDirectory(Path, Error);
-if (!CDB) {
-  if (!Error.empty()) {
-// FIXME(ibiryukov): logging
-// Output.log("Error when trying to load compilation database from " +
-//Twine(Path) + ": " + Twine(Error) + "\n");
-  }
-  continue;
-}
+  if (CachedIt != CompilationDatabases.end())
+return (CachedIt->second.get());
+  auto CDB = tooling::CompilationDatabase::loadFromDirectory(File, Error);
+  if (CDB && Error.empty()) {
+auto result = CDB.get();
+CompilationDatabases.insert(std::make_pair(File, std::move(CDB)));
 
 // FIXME(ibiryukov): Invalidate cached compil

[PATCH] D33852: Enable __declspec(selectany) on linux

2017-09-08 Thread David Majnemer via Phabricator via cfe-commits
majnemer added inline comments.



Comment at: include/clang/Basic/AttrDocs.td:3154
+
+def SelectAnyDocs : Documentation {
+   let Content = [{This attribute makes global symbol have a weak definition

aaron.ballman wrote:
> Prazek wrote:
> > aaron.ballman wrote:
> > > Prazek wrote:
> > > > aaron.ballman wrote:
> > > > > I think you need to set the `Category` as well.
> > > > > 
> > > > > To test this you should run something like (replacing  and 
> > > > > fixing up path separators as needed):
> > > > > ```
> > > > > clang-tblgen -gen-attr-docs -I \llvm\tools\clang\include 
> > > > > \llvm\tools\clang\include\clang\Basic\Attr.td -o 
> > > > > \llvm\tools\clang\docs\AttributeReference.rst
> > > > > ```
> > > > Thanks for the testing command. Should I do anything in order to check 
> > > > if docs build?
> > > > I enabled docs with -DLLVM_BUILD_DOCS=ON, and I have sphinx. Everything 
> > > > builds, but I don't see docs anywhere.
> > > > 
> > > > the docs looks like this:
> > > > +selectany (gnu::selectany)
> > > > +--
> > > > +.. csv-table:: Supported Syntaxes
> > > > +   :header: "GNU", "C++11", "__declspec", "Keyword", "Pragma", "Pragma 
> > > > clang attribute"
> > > > +
> > > > +   "X","X","X","", "", ""
> > > > +
> > > > +This attribute appertains to a global symbol, causing it to have a weak
> > > > +definition (
> > > > +.. _`linkonce`: https://llvm.org/docs/LangRef.html#linkage-types
> > > > +), allowing the linker to select any definition.
> > > > +
> > > > +For more information see
> > > > +.. `gcc documentation`: 
> > > > https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Microsoft-Windows-Variable-Attributes.html
> > > > +
> > > > Thanks for the testing command. Should I do anything in order to check 
> > > > if docs build?
> > > 
> > > On Windows, I use `make html` within the clang\docs directory to generate 
> > > the actual sphinx docs -- that will tell you if there are sphinx issues. 
> > > Be sure you do *not* commit the AttributeReference.rst file that it 
> > > generates, however.
> > I tried building docs but it doesn't seem that there is any target like 
> > "html". Do you know if there is documentation on how to build docs? I 
> > couldn't find any.
> I don't know that we have any docs on that, but I believe the command you 
> want to execute is `sphinx-build -b html -d _build/doctrees . _build/html` (I 
> pulled this from make.bat in the docs directory.)
This is not the first time this has come up. Can you please add a comment to 
the top of AttrDocs.td which explains how to generate the HTML?


https://reviews.llvm.org/D33852



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


[PATCH] D37629: [Sema] Move some stuff into -Wtautological-unsigned-enum-zero-compare

2017-09-08 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri created this revision.
lebedev.ri added a project: clang.

As requested by Sam McCall:

> Enums (not new I guess). Typical case: if (enum < 0 || enum > MAX)
>  The warning strongly suggests that the enum < 0 check has no effect
>  (for enums with nonnegative ranges).
>  Clang doesn't seem to optimize such checks out though, and they seem
>  likely to catch bugs in some cases. Yes, only if there's UB elsewhere,
>  but I assume not optimizing out these checks indicates a deliberate
>  decision to stay somewhat compatible with a technically-incorrect
>  mental model.
>  If this is the case, should we move these to a
>  -Wtautological-compare-enum subcategory?


Repository:
  rL LLVM

https://reviews.llvm.org/D37629

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/Sema/compare.c
  test/Sema/tautological-unsigned-enum-zero-compare.c

Index: test/Sema/tautological-unsigned-enum-zero-compare.c
===
--- /dev/null
+++ test/Sema/tautological-unsigned-enum-zero-compare.c
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -fsyntax-only -DTEST -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-enum-zero-compare -verify %s
+
+int main() {
+  enum A { A_foo, A_bar };
+  enum A a;
+
+#ifdef TEST
+  if (a < 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
+return 0;
+  if (a >= 0) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
+return 0;
+  if (0 <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
+return 0;
+  if (0 > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
+return 0;
+  if (a < 0U) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
+return 0;
+  if (a >= 0U) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
+return 0;
+  if (0U <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
+return 0;
+  if (0U > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
+return 0;
+#else
+  // expected-no-diagnostics
+  if (a < 0)
+return 0;
+  if (a >= 0)
+return 0;
+  if (0 <= a)
+return 0;
+  if (0 > a)
+return 0;
+  if (a < 0U)
+return 0;
+  if (a >= 0U)
+return 0;
+  if (0U <= a)
+return 0;
+  if (0U > a)
+return 0;
+#endif
+
+  return 1;
+}
Index: test/Sema/compare.c
===
--- test/Sema/compare.c
+++ test/Sema/compare.c
@@ -308,8 +308,59 @@
 int rdar8511238() {
   enum A { A_foo, A_bar };
   enum A a;
+
+  if (a == 0)
+  return 0;
+  if (a != 0)
+  return 0;
   if (a < 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
-return 0;
+  return 0;
+  if (a <= 0)
+  return 0;
+  if (a > 0)
+  return 0;
+  if (a >= 0) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
+  return 0;
+
+  if (0 == a)
+  return 0;
+  if (0 != a)
+  return 0;
+  if (0 < a)
+  return 0;
+  if (0 <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
+  return 0;
+  if (0 > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
+  return 0;
+  if (0 >= a)
+  return 0;
+
+  if (a == 0U)
+  return 0;
+  if (a != 0U)
+  return 0;
+  if (a < 0U) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
+  return 0;
+  if (a <= 0U)
+  return 0;
+  if (a > 0U)
+  return 0;
+  if (a >= 0U) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
+  return 0;
+
+  if (0U == a)
+  return 0;
+  if (0U != a)
+  return 0;
+  if (0U < a)
+  return 0;
+  if (0U <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
+  return 0;
+  if (0U > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
+  return 0;
+  if (0U >= a)
+  return 0;
+
   return 20;
 }
 
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -8590,28 +8590,72 @@
   Expr *LHS = E->getLHS();
   Expr *RHS = E->getRHS();
 
-  bool Match = true;
+  // is this a tautological comparison? if yes, than contains the always-result
+  llvm::Optional Result;
+  Expr *Value; // which one is the value, and not a constant?
+  const char *cmp; // the comparison used, as string
 
   if (op == BO_LT && isNonBooleanUnsignedValue(LHS) && IsZero(S, RHS)) {
-S.Diag(E->getOperatorLoc(), diag::warn_lunsigned_always_true_comparison)
-  << "< 0" << "false" << HasEnumType(LHS)
-  << LHS->getSourceRange()

Re: r312750 - [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

2017-09-08 Thread Roman Lebedev via cfe-commits
On Fri, Sep 8, 2017 at 3:26 PM, Roman Lebedev  wrote:
> On Fri, Sep 8, 2017 at 2:48 PM, Sam McCall  wrote:
> Hi.
>
>> Nice fix!
> Thank you!
>
>> It catches a lot of new cases on our codebase, all technically
>> correct so far.
>>
>> A couple of issues though:
>> A) Rollout - until we've completely cleaned up, we need to disable
>> -Wtautological-compare entirely, which is a valuable check. I imagine anyone
>> else using -Werror is in the same boat.
>> What do you think about putting the new warnings behind a subcategory? (e.g.
>> -Wtautological-compare-unsigned-zero, implied by -Wtautological-compare)
>> It's an ugly artifact of the history here, but allows this fix to be rolled
>> out in a controlled way.
> https://reviews.llvm.org/D37620
And landed.

>> B) Enums (not new I guess). Typical case: if (enum < 0 || enum > MAX)
>> The warning strongly suggests that the enum < 0 check has no effect (for
>> enums with nonnegative ranges).
>> Clang doesn't seem to optimize such checks out though, and they seem likely
>> to catch bugs in some cases. Yes, only if there's UB elsewhere, but I assume
>> not optimizing out these checks indicates a deliberate decision to stay
>> somewhat compatible with a technically-incorrect mental model.
>> If this is the case, should we move these to a -Wtautological-compare-enum
>> subcategory?
> (Did not look at this yet)
https://reviews.llvm.org/D37629 i hope that is what you meant.

> Roman.
Roman.

>> On Fri, Sep 8, 2017 at 12:14 AM, Roman Lebedev via cfe-commits
>>  wrote:
>>>
>>> Author: lebedevri
>>> Date: Thu Sep  7 15:14:25 2017
>>> New Revision: 312750
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=312750&view=rev
>>> Log:
>>> [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.
>>>
>>> Summary:
>>> This is a first half(?) of a fix for the following bug:
>>> https://bugs.llvm.org/show_bug.cgi?id=34147 (gcc -Wtype-limits)
>>>
>>> GCC's -Wtype-limits does warn on comparison of unsigned value
>>> with signed zero (as in, with 0), but clang only warns if the
>>> zero is unsigned (i.e. 0U).
>>>
>>> Also, be careful not to double-warn, or falsely warn on
>>> comparison of signed/fp variable and signed 0.
>>>
>>> Yes, all these testcases are needed.
>>>
>>> Testing: $ ninja check-clang-sema check-clang-semacxx
>>> Also, no new warnings for clang stage-2 build.
>>>
>>> Reviewers: rjmccall, rsmith, aaron.ballman
>>>
>>> Reviewed By: rjmccall
>>>
>>> Subscribers: cfe-commits
>>>
>>> Tags: #clang
>>>
>>> Differential Revision: https://reviews.llvm.org/D37565
>>>
>>> Modified:
>>> cfe/trunk/docs/ReleaseNotes.rst
>>> cfe/trunk/lib/Sema/SemaChecking.cpp
>>> cfe/trunk/test/Sema/compare.c
>>> cfe/trunk/test/Sema/outof-range-constant-compare.c
>>> cfe/trunk/test/SemaCXX/compare.cpp
>>>
>>> Modified: cfe/trunk/docs/ReleaseNotes.rst
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=312750&r1=312749&r2=312750&view=diff
>>>
>>> ==
>>> --- cfe/trunk/docs/ReleaseNotes.rst (original)
>>> +++ cfe/trunk/docs/ReleaseNotes.rst Thu Sep  7 15:14:25 2017
>>> @@ -71,6 +71,13 @@ Improvements to Clang's diagnostics
>>>errors/warnings, as the system frameworks might add a method with the
>>> same
>>>selector which could make the message send to ``id`` ambiguous.
>>>
>>> +- ``-Wtautological-compare`` now warns when comparing an unsigned integer
>>> and 0
>>> +  regardless of whether the constant is signed or unsigned."
>>> +
>>> +- ``-Wtautological-compare`` now warns about comparing a signed integer
>>> and 0
>>> +  when the signed integer is coerced to an unsigned type for the
>>> comparison.
>>> +  ``-Wsign-compare`` was adjusted not to warn in this case.
>>> +
>>>  Non-comprehensive list of changes in this release
>>>  -
>>>
>>>
>>> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=312750&r1=312749&r2=312750&view=diff
>>>
>>> ==
>>> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
>>> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Sep  7 15:14:25 2017
>>> @@ -8567,32 +8567,51 @@ bool HasEnumType(Expr *E) {
>>>return E->getType()->isEnumeralType();
>>>  }
>>>
>>> -void CheckTrivialUnsignedComparison(Sema &S, BinaryOperator *E) {
>>> +bool isNonBooleanUnsignedValue(Expr *E) {
>>> +  // We are checking that the expression is not known to have boolean
>>> value,
>>> +  // is an integer type; and is either unsigned after implicit casts,
>>> +  // or was unsigned before implicit casts.
>>> +  return !E->isKnownToHaveBooleanValue() && E->getType()->isIntegerType()
>>> &&
>>> + (!E->getType()->isSignedIntegerType() ||
>>> +  !E->IgnoreParenImpCasts()->getType()->isSignedIntegerType());
>>> +}
>>> +
>>> +bool CheckTautologicalCo

[PATCH] D37299: [Modules] Add ability to specify module name to module file mapping in a file

2017-09-08 Thread Boris Kolpackov via Phabricator via cfe-commits
boris added a comment.

Ping.


https://reviews.llvm.org/D37299



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


[PATCH] D33852: Enable __declspec(selectany) on linux

2017-09-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/Basic/AttrDocs.td:3154
+
+def SelectAnyDocs : Documentation {
+   let Content = [{This attribute makes global symbol have a weak definition

majnemer wrote:
> aaron.ballman wrote:
> > Prazek wrote:
> > > aaron.ballman wrote:
> > > > Prazek wrote:
> > > > > aaron.ballman wrote:
> > > > > > I think you need to set the `Category` as well.
> > > > > > 
> > > > > > To test this you should run something like (replacing  and 
> > > > > > fixing up path separators as needed):
> > > > > > ```
> > > > > > clang-tblgen -gen-attr-docs -I \llvm\tools\clang\include 
> > > > > > \llvm\tools\clang\include\clang\Basic\Attr.td -o 
> > > > > > \llvm\tools\clang\docs\AttributeReference.rst
> > > > > > ```
> > > > > Thanks for the testing command. Should I do anything in order to 
> > > > > check if docs build?
> > > > > I enabled docs with -DLLVM_BUILD_DOCS=ON, and I have sphinx. 
> > > > > Everything builds, but I don't see docs anywhere.
> > > > > 
> > > > > the docs looks like this:
> > > > > +selectany (gnu::selectany)
> > > > > +--
> > > > > +.. csv-table:: Supported Syntaxes
> > > > > +   :header: "GNU", "C++11", "__declspec", "Keyword", "Pragma", 
> > > > > "Pragma clang attribute"
> > > > > +
> > > > > +   "X","X","X","", "", ""
> > > > > +
> > > > > +This attribute appertains to a global symbol, causing it to have a 
> > > > > weak
> > > > > +definition (
> > > > > +.. _`linkonce`: https://llvm.org/docs/LangRef.html#linkage-types
> > > > > +), allowing the linker to select any definition.
> > > > > +
> > > > > +For more information see
> > > > > +.. `gcc documentation`: 
> > > > > https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Microsoft-Windows-Variable-Attributes.html
> > > > > +
> > > > > Thanks for the testing command. Should I do anything in order to 
> > > > > check if docs build?
> > > > 
> > > > On Windows, I use `make html` within the clang\docs directory to 
> > > > generate the actual sphinx docs -- that will tell you if there are 
> > > > sphinx issues. Be sure you do *not* commit the AttributeReference.rst 
> > > > file that it generates, however.
> > > I tried building docs but it doesn't seem that there is any target like 
> > > "html". Do you know if there is documentation on how to build docs? I 
> > > couldn't find any.
> > I don't know that we have any docs on that, but I believe the command you 
> > want to execute is `sphinx-build -b html -d _build/doctrees . _build/html` 
> > (I pulled this from make.bat in the docs directory.)
> This is not the first time this has come up. Can you please add a comment to 
> the top of AttrDocs.td which explains how to generate the HTML?
Definitely a good idea, I'll tackle it when I have a moment.


https://reviews.llvm.org/D33852



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


r312795 - Add '\n' in ClangDataCollectorsEmitter

2017-09-08 Thread Konstantin Zhuravlyov via cfe-commits
Author: kzhuravl
Date: Fri Sep  8 09:17:16 2017
New Revision: 312795

URL: http://llvm.org/viewvc/llvm-project?rev=312795&view=rev
Log:
Add '\n' in ClangDataCollectorsEmitter

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

Modified:
cfe/trunk/utils/TableGen/ClangDataCollectorsEmitter.cpp

Modified: cfe/trunk/utils/TableGen/ClangDataCollectorsEmitter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangDataCollectorsEmitter.cpp?rev=312795&r1=312794&r2=312795&view=diff
==
--- cfe/trunk/utils/TableGen/ClangDataCollectorsEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangDataCollectorsEmitter.cpp Fri Sep  8 09:17:16 
2017
@@ -8,7 +8,7 @@ void EmitClangDataCollectors(RecordKeepe
   const auto &Defs = RK.getClasses();
   for (const auto &Entry : Defs) {
 Record &R = *Entry.second;
-OS << "DEF_ADD_DATA(" << R.getName() << ", {";
+OS << "DEF_ADD_DATA(" << R.getName() << ", {\n";
 auto Code = R.getValue("Code")->getValue();
 OS << Code->getAsUnquotedString() << "}\n)";
 OS << "\n";


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


[PATCH] D37599: Add '\n' in ClangDataCollectorsEmitter

2017-09-08 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL312795: Add '\n' in ClangDataCollectorsEmitter (authored by 
kzhuravl).

Changed prior to commit:
  https://reviews.llvm.org/D37599?vs=114269&id=114376#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37599

Files:
  cfe/trunk/utils/TableGen/ClangDataCollectorsEmitter.cpp


Index: cfe/trunk/utils/TableGen/ClangDataCollectorsEmitter.cpp
===
--- cfe/trunk/utils/TableGen/ClangDataCollectorsEmitter.cpp
+++ cfe/trunk/utils/TableGen/ClangDataCollectorsEmitter.cpp
@@ -8,7 +8,7 @@
   const auto &Defs = RK.getClasses();
   for (const auto &Entry : Defs) {
 Record &R = *Entry.second;
-OS << "DEF_ADD_DATA(" << R.getName() << ", {";
+OS << "DEF_ADD_DATA(" << R.getName() << ", {\n";
 auto Code = R.getValue("Code")->getValue();
 OS << Code->getAsUnquotedString() << "}\n)";
 OS << "\n";


Index: cfe/trunk/utils/TableGen/ClangDataCollectorsEmitter.cpp
===
--- cfe/trunk/utils/TableGen/ClangDataCollectorsEmitter.cpp
+++ cfe/trunk/utils/TableGen/ClangDataCollectorsEmitter.cpp
@@ -8,7 +8,7 @@
   const auto &Defs = RK.getClasses();
   for (const auto &Entry : Defs) {
 Record &R = *Entry.second;
-OS << "DEF_ADD_DATA(" << R.getName() << ", {";
+OS << "DEF_ADD_DATA(" << R.getName() << ", {\n";
 auto Code = R.getValue("Code")->getValue();
 OS << Code->getAsUnquotedString() << "}\n)";
 OS << "\n";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.

2017-09-08 Thread kchoi via Phabricator via cfe-commits
choikwa updated this revision to Diff 114380.
choikwa added a comment.

addressed code review. made doc consistent with functionality.


https://reviews.llvm.org/D37624

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/instrument-functions.c

Index: test/CodeGen/instrument-functions.c
===
--- test/CodeGen/instrument-functions.c
+++ test/CodeGen/instrument-functions.c
@@ -1,18 +1,66 @@
-// RUN: %clang_cc1 -S -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-functions | FileCheck %s
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions | FileCheck %s
+// RUN: %clang -S -emit-llvm -o - %s -fno-instrument-functions | FileCheck %s --check-prefix=NOINSTR
+
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-file-list=instrument | FileCheck %s --check-prefix=NOFILE
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=NOFUNC
 
 // CHECK: @test1
+// NOINSTR: @test1
+// NOFILE: @test1
+// NOFUNC: @test1
 int test1(int x) {
-// CHECK: call void @__cyg_profile_func_enter({{.*}}, !dbg
-// CHECK: call void @__cyg_profile_func_exit({{.*}}, !dbg
+// CHECK: __cyg_profile_func_enter
+// CHECK: __cyg_profile_func_exit
 // CHECK: ret
+// NOINSTR-NOT: __cyg_profile_func_enter
+// NOINSTR-NOT: __cyg_profile_func_exit
+// NOINSTR: ret
+// NOFILE-NOT: __cyg_profile_func_enter
+// NOFILE-NOT: __cyg_profile_func_exit
+// NOFILE: ret
+// NOFUNC: __cyg_profile_func_enter
+// NOFUNC: __cyg_profile_func_exit
+// NOFUNC: ret
   return x;
 }
 
 // CHECK: @test2
+// NOINSTR: @test2
+// NOFILE: @test2
+// NOFUNC: @test2
 int test2(int) __attribute__((no_instrument_function));
 int test2(int x) {
 // CHECK-NOT: __cyg_profile_func_enter
 // CHECK-NOT: __cyg_profile_func_exit
 // CHECK: ret
+// NOINSTR-NOT: __cyg_profile_func_enter
+// NOINSTR-NOT: __cyg_profile_func_exit
+// NOINSTR: ret
+// NOFILE-NOT: __cyg_profile_func_enter
+// NOFILE-NOT: __cyg_profile_func_exit
+// NOFILE: ret
+// NOFUNC-NOT: __cyg_profile_func_enter
+// NOFUNC-NOT: __cyg_profile_func_exit
+// NOFUNC: ret
+  return x;
+}
+
+// CHECK: @test3
+// NOINSTR: @test3
+// NOFILE: @test3
+// NOFUNC: @test3
+int test3(int x) {
+// CHECK: __cyg_profile_func_enter
+// CHECK: __cyg_profile_func_exit
+// CHECK: ret
+// NOINSTR-NOT: __cyg_profile_func_enter
+// NOINSTR-NOT: __cyg_profile_func_exit
+// NOINSTR: ret
+// NOFILE-NOT: __cyg_profile_func_enter
+// NOFILE-NOT: __cyg_profile_func_exit
+// NOFILE: ret
+// NOFUNC-NOT: __cyg_profile_func_enter
+// NOFUNC-NOT: __cyg_profile_func_exit
+// NOFUNC: ret
   return x;
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -771,6 +771,12 @@
 
   Opts.PreserveVec3Type = Args.hasArg(OPT_fpreserve_vec3_type);
   Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions);
+  if (Opts.InstrumentFunctions) {
+Opts.InstrumentFunctionExclusionsFunctions
+= Args.getAllArgValues(OPT_finstrument_functions_exclude_function_list);
+Opts.InstrumentFunctionExclusionsPathSegments
+= Args.getAllArgValues(OPT_finstrument_functions_exclude_file_list);
+  }
   Opts.XRayInstrumentFunctions = Args.hasArg(OPT_fxray_instrument);
   Opts.XRayInstructionThreshold =
   getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3519,7 +3519,14 @@
 options::OPT_fno_unique_section_names, true))
 CmdArgs.push_back("-fno-unique-section-names");
 
-  Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions);
+  if (Args.hasArg(options::OPT_finstrument_functions,
+  options::OPT_fno_instrument_functions, false)) {
+Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions);
+Args.AddAllArgs(CmdArgs,
+options::OPT_finstrument_functions_exclude_file_list);
+Args.AddAllArgs(CmdArgs,
+options::OPT_finstrument_functions_exclude_function_list);
+  }
 
   addPGOAndCoverageFlags(C, D, Output, Args, CmdArgs);
 
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -1762,7 +1762,7 @@
 
   /// ShouldInstrumentFunction - Return true if the current function should be
   /// instrumented with __cyg_profile_func_* calls
-  bool ShouldInstrumentFunction();
+  bool ShouldInstru

[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.

2017-09-08 Thread kchoi via Phabricator via cfe-commits
choikwa added a comment.

Forgot to hang Cache to CodeGenModule, will do that shortly


https://reviews.llvm.org/D37624



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


r312798 - Add _Float16 as a C/C++ source language type

2017-09-08 Thread Sjoerd Meijer via cfe-commits
Author: sjoerdmeijer
Date: Fri Sep  8 09:43:10 2017
New Revision: 312798

URL: http://llvm.org/viewvc/llvm-project?rev=312798&view=rev
Log:
Add _Float16 as a C/C++ source language type

Pacify the windows builder; fixed the new test as on Windows some additional
attributes are printed.


Modified:
cfe/trunk/test/Frontend/float16.cpp

Modified: cfe/trunk/test/Frontend/float16.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/float16.cpp?rev=312798&r1=312797&r2=312798&view=diff
==
--- cfe/trunk/test/Frontend/float16.cpp (original)
+++ cfe/trunk/test/Frontend/float16.cpp Fri Sep  8 09:43:10 2017
@@ -116,7 +116,7 @@ public:
 //CHECK-NEXT: | |-VarDecl {{.*}} used f2c 'const _Float16' static
 //CHECK-NEXT: | |-FieldDecl {{.*}} f3c 'volatile _Float16'
 //CHECK-NEXT: | |-AccessSpecDecl
-//CHECK-NEXT: | |-CXXConstructorDecl {{.*}} used C1 'void (_Float16)'
+//CHECK-NEXT: | |-CXXConstructorDecl {{.*}} used C1 'void (_Float16)
 //CHECK-NEXT: | | |-ParmVarDecl {{.*}} used arg '_Float16'
 //CHECK-NEXT: | | |-CXXCtorInitializer Field {{.*}} 'f1c' '_Float16'
 //CHECK-NEXT: | | | `-ImplicitCastExpr {{.*}} '_Float16' 
@@ -125,7 +125,7 @@ public:
 //CHECK-NEXT: | | | `-ImplicitCastExpr {{.*}} '_Float16' 
 //CHECK-NEXT: | | |   `-DeclRefExpr {{.*}} '_Float16' lvalue ParmVar 0x{{.*}} 
'arg' '_Float16'
 //CHECK-NEXT: | | `-CompoundStmt
-//CHECK-NEXT: | |-CXXMethodDecl {{.*}} used func1c '_Float16 (_Float16)'
+//CHECK-NEXT: | |-CXXMethodDecl {{.*}} used func1c '_Float16 (_Float16)
 //CHECK-NEXT: | | |-ParmVarDecl {{.*}} used arg '_Float16'
 //CHECK-NEXT: | | `-CompoundStmt
 //CHECK-NEXT: | |   `-ReturnStmt
@@ -209,7 +209,7 @@ int main(void) {
 
   C1 c1(f1l);
 //CHECK:   | `-VarDecl{{.*}} used c1 'class C1' callinit
-//CHECK-NEXT:  |   `-CXXConstructExpr {{.*}} 'class C1' 'void (_Float16)'
+//CHECK-NEXT:  |   `-CXXConstructExpr {{.*}} 'class C1' 'void (_Float16)
 //CHECK-NEXT:  | `-ImplicitCastExpr {{.*}} '_Float16' 
 //CHECK-NEXT:  |   `-DeclRefExpr {{.*}} '_Float16' lvalue Var 0x{{.*}} 
'f1l' '_Float16'
 


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


[PATCH] D37599: Add '\n' in ClangDataCollectorsEmitter

2017-09-08 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
kzhuravl added a comment.

In https://reviews.llvm.org/D37599#864376, @arphaman wrote:

> LGTM. Do you have commit access?


Yep, committed. Thanks.


Repository:
  rL LLVM

https://reviews.llvm.org/D37599



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


[PATCH] D35082: [OpenCL] Add LangAS::opencl_private to represent private address space in AST

2017-09-08 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/Sema/SemaType.cpp:6994
+  // OpenCL v1.2 s6.5:
+  // The generic address space name for arguments to a function in a
+  // program, or local variables of a function is __private. All function

yaxunl wrote:
> Anastasia wrote:
> > yaxunl wrote:
> > > Anastasia wrote:
> > > > The generic address space -> The default address space
> > > 'The generic address space name for arguments' is literally from the 
> > > OpenCL 1.2 spec. Note it refers 'generic address space name', which is 
> > > not the 'generic address space' defined by OpenCL 2.0 spec.
> > True, but this spec was written before v2.0 was released. And I feel now it 
> > makes things confusing considering that we have v2.0 implementation too.
> I can make the change. I just feel a little bit uneasy since this looks like 
> a citation but actually is rephrased.
Cool! Thanks!


https://reviews.llvm.org/D35082



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


[PATCH] D33514: [WIP] Bug 32352 - Provide a way for OptimizationRemarkEmitter::allowExtraAnalysis to check if (specific) remarks are enabled

2017-09-08 Thread Adam Nemet via Phabricator via cfe-commits
anemet added a comment.

Only minor things at this point.  This is very close now.




Comment at: include/llvm/Analysis/OptimizationDiagnosticInfo.h:81
   /// detected by the user.
-  bool allowExtraAnalysis() const {
-// For now, only allow this with -fsave-optimization-record since the 
-Rpass
-// options are handled in the front-end.
-return F->getContext().getDiagnosticsOutputFile();
+  bool allowExtraAnalysis(StringRef &&PassName) const {
+return (F->getContext().getDiagnosticsOutputFile() ||

Why rvalue reference, you should just take this by value.  There is no 
ownership transfer here.



Comment at: include/llvm/Analysis/OptimizationDiagnosticInfo.h:84
+F->getContext().getDiagHandler()->isAnyRemarkEnabled(
+std::move(PassName)));
   }

No std::move here.  You have more of this later.



Comment at: include/llvm/IR/DiagnosticHandler.h:13
+
+#include "llvm/Support/Regex.h"
+

I don't think you need this.



Comment at: include/llvm/IR/DiagnosticHandler.h:18
+
+struct DiagnosticHandler {
+public:

Please add a comment before the class.



Comment at: include/llvm/IR/DiagnosticHandler.h:19
+struct DiagnosticHandler {
+public:
+  void *DiagnosticContext = nullptr;

No need for public for struct.



Comment at: include/llvm/IR/DiagnosticHandler.h:27
+
+  /// DiagHandlerCallback is settable from the C API and base implimentation
+  /// of DiagnosticHandler will call it from handleDiagnostics(). Any derived

implementation 



Comment at: include/llvm/IR/DiagnosticHandler.h:45
+
+  /// checks if remark requested with -pass-remarks-analysis, override
+  /// to provide different implementation

Capitalize first word and end with period; comments are full sentences. 



Comment at: include/llvm/IR/DiagnosticHandler.h:57
+
+  /// checks if remark requested with -pass-remarks{-missed/-analysis}
+  bool isAnyRemarkEnabled(StringRef &&PassName) const {

I would drop the flag names here since if those are overridden this is not 
true.  Just say "Return true if any remark type is enabled."



Comment at: lib/IR/DiagnosticInfo.cpp:47-65
 /// \brief Regular expression corresponding to the value given in one of the
 /// -pass-remarks* command line flags. Passes whose name matches this regexp
 /// will emit a diagnostic via ORE->emit(...);
 struct PassRemarksOpt {
   std::shared_ptr Pattern;
 
   void operator=(const std::string &Val) {

Is this still used here?



Comment at: lib/LTO/LTOCodeGenerator.cpp:667-668
-return Context.setDiagnosticHandler(nullptr, nullptr);
-  // Register the LTOCodeGenerator stub in the LLVMContext to forward the
-  // diagnostic to the external DiagHandler.
-  Context.setDiagnosticHandler(LTOCodeGenerator::DiagnosticHandler, this,

I think that this comment still applies.



Comment at: tools/llvm-lto/llvm-lto.cpp:39-72
+static std::string CurrentActivity;
+namespace {
+struct LLVMLTODiagnosticHandler : public DiagnosticHandler {
+  bool handleDiagnostics(const DiagnosticInfo &DI) override {
+raw_ostream &OS = errs();
+OS << "llvm-lto: ";
+switch (DI.getSeverity()) {

Don't move this code unless you have to.  The diff is easier to read that way.


https://reviews.llvm.org/D33514



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


r312801 - Use EmitPointerWithAlignment to get alignment information of the pointer used in atomic expr.

2017-09-08 Thread Wei Mi via cfe-commits
Author: wmi
Date: Fri Sep  8 10:07:32 2017
New Revision: 312801

URL: http://llvm.org/viewvc/llvm-project?rev=312801&view=rev
Log:
Use EmitPointerWithAlignment to get alignment information of the pointer used 
in atomic expr.

This is to fix PR34347. EmitAtomicExpr now only uses alignment information from
Type, instead of Decl, so when the declaration of an atomic variable is marked
to have the alignment equal as its size, EmitAtomicExpr doesn't know about it 
and
will generate libcall instead of atomic op. The patch uses 
EmitPointerWithAlignment
to get the precise alignment information.

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

Added:
cfe/trunk/test/CodeGenCXX/atomic-align.cpp
Modified:
cfe/trunk/lib/CodeGen/CGAtomic.cpp

Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=312801&r1=312800&r2=312801&view=diff
==
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp Fri Sep  8 10:07:32 2017
@@ -745,19 +745,19 @@ RValue CodeGenFunction::EmitAtomicExpr(A
   QualType MemTy = AtomicTy;
   if (const AtomicType *AT = AtomicTy->getAs())
 MemTy = AT->getValueType();
-  CharUnits sizeChars, alignChars;
-  std::tie(sizeChars, alignChars) = getContext().getTypeInfoInChars(AtomicTy);
-  uint64_t Size = sizeChars.getQuantity();
-  unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth();
-  bool UseLibcall = (sizeChars != alignChars ||
- getContext().toBits(sizeChars) > MaxInlineWidthInBits);
-
   llvm::Value *IsWeak = nullptr, *OrderFail = nullptr;
 
   Address Val1 = Address::invalid();
   Address Val2 = Address::invalid();
   Address Dest = Address::invalid();
-  Address Ptr(EmitScalarExpr(E->getPtr()), alignChars);
+  Address Ptr = EmitPointerWithAlignment(E->getPtr());
+
+  CharUnits sizeChars, alignChars;
+  std::tie(sizeChars, alignChars) = getContext().getTypeInfoInChars(AtomicTy);
+  uint64_t Size = sizeChars.getQuantity();
+  unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth();
+  bool UseLibcall = (sizeChars != Ptr.getAlignment() ||
+ getContext().toBits(sizeChars) > MaxInlineWidthInBits);
 
   if (E->getOp() == AtomicExpr::AO__c11_atomic_init ||
   E->getOp() == AtomicExpr::AO__opencl_atomic_init) {

Added: cfe/trunk/test/CodeGenCXX/atomic-align.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/atomic-align.cpp?rev=312801&view=auto
==
--- cfe/trunk/test/CodeGenCXX/atomic-align.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/atomic-align.cpp Fri Sep  8 10:07:32 2017
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 %s -std=c++11 -emit-llvm -o - -triple=x86_64-linux-gnu | 
FileCheck %s
+
+struct AM {
+  int f1, f2;
+};
+alignas(8) AM m;
+AM load1() {
+  AM am;
+  // m is declared to align to 8bytes, so generate load atomic instead
+  // of libcall.
+  // CHECK-LABEL: @_Z5load1v
+  // CHECK: load atomic {{.*}} monotonic
+  __atomic_load(&m, &am, 0);
+  return am;
+}
+
+struct BM {
+  int f1;
+  alignas(8) AM f2;
+};
+BM bm;
+AM load2() {
+  AM am;
+  // BM::f2 is declared to align to 8bytes, so generate load atomic instead
+  // of libcall.
+  // CHECK-LABEL: @_Z5load2v
+  // CHECK: load atomic {{.*}} monotonic
+  __atomic_load(&bm.f2, &am, 0);
+  return am;
+}


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


[PATCH] D37310: [Atomic] Merge alignment information from Decl and from Type when emit atomic expression.

2017-09-08 Thread Wei Mi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL312801: Use EmitPointerWithAlignment to get alignment 
information of the pointer used… (authored by wmi).

Changed prior to commit:
  https://reviews.llvm.org/D37310?vs=114300&id=114384#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37310

Files:
  cfe/trunk/lib/CodeGen/CGAtomic.cpp
  cfe/trunk/test/CodeGenCXX/atomic-align.cpp


Index: cfe/trunk/lib/CodeGen/CGAtomic.cpp
===
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp
@@ -745,19 +745,19 @@
   QualType MemTy = AtomicTy;
   if (const AtomicType *AT = AtomicTy->getAs())
 MemTy = AT->getValueType();
-  CharUnits sizeChars, alignChars;
-  std::tie(sizeChars, alignChars) = getContext().getTypeInfoInChars(AtomicTy);
-  uint64_t Size = sizeChars.getQuantity();
-  unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth();
-  bool UseLibcall = (sizeChars != alignChars ||
- getContext().toBits(sizeChars) > MaxInlineWidthInBits);
-
   llvm::Value *IsWeak = nullptr, *OrderFail = nullptr;
 
   Address Val1 = Address::invalid();
   Address Val2 = Address::invalid();
   Address Dest = Address::invalid();
-  Address Ptr(EmitScalarExpr(E->getPtr()), alignChars);
+  Address Ptr = EmitPointerWithAlignment(E->getPtr());
+
+  CharUnits sizeChars, alignChars;
+  std::tie(sizeChars, alignChars) = getContext().getTypeInfoInChars(AtomicTy);
+  uint64_t Size = sizeChars.getQuantity();
+  unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth();
+  bool UseLibcall = (sizeChars != Ptr.getAlignment() ||
+ getContext().toBits(sizeChars) > MaxInlineWidthInBits);
 
   if (E->getOp() == AtomicExpr::AO__c11_atomic_init ||
   E->getOp() == AtomicExpr::AO__opencl_atomic_init) {
Index: cfe/trunk/test/CodeGenCXX/atomic-align.cpp
===
--- cfe/trunk/test/CodeGenCXX/atomic-align.cpp
+++ cfe/trunk/test/CodeGenCXX/atomic-align.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 %s -std=c++11 -emit-llvm -o - -triple=x86_64-linux-gnu | 
FileCheck %s
+
+struct AM {
+  int f1, f2;
+};
+alignas(8) AM m;
+AM load1() {
+  AM am;
+  // m is declared to align to 8bytes, so generate load atomic instead
+  // of libcall.
+  // CHECK-LABEL: @_Z5load1v
+  // CHECK: load atomic {{.*}} monotonic
+  __atomic_load(&m, &am, 0);
+  return am;
+}
+
+struct BM {
+  int f1;
+  alignas(8) AM f2;
+};
+BM bm;
+AM load2() {
+  AM am;
+  // BM::f2 is declared to align to 8bytes, so generate load atomic instead
+  // of libcall.
+  // CHECK-LABEL: @_Z5load2v
+  // CHECK: load atomic {{.*}} monotonic
+  __atomic_load(&bm.f2, &am, 0);
+  return am;
+}


Index: cfe/trunk/lib/CodeGen/CGAtomic.cpp
===
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp
@@ -745,19 +745,19 @@
   QualType MemTy = AtomicTy;
   if (const AtomicType *AT = AtomicTy->getAs())
 MemTy = AT->getValueType();
-  CharUnits sizeChars, alignChars;
-  std::tie(sizeChars, alignChars) = getContext().getTypeInfoInChars(AtomicTy);
-  uint64_t Size = sizeChars.getQuantity();
-  unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth();
-  bool UseLibcall = (sizeChars != alignChars ||
- getContext().toBits(sizeChars) > MaxInlineWidthInBits);
-
   llvm::Value *IsWeak = nullptr, *OrderFail = nullptr;
 
   Address Val1 = Address::invalid();
   Address Val2 = Address::invalid();
   Address Dest = Address::invalid();
-  Address Ptr(EmitScalarExpr(E->getPtr()), alignChars);
+  Address Ptr = EmitPointerWithAlignment(E->getPtr());
+
+  CharUnits sizeChars, alignChars;
+  std::tie(sizeChars, alignChars) = getContext().getTypeInfoInChars(AtomicTy);
+  uint64_t Size = sizeChars.getQuantity();
+  unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth();
+  bool UseLibcall = (sizeChars != Ptr.getAlignment() ||
+ getContext().toBits(sizeChars) > MaxInlineWidthInBits);
 
   if (E->getOp() == AtomicExpr::AO__c11_atomic_init ||
   E->getOp() == AtomicExpr::AO__opencl_atomic_init) {
Index: cfe/trunk/test/CodeGenCXX/atomic-align.cpp
===
--- cfe/trunk/test/CodeGenCXX/atomic-align.cpp
+++ cfe/trunk/test/CodeGenCXX/atomic-align.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 %s -std=c++11 -emit-llvm -o - -triple=x86_64-linux-gnu | FileCheck %s
+
+struct AM {
+  int f1, f2;
+};
+alignas(8) AM m;
+AM load1() {
+  AM am;
+  // m is declared to align to 8bytes, so generate load atomic instead
+  // of libcall.
+  // CHECK-LABEL: @_Z5load1v
+  // CHECK: load atomic {{.*}} monotonic
+  __atomic_load(&m, &am, 0);
+  return am;
+}
+
+struct BM {
+  int f1;
+  alignas(8) AM f2;
+};
+BM bm;
+AM load2() {
+  AM am;
+  // BM::f2 is declared to align to 8bytes, so generate

[PATCH] D37604: Disable debuginfo-tests for non-native configurations

2017-09-08 Thread Paul Robinson via Phabricator via cfe-commits
probinson closed this revision.
probinson added a comment.

r312803.  Forgot to put the tag in the commit message


https://reviews.llvm.org/D37604



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


[PATCH] D37629: [Sema] Move some stuff into -Wtautological-unsigned-enum-zero-compare

2017-09-08 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 114387.
lebedev.ri added a subscriber: jroelofs.
lebedev.ri added a comment.

Rework as per @jroelofs's suggestion to have just one `switch`/`if` cascade 
that operates on `BinaryOperatorKind`


Repository:
  rL LLVM

https://reviews.llvm.org/D37629

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/Sema/compare.c
  test/Sema/tautological-unsigned-enum-zero-compare.c

Index: test/Sema/tautological-unsigned-enum-zero-compare.c
===
--- /dev/null
+++ test/Sema/tautological-unsigned-enum-zero-compare.c
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -fsyntax-only -DTEST -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-enum-zero-compare -verify %s
+
+int main() {
+  enum A { A_foo, A_bar };
+  enum A a;
+
+#ifdef TEST
+  if (a < 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
+return 0;
+  if (a >= 0) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
+return 0;
+  if (0 <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
+return 0;
+  if (0 > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
+return 0;
+  if (a < 0U) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
+return 0;
+  if (a >= 0U) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
+return 0;
+  if (0U <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
+return 0;
+  if (0U > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
+return 0;
+#else
+  // expected-no-diagnostics
+  if (a < 0)
+return 0;
+  if (a >= 0)
+return 0;
+  if (0 <= a)
+return 0;
+  if (0 > a)
+return 0;
+  if (a < 0U)
+return 0;
+  if (a >= 0U)
+return 0;
+  if (0U <= a)
+return 0;
+  if (0U > a)
+return 0;
+#endif
+
+  return 1;
+}
Index: test/Sema/compare.c
===
--- test/Sema/compare.c
+++ test/Sema/compare.c
@@ -308,8 +308,59 @@
 int rdar8511238() {
   enum A { A_foo, A_bar };
   enum A a;
+
+  if (a == 0)
+  return 0;
+  if (a != 0)
+  return 0;
   if (a < 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
-return 0;
+  return 0;
+  if (a <= 0)
+  return 0;
+  if (a > 0)
+  return 0;
+  if (a >= 0) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
+  return 0;
+
+  if (0 == a)
+  return 0;
+  if (0 != a)
+  return 0;
+  if (0 < a)
+  return 0;
+  if (0 <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
+  return 0;
+  if (0 > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
+  return 0;
+  if (0 >= a)
+  return 0;
+
+  if (a == 0U)
+  return 0;
+  if (a != 0U)
+  return 0;
+  if (a < 0U) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
+  return 0;
+  if (a <= 0U)
+  return 0;
+  if (a > 0U)
+  return 0;
+  if (a >= 0U) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
+  return 0;
+
+  if (0U == a)
+  return 0;
+  if (0U != a)
+  return 0;
+  if (0U < a)
+  return 0;
+  if (0U <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
+  return 0;
+  if (0U > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
+  return 0;
+  if (0U >= a)
+  return 0;
+
   return 20;
 }
 
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -8590,28 +8590,73 @@
   Expr *LHS = E->getLHS();
   Expr *RHS = E->getRHS();
 
-  bool Match = true;
+  enum IsEnum { False, True, SizeOfIsEnum };
+  struct TautologicalComparison {
+unsigned DiagID[SizeOfIsEnum];
+Expr *&Value;
+Expr *&Const;
+const char *cmp;
+bool Result;
+  };
 
-  if (op == BO_LT && isNonBooleanUnsignedValue(LHS) && IsZero(S, RHS)) {
-S.Diag(E->getOperatorLoc(), diag::warn_lunsigned_always_true_comparison)
-  << "< 0" << "false" << HasEnumType(LHS)
-  << LHS->getSourceRange() << RHS->getSourceRange();
-  } else if (op == BO_GE && isNonBooleanUnsignedValue(LHS) && IsZero(S, RHS)) {
-S.Diag(E->getOperatorLoc(), diag::warn_lunsigned_always_true_comparison)
-  << ">= 0" << "true" << HasEnumType(LHS)
-  << LHS->getSourceRange() << RHS->getSourceRange();
-  } else if (op == BO_GT && isNonBooleanUnsignedValue(RHS) && IsZero(S, LHS)) {
-S.Diag(E->getOperatorLoc(), diag::warn_runsigned_always_true_comparison)
-  << "0 >" << 

[PATCH] D37196: [Clang] Bug 32352 - Provide a way for OptimizationRemarkEmitter::allowExtraAnalysis to check if (specific) remarks are enabled

2017-09-08 Thread Adam Nemet via Phabricator via cfe-commits
anemet added a comment.

Please clean this up as well (don't have commented-out lines) so that it's 
ready to go with the LLVM patch.




Comment at: lib/CodeGen/CodeGenAction.cpp:302-305
 static void DiagnosticHandler(const llvm::DiagnosticInfo &DI,
   void *Context) {
   ((BackendConsumer *)Context)->DiagnosticHandlerImpl(DI);
 }

Remove this.



Comment at: lib/CodeGen/CodeGenAction.cpp:761
+public:
+  ClangDiagnosticHandler(const CodeGenOptions &CGOpts, void *DiagContext)
+  : DiagnosticHandler(DiagContext), CodeGenOpts(CGOpts) {}

Again don't overload DiagContext as such.  Have a dedicated field for the 
BackendConsumer.



Comment at: lib/CodeGen/CodeGenAction.cpp:882-883
   BEConsumer = Result.get();
-
+  VMContext->setDiagnosticHandler(llvm::make_unique(
+  CI.getCodeGenOpts(), Result.get()));
   // Enable generating macro debug info only when debug info is not disabled 
and

Any reason you moved where we set this up?


https://reviews.llvm.org/D37196



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


[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.

2017-09-08 Thread kchoi via Phabricator via cfe-commits
choikwa updated this revision to Diff 114388.
choikwa added a comment.

renamed and moved Cache to SourceLocToFileNameMap in CodeGenModule


https://reviews.llvm.org/D37624

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/instrument-functions.c

Index: test/CodeGen/instrument-functions.c
===
--- test/CodeGen/instrument-functions.c
+++ test/CodeGen/instrument-functions.c
@@ -1,18 +1,66 @@
-// RUN: %clang_cc1 -S -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-functions | FileCheck %s
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions | FileCheck %s
+// RUN: %clang -S -emit-llvm -o - %s -fno-instrument-functions | FileCheck %s --check-prefix=NOINSTR
+
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-file-list=instrument | FileCheck %s --check-prefix=NOFILE
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=NOFUNC
 
 // CHECK: @test1
+// NOINSTR: @test1
+// NOFILE: @test1
+// NOFUNC: @test1
 int test1(int x) {
-// CHECK: call void @__cyg_profile_func_enter({{.*}}, !dbg
-// CHECK: call void @__cyg_profile_func_exit({{.*}}, !dbg
+// CHECK: __cyg_profile_func_enter
+// CHECK: __cyg_profile_func_exit
 // CHECK: ret
+// NOINSTR-NOT: __cyg_profile_func_enter
+// NOINSTR-NOT: __cyg_profile_func_exit
+// NOINSTR: ret
+// NOFILE-NOT: __cyg_profile_func_enter
+// NOFILE-NOT: __cyg_profile_func_exit
+// NOFILE: ret
+// NOFUNC: __cyg_profile_func_enter
+// NOFUNC: __cyg_profile_func_exit
+// NOFUNC: ret
   return x;
 }
 
 // CHECK: @test2
+// NOINSTR: @test2
+// NOFILE: @test2
+// NOFUNC: @test2
 int test2(int) __attribute__((no_instrument_function));
 int test2(int x) {
 // CHECK-NOT: __cyg_profile_func_enter
 // CHECK-NOT: __cyg_profile_func_exit
 // CHECK: ret
+// NOINSTR-NOT: __cyg_profile_func_enter
+// NOINSTR-NOT: __cyg_profile_func_exit
+// NOINSTR: ret
+// NOFILE-NOT: __cyg_profile_func_enter
+// NOFILE-NOT: __cyg_profile_func_exit
+// NOFILE: ret
+// NOFUNC-NOT: __cyg_profile_func_enter
+// NOFUNC-NOT: __cyg_profile_func_exit
+// NOFUNC: ret
+  return x;
+}
+
+// CHECK: @test3
+// NOINSTR: @test3
+// NOFILE: @test3
+// NOFUNC: @test3
+int test3(int x) {
+// CHECK: __cyg_profile_func_enter
+// CHECK: __cyg_profile_func_exit
+// CHECK: ret
+// NOINSTR-NOT: __cyg_profile_func_enter
+// NOINSTR-NOT: __cyg_profile_func_exit
+// NOINSTR: ret
+// NOFILE-NOT: __cyg_profile_func_enter
+// NOFILE-NOT: __cyg_profile_func_exit
+// NOFILE: ret
+// NOFUNC-NOT: __cyg_profile_func_enter
+// NOFUNC-NOT: __cyg_profile_func_exit
+// NOFUNC: ret
   return x;
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -771,6 +771,12 @@
 
   Opts.PreserveVec3Type = Args.hasArg(OPT_fpreserve_vec3_type);
   Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions);
+  if (Opts.InstrumentFunctions) {
+Opts.InstrumentFunctionExclusionsFunctions
+= Args.getAllArgValues(OPT_finstrument_functions_exclude_function_list);
+Opts.InstrumentFunctionExclusionsPathSegments
+= Args.getAllArgValues(OPT_finstrument_functions_exclude_file_list);
+  }
   Opts.XRayInstrumentFunctions = Args.hasArg(OPT_fxray_instrument);
   Opts.XRayInstructionThreshold =
   getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3519,7 +3519,14 @@
 options::OPT_fno_unique_section_names, true))
 CmdArgs.push_back("-fno-unique-section-names");
 
-  Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions);
+  if (Args.hasArg(options::OPT_finstrument_functions,
+  options::OPT_fno_instrument_functions, false)) {
+Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions);
+Args.AddAllArgs(CmdArgs,
+options::OPT_finstrument_functions_exclude_file_list);
+Args.AddAllArgs(CmdArgs,
+options::OPT_finstrument_functions_exclude_function_list);
+  }
 
   addPGOAndCoverageFlags(C, D, Output, Args, CmdArgs);
 
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -499,6 +499,9 @@
   /// MDNodes.
   llvm::DenseMap MetadataIdMap;
 
+  /// Mapping from SourceLocation to PresumedLoc FileName
+  llvm::DenseMap Sour

[PATCH] D37474: [PCH] Allow VFS to be used for tests that generate PCH files

2017-09-08 Thread Cameron via Phabricator via cfe-commits
cameron314 added inline comments.



Comment at: lib/Frontend/ASTUnit.cpp:1014
+/// with another virtual file system.
+class PCHOverlayFileSystem : public vfs::FileSystem
+{

ilya-biryukov wrote:
> Maybe create a combination of `InMemoryFileSystem` and `OverlayFileSystem` 
> instead of custom filtering implementation?
> We really need to read only a single file given that `ASTUnit` never creates 
> directory PCHs.
> I bet it would make the code simpler and less error-prone.
I hadn't thought of that. Yes, that makes sense and is more concise.



Comment at: lib/Frontend/ASTUnit.cpp:1090
+  IntrusiveRefCntPtr RealFS = vfs::getRealFileSystem();
+  if (OverrideMainBuffer && VFS && RealFS && VFS != RealFS) {
+// We have a slight inconsistency here -- we're using the VFS to

ilya-biryukov wrote:
> Maybe create a PCH overlay only when `!VFS->exists(/*PreamblePath...*/)`?
> This seems like a good enough indication that `RealFS` is underneath the 
> `vfs::FileSystem` instance, even if pointer equality does not hold (i.e. in 
> case of overlays over `RealFS`).
Makes sense.



Comment at: unittests/Frontend/CMakeLists.txt:9
   CodeGenActionTest.cpp
+  PchPreambleTest.cpp
   )

ilya-biryukov wrote:
> Maybe rename to `PCHPreambleTest`?
> LLVM code generally capitalizes all letters in abbreviations.
Oops, overlooked this one. Will do!


https://reviews.llvm.org/D37474



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


[PATCH] D37572: [clang-tidy] SuspiciousEnumUsageCheck bugfix

2017-09-08 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: test/clang-tidy/misc-suspicious-enum-usage.cpp:122
+struct a> {
+  enum { ah = ad::m,
+ ai = ae::m,

aaron.ballman wrote:
> alexfh wrote:
> > aaron.ballman wrote:
> > > This seems like a lot of complicated code for the test case -- can this 
> > > be reduced further?
> > This is the best creduce could do. It should be possible to make this much 
> > shorter, but I wouldn't spend too much time on that.
> I'd appreciate the time spent because this is an almost-unintelligible test 
> for anyone reading it -- it's hard to understand what's going on there.
namespace PR34400 {
  enum { E1 = 0 };
  enum { E2 = -1 };

  enum { l = E1 | E2 };
}



https://reviews.llvm.org/D37572



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


[PATCH] D37629: [Sema] Move some stuff into -Wtautological-unsigned-enum-zero-compare

2017-09-08 Thread Jonathan Roelofs via Phabricator via cfe-commits
jroelofs added a comment.

I'm not sure it's better than writing the if/elseif/elseif/elseif out 
explicitly :/


Repository:
  rL LLVM

https://reviews.llvm.org/D37629



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


[PATCH] D37572: [clang-tidy] SuspiciousEnumUsageCheck bugfix

2017-09-08 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: test/clang-tidy/misc-suspicious-enum-usage.cpp:122
+struct a> {
+  enum { ah = ad::m,
+ ai = ae::m,

alexfh wrote:
> aaron.ballman wrote:
> > alexfh wrote:
> > > aaron.ballman wrote:
> > > > This seems like a lot of complicated code for the test case -- can this 
> > > > be reduced further?
> > > This is the best creduce could do. It should be possible to make this 
> > > much shorter, but I wouldn't spend too much time on that.
> > I'd appreciate the time spent because this is an almost-unintelligible test 
> > for anyone reading it -- it's hard to understand what's going on there.
> namespace PR34400 {
>   enum { E1 = 0 };
>   enum { E2 = -1 };
> 
>   enum { l = E1 | E2 };
> }
> 
This might not cover both code paths affected by the bug. But it should be easy 
to construct a case for the second one.


https://reviews.llvm.org/D37572



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


[PATCH] D37604: Disable debuginfo-tests for non-native configurations

2017-09-08 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

In https://reviews.llvm.org/D37604#864187, @aprantl wrote:

> This seems reasonable to me, thanks!
>  When you commit this, could you please double-check that the tests are still 
> running on the green dragon builders? I'll also keep an eye on them.


I was able to google "llvm green dragon" and find what looks like the right 
page, but I kind of would have expected to see a link on the llvm.org front 
page?  Am I just not looking in the right place?


https://reviews.llvm.org/D37604



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


[PATCH] D37629: [Sema] Move some stuff into -Wtautological-unsigned-enum-zero-compare

2017-09-08 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 114396.
lebedev.ri added a comment.

And finish reducing the code by for-range-loop`ing over array + use 
`std::array`.


Repository:
  rL LLVM

https://reviews.llvm.org/D37629

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/Sema/compare.c
  test/Sema/tautological-unsigned-enum-zero-compare.c

Index: test/Sema/tautological-unsigned-enum-zero-compare.c
===
--- /dev/null
+++ test/Sema/tautological-unsigned-enum-zero-compare.c
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -fsyntax-only -DTEST -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-enum-zero-compare -verify %s
+
+int main() {
+  enum A { A_foo, A_bar };
+  enum A a;
+
+#ifdef TEST
+  if (a < 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
+return 0;
+  if (a >= 0) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
+return 0;
+  if (0 <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
+return 0;
+  if (0 > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
+return 0;
+  if (a < 0U) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
+return 0;
+  if (a >= 0U) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
+return 0;
+  if (0U <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
+return 0;
+  if (0U > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
+return 0;
+#else
+  // expected-no-diagnostics
+  if (a < 0)
+return 0;
+  if (a >= 0)
+return 0;
+  if (0 <= a)
+return 0;
+  if (0 > a)
+return 0;
+  if (a < 0U)
+return 0;
+  if (a >= 0U)
+return 0;
+  if (0U <= a)
+return 0;
+  if (0U > a)
+return 0;
+#endif
+
+  return 1;
+}
Index: test/Sema/compare.c
===
--- test/Sema/compare.c
+++ test/Sema/compare.c
@@ -308,8 +308,59 @@
 int rdar8511238() {
   enum A { A_foo, A_bar };
   enum A a;
+
+  if (a == 0)
+  return 0;
+  if (a != 0)
+  return 0;
   if (a < 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
-return 0;
+  return 0;
+  if (a <= 0)
+  return 0;
+  if (a > 0)
+  return 0;
+  if (a >= 0) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
+  return 0;
+
+  if (0 == a)
+  return 0;
+  if (0 != a)
+  return 0;
+  if (0 < a)
+  return 0;
+  if (0 <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
+  return 0;
+  if (0 > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
+  return 0;
+  if (0 >= a)
+  return 0;
+
+  if (a == 0U)
+  return 0;
+  if (a != 0U)
+  return 0;
+  if (a < 0U) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
+  return 0;
+  if (a <= 0U)
+  return 0;
+  if (a > 0U)
+  return 0;
+  if (a >= 0U) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
+  return 0;
+
+  if (0U == a)
+  return 0;
+  if (0U != a)
+  return 0;
+  if (0U < a)
+  return 0;
+  if (0U <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
+  return 0;
+  if (0U > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
+  return 0;
+  if (0U >= a)
+  return 0;
+
   return 20;
 }
 
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -8583,35 +8583,69 @@
 
   // bool values are handled by DiagnoseOutOfRangeComparison().
 
-  BinaryOperatorKind op = E->getOpcode();
   if (E->isValueDependent())
 return false;
 
   Expr *LHS = E->getLHS();
   Expr *RHS = E->getRHS();
 
-  bool Match = true;
+  enum IsEnum { False = false, True = true, SizeOfIsEnum };
+  struct TautologicalComparison {
+Expr *&Value;
+BinaryOperatorKind op;
+Expr *&Const;
+std::array DiagID;
+const char *cmp;
+bool Result;
+  };
 
-  if (op == BO_LT && isNonBooleanUnsignedValue(LHS) && IsZero(S, RHS)) {
-S.Diag(E->getOperatorLoc(), diag::warn_lunsigned_always_true_comparison)
-  << "< 0" << "false" << HasEnumType(LHS)
-  << LHS->getSourceRange() << RHS->getSourceRange();
-  } else if (op == BO_GE && isNonBooleanUnsignedValue(LHS) && IsZero(S, RHS)) {
-S.Diag(E->getOperatorLoc(), diag::warn_lunsigned_always_true_comparison)
-  << ">= 0" << "true" << HasEnumType(LHS)
-  << LHS->getSourceRange() << RHS->getSourceRange();
-  } else if (op == BO_GT && isNonBooleanUnsignedValue(RH

  1   2   >