[all-commits] [llvm/llvm-project] 14192a: [clang][Sema] Fix ObjC file-scope literal diagnost...

Peter Rong via All-commits all-commits at lists.llvm.org
Thu Jul 30 23:01:56 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 14192adddc39cb28b7bcb1e6d50dc6ef87f4d54b
      https://github.com/llvm/llvm-project/commit/14192adddc39cb28b7bcb1e6d50dc6ef87f4d54b
  Author: Peter Rong <peterrong96 at gmail.com>
  Date:   2026-07-30 (Thu, 30 Jul 2026)

  Changed paths:
    M clang/lib/AST/Expr.cpp
    M clang/lib/Sema/SemaDecl.cpp
    A clang/test/SemaObjC/objc-constant-literal-dict-key-restrictions.m

  Log Message:
  -----------
  [clang][Sema] Fix ObjC file-scope literal diagnostic (#209688)

A non-constant ObjC collection literal used as a file-scope initializer
should get the targeted err_objc_literal_nonconstant_at_file_scope
pointing at the offending element. CheckForConstantInitializer instead
inspected the wrapped Init/Culprit, so under -fobjc-arc, for id-typed
variables, or with parentheses it skipped the per-element loop and fell
back to the generic "initializer element is not a compile-time constant"
on the whole @{...}/@[...] -- or blamed the wrong element (e.g. a valid
string key rather than the non-constant value).

Unwrap the culprit with IgnoreParenImpCasts and drive classification and
per-element reporting off it, mirroring BuildObjC{Array,Dictionary}Literal
(unwrap before each isa<>; keys must be string literals, values/elements
constant object literals). Also treat CK_ARCReclaimReturnedObject as
transparent in Expr::isConstantInitializer so ARC-wrapped literals are
recognized and the reported culprit is the literal itself.

Add objc-constant-literal-dict-key-restrictions.m (macOS no-ARC, iOS ARC,
ObjC++), with each culprit on its own line so -verify checks the caret.

[Assisted-by](https://t.ly/Dkjjk): Opus 4.8



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list