Skip to content

Conversation

patrykstefanski
Copy link

Allow using bounds-attributed types when deducing auto type in attribute-only mode. Since the bounds-attributed sugar would depend on a variable in a different scope etc, we drop the sugar and emit a warning.

rdar://140995829

@patrykstefanski patrykstefanski self-assigned this Sep 20, 2025
@patrykstefanski patrykstefanski added the clang:bounds-safety Issue relating to the experimental -fbounds-safety feature in Clang label Sep 20, 2025
@patrykstefanski patrykstefanski force-pushed the eng/pstefanski/PR-140995829 branch from 08b300d to c65fa57 Compare September 23, 2025 00:39
Copy link

@hnrklssn hnrklssn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Allow using bounds-attributed types when deducing auto type in
attribute-only mode. Since the bounds-attributed type can depend on a
variable in a different scope etc., we drop the bounds-attributed sugar
and emit a warning.

rdar://140995829
@patrykstefanski patrykstefanski force-pushed the eng/pstefanski/PR-140995829 branch from c65fa57 to 6b8f628 Compare September 24, 2025 19:11
@patrykstefanski
Copy link
Author

As discussed on slack, I removed support for inferring __counted_by(const), now it always drops the sugar and emits a warning.

@patrykstefanski
Copy link
Author

@swift-ci test llvm

if (const auto *CATy = dyn_cast<CountAttributedType>(BATy)) {
DesugaredTy = CATy->desugar();
Kind = CATy->getKind();
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about __null_terminated?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto will get __null_terminated without any warnings/errors:

void foo(int *__null_terminated x) {
  __auto_type p = x;
  auto r = x;
}

FunctionDecl foo 'void (int * __terminated_by(0))'
|-ParmVarDecl used x 'int * __terminated_by(0)':'int *'
`-CompoundStmt
  |-DeclStmt
  | `-VarDecl p 'int * __terminated_by(0)':'int *' cinit
  |   `-ImplicitCastExpr 'int * __terminated_by(0)':'int *' <LValueToRValue>
  |     `-DeclRefExpr 'int * __terminated_by(0)':'int *' lvalue ParmVar 'x' 'int * __terminated_by(0)':'int *'
  `-DeclStmt
    `-VarDecl r 'int * __terminated_by(0)':'int *' cinit
      `-ImplicitCastExpr 'int * __terminated_by(0)':'int *' <LValueToRValue>
        `-DeclRefExpr 'int * __terminated_by(0)':'int *' lvalue ParmVar 'x' 'int * __terminated_by(0)':'int *'

@patrykstefanski
Copy link
Author

Unrelated tests are failing.

@patrykstefanski patrykstefanski merged commit 4fe6dbb into swiftlang:next Sep 25, 2025
0 of 2 checks passed
@patrykstefanski patrykstefanski deleted the eng/pstefanski/PR-140995829 branch September 25, 2025 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bounds-safety Issue relating to the experimental -fbounds-safety feature in Clang

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants