Re: r313955 - Give external linkage and mangling to lambdas inside inline variables and variable templates.

2017-09-23 Thread NAKAMURA Takumi via cfe-commits
It seems libcxx (with -fmodules) dislikes this change. Any idea?
http://bb.pgr.jp/builders/bootstrap-clang-libcxx-lld-i686-linux/builds/238

On Fri, Sep 22, 2017 at 1:26 PM Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Thu Sep 21 21:25:05 2017
> New Revision: 313955
>
> URL: http://llvm.org/viewvc/llvm-project?rev=313955&view=rev
> Log:
> Give external linkage and mangling to lambdas inside inline variables and
> variable templates.
>
> This implements the proposed approach in
> https://github.com/itanium-cxx-abi/cxx-abi/issues/33
>
> This reinstates r313827, reverted in r313856, with a fix for the
> 'out-of-bounds
> enumeration value' ubsan error in that change.
>
> Modified:
> cfe/trunk/lib/AST/Decl.cpp
> cfe/trunk/lib/AST/ItaniumMangle.cpp
> cfe/trunk/lib/AST/Linkage.h
> cfe/trunk/lib/Parse/ParseDecl.cpp
> cfe/trunk/lib/Sema/SemaDeclCXX.cpp
> cfe/trunk/lib/Sema/SemaLambda.cpp
> cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
> cfe/trunk/test/CodeGenCXX/mangle-lambdas.cpp
> cfe/trunk/test/SemaCXX/vartemplate-lambda.cpp
> cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp
>
> Modified: cfe/trunk/lib/AST/Decl.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=313955&r1=313954&r2=313955&view=diff
>
> ==
> --- cfe/trunk/lib/AST/Decl.cpp (original)
> +++ cfe/trunk/lib/AST/Decl.cpp Thu Sep 21 21:25:05 2017
> @@ -554,7 +554,8 @@ static LinkageInfo getExternalLinkageFor
>
>  LinkageInfo
>  LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D,
> -LVComputationKind
> computation) {
> +LVComputationKind computation,
> +bool IgnoreVarTypeLinkage) {
>assert(D->getDeclContext()->getRedeclContext()->isFileContext() &&
>   "Not a name having namespace scope");
>ASTContext &Context = D->getASTContext();
> @@ -611,7 +612,7 @@ LinkageComputer::getLVForNamespaceScopeD
>  //   - a data member of an anonymous union.
>  const VarDecl *VD = IFD->getVarDecl();
>  assert(VD && "Expected a VarDecl in this IndirectFieldDecl!");
> -return getLVForNamespaceScopeDecl(VD, computation);
> +return getLVForNamespaceScopeDecl(VD, computation,
> IgnoreVarTypeLinkage);
>}
>assert(!isa(D) && "Didn't expect a FieldDecl!");
>
> @@ -700,7 +701,8 @@ LinkageComputer::getLVForNamespaceScopeD
>  //
>  // Note that we don't want to make the variable non-external
>  // because of this, but unique-external linkage suits us.
> -if (Context.getLangOpts().CPlusPlus && !isFirstInExternCContext(Var))
> {
> +if (Context.getLangOpts().CPlusPlus && !isFirstInExternCContext(Var)
> &&
> +!IgnoreVarTypeLinkage) {
>LinkageInfo TypeLV = getLVForType(*Var->getType(), computation);
>if (!isExternallyVisible(TypeLV.getLinkage()))
>  return LinkageInfo::uniqueExternal();
> @@ -740,15 +742,9 @@ LinkageComputer::getLVForNamespaceScopeD
>  // unique-external linkage, it's not legally usable from outside
>  // this translation unit.  However, we should use the C linkage
>  // rules instead for extern "C" declarations.
> -if (Context.getLangOpts().CPlusPlus &&
> -!Function->isInExternCContext()) {
> -  // Only look at the type-as-written. If this function has an
> auto-deduced
> -  // return type, we can't compute the linkage of that type because
> it could
> -  // require looking at the linkage of this function, and we don't
> need this
> -  // for correctness because the type is not part of the function's
> -  // signature.
> -  // FIXME: This is a hack. We should be able to solve this
> circularity and
> -  // the one in getLVForClassMember for Functions some other way.
> +if (Context.getLangOpts().CPlusPlus &&
> !Function->isInExternCContext()) {
> +  // Only look at the type-as-written. Otherwise, deducing the return
> type
> +  // of a function could change its linkage.
>QualType TypeAsWritten = Function->getType();
>if (TypeSourceInfo *TSI = Function->getTypeSourceInfo())
>  TypeAsWritten = TSI->getType();
> @@ -831,7 +827,8 @@ LinkageComputer::getLVForNamespaceScopeD
>
>  LinkageInfo
>  LinkageComputer::getLVForClassMember(const NamedDecl *D,
> - LVComputationKind computation) {
> + LVComputationKind computation,
> + bool IgnoreVarTypeLinkage) {
>// Only certain class members have linkage.  Note that fields don't
>// really have linkage, but it's convenient to say they do for the
>// purposes of calculating linkage of pointer-to-data-member
> @@ -889,22 +886,14 @@ LinkageComputer::getLVForClassMember(con
>const NamedDecl *explici

r314061 - [docs] Fix typos in Clang's User's Manual.

2017-09-23 Thread Reka Kovacs via cfe-commits
Author: rkovacs
Date: Sat Sep 23 05:13:32 2017
New Revision: 314061

URL: http://llvm.org/viewvc/llvm-project?rev=314061&view=rev
Log:
[docs] Fix typos in Clang's User's Manual.

Modified:
cfe/trunk/docs/UsersManual.rst

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=314061&r1=314060&r2=314061&view=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Sat Sep 23 05:13:32 2017
@@ -107,7 +107,7 @@ Options to Control Error and Warning Mes
 
 .. option:: -Wno-error=foo
 
-  Turn warning "foo" into an warning even if :option:`-Werror` is specified.
+  Turn warning "foo" into a warning even if :option:`-Werror` is specified.
 
 .. option:: -Wfoo
 
@@ -677,7 +677,7 @@ Current limitations
 
 Other Options
 -
-Clang options that that don't fit neatly into other categories.
+Clang options that don't fit neatly into other categories.
 
 .. option:: -MV
 


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


r314066 - Silence unused variable warning in Release builds.

2017-09-23 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Sat Sep 23 09:08:48 2017
New Revision: 314066

URL: http://llvm.org/viewvc/llvm-project?rev=314066&view=rev
Log:
Silence unused variable warning in Release builds.

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

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=314066&r1=314065&r2=314066&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Sat Sep 23 09:08:48 2017
@@ -1030,6 +1030,7 @@ Value *ScalarExprEmitter::EmitScalarConv
 // Source and destination are both expected to be vectors.
 llvm::Type *SrcElementTy = SrcTy->getVectorElementType();
 llvm::Type *DstElementTy = DstTy->getVectorElementType();
+(void)DstElementTy;
 
 assert(((SrcElementTy->isIntegerTy() &&
  DstElementTy->isIntegerTy()) ||


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


r314067 - Don't warn about runtime behavior problems in variable initializers that we

2017-09-23 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Sat Sep 23 11:27:11 2017
New Revision: 314067

URL: http://llvm.org/viewvc/llvm-project?rev=314067&view=rev
Log:
Don't warn about runtime behavior problems in variable initializers that we
know are going to be constant-evaluated.

Any relevant diagnostics should be produced by constant expression evaluation.

Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/CXX/class/class.static/class.static.data/p3.cpp
cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=314067&r1=314066&r2=314067&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Sep 23 11:27:11 2017
@@ -15179,10 +15179,24 @@ bool Sema::DiagRuntimeBehavior(SourceLoc
 if (Statement && getCurFunctionOrMethodDecl()) {
   FunctionScopes.back()->PossiblyUnreachableDiags.
 push_back(sema::PossiblyUnreachableDiag(PD, Loc, Statement));
+  return true;
 }
-else
-  Diag(Loc, PD);
-  
+
+// The initializer of a constexpr variable or of the first declaration of a
+// static data member is not syntactically a constant evaluated constant,
+// but nonetheless is always required to be a constant expression, so we
+// can skip diagnosing.
+// FIXME: Using the mangling context here is a hack.
+if (auto *VD = dyn_cast_or_null(
+ExprEvalContexts.back().ManglingContextDecl)) {
+  if (VD->isConstexpr() ||
+  (VD->isStaticDataMember() && VD->isFirstDecl() && !VD->isInline()))
+break;
+  // FIXME: For any other kind of variable, we should build a CFG for its
+  // initializer and check whether the context in question is reachable.
+}
+
+Diag(Loc, PD);
 return true;
   }
 

Modified: cfe/trunk/test/CXX/class/class.static/class.static.data/p3.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class/class.static/class.static.data/p3.cpp?rev=314067&r1=314066&r2=314067&view=diff
==
--- cfe/trunk/test/CXX/class/class.static/class.static.data/p3.cpp (original)
+++ cfe/trunk/test/CXX/class/class.static/class.static.data/p3.cpp Sat Sep 23 
11:27:11 2017
@@ -50,4 +50,4 @@ U u2; // expected-note {{here}}
 
 static_assert(U::a == 0, "");
 
-constexpr int outofline = (U::d, 0); // expected-note {{here}} 
expected-warning {{unused}}
+constexpr int outofline = (U::d, 0); // expected-note {{here}}

Modified: cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp?rev=314067&r1=314066&r2=314067&view=diff
==
--- cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp Sat Sep 23 11:27:11 2017
@@ -145,19 +145,19 @@ namespace UndefinedBehavior {
 
   constexpr int int_min = ~0x7fff;
   constexpr int minus_int_min = -int_min; // expected-error {{constant 
expression}} expected-note {{value 2147483648 is outside the range}}
-  constexpr int div0 = 3 / 0; // expected-error {{constant expression}} 
expected-note {{division by zero}} expected-warning {{undefined}}
-  constexpr int mod0 = 3 % 0; // expected-error {{constant expression}} 
expected-note {{division by zero}} expected-warning {{undefined}}
+  constexpr int div0 = 3 / 0; // expected-error {{constant expression}} 
expected-note {{division by zero}}
+  constexpr int mod0 = 3 % 0; // expected-error {{constant expression}} 
expected-note {{division by zero}}
   constexpr int int_min_div_minus_1 = int_min / -1; // expected-error 
{{constant expression}} expected-note {{value 2147483648 is outside the range}}
   constexpr int int_min_mod_minus_1 = int_min % -1; // expected-error 
{{constant expression}} expected-note {{value 2147483648 is outside the range}}
 
-  constexpr int shl_m1 = 0 << -1; // expected-error {{constant expression}} 
expected-note {{negative shift count -1}} expected-warning {{negative}}
+  constexpr int shl_m1 = 0 << -1; // expected-error {{constant expression}} 
expected-note {{negative shift count -1}}
   constexpr int shl_0 = 0 << 0; // ok
   constexpr int shl_31 = 0 << 31; // ok
-  constexpr int shl_32 = 0 << 32; // expected-error {{constant expression}} 
expected-note {{shift count 32 >= width of type 'int' (32}} expected-warning 
{{>= width of type}}
+  constexpr int shl_32 = 0 << 32; // expected-error {{constant expression}} 
expected-note {{shift count 32 >= width of type 'int' (32}}
   constexpr int shl_unsigned_negative = unsigned(-3) << 1; // ok
   constexpr int shl_unsigned_into_sign = 1u << 31; // ok
   constexpr int shl_unsign

Re: r313955 - Give external linkage and mangling to lambdas inside inline variables and variable templates.

2017-09-23 Thread Richard Smith via cfe-commits
On 23 September 2017 at 01:18, NAKAMURA Takumi via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> It seems libcxx (with -fmodules) dislikes this change. Any idea?
> http://bb.pgr.jp/builders/bootstrap-clang-libcxx-lld-i686-linux/builds/238
>

The code does this:

template struct X {
  static const unsigned M = (N == 32) ? ~0U : (1U << N) - 1;
};
X<32> x32;

... which seems pretty reasonable -- instantiating with N = 32 does not
reach the "1U << 32" portion. However, Clang's warning suppression for
unreachable code doesn't work for the initializer of a static data member,
and this change fixed a bug where we'd incorrectly treat such an
initializer as a constant-evaluated context, which happened to be hiding
the warning.

(The non-templated case:

struct X {
  static const unsigned M = (32 == 32) ? ~0U : (1U << 32) - 1;
};

... warned even before this change, but the function-scope version:

unsigned f() {
  return (32 == 32) ? ~0U : (1U << 32) - 1;
}

... does not, because we prune unreachable warnings within functions.)

Long-term, the right thing to do is to build a CFG for variable
initializers like we do for functions. But in the short term we can at
least suppress "runtime behavior" diagnostics in variable initializers that
will always be evaluated as constants (constexpr variables and in-class
initializers of static data members). I've implemented that in r314067.

On Fri, Sep 22, 2017 at 1:26 PM Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: rsmith
>> Date: Thu Sep 21 21:25:05 2017
>> New Revision: 313955
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=313955&view=rev
>> Log:
>> Give external linkage and mangling to lambdas inside inline variables and
>> variable templates.
>>
>> This implements the proposed approach in https://github.com/itanium-
>> cxx-abi/cxx-abi/issues/33
>>
>> This reinstates r313827, reverted in r313856, with a fix for the
>> 'out-of-bounds
>> enumeration value' ubsan error in that change.
>>
>> Modified:
>> cfe/trunk/lib/AST/Decl.cpp
>> cfe/trunk/lib/AST/ItaniumMangle.cpp
>> cfe/trunk/lib/AST/Linkage.h
>> cfe/trunk/lib/Parse/ParseDecl.cpp
>> cfe/trunk/lib/Sema/SemaDeclCXX.cpp
>> cfe/trunk/lib/Sema/SemaLambda.cpp
>> cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
>> cfe/trunk/test/CodeGenCXX/mangle-lambdas.cpp
>> cfe/trunk/test/SemaCXX/vartemplate-lambda.cpp
>> cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp
>>
>> Modified: cfe/trunk/lib/AST/Decl.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
>> Decl.cpp?rev=313955&r1=313954&r2=313955&view=diff
>> 
>> ==
>> --- cfe/trunk/lib/AST/Decl.cpp (original)
>> +++ cfe/trunk/lib/AST/Decl.cpp Thu Sep 21 21:25:05 2017
>> @@ -554,7 +554,8 @@ static LinkageInfo getExternalLinkageFor
>>
>>  LinkageInfo
>>  LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D,
>> -LVComputationKind
>> computation) {
>> +LVComputationKind
>> computation,
>> +bool IgnoreVarTypeLinkage) {
>>assert(D->getDeclContext()->getRedeclContext()->isFileContext() &&
>>   "Not a name having namespace scope");
>>ASTContext &Context = D->getASTContext();
>> @@ -611,7 +612,7 @@ LinkageComputer::getLVForNamespaceScopeD
>>  //   - a data member of an anonymous union.
>>  const VarDecl *VD = IFD->getVarDecl();
>>  assert(VD && "Expected a VarDecl in this IndirectFieldDecl!");
>> -return getLVForNamespaceScopeDecl(VD, computation);
>> +return getLVForNamespaceScopeDecl(VD, computation,
>> IgnoreVarTypeLinkage);
>>}
>>assert(!isa(D) && "Didn't expect a FieldDecl!");
>>
>> @@ -700,7 +701,8 @@ LinkageComputer::getLVForNamespaceScopeD
>>  //
>>  // Note that we don't want to make the variable non-external
>>  // because of this, but unique-external linkage suits us.
>> -if (Context.getLangOpts().CPlusPlus &&
>> !isFirstInExternCContext(Var)) {
>> +if (Context.getLangOpts().CPlusPlus &&
>> !isFirstInExternCContext(Var) &&
>> +!IgnoreVarTypeLinkage) {
>>LinkageInfo TypeLV = getLVForType(*Var->getType(), computation);
>>if (!isExternallyVisible(TypeLV.getLinkage()))
>>  return LinkageInfo::uniqueExternal();
>> @@ -740,15 +742,9 @@ LinkageComputer::getLVForNamespaceScopeD
>>  // unique-external linkage, it's not legally usable from outside
>>  // this translation unit.  However, we should use the C linkage
>>  // rules instead for extern "C" declarations.
>> -if (Context.getLangOpts().CPlusPlus &&
>> -!Function->isInExternCContext()) {
>> -  // Only look at the type-as-written. If this function has an
>> auto-deduced
>> -  // return type, we can't compute the linkage of that type because
>> it could
>> -  // require looking at the lin