[clang] [clang] Emit bad shift warnings (PR #70307)

2024-07-15 Thread Stephan Bergmann via cfe-commits

stbergmann wrote:

> That is intentional; `strlen` is not a valid constant expression in C, and so 
> that is technically a VLA, except we have an extension to fold it back into a 
> constant.

Thanks for confirming.  From the commit message and the changes to 
`clang/docs/ReleaseNotes.rst` it just didn't look like this newly emitted 
warning was intended by the commit.  But now I notice the changes to 
`clang/test/Sema/builtins.c` that do acknowledge this newly emitted warning.

https://github.com/llvm/llvm-project/pull/70307
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Emit bad shift warnings (PR #70307)

2024-07-15 Thread Stephan Bergmann via cfe-commits

stbergmann wrote:

This started to cause
```
$ cat test.c
#include 
void f(void) {
char a[strlen("x")];
(void) a;
}
```
```
$ clang -Wall -fsyntax-only test.c
test.c:3:12: warning: variable length array folded to constant array as an 
extension [-Wgnu-folding-constant]
3 | char a[strlen("x")];
  |^~~
1 warning generated.
```
to emit a warning, and I'm not sure that's intentional?

https://github.com/llvm/llvm-project/pull/70307
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-11 Thread Stephan Bergmann via cfe-commits

stbergmann wrote:

I think the discourse thread [Clang is overly aggressive when evaluating 
constexpr 
functions](https://discourse.llvm.org/t/clang-is-overly-aggressive-when-evaluating-constexpr-functions/67006)
 is relevant here.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-10 Thread Stephan Bergmann via cfe-commits

stbergmann wrote:

This change started to cause
```
$ cat test.cc
template struct P {
~P() { p->f(); }
T * p;
};
struct X;
struct B { virtual ~B(); };
struct S: B { P x; };
```
```
$ clang++ -std=c++23 -fsyntax-only test.cc
test.cc:2:13: error: member access into incomplete type 'X'
2 | ~P() { p->f(); }
  | ^
test.cc:7:8: note: in instantiation of member function 'P::~P' requested here
7 | struct S: B { P x; };
  |^
test.cc:5:8: note: forward declaration of 'X'
5 | struct X;
  |^
1 error generated.
```
to fail, which I think is not intentional?

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Fix missing warning when comparing mismatched enums in … (PR #81418)

2024-03-03 Thread Stephan Bergmann via cfe-commits

stbergmann wrote:

This change started to break the following C++26 code:
```
$ cat test.cc
enum E1 { E11 };
enum E2 {
E21 = E11,
E22 = 1,
E23 = E21 + E22
};
```
```
clang++ -std=c++26 -fsyntax-only test.cc
test.cc:5:15: error: invalid arithmetic between different enumeration types 
('E1' and 'E2')
5 | E23 = E21 + E22
  |   ~~~ ^ ~~~
1 error generated.
```
as within the definition of enum `E2` with unfixed underlying type, while the 
type of `E21` is indeed `E1`, the type of `E22` there is `int` rather than `E2` 
(see [dcl.enum]/5.1 "If an initializer is specified for an enumerator, the 
constant-expression shall be an integral constant expression (7.7). If the 
expression has unscoped enumeration type, the enumerator has the underlying 
type of that enumeration type, otherwise it has the same type as the 
expression.")

https://github.com/llvm/llvm-project/pull/81418
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d812488 - Call MarkVirtualMembersReferenced on an actual class definition

2023-03-02 Thread Stephan Bergmann via cfe-commits

Author: Stephan Bergmann
Date: 2023-03-02T15:50:12+01:00
New Revision: d812488d3c54c07f24d4bef79e329f17e7f19c3b

URL: 
https://github.com/llvm/llvm-project/commit/d812488d3c54c07f24d4bef79e329f17e7f19c3b
DIFF: 
https://github.com/llvm/llvm-project/commit/d812488d3c54c07f24d4bef79e329f17e7f19c3b.diff

LOG: Call MarkVirtualMembersReferenced on an actual class definition

...rather than on potentially just a declaration.

Without the fix, the newly added clang/test/SemaCXX/warn-undefined-internal.cpp
failed with

> error: 'warning' diagnostics expected but not seen:
>   File 
> /home/sbergman/github.com/llvm/llvm-project/clang/test/SemaCXX/warn-undefined-internal.cpp
>  Line 12 (directive at 
> /home/sbergman/github.com/llvm/llvm-project/clang/test/SemaCXX/warn-undefined-internal.cpp:13):
>  function 'test2()::S::f' has internal linkage but is not defined
> error: 'note' diagnostics expected but not seen:
>   File 
> /home/sbergman/github.com/llvm/llvm-project/clang/test/SemaCXX/warn-undefined-internal.cpp
>  Line 14 (directive at 
> /home/sbergman/github.com/llvm/llvm-project/clang/test/SemaCXX/warn-undefined-internal.cpp:15):
>  used here

(I ran into this when two LibreOffice Clang plugins produced false positive
warnings, as they relied on Decl::isReferenced() returning true for such virtual
member functions of local classes.)

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

Added: 
clang/test/SemaCXX/warn-undefined-internal.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDeclCXX.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7dc80a43e5eb..23a3bbd58b96 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -155,6 +155,8 @@ Improvements to Clang's diagnostics
 - Clang now warns by default for C++20 and later about deprecated capture of
   ``this`` with a capture default of ``=``. This warning can be disabled with
   ``-Wno-deprecated-this-capture``.
+- Clang had failed to emit some ``-Wundefined-internal`` for members of a local
+  class if that class was first introduced with a forward declaration.
 
 Bug Fixes in This Version
 -

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index ec85d503ccf8..cf74fcbc4cfa 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17975,7 +17975,7 @@ void Sema::MarkVTableUsed(SourceLocation Loc, 
CXXRecordDecl *Class,
   // immediately. For all other classes, we mark their virtual members
   // at the end of the translation unit.
   if (Class->isLocalClass())
-MarkVirtualMembersReferenced(Loc, Class);
+MarkVirtualMembersReferenced(Loc, Class->getDefinition());
   else
 VTableUses.push_back(std::make_pair(Class, Loc));
 }

diff  --git a/clang/test/SemaCXX/warn-undefined-internal.cpp 
b/clang/test/SemaCXX/warn-undefined-internal.cpp
new file mode 100644
index ..81dbbba1d001
--- /dev/null
+++ b/clang/test/SemaCXX/warn-undefined-internal.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -Wundefined-internal -verify %s
+
+void test1() {
+  struct S { virtual void f(); };
+  // expected-warning@-1{{function 'test1()::S::f' has internal linkage but is 
not defined}}
+  S s;
+  // expected-note@-1{{used here}}
+}
+
+void test2() {
+  struct S;
+  struct S { virtual void f(); };
+  // expected-warning@-1{{function 'test2()::S::f' has internal linkage but is 
not defined}}
+  S s;
+  // expected-note@-1{{used here}}
+}



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


[clang] 4996e3f - [test] Check for more -fsanitize=array-bounds behavior

2022-07-05 Thread Stephan Bergmann via cfe-commits

Author: Stephan Bergmann
Date: 2022-07-05T08:12:53+02:00
New Revision: 4996e3f68315f9ee7f43f2de9d368ab9979080db

URL: 
https://github.com/llvm/llvm-project/commit/4996e3f68315f9ee7f43f2de9d368ab9979080db
DIFF: 
https://github.com/llvm/llvm-project/commit/4996e3f68315f9ee7f43f2de9d368ab9979080db.diff

LOG: [test] Check for more -fsanitize=array-bounds behavior

...that had temporarily regressed with (since reverted)

"[clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible
arrays", and had then been seen to cause issues in the wild:

For one, the HarfBuzz project has various "fake" flexible array members of the
form

> TypearrayZ[HB_VAR_ARRAY];

in , where
HB_VAR_ARRAY is a macro defined as

> #ifndef HB_VAR_ARRAY
> #define HB_VAR_ARRAY 1
> #endif

in .

For another, the Firebird project in
 uses
a trailing member

> srq lhb_hash[1];// Hash table

as a "fake" flexible array, but declared in a

> struct lhb : public Firebird::MemoryHeader

that is not a standard-layout class (because the Firebird::MemoryHeader base
class also declares non-static data members).

(The second case is specific to C++.  Extend the test setup so that all the
other tests are now run for both C and C++, just in case the behavior could ever
start to diverge for those two languages.)

A third case where -fsanitize=array-bounds differs from -Warray-bounds (and
which is also specific to C++, but which doesn't appear to have been encountered
in the wild) is when the "fake" flexible array member's size results from
template argument substitution.

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

Added: 


Modified: 
clang/test/CodeGen/bounds-checking-fam.c

Removed: 




diff  --git a/clang/test/CodeGen/bounds-checking-fam.c 
b/clang/test/CodeGen/bounds-checking-fam.c
index 8da580fe06464..9d7994cee0948 100644
--- a/clang/test/CodeGen/bounds-checking-fam.c
+++ b/clang/test/CodeGen/bounds-checking-fam.c
@@ -1,5 +1,6 @@
 // REQUIRES: x86-registered-target
 // RUN: %clang_cc1 -emit-llvm -triple x86_64 -fsanitize=array-bounds %s -o - | 
FileCheck %s --check-prefixes=CHECK,CHECK-STRICT-0
+// RUN: %clang_cc1 -emit-llvm -triple x86_64 -fsanitize=array-bounds -x c++ %s 
-o - | FileCheck %s --check-prefixes=CHECK,CHECK-STRICT-0,CXX,CXX-STRICT-0
 
 /// Before flexible array member was added to C99, many projects use a
 /// one-element array as the last emember of a structure as an alternative.
@@ -15,20 +16,58 @@ struct Three {
   int a[3];
 };
 
-// CHECK-LABEL: define {{.*}} @test_one(
+// CHECK-LABEL: define {{.*}} @{{.*}}test_one{{.*}}(
 int test_one(struct One *p, int i) {
   // CHECK-STRICT-0-NOT: @__ubsan
   return p->a[i] + (p->a)[i];
 }
 
-// CHECK-LABEL: define {{.*}} @test_two(
+// CHECK-LABEL: define {{.*}} @{{.*}}test_two{{.*}}(
 int test_two(struct Two *p, int i) {
   // CHECK-STRICT-0: call void @__ubsan_handle_out_of_bounds_abort(
   return p->a[i] + (p->a)[i];
 }
 
-// CHECK-LABEL: define {{.*}} @test_three(
+// CHECK-LABEL: define {{.*}} @{{.*}}test_three{{.*}}(
 int test_three(struct Three *p, int i) {
   // CHECK-STRICT-0: call void @__ubsan_handle_out_of_bounds_abort(
   return p->a[i] + (p->a)[i];
 }
+
+#define FLEXIBLE 1
+struct Macro {
+  int a[FLEXIBLE];
+};
+
+// CHECK-LABEL: define {{.*}} @{{.*}}test_macro{{.*}}(
+int test_macro(struct Macro *p, int i) {
+  // CHECK-STRICT-0-NOT: @__ubsan
+  return p->a[i] + (p->a)[i];
+}
+
+#if defined __cplusplus
+
+struct Base {
+  int b;
+};
+struct NoStandardLayout : Base {
+  int a[1];
+};
+
+// CXX-LABEL: define {{.*}} @{{.*}}test_nostandardlayout{{.*}}(
+int test_nostandardlayout(NoStandardLayout *p, int i) {
+  // CXX-STRICT-0-NOT: @__ubsan
+  return p->a[i] + (p->a)[i];
+}
+
+template struct Template {
+  int a[N];
+};
+
+// CXX-LABEL: define {{.*}} @{{.*}}test_template{{.*}}(
+int test_template(Template<1> *p, int i) {
+  // CXX-STRICT-0-NOT: @__ubsan
+  return p->a[i] + (p->a)[i];
+}
+
+#endif



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


[clang] b5b9489 - Only consider built-in compound assignment operators for -Wunused-but-set-*

2021-06-14 Thread Stephan Bergmann via cfe-commits

Author: Stephan Bergmann
Date: 2021-06-14T08:04:03+02:00
New Revision: b5b9489b2415dc48c39d4d7d4bae6197dc499f38

URL: 
https://github.com/llvm/llvm-project/commit/b5b9489b2415dc48c39d4d7d4bae6197dc499f38
DIFF: 
https://github.com/llvm/llvm-project/commit/b5b9489b2415dc48c39d4d7d4bae6197dc499f38.diff

LOG: Only consider built-in compound assignment operators for -Wunused-but-set-*

At least LibreOffice has, for mainly historic reasons that would be hard to
change now, a class Any with an overloaded operator >>= that semantically does
not assign to the LHS but rather extracts into the (by-reference) RHS.  Which
thus caused false positive -Wunused-but-set-parameter and
-Wunused-but-set-variable after those have been introduced recently.

This change is more conservative about the assumed semantics of overloaded
operators, excluding compound assignment operators but keeping plain operator =
ones.  At least for LibreOffice, that strikes a good balance of not producing
false positives but still finding lots of true ones.

(The change to the BinaryOperator case in MaybeDecrementCount is necessary
because e.g. the template f4 test code in warn-unused-but-set-variables-cpp.cpp
turns the += into a BinaryOperator.)

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

Added: 


Modified: 
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 20925f95f18e..a57c5ad198e1 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -7808,11 +7808,15 @@ static void MaybeDecrementCount(
 Expr *E, llvm::DenseMap ) {
   DeclRefExpr *LHS = nullptr;
   if (BinaryOperator *BO = dyn_cast(E)) {
-if (!BO->isAssignmentOp())
+if (BO->getLHS()->getType()->isDependentType() ||
+BO->getRHS()->getType()->isDependentType()) {
+  if (BO->getOpcode() != BO_Assign)
+return;
+} else if (!BO->isAssignmentOp())
   return;
 LHS = dyn_cast(BO->getLHS());
   } else if (CXXOperatorCallExpr *COCE = dyn_cast(E)) {
-if (!COCE->isAssignmentOp())
+if (COCE->getOperator() != OO_Equal)
   return;
 LHS = dyn_cast(COCE->getArg(0));
   }

diff  --git a/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp 
b/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
index aa598408dee5..400e9d7681b3 100644
--- a/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
+++ b/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
@@ -6,6 +6,7 @@ struct S {
 
 struct __attribute__((warn_unused)) SWarnUnused {
   int j;
+  void operator +=(int);
 };
 
 int f0() {
@@ -48,3 +49,16 @@ void f2() {
   char a[x];
   char b[y];
 }
+
+void f3(int n) {
+  // Don't warn for overloaded compound assignment operators.
+  SWarnUnused swu;
+  swu += n;
+}
+
+template void f4(T n) {
+  // Don't warn for (potentially) overloaded compound assignment operators in
+  // template code.
+  SWarnUnused swu;
+  swu += n;
+}



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


[clang] 215ed9b - Adapt CastExpr::getSubExprAsWritten to ConstantExpr

2021-01-12 Thread Stephan Bergmann via cfe-commits

Author: Stephan Bergmann
Date: 2021-01-12T09:41:03+01:00
New Revision: 215ed9b33ccbe9858aeb65b357bdcff354be

URL: 
https://github.com/llvm/llvm-project/commit/215ed9b33ccbe9858aeb65b357bdcff354be
DIFF: 
https://github.com/llvm/llvm-project/commit/215ed9b33ccbe9858aeb65b357bdcff354be.diff

LOG: Adapt CastExpr::getSubExprAsWritten to ConstantExpr

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

Added: 


Modified: 
clang/lib/AST/Expr.cpp
clang/unittests/Tooling/CastExprTest.cpp

Removed: 




diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index a274bf37a407..94b6adf489fe 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1765,7 +1765,7 @@ Expr *CastExpr::getSubExprAsWritten() {
 // subexpression describing the call; strip it off.
 if (E->getCastKind() == CK_ConstructorConversion)
   SubExpr =
-skipImplicitTemporary(cast(SubExpr)->getArg(0));
+
skipImplicitTemporary(cast(SubExpr->IgnoreImplicit())->getArg(0));
 else if (E->getCastKind() == CK_UserDefinedConversion) {
   assert((isa(SubExpr) ||
   isa(SubExpr)) &&

diff  --git a/clang/unittests/Tooling/CastExprTest.cpp 
b/clang/unittests/Tooling/CastExprTest.cpp
index a9e78d2155b4..cda963a6a897 100644
--- a/clang/unittests/Tooling/CastExprTest.cpp
+++ b/clang/unittests/Tooling/CastExprTest.cpp
@@ -34,4 +34,24 @@ TEST(CastExprTest, 
GetSubExprAsWrittenThroughMaterializedTemporary) {
 "S1 f(S2 s) { return static_cast(s); }\n");
 }
 
+// Verify that getSubExprAsWritten looks through a ConstantExpr in a scenario
+// like
+//
+//   CXXFunctionalCastExpr functional cast to struct S 
+//   `-ConstantExpr 'S'
+// |-value: Struct
+// `-CXXConstructExpr 'S' 'void (int)'
+//   `-IntegerLiteral 'int' 0
+TEST(CastExprTest, GetSubExprAsWrittenThroughConstantExpr) {
+CastExprVisitor Visitor;
+Visitor.OnExplicitCast = [](ExplicitCastExpr *Expr) {
+  auto *Sub = Expr->getSubExprAsWritten();
+  EXPECT_TRUE(isa(Sub))
+<< "Expected IntegerLiteral, but saw " << Sub->getStmtClassName();
+};
+Visitor.runOver("struct S { consteval S(int) {} };\n"
+"S f() { return S(0); }\n",
+CastExprVisitor::Lang_CXX2a);
+}
+
 }



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


[clang] 7a5184e - [scan-build] Fix clang++ pathname again

2020-11-02 Thread Stephan Bergmann via cfe-commits

Author: Stephan Bergmann
Date: 2020-11-03T08:17:17+01:00
New Revision: 7a5184ed951ad38d652d7b3c339f4c6ae7842eeb

URL: 
https://github.com/llvm/llvm-project/commit/7a5184ed951ad38d652d7b3c339f4c6ae7842eeb
DIFF: 
https://github.com/llvm/llvm-project/commit/7a5184ed951ad38d652d7b3c339f4c6ae7842eeb.diff

LOG: [scan-build] Fix clang++ pathname again

e00629f777d9d62875730f40d266727df300dbb2 "[scan-build] Fix clang++ pathname" had
removed the -MAJOR.MINOR suffix, but since presumably LLVM 7 the suffix is only
-MAJOR, so ClangCXX (i.e., the CLANG_CXX environment variable passed to
clang/tools/scan-build/libexec/ccc-analyzer) now contained a non-existing
/path/to/clang-12++ (which apparently went largely unnoticed as
clang/tools/scan-build/libexec/ccc-analyzer falls back to just 'clang++' if the
executable denoted by CLANG_CXX does not exist).

For the new clang/test/Analysis/scan-build/cxx-name.test to be effective,
%scan-build must now take care to pass the clang executable's resolved pathname
(i.e., ending in .../clang-MAJOR rather than just .../clang) to --use-analyzer.

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

Added: 
clang/test/Analysis/scan-build/cxx-name.test

Modified: 
clang/test/Analysis/scan-build/lit.local.cfg
clang/tools/scan-build/bin/scan-build

Removed: 




diff  --git a/clang/test/Analysis/scan-build/cxx-name.test 
b/clang/test/Analysis/scan-build/cxx-name.test
new file mode 100644
index ..483762d619d1
--- /dev/null
+++ b/clang/test/Analysis/scan-build/cxx-name.test
@@ -0,0 +1,9 @@
+REQUIRES: shell
+
+RUN: %scan-build sh -c 'echo "CLANG_CXX=/$(basename "$CLANG_CXX")/"' | 
FileCheck %s
+
+Check that scan-build sets the CLANG_CXX environment variable (meant to be
+consumed by ccc-analyzer) to an appropriate pathname for the clang++ 
executable,
+derived from the pathname of the clang executable:
+
+CHECK: CLANG_CXX=/clang++{{(\.exe)?}}/

diff  --git a/clang/test/Analysis/scan-build/lit.local.cfg 
b/clang/test/Analysis/scan-build/lit.local.cfg
index b4e097d4bab9..09ed92171478 100644
--- a/clang/test/Analysis/scan-build/lit.local.cfg
+++ b/clang/test/Analysis/scan-build/lit.local.cfg
@@ -15,4 +15,4 @@ config.substitutions.append(('%scan-build',
 'tools',
 'scan-build',
 'bin')),
- config.clang)))
+ os.path.realpath(config.clang

diff  --git a/clang/tools/scan-build/bin/scan-build 
b/clang/tools/scan-build/bin/scan-build
index aed8c417b6cc..645f5507b6fa 100755
--- a/clang/tools/scan-build/bin/scan-build
+++ b/clang/tools/scan-build/bin/scan-build
@@ -1925,7 +1925,7 @@ if ($Clang !~ /\+\+(\.exe)?$/) {
 $ClangCXX =~ s/.exe$/++.exe/;
   }
   else {
-$ClangCXX =~ s/\-\d+\.\d+$//;
+$ClangCXX =~ s/\-\d+(\.\d+)?$//;
 $ClangCXX .= "++";
   }
 }



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


Re: r374135 - [c++20] P1152R4: warn on any simple-assignment to a volatile lvalue

2019-10-17 Thread Stephan Bergmann via cfe-commits

On 09/10/2019 04:04, Richard Smith via cfe-commits wrote:

Author: rsmith
Date: Tue Oct  8 19:04:54 2019
New Revision: 374135

URL: http://llvm.org/viewvc/llvm-project?rev=374135=rev
Log:
[c++20] P1152R4: warn on any simple-assignment to a volatile lvalue
whose value is not ignored.

We don't warn on all the cases that are deprecated: specifically, we
choose to not warn for now if there are parentheses around the
assignment but its value is not actually used. This seems like a more
defensible rule, particularly for cases like sizeof(v = a), where the
parens are part of the operand rather than the sizeof syntax.

Modified:
 cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
 cfe/trunk/include/clang/Sema/Sema.h
 cfe/trunk/lib/Sema/SemaExpr.cpp
 cfe/trunk/lib/Sema/SemaExprCXX.cpp
 cfe/trunk/test/SemaCXX/deprecated.cpp
 cfe/trunk/www/cxx_status.html


Oh, I should probably have commented here on the mailing list rather 
than at 
:


I assume the scenario at 
 "Avoid C++20 
deprecated assignment to volatile",


  (void) (0 ? *(location) = (result) : 0);

where *(location) is of (non-class) volatile type, is a true positive 
that we indeed want to warn about?


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


r375104 - Include leading attributes in DeclStmt's SourceRange

2019-10-17 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Thu Oct 17 04:20:21 2019
New Revision: 375104

URL: http://llvm.org/viewvc/llvm-project?rev=375104=rev
Log:
Include leading attributes in DeclStmt's SourceRange

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

Modified:
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/test/AST/sourceranges.cpp

Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=375104=375103=375104=diff
==
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Thu Oct 17 04:20:21 2019
@@ -220,6 +220,8 @@ Retry:
 Decl =
 ParseDeclaration(DeclaratorContext::BlockContext, DeclEnd, Attrs);
   }
+  if (Attrs.Range.getBegin().isValid())
+DeclStart = Attrs.Range.getBegin();
   return Actions.ActOnDeclStmt(Decl, DeclStart, DeclEnd);
 }
 

Modified: cfe/trunk/test/AST/sourceranges.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/sourceranges.cpp?rev=375104=375103=375104=diff
==
--- cfe/trunk/test/AST/sourceranges.cpp (original)
+++ cfe/trunk/test/AST/sourceranges.cpp Thu Oct 17 04:20:21 2019
@@ -92,6 +92,22 @@ struct map {
 
 }; // namespace std
 
+// CHECK: NamespaceDecl {{.*}} attributed_decl
+namespace attributed_decl {
+  void f() {
+// CHECK: DeclStmt {{.*}} 
+[[maybe_unused]] int i1;
+// CHECK: DeclStmt {{.*}} 
+__attribute__((unused)) int i2;
+// CHECK: DeclStmt {{.*}} 
+int __attribute__((unused)) i3;
+// CHECK: DeclStmt {{.*}} <:{{.*}}, {{.*}}:[[@LINE+1]]:40>
+__declspec(dllexport) extern int i4;
+// CHECK: DeclStmt {{.*}} 
+extern int __declspec(dllexport) i5;
+  }
+}
+
 #if __cplusplus >= 201703L
 // CHECK-1Z: FunctionDecl {{.*}} construct_with_init_list
 std::map construct_with_init_list() {


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


r369345 - Rudimentary support for Doxygen \retval command

2019-08-20 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Tue Aug 20 01:36:21 2019
New Revision: 369345

URL: http://llvm.org/viewvc/llvm-project?rev=369345=rev
Log:
Rudimentary support for Doxygen \retval command

...so that at least a preceding \param etc. that lacks a description gets a
-Wdocumentation warning (instead of erroneously treating the \retval ... text as
its paragraph).

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

Modified:
cfe/trunk/include/clang/AST/CommentCommands.td
cfe/trunk/test/Sema/warn-documentation.cpp

Modified: cfe/trunk/include/clang/AST/CommentCommands.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentCommands.td?rev=369345=369344=369345=diff
==
--- cfe/trunk/include/clang/AST/CommentCommands.td (original)
+++ cfe/trunk/include/clang/AST/CommentCommands.td Tue Aug 20 01:36:21 2019
@@ -139,6 +139,7 @@ def Post   : BlockCommand<"post">;
 def Pre: BlockCommand<"pre">;
 def Remark : BlockCommand<"remark">;
 def Remarks: BlockCommand<"remarks">;
+def Retval : BlockCommand<"retval">;
 def Sa : BlockCommand<"sa">;
 def See: BlockCommand<"see">;
 def Since  : BlockCommand<"since">;

Modified: cfe/trunk/test/Sema/warn-documentation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-documentation.cpp?rev=369345=369344=369345=diff
==
--- cfe/trunk/test/Sema/warn-documentation.cpp (original)
+++ cfe/trunk/test/Sema/warn-documentation.cpp Tue Aug 20 01:36:21 2019
@@ -288,6 +288,11 @@ int test_param21(int a);
 /// \param x2 Ccc.
 int test_param22(int x1, int x2, int x3);
 
+// expected-warning@+1 {{empty paragraph passed to '\param' command}}
+/// \param a
+/// \retval 0 Blah blah.
+int test_param23(int a);
+
 //===---
 // Test that we treat typedefs to some non-function types as functions for the
 // purposes of documentation comment parsing.


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


r366186 - Finish "Adapt -fsanitize=function to SANITIZER_NON_UNIQUE_TYPEINFO"

2019-07-16 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Mon Jul 15 23:23:27 2019
New Revision: 366186

URL: http://llvm.org/viewvc/llvm-project?rev=366186=rev
Log:
Finish "Adapt -fsanitize=function to SANITIZER_NON_UNIQUE_TYPEINFO"

i.e., recent 5745eccef54ddd3caca278d1d292a88b2281528b:

* Bump the function_type_mismatch handler version, as its signature has changed.

* The function_type_mismatch handler can return successfully now, so
  SanitizerKind::Function must be AlwaysRecoverable (like for
  SanitizerKind::Vptr).

* But the minimal runtime would still unconditionally treat a call to the
  function_type_mismatch handler as failure, so disallow -fsanitize=function in
  combination with -fsanitize-minimal-runtime (like it was already done for
  -fsanitize=vptr).

* Add tests.

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

Added:
cfe/trunk/test/CodeGen/ubsan-function.cpp
Modified:
cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/test/Driver/fsanitize.c

Modified: cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UndefinedBehaviorSanitizer.rst?rev=366186=366185=366186=diff
==
--- cfe/trunk/docs/UndefinedBehaviorSanitizer.rst (original)
+++ cfe/trunk/docs/UndefinedBehaviorSanitizer.rst Mon Jul 15 23:23:27 2019
@@ -205,8 +205,8 @@ Minimal Runtime
 
 There is a minimal UBSan runtime available suitable for use in production
 environments. This runtime has a small attack surface. It only provides very
-basic issue logging and deduplication, and does not support ``-fsanitize=vptr``
-checking.
+basic issue logging and deduplication, and does not support
+``-fsanitize=function`` and ``-fsanitize=vptr`` checking.
 
 To use the minimal runtime, add ``-fsanitize-minimal-runtime`` to the clang
 command line options. For example, if you're used to compiling with

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=366186=366185=366186=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Jul 15 23:23:27 2019
@@ -2927,7 +2927,7 @@ enum class CheckRecoverableKind {
 
 static CheckRecoverableKind getRecoverableKind(SanitizerMask Kind) {
   assert(Kind.countPopulation() == 1);
-  if (Kind == SanitizerKind::Vptr)
+  if (Kind == SanitizerKind::Function || Kind == SanitizerKind::Vptr)
 return CheckRecoverableKind::AlwaysRecoverable;
   else if (Kind == SanitizerKind::Return || Kind == SanitizerKind::Unreachable)
 return CheckRecoverableKind::Unrecoverable;

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=366186=366185=366186=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Mon Jul 15 23:23:27 2019
@@ -114,7 +114,7 @@ enum TypeEvaluationKind {
   SANITIZER_CHECK(DivremOverflow, divrem_overflow, 0)  
\
   SANITIZER_CHECK(DynamicTypeCacheMiss, dynamic_type_cache_miss, 0)
\
   SANITIZER_CHECK(FloatCastOverflow, float_cast_overflow, 0)   
\
-  SANITIZER_CHECK(FunctionTypeMismatch, function_type_mismatch, 0) 
\
+  SANITIZER_CHECK(FunctionTypeMismatch, function_type_mismatch, 1) 
\
   SANITIZER_CHECK(ImplicitConversion, implicit_conversion, 0)  
\
   SANITIZER_CHECK(InvalidBuiltin, invalid_builtin, 0)  
\
   SANITIZER_CHECK(LoadInvalidValue, load_invalid_value, 0) 
\

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=366186=366185=366186=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Mon Jul 15 23:23:27 2019
@@ -31,7 +31,8 @@ static const SanitizerMask NeedsUbsanRt
 static const SanitizerMask NeedsUbsanCxxRt =
 SanitizerKind::Vptr | SanitizerKind::CFI;
 static const SanitizerMask NotAllowedWithTrap = SanitizerKind::Vptr;
-static const SanitizerMask NotAllowedWithMinimalRuntime = SanitizerKind::Vptr;
+static const SanitizerMask NotAllowedWithMinimalRuntime =
+SanitizerKind::Function | SanitizerKind::Vptr;
 static const SanitizerMask RequiresPIE =
 SanitizerKind::DataFlow | SanitizerKind::HWAddress | SanitizerKind::Scudo;
 static const SanitizerMask NeedsUnwindTables =

Added: cfe/trunk/test/CodeGen/ubsan-function.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ubsan-function.cpp?rev=366186=auto

Re: r361329 - [c++20] P1330R0: permit simple-assignments that change the active member

2019-05-30 Thread Stephan Bergmann via cfe-commits

On 22/05/2019 01:15, Richard Smith via cfe-commits wrote:

Author: rsmith
Date: Tue May 21 16:15:20 2019
New Revision: 361329

URL: http://llvm.org/viewvc/llvm-project?rev=361329=rev
Log:
[c++20] P1330R0: permit simple-assignments that change the active member
of a union within constant expression evaluation.

[...]

--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue May 21 16:15:20 2019

[...]> @@ -4888,6 +4916,159 @@ static bool HandleDynamicCast(EvalInfo &
[...]

+/// Handle a builtin simple-assignment or a call to a trivial assignment
+/// operator whose left-hand side might involve a union member access. If it
+/// does, implicitly start the lifetime of any accessed union elements per
+/// C++20 [class.union]5.
+static bool HandleUnionActiveMemberChange(EvalInfo , const Expr *LHSExpr,
+  const LValue ) {
+  if (LHS.InvalidBase || LHS.Designator.Invalid)
+return false;
+
+  llvm::SmallVector, 4> UnionPathLengths;
+  // C++ [class.union]p5:
+  //   define the set S(E) of subexpressions of E as follows:
+  const Expr *E = LHSExpr;
+  unsigned PathLength = LHS.Designator.Entries.size();
+  while (E) {
+//   -- If E is of the form A.B, S(E) contains the elements of S(A)...
+if (auto *ME = dyn_cast(E)) {
+  auto *FD = dyn_cast(ME->getMemberDecl());
+  if (!FD)
+break;
+
+  //... and also contains A.B if B names a union member
+  if (FD->getParent()->isUnion())
+UnionPathLengths.push_back({PathLength - 1, FD});
+
+  E = ME->getBase();
+  --PathLength;
+  assert(declaresSameEntity(FD,
+LHS.Designator.Entries[PathLength]
+.getAsBaseOrMember().getPointer()));
+
+  //   -- If E is of the form A[B] and is interpreted as a built-in array
+  //  subscripting operator, S(E) is [S(the array operand, if any)].
+} else if (auto *ASE = dyn_cast(E)) {
+  // Step over an ArrayToPointerDecay implicit cast.
+  auto *Base = ASE->getBase()->IgnoreImplicit();
+  if (!Base->getType()->isArrayType())
+break;
+
+  E = Base;
+  --PathLength;
+
+} else if (auto *ICE = dyn_cast(E)) {
+  // Step over a derived-to-base conversion.
+  if (ICE->getCastKind() == CK_NoOp)
+continue;
+  if (ICE->getCastKind() != CK_DerivedToBase &&
+  ICE->getCastKind() != CK_UncheckedDerivedToBase)
+break;
+  for (const CXXBaseSpecifier *Elt : ICE->path()) {
+--PathLength;
+assert(declaresSameEntity(Elt->getType()->getAsCXXRecordDecl(),
+  LHS.Designator.Entries[PathLength]
+  .getAsBaseOrMember().getPointer()));


the above assert fires for the below test.cc with `clang++ -std=c++2a 
-fsyntax-only test.cc`:



struct S1 { int n; };
struct S2: S1 {};
struct S3: S2 {};
void f() {
 S3 s;
 s.n = 0;
}

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


Re: r360308 - [c++20] Implement P0846R0: allow (ADL-only) calls to template-ids whose

2019-05-16 Thread Stephan Bergmann via cfe-commits

On 15/05/2019 18:16, Stephan Bergmann wrote:

The below commit started to cause the following failure:


...and which apparently got fixed in the meantime, presumably by 
 
"Make tentative parsing to detect template-argument-lists less aggressive"

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


Re: r360308 - [c++20] Implement P0846R0: allow (ADL-only) calls to template-ids whose

2019-05-15 Thread Stephan Bergmann via cfe-commits

The below commit started to cause the following failure:


$ cat test.cc
template struct S1 { static int const n = 0; };
template struct S2 { typedef int t; };
template struct S3 { typename S2::n < 0, int>::t n; };

$ clang++ -fsyntax-only test.cc
test.cc:3:53: error: use 'template' keyword to treat 'n' as a dependent
  template name
template struct S3 { typename S2::n < 0, int>::t n; };
^
template 
test.cc:3:46: error: missing 'typename' prior to dependent type name

  'S1::S1::n<0, int>::t'
template struct S3 { typename S2::n < 0, int>::t n; };
 ^
 typename 
test.cc:3:68: error: expected '>'

template struct S3 { typename S2::n < 0, int>::t n; };
   ^
3 errors generated.



On 09/05/2019 05:31, Richard Smith via cfe-commits wrote:

Author: rsmith
Date: Wed May  8 20:31:27 2019
New Revision: 360308

URL: http://llvm.org/viewvc/llvm-project?rev=360308=rev
Log:
[c++20] Implement P0846R0: allow (ADL-only) calls to template-ids whose
template name is not visible to unqualified lookup.

In order to support this without a severe degradation in our ability to
diagnose typos in template names, this change significantly restructures
the way we handle template-id-shaped syntax for which lookup of the
template name finds nothing.

Instead of eagerly diagnosing an undeclared template name, we now form a
placeholder template-name representing a name that is known to not find
any templates. When the parser sees such a name, it attempts to
disambiguate whether we have a less-than comparison or a template-id.
Any diagnostics or typo-correction for the name are delayed until its
point of use.

The upshot should be a small improvement of our diagostic quality
overall: we now take more syntactic context into account when trying to
resolve an undeclared identifier on the left hand side of a '<'. In
fact, this works well enough that the backwards-compatible portion (for
an undeclared identifier rather than a lookup that finds functions but
no function templates) is enabled in all language modes.

Added:
 cfe/trunk/test/SemaCXX/cxx2a-adl-only-template-id.cpp
Modified:
 cfe/trunk/include/clang/AST/ASTContext.h
 cfe/trunk/include/clang/AST/DeclarationName.h
 cfe/trunk/include/clang/AST/TemplateName.h
 cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
 cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
 cfe/trunk/include/clang/Basic/TemplateKinds.h
 cfe/trunk/include/clang/Parse/Parser.h
 cfe/trunk/include/clang/Sema/Sema.h
 cfe/trunk/lib/AST/ASTContext.cpp
 cfe/trunk/lib/AST/ASTImporter.cpp
 cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
 cfe/trunk/lib/AST/ItaniumMangle.cpp
 cfe/trunk/lib/AST/ODRHash.cpp
 cfe/trunk/lib/AST/TemplateName.cpp
 cfe/trunk/lib/Parse/ParseDecl.cpp
 cfe/trunk/lib/Parse/ParseDeclCXX.cpp
 cfe/trunk/lib/Parse/ParseExprCXX.cpp
 cfe/trunk/lib/Parse/ParseTemplate.cpp
 cfe/trunk/lib/Parse/ParseTentative.cpp
 cfe/trunk/lib/Parse/Parser.cpp
 cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
 cfe/trunk/lib/Sema/SemaDecl.cpp
 cfe/trunk/lib/Sema/SemaDeclCXX.cpp
 cfe/trunk/lib/Sema/SemaExpr.cpp
 cfe/trunk/lib/Sema/SemaExprCXX.cpp
 cfe/trunk/lib/Sema/SemaOverload.cpp
 cfe/trunk/lib/Sema/SemaTemplate.cpp
 cfe/trunk/lib/Serialization/ASTReader.cpp
 cfe/trunk/lib/Serialization/ASTWriter.cpp
 cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.unqual/p3.cpp
 cfe/trunk/test/CXX/drs/dr2xx.cpp
 cfe/trunk/test/CXX/drs/dr6xx.cpp
 cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p5.cpp
 cfe/trunk/test/FixIt/typo-crash.cpp
 cfe/trunk/test/Misc/diag-template-diffing.cpp
 cfe/trunk/test/Modules/module-private.cpp
 cfe/trunk/test/Modules/submodules-merge-defs.cpp
 cfe/trunk/test/Parser/cxx-ambig-init-templ.cpp
 cfe/trunk/test/Parser/cxx-template-argument.cpp
 cfe/trunk/test/Parser/cxx-template-decl.cpp
 cfe/trunk/test/SemaCXX/alias-template.cpp
 cfe/trunk/test/SemaCXX/class.cpp
 cfe/trunk/test/SemaCXX/destructor.cpp
 cfe/trunk/test/SemaCXX/invalid-member-expr.cpp
 cfe/trunk/test/SemaCXX/typo-correction.cpp
 cfe/trunk/test/SemaTemplate/dependent-base-classes.cpp
 cfe/trunk/test/SemaTemplate/dependent-template-recover.cpp
 cfe/trunk/test/SemaTemplate/rdar9173693.cpp
 cfe/trunk/test/SemaTemplate/recovery-crash.cpp
 cfe/trunk/tools/libclang/CIndex.cpp
 cfe/trunk/www/cxx_status.html

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


r359759 - Adapt -fsanitize=function to SANITIZER_NON_UNIQUE_TYPEINFO

2019-05-02 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Wed May  1 23:40:33 2019
New Revision: 359759

URL: http://llvm.org/viewvc/llvm-project?rev=359759=rev
Log:
Adapt -fsanitize=function to SANITIZER_NON_UNIQUE_TYPEINFO

This follows up after b7692bc3e9ad2691fc07261904b88fb15f30696b "[UBSan] Fix
isDerivedFromAtOffset on iOS ARM64" fixed the RTTI comparison in
isDerivedFromAtOffset on just one platform and then
a25a2c7c9a7e1e328a5bd8274d2d86b1fadc4692 "Always compare C++ typeinfo (based on
libstdc++ implementation)" extended that fix to more platforms.

But there is another RTTI comparison for -fsanitize=function generated in
clang's CodeGenFunction::EmitCall as just a pointer comparison.  For
SANITIZER_NON_UNIQUE_TYPEINFO platforms this needs to be extended to also do
string comparison.  For that, __ubsan_handle_function_type_mismatch[_abort]
takes the two std::type_info pointers as additional parameters now, checks them
internally for potential equivalence, and returns without reporting failure if
they turn out to be equivalent after all.  (NORETURN needed to be dropped from
the _abort variant for that.)  Also these functions depend on ABI-specific RTTI
now, so needed to be moved from plain UBSAN_SOURCES (ubsan_handlers.h/cc) to
UBSAN_CXXABI_SOURCES (ubsan_handlers_cxx.h/cc), but as -fsanitize=function is
only supported in C++ mode that's not a problem.

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

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=359759=359758=359759=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed May  1 23:40:33 2019
@@ -4672,7 +4672,8 @@ RValue CodeGenFunction::EmitCall(QualTyp
   llvm::Constant *StaticData[] = 
{EmitCheckSourceLocation(E->getBeginLoc()),
   EmitCheckTypeDescriptor(CalleeType)};
   EmitCheck(std::make_pair(CalleeRTTIMatch, SanitizerKind::Function),
-SanitizerHandler::FunctionTypeMismatch, StaticData, CalleePtr);
+SanitizerHandler::FunctionTypeMismatch, StaticData,
+{CalleePtr, CalleeRTTI, FTRTTIConst});
 
   Builder.CreateBr(Cont);
   EmitBlock(Cont);


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


r353931 - Look through typedefs in getFunctionTypeWithExceptionSpec

2019-02-13 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Wed Feb 13 01:39:17 2019
New Revision: 353931

URL: http://llvm.org/viewvc/llvm-project?rev=353931=rev
Log:
Look through typedefs in getFunctionTypeWithExceptionSpec

Fixes https://bugs.llvm.org/show_bug.cgi?id=40658

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

Added:
cfe/trunk/test/AST/function-alias.cpp
Modified:
cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=353931=353930=353931=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Feb 13 01:39:17 2019
@@ -2771,7 +2771,7 @@ QualType ASTContext::getFunctionTypeWith
 
   // Anything else must be a function type. Rebuild it with the new exception
   // specification.
-  const auto *Proto = cast(Orig);
+  const auto *Proto = Orig->getAs();
   return getFunctionType(
   Proto->getReturnType(), Proto->getParamTypes(),
   Proto->getExtProtoInfo().withExceptionSpec(ESI));

Added: cfe/trunk/test/AST/function-alias.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/function-alias.cpp?rev=353931=auto
==
--- cfe/trunk/test/AST/function-alias.cpp (added)
+++ cfe/trunk/test/AST/function-alias.cpp Wed Feb 13 01:39:17 2019
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only %s
+
+// Verify that ASTContext::getFunctionTypeWithExceptionSpec (called through
+// ASTContext::hasSameFunctionTypeIgnoringExceptionSpec from
+// ExprEvaluatorBase::handleCallExpr in lib/AST/ExprConstant.cpp) does not 
crash
+// for a type alias.
+
+constexpr int f() noexcept { return 0; }
+
+using F = int();
+
+constexpr int g(F * p) { return p(); }
+
+constexpr int n = g(f);


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


Re: r343285 - [cxx2a] P0641R2: (Some) type mismatches on defaulted functions only

2018-10-04 Thread Stephan Bergmann via cfe-commits

On 04/10/2018 01:14, Richard Smith wrote:
On Tue, 2 Oct 2018 at 01:18, Stephan Bergmann via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:


On 28/09/2018 03:16, Richard Smith via cfe-commits wrote:
 > Author: rsmith
 > Date: Thu Sep 27 18:16:43 2018
 > New Revision: 343285
 >
 > URL: http://llvm.org/viewvc/llvm-project?rev=343285=rev
 > Log:
 > [cxx2a] P0641R2: (Some) type mismatches on defaulted functions only
 > render the function deleted instead of rendering the program
ill-formed.
 >
 > This change also adds an enabled-by-default warning for the case
where
 > an explicitly-defaulted special member function of a non-template
class
 > is implicitly deleted by the type checking rules. (This fires
either due
 > to this language change or due to pre-C++20 reasons for the
member being
 > implicitly deleted). I've tested this on a large codebase and
found only
 > bugs (where the program means something that's clearly different from
 > what the programmer intended), so this is enabled by default, but we
 > should revisit this if there are problems with this being enabled by
 > default.

Two questions on the new -Wdefaulted-function-deleted:

1  Do you have examples of actual bugs found by that?


What do you mean by "actual bugs"? Every instance I've seen it flag is a 
case where the code means something other than what the programmer 
intended. (Eg, every case fixed by https://reviews.llvm.org/rL343369 is 
a bug in that sense.)


You started to talk about "bugs" here :)  What I had a hard time 
figuring out is what such a case of =default would look like where the 
programmer's intend obviously had been that the function wouldn't be 
implicitly deleted.


However, it's rare that it'll flag something that leads to the runtime 
behavior of the program being different from the intent (usually you 
instead get a later compile error in cases where that would happen). It 
is possible, though -- in particular, it will flag cases where a move 
operation that you really wanted to result in a move actually results in 
a copy, and the program is silently accepted and is less efficient than 
you had expected.


Thanks, that clarifies what you meant with "bugs".


I'm running it on
the LibreOffice code base now and it feels like lots of just noise. 
For

example, I recently added explicitly defaulted decls of the four
copy/move functions to lots of classes with a virtual dtor (where the
dtor needs to be user-declared e.g. because it doesn't override any
virtual base class dtor or because it shall not be defined inline), to
silence GCC's new -Wdeprecated-copy.  If such a class then for example
has a const non-static data member, Clang's
-Wdefaulted-function-deleted
now kicks in for the assignment ops.  I'm not sure whether it's better
to have those functions explicitly deleted (which then needs revisiting
when some details of the class change), or just explicitly defaulted
and
the compiler figure out whether its deleted or not (but which now
causes
Clang to bark), or simply not user-declared at all (but which now
causes
GCC to bark).


When revising (say) a non-copyable class results in it becoming 
copyable, do you want that change to happen with no notice being given 
to the programmer? I at least don't think that it's obvious that you do.


Having gone through all the warnings in the LibreOffice code base now, 
it wasn't that many individual warnings in the end (just blown up by 
being reported over and over again in the same include files), and the 
vast majority was involving classes that already exhibit pathological 
behavior anyway, like deriving from a base that has non-deleted copy 
ctor but deleted copy assignment op, due to somewhat broken overall 
design.  (Plus some cases where members had recently been made const, 
implicitly deleting the assignment ops.)  So I'm rather neutral now on 
whether that warning is on by default.


I'm fine with turning this warning off by default (maybe moving it to 
-Wextra or similar) if there's a feeling that it's more noisy than it is 
useful.

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


Re: r343285 - [cxx2a] P0641R2: (Some) type mismatches on defaulted functions only

2018-10-02 Thread Stephan Bergmann via cfe-commits

On 28/09/2018 03:16, Richard Smith via cfe-commits wrote:

Author: rsmith
Date: Thu Sep 27 18:16:43 2018
New Revision: 343285

URL: http://llvm.org/viewvc/llvm-project?rev=343285=rev
Log:
[cxx2a] P0641R2: (Some) type mismatches on defaulted functions only
render the function deleted instead of rendering the program ill-formed.

This change also adds an enabled-by-default warning for the case where
an explicitly-defaulted special member function of a non-template class
is implicitly deleted by the type checking rules. (This fires either due
to this language change or due to pre-C++20 reasons for the member being
implicitly deleted). I've tested this on a large codebase and found only
bugs (where the program means something that's clearly different from
what the programmer intended), so this is enabled by default, but we
should revisit this if there are problems with this being enabled by
default.


Two questions on the new -Wdefaulted-function-deleted:

1  Do you have examples of actual bugs found by that?  I'm running it on 
the LibreOffice code base now and it feels like lots of just noise.  For 
example, I recently added explicitly defaulted decls of the four 
copy/move functions to lots of classes with a virtual dtor (where the 
dtor needs to be user-declared e.g. because it doesn't override any 
virtual base class dtor or because it shall not be defined inline), to 
silence GCC's new -Wdeprecated-copy.  If such a class then for example 
has a const non-static data member, Clang's -Wdefaulted-function-deleted 
now kicks in for the assignment ops.  I'm not sure whether it's better 
to have those functions explicitly deleted (which then needs revisiting 
when some details of the class change), or just explicitly defaulted and 
the compiler figure out whether its deleted or not (but which now causes 
Clang to bark), or simply not user-declared at all (but which now causes 
GCC to bark).


2  With


$ cat test.cc
struct S1 { S1 & operator =(S1 const &) = delete; };
struct S2 {
S1 m;
S2(S2 const &);
};
struct S3: S2 {
S3 & operator =(S3 const &) = default;
S3 & operator =(S3 &&) = default;
};

$ clang++ -fsyntax-only test.cc
test.cc:7:10: warning: explicitly defaulted copy assignment operator is 
implicitly deleted [-Wdefaulted-function-deleted]
S3 & operator =(S3 const &) = default;
 ^
test.cc:6:12: note: copy assignment operator of 'S3' is implicitly deleted 
because base class 'S2' has a deleted copy assignment operator
struct S3: S2 {
   ^
test.cc:3:8: note: copy assignment operator of 'S2' is implicitly deleted 
because field 'm' has a deleted copy assignment operator
S1 m;
   ^
test.cc:1:18: note: 'operator=' has been explicitly marked deleted here
struct S1 { S1 & operator =(S1 const &) = delete; };
 ^
test.cc:8:10: warning: explicitly defaulted move assignment operator is 
implicitly deleted [-Wdefaulted-function-deleted]
S3 & operator =(S3 &&) = default;
 ^
test.cc:6:12: note: move assignment operator of 'S3' is implicitly deleted 
because base class 'S2' has a deleted move assignment operator
struct S3: S2 {
   ^
test.cc:3:8: note: copy assignment operator of 'S2' is implicitly deleted 
because field 'm' has a deleted copy assignment operator
S1 m;
   ^
test.cc:1:18: note: 'operator=' has been explicitly marked deleted here
struct S1 { S1 & operator =(S1 const &) = delete; };
 ^
2 warnings generated.


the final two notes for the second warning are somewhat confusing I 
think, as there's a mismatch from the preceding note's "'S2' has a 
deleted move assignment operator" to the second-last note's "copy 
assignment operator of 'S2' is implicitly deleted".  Not sure though 
whether this is an issue specific to this new 
-Wdefaulted-function-deleted, or a general issue with generic code 
producing such "deleted because" notes.

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


r326990 - Propagate DLLAttr to friend re-declarations of member functions

2018-03-07 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Wed Mar  7 23:34:40 2018
New Revision: 326990

URL: http://llvm.org/viewvc/llvm-project?rev=326990=rev
Log:
Propagate DLLAttr to friend re-declarations of member functions

...that have already been constructed (e.g., in inner classes) while parsing the
class definition.  They would otherwise lack any DLLAttr inherited from the
class, which are only set here (called from Sema::CheckCompletedClass) after the
class definition has been parsed completely.

Differential revision: https://reviews.llvm.org/D16632

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CodeGenCXX/dllexport.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=326990=326989=326990=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Mar  7 23:34:40 2018
@@ -5685,6 +5685,21 @@ void Sema::checkClassLevelDLLAttribute(C
   cast(ClassAttr->clone(getASTContext()));
   NewAttr->setInherited(true);
   Member->addAttr(NewAttr);
+
+  if (MD) {
+// Propagate DLLAttr to friend re-declarations of MD that have already
+// been constructed.
+for (FunctionDecl *FD = MD->getMostRecentDecl(); FD;
+ FD = FD->getPreviousDecl()) {
+  if (FD->getFriendObjectKind() == Decl::FOK_None)
+continue;
+  assert(!getDLLAttr(FD) &&
+ "friend re-decl should not already have a DLLAttr");
+  NewAttr = cast(ClassAttr->clone(getASTContext()));
+  NewAttr->setInherited(true);
+  FD->addAttr(NewAttr);
+}
+  }
 }
   }
 

Modified: cfe/trunk/test/CodeGenCXX/dllexport.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllexport.cpp?rev=326990=326989=326990=diff
==
--- cfe/trunk/test/CodeGenCXX/dllexport.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllexport.cpp Wed Mar  7 23:34:40 2018
@@ -290,6 +290,16 @@ struct FuncFriend {
 __declspec(dllexport) void friend1() {}
   void friend2() {}
 
+// MSC-DAG: define dso_local dllexport void @"\01?func@Befriended@@SAXXZ"()
+// GNU-DAG: define dso_local dllexport void @_ZN10Befriended4funcEv()
+struct __declspec(dllexport) Befriended {
+  static void func();
+  struct Befriending {
+friend void Befriended::func();
+  };
+};
+void Befriended::func() {}
+
 // Implicit declarations can be redeclared with dllexport.
 // MSC-DAG: define dso_local dllexport noalias i8* 
@"\01??2@{{YAPAXI|YAPEAX_K}}@Z"(
 // GNU-DAG: define dso_local dllexport noalias i8* @_Znw{{[yj]}}(


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


r321861 - Commit new test file forgotten in previous commit

2018-01-05 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Thu Jan  4 23:59:57 2018
New Revision: 321861

URL: http://llvm.org/viewvc/llvm-project?rev=321861=rev
Log:
Commit new test file forgotten in previous commit

Added:
cfe/trunk/test/CodeGenCXX/ubsan-function-noexcept.cpp

Added: cfe/trunk/test/CodeGenCXX/ubsan-function-noexcept.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ubsan-function-noexcept.cpp?rev=321861=auto
==
--- cfe/trunk/test/CodeGenCXX/ubsan-function-noexcept.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/ubsan-function-noexcept.cpp Thu Jan  4 23:59:57 
2018
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++17 -fsanitize=function -emit-llvm -triple 
x86_64-linux-gnu %s -o - | FileCheck %s
+
+// Check that typeinfo recorded in function prolog doesn't have "Do" noexcept
+// qualifier in its mangled name.
+// CHECK: @[[RTTI:[0-9]+]] = private constant i8* bitcast ({ i8*, i8* }* 
@_ZTIFvvE to i8*)
+// CHECK: define void @_Z1fv() #{{.*}} prologue <{ i32, i32 }> <{ i32 {{.*}}, 
i32 trunc (i64 sub (i64 ptrtoint (i8** @[[RTTI]] to i64), i64 ptrtoint (void 
()* @_Z1fv to i64)) to i32) }>
+void f() noexcept {}
+
+// CHECK: define void @_Z1gPDoFvvE
+void g(void (*p)() noexcept) {
+  // Check that reference typeinfo at call site doesn't have "Do" noexcept
+  // qualifier in its mangled name, either.
+  // CHECK: icmp eq i8* %{{.*}}, bitcast ({ i8*, i8* }* @_ZTIFvvE to i8*), 
!nosanitize
+  p();
+}


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


r321859 - No -fsanitize=function warning when calling noexcept function through non-noexcept pointer in C++17

2018-01-04 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Thu Jan  4 23:57:12 2018
New Revision: 321859

URL: http://llvm.org/viewvc/llvm-project?rev=321859=rev
Log:
No -fsanitize=function warning when calling noexcept function through 
non-noexcept pointer in C++17

As discussed in the mail thread  "Calling noexcept function throug non-
noexcept pointer is undefined behavior?", such a call should not be UB.
However, Clang currently warns about it.

This change removes exception specifications from the function types recorded
for -fsanitize=function, both in the functions themselves and at the call sites.
That means that calling a non-noexcept function through a noexcept pointer will
also not be flagged as UB.  In the review of this change, that was deemed
acceptable, at least for now.  (See the "TODO" in compiler-rt
test/ubsan/TestCases/TypeCheck/Function/function.cpp.)

To remove exception specifications from types, the existing internal
ASTContext::getFunctionTypeWithExceptionSpec was made public, and some places
otherwise unrelated to this change have been adapted to call it, too.

This is the cfe part of a patch covering both cfe and compiler-rt.

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

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=321859=321858=321859=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Thu Jan  4 23:57:12 2018
@@ -1162,6 +1162,13 @@ public:
   /// \brief Change the result type of a function type once it is deduced.
   void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType);
 
+  /// Get a function type and produce the equivalent function type with the
+  /// specified exception specification. Type sugar that can be present on a
+  /// declaration of a function with an exception specification is permitted
+  /// and preserved. Other type sugar (for instance, typedefs) is not.
+  QualType getFunctionTypeWithExceptionSpec(
+  QualType Orig, const FunctionProtoType::ExceptionSpecInfo );
+
   /// \brief Determine whether two function types are the same, ignoring
   /// exception specifications in cases where they're part of the type.
   bool hasSameFunctionTypeIgnoringExceptionSpec(QualType T, QualType U);

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=321859=321858=321859=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu Jan  4 23:57:12 2018
@@ -2582,26 +2582,24 @@ void ASTContext::adjustDeducedFunctionRe
 /// specified exception specification. Type sugar that can be present on a
 /// declaration of a function with an exception specification is permitted
 /// and preserved. Other type sugar (for instance, typedefs) is not.
-static QualType getFunctionTypeWithExceptionSpec(
-ASTContext , QualType Orig,
-const FunctionProtoType::ExceptionSpecInfo ) {
+QualType ASTContext::getFunctionTypeWithExceptionSpec(
+QualType Orig, const FunctionProtoType::ExceptionSpecInfo ) {
   // Might have some parens.
   if (auto *PT = dyn_cast(Orig))
-return Context.getParenType(
-getFunctionTypeWithExceptionSpec(Context, PT->getInnerType(), ESI));
+return getParenType(
+getFunctionTypeWithExceptionSpec(PT->getInnerType(), ESI));
 
   // Might have a calling-convention attribute.
   if (auto *AT = dyn_cast(Orig))
-return Context.getAttributedType(
+return getAttributedType(
 AT->getAttrKind(),
-getFunctionTypeWithExceptionSpec(Context, AT->getModifiedType(), ESI),
-getFunctionTypeWithExceptionSpec(Context, AT->getEquivalentType(),
- ESI));
+getFunctionTypeWithExceptionSpec(AT->getModifiedType(), ESI),
+getFunctionTypeWithExceptionSpec(AT->getEquivalentType(), ESI));
 
   // Anything else must be a function type. Rebuild it with the new exception
   // specification.
   const FunctionProtoType *Proto = cast(Orig);
-  return Context.getFunctionType(
+  return getFunctionType(
   Proto->getReturnType(), Proto->getParamTypes(),
   Proto->getExtProtoInfo().withExceptionSpec(ESI));
 }
@@ -2610,8 +2608,8 @@ bool ASTContext::hasSameFunctionTypeIgno
   QualType U) {
   return hasSameType(T, U) ||
  (getLangOpts().CPlusPlus17 &&
-  

r321519 - -fsanitize=vptr warnings on bad static types in dynamic_cast and typeid

2017-12-28 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Thu Dec 28 04:45:41 2017
New Revision: 321519

URL: http://llvm.org/viewvc/llvm-project?rev=321519=rev
Log:
-fsanitize=vptr warnings on bad static types in dynamic_cast and typeid

...when such an operation is done on an object during con-/destruction.

This is the cfe part of a patch covering both cfe and compiler-rt.

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


Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGenCXX/ubsan-vtable-checks.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=321519=321518=321519=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Dec 28 04:45:41 2017
@@ -570,7 +570,7 @@ static llvm::Value *emitHash16Bytes(CGBu
 
 bool CodeGenFunction::isNullPointerAllowed(TypeCheckKind TCK) {
   return TCK == TCK_DowncastPointer || TCK == TCK_Upcast ||
- TCK == TCK_UpcastToVirtualBase;
+ TCK == TCK_UpcastToVirtualBase || TCK == TCK_DynamicOperation;
 }
 
 bool CodeGenFunction::isVptrCheckRequired(TypeCheckKind TCK, QualType Ty) {
@@ -578,7 +578,7 @@ bool CodeGenFunction::isVptrCheckRequire
   return (RD && RD->hasDefinition() && RD->isDynamicClass()) &&
  (TCK == TCK_MemberAccess || TCK == TCK_MemberCall ||
   TCK == TCK_DowncastPointer || TCK == TCK_DowncastReference ||
-  TCK == TCK_UpcastToVirtualBase);
+  TCK == TCK_UpcastToVirtualBase || TCK == TCK_DynamicOperation);
 }
 
 bool CodeGenFunction::sanitizePerformTypeCheck() const {

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=321519=321518=321519=diff
==
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Thu Dec 28 04:45:41 2017
@@ -2056,6 +2056,15 @@ static llvm::Value *EmitTypeidFromVTable
   // Get the vtable pointer.
   Address ThisPtr = CGF.EmitLValue(E).getAddress();
 
+  QualType SrcRecordTy = E->getType();
+
+  // C++ [class.cdtor]p4:
+  //   If the operand of typeid refers to the object under construction or
+  //   destruction and the static type of the operand is neither the 
constructor
+  //   or destructor’s class nor one of its bases, the behavior is undefined.
+  CGF.EmitTypeCheck(CodeGenFunction::TCK_DynamicOperation, E->getExprLoc(),
+ThisPtr.getPointer(), SrcRecordTy);
+
   // C++ [expr.typeid]p2:
   //   If the glvalue expression is obtained by applying the unary * operator 
to
   //   a pointer and the pointer is a null pointer value, the typeid expression
@@ -2064,7 +2073,6 @@ static llvm::Value *EmitTypeidFromVTable
   // However, this paragraph's intent is not clear.  We choose a very generous
   // interpretation which implores us to consider comma operators, conditional
   // operators, parentheses and other such constructs.
-  QualType SrcRecordTy = E->getType();
   if (CGF.CGM.getCXXABI().shouldTypeidBeNullChecked(
   isGLValueFromPointerDeref(E), SrcRecordTy)) {
 llvm::BasicBlock *BadTypeidBlock =
@@ -2127,10 +2135,6 @@ llvm::Value *CodeGenFunction::EmitDynami
   CGM.EmitExplicitCastExprType(DCE, this);
   QualType DestTy = DCE->getTypeAsWritten();
 
-  if (DCE->isAlwaysNull())
-if (llvm::Value *T = EmitDynamicCastToNull(*this, DestTy))
-  return T;
-
   QualType SrcTy = DCE->getSubExpr()->getType();
 
   // C++ [expr.dynamic.cast]p7:
@@ -2151,6 +2155,18 @@ llvm::Value *CodeGenFunction::EmitDynami
 DestRecordTy = DestTy->castAs()->getPointeeType();
   }
 
+  // C++ [class.cdtor]p5:
+  //   If the operand of the dynamic_cast refers to the object under
+  //   construction or destruction and the static type of the operand is not a
+  //   pointer to or object of the constructor or destructor’s own class or 
one
+  //   of its bases, the dynamic_cast results in undefined behavior.
+  EmitTypeCheck(TCK_DynamicOperation, DCE->getExprLoc(), ThisAddr.getPointer(),
+SrcRecordTy);
+
+  if (DCE->isAlwaysNull())
+if (llvm::Value *T = EmitDynamicCastToNull(*this, DestTy))
+  return T;
+
   assert(SrcRecordTy->isRecordType() && "source type must be a record type!");
 
   // C++ [expr.dynamic.cast]p4: 

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=321519=321518=321519=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Thu Dec 28 04:45:41 2017
@@ -2371,7 +2371,10 @@ public:
 /// object within its lifetime.
 TCK_UpcastToVirtualBase,
 /// Checking the 

Re: r320982 - Revert r320978 "No -fsanitize=function warning when calling noexcept function through non-noexcept pointer in C++17"

2017-12-19 Thread Stephan Bergmann via cfe-commits

On 12/19/2017 01:58 PM, Richard Smith wrote:
On 18 Dec 2017 15:23, "Stephan Bergmann via cfe-commits" 
<cfe-commits@lists.llvm.org <mailto:cfe-commits@lists.llvm.org>> wrote:


On 12/18/2017 03:05 PM, Richard Smith wrote:

Can we just strip the noexcept from the function type before
emitting the fsan type info?


As is apparently already done when emitting the (not
noexcept-annotated) __cxxabiv1::__function_type_info referenced from
a noexcept-annotated __cxxabiv1::__pointer_type_info?

That would indeed look like a better way to address this, then.  But
wouldn't that also prevent -fsanitize=function from finding
mismatches where a non-noexcept function is called through a
noexcept pointer, as in

   void f() {}
   void g(void (*p)() noexcept) { p(); }
   int main() { g(reinterpret_cast(f)); }


That call seems OK to me; if the function does throw, std::terminate() 
will be called.


I would have assumed that should be UB.  But that arguably could depend 
on whether and how that DR about calling noexpect functions through 
non-noexcept pointers that both you and I reported will be resolved. 
(It's a bit unfortunate that no information about those DR filings is 
yet available at 
<http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html>.)


One more argument in favour of resolving this issue as per 
<https://reviews.llvm.org/D40720#958730> for now.  So I'll look into that.

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


Re: r320982 - Revert r320978 "No -fsanitize=function warning when calling noexcept function through non-noexcept pointer in C++17"

2017-12-18 Thread Stephan Bergmann via cfe-commits

On 12/18/2017 03:05 PM, Richard Smith wrote:
Can we just strip the noexcept from the function type before emitting 
the fsan type info?


As is apparently already done when emitting the (not noexcept-annotated) 
__cxxabiv1::__function_type_info referenced from a noexcept-annotated 
__cxxabiv1::__pointer_type_info?


That would indeed look like a better way to address this, then.  But 
wouldn't that also prevent -fsanitize=function from finding mismatches 
where a non-noexcept function is called through a noexcept pointer, as in


  void f() {}
  void g(void (*p)() noexcept) { p(); }
  int main() { g(reinterpret_cast(f)); }

On 18 Dec 2017 13:52, "Stephan Bergmann via cfe-commits" 
<cfe-commits@lists.llvm.org <mailto:cfe-commits@lists.llvm.org>> wrote:


Author: sberg
Date: Mon Dec 18 05:51:48 2017
New Revision: 320982

URL: http://llvm.org/viewvc/llvm-project?rev=320982=rev
<http://llvm.org/viewvc/llvm-project?rev=320982=rev>
Log:
Revert r320978 "No -fsanitize=function warning when calling noexcept
function through non-noexcept pointer in C++17"

At least
<http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-android/
builds/6013/steps/annotate/logs/stdio
<http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-android/
builds/6013/steps/annotate/logs/stdio>> complains about
__ubsan::__ubsan_handle_function_type_mismatch_abort (compiler-rt
lib/ubsan/ubsan_handlers.cc) returning now despite being declared
'noreturn', so
looks like a different approach is needed for the
function_type_mismatch check
to be called also in cases that may ultimately succeed.

Modified:
     cfe/trunk/lib/CodeGen/CGExpr.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL:

http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=320982=320981=320982=diff

<http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=320982=320981=320982=diff>

==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Dec 18 05:51:48 2017
@@ -4504,14 +4504,10 @@ RValue CodeGenFunction::EmitCall(QualTyp
            Builder.CreateICmpEQ(CalleeRTTI, FTRTTIConst);
        llvm::Constant *StaticData[] = {
          EmitCheckSourceLocation(E->getLocStart()),
-        EmitCheckTypeDescriptor(CalleeType),
-        cast(FnType)->isNothrow(getContext())
-          ? llvm::Constant::getNullValue(FTRTTIConst->getType())
-          : FTRTTIConst
+        EmitCheckTypeDescriptor(CalleeType)
        };
        EmitCheck(std::make_pair(CalleeRTTIMatch,
SanitizerKind::Function),
-                SanitizerHandler::FunctionTypeMismatch, StaticData,
-                {CalleePtr, CalleeRTTI});
+                SanitizerHandler::FunctionTypeMismatch, StaticData,
CalleePtr);

        Builder.CreateBr(Cont);
        EmitBlock(Cont);

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


r320982 - Revert r320978 "No -fsanitize=function warning when calling noexcept function through non-noexcept pointer in C++17"

2017-12-18 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Mon Dec 18 05:51:48 2017
New Revision: 320982

URL: http://llvm.org/viewvc/llvm-project?rev=320982=rev
Log:
Revert r320978 "No -fsanitize=function warning when calling noexcept function 
through non-noexcept pointer in C++17"

At least  complains about
__ubsan::__ubsan_handle_function_type_mismatch_abort (compiler-rt
lib/ubsan/ubsan_handlers.cc) returning now despite being declared 'noreturn', so
looks like a different approach is needed for the function_type_mismatch check
to be called also in cases that may ultimately succeed.

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=320982=320981=320982=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Dec 18 05:51:48 2017
@@ -4504,14 +4504,10 @@ RValue CodeGenFunction::EmitCall(QualTyp
   Builder.CreateICmpEQ(CalleeRTTI, FTRTTIConst);
   llvm::Constant *StaticData[] = {
 EmitCheckSourceLocation(E->getLocStart()),
-EmitCheckTypeDescriptor(CalleeType),
-cast(FnType)->isNothrow(getContext())
-  ? llvm::Constant::getNullValue(FTRTTIConst->getType())
-  : FTRTTIConst
+EmitCheckTypeDescriptor(CalleeType)
   };
   EmitCheck(std::make_pair(CalleeRTTIMatch, SanitizerKind::Function),
-SanitizerHandler::FunctionTypeMismatch, StaticData,
-{CalleePtr, CalleeRTTI});
+SanitizerHandler::FunctionTypeMismatch, StaticData, CalleePtr);
 
   Builder.CreateBr(Cont);
   EmitBlock(Cont);


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


r320978 - No -fsanitize=function warning when calling noexcept function through non-noexcept pointer in C++17

2017-12-18 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Mon Dec 18 05:05:42 2017
New Revision: 320978

URL: http://llvm.org/viewvc/llvm-project?rev=320978=rev
Log:
No -fsanitize=function warning when calling noexcept function through 
non-noexcept pointer in C++17

As discussed in the mail thread  "Calling noexcept function throug non-
noexcept pointer is undefined behavior?", such a call should not be UB.
However, Clang currently warns about it.

There is no cheap check whether two function type_infos only differ in noexcept,
so pass those two type_infos as additional data to the function_type_mismatch
handler (with the optimization of passing a null "static callee type" info when
that is already noexcept, so the additional check can be avoided anyway).  For
the Itanium ABI (which appears to be the only one that happens to be used on
platforms that support -fsanitize=function, and which appears to only record
noexcept information for pointer-to-function type_infos, not for function
type_infos themselves), we then need to check the mangled names for occurrence
of "Do" representing "noexcept".

This is the cfe part of a patch covering both cfe and compiler-rt.

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

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=320978=320977=320978=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Dec 18 05:05:42 2017
@@ -4504,10 +4504,14 @@ RValue CodeGenFunction::EmitCall(QualTyp
   Builder.CreateICmpEQ(CalleeRTTI, FTRTTIConst);
   llvm::Constant *StaticData[] = {
 EmitCheckSourceLocation(E->getLocStart()),
-EmitCheckTypeDescriptor(CalleeType)
+EmitCheckTypeDescriptor(CalleeType),
+cast(FnType)->isNothrow(getContext())
+  ? llvm::Constant::getNullValue(FTRTTIConst->getType())
+  : FTRTTIConst
   };
   EmitCheck(std::make_pair(CalleeRTTIMatch, SanitizerKind::Function),
-SanitizerHandler::FunctionTypeMismatch, StaticData, CalleePtr);
+SanitizerHandler::FunctionTypeMismatch, StaticData,
+{CalleePtr, CalleeRTTI});
 
   Builder.CreateBr(Cont);
   EmitBlock(Cont);


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


r320135 - In stdbool.h, define bool, false, true only in gnu++98

2017-12-08 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Fri Dec  8 00:28:08 2017
New Revision: 320135

URL: http://llvm.org/viewvc/llvm-project?rev=320135=rev
Log:
In stdbool.h, define bool, false, true only in gnu++98

GCC has meanwhile corrected that with the similar
 "C++11
explicitly forbids macros for bool, true and false."

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

Modified:
cfe/trunk/lib/Headers/stdbool.h
cfe/trunk/test/Headers/stdbool.cpp

Modified: cfe/trunk/lib/Headers/stdbool.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/stdbool.h?rev=320135=320134=320135=diff
==
--- cfe/trunk/lib/Headers/stdbool.h (original)
+++ cfe/trunk/lib/Headers/stdbool.h Fri Dec  8 00:28:08 2017
@@ -32,12 +32,15 @@
 #define true 1
 #define false 0
 #elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
-/* Define _Bool, bool, false, true as a GNU extension. */
+/* Define _Bool as a GNU extension. */
 #define _Bool bool
+#if __cplusplus < 201103L
+/* For C++98, define bool, false, true as a GNU extension. */
 #define bool  bool
 #define false false
 #define true  true
 #endif
+#endif
 
 #define __bool_true_false_are_defined 1
 

Modified: cfe/trunk/test/Headers/stdbool.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/stdbool.cpp?rev=320135=320134=320135=diff
==
--- cfe/trunk/test/Headers/stdbool.cpp (original)
+++ cfe/trunk/test/Headers/stdbool.cpp Fri Dec  8 00:28:08 2017
@@ -1,13 +1,19 @@
-// RUN: %clang_cc1 -E -dM %s | FileCheck --check-prefix=CHECK-GNU-COMPAT %s
+// RUN: %clang_cc1 -std=gnu++98 -E -dM %s | FileCheck 
--check-prefix=CHECK-GNU-COMPAT-98 %s
+// RUN: %clang_cc1 -std=gnu++11 -E -dM %s | FileCheck 
--check-prefix=CHECK-GNU-COMPAT-11 %s
 // RUN: %clang_cc1 -std=c++98 -E -dM %s | FileCheck 
--check-prefix=CHECK-CONFORMING %s
 // RUN: %clang_cc1 -fsyntax-only -std=gnu++98 -verify -Weverything %s
 #include 
 #define zzz
 
-// CHECK-GNU-COMPAT: #define _Bool bool
-// CHECK-GNU-COMPAT: #define bool bool
-// CHECK-GNU-COMPAT: #define false false
-// CHECK-GNU-COMPAT: #define true true
+// CHECK-GNU-COMPAT-98: #define _Bool bool
+// CHECK-GNU-COMPAT-98: #define bool bool
+// CHECK-GNU-COMPAT-98: #define false false
+// CHECK-GNU-COMPAT-98: #define true true
+
+// CHECK-GNU-COMPAT-11: #define _Bool bool
+// CHECK-GNU-COMPAT-11-NOT: #define bool bool
+// CHECK-GNU-COMPAT-11-NOT: #define false false
+// CHECK-GNU-COMPAT-11-NOT: #define true true
 
 // CHECK-CONFORMING-NOT: #define _Bool
 // CHECK-CONFORMING: #define __CHAR_BIT__


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


r318530 - Indent code blocks so they are actually treated as such

2017-11-17 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Fri Nov 17 08:34:36 2017
New Revision: 318530

URL: http://llvm.org/viewvc/llvm-project?rev=318530=rev
Log:
Indent code blocks so they are actually treated as such

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=318530=318529=318530=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Fri Nov 17 08:34:36 2017
@@ -994,9 +994,9 @@ the configuration (without a prefix: ``A
 
 .. code-block:: c++
 
-Constructor()
-: initializer1(),
-  initializer2()
+  Constructor()
+  : initializer1(),
+initializer2()
 
   * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
 Break constructor initializers before the colon and commas, and align
@@ -1004,18 +1004,18 @@ the configuration (without a prefix: ``A
 
 .. code-block:: c++
 
-Constructor()
-: initializer1()
-, initializer2()
+  Constructor()
+  : initializer1()
+  , initializer2()
 
   * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
 Break constructor initializers after the colon and commas.
 
 .. code-block:: c++
 
-Constructor() :
-initializer1(),
-initializer2()
+  Constructor() :
+  initializer1(),
+  initializer2()
 
 
 


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


[libcxxabi] r318043 - Remove excess whitespace from syslog message; NFC

2017-11-13 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Mon Nov 13 07:40:31 2017
New Revision: 318043

URL: http://llvm.org/viewvc/llvm-project?rev=318043=rev
Log:
Remove excess whitespace from syslog message; NFC

Modified:
libcxxabi/trunk/src/private_typeinfo.cpp

Modified: libcxxabi/trunk/src/private_typeinfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/private_typeinfo.cpp?rev=318043=318042=318043=diff
==
--- libcxxabi/trunk/src/private_typeinfo.cpp (original)
+++ libcxxabi/trunk/src/private_typeinfo.cpp Mon Nov 13 07:40:31 2017
@@ -673,8 +673,8 @@ __dynamic_cast(const void *static_ptr, c
 info.path_dynamic_ptr_to_static_ptr == unknown)
 {
 syslog(LOG_ERR, "dynamic_cast error 2: One or more of the 
following type_info's "
-" has hidden visibility.  They should all have 
public visibility.  "
-" %s, %s, %s.\n", static_type->name(), 
dynamic_type->name(),
+"has hidden visibility.  They should all have 
public visibility.  "
+"%s, %s, %s.\n", static_type->name(), 
dynamic_type->name(),
 dst_type->name());
 // Redo the search comparing type_info's using strcmp
 info = {dst_type, static_ptr, static_type, src2dst_offset, 0};


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


r306799 - Fold exception-warnings.cpp into warn-throw-out-noexcept-func.cpp

2017-06-30 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Fri Jun 30 00:22:02 2017
New Revision: 306799

URL: http://llvm.org/viewvc/llvm-project?rev=306799=rev
Log:
Fold exception-warnings.cpp into warn-throw-out-noexcept-func.cpp

I had failed to notice the latter existed when I recently introduced the former.

Removed:
cfe/trunk/test/SemaCXX/exception-warnings.cpp
Modified:
cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp

Removed: cfe/trunk/test/SemaCXX/exception-warnings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/exception-warnings.cpp?rev=306798=auto
==
--- cfe/trunk/test/SemaCXX/exception-warnings.cpp (original)
+++ cfe/trunk/test/SemaCXX/exception-warnings.cpp (removed)
@@ -1,36 +0,0 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s
-
-struct B {};
-struct D: B {};
-void goodPlain() throw () {
-  try {
-throw D();
-  } catch (B) {}
-}
-void goodReference() throw () {
-  try {
-throw D();
-  } catch (B &) {}
-}
-void goodPointer() throw () {
-  D d;
-  try {
-throw 
-  } catch (B *) {}
-}
-void badPlain() throw () { // expected-note {{non-throwing function declare 
here}}
-  try {
-throw B(); // expected-warning {{'badPlain' has a non-throwing exception 
specification but can still throw, resulting in unexpected program termination}}
-  } catch (D) {}
-}
-void badReference() throw () { // expected-note {{non-throwing function 
declare here}}
-  try {
-throw B(); // expected-warning {{'badReference' has a non-throwing 
exception specification but can still throw, resulting in unexpected program 
termination}}
-  } catch (D &) {}
-}
-void badPointer() throw () { // expected-note {{non-throwing function declare 
here}}
-  B b;
-  try {
-throw  // expected-warning {{'badPointer' has a non-throwing exception 
specification but can still throw, resulting in unexpected program termination}}
-  } catch (D *) {}
-}

