aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaExprMember.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Sema/SemaExprMember.cpp')
-rw-r--r--clang/lib/Sema/SemaExprMember.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp
index dfd93aa4638d..c9d9ef31f3ee 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -940,7 +940,7 @@ static bool IsInFnTryBlockHandler(const Scope *S) {
// function scope. If a FnTryCatchScope is found, check whether the TryScope
// flag is set. If it is not, it's a function-try-block handler.
for (; S != S->getFnParent(); S = S->getParent()) {
- if (S->getFlags() & Scope::FnTryCatchScope)
+ if (S->isFnTryCatchScope())
return (S->getFlags() & Scope::TryScope) != Scope::TryScope;
}
return false;
@@ -1292,6 +1292,21 @@ static ExprResult LookupMemberExpr(Sema &S, LookupResult &R,
}
}
+ // If the base type is an atomic type, this access is undefined behavior per
+ // C11 6.5.2.3p5. Instead of giving a typecheck error, we'll warn the user
+ // about the UB and recover by converting the atomic lvalue into a non-atomic
+ // lvalue. Because this is inherently unsafe as an atomic operation, the
+ // warning defaults to an error.
+ if (const auto *ATy = BaseType->getAs<AtomicType>()) {
+ S.DiagRuntimeBehavior(OpLoc, nullptr,
+ S.PDiag(diag::warn_atomic_member_access));
+ BaseType = ATy->getValueType().getUnqualifiedType();
+ BaseExpr = ImplicitCastExpr::Create(
+ S.Context, IsArrow ? S.Context.getPointerType(BaseType) : BaseType,
+ CK_AtomicToNonAtomic, BaseExpr.get(), nullptr,
+ BaseExpr.get()->getValueKind(), FPOptionsOverride());
+ }
+
// Handle field access to simple records.
if (const RecordType *RTy = BaseType->getAs<RecordType>()) {
TypoExpr *TE = nullptr;
@@ -1592,6 +1607,16 @@ static ExprResult LookupMemberExpr(Sema &S, LookupResult &R,
false);
}
+ if (BaseType->isExtVectorBoolType()) {
+ // We disallow element access for ext_vector_type bool. There is no way to
+ // materialize a reference to a vector element as a pointer (each element is
+ // one bit in the vector).
+ S.Diag(R.getNameLoc(), diag::err_ext_vector_component_name_illegal)
+ << MemberName
+ << (BaseExpr.get() ? BaseExpr.get()->getSourceRange() : SourceRange());
+ return ExprError();
+ }
+
// Handle 'field access' to vectors, such as 'V.xx'.
if (BaseType->isExtVectorType()) {
// FIXME: this expr should store IsArrow.
@@ -1711,6 +1736,9 @@ ExprResult Sema::ActOnMemberAccessExpr(Scope *S, Expr *Base,
DeclarationName Name = NameInfo.getName();
bool IsArrow = (OpKind == tok::arrow);
+ if (getLangOpts().HLSL && IsArrow)
+ return ExprError(Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 2);
+
NamedDecl *FirstQualifierInScope
= (!SS.isSet() ? nullptr : FindFirstQualifierInScope(S, SS.getScopeRep()));