[PATCH] D33308: [analyzer]: Improve test handling with multiple constraint managers

2017-06-10 Thread Dominic Chen via Phabricator via cfe-commits
ddcc added a comment.

@dcoughlin @zaks.anna @NoQ @xazax.hun Ping, I'd appreciate it if I could get a 
review for this (https://reviews.llvm.org/D33308), 
https://reviews.llvm.org/D28955, https://reviews.llvm.org/D28953, and 
https://reviews.llvm.org/D28954. Rebasing and fixing up these commits is fairly 
time consuming.


https://reviews.llvm.org/D33308



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


[PATCH] D17143: [Sema] PR25156 Crash when parsing dtor call on incomplete type

2017-06-10 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Thanks, looks great.

If you're going to be submitting multiple patches, you should really ask for 
commit access; it's not an arduous process.


https://reviews.llvm.org/D17143



___
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-06-10 Thread Davide Italiano via Phabricator via cfe-commits
davide added inline comments.



Comment at: include/clang/Basic/Attr.td:2421
 
-def SelectAny : InheritableAttr, TargetSpecificAttr {
+def SelectAny : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Declspec<"selectany">, GCC<"selectany">];

Prazek wrote:
> majnemer wrote:
> > selectany should work on targets other than "x86", "x86_64", "arm", 
> > "thumb", etc. I think it is only necessary to require that it be a COFF or 
> > ELF target.
> Should we allow other OSes than Win32 and Linux?
I guess everything ELF should be allowed.


https://reviews.llvm.org/D33852



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


Re: r303317 - The constant expression evaluator should examine function arguments for non-constexpr function calls unless the EvalInfo says to stop.

2017-06-10 Thread Joerg Sonnenberger via cfe-commits
On Tue, May 30, 2017 at 07:01:22PM -0700, Nick Lewycky wrote:
> Joerg Sonnenberger wrote:
> > On Wed, May 17, 2017 at 11:56:55PM -, Nick Lewycky via cfe-commits 
> > wrote:
> > > Author: nicholas
> > > Date: Wed May 17 18:56:54 2017
> > > New Revision: 303317
> > > 
> > > URL: http://llvm.org/viewvc/llvm-project?rev=303317=rev
> > > Log:
> > > The constant expression evaluator should examine function arguments for 
> > > non-constexpr function calls unless the EvalInfo says to stop.
> > 
> > Crashes with -std=c++11 on:
> > 
> > enum SizeHint { MinimumSize, MaximumSize };
> > class QSizeF {
> > public:
> >constexpr QSizeF();
> >QSizeF m_fn1(QSizeF);
> >double wd;
> >double ht;
> > };
> > constexpr QSizeF::QSizeF() : wd(), ht() {}
> > class A {
> >void m_fn2();
> >QSizeF m_fn3(SizeHint, const QSizeF&  = QSizeF());
> > };
> > void A::m_fn2() { m_fn3(MinimumSize).m_fn1(m_fn3(MaximumSize)); }
> 
> Did you run this with assertions disabled? This looks like another testcase
> for PR33140, but it should hit an assertion first.

Right, same problem as the second test case. This is somewhat
high-profile for me as it affects Qt5.

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


[PATCH] D33997: Implement the non-execution policy versions of `reduce` and `transform_reduce` for C++17

2017-06-10 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists marked 7 inline comments as done.
mclow.lists added inline comments.



Comment at: include/numeric:154
+return reduce(__first, __last, 
+   typename iterator_traits<_InputIterator>::value_type{}, 
_VSTD::plus<>());
+}

wash wrote:
> In the spec, this overload of `reduce` is described as equivalent to `return 
> reduce(std::forward(exec), first, last, typename 
> iterator_traits::value_type{});`.  The overload that it 
> calls (the three argument version that omits a binary operation) just 
> forwards to the four-argument reduce, adding the `plus<>()` argument.
> 
> Is there a reason you wanted to avoid the extra layer of function call 
> indirection (it should be inlined and optimized away, right)? What you have 
> seems perfectly fine, I'm just curious though.
Nah. Just eager on the copy/paste.



Comment at: 
test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_init_bop_uop.pass.cpp:36
+_NOEXCEPT_(noexcept(_VSTD::forward<_Tp>(__x)))
+-> decltype(_VSTD::forward<_Tp>(__x))
+{ return_VSTD::forward<_Tp>(__x); }

rsmith wrote:
> Maybe use `decltype(auto)` here?
I copied this formulation from `` where we use it all over the 
place ;-)
(but that's because we support old standards)


https://reviews.llvm.org/D33997



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


[PATCH] D33997: Implement the non-execution policy versions of `reduce` and `transform_reduce` for C++17

2017-06-10 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists updated this revision to Diff 102125.
mclow.lists added a comment.

Rebased now that https://reviews.llvm.org/D34038 has landed; address Richard 
and Bryce's comments


https://reviews.llvm.org/D33997

Files:
  include/numeric
  test/std/numerics/numeric.ops/reduce/reduce_iter_iter.pass.cpp
  test/std/numerics/numeric.ops/reduce/reduce_iter_iter_T.pass.cpp
  test/std/numerics/numeric.ops/reduce/reduce_iter_iter_T_op.pass.cpp
  
test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_init_bop_uop.pass.cpp
  
test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp
  
test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init_op_op.pass.cpp

Index: test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init_op_op.pass.cpp
===
--- test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init_op_op.pass.cpp
+++ test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init_op_op.pass.cpp
@@ -0,0 +1,97 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+// template 
+//T transform_reduce(InputIterator1 first1, InputIterator1 last1,
+//   InputIterator2 first2, T init,
+//   BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
+//  
+  
+#include 
+#include 
+
+#include "test_iterators.h"
+
+template 
+void
+test(Iter1 first1, Iter1 last1, Iter2 first2, T init, Op1 op1, Op2 op2, T x)
+{
+static_assert( std::is_same_v );
+assert(std::transform_reduce(first1, last1, first2, init, op1, op2) == x);
+}
+
+template 
+void
+test()
+{
+int ia[]  = {1, 2, 3, 4, 5, 6};
+unsigned int ua[] = {2, 4, 6, 8, 10,12};
+unsigned sa = sizeof(ia) / sizeof(ia[0]);
+assert(sa == sizeof(ua) / sizeof(ua[0]));   // just to be sure
+
+test(SIter(ia), SIter(ia),UIter(ua), 0, std::plus<>(), std::multiplies<>(),   0);
+test(UIter(ua), UIter(ua),SIter(ia), 1, std::multiplies<>(), std::plus<>(),   1);
+test(SIter(ia), SIter(ia+1),  UIter(ua), 0, std::multiplies<>(), std::plus<>(),   0);
+test(UIter(ua), UIter(ua+1),  SIter(ia), 2, std::plus<>(), std::multiplies<>(),   4);
+test(SIter(ia), SIter(ia+2),  UIter(ua), 0, std::plus<>(), std::multiplies<>(),  10);
+test(UIter(ua), UIter(ua+2),  SIter(ia), 3, std::multiplies<>(), std::plus<>(),  54);
+test(SIter(ia), SIter(ia+sa), UIter(ua), 4, std::multiplies<>(), std::plus<>(), 2099520);
+test(UIter(ua), UIter(ua+sa), SIter(ia), 4, std::plus<>(), std::multiplies<>(), 186);
+}
+
+template 
+void test_return_type()
+{
+T *p = nullptr;
+static_assert( std::is_same_v(), std::multiplies<>()))> );
+}
+
+int main()
+{
+test_return_type();
+test_return_type();
+test_return_type();
+test_return_type();
+test_return_type();
+test_return_type();
+test_return_type();
+
+//  All the iterator categories
+test, input_iterator >();
+test, forward_iterator   >();
+test, bidirectional_iterator >();
+test, random_access_iterator >();
+
+test, input_iterator >();
+test, forward_iterator   >();
+test, bidirectional_iterator >();
+test, random_access_iterator >();
+
+test();
+test();
+test();
+test();
+
+test();
+test();
+test();
+test();
+
+//  just plain pointers (const vs. non-const, too)
+test();
+test();
+test<  int*, const unsigned int *>();
+test<  int*,   unsigned int *>();
+}
Index: test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp
===
--- test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp
+++ 

