[PATCH] D52967: Extend shelf-life by 70 years

2018-10-06 Thread Bernhard M. Wiedemann via Phabricator via cfe-commits
bmwiedemann created this revision.
bmwiedemann added a reviewer: RKSimon.
Herald added a subscriber: cfe-commits.

Without this patch, tests would fail after 2030.

Note: requires timestamps with more than 31 bits


Repository:
  rC Clang

https://reviews.llvm.org/D52967

Files:
  test/Modules/fmodules-validate-once-per-build-session.c


Index: test/Modules/fmodules-validate-once-per-build-session.c
===
--- test/Modules/fmodules-validate-once-per-build-session.c
+++ test/Modules/fmodules-validate-once-per-build-session.c
@@ -51,8 +51,8 @@
 // RUN: not diff %t/modules-to-compare/Foo-before-user.pcm 
%t/modules-to-compare/Foo-after-user.pcm
 
 // ===
-// Recompile the module if the today's date is before 01 January 2030.
-// RUN: %clang_cc1 -cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash 
-fmodules-cache-path=%t/modules-cache -fsyntax-only -isystem %t/Inputs 
-fbuild-session-timestamp=1893456000 -fmodules-validate-once-per-build-session 
%s
+// Recompile the module if the today's date is before 01 January 2100.
+// RUN: %clang_cc1 -cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash 
-fmodules-cache-path=%t/modules-cache -fsyntax-only -isystem %t/Inputs 
-fbuild-session-timestamp=4102441200 -fmodules-validate-once-per-build-session 
%s
 // RUN: ls -R %t/modules-cache | grep Foo.pcm.timestamp
 // RUN: cp %t/modules-cache/Foo.pcm %t/modules-to-compare/Foo-after.pcm
 


Index: test/Modules/fmodules-validate-once-per-build-session.c
===
--- test/Modules/fmodules-validate-once-per-build-session.c
+++ test/Modules/fmodules-validate-once-per-build-session.c
@@ -51,8 +51,8 @@
 // RUN: not diff %t/modules-to-compare/Foo-before-user.pcm %t/modules-to-compare/Foo-after-user.pcm
 
 // ===
-// Recompile the module if the today's date is before 01 January 2030.
-// RUN: %clang_cc1 -cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash -fmodules-cache-path=%t/modules-cache -fsyntax-only -isystem %t/Inputs -fbuild-session-timestamp=1893456000 -fmodules-validate-once-per-build-session %s
+// Recompile the module if the today's date is before 01 January 2100.
+// RUN: %clang_cc1 -cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash -fmodules-cache-path=%t/modules-cache -fsyntax-only -isystem %t/Inputs -fbuild-session-timestamp=4102441200 -fmodules-validate-once-per-build-session %s
 // RUN: ls -R %t/modules-cache | grep Foo.pcm.timestamp
 // RUN: cp %t/modules-cache/Foo.pcm %t/modules-to-compare/Foo-after.pcm
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46441: [clang][CodeGenCXX] Noalias attr for copy/move constructor arguments

2018-10-06 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev marked an inline comment as done.
AntonBikineev added a comment.

I've submitted an issue to the Core about the case. Presumably, it will be 
included in the next revision (mailing deadline of which is tomorrow).




Comment at: lib/CodeGen/CGCall.cpp:1893
+
+IsCtor = isa(TargetDecl);
   }

rjmccall wrote:
> I feel like you should just use `TargetDecl && 
> isa(TargetDecl)` below; it's more obvious.
> 
> Is there not an analogous rule for destructors?
There appears to be no similar rule for destructors, maybe because at the point 
of calling a destructor the value of the object/subobjects is well-determined.


Repository:
  rC Clang

https://reviews.llvm.org/D46441



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


[PATCH] D52219: [analyzer] (1/n) Support pointee mutation analysis in ExprMutationAnalyzer.

2018-10-06 Thread Shuai Wang via Phabricator via cfe-commits
shuaiwang updated this revision to Diff 168578.
shuaiwang marked 5 inline comments as done.
shuaiwang added a comment.

Resolved review comments.


Repository:
  rC Clang

https://reviews.llvm.org/D52219

Files:
  include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
  lib/Analysis/ExprMutationAnalyzer.cpp
  unittests/Analysis/ExprMutationAnalyzerTest.cpp

Index: unittests/Analysis/ExprMutationAnalyzerTest.cpp
===
--- unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -50,13 +50,23 @@
 }
 
 bool isMutated(const SmallVectorImpl , ASTUnit *AST) {
-  const auto *const S = selectFirst("stmt", Results);
-  const auto *const E = selectFirst("expr", Results);
+  const auto *S = selectFirst("stmt", Results);
+  const auto *E = selectFirst("expr", Results);
+  assert(S && E);
   return ExprMutationAnalyzer(*S, AST->getASTContext()).isMutated(E);
 }
 
+bool isPointeeMutated(const SmallVectorImpl ,
+  ASTUnit *AST) {
+  const auto *S = selectFirst("stmt", Results);
+  const auto *E = selectFirst("expr", Results);
+  assert(S && E);
+  return ExprMutationAnalyzer(*S, AST->getASTContext()).isPointeeMutated(E);
+}
+
 SmallVector
 mutatedBy(const SmallVectorImpl , ASTUnit *AST) {
+  EXPECT_TRUE(isMutated(Results, AST));
   const auto *const S = selectFirst("stmt", Results);
   SmallVector Chain;
   ExprMutationAnalyzer Analyzer(*S, AST->getASTContext());
@@ -71,6 +81,19 @@
   return Chain;
 }
 
