[cfe-commits] r140796 - in /cfe/trunk: include/clang/Basic/Attr.td include/clang/Basic/DiagnosticParseKinds.td include/clang/Basic/TokenKinds.def include/clang/Parse/Parser.h lib/AST/ASTContext.cpp lib/Headers/CMakeLists.txt lib/Headers/stdalign.h lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp lib/Parse/ParseTentative.cpp test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp test/Parser/c1x-alignas.c test/Parser/cxx0x-attributes.cpp test/Sema/alignas.c test/Sema/warn-cast-align.c test/SemaCXX/attr-cxx0x.cpp

Douglas Gregor dgregor at apple.com
Tue Oct 18 22:48:55 PDT 2011


On Sep 29, 2011, at 11:04 AM, Peter Collingbourne wrote:

> Author: pcc
> Date: Thu Sep 29 13:04:28 2011
> New Revision: 140796
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=140796&view=rev
> Log:
> Add support for alignment-specifiers in C1X and C++11, remove
> support for the C++0x draft [[align]] attribute and add the C1X
> standard header file stdalign.h
> 
> Added:
>    cfe/trunk/lib/Headers/stdalign.h
>    cfe/trunk/test/Parser/c1x-alignas.c
>    cfe/trunk/test/Sema/alignas.c
> Modified:
>    cfe/trunk/include/clang/Basic/Attr.td
>    cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
>    cfe/trunk/include/clang/Basic/TokenKinds.def
>    cfe/trunk/include/clang/Parse/Parser.h
>    cfe/trunk/lib/AST/ASTContext.cpp
>    cfe/trunk/lib/Headers/CMakeLists.txt
>    cfe/trunk/lib/Parse/ParseDecl.cpp
>    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
>    cfe/trunk/lib/Parse/ParseTentative.cpp
>    cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp
>    cfe/trunk/test/Parser/cxx0x-attributes.cpp
>    cfe/trunk/test/Sema/warn-cast-align.c
>    cfe/trunk/test/SemaCXX/attr-cxx0x.cpp
> 
> +/// ParseAlignArgument - Parse the argument to an alignment-specifier.
> +///
> +/// FIXME: Simply returns an alignof() expression if the argument is a
> +/// type. Ideally, the type should be propagated directly into Sema.
> +///
> +/// [C1X/C++0x] type-id
> +/// [C1X]       constant-expression
> +/// [C++0x]     assignment-expression
> +ExprResult Parser::ParseAlignArgument(SourceLocation Start) {
> +  if (isTypeIdInParens()) {
> +    EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated);

This EnterExpressionEvaluationContext should be unnecessary, since we're just parsing a type anyway.

> +    SourceLocation TypeLoc = Tok.getLocation();
> +    ParsedType Ty = ParseTypeName().get();
> +    SourceRange TypeRange(Start, Tok.getLocation());
> +    return Actions.ActOnUnaryExprOrTypeTraitExpr(TypeLoc, UETT_AlignOf, true,
> +                                                Ty.getAsOpaquePtr(), TypeRange);

I agree that the FIXME is pretty important for AST fidelity.

> +  } else
> +    return ParseConstantExpression();
> +}
> +
> +/// ParseAlignmentSpecifier - Parse an alignment-specifier, and add the
> +/// attribute to Attrs.
> +///
> +/// alignment-specifier:
> +/// [C1X]   '_Alignas' '(' type-id ')'
> +/// [C1X]   '_Alignas' '(' constant-expression ')'
> +/// [C++0x] 'alignas' '(' type-id ')'
> +/// [C++0x] 'alignas' '(' assignment-expression ')'

FWIW, C++0x has an optional ellipsis after the type-id and assignment-expression, which is used with variadic templates. At the very least this needs a FIXME, but it also will need to be implemented.

	- Doug




More information about the cfe-commits mailing list