|
@@ -3596,7 +3596,8 @@ static bool CheckExtensionTraitOperandType(Sema &S, QualType T,
|
|
|
|
|
|
// C99 6.5.3.4p1:
|
|
// C99 6.5.3.4p1:
|
|
if (T->isFunctionType() &&
|
|
if (T->isFunctionType() &&
|
|
- (TraitKind == UETT_SizeOf || TraitKind == UETT_AlignOf)) {
|
|
|
|
|
|
+ (TraitKind == UETT_SizeOf || TraitKind == UETT_AlignOf ||
|
|
|
|
+ TraitKind == UETT_PreferredAlignOf)) {
|
|
// sizeof(function)/alignof(function) is allowed as an extension.
|
|
// sizeof(function)/alignof(function) is allowed as an extension.
|
|
S.Diag(Loc, diag::ext_sizeof_alignof_function_type)
|
|
S.Diag(Loc, diag::ext_sizeof_alignof_function_type)
|
|
<< TraitKind << ArgRange;
|
|
<< TraitKind << ArgRange;
|
|
@@ -3674,7 +3675,7 @@ bool Sema::CheckUnaryExprOrTypeTraitOperand(Expr *E,
|
|
// the expression to be complete. 'sizeof' requires the expression's type to
|
|
// the expression to be complete. 'sizeof' requires the expression's type to
|
|
// be complete (and will attempt to complete it if it's an array of unknown
|
|
// be complete (and will attempt to complete it if it's an array of unknown
|
|
// bound).
|
|
// bound).
|
|
- if (ExprKind == UETT_AlignOf) {
|
|
|
|
|
|
+ if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
|
|
if (RequireCompleteType(E->getExprLoc(),
|
|
if (RequireCompleteType(E->getExprLoc(),
|
|
Context.getBaseElementType(E->getType()),
|
|
Context.getBaseElementType(E->getType()),
|
|
diag::err_sizeof_alignof_incomplete_type, ExprKind,
|
|
diag::err_sizeof_alignof_incomplete_type, ExprKind,
|
|
@@ -3698,7 +3699,8 @@ bool Sema::CheckUnaryExprOrTypeTraitOperand(Expr *E,
|
|
|
|
|
|
// The operand for sizeof and alignof is in an unevaluated expression context,
|
|
// The operand for sizeof and alignof is in an unevaluated expression context,
|
|
// so side effects could result in unintended consequences.
|
|
// so side effects could result in unintended consequences.
|
|
- if ((ExprKind == UETT_SizeOf || ExprKind == UETT_AlignOf) &&
|
|
|
|
|
|
+ if ((ExprKind == UETT_SizeOf || ExprKind == UETT_AlignOf ||
|
|
|
|
+ ExprKind == UETT_PreferredAlignOf) &&
|
|
!inTemplateInstantiation() && E->HasSideEffects(Context, false))
|
|
!inTemplateInstantiation() && E->HasSideEffects(Context, false))
|
|
Diag(E->getExprLoc(), diag::warn_side_effects_unevaluated_context);
|
|
Diag(E->getExprLoc(), diag::warn_side_effects_unevaluated_context);
|
|
|
|
|
|
@@ -3767,7 +3769,8 @@ bool Sema::CheckUnaryExprOrTypeTraitOperand(QualType ExprType,
|
|
// C11 6.5.3.4/3, C++11 [expr.alignof]p3:
|
|
// C11 6.5.3.4/3, C++11 [expr.alignof]p3:
|
|
// When alignof or _Alignof is applied to an array type, the result
|
|
// When alignof or _Alignof is applied to an array type, the result
|
|
// is the alignment of the element type.
|
|
// is the alignment of the element type.
|
|
- if (ExprKind == UETT_AlignOf || ExprKind == UETT_OpenMPRequiredSimdAlign)
|
|
|
|
|
|
+ if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf ||
|
|
|
|
+ ExprKind == UETT_OpenMPRequiredSimdAlign)
|
|
ExprType = Context.getBaseElementType(ExprType);
|
|
ExprType = Context.getBaseElementType(ExprType);
|
|
|
|
|
|
if (ExprKind == UETT_VecStep)
|
|
if (ExprKind == UETT_VecStep)
|
|
@@ -3796,7 +3799,7 @@ bool Sema::CheckUnaryExprOrTypeTraitOperand(QualType ExprType,
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
-static bool CheckAlignOfExpr(Sema &S, Expr *E) {
|
|
|
|
|
|
+static bool CheckAlignOfExpr(Sema &S, Expr *E, UnaryExprOrTypeTrait ExprKind) {
|
|
E = E->IgnoreParens();
|
|
E = E->IgnoreParens();
|
|
|
|
|
|
// Cannot know anything else if the expression is dependent.
|
|
// Cannot know anything else if the expression is dependent.
|
|
@@ -3850,7 +3853,7 @@ static bool CheckAlignOfExpr(Sema &S, Expr *E) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- return S.CheckUnaryExprOrTypeTraitOperand(E, UETT_AlignOf);
|
|
|
|
|
|
+ return S.CheckUnaryExprOrTypeTraitOperand(E, ExprKind);
|
|
}
|
|
}
|
|
|
|
|
|
bool Sema::CheckVecStepExpr(Expr *E) {
|
|
bool Sema::CheckVecStepExpr(Expr *E) {
|
|
@@ -4046,8 +4049,8 @@ Sema::CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc,
|
|
bool isInvalid = false;
|
|
bool isInvalid = false;
|
|
if (E->isTypeDependent()) {
|
|
if (E->isTypeDependent()) {
|
|
// Delay type-checking for type-dependent expressions.
|
|
// Delay type-checking for type-dependent expressions.
|
|
- } else if (ExprKind == UETT_AlignOf) {
|
|
|
|
- isInvalid = CheckAlignOfExpr(*this, E);
|
|
|
|
|
|
+ } else if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
|
|
|
|
+ isInvalid = CheckAlignOfExpr(*this, E, ExprKind);
|
|
} else if (ExprKind == UETT_VecStep) {
|
|
} else if (ExprKind == UETT_VecStep) {
|
|
isInvalid = CheckVecStepExpr(E);
|
|
isInvalid = CheckVecStepExpr(E);
|
|
} else if (ExprKind == UETT_OpenMPRequiredSimdAlign) {
|
|
} else if (ExprKind == UETT_OpenMPRequiredSimdAlign) {
|