+std::string pointeeMutatedBy(const SmallVectorImpl ,
+ ASTUnit *AST) {
+  EXPECT_TRUE(isPointeeMutated(Results, AST));
+  const auto *S = selectFirst("stmt", Results);
+  const auto *E = selectFirst("expr", Results);
+  ExprMutationAnalyzer Analyzer(*S, AST->getASTContext());
+  std::string buffer;
+  llvm::raw_string_ostream stream(buffer);
+  const Stmt *By = Analyzer.findPointeeMutation(E);
+  By->printPretty(stream, nullptr, AST->getASTContext().getPrintingPolicy());
+  return StringRef(stream.str()).trim().str();
+}
+
 std::string removeSpace(std::string s) {
   s.erase(std::remove_if(s.begin(), s.end(),
  [](char c) { return std::isspace(c); }),
@@ -100,10 +123,14 @@
 } // namespace
 
 TEST(ExprMutationAnalyzerTest, Trivial) {
-  const auto AST = buildASTFromCode("void f() { int x; x; }");
-  const auto Results =
+  auto AST = buildASTFromCode("void f() { int x; x; }");
+  auto Results =
   match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
   EXPECT_FALSE(isMutated(Results, AST.get()));
+
+  AST = buildASTFromCode("void f() { const int x = 0; x; }");
+  Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_FALSE(isMutated(Results, AST.get()));
 }
 
 class AssignmentTest : public ::testing::TestWithParam {};
@@ -134,41 +161,111 @@
 Values("++x", "--x", "x++", "x--"), );
 
 TEST(ExprMutationAnalyzerTest, NonConstMemberFunc) {
-  const auto AST = buildASTFromCode(
+  auto AST = buildASTFromCode(
   "void f() { struct Foo { void mf(); }; Foo x; x.mf(); }");
-  const auto Results =
+  auto Results =
   match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
   EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x.mf()"));
+  EXPECT_FALSE(isPointeeMutated(Results, AST.get()));
+
+  AST = buildASTFromCode(
+  "void f() { struct Foo { void mf(); }; Foo *p; p->mf(); }");
+  Results = match(withEnclosingCompound(declRefTo("p")), AST->getASTContext());
+  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_EQ(pointeeMutatedBy(Results, AST.get()), "p->mf()");
+
+  AST = buildASTFromCode(
+  "void f() { struct Foo { void mf(); }; Foo *x; Foo * = x; p->mf(); }");
+  Results = match(withEnclosingCompound(declRefTo("p")), AST->getASTContext());
+  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_EQ(pointeeMutatedBy(Results, AST.get()), "p->mf()");
 }
 
 TEST(ExprMutationAnalyzerTest, AssumedNonConstMemberFunc) {
   auto AST = buildASTFromCodeWithArgs(
   "struct X { template  void mf(); };"
-  "template  void f() { X x; x.mf(); }",
+  "template  void f() { X x; x.mf(); }"
+  "template  void g() { X *p; p->mf(); }",
   {"-fno-delayed-template-parsing"});
   auto Results =
   match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
   EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x.mf()"));
+  Results = match(withEnclosingCompound(declRefTo("p")), AST->getASTContext());
+  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_EQ(pointeeMutatedBy(Results, AST.get()), "p->mf()");
 
-  AST = buildASTFromCodeWithArgs("template  void f() { T x; x.mf(); }",
- {"-fno-delayed-template-parsing"});
+  AST =
+  buildASTFromCodeWithArgs("template  void f() { T x; x.mf(); }"
+   "template  void g() { T *p; p->mf(); }",
+  

[PATCH] D51809: [CUDA][HIP] Fix ShouldDeleteSpecialMember for inherited constructors

2018-10-06 Thread Justin Lebar via Phabricator via cfe-commits
jlebar accepted this revision.
jlebar added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Sema/SemaDeclCXX.cpp:7231
+if (ICI)
+  CSM = getSpecialMember(MD);
+

LGTM, but perhaps we should use a new variable instead of modifying `CSM` in 
case someone adds code beneath this branch?


https://reviews.llvm.org/D51809



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


[PATCH] D52527: [clang-format] fix Bug 38686: add AfterCaseLabel to BraceWrapping

2018-10-06 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In https://reviews.llvm.org/D52527#1257277, @owenpan wrote:

> I'd greatly appreciate it if someone could review this before I commit it 
> next week.


Please do not commit without review. It is ok, to write `ping` every 5-7 days 
if there is no comment from the reviewers.


Repository:
  rC Clang

https://reviews.llvm.org/D52527



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


Re: [PATCH] D52527: [clang-format] fix Bug 38686: add AfterCaseLabel to BraceWrapping

2018-10-06 Thread Roman Lebedev via cfe-commits
On Sat, Oct 6, 2018 at 10:06 PM Owen Pan via Phabricator via
cfe-commits  wrote:
>
> owenpan added a comment.
>
> I'd greatly appreciate it if someone could review this before I commit it 
> next week.
That is not how LLVM reviews work.
Commit-without-review mostly is only for NFC changes in the code you know/own.

> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D52527
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52527: [clang-format] fix Bug 38686: add AfterCaseLabel to BraceWrapping

2018-10-06 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

I'd greatly appreciate it if someone could review this before I commit it next 
week.


Repository:
  rC Clang

https://reviews.llvm.org/D52527



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


[PATCH] D52412: OpenCL: Mark printf format string argument

2018-10-06 Thread James Price via Phabricator via cfe-commits
jprice added a comment.

This change has caused Clang to start emitting erroneous warnings when using 
OpenCL's vector specifier, e.g. "%v4f", which doesn't seem to be covered by the 
format string analysis.


https://reviews.llvm.org/D52412



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


[PATCH] D52750: [Diagnostics] Check for integer overflow in array size expressions

2018-10-06 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: lib/Sema/SemaType.cpp:2232
+
+  if (isa(ArraySize))
+ArraySize->EvaluateForOverflow(Context);

xbolva00 wrote:
> Rakete wrote:
> > What's up with this statement? Why is it needed? This won't handle 
> > overflows for unary expression for example.
> Ok, I should use Sema::CheckForIntOverflow
> 
> But anyway, CheckForIntOverflow does not care about UnaryOperator either 
> currently :)
Anyway, the negative array size is handled a few lines above.


https://reviews.llvm.org/D52750



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


[PATCH] D52750: [Diagnostics] Check for integer overflow in array size expressions

2018-10-06 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 168575.
xbolva00 added a comment.

- Use Sema::CheckForIntOverflow


https://reviews.llvm.org/D52750

Files:
  lib/Sema/SemaType.cpp
  test/Sema/integer-overflow.c


Index: test/Sema/integer-overflow.c
===
--- test/Sema/integer-overflow.c
+++ test/Sema/integer-overflow.c
@@ -172,6 +172,9 @@
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
   (void)f2(0, f0(4608 * 1024 * 1024));
 }
+void check_integer_overflows_in_array_size() {
+  int arr[4608 * 1024 * 1024]; // expected-warning {{overflow in expression; 
result is 536870912 with type 'int'}}
+}
 
 struct s {
   unsigned x;
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2228,6 +2228,8 @@
 << ConstVal.toString(10) << ArraySize->getSourceRange();
 return QualType();
   }
+
+  CheckForIntOverflow(ArraySize);
 }
 
 T = Context.getConstantArrayType(T, ConstVal, ASM, Quals);


Index: test/Sema/integer-overflow.c
===
--- test/Sema/integer-overflow.c
+++ test/Sema/integer-overflow.c
@@ -172,6 +172,9 @@
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
   (void)f2(0, f0(4608 * 1024 * 1024));
 }