Modified: cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp?rev=306799=306798=306799=diff
==
--- cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp Fri Jun 30 00:22:02 
2017
@@ -253,6 +253,43 @@ void with_try_block1() noexcept try { //
 } catch (char *) {
 }
 
+namespace derived {
+struct B {};
+struct D: B {};
+void goodPlain() noexcept {
+  try {
+throw D();
+  } catch (B) {}
+}
+void goodReference() noexcept {
+  try {
+throw D();
+  } catch (B &) {}
+}
+void goodPointer() noexcept {
+  D d;
+  try {
+throw 
+  } catch (B *) {}
+}
+void badPlain() noexcept { // expected-note {{non-throwing function declare 
here}}
+  try {
+throw B(); // expected-warning {{'badPlain' has a non-throwing exception 
specification but can still throw, resulting in unexpected program termination}}
+  } catch (D) {}
+}
+void badReference() noexcept { // expected-note {{non-throwing function 
declare here}}
+  try {
+throw B(); // expected-warning {{'badReference' has a non-throwing 
exception specification but can still throw, resulting in unexpected program 
termination}}
+  } catch (D &) {}
+}
+void badPointer() noexcept { // expected-note {{non-throwing function declare 
here}}
+  B b;
+  try {
+throw  // expected-warning {{'badPointer' has a non-throwing exception 
specification but can still throw, resulting in unexpected program termination}}
+  } catch (D *) {}
+}
+}
+
 int main() {
   R1_ShouldDiag o; //expected-note {{in instantiation of member function}}
   S1_ShouldDiag b; //expected-note {{in instantiation of member function}}


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


r306715 - Fixed -Wexceptions derived-to-base false positives

2017-06-29 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Thu Jun 29 10:58:59 2017
New Revision: 306715

URL: http://llvm.org/viewvc/llvm-project?rev=306715=rev
Log:
Fixed -Wexceptions derived-to-base false positives

...as introduced with recent  "Emit warning
when throw exception in destruct or dealloc functions which has a (possible
implicit) noexcept specifier".  (The equivalent of the goodReference case hit
when building LibreOffice.)