[PATCH] D34082: [Frontend 'Show hotness' can be used with a sampling profile

2017-06-10 Thread David Li via Phabricator via cfe-commits
davidxl added inline comments.



Comment at: test/Frontend/optimization-remark-with-hotness.c:32
+// RUN: -Rpass-analysis=inline -fdiagnostics-show-hotness  2>&1 | 
FileCheck \
+// RUN: -check-prefix=PGO_ENABLED %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \

anemet wrote:
> modocache wrote:
> > Ideally, I'd like for this test to be identical to the ones that use 
> > `-verify` above, save for using `-fprofile-sample-use`. However I couldn't 
> > figure out how to write `optimization-remark-with-hotness-sample.proftext` 
> > such that it would produce hotness info for each of the functions. I'm able 
> > to confirm, using real sampling from another program of mine, that remarks 
> > using AutoFDO data do indeed show hotness, but this test does not verify 
> > this in its current state.
> > 
> > Any advice here? I wrote `optimization-remark-with-hotness-sample.proftext` 
> > based on the format specified in 
> > https://clang.llvm.org/docs/UsersManual.html#sample-profile-text-format, 
> > but maybe it's missing something that would allow hotness to be displayed?
> I don't have any immediate ideas since I am not familiar with sample-based 
> profiling unfortunately.  I will study this later unless you beat me to it or 
> David has some ideas.
The hotness is based on profile summary, so you need to adjust the bar's entry 
count and inline instance of foo's count to be  very large value to let 
compiler decide it is hot.


https://reviews.llvm.org/D34082



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


[PATCH] D34082: [Frontend 'Show hotness' can be used with a sampling profile

2017-06-10 Thread Adam Nemet via Phabricator via cfe-commits
anemet added inline comments.



Comment at: test/Frontend/optimization-remark-with-hotness.c:32
+// RUN: -Rpass-analysis=inline -fdiagnostics-show-hotness  2>&1 | 
FileCheck \
+// RUN: -check-prefix=PGO_ENABLED %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \

modocache wrote:
> Ideally, I'd like for this test to be identical to the ones that use 
> `-verify` above, save for using `-fprofile-sample-use`. However I couldn't 
> figure out how to write `optimization-remark-with-hotness-sample.proftext` 
> such that it would produce hotness info for each of the functions. I'm able 
> to confirm, using real sampling from another program of mine, that remarks 
> using AutoFDO data do indeed show hotness, but this test does not verify this 
> in its current state.
> 
> Any advice here? I wrote `optimization-remark-with-hotness-sample.proftext` 
> based on the format specified in 
> https://clang.llvm.org/docs/UsersManual.html#sample-profile-text-format, but 
> maybe it's missing something that would allow hotness to be displayed?
I don't have any immediate ideas since I am not familiar with sample-based 
profiling unfortunately.  I will study this later unless you beat me to it or 
David has some ideas.


https://reviews.llvm.org/D34082



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


[PATCH] D34082: [Frontend 'Show hotness' can be used with a sampling profile

2017-06-10 Thread Adam Nemet via Phabricator via cfe-commits
anemet added inline comments.



Comment at: test/Frontend/optimization-remark-with-hotness.c:1-34
+// Generate instrumentation and sampling profile data.
 // RUN: llvm-profdata merge \
-// RUN: %S/Inputs/optimization-remark-with-hotness.proftext   \
+// RUN: %S/Inputs/optimization-remark-with-hotness.proftext \
 // RUN: -o %t.profdata
+// RUN: llvm-profdata merge -sample \
+// RUN: %S/Inputs/optimization-remark-with-hotness-sample.proftext \
+// RUN: -o %t-sample.profdata

Why don't you put the sampling test right under the instrumented test.  Also I 
don't think we want a separate --check-prefix for it.  It should just use the 
default CHECK since the entire point is that the two should be identical.  In 
other words, please check that we don't warn on either case.


https://reviews.llvm.org/D34082



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


r305148 - Revert "[clang] Implement -Wcast-qual for C++"

2017-06-10 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Sat Jun 10 12:49:23 2017
New Revision: 305148

URL: http://llvm.org/viewvc/llvm-project?rev=305148=rev
Log:
Revert "[clang] Implement -Wcast-qual for C++"

Breaks -Werror builders.

Removed:
cfe/trunk/test/SemaCXX/warn-cast-qual.cpp
Modified:
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/lib/Sema/SemaCast.cpp
cfe/trunk/test/Sema/warn-cast-qual.c

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=305148=305147=305148=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Sat Jun 10 12:49:23 2017
@@ -52,9 +52,6 @@ Major New Features
 Improvements to Clang's diagnostics
 ^^^
 
--  -Wcast-qual was implemented for C++. C-style casts are now properly
-   diagnosed.
-
 -  -Wunused-lambda-capture warns when a variable explicitly captured
by a lambda is not used in the body of the lambda.
 

Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=305148=305147=305148=diff
==
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Sat Jun 10 12:49:23 2017
@@ -143,9 +143,6 @@ namespace {
   };
 }
 
-static void DiagnoseCastQual(Sema , const ExprResult ,
- QualType DestType);
-
 // The Try functions attempt a specific way of casting. If they succeed, they
 // return TC_Success. If their way of casting is not appropriate for the given
 // arguments, they return TC_NotApplicable and *may* set diag to a diagnostic
@@ -430,10 +427,6 @@ static void diagnoseBadCast(Sema , uns
 /// the same kind of pointer (plain or to-member). Unlike the Sema function,
 /// this one doesn't care if the two pointers-to-member don't point into the
 /// same class. This is because CastsAwayConstness doesn't care.
-/// And additionally, it handles C++ references. If both the types are
-/// references, then their pointee types are returned,
-/// else if only one of them is reference, it's pointee type is returned,
-/// and the other type is returned as-is.
 static bool UnwrapDissimilarPointerTypes(QualType& T1, QualType& T2) {
   const PointerType *T1PtrType = T1->getAs(),
 *T2PtrType = T2->getAs();
@@ -482,26 +475,6 @@ static bool UnwrapDissimilarPointerTypes
 return true;
   }
   
-  const LValueReferenceType *T1RefType = T1->getAs(),
-*T2RefType = T2->getAs();
-  if (T1RefType && T2RefType) {
-T1 = T1RefType->getPointeeType();
-T2 = T2RefType->getPointeeType();
-return true;
-  }
-
-  if (T1RefType) {
-T1 = T1RefType->getPointeeType();
-// T2 = T2;
-return true;
-  }
-
-  if (T2RefType) {
-// T1 = T1;
-T2 = T2RefType->getPointeeType();
-return true;
-  }
-
   return false;
 }
 
@@ -530,13 +503,11 @@ CastsAwayConstness(Sema , QualType
   // the rules are non-trivial. So first we construct Tcv *...cv* as described
   // in C++ 5.2.11p8.
   assert((SrcType->isAnyPointerType() || SrcType->isMemberPointerType() ||
-  SrcType->isBlockPointerType() ||
-  DestType->isLValueReferenceType()) &&
+  SrcType->isBlockPointerType()) &&
  "Source type is not pointer or pointer to member.");
   assert((DestType->isAnyPointerType() || DestType->isMemberPointerType() ||
-  DestType->isBlockPointerType() ||
-  DestType->isLValueReferenceType()) &&
- "Destination type is not pointer or pointer to member, or 
reference.");
+  DestType->isBlockPointerType()) &&
+ "Destination type is not pointer or pointer to member.");
 
   QualType UnwrappedSrcType = Self.Context.getCanonicalType(SrcType), 
UnwrappedDestType = Self.Context.getCanonicalType(DestType);
@@ -2206,8 +2177,6 @@ static TryCastResult TryReinterpretCast(
 
 void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle,
bool ListInitialization) {
-  assert(Self.getLangOpts().CPlusPlus);
-
   // Handle placeholders.
   if (isPlaceholder()) {
 // C-style casts can resolve __unknown_any types.
@@ -2611,42 +2580,30 @@ void CastOperation::CheckCStyleCast() {
 
   if (Kind == CK_BitCast)
 checkCastAlign();
-}
-
-/// DiagnoseCastQual - Warn whenever casts discards a qualifiers, be it either
-/// const, volatile or both.
-static void DiagnoseCastQual(Sema , const ExprResult ,
- QualType DestType) {
-  if (SrcExpr.isInvalid())
-return;
-
-  QualType SrcType = SrcExpr.get()->getType();
-  if (!((SrcType->isAnyPointerType() && DestType->isAnyPointerType()) ||
-DestType->isLValueReferenceType()))
-return;
 
+  // -Wcast-qual
   QualType TheOffendingSrcType, TheOffendingDestType;
   Qualifiers CastAwayQualifiers;
-  if 

[PATCH] D34082: [Frontend 'Show hotness' can be used with a sampling profile

2017-06-10 Thread Brian Gesiak via Phabricator via cfe-commits
modocache added inline comments.



Comment at: test/Frontend/optimization-remark-with-hotness.c:32
+// RUN: -Rpass-analysis=inline -fdiagnostics-show-hotness  2>&1 | 
FileCheck \
+// RUN: -check-prefix=PGO_ENABLED %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \

Ideally, I'd like for this test to be identical to the ones that use `-verify` 
above, save for using `-fprofile-sample-use`. However I couldn't figure out how 
to write `optimization-remark-with-hotness-sample.proftext` such that it would 
produce hotness info for each of the functions. I'm able to confirm, using real 
sampling from another program of mine, that remarks using AutoFDO data do 
indeed show hotness, but this test does not verify this in its current state.

Any advice here? I wrote `optimization-remark-with-hotness-sample.proftext` 
based on the format specified in 
https://clang.llvm.org/docs/UsersManual.html#sample-profile-text-format, but 
maybe it's missing something that would allow hotness to be displayed?


https://reviews.llvm.org/D34082



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


[PATCH] D34082: [Frontend 'Show hotness' can be used with a sampling profile

2017-06-10 Thread Brian Gesiak via Phabricator via cfe-commits
modocache created this revision.

Prior to this change, using `-fdiagnostics-show-hotness` with a sampling
profile specified via `-fprofile-sample-use=` would result in the Clang
frontend emitting a warning: "argument '-fdiagnostics-show-hotness' requires
profile-guided optimization information". Of course, a sampling profile
*is* profile-guided optimization information, so the warning is misleading.
Furthermore, despite the warning, hotness was displayed based on the data in
the sampling profile.

Prevent the warning from being emitted when a sampling profile is used, and
add a test that verifies this.


https://reviews.llvm.org/D34082

Files:
  lib/Frontend/CompilerInvocation.cpp
  test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext
  test/Frontend/optimization-remark-with-hotness.c


Index: test/Frontend/optimization-remark-with-hotness.c
===
--- test/Frontend/optimization-remark-with-hotness.c
+++ test/Frontend/optimization-remark-with-hotness.c
@@ -1,6 +1,11 @@
+// Generate instrumentation and sampling profile data.
 // RUN: llvm-profdata merge \
-// RUN: %S/Inputs/optimization-remark-with-hotness.proftext   \
+// RUN: %S/Inputs/optimization-remark-with-hotness.proftext \
 // RUN: -o %t.profdata
+// RUN: llvm-profdata merge -sample \
+// RUN: %S/Inputs/optimization-remark-with-hotness-sample.proftext \
+// RUN: -o %t-sample.profdata
+//
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
@@ -22,6 +27,11 @@
 // RUN: -check-prefix=HOTNESS_OFF %s
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
+// RUN: -fprofile-sample-use=%t-sample.profdata -Rpass=inline \
+// RUN: -Rpass-analysis=inline -fdiagnostics-show-hotness  2>&1 | 
FileCheck \
+// RUN: -check-prefix=PGO_ENABLED %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
+// RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
 // RUN: -Rpass=inline -Rpass-analysis=inline -fdiagnostics-show-hotness  
2>&1 \
 // RUN: | FileCheck -check-prefix=NO_PGO %s
 
@@ -33,6 +43,7 @@
 void bar(int x) {
   // HOTNESS_OFF: foo inlined into bar
   // HOTNESS_OFF-NOT: hotness:
+  // PGO_ENABLED-NOT: '-fdiagnostics-show-hotness' requires profile-guided 
optimization information
   // NO_PGO: '-fdiagnostics-show-hotness' requires profile-guided optimization 
information
   // expected-remark@+2 {{foo should always be inlined (cost=always) (hotness: 
30)}}
   // expected-remark@+1 {{foo inlined into bar (hotness: 30)}}
Index: test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext
===
--- /dev/null
+++ test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext
@@ -0,0 +1,6 @@
+bar:15:0
+  1: foo:15
+1: 15
+main:100:0
+  1: 100
+
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -884,14 +884,18 @@
 
   Opts.DiagnosticsWithHotness =
   Args.hasArg(options::OPT_fdiagnostics_show_hotness);
+  bool UsingSampleProfile = !Opts.SampleProfileFile.empty();
+
   if (Opts.DiagnosticsWithHotness &&
-  Opts.getProfileUse() == CodeGenOptions::ProfileNone)
+  Opts.getProfileUse() == CodeGenOptions::ProfileNone &&
+  !UsingSampleProfile) {
 Diags.Report(diag::warn_drv_fdiagnostics_show_hotness_requires_pgo);
+  }
 
   // If the user requested to use a sample profile for PGO, then the
   // backend will need to track source location information so the profile
   // can be incorporated into the IR.
-  if (!Opts.SampleProfileFile.empty())
+  if (UsingSampleProfile)
 NeedLocTracking = true;
 
   // If the user requested a flag that requires source locations available in


Index: test/Frontend/optimization-remark-with-hotness.c
===
--- test/Frontend/optimization-remark-with-hotness.c
+++ test/Frontend/optimization-remark-with-hotness.c
@@ -1,6 +1,11 @@
+// Generate instrumentation and sampling profile data.
 // RUN: llvm-profdata merge \
-// RUN: %S/Inputs/optimization-remark-with-hotness.proftext   \
+// RUN: %S/Inputs/optimization-remark-with-hotness.proftext \
 // RUN: -o %t.profdata
+// RUN: llvm-profdata merge -sample \
+// RUN: %S/Inputs/optimization-remark-with-hotness-sample.proftext \
+// RUN: -o %t-sample.profdata
+//
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
@@ -22,6 +27,11 @@
 // 

[PATCH] D33102: [clang] Implement -Wcast-qual for C++

2017-06-10 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305147: [clang] Implement -Wcast-qual for C++ (authored by 
lebedevri).

Changed prior to commit:
  https://reviews.llvm.org/D33102?vs=102119=102120#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33102

Files:
  cfe/trunk/docs/ReleaseNotes.rst
  cfe/trunk/lib/Sema/SemaCast.cpp
  cfe/trunk/test/Sema/warn-cast-qual.c
  cfe/trunk/test/SemaCXX/warn-cast-qual.cpp

Index: cfe/trunk/test/SemaCXX/warn-cast-qual.cpp
===
--- cfe/trunk/test/SemaCXX/warn-cast-qual.cpp
+++ cfe/trunk/test/SemaCXX/warn-cast-qual.cpp
@@ -0,0 +1,140 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -Wcast-qual -verify %s
+
+#include 
+
+// do *NOT* warn on const_cast<>()
+// use clang-tidy's cppcoreguidelines-pro-type-const-cast for that.
+void foo_ptr() {
+  const char *const ptr = 0;
+  char *t0 = const_cast(ptr); // no warning
+
+  volatile char *ptr2 = 0;
+  char *t1 = const_cast(ptr2); // no warning
+
+  const volatile char *ptr3 = 0;
+  char *t2 = const_cast(ptr3); // no warning
+}
+
+void cstr() {
+  void* p0 = (void*)(const void*)"txt"; // expected-warning {{cast from 'const void *' to 'void *' drops const qualifier}}
+  void* p1 = (void*)"txt"; // FIXME
+  char* p2 = (char*)"txt"; // expected-warning {{cast from 'const char *' to 'char *' drops const qualifier}}
+}
+
+void foo_0() {
+  const int a = 0;
+
+  const int  = a;  // no warning
+  const int  = (const int &)a; // no warning
+
+  int  = (int &)a;  // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}}
+  const int  = (int &)a;// expected-warning {{cast from 'const int' to 'int &' drops const qualifier}}
+  int  = (int &)((const int &)a);   // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}}
+  int  = (int &)((int &)a); // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}}
+  const int  = (int &)((int &)a);   // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}}
+  const int  = (int &)((const int &)a); // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}}
+  const int  = (const int &)((int &)a); // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}}
+}
+
+void foo_1() {
+  volatile int a = 0;
+
+  volatile int  = a; // no warning
+  volatile int  = (volatile int &)a; // no warning
+
+  int  = (int &)a;// expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}}
+  volatile int  = (int &)a;   // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}}
+  int  = (int &)((volatile int &)a);  // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}}
+  int  = (int &)((int &)a);   // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}}
+  volatile int  = (int &)((int &)a);  // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}}
+  volatile int  = (int &)((volatile int &)a); // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}}
+  volatile int  = (volatile int &)((int &)a); // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}}
+}
+
+void foo_2() {
+  const volatile int a = 0;
+
+  const volatile int  = a;   // no warning
+  const volatile int  = (const volatile int &)a; // no warning
+
+  int  = (int &)a;// expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}}
+  const volatile int  = (int &)a; // expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}}
+  int  = (int &)((const volatile int &)a);// expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}}
+  int  = (int &)((int &)a);   // expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}}
+  const volatile int  = (int &)((int &)a);// expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}}
+  const volatile int  = (int &)((const volatile int &)a); // expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}}
+  const volatile int  = (const volatile int &)((int &)a); // expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}}
+}
+
+void bar_0() {
+  const int *_a = 0;
+  const int **a = &_a;
+
+  int **a0 = (int **)((const int **)a); // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}}
+  

r305147 - [clang] Implement -Wcast-qual for C++

2017-06-10 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Sat Jun 10 12:19:19 2017
New Revision: 305147

URL: http://llvm.org/viewvc/llvm-project?rev=305147=rev
Log:
[clang] Implement -Wcast-qual for C++

Summary:
This way, the behavior of that warning flag
more closely resembles that of GCC.

Do note that there is at least one false-negative (see FIXME in tests).

Fixes PR4802.

Testing:
```
ninja check-clang-sema check-clang-semacxx
```

Reviewers: dblaikie, majnemer, rnk

Reviewed By: dblaikie, rnk

Subscribers: cfe-commits, alexfh, rnk

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

Added:
cfe/trunk/test/SemaCXX/warn-cast-qual.cpp
Modified:
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/lib/Sema/SemaCast.cpp
cfe/trunk/test/Sema/warn-cast-qual.c

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=305147=305146=305147=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Sat Jun 10 12:19:19 2017
@@ -52,6 +52,9 @@ Major New Features
 Improvements to Clang's diagnostics
 ^^^
 
+-  -Wcast-qual was implemented for C++. C-style casts are now properly
+   diagnosed.
+
 -  -Wunused-lambda-capture warns when a variable explicitly captured
by a lambda is not used in the body of the lambda.
 

Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=305147=305146=305147=diff
==
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Sat Jun 10 12:19:19 2017
@@ -143,6 +143,9 @@ namespace {
   };
 }
 
+static void DiagnoseCastQual(Sema , const ExprResult ,
+ QualType DestType);
+
 // The Try functions attempt a specific way of casting. If they succeed, they
 // return TC_Success. If their way of casting is not appropriate for the given
 // arguments, they return TC_NotApplicable and *may* set diag to a diagnostic
@@ -427,6 +430,10 @@ static void diagnoseBadCast(Sema , uns
 /// the same kind of pointer (plain or to-member). Unlike the Sema function,
 /// this one doesn't care if the two pointers-to-member don't point into the
 /// same class. This is because CastsAwayConstness doesn't care.
+/// And additionally, it handles C++ references. If both the types are
+/// references, then their pointee types are returned,
+/// else if only one of them is reference, it's pointee type is returned,
+/// and the other type is returned as-is.
 static bool UnwrapDissimilarPointerTypes(QualType& T1, QualType& T2) {
   const PointerType *T1PtrType = T1->getAs(),
 *T2PtrType = T2->getAs();
@@ -475,6 +482,26 @@ static bool UnwrapDissimilarPointerTypes
 return true;
   }
   
+  const LValueReferenceType *T1RefType = T1->getAs(),
+*T2RefType = T2->getAs();
+  if (T1RefType && T2RefType) {
+T1 = T1RefType->getPointeeType();
+T2 = T2RefType->getPointeeType();
+return true;
+  }
+
+  if (T1RefType) {
+T1 = T1RefType->getPointeeType();
+// T2 = T2;
+return true;
+  }
+
+  if (T2RefType) {
+// T1 = T1;
+T2 = T2RefType->getPointeeType();
+return true;
+  }
+
   return false;
 }
 
@@ -503,11 +530,13 @@ CastsAwayConstness(Sema , QualType
   // the rules are non-trivial. So first we construct Tcv *...cv* as described
   // in C++ 5.2.11p8.
   assert((SrcType->isAnyPointerType() || SrcType->isMemberPointerType() ||
-  SrcType->isBlockPointerType()) &&
+  SrcType->isBlockPointerType() ||
+  DestType->isLValueReferenceType()) &&
  "Source type is not pointer or pointer to member.");
   assert((DestType->isAnyPointerType() || DestType->isMemberPointerType() ||
-  DestType->isBlockPointerType()) &&
- "Destination type is not pointer or pointer to member.");
+  DestType->isBlockPointerType() ||
+  DestType->isLValueReferenceType()) &&
+ "Destination type is not pointer or pointer to member, or 
reference.");
 
   QualType UnwrappedSrcType = Self.Context.getCanonicalType(SrcType), 
UnwrappedDestType = Self.Context.getCanonicalType(DestType);
@@ -2177,6 +2206,8 @@ static TryCastResult TryReinterpretCast(
 
 void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle,
bool ListInitialization) {
+  assert(Self.getLangOpts().CPlusPlus);
+
   // Handle placeholders.
   if (isPlaceholder()) {
 // C-style casts can resolve __unknown_any types.
@@ -2580,30 +2611,42 @@ void CastOperation::CheckCStyleCast() {
 
   if (Kind == CK_BitCast)
 checkCastAlign();
+}
+
+/// DiagnoseCastQual - Warn whenever casts discards a qualifiers, be it either
+/// const, volatile or both.
+static void DiagnoseCastQual(Sema , const ExprResult ,
+ 

[PATCH] D33102: [clang] Implement -Wcast-qual for C++

2017-06-10 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 102119.
lebedev.ri edited the summary of this revision.
lebedev.ri added a comment.
This revision is now accepted and ready to land.

After further mail exchange, i will proceed to commit this as-is.
No code changes, rebase before commit.


Repository:
  rL LLVM

https://reviews.llvm.org/D33102

Files:
  docs/ReleaseNotes.rst
  lib/Sema/SemaCast.cpp
  test/Sema/warn-cast-qual.c
  test/SemaCXX/warn-cast-qual.cpp

Index: test/SemaCXX/warn-cast-qual.cpp
===
--- /dev/null
+++ test/SemaCXX/warn-cast-qual.cpp
@@ -0,0 +1,140 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -Wcast-qual -verify %s
+
+#include 
+
+// do *NOT* warn on const_cast<>()
+// use clang-tidy's cppcoreguidelines-pro-type-const-cast for that.
+void foo_ptr() {
+  const char *const ptr = 0;
+  char *t0 = const_cast(ptr); // no warning
+
+  volatile char *ptr2 = 0;
+  char *t1 = const_cast(ptr2); // no warning
+
+  const volatile char *ptr3 = 0;
+  char *t2 = const_cast(ptr3); // no warning
+}
+
+void cstr() {
+  void* p0 = (void*)(const void*)"txt"; // expected-warning {{cast from 'const void *' to 'void *' drops const qualifier}}
+  void* p1 = (void*)"txt"; // FIXME
+  char* p2 = (char*)"txt"; // expected-warning {{cast from 'const char *' to 'char *' drops const qualifier}}
+}
+
+void foo_0() {
+  const int a = 0;
+
+  const int  = a;  // no warning
+  const int  = (const int &)a; // no warning
+
+  int  = (int &)a;  // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}}
+  const int  = (int &)a;// expected-warning {{cast from 'const int' to 'int &' drops const qualifier}}
+  int  = (int &)((const int &)a);   // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}}
+  int  = (int &)((int &)a); // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}}
+  const int  = (int &)((int &)a);   // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}}
+  const int  = (int &)((const int &)a); // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}}
+  const int  = (const int &)((int &)a); // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}}
+}
+
+void foo_1() {
+  volatile int a = 0;
+
+  volatile int  = a; // no warning
+  volatile int  = (volatile int &)a; // no warning
+
+  int  = (int &)a;// expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}}
+  volatile int  = (int &)a;   // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}}
+  int  = (int &)((volatile int &)a);  // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}}
+  int  = (int &)((int &)a);   // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}}
+  volatile int  = (int &)((int &)a);  // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}}
+  volatile int  = (int &)((volatile int &)a); // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}}
+  volatile int  = (volatile int &)((int &)a); // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}}
+}
+
+void foo_2() {
+  const volatile int a = 0;
+
+  const volatile int  = a;   // no warning
+  const volatile int  = (const volatile int &)a; // no warning
+
+  int  = (int &)a;// expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}}
+  const volatile int  = (int &)a; // expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}}
+  int  = (int &)((const volatile int &)a);// expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}}
+  int  = (int &)((int &)a);   // expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}}
+  const volatile int  = (int &)((int &)a);// expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}}
+  const volatile int  = (int &)((const volatile int &)a); // expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}}
+  const volatile int  = (const volatile int &)((int &)a); // expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}}
+}
+
+void bar_0() {
+  const int *_a = 0;
+  const int **a = &_a;
+
+  int **a0 = (int **)((const int **)a); // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}}
+  int **a1 = (int **)((int **)a);   // expected-warning 

Re: [PATCH] D33102: [clang] Implement -Wcast-qual for C++

2017-06-10 Thread Roman Lebedev via cfe-commits
On Sat, Jun 10, 2017 at 7:05 PM, David Blaikie  wrote:
>
>
> On Sat, Jun 10, 2017 at 3:33 AM Roman Lebedev via Phabricator
>  wrote:
>>
>> lebedev.ri planned changes to this revision.
>> lebedev.ri added a comment.
>>
>> In https://reviews.llvm.org/D33102#773296, @dblaikie wrote:
>>
>> > But sure. Could you also (manually, I guess) confirm that this matches
>> > GCC's cast-qual behavior (insofar as the warning fires in the same
>> > situations). If there are any deviations, let's chat about them.
>>
>>
>> Great, you were right :)
>> Found a false-negative:
>>
>>   $ cat /tmp/tst.c
>>   int main() {
>> void* p1 = (void*)"txt";
>> char* p2 = (char*)"txt";
>>   }
>>   $ gcc -x c -Wcast-qual /tmp/tst.c
>>   $ gcc -x c++ -Wcast-qual /tmp/tst.c
>>   /tmp/tst.c: In function ‘int main()’:
>>   /tmp/tst.c:2:21: warning: cast from type ‘const char*’ to type ‘void*’
>> casts away qualifiers [-Wcast-qual]
>>  void* p1 = (void*)"txt";
>>^
>>   /tmp/tst.c:3:21: warning: cast from type ‘const char*’ to type ‘char*’
>> casts away qualifiers [-Wcast-qual]
>>  char* p2 = (char*)"txt";
>>^
>>
>>   $ ./bin/clang -x c -Wcast-qual /tmp/tst.c
>>   $ ./bin/clang -x c++ -Wcast-qual /tmp/tst.c
>>   /tmp/tst.c:3:21: warning: cast from 'const char *' to 'char *' drops
>> const qualifier [-Wcast-qual]
>> char* p2 = (char*)"txt";
>>   ^
>>   1 warning generated.
>>
>> So at least, in C++ mode, it should warn on both lines.
>
>
> Seems reasonable that it should, yes.
>
> (aside: You're still welcome to commit this patch as-is, and provide patches
> for improvements as follow-up (mostly false positives would be more of a
> concern to address before commit))
Yeah...

I have looked around, and best i can figure out is that auto-inserted
`-ImplicitCastExpr  'void *' 
somehow lacks the constness.
I'm not sure where it is inserted, or why the const is missing,
but i guess ImpCastExprToType function is responsible.

TranslationUnitDecl
`-FunctionDecl  line:1:5 main 'int (void)'
  `-CompoundStmt 
`-DeclStmt 
  `-VarDecl  col:9 p2 'void *' cinit
`-CStyleCastExpr  'void *' 
  `-ImplicitCastExpr  'void *' 
`-ImplicitCastExpr  'const char *' 
  `-StringLiteral  'const char [4]' lvalue "txt"

So yeah, i will commit as-is.

>>
>> I'm not sure, should that really not produce a warning in C?
>> (gcc version 6.3.0 20170516 (Debian 6.3.0-18) )

> Probably not, no - string literals have some weird mutability in C (& in
> older versions of C++, even).
I agree. After leaving that comment, i checked AST, and in C, the type
of such string is non-const:

TranslationUnitDecl
`-FunctionDecl  line:1:5 main 'int ()'
  `-CompoundStmt 
`-DeclStmt 
  `-VarDecl  col:9 p2 'char *' cinit
`-CStyleCastExpr  'char *' 
  `-ImplicitCastExpr  'char *' 
`-StringLiteral  'char [4]' lvalue "txt"


And, while there, i found out that -Wcast-align is broken for
reinterpret_cast<>() :/
https://bugs.llvm.org/show_bug.cgi?id=33397

> - Dave
Roman.

>>
>>
>>
>> Repository:
>>   rL LLVM
>>
>> https://reviews.llvm.org/D33102
>>
>>
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D33102: [clang] Implement -Wcast-qual for C++

2017-06-10 Thread David Blaikie via cfe-commits
On Sat, Jun 10, 2017 at 3:33 AM Roman Lebedev via Phabricator <
revi...@reviews.llvm.org> wrote:

> lebedev.ri planned changes to this revision.
> lebedev.ri added a comment.
>
> In https://reviews.llvm.org/D33102#773296, @dblaikie wrote:
>
> > But sure. Could you also (manually, I guess) confirm that this matches
> GCC's cast-qual behavior (insofar as the warning fires in the same
> situations). If there are any deviations, let's chat about them.
>
>
> Great, you were right :)
> Found a false-negative:
>
>   $ cat /tmp/tst.c
>   int main() {
> void* p1 = (void*)"txt";
> char* p2 = (char*)"txt";
>   }
>   $ gcc -x c -Wcast-qual /tmp/tst.c
>   $ gcc -x c++ -Wcast-qual /tmp/tst.c
>   /tmp/tst.c: In function ‘int main()’:
>   /tmp/tst.c:2:21: warning: cast from type ‘const char*’ to type ‘void*’
> casts away qualifiers [-Wcast-qual]
>  void* p1 = (void*)"txt";
>^
>   /tmp/tst.c:3:21: warning: cast from type ‘const char*’ to type ‘char*’
> casts away qualifiers [-Wcast-qual]
>  char* p2 = (char*)"txt";
>^
>
>   $ ./bin/clang -x c -Wcast-qual /tmp/tst.c
>   $ ./bin/clang -x c++ -Wcast-qual /tmp/tst.c
>   /tmp/tst.c:3:21: warning: cast from 'const char *' to 'char *' drops
> const qualifier [-Wcast-qual]
> char* p2 = (char*)"txt";
>   ^
>   1 warning generated.
>
> So at least, in C++ mode, it should warn on both lines.
>

Seems reasonable that it should, yes.

(aside: You're still welcome to commit this patch as-is, and provide
patches for improvements as follow-up (mostly false positives would be more
of a concern to address before commit))


> I'm not sure, should that really not produce a warning in C?
> (gcc version 6.3.0 20170516 (Debian 6.3.0-18) )
>

Probably not, no - string literals have some weird mutability in C (& in
older versions of C++, even).

- Dave


>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D33102
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D30748: [Lexer] Finding beginning of token with escaped new line

2017-06-10 Thread Paweł Żukowski via Phabricator via cfe-commits
idlecode updated this revision to Diff 102110.
idlecode added a comment.

Added tests for `isNewLineEscaped` - this fixed some corner cases


https://reviews.llvm.org/D30748

Files:
  lib/Lex/Lexer.cpp
  unittests/Lex/LexerTest.cpp

Index: unittests/Lex/LexerTest.cpp
===
--- unittests/Lex/LexerTest.cpp
+++ unittests/Lex/LexerTest.cpp
@@ -25,6 +25,8 @@
 
 using namespace clang;
 
+bool isNewLineEscaped(const char *BufferStart, const char *Str);
+
 namespace {
 
 // The test fixture.
@@ -365,4 +367,53 @@
   EXPECT_EQ(SourceMgr.getFileIDSize(SourceMgr.getFileID(helper1ArgLoc)), 8U);
 }
 
+TEST_F(LexerTest, IsNewLineEscapedValid) {
+  std::vector> TestLines = {
+  {true, "\\\r"},{true, "\\\n"},{true, "\\\r\n"},
+  {true, "\\\n\r"},  {true, "\\ \t\v\f\r"}, {true, "\\ \t\v\f\r\n"},
+  {false, "\\\r\r"}, {false, "\\\r\r\n"},   {false, "\\\n\n"},
+  {false, "\r"}, {false, "\n"}, {false, "\r\n"},
+  {false, "\n\r"},   {false, "\r\r"},   {false, "\n\n"}};
+
+  int i = 1;
+  for (const std::pair  : TestLines) {
+bool IsEscaped = Pattern.first;
+const std::string  = Pattern.second;
+EXPECT_EQ(IsEscaped,
+  isNewLineEscaped(Line.c_str(), Line.c_str() + Line.length() - 1))
+<< "Pattern #" << i << " not recognized as escaped new line\n";
+++i;
+  }
+}
+
+TEST_F(LexerTest, GetBeginningOfTokenWithEscapedNewLine) {
+  // Each line should have the same length for
+  // further offset calculation to be more straightforward.
+  const unsigned IdentifierLength = 8;
+  std::string TextToLex = "rabarbar\n"
+  "foo\\\nbar\n"
+  "foo\\\rbar\n"
+  "fo\\\r\nbar\n"
+  "foo\\\n\rba\n";
+  std::vector ExpectedTokens{5, tok::identifier};
+  std::vector LexedTokens = CheckLex(TextToLex, ExpectedTokens);
+
+  for (const Token  : LexedTokens) {
+std::pair OriginalLocation =
+SourceMgr.getDecomposedLoc(Tok.getLocation());
+for (unsigned Offset = 0; Offset < IdentifierLength; ++Offset) {
+  SourceLocation LookupLocation =
+  Tok.getLocation().getLocWithOffset(Offset);
+
+  std::pair FoundLocation =
+  SourceMgr.getDecomposedExpansionLoc(
+  Lexer::GetBeginningOfToken(LookupLocation, SourceMgr, LangOpts));
+
+  // Check that location returned by the GetBeginningOfToken
+  // is the same as original token location reported by Lexer.
+  EXPECT_EQ(FoundLocation.second, OriginalLocation.second);
+}
+  }
+}
+
 } // anonymous namespace
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -456,25 +456,45 @@
   return false;
 }
 