+void check_integer_overflows_in_array_size() {
+  int arr[4608 * 1024 * 1024]; // expected-warning {{overflow in expression; result is 536870912 with type 'int'}}
+}
 
 struct s {
   unsigned x;
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2228,6 +2228,8 @@
 << ConstVal.toString(10) << ArraySize->getSourceRange();
 return QualType();
   }
+
+  CheckForIntOverflow(ArraySize);
 }
 
 T = Context.getConstantArrayType(T, ConstVal, ASM, Quals);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52750: [Diagnostics] Check for integer overflow in array size expressions

2018-10-06 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: lib/Sema/SemaType.cpp:2232
+
+  if (isa(ArraySize))
+ArraySize->EvaluateForOverflow(Context);

Rakete wrote:
> What's up with this statement? Why is it needed? This won't handle overflows 
> for unary expression for example.
Ok, I should use Sema::CheckForIntOverflow

But anyway, CheckForIntOverflow does not care about UnaryOperator either 
currently :)


https://reviews.llvm.org/D52750



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


[PATCH] D52750: [Diagnostics] Check for integer overflow in array size expressions

2018-10-06 Thread Nicolas Lesser via Phabricator via cfe-commits
Rakete added inline comments.



Comment at: lib/Sema/SemaType.cpp:2232
+
+  if (isa(ArraySize))
+ArraySize->EvaluateForOverflow(Context);

What's up with this statement? Why is it needed? This won't handle overflows 
for unary expression for example.


https://reviews.llvm.org/D52750



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


[PATCH] D52791: [Diagnostics] Check for misleading pointer declarations

2018-10-06 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 abandoned this revision.
xbolva00 added a comment.

This shouldn't be implemented here, better choice is clang-tidy. Closing this 
revision.


https://reviews.llvm.org/D52791



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


[PATCH] D28462: clang-format: Add new style option AlignConsecutiveMacros

2018-10-06 Thread Robin Eklind via Phabricator via cfe-commits
mewmew added a comment.

Any update on this? There are quite a few people who got excited about this 
change and would like to start using it with clang-format.


Repository:
  rL LLVM

https://reviews.llvm.org/D28462



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


[clang-tools-extra] r343917 - Revert rL343916: Fix -Wmissing-braces warning. NFCI.

2018-10-06 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Sat Oct  6 04:59:31 2018
New Revision: 343917

URL: http://llvm.org/viewvc/llvm-project?rev=343917=rev
Log:
Revert rL343916: Fix -Wmissing-braces warning. NFCI.

Modified:

clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp?rev=343917=343916=343917=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp 
Sat Oct  6 04:59:31 2018
@@ -18,9 +18,9 @@ namespace tidy {
 namespace modernize {
 
 static const std::array DeprecatedTypes = {
-{"::std::ios_base::io_state"},  {"::std::ios_base::open_mode"},
-{"::std::ios_base::seek_dir"},  {"::std::ios_base::streamoff"},
-{"::std::ios_base::streampos"},
+"::std::ios_base::io_state",  "::std::ios_base::open_mode",
+"::std::ios_base::seek_dir",  "::std::ios_base::streamoff",
+"::std::ios_base::streampos",
 };
 
 static const llvm::StringMap ReplacementTypes = {


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


[PATCH] D52957: [analyzer] Teach CallEvent about C++17 aligned new.

2018-10-06 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h:929
+  // number of arguments is always the same as the number of parameters.
+  unsigned getNumImplicitArgs() const {
+return getOriginExpr()->passAlignment() ? 2 : 1;

Can you include doxygen comments too, or make these doxygen comments?


Repository:
  rC Clang

https://reviews.llvm.org/D52957



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


[clang-tools-extra] r343916 - Fix -Wmissing-braces warning. NFCI.

2018-10-06 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Sat Oct  6 04:46:27 2018
New Revision: 343916

URL: http://llvm.org/viewvc/llvm-project?rev=343916=rev
Log:
Fix -Wmissing-braces warning. NFCI.

Modified:

clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp?rev=343916=343915=343916=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp 
Sat Oct  6 04:46:27 2018
@@ -18,9 +18,9 @@ namespace tidy {
 namespace modernize {
 
 static const std::array DeprecatedTypes = {
-"::std::ios_base::io_state",  "::std::ios_base::open_mode",
-"::std::ios_base::seek_dir",  "::std::ios_base::streamoff",
-"::std::ios_base::streampos",
+{"::std::ios_base::io_state"},  {"::std::ios_base::open_mode"},
+{"::std::ios_base::seek_dir"},  {"::std::ios_base::streamoff"},
+{"::std::ios_base::streampos"},
 };
 
 static const llvm::StringMap ReplacementTypes = {


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


r343915 - Wdocumentation fix

2018-10-06 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Sat Oct  6 04:12:59 2018
New Revision: 343915

URL: http://llvm.org/viewvc/llvm-project?rev=343915=rev
Log:
Wdocumentation fix

Modified:
cfe/trunk/include/clang/Lex/CodeCompletionHandler.h

Modified: cfe/trunk/include/clang/Lex/CodeCompletionHandler.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/CodeCompletionHandler.h?rev=343915=343914=343915=diff
==
--- cfe/trunk/include/clang/Lex/CodeCompletionHandler.h (original)
+++ cfe/trunk/include/clang/Lex/CodeCompletionHandler.h Sat Oct  6 04:12:59 2018
@@ -64,7 +64,7 @@ public:
 
   /// Callback invoked when performing code completion inside the filename
   /// part of an #include directive. (Also #import, #include_next, etc).
-  /// \p Dir is the directory relative to the include path, e.g. "a" for 
"http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52949: [Diagnostics] Implement -Wsizeof-pointer-div

2018-10-06 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 168569.
xbolva00 added a comment.

- added DefaultIgnore


https://reviews.llvm.org/D52949

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExpr.cpp
  test/Sema/div-sizeof-ptr.c

Index: test/Sema/div-sizeof-ptr.c
===
--- test/Sema/div-sizeof-ptr.c
+++ test/Sema/div-sizeof-ptr.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -verify -Wsizeof-pointer-div -fsyntax-only
+
+void test(int *p, int **q) {
+int a = sizeof(p) / sizeof(*p);  // expected-warning {{division produces the incorrect number of array elements}}
+int b = sizeof p / sizeof *p;// expected-warning {{division produces the incorrect number of array elements}}
+int c = sizeof(*q) / sizeof(**q);// expected-warning {{division produces the incorrect number of array elements}}
+int d = sizeof(p) / sizeof(int); // expected-warning {{division produces the incorrect number of array elements}}
+
+int e = sizeof(int *) / sizeof(int);
+int f = sizeof(p) / sizeof(p);
+int g = sizeof(*q) / sizeof(q);
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -8677,6 +8677,39 @@
   << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
 }
 
+static void DiagnoseDivisionSizeofPointer(Sema , Expr *LHS, Expr *RHS,
+  SourceLocation Loc) {
+  UnaryExprOrTypeTraitExpr *LUE =
+  dyn_cast_or_null(LHS);
+  UnaryExprOrTypeTraitExpr *RUE =
+  dyn_cast_or_null(RHS);
+
+  if (!LUE || !RUE)
+return;
+  if (LUE->getKind() != UETT_SizeOf || LUE->isArgumentType() ||
+  RUE->getKind() != UETT_SizeOf)
+return;
+
+  QualType LHSTy;
+  QualType RHSTy;
+  LHS = LUE->getArgumentExpr()->IgnoreParens();
+  LHSTy = LHS->getType();
+
+  if (RUE->isArgumentType()) {
+RHSTy = RUE->getArgumentType();
+  } else {
+RHS = RUE->getArgumentExpr()->IgnoreParens();
+RHSTy = RHS->getType();
+  }
+
+  if (!LHSTy->isPointerType() || RHSTy->isPointerType())
+return;
+  if (LHSTy->getPointeeType() != RHSTy)
+return;
+
+  S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS->getSourceRange();
+}
+
 static void DiagnoseBadDivideOrRemainderValues(Sema& S, ExprResult ,
ExprResult ,
SourceLocation Loc, bool IsDiv) {
@@ -8707,8 +8740,10 @@
 
   if (compType.isNull() || !compType->isArithmeticType())
 return InvalidOperands(Loc, LHS, RHS);
-  if (IsDiv)
+  if (IsDiv) {
 DiagnoseBadDivideOrRemainderValues(*this, LHS, RHS, Loc, IsDiv);
+DiagnoseDivisionSizeofPointer(*this, LHS.get(), RHS.get(), Loc);
+  }
   return compType;
 }
 
@@ -16541,4 +16576,4 @@
 
   return new (Context)
   ObjCAvailabilityCheckExpr(Version, AtLoc, RParen, Context.BoolTy);
-}
+}
\ No newline at end of file
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -3293,6 +3293,10 @@
   InGroup;
 def note_reference_is_return_value : Note<"%0 returns a reference">;
 
+def warn_division_sizeof_ptr : Warning<
+  "division produces the incorrect number of array elements">,
+  InGroup, DefaultIgnore;
+
 def note_function_warning_silence : Note<
 "prefix with the address-of operator to silence this warning">;
 def note_function_to_function_call : Note<
Index: include/clang/Basic/DiagnosticGroups.td
===
--- include/clang/Basic/DiagnosticGroups.td
+++ include/clang/Basic/DiagnosticGroups.td
@@ -142,6 +142,7 @@
 def : DiagGroup<"discard-qual">;
 def DivZero : DiagGroup<"division-by-zero">;
 def : DiagGroup<"div-by-zero", [DivZero]>;
+def DivSizeofPtr : DiagGroup<"sizeof-pointer-div">;
 
 def DocumentationHTML : DiagGroup<"documentation-html">;
 def DocumentationUnknownCommand : DiagGroup<"documentation-unknown-command">;
@@ -785,6 +786,7 @@
 SelfMove,
 SizeofArrayArgument,
 SizeofArrayDecay,
+DivSizeofPtr,
 StringPlusInt,
 Trigraphs,
 Uninitialized,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52750: [Diagnostics] Check for integer overflow in array size expressions

2018-10-06 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

Ping :)


https://reviews.llvm.org/D52750



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


[PATCH] D52949: [Diagnostics] Implement -Wsizeof-pointer-div

2018-10-06 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 168564.

https://reviews.llvm.org/D52949

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExpr.cpp
  test/Sema/div-sizeof-ptr.c

Index: test/Sema/div-sizeof-ptr.c
===
--- test/Sema/div-sizeof-ptr.c
+++ test/Sema/div-sizeof-ptr.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -verify -Wsizeof-pointer-div -fsyntax-only
+
+void test(int *p, int **q) {
+int a = sizeof(p) / sizeof(*p);  // expected-warning {{division produces the incorrect number of array elements}}
+int b = sizeof p / sizeof *p;// expected-warning {{division produces the incorrect number of array elements}}
+int c = sizeof(*q) / sizeof(**q);// expected-warning {{division produces the incorrect number of array elements}}
+int d = sizeof(p) / sizeof(int); // expected-warning {{division produces the incorrect number of array elements}}
+
+int e = sizeof(int *) / sizeof(int);
+int f = sizeof(p) / sizeof(p);
+int g = sizeof(*q) / sizeof(q);
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -8677,6 +8677,39 @@
   << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
 }
 
+static void DiagnoseDivisionSizeofPointer(Sema , Expr *LHS, Expr *RHS,
+  SourceLocation Loc) {
+  UnaryExprOrTypeTraitExpr *LUE =
+  dyn_cast_or_null(LHS);
+  UnaryExprOrTypeTraitExpr *RUE =
+  dyn_cast_or_null(RHS);
+
+  if (!LUE || !RUE)
+return;
+  if (LUE->getKind() != UETT_SizeOf || LUE->isArgumentType() ||
+  RUE->getKind() != UETT_SizeOf)
+return;
+
+  QualType LHSTy;
+  QualType RHSTy;
+  LHS = LUE->getArgumentExpr()->IgnoreParens();
+  LHSTy = LHS->getType();
+
+  if (RUE->isArgumentType()) {
+RHSTy = RUE->getArgumentType();
+  } else {
+RHS = RUE->getArgumentExpr()->IgnoreParens();
+RHSTy = RHS->getType();
+  }
+
+  if (!LHSTy->isPointerType() || RHSTy->isPointerType())
+return;
+  if (LHSTy->getPointeeType() != RHSTy)
+return;
+
+  S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS->getSourceRange();
+}
+
 static void DiagnoseBadDivideOrRemainderValues(Sema& S, ExprResult ,
ExprResult ,
SourceLocation Loc, bool IsDiv) {
@@ -8707,8 +8740,10 @@
 
   if (compType.isNull() || !compType->isArithmeticType())
 return InvalidOperands(Loc, LHS, RHS);
-  if (IsDiv)
+  if (IsDiv) {
 DiagnoseBadDivideOrRemainderValues(*this, LHS, RHS, Loc, IsDiv);
+DiagnoseDivisionSizeofPointer(*this, LHS.get(), RHS.get(), Loc);
+  }
   return compType;
 }
 
@@ -16541,4 +16576,4 @@
 
   return new (Context)
   ObjCAvailabilityCheckExpr(Version, AtLoc, RParen, Context.BoolTy);
-}
+}
\ No newline at end of file
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -3293,6 +3293,10 @@
   InGroup;
 def note_reference_is_return_value : Note<"%0 returns a reference">;
 
+def warn_division_sizeof_ptr : Warning<
+  "division produces the incorrect number of array elements">,
+  InGroup;
+
 def note_function_warning_silence : Note<
 "prefix with the address-of operator to silence this warning">;
 def note_function_to_function_call : Note<
Index: include/clang/Basic/DiagnosticGroups.td
===
--- include/clang/Basic/DiagnosticGroups.td
+++ include/clang/Basic/DiagnosticGroups.td
@@ -142,6 +142,7 @@
 def : DiagGroup<"discard-qual">;
 def DivZero : DiagGroup<"division-by-zero">;
 def : DiagGroup<"div-by-zero", [DivZero]>;
+def DivSizeofPtr : DiagGroup<"sizeof-pointer-div">;
 
 def DocumentationHTML : DiagGroup<"documentation-html">;
 def DocumentationUnknownCommand : DiagGroup<"documentation-unknown-command">;
@@ -785,6 +786,7 @@
 SelfMove,
 SizeofArrayArgument,
 SizeofArrayDecay,
+DivSizeofPtr,
 StringPlusInt,
 Trigraphs,
 Uninitialized,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52949: [Diagnostics] Implement -Wsizeof-pointer-div

2018-10-06 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 168562.
xbolva00 added a comment.

- fixed formatting noise


https://reviews.llvm.org/D52949

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExpr.cpp
  test/Sema/div-sizeof-ptr.c

Index: test/Sema/div-sizeof-ptr.c
===
--- test/Sema/div-sizeof-ptr.c
+++ test/Sema/div-sizeof-ptr.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -verify -Wsizeof-pointer-div -fsyntax-only
+
+void test(int *p, int **q) {
+int a = sizeof(p) / sizeof(*p);  // expected-warning {{division produces the incorrect number of array elements}}
+int b = sizeof p / sizeof *p;// expected-warning {{division produces the incorrect number of array elements}}
+int c = sizeof(*q) / sizeof(**q);// expected-warning {{division produces the incorrect number of array elements}}
+int d = sizeof(p) / sizeof(int); // expected-warning {{division produces the incorrect number of array elements}}
+
+int e = sizeof(int *) / sizeof(int);
+int f = sizeof(p) / sizeof(p);
+int g = sizeof(*q) / sizeof(q);
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -5862,6 +5862,8 @@
   LangAS DestAS = DestTy->getPointeeType().getAddressSpace();
   if (SrcAS != DestAS)
 return CK_AddressSpaceConversion;
+  if (Context.hasCvrSimilarType(SrcTy, DestTy))
+return CK_NoOp;
   return CK_BitCast;
 }
 case Type::STK_BlockPointer:
@@ -7762,7 +7764,12 @@
 if (isa(RHSType)) {
   LangAS AddrSpaceL = LHSPointer->getPointeeType().getAddressSpace();
   LangAS AddrSpaceR = RHSType->getPointeeType().getAddressSpace();
-  Kind = AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast;
+  if (AddrSpaceL != AddrSpaceR)
+Kind = CK_AddressSpaceConversion;
+  else if (Context.hasCvrSimilarType(RHSType, LHSType))
+Kind = CK_NoOp;
+  else
+Kind = CK_BitCast;
   return checkPointerTypesForAssignment(*this, LHSType, RHSType);
 }
 
@@ -8670,6 +8677,39 @@
   << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
 }
 
+static void DiagnoseDivisionSizeofPointer(Sema , Expr *LHS, Expr *RHS,
+  SourceLocation Loc) {
+  UnaryExprOrTypeTraitExpr *LUE =
+  dyn_cast_or_null(LHS);
+  UnaryExprOrTypeTraitExpr *RUE =
+  dyn_cast_or_null(RHS);
+
+  if (!LUE || !RUE)
+return;
+  if (LUE->getKind() != UETT_SizeOf || LUE->isArgumentType() ||
+  RUE->getKind() != UETT_SizeOf)
+return;
+
+  QualType LHSTy;
+  QualType RHSTy;
+  LHS = LUE->getArgumentExpr()->IgnoreParens();
+  LHSTy = LHS->getType();
+
+  if (RUE->isArgumentType()) {
+RHSTy = RUE->getArgumentType();
+  } else {
+RHS = RUE->getArgumentExpr()->IgnoreParens();
+RHSTy = RHS->getType();
+  }
+
+  if (!LHSTy->isPointerType() || RHSTy->isPointerType())
+return;
+  if (LHSTy->getPointeeType() != RHSTy)
+return;
+
+  S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS->getSourceRange();
+}
+
 static void DiagnoseBadDivideOrRemainderValues(Sema& S, ExprResult ,
ExprResult ,
SourceLocation Loc, bool IsDiv) {
@@ -8700,8 +8740,10 @@
 
   if (compType.isNull() || !compType->isArithmeticType())
 return InvalidOperands(Loc, LHS, RHS);
-  if (IsDiv)
+  if (IsDiv) {
 DiagnoseBadDivideOrRemainderValues(*this, LHS, RHS, Loc, IsDiv);
+DiagnoseDivisionSizeofPointer(*this, LHS.get(), RHS.get(), Loc);
+  }
   return compType;
 }
 
@@ -13428,6 +13470,7 @@
   PopExpressionEvaluationContext();
 
   BlockScopeInfo *BSI = cast(FunctionScopes.back());
+  BlockDecl *BD = BSI->TheDecl;
 
   if (BSI->HasImplicitReturnType)
 deduceClosureReturnType(*BSI);
@@ -13438,7 +13481,7 @@
   if (!BSI->ReturnType.isNull())
 RetTy = BSI->ReturnType;
 
-  bool NoReturn = BSI->TheDecl->hasAttr();
+  bool NoReturn = BD->hasAttr();
   QualType BlockTy;
 
   // Set the captured variables on the block.
@@ -13451,7 +13494,7 @@
   Cap.isNested(), Cap.getInitExpr());
 Captures.push_back(NewCap);
   }