(These warnings are apparently only emitted when no errors have yet been
encountered, so it didn't work to add the test code to the end of the existing
clang/test/SemaCXX/exceptions.cpp.)

Added:
cfe/trunk/test/SemaCXX/exception-warnings.cpp
Modified:
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=306715=306714=306715=diff
==
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Thu Jun 29 10:58:59 2017
@@ -305,10 +305,14 @@ static bool isThrowCaught(const CXXThrow
 CaughtType = CaughtType->castAs()
  ->getPointeeType()
  ->getUnqualifiedDesugaredType();
+  if (ThrowType->isPointerType() && CaughtType->isPointerType()) {
+ThrowType = ThrowType->getPointeeType()->getUnqualifiedDesugaredType();
+CaughtType = CaughtType->getPointeeType()->getUnqualifiedDesugaredType();
+  }
   if (CaughtType == ThrowType)
 return true;
   const CXXRecordDecl *CaughtAsRecordType =
-  CaughtType->getPointeeCXXRecordDecl();
+  CaughtType->getAsCXXRecordDecl();
   const CXXRecordDecl *ThrowTypeAsRecordType = ThrowType->getAsCXXRecordDecl();
   if (CaughtAsRecordType && ThrowTypeAsRecordType)
 return ThrowTypeAsRecordType->isDerivedFrom(CaughtAsRecordType);

Added: cfe/trunk/test/SemaCXX/exception-warnings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/exception-warnings.cpp?rev=306715=auto
==
--- cfe/trunk/test/SemaCXX/exception-warnings.cpp (added)
+++ cfe/trunk/test/SemaCXX/exception-warnings.cpp Thu Jun 29 10:58:59 2017
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s
+
+struct B {};
+struct D: B {};
+void goodPlain() throw () {
+  try {
+throw D();
+  } catch (B) {}
+}
+void goodReference() throw () {
+  try {
+throw D();
+  } catch (B &) {}
+}
+void goodPointer() throw () {
+  D d;
+  try {
+throw 
+  } catch (B *) {}
+}
+void badPlain() throw () { // expected-note {{non-throwing function declare 
here}}
+  try {
+throw B(); // expected-warning {{'badPlain' has a non-throwing exception 
specification but can still throw, resulting in unexpected program termination}}
+  } catch (D) {}
+}
+void badReference() throw () { // expected-note {{non-throwing function 
declare here}}
+  try {
+throw B(); // expected-warning {{'badReference' has a non-throwing 
exception specification but can still throw, resulting in unexpected program 
termination}}
+  } catch (D &) {}
+}
+void badPointer() throw () { // expected-note {{non-throwing function declare 
here}}
+  B b;
+  try {
+throw  // expected-warning {{'badPointer' has a non-throwing exception 
specification but can still throw, resulting in unexpected program termination}}
+  } catch (D *) {}
+}


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


r306377 - Make CastExpr::getSubExprAsWritten look through implicit temporary under CK_ConstructorConversion

2017-06-27 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Tue Jun 27 01:19:09 2017
New Revision: 306377

URL: http://llvm.org/viewvc/llvm-project?rev=306377=rev
Log:
Make CastExpr::getSubExprAsWritten look through implicit temporary under 
CK_ConstructorConversion

With

struct S1 {};
struct S2 { operator S1(); };
S1 f(S2 s) { return static_cast(s); }

the static_cast expr is

CXXStaticCastExpr 0x... 'struct S1' static_cast 

`-CXXConstructExpr 0x... 'struct S1' 'void (struct S1 &&) noexcept' elidable

`-MaterializeTemporaryExpr 0x... 'struct S1' xvalue
  `-ImplicitCastExpr 0x... 'struct S1' 
`-CXXMemberCallExpr 0x... 'struct S1'
  `-MemberExpr 0x... '' .operator S1 0x...
`-DeclRefExpr 0x... 'struct S2' lvalue ParmVar 0x... 's' 'struct S2'

getSubExprAsWritten used to return the MaterializeTemporaryExpr (of type S1)
under the CXXConstructExpr, instead of unwinding further to the DeclRefExpr (of
type S2) at the bottom.

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

Added:
cfe/trunk/unittests/Tooling/CastExprTest.cpp
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/unittests/Tooling/CMakeLists.txt

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=306377=306376=306377=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Jun 27 01:19:09 2017
@@ -1641,25 +1641,32 @@ const char *CastExpr::getCastKindName()
   llvm_unreachable("Unhandled cast kind!");
 }
 