+/// \brief Check if new line pointed by Str is escaped.
+bool isNewLineEscaped(const char *BufferStart, const char *Str) {
+  assert(isVerticalWhitespace(Str[0]));
+  if (Str - 1 < BufferStart)
+return false;
+
+  if ((Str[0] == '\n' && Str[-1] == '\r') ||
+  (Str[0] == '\r' && Str[-1] == '\n')) {
+if (Str - 2 < BufferStart)
+  return false;
+--Str;
+  }
+  --Str;
+
+  // Rewind to first non-space character:
+  while (isHorizontalWhitespace(*Str) && Str > BufferStart)
+--Str;
+
+  return *Str == '\\';
+}
+
 /// Returns the pointer that points to the beginning of line that contains
 /// the given offset, or null if the offset if invalid.
 static const char *findBeginningOfLine(StringRef Buffer, unsigned Offset) {
   const char *BufStart = Buffer.data();
   if (Offset >= Buffer.size())
 return nullptr;
-  const char *StrData = BufStart + Offset;
 
-  if (StrData[0] == '\n' || StrData[0] == '\r')
-return StrData;
+  const char *LexStart = BufStart + Offset;
+  for (; LexStart != BufStart; --LexStart) {
+if (!isVerticalWhitespace(LexStart[0]))
+  continue;
 
-  const char *LexStart = StrData;
-  while (LexStart != BufStart) {
-if (LexStart[0] == '\n' || LexStart[0] == '\r') {
-  ++LexStart;
-  break;
-}
+if (isNewLineEscaped(BufStart, LexStart))
+  continue;
 
---LexStart;
+// LexStart should point at first character of logical line.
+++LexStart;
+break;
   }
   return LexStart;
 }
@@ -486,7 +506,7 @@
   std::pair LocInfo = SM.getDecomposedLoc(Loc);
   if (LocInfo.first.isInvalid())
 return Loc;
-  
+
   bool Invalid = false;
   StringRef Buffer = SM.getBufferData(LocInfo.first, );
   if (Invalid)
@@ -498,52 +518,52 @@
   const char *LexStart = findBeginningOfLine(Buffer, LocInfo.second);
   if (!LexStart || LexStart == StrData)
 return Loc;
-  
+
   // Create a lexer starting at the beginning of this token.
   SourceLocation LexerStartLoc = Loc.getLocWithOffset(-LocInfo.second);
   Lexer TheLexer(LexerStartLoc, LangOpts, Buffer.data(), LexStart,

[PATCH] D33102: [clang] Implement -Wcast-qual for C++

2017-06-10 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri planned changes to this revision.
lebedev.ri added a comment.

In https://reviews.llvm.org/D33102#773296, @dblaikie wrote:

> But sure. Could you also (manually, I guess) confirm that this matches GCC's 
> cast-qual behavior (insofar as the warning fires in the same situations). If 
> there are any deviations, let's chat about them.


Great, you were right :)
Found a false-negative:

  $ cat /tmp/tst.c
  int main() {
void* p1 = (void*)"txt";
char* p2 = (char*)"txt";
  }
  $ gcc -x c -Wcast-qual /tmp/tst.c
  $ gcc -x c++ -Wcast-qual /tmp/tst.c
  /tmp/tst.c: In function ‘int main()’:
  /tmp/tst.c:2:21: warning: cast from type ‘const char*’ to type ‘void*’ casts 
away qualifiers [-Wcast-qual]
 void* p1 = (void*)"txt";
   ^
  /tmp/tst.c:3:21: warning: cast from type ‘const char*’ to type ‘char*’ casts 
away qualifiers [-Wcast-qual]
 char* p2 = (char*)"txt";
   ^
  
  $ ./bin/clang -x c -Wcast-qual /tmp/tst.c 
  $ ./bin/clang -x c++ -Wcast-qual /tmp/tst.c 
  /tmp/tst.c:3:21: warning: cast from 'const char *' to 'char *' drops const 
qualifier [-Wcast-qual]
char* p2 = (char*)"txt";
  ^
  1 warning generated.

So at least, in C++ mode, it should warn on both lines.
I'm not sure, should that really not produce a warning in C?
(gcc version 6.3.0 20170516 (Debian 6.3.0-18) )


Repository:
  rL LLVM

https://reviews.llvm.org/D33102



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


[PATCH] D33722: [clang-tidy] Add checker for undelegated copy of base classes

2017-06-10 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik marked 2 inline comments as done.
szdominik added a comment.

Warnings of the check's run on llvm/clang codebase.

F3426875: undelegated-copy-of-base-classes-clangrun.txt 



https://reviews.llvm.org/D33722



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