-  BSI->TheDecl->setCaptures(Context, Captures, BSI->CXXThisCaptureIndex != 0);
+  BD->setCaptures(Context, Captures, BSI->CXXThisCaptureIndex != 0);
 
   // If the user wrote a function type in some form, try to use that.
   if (!BSI->FunctionType.isNull()) {
@@ -13488,27 +13531,27 @@
 BlockTy = Context.getFunctionType(RetTy, None, EPI);
   }
 
-  DiagnoseUnusedParameters(BSI->TheDecl->parameters());
+  DiagnoseUnusedParameters(BD->parameters());
   BlockTy = Context.getBlockPointerType(BlockTy);
 
   // If needed, diagnose invalid gotos and switches in the block.
   if (getCurFunction()->NeedsScopeChecking() &&
   !PP.isCodeCompletionEnabled())

[PATCH] D52936: Add some automatic tests for DivideZero checker

2018-10-06 Thread Tamás Zolnai via Phabricator via cfe-commits
ztamas added a reviewer: dcoughlin.
ztamas added a comment.

Based on CODE_OWNERS.txt.


Repository:
  rC Clang

https://reviews.llvm.org/D52936



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


[clang-tools-extra] r343912 - [clangd] Remove unused headers from CodeComplete.cpp

2018-10-06 Thread Fangrui Song via cfe-commits
Author: maskray
Date: Sat Oct  6 00:00:50 2018
New Revision: 343912

URL: http://llvm.org/viewvc/llvm-project?rev=343912=rev
Log:
[clangd] Remove unused headers from CodeComplete.cpp

queue is not used after index-provided completions' merge with those from Sema
USRGeneration.h is not used after introduction of getSymbolID

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=343912=343911=343912=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Sat Oct  6 00:00:50 2018
@@ -40,11 +40,9 @@
 #include "clang/Format/Format.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendActions.h"
-#include "clang/Index/USRGeneration.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Sema/Sema.h"
-#include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
@@ -54,7 +52,6 @@
 #include "llvm/Support/ScopedPrinter.h"
 #include 
 #include 
-#include 
 
 // We log detailed candidate here if you run with -debug-only=codecomplete.
 #define DEBUG_TYPE "CodeComplete"


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