Re: Implict casts disappeared from syntactic init list expressions in C++

2015-08-29 Thread Abramo Bagnara via cfe-commits
Il 28/08/2015 23:27, Richard Smith ha scritto:
 On Tue, Aug 25, 2015 at 10:27 AM, Abramo Bagnara
 abramo.bagn...@bugseng.com mailto:abramo.bagn...@bugseng.com wrote:
 
 Comparing the result of InitListExpr::getSyntacticForm between r224986
 and r245836 I've discovered that integer to char implicit cast for
 integer literal 3 is no longer added to AST for C++ (while it is present
 in C).
 
 This is the source used to test:
 
 char v[10] = { 3 };
 
 Taken in account that:
 
 - implicit cast (and other conversions, constructor calls, etc.) are
 very important also for who need to visit the syntactic form (obvious in
 *both* C and C++)
 
 - to generate that for the syntactic form permit to increase the
 efficiency and the sharing when using designated range extensions (as
 the conversion chain don't need to be replicated for each entry)
 
 I think it is a regression. Am I missing something?
 
 
 Why do you expect this semantic information to appear in the syntactic
 form of the initializer? 

Compare:

int x = 2.0;

with

struct s {
  int x;
} v = { .x = 2.0 };

For first declaration I have non-syntactic nodes (namely
ImplicitCastExpr) along with syntactic nodes, while for the second I
don't have that (for C++). This is an obstacle to write semi-syntactic
checkers that aims to find e.g. implicit cast from double to int in its
syntactic context.
Note that although we might visit the semantic form, we'll lose the
designators (not present in semantic form).

To resume, the reason why I would expect that are:

1) this is how it always has worked for C (and fortunately still works
this way)


2) this is how it always has worked (although partially, there was some
bugs) for C++. In past we have had patches to fix the areas where this
invariant was not respected (see commit 3146766
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20111212/050339.html
as an example).

This behavior has changed rather recently (if you think it is useful I
can find the commit that has removed the implicit casts from syntactic
form in C++)

Before such commit(s) the only bug I was aware where AST was missing
conversion chain was the following:

struct R2 {
  R2(int) {
  }
};
R2 v2[] = { 1.0 };


3) this way it would be congruent with other areas of AST where we have
non-syntactic nodes along with syntactic ones


4) it would permit to share more nodes in semantic form (and avoid to
rebuild many times the same conversion chain).

Looking at following typescript you can observe that ImplicitCastExpr is
shared only for C, but not for C++. I've initialized only two entries,
but it might be 1000 or 1000.

$ cat p.c
int x[100] = { [0 ... 1] = 3.0 };
$ clang-3.8 -cc1 -ast-dump -x c p.c
TranslationUnitDecl 0x272de40 invalid sloc invalid sloc
|-TypedefDecl 0x272e338 invalid sloc invalid sloc implicit
__int128_t '__int128'
|-TypedefDecl 0x272e398 invalid sloc invalid sloc implicit
__uint128_t 'unsigned __int128'
|-TypedefDecl 0x272e648 invalid sloc invalid sloc implicit
__builtin_va_list 'struct __va_list_tag [1]'
`-VarDecl 0x272e718 p.c:1:1, col:36 col:5 x 'int [100]' cinit
  `-InitListExpr 0x272e8b0 col:18, col:36 'int [100]'
|-array filler
| `-ImplicitValueInitExpr 0x272e918 invalid sloc 'int'
|-ImplicitCastExpr 0x272e900 col:32 'int' FloatingToIntegral
| `-FloatingLiteral 0x272e7f8 col:32 'double' 3.00e+00
`-ImplicitCastExpr 0x272e900 col:32 'int' FloatingToIntegral
  `-FloatingLiteral 0x272e7f8 col:32 'double' 3.00e+00
$ clang-3.8 -cc1 -ast-dump -x c++ p.c
TranslationUnitDecl 0x3300e60 invalid sloc invalid sloc
|-TypedefDecl 0x3301398 invalid sloc invalid sloc implicit
__int128_t '__int128'
|-TypedefDecl 0x33013f8 invalid sloc invalid sloc implicit
__uint128_t 'unsigned __int128'
|-TypedefDecl 0x3301718 invalid sloc invalid sloc implicit
__builtin_va_list 'struct __va_list_tag [1]'
`-VarDecl 0x33017e8 p.c:1:1, col:36 col:5 x 'int [100]' cinit
  `-InitListExpr 0x3301980 col:18, col:36 'int [100]'
|-array filler
| `-ImplicitValueInitExpr 0x3301a00 invalid sloc 'int'
|-ImplicitCastExpr 0x33019d0 col:32 'int' FloatingToIntegral
| `-FloatingLiteral 0x33018c8 col:32 'double' 3.00e+00
`-ImplicitCastExpr 0x33019e8 col:32 'int' FloatingToIntegral
  `-FloatingLiteral 0x33018c8 col:32 'double' 3.00e+00


