<div dir="ltr">Hi Evgeniy,<div><br></div><div>There is nothing in r213120, that could cause memory leaks in NestedNameSpecifierLocBuilder, maybe this change triggered existing problem.</div><div>Sanitizer reports leaks of tiny blocks (1 byte), in r213178 such blocks should not be created. However I am not sure if this can help.</div>
<div><br></div><div>By the way, how I can build compiler with sanitizer enabled? When I create build using command:</div><div><br></div><div><div>cmake \</div><div> -DCMAKE_BUILD_TYPE=Release \</div><div> -DLLVM_ENABLE_ASSERTIONS=ON \</div>
<div> -DCMAKE_C_COMPILER=$CLANGPATH/clang \</div><div> -DCMAKE_CXX_COMPILER=$CLANGPATH/clang++ \</div><div> -DLLVM_USE_SANITIZER=Memory \</div><div> -DLLVM_TARGETS_TO_BUILD=X86 \</div><div> ../llvm</div></div>
<div><br></div><div>make fails:</div><div><br></div><div><div>[ 6%] Building Intrinsics.gen...</div><div>==25305== WARNING: MemorySanitizer: use-of-uninitialized-value</div><div> #0 0x7fb534d9dedd in _M_dispose /usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/bits/basic_string.h:240:34</div>
</div><div>...</div><div><br></div><div class="gmail_extra"><br clear="all"><div>Thanks,<br>--Serge<br></div>
<br><br><div class="gmail_quote">2014-07-16 19:50 GMT+07:00 Evgeniy Stepanov <span dir="ltr"><<a href="mailto:eugeni.stepanov@gmail.com" target="_blank">eugeni.stepanov@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
is looks like there are new memory leaks from this change:<br>
<a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/3963/steps/check-clang%20asan/logs/stdio" target="_blank">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/3963/steps/check-clang%20asan/logs/stdio</a><br>
<div class="HOEnZb"><div class="h5"><br>
On Wed, Jul 16, 2014 at 9:16 AM, Serge Pavlov <<a href="mailto:sepavloff@gmail.com">sepavloff@gmail.com</a>> wrote:<br>
> Author: sepavloff<br>
> Date: Wed Jul 16 00:16:52 2014<br>
> New Revision: 213120<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=213120&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=213120&view=rev</a><br>
> Log:<br>
> Improve error recovery around colon.<br>
><br>
> Recognize additional cases, when '::' is mistyped as ':'.<br>
> This is a fix to RP18587 - colons have too much protection in member-declarations<br>
> Review is tracked by <a href="http://reviews.llvm.org/D3653" target="_blank">http://reviews.llvm.org/D3653</a>.<br>
><br>
> This is an attempt to recommit the fix, initially committed as r212957 but then<br>
> reverted in r212965 as it broke self-build. In the updated patch ParseDirectDeclarator<br>
> turns on colon protection in for context as well.<br>
><br>
> Modified:<br>
> cfe/trunk/lib/Parse/ParseDecl.cpp<br>
> cfe/trunk/lib/Parse/ParseDeclCXX.cpp<br>
> cfe/trunk/test/SemaCXX/enum-bitfield.cpp<br>
> cfe/trunk/test/SemaCXX/for-range-examples.cpp<br>
> cfe/trunk/test/SemaCXX/nested-name-spec.cpp<br>
><br>
> Modified: cfe/trunk/lib/Parse/ParseDecl.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=213120&r1=213119&r2=213120&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=213120&r1=213119&r2=213120&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Parse/ParseDecl.cpp (original)<br>
> +++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed Jul 16 00:16:52 2014<br>
> @@ -2715,24 +2715,23 @@ void Parser::ParseDeclarationSpecifiers(<br>
> // typedef-name<br>
> case tok::kw_decltype:<br>
> case tok::identifier: {<br>
> + // This identifier can only be a typedef name if we haven't already seen<br>
> + // a type-specifier. Without this check we misparse:<br>
> + // typedef int X; struct Y { short X; }; as 'short int'.<br>
> + if (DS.hasTypeSpecifier())<br>
> + goto DoneWithDeclSpec;<br>
> +<br>
> // In C++, check to see if this is a scope specifier like foo::bar::, if<br>
> // so handle it as such. This is important for ctor parsing.<br>
> if (getLangOpts().CPlusPlus) {<br>
> if (TryAnnotateCXXScopeToken(EnteringContext)) {<br>
> - if (!DS.hasTypeSpecifier())<br>
> - DS.SetTypeSpecError();<br>
> + DS.SetTypeSpecError();<br>
> goto DoneWithDeclSpec;<br>
> }<br>
> if (!Tok.is(tok::identifier))<br>
> continue;<br>
> }<br>
><br>
> - // This identifier can only be a typedef name if we haven't already seen<br>
> - // a type-specifier. Without this check we misparse:<br>
> - // typedef int X; struct Y { short X; }; as 'short int'.<br>
> - if (DS.hasTypeSpecifier())<br>
> - goto DoneWithDeclSpec;<br>
> -<br>
> // Check for need to substitute AltiVec keyword tokens.<br>
> if (TryAltiVecToken(DS, Loc, PrevSpec, DiagID, isInvalid))<br>
> break;<br>
> @@ -4529,7 +4528,9 @@ void Parser::ParseDeclaratorInternal(Dec<br>
> // Member pointers get special handling, since there's no place for the<br>
> // scope spec in the generic path below.<br>
> if (getLangOpts().CPlusPlus &&<br>
> - (Tok.is(tok::coloncolon) || Tok.is(tok::identifier) ||<br>
> + (Tok.is(tok::coloncolon) ||<br>
> + (Tok.is(tok::identifier) &&<br>
> + (NextToken().is(tok::coloncolon) || NextToken().is(tok::less))) ||<br>
> Tok.is(tok::annot_cxxscope))) {<br>
> bool EnteringContext = D.getContext() == Declarator::FileContext ||<br>
> D.getContext() == Declarator::MemberContext;<br>
> @@ -4722,6 +4723,14 @@ void Parser::ParseDirectDeclarator(Decla<br>
> DeclaratorScopeObj DeclScopeObj(*this, D.getCXXScopeSpec());<br>
><br>
> if (getLangOpts().CPlusPlus && D.mayHaveIdentifier()) {<br>
> + // Don't parse FOO:BAR as if it were a typo for FOO::BAR inside a class, in<br>
> + // this context it is a bitfield. Also in range-based for statement colon<br>
> + // may delimit for-range-declaration.<br>
> + ColonProtectionRAIIObject X(*this,<br>
> + D.getContext() == Declarator::MemberContext ||<br>
> + (D.getContext() == Declarator::ForContext &&<br>
> + getLangOpts().CPlusPlus11));<br>
> +<br>
> // ParseDeclaratorInternal might already have parsed the scope.<br>
> if (D.getCXXScopeSpec().isEmpty()) {<br>
> bool EnteringContext = D.getContext() == Declarator::FileContext ||<br>
><br>
> Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=213120&r1=213119&r2=213120&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=213120&r1=213119&r2=213120&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)<br>
> +++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Wed Jul 16 00:16:52 2014<br>
> @@ -1239,7 +1239,8 @@ void Parser::ParseClassSpecifier(tok::To<br>
> // Parse the (optional) nested-name-specifier.<br>
> CXXScopeSpec &SS = DS.getTypeSpecScope();<br>
> if (getLangOpts().CPlusPlus) {<br>
> - // "FOO : BAR" is not a potential typo for "FOO::BAR".<br>
> + // "FOO : BAR" is not a potential typo for "FOO::BAR". In this context it<br>
> + // is a base-specifier-list.<br>
> ColonProtectionRAIIObject X(*this);<br>
><br>
> if (ParseOptionalCXXScopeSpecifier(SS, ParsedType(), EnteringContext))<br>
> @@ -1926,14 +1927,8 @@ void Parser::ParseCXXMemberDeclaratorBef<br>
> // declarator pure-specifier[opt]<br>
> // declarator brace-or-equal-initializer[opt]<br>
> // identifier[opt] ':' constant-expression<br>
> - if (Tok.isNot(tok::colon)) {<br>
> - // Don't parse FOO:BAR as if it were a typo for FOO::BAR, in this context it<br>
> - // is a bitfield.<br>
> - // FIXME: This should only apply when parsing the id-expression (see<br>
> - // PR18587).<br>
> - ColonProtectionRAIIObject X(*this);<br>
> + if (Tok.isNot(tok::colon))<br>
> ParseDeclarator(DeclaratorInfo);<br>
> - }<br>
><br>
> if (!DeclaratorInfo.isFunctionDeclarator() && TryConsumeToken(tok::colon)) {<br>
> BitfieldSize = ParseConstantExpression();<br>
> @@ -2015,6 +2010,14 @@ void Parser::ParseCXXClassMemberDeclarat<br>
> return;<br>
> }<br>
><br>
> + // Turn on colon protection early, while parsing declspec, although there is<br>
> + // nothing to protect there. It prevents from false errors if error recovery<br>
> + // incorrectly determines where the declspec ends, as in the example:<br>
> + // struct A { enum class B { C }; };<br>
> + // const int C = 4;<br>
> + // struct D { A::B : C; };<br>
> + ColonProtectionRAIIObject X(*this);<br>
> +<br>
> // Access declarations.<br>
> bool MalformedTypeSpec = false;<br>
> if (!TemplateInfo.Kind &&<br>
> @@ -2128,13 +2131,11 @@ void Parser::ParseCXXClassMemberDeclarat<br>
> if (MalformedTypeSpec)<br>
> DS.SetTypeSpecError();<br>
><br>
> - {<br>
> - // Don't parse FOO:BAR as if it were a typo for FOO::BAR, in this context it<br>
> - // is a bitfield.<br>
> - ColonProtectionRAIIObject X(*this);<br>
> - ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC_class,<br>
> - &CommonLateParsedAttrs);<br>
> - }<br>
> + ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC_class,<br>
> + &CommonLateParsedAttrs);<br>
> +<br>
> + // Turn off colon protection that was set for declspec.<br>
> + X.restore();<br>
><br>
> // If we had a free-standing type definition with a missing semicolon, we<br>
> // may get this far before the problem becomes obvious.<br>
><br>
> Modified: cfe/trunk/test/SemaCXX/enum-bitfield.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enum-bitfield.cpp?rev=213120&r1=213119&r2=213120&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enum-bitfield.cpp?rev=213120&r1=213119&r2=213120&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/test/SemaCXX/enum-bitfield.cpp (original)<br>
> +++ cfe/trunk/test/SemaCXX/enum-bitfield.cpp Wed Jul 16 00:16:52 2014<br>
> @@ -16,3 +16,15 @@ struct Y {<br>
> enum E : int(2);<br>
> enum E : Z(); // expected-error{{integral constant expression must have integral or unscoped enumeration type, not 'Z'}}<br>
> };<br>
> +<br>
> +namespace pr18587 {<br>
> +struct A {<br>
> + enum class B {<br>
> + C<br>
> + };<br>
> +};<br>
> +const int C = 4;<br>
> +struct D {<br>
> + A::B : C;<br>
> +};<br>
> +}<br>
><br>
> Modified: cfe/trunk/test/SemaCXX/for-range-examples.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/for-range-examples.cpp?rev=213120&r1=213119&r2=213120&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/for-range-examples.cpp?rev=213120&r1=213119&r2=213120&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/test/SemaCXX/for-range-examples.cpp (original)<br>
> +++ cfe/trunk/test/SemaCXX/for-range-examples.cpp Wed Jul 16 00:16:52 2014<br>
> @@ -227,3 +227,15 @@ namespace test7 {<br>
> for (e [[deprecated]] : arr) { e = 0; } // expected-warning {{deprecated}} expected-note {{here}} expected-warning {{extension}}<br>
> }<br>
> }<br>
> +<br>
> +namespace pr18587 {<br>
> + class Arg {};<br>
> + struct Cont {<br>
> + int *begin();<br>
> + int *end();<br>
> + };<br>
> + void AddAllArgs(Cont &x) {<br>
> + for (auto Arg: x) {<br>
> + }<br>
> + }<br>
> +}<br>
><br>
> Modified: cfe/trunk/test/SemaCXX/nested-name-spec.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nested-name-spec.cpp?rev=213120&r1=213119&r2=213120&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nested-name-spec.cpp?rev=213120&r1=213119&r2=213120&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/test/SemaCXX/nested-name-spec.cpp (original)<br>
> +++ cfe/trunk/test/SemaCXX/nested-name-spec.cpp Wed Jul 16 00:16:52 2014<br>
> @@ -311,3 +311,102 @@ namespace N {<br>
><br>
> namespace TypedefNamespace { typedef int F; };<br>
> TypedefNamespace::F::NonexistentName BadNNSWithCXXScopeSpec; // expected-error {{'F' (aka 'int') is not a class, namespace, or scoped enumeration}}<br>
> +<br>
> +namespace PR18587 {<br>
> +<br>
> +struct C1 {<br>
> + int a, b, c;<br>
> + typedef int C2;<br>
> + struct B1 {<br>
> + struct B2 {<br>
> + int a, b, c;<br>
> + };<br>
> + };<br>
> +};<br>
> +struct C2 { static const unsigned N1 = 1; };<br>
> +struct B1 {<br>
> + enum E1 { B2 = 2 };<br>
> + static const int B3 = 3;<br>
> +};<br>
> +const int N1 = 2;<br>
> +<br>
> +// Function declarators<br>
> +struct S1a { int f(C1::C2); };<br>
> +struct S1b { int f(C1:C2); }; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}<br>
> +<br>
> +struct S2a {<br>
> + C1::C2 f(C1::C2);<br>
> +};<br>
> +struct S2c {<br>
> + C1::C2 f(C1:C2); // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}<br>
> +};<br>
> +<br>
> +struct S3a {<br>
> + int f(C1::C2), C2 : N1;<br>
> + int g : B1::B2;<br>
> +};<br>
> +struct S3b {<br>
> + int g : B1:B2; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}<br>
> +};<br>
> +<br>
> +// Inside square brackets<br>
> +struct S4a {<br>
> + int f[C2::N1];<br>
> +};<br>
> +struct S4b {<br>
> + int f[C2:N1]; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}<br>
> +};<br>
> +<br>
> +struct S5a {<br>
> + int f(int xx[B1::B3 ? C2::N1 : B1::B2]);<br>
> +};<br>
> +struct S5b {<br>
> + int f(int xx[B1::B3 ? C2::N1 : B1:B2]); // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}<br>
> +};<br>
> +struct S5c {<br>
> + int f(int xx[B1:B3 ? C2::N1 : B1::B2]); // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}<br>
> +};<br>
> +<br>
> +// Bit fields<br>
> +struct S6a {<br>
> + C1::C2 m1 : B1::B2;<br>
> +};<br>
> +struct S6c {<br>
> + C1::C2 m1 : B1:B2; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}<br>
> +};<br>
> +struct S6d {<br>
> + int C2:N1;<br>
> +};<br>
> +struct S6e {<br>
> + static const int N = 3;<br>
> + B1::E1 : N;<br>
> +};<br>
> +struct S6g {<br>
> + C1::C2 : B1:B2; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}<br>
> + B1::E1 : B1:B2; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}<br>
> +};<br>
> +<br>
> +// Template parameters<br>
> +template <int N> struct T1 {<br>
> + int a,b,c;<br>
> + static const unsigned N1 = N;<br>
> + typedef unsigned C1;<br>
> +};<br>
> +T1<C2::N1> var_1a;<br>
> +T1<C2:N1> var_1b; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}<br>
> +template<int N> int F() {}<br>
> +int (*X1)() = (B1::B2 ? F<1> : F<2>);<br>
> +int (*X2)() = (B1:B2 ? F<1> : F<2>); // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}<br>
> +<br>
> +// Bit fields + templates<br>
> +struct S7a {<br>
> + T1<B1::B2>::C1 m1 : T1<B1::B2>::N1;<br>
> +};<br>
> +struct S7b {<br>
> + T1<B1:B2>::C1 m1 : T1<B1::B2>::N1; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}<br>
> +};<br>
> +struct S7c {<br>
> + T1<B1::B2>::C1 m1 : T1<B1:B2>::N1; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}<br>
> +};<br>
> +<br>
> +}<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div></div>