+namespace {
+  Expr *skipImplicitTemporary(Expr *expr) {
+// Skip through reference binding to temporary.
+if (MaterializeTemporaryExpr *Materialize
+  = dyn_cast(expr))
+  expr = Materialize->GetTemporaryExpr();
+
+// Skip any temporary bindings; they're implicit.
+if (CXXBindTemporaryExpr *Binder = dyn_cast(expr))
+  expr = Binder->getSubExpr();
+
+return expr;
+  }
+}
+
 Expr *CastExpr::getSubExprAsWritten() {
   Expr *SubExpr = nullptr;
   CastExpr *E = this;
   do {
-SubExpr = E->getSubExpr();
+SubExpr = skipImplicitTemporary(E->getSubExpr());
 
-// Skip through reference binding to temporary.
-if (MaterializeTemporaryExpr *Materialize 
-  = 
dyn_cast(SubExpr))
-  SubExpr = Materialize->GetTemporaryExpr();
-
-// Skip any temporary bindings; they're implicit.
-if (CXXBindTemporaryExpr *Binder = dyn_cast(SubExpr))
-  SubExpr = Binder->getSubExpr();
-
 // Conversions by constructor and conversion functions have a
 // subexpression describing the call; strip it off.
 if (E->getCastKind() == CK_ConstructorConversion)
-  SubExpr = cast(SubExpr)->getArg(0);
+  SubExpr =
+skipImplicitTemporary(cast(SubExpr)->getArg(0));
 else if (E->getCastKind() == CK_UserDefinedConversion) {
   assert((isa(SubExpr) ||
   isa(SubExpr)) &&

Modified: cfe/trunk/unittests/Tooling/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/CMakeLists.txt?rev=306377=306376=306377=diff
==
--- cfe/trunk/unittests/Tooling/CMakeLists.txt (original)
+++ cfe/trunk/unittests/Tooling/CMakeLists.txt Tue Jun 27 01:19:09 2017
@@ -11,6 +11,7 @@ if (MSVC)
 endif()
 
 add_clang_unittest(ToolingTests
+  CastExprTest.cpp
   CommentHandlerTest.cpp
   CompilationDatabaseTest.cpp
   FixItTest.cpp

Added: cfe/trunk/unittests/Tooling/CastExprTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/CastExprTest.cpp?rev=306377=auto
==
--- cfe/trunk/unittests/Tooling/CastExprTest.cpp (added)
+++ cfe/trunk/unittests/Tooling/CastExprTest.cpp Tue Jun 27 01:19:09 2017
@@ -0,0 +1,38 @@
+//===- unittest/Tooling/CastExprTest.cpp 
--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "TestVisitor.h"
+
+using namespace clang;
+
+namespace {
+
+struct CastExprVisitor : TestVisitor {
+  std::function OnExplicitCast;
+
+  bool VisitExplicitCastExpr(ExplicitCastExpr *Expr) {
+if (OnExplicitCast)
+  OnExplicitCast(Expr);
+return true;
+  }
+};
+
+TEST(CastExprTest, GetSubExprAsWrittenThroughMaterializedTemporary) {
+CastExprVisitor Visitor;
+Visitor.OnExplicitCast = [](ExplicitCastExpr *Expr) {
+  auto Sub = Expr->getSubExprAsWritten();
+  EXPECT_TRUE(isa(Sub))
+<< "Expected DeclRefExpr, but saw " << Sub->getStmtClassName();
+};
+Visitor.runOver("struct S1 {};\n"
+"struct S2 { operator S1(); 

r306374 - Make sure TraverseInitListExpr visits InitListExpr exactly twice

2017-06-27 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Tue Jun 27 01:04:08 2017
New Revision: 306374

URL: http://llvm.org/viewvc/llvm-project?rev=306374=rev
Log:
Make sure TraverseInitListExpr visits InitListExpr exactly twice

... once each for the syntactic and semantic form. Without this fix, behavior
of the newly added tests would have been

InitListExprIsPreOrderVisitedTwice:
 syntactic: 1
 semantic: 2

InitListExprIsPostOrderVisitedTwice:
 syntactic: 0
 semantic: 1

InitListExprIsPreOrderNoQueueVisitedTwice:
 syntactic: 1
 semantic: 2

InitListExprIsPostOrderNoQueueVisitedTwice:
 syntactic: 0
 semantic: 2

Modified:
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=306374=306373=306374=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Tue Jun 27 01:04:08 2017
@@ -593,6 +593,16 @@ bool RecursiveASTVisitor::PostV
 #define STMT(CLASS, PARENT)
\
   case Stmt::CLASS##Class: 
\
 TRY_TO(WalkUpFrom##CLASS(static_cast(S))); break;
+#define INITLISTEXPR(CLASS, PARENT)
\
+  case Stmt::CLASS##Class: 
\
+{  
\
+  auto ILE = static_cast(S);  
\
+  if (auto Syn = ILE->isSemanticForm() ? ILE->getSyntacticForm() : ILE)
\
+TRY_TO(WalkUpFrom##CLASS(Syn));
\
+  if (auto Sem = ILE->isSemanticForm() ? ILE : ILE->getSemanticForm()) 
\
+TRY_TO(WalkUpFrom##CLASS(Sem));
\
+  break;   
\
+}
 #include "clang/AST/StmtNodes.inc"
   }
 
@@ -2220,13 +2230,15 @@ bool RecursiveASTVisitor::Trave
 // the syntactic and the semantic form.
 //
 // There is no guarantee about which form \p S takes when this method is 
called.
-DEF_TRAVERSE_STMT(InitListExpr, {
+template 
+bool RecursiveASTVisitor::TraverseInitListExpr(
+InitListExpr *S, DataRecursionQueue *Queue) {
   TRY_TO(TraverseSynOrSemInitListExpr(
   S->isSemanticForm() ? S->getSyntacticForm() : S, Queue));
   TRY_TO(TraverseSynOrSemInitListExpr(
   S->isSemanticForm() ? S : S->getSemanticForm(), Queue));
-  ShouldVisitChildren = false;
-})
+  return true;
+}
 
 // GenericSelectionExpr is a special case because the types and expressions
 // are interleaved.  We also need to watch out for null types (default

Modified: cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp?rev=306374=306373=306374=diff
==
--- cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp Tue Jun 27 01:04:08 
2017
@@ -158,4 +158,90 @@ TEST(RecursiveASTVisitor, DefaultArgumen
   "static int k = f();\n"));
 }
 
+// Check to ensure that InitListExpr is visited twice, once each for the
+// syntactic and semantic form.
+class InitListExprPreOrderVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool VisitInitListExpr(InitListExpr *ILE) {
+Match(ILE->isSemanticForm() ? "semantic" : "syntactic", 
ILE->getLocStart());
+return true;
+  }
+};
+
+class InitListExprPostOrderVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool shouldTraversePostOrder() const { return true; }
+
+  bool VisitInitListExpr(InitListExpr *ILE) {
+Match(ILE->isSemanticForm() ? "semantic" : "syntactic", 
ILE->getLocStart());
+return true;
+  }
+};
+
+class InitListExprPreOrderNoQueueVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool TraverseInitListExpr(InitListExpr *ILE) {
+return ExpectedLocationVisitor::TraverseInitListExpr(ILE);
+  }
+
+  bool VisitInitListExpr(InitListExpr *ILE) {
+Match(ILE->isSemanticForm() ? "semantic" : "syntactic", 
ILE->getLocStart());
+return true;
+  }
+};
+
+class InitListExprPostOrderNoQueueVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool shouldTraversePostOrder() const { return true; }
+
+  bool TraverseInitListExpr(InitListExpr *ILE) {
+return ExpectedLocationVisitor::TraverseInitListExpr(ILE);
+  }
+
+  bool VisitInitListExpr(InitListExpr *ILE) {
+Match(ILE->isSemanticForm() ? "semantic" : "syntactic", 
ILE->getLocStart());
+return true;
+  }
+};
+
+TEST(RecursiveASTVisitor, InitListExprIsPreOrderVisitedTwice) {

r306373 - Switch TestVisitor to Lang_C via -x c

2017-06-27 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Tue Jun 27 00:59:56 2017
New Revision: 306373

URL: http://llvm.org/viewvc/llvm-project?rev=306373=rev
Log:
Switch TestVisitor to Lang_C via -x c

...instead of -std=c99, as the latter lead to

  error: invalid argument '-std=c99' not allowed with 'C++'

complaints in test logs

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

Modified:
cfe/trunk/unittests/Tooling/TestVisitor.h

Modified: cfe/trunk/unittests/Tooling/TestVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/TestVisitor.h?rev=306373=306372=306373=diff
==
--- cfe/trunk/unittests/Tooling/TestVisitor.h (original)
+++ cfe/trunk/unittests/Tooling/TestVisitor.h Tue Jun 27 00:59:56 2017
@@ -53,7 +53,10 @@ public:
   bool runOver(StringRef Code, Language L = Lang_CXX) {
 std::vector Args;
 switch (L) {
-  case Lang_C: Args.push_back("-std=c99"); break;
+  case Lang_C:
+Args.push_back("-x");
+Args.push_back("c");
+break;
   case Lang_CXX98: Args.push_back("-std=c++98"); break;
   case Lang_CXX11: Args.push_back("-std=c++11"); break;
   case Lang_CXX14: Args.push_back("-std=c++14"); break;


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


r299522 - Don't issue a warning if the shadowing declaration is in a class

2017-04-05 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Wed Apr  5 03:36:58 2017
New Revision: 299522

URL: http://llvm.org/viewvc/llvm-project?rev=299522=rev
Log:
Don't issue a warning if the shadowing declaration is in a class

Follow-up to r299363 "Enhance -Wshadow to warn when shadowing typedefs or type
aliases".

Patch by Ahmed Asadi.

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

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/warn-shadow.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=299522=299521=299522=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Apr  5 03:36:58 2017
@@ -6744,6 +6744,10 @@ NamedDecl *Sema::getShadowedDeclaration(
 /// if it doesn't shadow any declaration or shadowing warnings are disabled.
 NamedDecl *Sema::getShadowedDeclaration(const TypedefNameDecl *D,
 const LookupResult ) {
+  // Don't warn if typedef declaration is part of a class
+  if (D->getDeclContext()->isRecord())
+return nullptr;
+  
   if (!shouldWarnIfShadowedDecl(Diags, R))
 return nullptr;
 

Modified: cfe/trunk/test/SemaCXX/warn-shadow.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-shadow.cpp?rev=299522=299521=299522=diff
==
--- cfe/trunk/test/SemaCXX/warn-shadow.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-shadow.cpp Wed Apr  5 03:36:58 2017
@@ -87,6 +87,16 @@ class A {
   }
 };
 
+struct path {
+  using value_type = char;
+  typedef char value_type2;
+  struct iterator {
+using value_type = path; // no warning
+typedef path value_type2; // no warning
+  };
+};
+
+
 // TODO: this should warn, 
 class B : A {
   int data;


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


r298490 - Add LibreOffice Clang plugin to ExternalClangExamples.rst

2017-03-22 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Wed Mar 22 03:45:49 2017
New Revision: 298490

URL: http://llvm.org/viewvc/llvm-project?rev=298490=rev
Log:
Add LibreOffice Clang plugin to ExternalClangExamples.rst

Reviewers: rsmith, rizsotto.mailinglist

Subscribers: cfe-commits

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

Modified:
cfe/trunk/docs/ExternalClangExamples.rst

Modified: cfe/trunk/docs/ExternalClangExamples.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ExternalClangExamples.rst?rev=298490=298489=298490=diff
==
--- cfe/trunk/docs/ExternalClangExamples.rst (original)
+++ cfe/trunk/docs/ExternalClangExamples.rst Wed Mar 22 03:45:49 2017
@@ -90,3 +90,11 @@ List of projects and tools
You get more than 50 Qt related compiler warnings, ranging from unneeded
memory allocations to misusage of API, including fix-its for automatic
refactoring."
+
+``_
+   "LibreOffice uses a Clang plugin infrastructure to check during the build
+   various things, some more, some less specific to the LibreOffice source 
code.
+   There are currently around 50 such checkers, from flagging C-style casts and
+   uses of reserved identifiers to ensuring that code adheres to lifecycle
+   protocols for certain LibreOffice-specific classes.  They may serve as
+   examples for writing RecursiveASTVisitor-based plugins."


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


r289647 - Replace APFloatBase static fltSemantics data members with getter functions

2016-12-14 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Wed Dec 14 05:57:17 2016
New Revision: 289647

URL: http://llvm.org/viewvc/llvm-project?rev=289647=rev
Log:
Replace APFloatBase static fltSemantics data members with getter functions

At least the plugin used by the LibreOffice build
() indirectly
uses those members (through inline functions in LLVM/Clang include files in turn
using them), but they are not exported by utils/extract_symbols.py on Windows,
and accessing data across DLL/EXE boundaries on Windows is generally
problematic.

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

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
cfe/trunk/lib/AST/APValue.cpp
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=289647=289646=289647=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Wed Dec 14 
05:57:17 2016
@@ -1421,18 +1421,18 @@ private:
 template <>
 inline bool ValueEqualsMatcher::matchesNode(
 const FloatingLiteral ) const {
-  if ((()) == ::APFloat::IEEEsingle)
+  if ((()) == ::APFloat::IEEEsingle())
 return Node.getValue().convertToFloat() == ExpectedValue;
-  if ((()) == ::APFloat::IEEEdouble)
+  if ((()) == ::APFloat::IEEEdouble())
 return Node.getValue().convertToDouble() == ExpectedValue;
   return false;
 }
 template <>
 inline bool ValueEqualsMatcher::matchesNode(
 const FloatingLiteral ) const {
-  if ((()) == ::APFloat::IEEEsingle)
+  if ((()) == ::APFloat::IEEEsingle())
 return Node.getValue().convertToFloat() == ExpectedValue;
-  if ((()) == ::APFloat::IEEEdouble)
+  if ((()) == ::APFloat::IEEEdouble())
 return Node.getValue().convertToDouble() == ExpectedValue;
   return false;
 }

Modified: cfe/trunk/lib/AST/APValue.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/APValue.cpp?rev=289647=289646=289647=diff
==
--- cfe/trunk/lib/AST/APValue.cpp (original)
+++ cfe/trunk/lib/AST/APValue.cpp Wed Dec 14 05:57:17 2016
@@ -263,7 +263,7 @@ LLVM_DUMP_METHOD void APValue::dump() co
 static double GetApproxValue(const llvm::APFloat ) {
   llvm::APFloat V = F;
   bool ignored;
-  V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven,
+  V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven,
 );
   return V.convertToDouble();
 }

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=289647=289646=289647=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Wed Dec 14 05:57:17 2016
@@ -782,33 +782,33 @@ FloatingLiteral::Create(const ASTContext
 const llvm::fltSemantics ::getSemantics() const {
   switch(FloatingLiteralBits.Semantics) {
   case IEEEhalf:
-return llvm::APFloat::IEEEhalf;
+return llvm::APFloat::IEEEhalf();
   case IEEEsingle:
-return llvm::APFloat::IEEEsingle;
+return llvm::APFloat::IEEEsingle();
   case IEEEdouble:
-return llvm::APFloat::IEEEdouble;
+return llvm::APFloat::IEEEdouble();
   case x87DoubleExtended:
-return llvm::APFloat::x87DoubleExtended;
+return llvm::APFloat::x87DoubleExtended();
   case IEEEquad:
-return llvm::APFloat::IEEEquad;
+return llvm::APFloat::IEEEquad();
   case PPCDoubleDouble:
-return llvm::APFloat::PPCDoubleDouble;
+return llvm::APFloat::PPCDoubleDouble();
   }
   llvm_unreachable("Unrecognised floating semantics");
 }
 
 void FloatingLiteral::setSemantics(const llvm::fltSemantics ) {
-  if ( == ::APFloat::IEEEhalf)
+  if ( == ::APFloat::IEEEhalf())
 FloatingLiteralBits.Semantics = IEEEhalf;
-  else if ( == ::APFloat::IEEEsingle)
+  else if ( == ::APFloat::IEEEsingle())
 FloatingLiteralBits.Semantics = IEEEsingle;
-  else if ( == ::APFloat::IEEEdouble)
+  else if ( == ::APFloat::IEEEdouble())
 FloatingLiteralBits.Semantics = IEEEdouble;
-  else if ( == ::APFloat::x87DoubleExtended)
+  else if ( == ::APFloat::x87DoubleExtended())
 FloatingLiteralBits.Semantics = x87DoubleExtended;
-  else if ( == ::APFloat::IEEEquad)
+  else if ( == 

[clang-tools-extra] r289647 - Replace APFloatBase static fltSemantics data members with getter functions

2016-12-14 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Wed Dec 14 05:57:17 2016
New Revision: 289647

URL: http://llvm.org/viewvc/llvm-project?rev=289647=rev
Log:
Replace APFloatBase static fltSemantics data members with getter functions

At least the plugin used by the LibreOffice build
() indirectly
uses those members (through inline functions in LLVM/Clang include files in turn
using them), but they are not exported by utils/extract_symbols.py on Windows,
and accessing data across DLL/EXE boundaries on Windows is generally
problematic.

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

Modified:
clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp?rev=289647=289646=289647=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp Wed Dec 14 
05:57:17 2016
@@ -23,9 +23,9 @@ namespace misc {
 namespace {
 AST_MATCHER(FloatingLiteral, floatHalf) {
   const auto  = Node.getValue();
-  if ((()) == ::APFloat::IEEEsingle)
+  if ((()) == ::APFloat::IEEEsingle())
 return literal.convertToFloat() == 0.5f;
-  if ((()) == ::APFloat::IEEEdouble)
+  if ((()) == ::APFloat::IEEEdouble())
 return literal.convertToDouble() == 0.5;
   return false;
 }


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


Re: [PATCH] D23907: Fix documentation of MemberExpr::getMemberDecl

2016-09-14 Thread Stephan Bergmann via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281469: Fix documentation of MemberExpr::getMemberDecl 
(authored by sberg).

Changed prior to commit:
  https://reviews.llvm.org/D23907?vs=69317=71357#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23907

Files:
  cfe/trunk/include/clang/AST/Expr.h

Index: cfe/trunk/include/clang/AST/Expr.h
===
--- cfe/trunk/include/clang/AST/Expr.h
+++ cfe/trunk/include/clang/AST/Expr.h
@@ -2406,8 +2406,8 @@
 
   /// \brief Retrieve the member declaration to which this expression refers.
   ///
-  /// The returned declaration will either be a FieldDecl or (in C++)
-  /// a CXXMethodDecl.
+  /// The returned declaration will be a FieldDecl or (in C++) a VarDecl (for
+  /// static data members), a CXXMethodDecl, or an EnumConstantDecl.
   ValueDecl *getMemberDecl() const { return MemberDecl; }
   void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
 


Index: cfe/trunk/include/clang/AST/Expr.h
===
--- cfe/trunk/include/clang/AST/Expr.h
+++ cfe/trunk/include/clang/AST/Expr.h
@@ -2406,8 +2406,8 @@
 
   /// \brief Retrieve the member declaration to which this expression refers.
   ///
-  /// The returned declaration will either be a FieldDecl or (in C++)
-  /// a CXXMethodDecl.
+  /// The returned declaration will be a FieldDecl or (in C++) a VarDecl (for
+  /// static data members), a CXXMethodDecl, or an EnumConstantDecl.
   ValueDecl *getMemberDecl() const { return MemberDecl; }
   void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r281469 - Fix documentation of MemberExpr::getMemberDecl

2016-09-14 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Wed Sep 14 09:03:50 2016
New Revision: 281469

URL: http://llvm.org/viewvc/llvm-project?rev=281469=rev
Log:
Fix documentation of MemberExpr::getMemberDecl

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

Modified:
cfe/trunk/include/clang/AST/Expr.h

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=281469=281468=281469=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Sep 14 09:03:50 2016
@@ -2406,8 +2406,8 @@ public:
 
   /// \brief Retrieve the member declaration to which this expression refers.
   ///
-  /// The returned declaration will either be a FieldDecl or (in C++)
-  /// a CXXMethodDecl.
+  /// The returned declaration will be a FieldDecl or (in C++) a VarDecl (for
+  /// static data members), a CXXMethodDecl, or an EnumConstantDecl.
   ValueDecl *getMemberDecl() const { return MemberDecl; }
   void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
 


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


[PATCH] D23907: Fix documentation of MemberExpr::getMemberDecl

2016-08-25 Thread Stephan Bergmann via cfe-commits
sberg created this revision.
sberg added reviewers: rsmith, doug.gregor.
sberg added a subscriber: cfe-commits.

https://reviews.llvm.org/D23907

Files:
  include/clang/AST/Expr.h

Index: include/clang/AST/Expr.h
===
--- include/clang/AST/Expr.h
+++ include/clang/AST/Expr.h
@@ -2406,8 +2406,8 @@
 
   /// \brief Retrieve the member declaration to which this expression refers.
   ///
-  /// The returned declaration will either be a FieldDecl or (in C++)
-  /// a CXXMethodDecl.
+  /// The returned declaration will be a FieldDecl or (in C++) a VarDecl (for
+  /// static data members), a CXXMethodDecl, or an EnumConstantDecl.
   ValueDecl *getMemberDecl() const { return MemberDecl; }
   void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
 


Index: include/clang/AST/Expr.h
===
--- include/clang/AST/Expr.h
+++ include/clang/AST/Expr.h
@@ -2406,8 +2406,8 @@
 
   /// \brief Retrieve the member declaration to which this expression refers.
   ///
-  /// The returned declaration will either be a FieldDecl or (in C++)
-  /// a CXXMethodDecl.
+  /// The returned declaration will be a FieldDecl or (in C++) a VarDecl (for
+  /// static data members), a CXXMethodDecl, or an EnumConstantDecl.
   ValueDecl *getMemberDecl() const { return MemberDecl; }
   void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22128: Make CastExpr::getSubExprAsWritten look through implicit temporary under CK_ConstructorConversion

2016-07-08 Thread Stephan Bergmann via cfe-commits
sberg added a comment.

(I'm not sure where and how to add a test for this?)


http://reviews.llvm.org/D22128



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


[PATCH] D22128: Make CastExpr::getSubExprAsWritten look through implicit temporary under CK_ConstructorConversion

2016-07-08 Thread Stephan Bergmann via cfe-commits
sberg created this revision.
sberg added a reviewer: rsmith.
sberg added a subscriber: cfe-commits.
Herald added a subscriber: aemerson.

With

> struct S1 {};
> struct S2 { operator S1(); };
> S1 f(S2 s) { return static_cast(s); }

the static_cast expr is

> CXXStaticCastExpr 0x... 'struct S1' static_cast 
> 
> `-CXXConstructExpr 0x... 'struct S1' 'void (struct S1 &&) noexcept' elidable
>   `-MaterializeTemporaryExpr 0x... 'struct S1' xvalue
> `-ImplicitCastExpr 0x... 'struct S1' 
>   `-CXXMemberCallExpr 0x... 'struct S1'
> `-MemberExpr 0x... '' .operator S1 0x...
>   `-DeclRefExpr 0x... 'struct S2' lvalue ParmVar 0x... 's' 'struct S2'

getSubExprAsWritten used to return the MaterializeTemporaryExpr (of type S1) 
under the CXXConstructExpr, instead of unwinding further to the DeclRefExpr (of 
type S2) at the bottom.

http://reviews.llvm.org/D22128

Files:
  lib/AST/Expr.cpp

Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -1602,25 +1602,32 @@
   llvm_unreachable("Unhandled cast kind!");
 }
 
+namespace {
+  Expr *skipImplicitTemporary(Expr *expr) {
+// Skip through reference binding to temporary.
+if (MaterializeTemporaryExpr *Materialize
+  = dyn_cast(expr))
+  expr = Materialize->GetTemporaryExpr();
+
+// Skip any temporary bindings; they're implicit.
+if (CXXBindTemporaryExpr *Binder = dyn_cast(expr))
+  expr = Binder->getSubExpr();
+
+return expr;
+  }
+}
+
 Expr *CastExpr::getSubExprAsWritten() {
   Expr *SubExpr = nullptr;
   CastExpr *E = this;
   do {
-SubExpr = E->getSubExpr();
+SubExpr = skipImplicitTemporary(E->getSubExpr());
 
-// Skip through reference binding to temporary.
-if (MaterializeTemporaryExpr *Materialize 
-  = 
dyn_cast(SubExpr))
-  SubExpr = Materialize->GetTemporaryExpr();
-
-// Skip any temporary bindings; they're implicit.
-if (CXXBindTemporaryExpr *Binder = dyn_cast(SubExpr))
-  SubExpr = Binder->getSubExpr();
-
 // Conversions by constructor and conversion functions have a
 // subexpression describing the call; strip it off.
 if (E->getCastKind() == CK_ConstructorConversion)
-  SubExpr = cast(SubExpr)->getArg(0);
+  SubExpr =
+skipImplicitTemporary(cast(SubExpr)->getArg(0));
 else if (E->getCastKind() == CK_UserDefinedConversion) {
   assert((isa(SubExpr) ||
   isa(SubExpr)) &&


Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -1602,25 +1602,32 @@
   llvm_unreachable("Unhandled cast kind!");
 }
 
+namespace {
+  Expr *skipImplicitTemporary(Expr *expr) {
+// Skip through reference binding to temporary.
+if (MaterializeTemporaryExpr *Materialize
+  = dyn_cast(expr))
+  expr = Materialize->GetTemporaryExpr();
+
+// Skip any temporary bindings; they're implicit.
+if (CXXBindTemporaryExpr *Binder = dyn_cast(expr))
+  expr = Binder->getSubExpr();
+
+return expr;
+  }
+}
+
 Expr *CastExpr::getSubExprAsWritten() {
   Expr *SubExpr = nullptr;
   CastExpr *E = this;
   do {
-SubExpr = E->getSubExpr();
+SubExpr = skipImplicitTemporary(E->getSubExpr());
 
-// Skip through reference binding to temporary.
-if (MaterializeTemporaryExpr *Materialize 
-  = dyn_cast(SubExpr))
-  SubExpr = Materialize->GetTemporaryExpr();
-
-// Skip any temporary bindings; they're implicit.
-if (CXXBindTemporaryExpr *Binder = dyn_cast(SubExpr))
-  SubExpr = Binder->getSubExpr();
-
 // Conversions by constructor and conversion functions have a
 // subexpression describing the call; strip it off.
 if (E->getCastKind() == CK_ConstructorConversion)
-  SubExpr = cast(SubExpr)->getArg(0);
+  SubExpr =
+skipImplicitTemporary(cast(SubExpr)->getArg(0));
 else if (E->getCastKind() == CK_UserDefinedConversion) {
   assert((isa(SubExpr) ||
   isa(SubExpr)) &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21682: DeadStoresChecker: Don't warn about dead stores into volatile variables

2016-06-24 Thread Stephan Bergmann via cfe-commits
sberg closed this revision.
sberg added a comment.

Committed revision 273689.


http://reviews.llvm.org/D21682



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


r273689 - DeadStoresChecker: Don't warn about dead stores into volatile variables

2016-06-24 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Fri Jun 24 11:26:43 2016
New Revision: 273689

URL: http://llvm.org/viewvc/llvm-project?rev=273689=rev
Log:
DeadStoresChecker: Don't warn about dead stores into volatile variables

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
cfe/trunk/test/Analysis/dead-stores.c

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp?rev=273689=273688=273689=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp Fri Jun 24 
11:26:43 2016
@@ -278,6 +278,8 @@ public:
   RHS = RHS->IgnoreParenCasts();
 
   QualType T = VD->getType();
+  if (T.isVolatileQualified())
+return;
   if (T->isPointerType() || T->isObjCObjectPointerType()) {
 if (RHS->isNullPointerConstant(Ctx, 
Expr::NPC_ValueDependentIsNull))
   return;

Modified: cfe/trunk/test/Analysis/dead-stores.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dead-stores.c?rev=273689=273688=273689=diff
==
--- cfe/trunk/test/Analysis/dead-stores.c (original)
+++ cfe/trunk/test/Analysis/dead-stores.c Fri Jun 24 11:26:43 2016
@@ -569,3 +569,7 @@ void testBOComma() {
 
 }
 
+void testVolatile() {
+volatile int v;
+v = 0; // no warning
+}


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


[PATCH] D21682: DeadStoresChecker: Don't warn about dead stores into volatile variables

2016-06-24 Thread Stephan Bergmann via cfe-commits
sberg created this revision.
sberg added a reviewer: zaks.anna.
sberg added a subscriber: cfe-commits.

http://reviews.llvm.org/D21682

Files:
  lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
  test/Analysis/dead-stores.c

Index: test/Analysis/dead-stores.c
===
--- test/Analysis/dead-stores.c
+++ test/Analysis/dead-stores.c
@@ -569,3 +569,7 @@
 
 }
 
+void testVolatile() {
+volatile int v;
+v = 0; // no warning
+}
Index: lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
+++ lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
@@ -278,6 +278,8 @@
   RHS = RHS->IgnoreParenCasts();
 
   QualType T = VD->getType();
+  if (T.isVolatileQualified())
+return;
   if (T->isPointerType() || T->isObjCObjectPointerType()) {
 if (RHS->isNullPointerConstant(Ctx, 
Expr::NPC_ValueDependentIsNull))
   return;


Index: test/Analysis/dead-stores.c
===
--- test/Analysis/dead-stores.c
+++ test/Analysis/dead-stores.c
@@ -569,3 +569,7 @@
 
 }
 
+void testVolatile() {
+volatile int v;
+v = 0; // no warning
+}
Index: lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
+++ lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
@@ -278,6 +278,8 @@
   RHS = RHS->IgnoreParenCasts();
 
   QualType T = VD->getType();
+  if (T.isVolatileQualified())
+return;
   if (T->isPointerType() || T->isObjCObjectPointerType()) {
 if (RHS->isNullPointerConstant(Ctx, Expr::NPC_ValueDependentIsNull))
   return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18430: For MS ABI, emit dllexport friend functions defined inline in class

2016-03-30 Thread Stephan Bergmann via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL264841: For MS ABI, emit dllexport friend functions defined 
inline in class (authored by sberg).

Changed prior to commit:
  http://reviews.llvm.org/D18430?vs=51517=52024#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18430

Files:
  cfe/trunk/include/clang/AST/ASTConsumer.h
  cfe/trunk/include/clang/Frontend/MultiplexConsumer.h
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/CodeGen/CodeGenAction.cpp
  cfe/trunk/lib/CodeGen/ModuleBuilder.cpp
  cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
  cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/test/CodeGenCXX/dllexport-ms-friend.cpp

Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -1773,7 +1773,7 @@
   Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body);
   Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation);
   Decl *ActOnSkippedFunctionBody(Decl *Decl);
-  void ActOnFinishInlineMethodDef(CXXMethodDecl *D);
+  void ActOnFinishInlineFunctionDef(FunctionDecl *D);
 
   /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an
   /// attribute for which parsing is delayed.
Index: cfe/trunk/include/clang/Frontend/MultiplexConsumer.h
===
--- cfe/trunk/include/clang/Frontend/MultiplexConsumer.h
+++ cfe/trunk/include/clang/Frontend/MultiplexConsumer.h
@@ -36,7 +36,7 @@
   void Initialize(ASTContext ) override;
   void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override;
   bool HandleTopLevelDecl(DeclGroupRef D) override;
-  void HandleInlineMethodDefinition(CXXMethodDecl *D) override;
+  void HandleInlineFunctionDefinition(FunctionDecl *D) override;
   void HandleInterestingDecl(DeclGroupRef D) override;
   void HandleTranslationUnit(ASTContext ) override;
   void HandleTagDeclDefinition(TagDecl *D) override;
Index: cfe/trunk/include/clang/AST/ASTConsumer.h
===
--- cfe/trunk/include/clang/AST/ASTConsumer.h
+++ cfe/trunk/include/clang/AST/ASTConsumer.h
@@ -55,9 +55,9 @@
   /// \returns true to continue parsing, or false to abort parsing.
   virtual bool HandleTopLevelDecl(DeclGroupRef D);
 
-  /// \brief This callback is invoked each time an inline method definition is
-  /// completed.
-  virtual void HandleInlineMethodDefinition(CXXMethodDecl *D) {}
+  /// \brief This callback is invoked each time an inline (method or friend)
+  /// function definition in a class is completed.
+  virtual void HandleInlineFunctionDefinition(FunctionDecl *D) {}
 
   /// HandleInterestingDecl - Handle the specified interesting declaration. This
   /// is called by the AST reader when deserializing things that might interest
Index: cfe/trunk/test/CodeGenCXX/dllexport-ms-friend.cpp
===
--- cfe/trunk/test/CodeGenCXX/dllexport-ms-friend.cpp
+++ cfe/trunk/test/CodeGenCXX/dllexport-ms-friend.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple %ms_abi_triple -fms-extensions -emit-llvm -O0 -o - %s | FileCheck %s
+
+// Friend functions defined in classes are emitted.
+// CHECK: define weak_odr dllexport void @"\01?friend1@@YAXXZ"()
+struct FuncFriend1 {
+  friend __declspec(dllexport) void friend1() {}
+};
+
+// But function templates and functions defined in class templates are not
+// emitted.
+// CHECK-NOT: friend2
+// CHECK-NOT: friend3
+// CHECK-NOT: friend4
+struct FuncFriend2 {
+  template friend __declspec(dllexport) void friend2() {}
+};
+template struct FuncFriend3 {
+  friend __declspec(dllexport) void friend3() {}
+  struct Inner {
+friend __declspec(dllexport) void friend4() {}
+  };
+};
Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -10875,8 +10875,8 @@
   return ActOnStartOfFunctionDef(FnBodyScope, DP, SkipBody);
 }
 
-void Sema::ActOnFinishInlineMethodDef(CXXMethodDecl *D) {
-  Consumer.HandleInlineMethodDefinition(D);
+void Sema::ActOnFinishInlineFunctionDef(FunctionDecl *D) {
+  Consumer.HandleInlineFunctionDefinition(D);
 }
 
 static bool ShouldWarnAboutMissingPrototype(const FunctionDecl *FD, 
Index: cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
===
--- cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
+++ cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
@@ -272,9 +272,9 @@
   return Continue;
 }
 
-void MultiplexConsumer::HandleInlineMethodDefinition(CXXMethodDecl *D) {
+void MultiplexConsumer::HandleInlineFunctionDefinition(FunctionDecl *D) {
   for (auto  : Consumers)
-Consumer->HandleInlineMethodDefinition(D);
+

r264841 - For MS ABI, emit dllexport friend functions defined inline in class

2016-03-30 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Wed Mar 30 01:27:31 2016
New Revision: 264841

URL: http://llvm.org/viewvc/llvm-project?rev=264841=rev
Log:
For MS ABI, emit dllexport friend functions defined inline in class

...as that is apparently what MSVC does.  This is an updated version of r263738,
which had to be reverted in r263740 due to test failures.  The original version
had erroneously emitted functions that are defined in class templates, too (see
the updated "Handle friend functions" code in EmitDeferredDecls,
lib/CodeGen/ModuleBuilder.cpp).  (The updated tests needed to be split out into
their own dllexport-ms-friend.cpp because of the CHECK-NOTs which would have
interfered with subsequent CHECK-DAGs in dllexport.cpp.)

Differential Revision: http://reviews.llvm.org/D18430

Added:
cfe/trunk/test/CodeGenCXX/dllexport-ms-friend.cpp
Modified:
cfe/trunk/include/clang/AST/ASTConsumer.h
cfe/trunk/include/clang/Frontend/MultiplexConsumer.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/CodeGen/CodeGenAction.cpp
cfe/trunk/lib/CodeGen/ModuleBuilder.cpp
cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/include/clang/AST/ASTConsumer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTConsumer.h?rev=264841=264840=264841=diff
==
--- cfe/trunk/include/clang/AST/ASTConsumer.h (original)
+++ cfe/trunk/include/clang/AST/ASTConsumer.h Wed Mar 30 01:27:31 2016
@@ -55,9 +55,9 @@ public:
   /// \returns true to continue parsing, or false to abort parsing.
   virtual bool HandleTopLevelDecl(DeclGroupRef D);
 
-  /// \brief This callback is invoked each time an inline method definition is
-  /// completed.
-  virtual void HandleInlineMethodDefinition(CXXMethodDecl *D) {}
+  /// \brief This callback is invoked each time an inline (method or friend)
+  /// function definition in a class is completed.
+  virtual void HandleInlineFunctionDefinition(FunctionDecl *D) {}
 
   /// HandleInterestingDecl - Handle the specified interesting declaration. 
This
   /// is called by the AST reader when deserializing things that might interest

Modified: cfe/trunk/include/clang/Frontend/MultiplexConsumer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/MultiplexConsumer.h?rev=264841=264840=264841=diff
==
--- cfe/trunk/include/clang/Frontend/MultiplexConsumer.h (original)
+++ cfe/trunk/include/clang/Frontend/MultiplexConsumer.h Wed Mar 30 01:27:31 
2016
@@ -36,7 +36,7 @@ public:
   void Initialize(ASTContext ) override;
   void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override;
   bool HandleTopLevelDecl(DeclGroupRef D) override;
-  void HandleInlineMethodDefinition(CXXMethodDecl *D) override;
+  void HandleInlineFunctionDefinition(FunctionDecl *D) override;
   void HandleInterestingDecl(DeclGroupRef D) override;
   void HandleTranslationUnit(ASTContext ) override;
   void HandleTagDeclDefinition(TagDecl *D) override;

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=264841=264840=264841=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Mar 30 01:27:31 2016
@@ -1773,7 +1773,7 @@ public:
   Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body);
   Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation);
   Decl *ActOnSkippedFunctionBody(Decl *Decl);
-  void ActOnFinishInlineMethodDef(CXXMethodDecl *D);
+  void ActOnFinishInlineFunctionDef(FunctionDecl *D);
 
   /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an
   /// attribute for which parsing is delayed.

Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=264841=264840=264841=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Wed Mar 30 01:27:31 2016
@@ -123,14 +123,14 @@ namespace clang {
   return true;
 }
 
-void HandleInlineMethodDefinition(CXXMethodDecl *D) override {
+void HandleInlineFunctionDefinition(FunctionDecl *D) override {
   PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
  Context->getSourceManager(),
- "LLVM IR generation of inline method");
+ "LLVM IR generation of inline function");
   if (llvm::TimePassesIsEnabled)
 LLVMIRGeneration.startTimer();
 
-  Gen->HandleInlineMethodDefinition(D);
+  Gen->HandleInlineFunctionDefinition(D);
 
 

Re: r263740 - Revert "For MS ABI, emit dllexport friend functions defined inline in class"

2016-03-24 Thread Stephan Bergmann via cfe-commits

On 03/22/2016 06:38 PM, Reid Kleckner wrote:

Ugh, templates and friend function definitions strike again!

I think this is where "semantic" vs. "lexical" DeclContexts come into
play. Try doing D->getLexicalDeclContext()->isDependentContext().


Great, thanks, that's what I'd been searching for.

I've put an updated version up for review now at 
.



On Tue, Mar 22, 2016 at 5:23 AM, Stephan Bergmann > wrote:

On 03/17/2016 09:06 PM, Reid Kleckner via cfe-commits wrote:

Author: rnk
Date: Thu Mar 17 15:06:58 2016
New Revision: 263740

URL: http://llvm.org/viewvc/llvm-project?rev=263740=rev
Log:
Revert "For MS ABI, emit dllexport friend functions defined
inline in class"

This reverts commit r263738.

This appears to cause a failure in
CXX/temp/temp.decls/temp.friend/p1.cpp


Ah, indeed, if you stick "-triple %ms_abi_triple" in
test/CXX/temp/temp.decls/temp.friend/p1.cpp, it would consistently
have failed on all platforms.

The problem is with friend functions defined inline within class
templates (instead of classes), as in

   template struct S { friend void f() {} };

But which MSVC apparently wouldn't emit when parsing the class
template, anyway, so we shouldn't either.

So we should filter out friend functions that are defined within
class templates:

(a) either in Parser::ParseLexedMethodDef
(lib/Parse/ParseCXXInlineMethods.cpp) before calling
ActOnFinishInlineFunctionDef,

(b) or (probably preferably) later in the "Handle friend functions"
block in HandleInlineFunctionDefinition (lib/CodeGen/ModuleBuilder.cpp).

However, I'm having trouble how to determine that condition, in
either case.  For (a), I thought that maybe

   CurTemplateDepthTracker.getDepth() != 0

could work, but apparently doesn't.  And for (b),

   !D->getDeclContext()->isDependentContext()

doesn't work, either (as the context of the declaration presumably
isn't the class template, but rather the surrounding namespace).

Any hints?


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


[PATCH] D18430: For MS ABI, emit dllexport friend functions defined inline in class

2016-03-24 Thread Stephan Bergmann via cfe-commits
sberg created this revision.
sberg added a reviewer: rnk.
sberg added a subscriber: cfe-commits.

...as that is apparently what MSVC does.  This is an updated version of r263738,
which had to be reverted in r263740 due to test failures.  The original version
had erroneously emitted functions that are defined in class templates, too (see
the updated "Handle friend functions" code in EmitDeferredDecls,
lib/CodeGen/ModuleBuilder.cpp).  (The updated tests needed to be split out into
their own dllexport-ms-friend.cpp because of the CHECK-NOTs which would have
interfered with subsequent CHECK-DAGs in dllexport.cpp.)

http://reviews.llvm.org/D18430

Files:
  include/clang/AST/ASTConsumer.h
  include/clang/Frontend/MultiplexConsumer.h
  include/clang/Sema/Sema.h
  lib/CodeGen/CodeGenAction.cpp
  lib/CodeGen/ModuleBuilder.cpp
  lib/Frontend/MultiplexConsumer.cpp
  lib/Parse/ParseCXXInlineMethods.cpp
  lib/Sema/SemaDecl.cpp
  test/CodeGenCXX/dllexport-ms-friend.cpp

Index: test/CodeGenCXX/dllexport-ms-friend.cpp
===
--- /dev/null
+++ test/CodeGenCXX/dllexport-ms-friend.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple %ms_abi_triple -fms-extensions -emit-llvm -O0 -o - %s | FileCheck %s
+
+// Friend functions defined in classes are emitted.
+// CHECK: define weak_odr dllexport void @"\01?friend1@@YAXXZ"()
+struct FuncFriend1 {
+  friend __declspec(dllexport) void friend1() {}
+};
+
+// But function templates and functions defined in class templates are not
+// emitted.
+// CHECK-NOT: friend2
+// CHECK-NOT: friend3
+// CHECK-NOT: friend4
+struct FuncFriend2 {
+  template friend __declspec(dllexport) void friend2() {}
+};
+template struct FuncFriend3 {
+  friend __declspec(dllexport) void friend3() {}
+  struct Inner {
+friend __declspec(dllexport) void friend4() {}
+  };
+};
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -10872,8 +10872,8 @@
   return ActOnStartOfFunctionDef(FnBodyScope, DP, SkipBody);
 }
 
-void Sema::ActOnFinishInlineMethodDef(CXXMethodDecl *D) {
-  Consumer.HandleInlineMethodDefinition(D);
+void Sema::ActOnFinishInlineFunctionDef(FunctionDecl *D) {
+  Consumer.HandleInlineFunctionDefinition(D);
 }
 
 static bool ShouldWarnAboutMissingPrototype(const FunctionDecl *FD, 
Index: lib/Parse/ParseCXXInlineMethods.cpp
===
--- lib/Parse/ParseCXXInlineMethods.cpp
+++ lib/Parse/ParseCXXInlineMethods.cpp
@@ -564,8 +564,10 @@
   if (Tok.is(tok::eof) && Tok.getEofData() == LM.D)
 ConsumeAnyToken();
 
-  if (CXXMethodDecl *MD = dyn_cast_or_null(LM.D))
-Actions.ActOnFinishInlineMethodDef(MD);
+  if (auto *FD = dyn_cast_or_null(LM.D))
+if (isa(FD) ||
+FD->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend))
+  Actions.ActOnFinishInlineFunctionDef(FD);
 }
 
 /// ParseLexedMemberInitializers - We finished parsing the member specification
Index: lib/Frontend/MultiplexConsumer.cpp
===
--- lib/Frontend/MultiplexConsumer.cpp
+++ lib/Frontend/MultiplexConsumer.cpp
@@ -272,9 +272,9 @@
   return Continue;
 }
 
-void MultiplexConsumer::HandleInlineMethodDefinition(CXXMethodDecl *D) {
+void MultiplexConsumer::HandleInlineFunctionDefinition(FunctionDecl *D) {
   for (auto  : Consumers)
-Consumer->HandleInlineMethodDefinition(D);
+Consumer->HandleInlineFunctionDefinition(D);
 }
 
 void MultiplexConsumer::HandleCXXStaticMemberVarInstantiation(VarDecl *VD) {
Index: lib/CodeGen/ModuleBuilder.cpp
===
--- lib/CodeGen/ModuleBuilder.cpp
+++ lib/CodeGen/ModuleBuilder.cpp
@@ -143,27 +143,38 @@
   DeferredInlineMethodDefinitions.clear();
 }
 
-void HandleInlineMethodDefinition(CXXMethodDecl *D) override {
+void HandleInlineFunctionDefinition(FunctionDecl *D) override {
   if (Diags.hasErrorOccurred())
 return;
 
   assert(D->doesThisDeclarationHaveABody());
 
+  // Handle friend functions.
+  if (D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend)) {
+if (Ctx->getTargetInfo().getCXXABI().isMicrosoft()
+&& !D->getLexicalDeclContext()->isDependentContext())
+  Builder->EmitTopLevelDecl(D);
+return;
+  }
+
+  // Otherwise, must be a method.
+  auto MD = cast(D);
+
   // We may want to emit this definition. However, that decision might be
   // based on computing the linkage, and we have to defer that in case we
   // are inside of something that will change the method's final linkage,
   // e.g.
   //   typedef struct {
   // void bar();
   // void foo() { bar(); }
   //   } A;
-  DeferredInlineMethodDefinitions.push_back(D);
+  DeferredInlineMethodDefinitions.push_back(MD);
 
   // Provide some coverage mapping 

Re: r263740 - Revert "For MS ABI, emit dllexport friend functions defined inline in class"

2016-03-22 Thread Stephan Bergmann via cfe-commits

On 03/17/2016 09:06 PM, Reid Kleckner via cfe-commits wrote:

Author: rnk
Date: Thu Mar 17 15:06:58 2016
New Revision: 263740

URL: http://llvm.org/viewvc/llvm-project?rev=263740=rev
Log:
Revert "For MS ABI, emit dllexport friend functions defined inline in class"

This reverts commit r263738.

This appears to cause a failure in
CXX/temp/temp.decls/temp.friend/p1.cpp


Ah, indeed, if you stick "-triple %ms_abi_triple" in 
test/CXX/temp/temp.decls/temp.friend/p1.cpp, it would consistently have 
failed on all platforms.


The problem is with friend functions defined inline within class 
templates (instead of classes), as in


  template struct S { friend void f() {} };

But which MSVC apparently wouldn't emit when parsing the class template, 
anyway, so we shouldn't either.


So we should filter out friend functions that are defined within class 
templates:


(a) either in Parser::ParseLexedMethodDef 
(lib/Parse/ParseCXXInlineMethods.cpp) before calling 
ActOnFinishInlineFunctionDef,


(b) or (probably preferably) later in the "Handle friend functions" 
block in HandleInlineFunctionDefinition (lib/CodeGen/ModuleBuilder.cpp).


However, I'm having trouble how to determine that condition, in either 
case.  For (a), I thought that maybe


  CurTemplateDepthTracker.getDepth() != 0

could work, but apparently doesn't.  And for (b),

  !D->getDeclContext()->isDependentContext()

doesn't work, either (as the context of the declaration presumably isn't 
the class template, but rather the surrounding namespace).


Any hints?



Modified:
 cfe/trunk/include/clang/AST/ASTConsumer.h
 cfe/trunk/include/clang/Frontend/MultiplexConsumer.h
 cfe/trunk/include/clang/Sema/Sema.h
 cfe/trunk/lib/CodeGen/CodeGenAction.cpp
 cfe/trunk/lib/CodeGen/ModuleBuilder.cpp
 cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
 cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
 cfe/trunk/lib/Sema/SemaDecl.cpp
 cfe/trunk/test/CodeGenCXX/dllexport.cpp

Modified: cfe/trunk/include/clang/AST/ASTConsumer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTConsumer.h?rev=263740=263739=263740=diff
==
--- cfe/trunk/include/clang/AST/ASTConsumer.h (original)
+++ cfe/trunk/include/clang/AST/ASTConsumer.h Thu Mar 17 15:06:58 2016
@@ -55,9 +55,9 @@ public:
/// \returns true to continue parsing, or false to abort parsing.
virtual bool HandleTopLevelDecl(DeclGroupRef D);

-  /// \brief This callback is invoked each time an inline (method or friend)
-  /// function definition in a class is completed.
-  virtual void HandleInlineFunctionDefinition(FunctionDecl *D) {}
+  /// \brief This callback is invoked each time an inline method definition is
+  /// completed.
+  virtual void HandleInlineMethodDefinition(CXXMethodDecl *D) {}

/// HandleInterestingDecl - Handle the specified interesting declaration. 
This
/// is called by the AST reader when deserializing things that might 
interest

Modified: cfe/trunk/include/clang/Frontend/MultiplexConsumer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/MultiplexConsumer.h?rev=263740=263739=263740=diff
==
--- cfe/trunk/include/clang/Frontend/MultiplexConsumer.h (original)
+++ cfe/trunk/include/clang/Frontend/MultiplexConsumer.h Thu Mar 17 15:06:58 
2016
@@ -36,7 +36,7 @@ public:
void Initialize(ASTContext ) override;
void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override;
bool HandleTopLevelDecl(DeclGroupRef D) override;
-  void HandleInlineFunctionDefinition(FunctionDecl *D) override;
+  void HandleInlineMethodDefinition(CXXMethodDecl *D) override;
void HandleInterestingDecl(DeclGroupRef D) override;
void HandleTranslationUnit(ASTContext ) override;
void HandleTagDeclDefinition(TagDecl *D) override;

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=263740=263739=263740=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Mar 17 15:06:58 2016
@@ -1773,7 +1773,7 @@ public:
Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body);
Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation);
Decl *ActOnSkippedFunctionBody(Decl *Decl);
-  void ActOnFinishInlineFunctionDef(FunctionDecl *D);
+  void ActOnFinishInlineMethodDef(CXXMethodDecl *D);

/// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an
/// attribute for which parsing is delayed.

Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=263740=263739=263740=diff
==
--- 

Re: [PATCH] D16628: clang-cl: support __cdecl-on-struct anachronism

2016-03-21 Thread Stephan Bergmann via cfe-commits
sberg added a comment.

friendly ping


http://reviews.llvm.org/D16628



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


Re: [PATCH] D15267: For MS ABI, emit dllexport friend functions defined inline in class

2016-03-03 Thread Stephan Bergmann via cfe-commits
sberg added a comment.

Can you please push this, I do not have commit access. Thanks


http://reviews.llvm.org/D15267



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


Re: [PATCH] D16628: clang-cl: support __cdecl-on-struct anachronism

2016-03-03 Thread Stephan Bergmann via cfe-commits
sberg added a comment.

Can you please push this, I do not have commit access.  Thanks


http://reviews.llvm.org/D16628



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


Re: [PATCH] D17567: [GCC] PR23529 Sema part of attrbute abi_tag support

2016-03-02 Thread Stephan Bergmann via cfe-commits
sberg added a subscriber: sberg.


Comment at: lib/Sema/SemaDeclAttr.cpp:4497
@@ +4496,3 @@
+static void handleAbiTagAttr(Sema , Decl *D, const AttributeList ) {
+  SmallVector Tags;
+  for (unsigned I = 0, E = Attr.getNumArgs(); I != E; ++I) {

needs to be SmallVector with current trunk


http://reviews.llvm.org/D17567



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


Re: [PATCH] D15267: For MS ABI, emit dllexport friend functions defined inline in class

2016-03-02 Thread Stephan Bergmann via cfe-commits
sberg added a comment.

friendly ping


http://reviews.llvm.org/D15267



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


Re: [PATCH] D16628: clang-cl: support __cdecl-on-struct anachronism

2016-03-02 Thread Stephan Bergmann via cfe-commits
sberg added a comment.

friendly ping


http://reviews.llvm.org/D16628



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


[PATCH] D16632: clang-cl: Take dllexport from original function decl into account

2016-01-27 Thread Stephan Bergmann via cfe-commits
sberg created this revision.
sberg added a reviewer: rnk.
sberg added a subscriber: cfe-commits.

...in cases where a member function is redeclared as a friend of a nested 
class.  (LibreOffice happens to get tripped up by this.)

http://reviews.llvm.org/D16632

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGenCXX/dllexport.cpp

Index: test/CodeGenCXX/dllexport.cpp
===
--- test/CodeGenCXX/dllexport.cpp
+++ test/CodeGenCXX/dllexport.cpp
@@ -264,6 +264,16 @@
 __declspec(dllexport) void friend1() {}
   void friend2() {}
 
+// MSC-DAG: define dllexport void @"\01?func@Befriended@@SAXXZ"()
+// GNU-DAG: define dllexport void @_ZN10Befriended4funcEv()
+struct __declspec(dllexport) Befriended {
+  static void func();
+  struct Befriending {
+friend void Befriended::func();
+  };
+};
+void Befriended::func() {}
+
 // Implicit declarations can be redeclared with dllexport.
 // MSC-DAG: define dllexport noalias i8* @"\01??2@{{YAPAXI|YAPEAX_K}}@Z"(
 // GNU-DAG: define dllexport noalias i8* @_Znw{{[yj]}}(
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -765,7 +765,8 @@
 
   if (FD->hasAttr())
 F->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass);
-  else if (FD->hasAttr())
+  else if (FD->hasAttr() ||
+   FD->getCanonicalDecl()->hasAttr())
 F->setDLLStorageClass(llvm::GlobalVariable::DLLExportStorageClass);
   else
 F->setDLLStorageClass(llvm::GlobalVariable::DefaultStorageClass);


Index: test/CodeGenCXX/dllexport.cpp
===
--- test/CodeGenCXX/dllexport.cpp
+++ test/CodeGenCXX/dllexport.cpp
@@ -264,6 +264,16 @@
 __declspec(dllexport) void friend1() {}
   void friend2() {}
 
+// MSC-DAG: define dllexport void @"\01?func@Befriended@@SAXXZ"()
+// GNU-DAG: define dllexport void @_ZN10Befriended4funcEv()
+struct __declspec(dllexport) Befriended {
+  static void func();
+  struct Befriending {
+friend void Befriended::func();
+  };
+};
+void Befriended::func() {}
+
 // Implicit declarations can be redeclared with dllexport.
 // MSC-DAG: define dllexport noalias i8* @"\01??2@{{YAPAXI|YAPEAX_K}}@Z"(
 // GNU-DAG: define dllexport noalias i8* @_Znw{{[yj]}}(
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -765,7 +765,8 @@
 
   if (FD->hasAttr())
 F->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass);
-  else if (FD->hasAttr())
+  else if (FD->hasAttr() ||
+   FD->getCanonicalDecl()->hasAttr())
 F->setDLLStorageClass(llvm::GlobalVariable::DLLExportStorageClass);
   else
 F->setDLLStorageClass(llvm::GlobalVariable::DefaultStorageClass);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15267: For MS ABI, emit dllexport friend functions defined inline in class

2016-01-27 Thread Stephan Bergmann via cfe-commits
sberg added inline comments.


Comment at: include/clang/AST/ASTConsumer.h:58-64
@@ -57,5 +57,9 @@
 
   /// \brief This callback is invoked each time an inline method definition is
   /// completed.
   virtual void HandleInlineMethodDefinition(CXXMethodDecl *D) {}
 
+  /// \brief This callback is invoked each time an inline friend function
+  /// definition is completed.
+  virtual void HandleInlineFriendFunctionDefinition(FunctionDecl *D) {}
+

rnk wrote:
> I'm pretty sure we can relax HandleInlineMethodDefinition to take a 
> FunctionDecl and then we don't need the extra AST consumer callback.
...and then also rename it from HandleInlineMethodDefinition to, 
say,HandleInlineFunctionDefinition?  Or better stick with the (then no longer 
accurate) name?


http://reviews.llvm.org/D15267



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


Re: [PATCH] D16628: clang-cl: support __cdecl-on-struct anachronism

2016-01-27 Thread Stephan Bergmann via cfe-commits
sberg updated this revision to Diff 46228.
sberg added a comment.

updated as discussed in the comments


http://reviews.llvm.org/D16628

Files:
  lib/Parse/ParseDeclCXX.cpp
  test/Parser/ms-anachronism.c

Index: test/Parser/ms-anachronism.c
===
--- /dev/null
+++ test/Parser/ms-anachronism.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -triple i686-windows-msvc -fms-extensions -fsyntax-only 
-verify %s
+
+struct {} __cdecl s; // expected-warning {{'__cdecl' only applies to function 
types; type here is 'struct}}
Index: lib/Parse/ParseDeclCXX.cpp
===
--- lib/Parse/ParseDeclCXX.cpp
+++ lib/Parse/ParseDeclCXX.cpp
@@ -1103,6 +1103,15 @@
 return true;
   case tok::colon:
 return CouldBeBitfield; // enum E { ... }   : 2;
+  // Microsoft compatibility
+  case tok::kw___cdecl: // struct foo {...} __cdecl  x;
+  case tok::kw___fastcall:  // struct foo {...} __fastcall   x;
+  case tok::kw___stdcall:   // struct foo {...} __stdcallx;
+  case tok::kw___thiscall:  // struct foo {...} __thiscall   x;
+  case tok::kw___vectorcall:// struct foo {...} __vectorcall x;
+// We will diagnose these calling-convention specifiers on non-function
+// declarations later, so claim they are valid after a type specifier.
+return getLangOpts().MicrosoftExt;
   // Type qualifiers
   case tok::kw_const:   // struct foo {...} const x;
   case tok::kw_volatile:// struct foo {...} volatile  x;


Index: test/Parser/ms-anachronism.c
===
--- /dev/null
+++ test/Parser/ms-anachronism.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -triple i686-windows-msvc -fms-extensions -fsyntax-only -verify %s
+
+struct {} __cdecl s; // expected-warning {{'__cdecl' only applies to function types; type here is 'struct}}
Index: lib/Parse/ParseDeclCXX.cpp
===
--- lib/Parse/ParseDeclCXX.cpp
+++ lib/Parse/ParseDeclCXX.cpp
@@ -1103,6 +1103,15 @@
 return true;
   case tok::colon:
 return CouldBeBitfield; // enum E { ... }   : 2;
+  // Microsoft compatibility
+  case tok::kw___cdecl: // struct foo {...} __cdecl  x;
+  case tok::kw___fastcall:  // struct foo {...} __fastcall   x;
+  case tok::kw___stdcall:   // struct foo {...} __stdcallx;
+  case tok::kw___thiscall:  // struct foo {...} __thiscall   x;
+  case tok::kw___vectorcall:// struct foo {...} __vectorcall x;
+// We will diagnose these calling-convention specifiers on non-function
+// declarations later, so claim they are valid after a type specifier.
+return getLangOpts().MicrosoftExt;
   // Type qualifiers
   case tok::kw_const:   // struct foo {...} const x;
   case tok::kw_volatile:// struct foo {...} volatile  x;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D16632: clang-cl: Take dllexport from original function decl into account

2016-01-27 Thread Stephan Bergmann via cfe-commits
sberg added a comment.

Yeah, my first naive finding when encountering the error was that it went away 
when unconditionally using FD->getCanonicalDecl() instead of FD in that 
if-else-if block. But that caused other parts of clang-test to fail. The 
current version passes all tests (happens to), but indeed does not feel "right" 
at all.


http://reviews.llvm.org/D16632



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


Re: [PATCH] D15267: For MS ABI, emit dllexport friend functions defined inline in class

2016-01-27 Thread Stephan Bergmann via cfe-commits
sberg updated this revision to Diff 46227.
sberg added a comment.

updated as discussed in the comments


http://reviews.llvm.org/D15267

Files:
  include/clang/AST/ASTConsumer.h
  include/clang/Frontend/MultiplexConsumer.h
  include/clang/Sema/Sema.h
  lib/CodeGen/CodeGenAction.cpp
  lib/CodeGen/ModuleBuilder.cpp
  lib/Frontend/MultiplexConsumer.cpp
  lib/Parse/ParseCXXInlineMethods.cpp
  lib/Sema/SemaDecl.cpp
  test/CodeGenCXX/dllexport.cpp

Index: test/CodeGenCXX/dllexport.cpp
===
--- test/CodeGenCXX/dllexport.cpp
+++ test/CodeGenCXX/dllexport.cpp
@@ -255,9 +255,11 @@
 // GNU-DAG: define dllexport void @_Z7friend1v()
 // MSC-DAG: define dllexport void @"\01?friend2@@YAXXZ"()
 // GNU-DAG: define dllexport void @_Z7friend2v()
+// MSC-DAG: define weak_odr dllexport void @"\01?friend3@@YAXXZ"()
 struct FuncFriend {
   friend __declspec(dllexport) void friend1();
   friend __declspec(dllexport) void friend2();
+  friend __declspec(dllexport) void friend3() {}
 };
 __declspec(dllexport) void friend1() {}
   void friend2() {}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -10701,8 +10701,8 @@
   return ActOnStartOfFunctionDef(FnBodyScope, DP, SkipBody);
 }
 
-void Sema::ActOnFinishInlineMethodDef(CXXMethodDecl *D) {
-  Consumer.HandleInlineMethodDefinition(D);
+void Sema::ActOnFinishInlineFunctionDef(FunctionDecl *D) {
+  Consumer.HandleInlineFunctionDefinition(D);
 }
 
 static bool ShouldWarnAboutMissingPrototype(const FunctionDecl *FD, 
Index: lib/Parse/ParseCXXInlineMethods.cpp
===
--- lib/Parse/ParseCXXInlineMethods.cpp
+++ lib/Parse/ParseCXXInlineMethods.cpp
@@ -563,8 +563,10 @@
   if (Tok.is(tok::eof) && Tok.getEofData() == LM.D)
 ConsumeAnyToken();
 
-  if (CXXMethodDecl *MD = dyn_cast_or_null(LM.D))
-Actions.ActOnFinishInlineMethodDef(MD);
+  if (auto *FD = dyn_cast_or_null(LM.D))
+if (isa(FD) ||
+FD->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend))
+  Actions.ActOnFinishInlineFunctionDef(FD);
 }
 
 /// ParseLexedMemberInitializers - We finished parsing the member specification
Index: lib/Frontend/MultiplexConsumer.cpp
===
--- lib/Frontend/MultiplexConsumer.cpp
+++ lib/Frontend/MultiplexConsumer.cpp
@@ -272,9 +272,9 @@
   return Continue;
 }
 
-void MultiplexConsumer::HandleInlineMethodDefinition(CXXMethodDecl *D) {
+void MultiplexConsumer::HandleInlineFunctionDefinition(FunctionDecl *D) {
   for (auto  : Consumers)
-Consumer->HandleInlineMethodDefinition(D);
+Consumer->HandleInlineFunctionDefinition(D);
 }
 
 void MultiplexConsumer::HandleCXXStaticMemberVarInstantiation(VarDecl *VD) {
Index: lib/CodeGen/ModuleBuilder.cpp
===
--- lib/CodeGen/ModuleBuilder.cpp
+++ lib/CodeGen/ModuleBuilder.cpp
@@ -142,27 +142,37 @@
   DeferredInlineMethodDefinitions.clear();
 }
 
-void HandleInlineMethodDefinition(CXXMethodDecl *D) override {
+void HandleInlineFunctionDefinition(FunctionDecl *D) override {
   if (Diags.hasErrorOccurred())
 return;
 
   assert(D->doesThisDeclarationHaveABody());
 
+  // Handle friend functions.
+  if (D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend)) {
+if (Ctx->getTargetInfo().getCXXABI().isMicrosoft())
+  Builder->EmitTopLevelDecl(D);
+return;
+  }
+
+  // Otherwise, must be a method.
+  auto MD = cast(D);
+
   // We may want to emit this definition. However, that decision might be
   // based on computing the linkage, and we have to defer that in case we
   // are inside of something that will change the method's final linkage,
   // e.g.
   //   typedef struct {
   // void bar();
   // void foo() { bar(); }
   //   } A;
-  DeferredInlineMethodDefinitions.push_back(D);
+  DeferredInlineMethodDefinitions.push_back(MD);
 
   // Provide some coverage mapping even for methods that aren't emitted.
   // Don't do this for templated classes though, as they may not be
   // instantiable.
-  if (!D->getParent()->getDescribedClassTemplate())
-Builder->AddDeferredUnusedCoverageMapping(D);
+  if (!MD->getParent()->getDescribedClassTemplate())
+Builder->AddDeferredUnusedCoverageMapping(MD);
 }
 
 /// HandleTagDeclDefinition - This callback is invoked each time a TagDecl
Index: lib/CodeGen/CodeGenAction.cpp
===
--- lib/CodeGen/CodeGenAction.cpp
+++ lib/CodeGen/CodeGenAction.cpp
@@ -123,14 +123,14 @@
   return true;
 }
 
-void HandleInlineMethodDefinition(CXXMethodDecl *D) override {
+void HandleInlineFunctionDefinition(FunctionDecl *D) 

Re: [PATCH] D16628: clang-cl: support __cdecl-on-struct anachronism

2016-01-27 Thread Stephan Bergmann via cfe-commits
sberg added inline comments.


Comment at: lib/Parse/ParseDeclCXX.cpp:1107
@@ +1106,3 @@
+  // Microsoft compatibility
+  case tok::kw___cdecl: // struct foo {...} __cdecl   x; // C4229
+if (!getLangOpts().MicrosoftExt)

majnemer wrote:
> What about __fastcall, etc.
To be honest, I have no idea what the full set of keywords is that would need 
to be taken care of here (so hoped I would get away with just the one I 
happened to come across ;)


http://reviews.llvm.org/D16628



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


[PATCH] D16628: clang-cl: support __cdecl-on-struct anachronism

2016-01-27 Thread Stephan Bergmann via cfe-commits
sberg created this revision.
sberg added a reviewer: rnk.
sberg added a subscriber: cfe-commits.

The Microsoft compiler emits

  warning C4229: anachronism used : modifiers on data are ignored

for

  struct {} __cdecl s;

but ICU's gendict can generate such (and does when building LibreOffice), so 
accepting this in clang-cl too would be useful.

http://reviews.llvm.org/D16628

Files:
  lib/Parse/ParseDeclCXX.cpp
  test/Parser/ms-anachronism.c

Index: test/Parser/ms-anachronism.c
===
--- /dev/null
+++ test/Parser/ms-anachronism.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -triple i686-windows-msvc -fms-extensions -fsyntax-only 
-verify %s
+
+struct {} __cdecl s; // expected-warning {{'__cdecl' only applies to function 
types; type here is 'struct}}
Index: lib/Parse/ParseDeclCXX.cpp
===
--- lib/Parse/ParseDeclCXX.cpp
+++ lib/Parse/ParseDeclCXX.cpp
@@ -1103,6 +1103,11 @@
 return true;
   case tok::colon:
 return CouldBeBitfield; // enum E { ... }   : 2;
+  // Microsoft compatibility
+  case tok::kw___cdecl: // struct foo {...} __cdecl   x; // C4229
+if (!getLangOpts().MicrosoftExt)
+  break;
+// fall through
   // Type qualifiers
   case tok::kw_const:   // struct foo {...} const x;
   case tok::kw_volatile:// struct foo {...} volatile  x;


Index: test/Parser/ms-anachronism.c
===
--- /dev/null
+++ test/Parser/ms-anachronism.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -triple i686-windows-msvc -fms-extensions -fsyntax-only -verify %s
+
+struct {} __cdecl s; // expected-warning {{'__cdecl' only applies to function types; type here is 'struct}}
Index: lib/Parse/ParseDeclCXX.cpp
===
--- lib/Parse/ParseDeclCXX.cpp
+++ lib/Parse/ParseDeclCXX.cpp
@@ -1103,6 +1103,11 @@
 return true;
   case tok::colon:
 return CouldBeBitfield; // enum E { ... }   : 2;
+  // Microsoft compatibility
+  case tok::kw___cdecl: // struct foo {...} __cdecl   x; // C4229
+if (!getLangOpts().MicrosoftExt)
+  break;
+// fall through
   // Type qualifiers
   case tok::kw_const:   // struct foo {...} const x;
   case tok::kw_volatile:// struct foo {...} volatile  x;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D16301: Allow mode attribute for member variables again

2016-01-19 Thread Stephan Bergmann via cfe-commits
sberg added a comment.

Please somebody push this for me; I don't have commit access. Thanks


http://reviews.llvm.org/D16301



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


Re: [PATCH] D16301: Allow mode attribute for member variables again

2016-01-19 Thread Stephan Bergmann via cfe-commits
sberg updated this revision to Diff 45310.
sberg added a comment.

oops, had erroneously based it on some other local patch; rebased now


http://reviews.llvm.org/D16301

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/AttributeList.h
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/attr-mode.c

Index: test/Sema/attr-mode.c
===
--- test/Sema/attr-mode.c
+++ test/Sema/attr-mode.c
@@ -24,8 +24,8 @@
 
 int **__attribute((mode(QI)))* i32;  // expected-error{{mode attribute}}
 
-__attribute__((mode(QI))) int invalid_func() { return 1; } // 
expected-error{{'mode' attribute only applies to variables and typedefs}}
-enum invalid_enum { A1 __attribute__((mode(QI))) }; // expected-error{{'mode' 
attribute only applies to variables and typedefs}}
+__attribute__((mode(QI))) int invalid_func() { return 1; } // 
expected-error{{'mode' attribute only applies to variables, fields and 
typedefs}}
+enum invalid_enum { A1 __attribute__((mode(QI))) }; // expected-error{{'mode' 
attribute only applies to variables, fields and typedefs}}
 
 typedef _Complex double c32 __attribute((mode(SC)));
 int c32_test[sizeof(c32) == 8 ? 1 : -1];
@@ -76,3 +76,7 @@
 #else
 #error Unknown test architecture.
 #endif
+
+struct S {
+  int n __attribute((mode(HI)));
+};
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3392,7 +3392,7 @@
   if (TypedefNameDecl *TD = dyn_cast(D))
 OldTy = TD->getUnderlyingType();
   else
-OldTy = cast(D)->getType();
+OldTy = cast(D)->getType();
 
   // Base type can also be a vector type (see PR17453).
   // Distinguish between base type and base element type.
@@ -3465,7 +3465,7 @@
   if (TypedefNameDecl *TD = dyn_cast(D))
 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
   else
-cast(D)->setType(NewTy);
+cast(D)->setType(NewTy);
 
   D->addAttr(::new (S.Context)
  ModeAttr(Attr.getRange(), S.Context, Name,
Index: include/clang/Sema/AttributeList.h
===
--- include/clang/Sema/AttributeList.h
+++ include/clang/Sema/AttributeList.h
@@ -855,7 +855,8 @@
   ExpectedStructOrTypedef,
   ExpectedObjectiveCInterfaceOrProtocol,
   ExpectedKernelFunction,
-  ExpectedFunctionWithProtoType
+  ExpectedFunctionWithProtoType,
+  ExpectedVariableFieldOrTypedef
 };
 
 }  // end namespace clang
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -2441,7 +2441,8 @@
   "Objective-C instance methods|init methods of interface or class extension 
declarations|"
   "variables, functions and classes|Objective-C protocols|"
   "functions and global variables|structs, unions, and typedefs|structs and 
typedefs|"
-  "interface or protocol declarations|kernel functions|non-K 
functions}1">,
+  "interface or protocol declarations|kernel functions|non-K 
functions|"
+  "variables, fields and typedefs}1">,
   InGroup;
 def err_attribute_wrong_decl_type : Error;
 def warn_type_attribute_wrong_type : Warning<
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -879,8 +879,8 @@
 
 def Mode : Attr {
   let Spellings = [GCC<"mode">];
-  let Subjects = SubjectList<[Var, TypedefName], ErrorDiag,
- "ExpectedVariableOrTypedef">;
+  let Subjects = SubjectList<[Var, TypedefName, Field], ErrorDiag,
+ "ExpectedVariableFieldOrTypedef">;
   let Args = [IdentifierArgument<"Mode">];
   let Documentation = [Undocumented];
 }


Index: test/Sema/attr-mode.c
===
--- test/Sema/attr-mode.c
+++ test/Sema/attr-mode.c
@@ -24,8 +24,8 @@
 
 int **__attribute((mode(QI)))* i32;  // expected-error{{mode attribute}}
 
-__attribute__((mode(QI))) int invalid_func() { return 1; } // expected-error{{'mode' attribute only applies to variables and typedefs}}
-enum invalid_enum { A1 __attribute__((mode(QI))) }; // expected-error{{'mode' attribute only applies to variables and typedefs}}
+__attribute__((mode(QI))) int invalid_func() { return 1; } // expected-error{{'mode' attribute only applies to variables, fields and typedefs}}
+enum invalid_enum { A1 __attribute__((mode(QI))) }; // expected-error{{'mode' attribute only applies to variables, fields and typedefs}}
 
 typedef _Complex double c32 __attribute((mode(SC)));
 int c32_test[sizeof(c32) == 8 ? 1 : -1];
@@ -76,3 +76,7 @@
 #else
 #error Unknown test architecture.
 #endif
+
+struct S {
+  int n __attribute((mode(HI)));
+};
Index: lib/Sema/SemaDeclAttr.cpp

Re: [PATCH] D16301: Allow mode attribute for member variables again

2016-01-19 Thread Stephan Bergmann via cfe-commits
sberg updated this revision to Diff 45268.
sberg added a comment.

updated the diagnostic message to mention fields in addition to variables and 
typedefs


http://reviews.llvm.org/D16301

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/AttributeList.h
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/attr-mode.c

Index: test/Sema/attr-mode.c
===
--- test/Sema/attr-mode.c
+++ test/Sema/attr-mode.c
@@ -24,8 +24,8 @@
 
 int **__attribute((mode(QI)))* i32;  // expected-error{{mode attribute}}
 
-__attribute__((mode(QI))) int invalid_func() { return 1; } // 
expected-error{{'mode' attribute only applies to variables and typedefs}}
-enum invalid_enum { A1 __attribute__((mode(QI))) }; // expected-error{{'mode' 
attribute only applies to variables and typedefs}}
+__attribute__((mode(QI))) int invalid_func() { return 1; } // 
expected-error{{'mode' attribute only applies to variables, fields and 
typedefs}}
+enum invalid_enum { A1 __attribute__((mode(QI))) }; // expected-error{{'mode' 
attribute only applies to variables, fields and typedefs}}
 
 typedef _Complex double c32 __attribute((mode(SC)));
 int c32_test[sizeof(c32) == 8 ? 1 : -1];
@@ -76,3 +76,7 @@
 #else
 #error Unknown test architecture.
 #endif
+
+struct S {
+  int n __attribute((mode(HI)));
+};
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3392,7 +3392,7 @@
   if (TypedefNameDecl *TD = dyn_cast(D))
 OldTy = TD->getUnderlyingType();
   else
-OldTy = cast(D)->getType();
+OldTy = cast(D)->getType();
 
   // Base type can also be a vector type (see PR17453).
   // Distinguish between base type and base element type.
@@ -3465,7 +3465,7 @@
   if (TypedefNameDecl *TD = dyn_cast(D))
 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
   else
-cast(D)->setType(NewTy);
+cast(D)->setType(NewTy);
 
   D->addAttr(::new (S.Context)
  ModeAttr(Attr.getRange(), S.Context, Name,
Index: include/clang/Sema/AttributeList.h
===
--- include/clang/Sema/AttributeList.h
+++ include/clang/Sema/AttributeList.h
@@ -856,7 +856,8 @@
   ExpectedObjectiveCInterfaceOrProtocol,
   ExpectedKernelFunction,
   ExpectedFunctionWithProtoType,
-  ExpectedStructClassVariableFunctionMethodOrInlineNamespace
+  ExpectedStructClassVariableFunctionMethodOrInlineNamespace,
+  ExpectedVariableFieldOrTypedef
 };
 
 }  // end namespace clang
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -2442,7 +2442,8 @@
   "variables, functions and classes|Objective-C protocols|"
   "functions and global variables|structs, unions, and typedefs|structs and 
typedefs|"
   "interface or protocol declarations|kernel functions|non-K 
functions|"
-  "structs, classes, variables, functions, methods and inline namespaces}1">,
+  "structs, classes, variables, functions, methods and inline namespaces|"
+  "variables, fields and typedefs}1">,
   InGroup;
 def err_attribute_wrong_decl_type : Error;
 def warn_type_attribute_wrong_type : Warning<
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -887,8 +887,8 @@
 
 def Mode : Attr {
   let Spellings = [GCC<"mode">];
-  let Subjects = SubjectList<[Var, TypedefName], ErrorDiag,
- "ExpectedVariableOrTypedef">;
+  let Subjects = SubjectList<[Var, TypedefName, Field], ErrorDiag,
+ "ExpectedVariableFieldOrTypedef">;
   let Args = [IdentifierArgument<"Mode">];
   let Documentation = [Undocumented];
 }


Index: test/Sema/attr-mode.c
===
--- test/Sema/attr-mode.c
+++ test/Sema/attr-mode.c
@@ -24,8 +24,8 @@
 
 int **__attribute((mode(QI)))* i32;  // expected-error{{mode attribute}}
 
-__attribute__((mode(QI))) int invalid_func() { return 1; } // expected-error{{'mode' attribute only applies to variables and typedefs}}
-enum invalid_enum { A1 __attribute__((mode(QI))) }; // expected-error{{'mode' attribute only applies to variables and typedefs}}
+__attribute__((mode(QI))) int invalid_func() { return 1; } // expected-error{{'mode' attribute only applies to variables, fields and typedefs}}
+enum invalid_enum { A1 __attribute__((mode(QI))) }; // expected-error{{'mode' attribute only applies to variables, fields and typedefs}}
 
 typedef _Complex double c32 __attribute((mode(SC)));
 int c32_test[sizeof(c32) == 8 ? 1 : -1];
@@ -76,3 +76,7 @@
 #else
 #error Unknown test architecture.
 #endif
+
+struct S {
+  int n __attribute((mode(HI)));
+};
Index: 

[PATCH] D16301: Allow mode attribute for member variables again

2016-01-18 Thread Stephan Bergmann via cfe-commits
sberg created this revision.
sberg added reviewers: ABataev, aaron.ballman.
sberg added a subscriber: cfe-commits.

...after r257868 "PR26111: segmentation fault with __attribute__((mode(QI))) on 
function declaration" (presumably accidentally) restricted it to variables and 
typedefs, excluding member variables (aka fields).  That broke building 
LibreOffice, which, in bridges/source/cpp_uno/gcc3_linux_x86-64/share.hxx, 
contains a "typedef-unwound" copy of struct _Unwind_Except from GCC's 
libgcc/unwind-generic.h.

http://reviews.llvm.org/D16301

Files:
  include/clang/Basic/Attr.td
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/attr-mode.c

Index: test/Sema/attr-mode.c
===
--- test/Sema/attr-mode.c
+++ test/Sema/attr-mode.c
@@ -76,3 +76,7 @@
 #else
 #error Unknown test architecture.
 #endif
+
+struct S {
+  int n __attribute((mode(HI)));
+};
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3392,7 +3392,7 @@
   if (TypedefNameDecl *TD = dyn_cast(D))
 OldTy = TD->getUnderlyingType();
   else
-OldTy = cast(D)->getType();
+OldTy = cast(D)->getType();
 
   // Base type can also be a vector type (see PR17453).
   // Distinguish between base type and base element type.
@@ -3465,7 +3465,7 @@
   if (TypedefNameDecl *TD = dyn_cast(D))
 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
   else
-cast(D)->setType(NewTy);
+cast(D)->setType(NewTy);
 
   D->addAttr(::new (S.Context)
  ModeAttr(Attr.getRange(), S.Context, Name,
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -887,7 +887,7 @@
 
 def Mode : Attr {
   let Spellings = [GCC<"mode">];
-  let Subjects = SubjectList<[Var, TypedefName], ErrorDiag,
+  let Subjects = SubjectList<[Var, TypedefName, Field], ErrorDiag,
  "ExpectedVariableOrTypedef">;
   let Args = [IdentifierArgument<"Mode">];
   let Documentation = [Undocumented];


Index: test/Sema/attr-mode.c
===
--- test/Sema/attr-mode.c
+++ test/Sema/attr-mode.c
@@ -76,3 +76,7 @@
 #else
 #error Unknown test architecture.
 #endif
+
+struct S {
+  int n __attribute((mode(HI)));
+};
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3392,7 +3392,7 @@
   if (TypedefNameDecl *TD = dyn_cast(D))
 OldTy = TD->getUnderlyingType();
   else
-OldTy = cast(D)->getType();
+OldTy = cast(D)->getType();
 
   // Base type can also be a vector type (see PR17453).
   // Distinguish between base type and base element type.
@@ -3465,7 +3465,7 @@
   if (TypedefNameDecl *TD = dyn_cast(D))
 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
   else
-cast(D)->setType(NewTy);
+cast(D)->setType(NewTy);
 
   D->addAttr(::new (S.Context)
  ModeAttr(Attr.getRange(), S.Context, Name,
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -887,7 +887,7 @@
 
 def Mode : Attr {
   let Spellings = [GCC<"mode">];
-  let Subjects = SubjectList<[Var, TypedefName], ErrorDiag,
+  let Subjects = SubjectList<[Var, TypedefName, Field], ErrorDiag,
  "ExpectedVariableOrTypedef">;
   let Args = [IdentifierArgument<"Mode">];
   let Documentation = [Undocumented];
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12834: add gcc abi_tag support

2015-12-09 Thread Stephan Bergmann via cfe-commits
sberg added a subscriber: sberg.
sberg added a comment.

I can't figure out how to add code to someone else's Phabricator review, so 
sent it to the mailing list 
instead: 
 
 
"[PATCH] Re http://reviews.llvm.org/D12834 add gcc abi_tag support."


Repository:
  rL LLVM

http://reviews.llvm.org/D12834



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


[PATCH] Re D12834 add gcc abi_tag support

2015-12-09 Thread Stephan Bergmann via cfe-commits
I can't figure out how to add code to someone else's Phabricator review 
, so sending it here to the mailing list 
instead.


* Attached 0001-add-gcc-abi_tag-support.patch rebases 
 against recent trunk (there 
were three minor conflicts that needed resolution).


* Attached 0002-Fix-handling-of-abi_tag-attribute-on-namespaces.patch 
fixes the handling of abi_tag attributes on namespaces to match GCC 
behavior.
>From 88aa3688d46ecb49ba236da6f761053b75b01528 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20B=C3=BChler?= 
Date: Thu, 3 Dec 2015 14:51:50 +0100
Subject: [PATCH 1/2] add gcc abi_tag support


conflicts:
	include/clang/Basic/DiagnosticSemaKinds.td
	include/clang/Sema/AttributeList.h
	lib/AST/ItaniumMangle.cpp
---
 docs/ItaniumMangleAbiTags.rst  |  90 +
 include/clang/Basic/Attr.td|   8 +
 include/clang/Basic/DiagnosticSemaKinds.td |  10 +-
 include/clang/Sema/AttributeList.h |   3 +-
 lib/AST/ItaniumMangle.cpp  | 525 -
 lib/Sema/SemaDeclAttr.cpp  |  55 +++
 6 files changed, 609 insertions(+), 82 deletions(-)
 create mode 100644 docs/ItaniumMangleAbiTags.rst

diff --git a/docs/ItaniumMangleAbiTags.rst b/docs/ItaniumMangleAbiTags.rst
new file mode 100644
index 000..d390162
--- /dev/null
+++ b/docs/ItaniumMangleAbiTags.rst
@@ -0,0 +1,90 @@
+
+Abi Tags
+
+
+Introduction
+
+
+This text tries to describe gcc semantic for mangling "abi_tag" attributes
+described in https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html
+
+There is no guarantee the following rules are correct, complete or make sense
+in any way as they were determined empirically by experiments with gcc5.
+
+Declaration
+===
+
+Abi tags are declared in an abi_tag attribute and can be applied to a
+function, variable, class or inline namespace declaration. The attribute takes
+one or more strings (called tags); the order does not matter.
+
+See https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html for
+details.
+
+Tags on an inline namespace are called "implicit tags", all other tags are
+"explicit tags".
+
+Mangling
+
+
+All tags that are "active" on a  are emitted after the
+, before  or , and are part of
+the same  the  is.
+
+They are mangled as:
+
+ ::= *   # sort by name
+ ::= B 
+
+Example:
+
+__attribute__((abi_tag("test")))
+void Func();
+
+gets mangled as: _Z4FuncB4testv (prettified as `Func[abi:test]()`)
+
+Active tags
+===
+
+A namespace has never any active tags; for types (class / struct / union /
+enum) the explicit tags are the active tags.
+
+For variables and functions the active tags are the explicit tags plus any
+"required tags" which are not in the "available tags" set:
+
+derived-tags := (required-tags - available-tags)
+active-tags := explicit-tags + derived-tags
+
+Required tags for a function
+
+
+If a function is used as a local scope for another name, and is part of
+another function as local scope, it doesn't have any required tags.
+
+If a function is used as a local scope for a guard variable name, it doesn't
+have any required tags.
+
+Otherwise the function requires any implicit or explicit tag used in the name
+for the return type.
+
+Required tags for a variable
+
+
+A variable requires any implicit or explicit tag used in its type.
+
+Available tags
+==
+
+All tags used in the prefix and in the template arguments for a name are
+available; for functions also all  tags from the  (which
+might include the return type for template functions) are available.
+
+For s all active tags used in the local part () are available, but not implicit tags which were not active!
+
+Implicit and explicit tags used in the  for a function (as
+in the type of a cast operator) are NOT available.
+
+Example: a cast operator to std::string (which is
+std::__cxx11::basic_string<...>) will use 'cxx11' as active tag, as it is
+required from the return type `std::string` but not available.
diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td
index d5ba722..36be1fc 100644
--- a/include/clang/Basic/Attr.td
+++ b/include/clang/Basic/Attr.td
@@ -349,6 +349,14 @@ class IgnoredAttr : Attr {
 // Attributes begin here
 //
 
+def AbiTag : Attr {
+  let Spellings = [GCC<"abi_tag">];
+  let Args = [VariadicStringArgument<"Tags">];
+  let Subjects = SubjectList<[Struct, Var, Function, Namespace], ErrorDiag,
+ "ExpectedStructClassVariableFunctionMethodOrInlineNamespace">;
+  let Documentation = [Undocumented];
+}
+
 def AddressSpace : TypeAttr {
   let Spellings = [GNU<"address_space">];
   let Args = [IntArgument<"AddressSpace">];
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td 

Re: [PATCH] D13386: PR24115: Don't instantiate constexpr function templates in decltype

2015-10-06 Thread Stephan Bergmann via cfe-commits
sberg abandoned this revision.
sberg added a comment.

Ah, I see.  I'll wait for that approach to be implemented then.


http://reviews.llvm.org/D13386



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


[PATCH] D13386: PR24115: Don't instantiate constexpr function templates in decltype

2015-10-02 Thread Stephan Bergmann via cfe-commits
sberg created this revision.
sberg added reviewers: cfe-commits, rsmith.

As discussed in [[ https://llvm.org/bugs/show_bug.cgi?id=24115 | "llvm-nm fails 
to build with gcc 5.1's libstdc++," ]] both llvm-nm and LibreOffice fail to 
build against GCC 5.1 libstdc++, due to Clang trying (and failing) to 
instantiate constexpr function templates referenced from within a decltype.
See [[ 
https://groups.google.com/a/isocpp.org/forum/#!topic/std-discussion/6udLpHDvShU 
| "Implicit instantiation of constexpr function template specialization called 
in decltype expression?" ]] for a stripped-down test case and a discussion why 
the Clang behaviour is considered wrong.
There is a comment in test/SemaTemplate/constexpr-instantiate.cpp claiming this 
behaviour is in line with g++, but I cannot reproduce that neither with some 
GCC 5.1.1 nor with a recent GCC trunk build.  The comment also says "FIXME: 
None of this is required by the C++ standard. The rules in this area are poorly 
specified, so this is subject to change.", and from the above build breakage I 
think it would be best to change the behaviour to not instantiate constexpr 
function templates merely because they are referenced from within a decltype.  
(Doing so of course breaks the test corresponding to that comment, so turn that 
test around to check the changed behaviour now.)

http://reviews.llvm.org/D13386

Files:
  lib/Sema/SemaExpr.cpp
  test/SemaTemplate/constexpr-instantiate.cpp

Index: test/SemaTemplate/constexpr-instantiate.cpp
===
--- test/SemaTemplate/constexpr-instantiate.cpp
+++ test/SemaTemplate/constexpr-instantiate.cpp
@@ -77,37 +77,23 @@
 }
 
 namespace Unevaluated {
-  // We follow g++ in treating any reference to a constexpr function template
-  // specialization as requiring an instantiation, even if it occurs in an
-  // unevaluated context.
-  //
-  // We go slightly further than g++, and also trigger the implicit definition
-  // of a defaulted special member in the same circumstances. This seems scary,
-  // since a lot of classes have constexpr special members in C++11, but the
-  // only observable impact should be the implicit instantiation of constexpr
-  // special member templates (defaulted special members should only be
-  // generated if they are well-formed, and non-constexpr special members in a
-  // base or member cause the class's special member to not be constexpr).
-  //
-  // FIXME: None of this is required by the C++ standard. The rules in this
-  //area are poorly specified, so this is subject to change.
   namespace NotConstexpr {
 template struct S {
   S() : n(0) {}
   S(const S&) : n(T::error) {}
   int n;
 };
 struct U : S {};
-decltype(U(U())) u; // ok, don't instantiate S::S() because it wasn't 
declared constexpr
+decltype(U(U())) u; // ok, don't instantiate S::S()
   }
   namespace Constexpr {
 template struct S {
   constexpr S() : n(0) {}
-  constexpr S(const S&) : n(T::error) {} // expected-error {{has no 
members}}
+  constexpr S(const S&) : n(T::error) {}
   int n;
 };
-struct U : S {}; // expected-note {{instantiation}}
-decltype(U(U())) u; // expected-note {{here}}
+struct U : S {};
+decltype(U(U())) u; // ok, don't instantiate S::S()
   }
 
   namespace PR11851_Comment0 {
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -12414,7 +12414,8 @@
 // However, they cannot be referenced if they are deleted, and they are
 // deleted whenever the implicit definition of the special member would
 // fail.
-if (!Func->isConstexpr() || Func->getBody())
+if (!Func->isConstexpr() || Func->getBody() ||
+ExprEvalContexts.back().IsDecltype)
   return;
 CXXMethodDecl *MD = dyn_cast(Func);
 if (!Func->isImplicitlyInstantiable() && (!MD || MD->isUserProvided()))


Index: test/SemaTemplate/constexpr-instantiate.cpp
===
--- test/SemaTemplate/constexpr-instantiate.cpp
+++ test/SemaTemplate/constexpr-instantiate.cpp
@@ -77,37 +77,23 @@
 }
 
 namespace Unevaluated {
-  // We follow g++ in treating any reference to a constexpr function template
-  // specialization as requiring an instantiation, even if it occurs in an
-  // unevaluated context.
-  //
-  // We go slightly further than g++, and also trigger the implicit definition
-  // of a defaulted special member in the same circumstances. This seems scary,
-  // since a lot of classes have constexpr special members in C++11, but the
-  // only observable impact should be the implicit instantiation of constexpr
-  // special member templates (defaulted special members should only be
-  // generated if they are well-formed, and non-constexpr special members in a
-  // base or member cause the class's special member to not be 

Re: [PATCH] D12359: New warning -Wnonconst-parameter when a pointer parameter can be const

2015-08-26 Thread Stephan Bergmann via cfe-commits
sberg added a subscriber: sberg.
sberg added a comment.

causes false positive for

  char * f(char *);
  char * g(char * p) { return f(p); }


http://reviews.llvm.org/D12359



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