5) if we would visit semantic form in a checker searching for implicit
cast from float to int in the C source above we'll find *two* of them,
while syntactically we have only one. This means that we should be
forced do some dirty tricks to avoid double reporting.

-- 
Abramo Bagnara

BUGSENG srl - http://bugseng.com
mailto:abramo.bagn...@bugseng.com
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r246359 - [AST] Don't crash when comparing incomplete object

2015-08-29 Thread David Majnemer via cfe-commits
Author: majnemer
Date: Sat Aug 29 03:32:55 2015
New Revision: 246359

URL: http://llvm.org/viewvc/llvm-project?rev=246359view=rev
Log:
[AST] Don't crash when comparing incomplete object

We cannot tell if an object is past-the-end if its type is incomplete.
Zero sized objects satisfy past-the-end criteria and our object might
turn out to be such an object.

This fixes PR24622.

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/Sema/const-eval.c

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=246359r1=246358r2=246359view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sat Aug 29 03:32:55 2015
@@ -6602,9 +6602,15 @@ static bool isOnePastTheEndOfCompleteObj
   !LV.getLValueDesignator().isOnePastTheEnd())
 return false;
 
+  // A pointer to an incomplete type might be past-the-end if the type's size 
is
+  // zero.  We cannot tell because the type is incomplete.
+  QualType Ty = getType(LV.getLValueBase());
+  if (Ty-isIncompleteType())
+return true;
+
   // We're a past-the-end pointer if we point to the byte after the object,
   // no matter what our type or path is.
-  auto Size = Ctx.getTypeSizeInChars(getType(LV.getLValueBase()));
+  auto Size = Ctx.getTypeSizeInChars(Ty);
   return LV.getLValueOffset() == Size;
 }
 

Modified: cfe/trunk/test/Sema/const-eval.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/const-eval.c?rev=246359r1=246358r2=246359view=diff
==
--- cfe/trunk/test/Sema/const-eval.c (original)
+++ cfe/trunk/test/Sema/const-eval.c Sat Aug 29 03:32:55 2015
@@ -133,3 +133,7 @@ EVAL_EXPR(51, 0 != (float)1e99)
 
 // PR21945
 void PR21945() { int i = (({}), 0l); }
+
+void PR24622();
+struct PR24622 {} pr24622;
+EVAL_EXPR(52, pr24622 == (void *)PR24622); // expected-error {{must have a 
constant size}}


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


Re: r246359 - [AST] Don't crash when comparing incomplete object

2015-08-29 Thread Renato Golin via cfe-commits
On 29 August 2015 at 09:32, David Majnemer via cfe-commits
cfe-commits@lists.llvm.org wrote:
 Author: majnemer
 Date: Sat Aug 29 03:32:55 2015
 New Revision: 246359

 URL: http://llvm.org/viewvc/llvm-project?rev=246359view=rev
 Log:
 [AST] Don't crash when comparing incomplete object

 We cannot tell if an object is past-the-end if its type is incomplete.
 Zero sized objects satisfy past-the-end criteria and our object might
 turn out to be such an object.

Hi David,

With all the bots broken by other reasons, just making sure you're
aware of this:

http://lab.llvm.org:8011/builders/clang-cmake-aarch64-full/builds/96

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


Re: [PATCH] D12466: Fix empty -L Path on OSX hosts

2015-08-29 Thread Yaron Keren via cfe-commits
yaron.keren added a comment.

I have never used OSX, Try to add one of the Apple clang developers as 
reviewers, they know more than me about OSX.

My guess there should not be empty paths in  in TC.getFilePaths(). That patch 
seems only to sidestep the issue which will probably surface in other places. 
Can you debug why this empty path is created and fix that?


Repository:
  rL LLVM

http://reviews.llvm.org/D12466



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


[PATCH] D12471: Correct documentation for numSelectorArgs matcher

2015-08-29 Thread Dave Lee via cfe-commits
kastiglione created this revision.
kastiglione added a reviewer: modocache.
kastiglione added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

Currently, the documentation for `numSelectorArgs` includes an incorrect 
example. It shows a case where an argument of 1 will match a property getter, 
but a getter will be matched only when `N == 0`.

This diff corrects the documentation.

http://reviews.llvm.org/D12471

Files:
  include/clang/ASTMatchers/ASTMatchers.h

Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -2139,7 +2139,7 @@
 
 /// \brief Matches when the selector has the specified number of arguments
 ///
-///  matcher = objCMessageExpr(numSelectorArgs(1));
+///  matcher = objCMessageExpr(numSelectorArgs(0));
 ///  matches self.bodyView in the code below
 ///
 ///  matcher = objCMessageExpr(numSelectorArgs(2));


Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -2139,7 +2139,7 @@
 
 /// \brief Matches when the selector has the specified number of arguments
 ///
-///  matcher = objCMessageExpr(numSelectorArgs(1));
+///  matcher = objCMessageExpr(numSelectorArgs(0));
 ///  matches self.bodyView in the code below
 ///
 ///  matcher = objCMessageExpr(numSelectorArgs(2));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits