-
Notifications
You must be signed in to change notification settings - Fork 79
Add relative alignment to StmtProfiler::VisitRangeBoundsExpr #692
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
Conversation
lib/AST/StmtProfile.cpp
Outdated
|
||
if (S->hasRelativeBoundsClause()) { | ||
RelativeBoundsClause *R = S->getRelativeBoundsClause(); | ||
switch (R->getClauseKind()) { |
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.
Nit: There are only two valid clause kinds for RelativeBoundsClause. An if-statement might be simpler to use here rather than a switch-case. For example, see ASTDumper::VisitRangeBoundsExpr.
lib/AST/StmtProfile.cpp
Outdated
case RelativeBoundsClause::Kind::Const: | ||
VisitExpr(cast<RelativeConstExprBoundsClause>(R)->getConstExpr()); | ||
break; | ||
default: { |
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.
You can add this here: llvm_unreachable("unexpected kind field of relative bounds clause");
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.
I agree with this suggestion.
// Test declaration and definition of functions with a range bounds parameter with a rel_align_value clause. | ||
// | ||
|
||
const int val1 = 6; |
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.
Have you tried with more complicated compile time expressions like constexpr int val3 = foo(); where "foo" returns '5+1' as a constexpr?
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.
This test is for C, not C++, so we don't have constexpr available.
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.
Overall, looks great. I agree that you should use llvm_unreachable if the code unexpectedl falls into a default block.
// Tests for checking that function declarations involving range bounds | ||
// account for relative alignment information. | ||
// | ||
// RUN: %clang -cc1 -fcheckedc-extension -Wcheck-bounds-decls -verify %s |
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.
You don't need the -fcheckedc-extension flag.
// Test declaration and definition of functions with a range bounds parameter with a rel_align_value clause. | ||
// | ||
|
||
const int val1 = 6; |
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.
This test is for C, not C++, so we don't have constexpr available.
lib/AST/StmtProfile.cpp
Outdated
case RelativeBoundsClause::Kind::Const: | ||
VisitExpr(cast<RelativeConstExprBoundsClause>(R)->getConstExpr()); | ||
break; | ||
default: { |
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.
I agree with this suggestion.
lib/AST/StmtProfile.cpp
Outdated
if (S->hasRelativeBoundsClause()) { | ||
RelativeBoundsClause *R = S->getRelativeBoundsClause(); | ||
RelativeBoundsClause::Kind CK = R->getClauseKind(); | ||
if (CK == RelativeBoundsClause::Kind::Type) { |
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.
You can leave out braces in single statement if's.
Cherry-picked from commit da2b542 Author: Katherine Kjeer <[email protected]> Commit: GitHub <[email protected]> Add relative alignment to StmtProfiler::VisitRangeBoundsExpr (#692) * Remove unused BoundsCastExpr::SyntaxType enum * Visit relative bounds clause in StmtProfiler::VisitRangeBoundsExpr * Add nullptr to ID for RangeBoundsExpr with no relative alignment * Add tests for range bounds with relative alignment * Use if/else instead of switch * Remove unnecessary -fcheckedc-extension from test * Remove braces from single statement if's
We previously used the _3COptions structure to store command line options immediately after they were parsed, but later copied the option values out of this structure and into global variables for use in the rest of the program. This change deletes the global variables and replaces them with a single global instance of the _3COptions structure.
This is a follow up PR from checkedc#692 that moves all command line options into the _3COptions structure, moves all of 3C's command line options into the same category so that all options are shown by -help (fixes checkedc#393), and reformats some of the code around creating command line options. It also removes the the option -enable-itypeprop which was not referenced anywhere in the code.
Visit the relative bounds clause (if any) for a RangeBoundsExpr in StmtProfiler::VisitRangeBoundsExpr. This means that examples such as the following now do not compile:
This addresses the first part of issue #331 (VisitRangeBoundsExpr needs to examine relative alignment information). Issue #691 tracks work related to VisitBoundsCastExpr and will be addressed in a separate PR.
Tests: