-
Notifications
You must be signed in to change notification settings - Fork 74
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
Conversation
This is WIP. I will soon add comments and unit tests to this patch. |
Have asked @Machiry to verify whether this fixes the issue he reported. |
Added a simple test case. Will add more complex ones soon. |
Run time tests for predefined literals added in checkedc/checkedc#380. |
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
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.
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.
This fixes issue #650 .