[clang] [Clang] Add __builtin_get_counted_by builtin (PR #102549)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 13 02:07:18 PDT 2024
================
@@ -6590,8 +6590,34 @@ ExprResult Sema::BuildCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc,
return CallExpr::Create(Context, Fn, ArgExprs, Context.DependentTy,
VK_PRValue, RParenLoc, CurFPFeatureOverrides());
}
- return BuildResolvedCallExpr(Fn, NDecl, LParenLoc, ArgExprs, RParenLoc,
- ExecConfig, IsExecConfig);
+
+ Result = BuildResolvedCallExpr(Fn, NDecl, LParenLoc, ArgExprs, RParenLoc,
+ ExecConfig, IsExecConfig);
+
+ if (FunctionDecl *FDecl = dyn_cast_or_null<FunctionDecl>(NDecl);
+ FDecl && FDecl->getBuiltinID() == Builtin::BI__builtin_get_counted_by) {
+ if (const MemberExpr *ME = ArgExprs[0]->getMemberExpr()) {
+ bool IsFlexibleArrayMember = ME->isFlexibleArrayMemberLike(
+ Context, getLangOpts().getStrictFlexArraysLevel());
+
+ if (!ME->HasSideEffects(Context) && IsFlexibleArrayMember &&
----------------
Sirraide wrote:
I don’t think we need to reject this if the expression contains side-effects, but we should definitely warn that it isn’t actually going to be evaluated. I think something along the lines of ‘argument to '__builtin_get_counted_by' has side-effects that will be discarded’ (which is pretty much exactly what we used to issue for e.g. `__builtin_assume` before we had to change that for... reasons), would be enough to tell the user ‘hey, make sure you really want to do this’.
https://github.com/llvm/llvm-project/pull/102549
More information about the cfe-commits
mailing list