Skip to content

Stop assuming CFSTR is a constant-time expression with Clang 15 #4872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Feb 14, 2024

From Clang 15, nested static initializer inside statement-expression is no longer a constant-time expression (See https://reviews.llvm.org/D127201). OSS Foundation defines CFSTR as a macro rather than __builtin___CFStringMakeConstantString and it uses nested static initializer inside statement-expression, so we can't assume CFSTR itself is always a constant-time expression.
This patch removes some static qualifiers associated with CFSTR to make them acceptable with Clang 15 and later.

I confirmed there is no change at LLVM IR level between before/after this patch with Clang 14 and -O3, so I assume Clang 15 and later also can optimize those non-static variables to be static global rodata. So this fix does not cause any performance regression.

This issue was originally found in #4866 (comment)

From Clang 15, nested static initializer inside statement-expression is no
longer a constant-time expression (See https://reviews.llvm.org/D127201).
OSS Foundation defines `CFSTR` as a macro rather than
`__builtin___CFStringMakeConstantString` and it uses nested static
initializer inside statement-expression, so we can't assume `CFSTR` itself
is always a constant-time expression.
This patch removes some `static` qualifiers associated with `CFSTR` to
make them acceptable with Clang 15 and later.
@kateinoigakukun
Copy link
Member Author

@swift-ci Please test

@kateinoigakukun
Copy link
Member Author

kateinoigakukun commented Feb 14, 2024

The original issue seems fixed, but XCTest is still failing due to another issue (will be fixed by #4873)

https://ci.swift.org/job/swift-corelibs-foundation-PR-macOS/364/console

# command stderr:
dyld[47446]: Symbol not found: _swift_getTypeByMangledNameInContext2
  Referenced from: <7B2821A0-0F0D-3D4D-B6AA-B823A43D0D5E> /Users/ec2-user/jenkins/workspace/swift-corelibs-foundation-PR-macOS/branch-main/swift-corelibs-xctest/Tests/Functional/TestCaseLifecycle/Output/TestCaseLifecycle (built for macOS 14.2 which is newer than running OS)
  Expected in:     <087DADAD-D590-35EA-AC4D-7B0E966804EB> /usr/lib/swift/libswiftCore.dylib

error: command failed with exit status: -6

@parkera parkera merged commit dc54902 into swiftlang:main Feb 15, 2024
@kateinoigakukun
Copy link
Member Author

Thanks!

@kateinoigakukun kateinoigakukun deleted the yt/fix-clang-15-issue branch February 15, 2024 17:29
parkera pushed a commit to parkera/swift-corelibs-foundation that referenced this pull request Feb 15, 2024
…iftlang#4872)

From Clang 15, nested static initializer inside statement-expression is no
longer a constant-time expression (See https://reviews.llvm.org/D127201).
OSS Foundation defines `CFSTR` as a macro rather than
`__builtin___CFStringMakeConstantString` and it uses nested static
initializer inside statement-expression, so we can't assume `CFSTR` itself
is always a constant-time expression.
This patch removes some `static` qualifiers associated with `CFSTR` to
make them acceptable with Clang 15 and later.
etcwilde pushed a commit to etcwilde/swift-corelibs-foundation that referenced this pull request May 11, 2024
…iftlang#4872)

From Clang 15, nested static initializer inside statement-expression is no
longer a constant-time expression (See https://reviews.llvm.org/D127201).
OSS Foundation defines `CFSTR` as a macro rather than
`__builtin___CFStringMakeConstantString` and it uses nested static
initializer inside statement-expression, so we can't assume `CFSTR` itself
is always a constant-time expression.
This patch removes some `static` qualifiers associated with `CFSTR` to
make them acceptable with Clang 15 and later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants