Skip to content
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

Correctly determine bounds for predefined literals #673

Merged
merged 8 commits into from
Sep 14, 2019
Merged

Correctly determine bounds for predefined literals #673

merged 8 commits into from
Sep 14, 2019

Conversation

mgrang
Copy link

@mgrang mgrang commented Aug 22, 2019

This fixes issue #650 .

@mgrang
Copy link
Author

mgrang commented Aug 22, 2019

This is WIP. I will soon add comments and unit tests to this patch.

@mgrang mgrang changed the title Correctly determine bounds for predefined literals [WIP] Correctly determine bounds for predefined literals Aug 22, 2019
@mgrang
Copy link
Author

mgrang commented Aug 22, 2019

Have asked @Machiry to verify whether this fixes the issue he reported.

@mgrang
Copy link
Author

mgrang commented Aug 24, 2019

Added a simple test case. Will add more complex ones soon.

@mgrang mgrang closed this Aug 24, 2019
@mgrang mgrang reopened this Aug 24, 2019
@mgrang mgrang changed the title [WIP] Correctly determine bounds for predefined literals Correctly determine bounds for predefined literals Aug 26, 2019
@mgrang
Copy link
Author

mgrang commented Aug 26, 2019

Run time tests for predefined literals added in checkedc/checkedc#380.

Copy link
Member

@dtarditi dtarditi left a comment

Choose a reason for hiding this comment

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

For a string literal expression, we always bind the result of the expression to a temporary. We then use this temporary in the bounds expression for the string literal expression. Unfortunately, I think you need to do something similar here. Otherwise, a runtime bounds check based on accessing the predefined expression could be incorrect: the base value could be different for the lower and upper bounds.

Copy link
Member

@dtarditi dtarditi left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@dtarditi dtarditi merged commit 6252abb into master Sep 14, 2019
@mgrang mgrang deleted the fix2 branch September 14, 2019 16:57
mgrang pushed a commit that referenced this pull request Sep 27, 2019
Cherry-picked from commit 6252abb

    Correctly determine bounds for predefined literals.  Section 6.4.2.2 of the C11 Standard defines predefined identifiers: the special identifier __func__ evaluates to a string that is the name of the current function.

    In clang, predefined identifiers are represented using the PredefinedExpr class, which wraps a string literal.   The PredefinedExpr class evaluates to an lvalue that is the address of the string literal.   To represent bounds information, follow the same pattern that we use for string literals:.  Bind the result of the PredefinedExpr class to a temporary and use the temporary in the bounds of the expression.   We considered having the class wrap a temporary expression, but that causes existing tests of predefined literals to break and requires more changes to the compiler logic for predefined expressions.
mgrang pushed a commit that referenced this pull request Sep 27, 2019
Cherry-picked from commit 6252abb

    Correctly determine bounds for predefined literals.  Section 6.4.2.2 of the C11 Standard defines predefined identifiers: the special identifier __func__ evaluates to a string that is the name of the current function.

    In clang, predefined identifiers are represented using the PredefinedExpr class, which wraps a string literal.   The PredefinedExpr class evaluates to an lvalue that is the address of the string literal.   To represent bounds information, follow the same pattern that we use for string literals:.  Bind the result of the PredefinedExpr class to a temporary and use the temporary in the bounds of the expression.   We considered having the class wrap a temporary expression, but that causes existing tests of predefined literals to break and requires more changes to the compiler logic for predefined expressions.
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