Skip to content

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

Merged
merged 7 commits into from
Oct 9, 2019

Conversation

kkjeer
Copy link
Contributor

@kkjeer kkjeer commented Oct 3, 2019

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:

void f(_Array_ptr<int> p : bounds(p, p + 1) rel_align(char);
void f(_Array_ptr<int> p : bounds(p, p + 1) rel_align(double) {}

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:

  • Add bounds-rel-align.c to test function declarations involving parameters with rel_align and rel_align_value clauses
  • Existing tests pass


if (S->hasRelativeBoundsClause()) {
RelativeBoundsClause *R = S->getRelativeBoundsClause();
switch (R->getClauseKind()) {

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.

case RelativeBoundsClause::Kind::Const:
VisitExpr(cast<RelativeConstExprBoundsClause>(R)->getConstExpr());
break;
default: {

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");

Copy link
Member

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;

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?

Copy link
Member

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.

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.

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
Copy link
Member

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;
Copy link
Member

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.

case RelativeBoundsClause::Kind::Const:
VisitExpr(cast<RelativeConstExprBoundsClause>(R)->getConstExpr());
break;
default: {
Copy link
Member

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.

if (S->hasRelativeBoundsClause()) {
RelativeBoundsClause *R = S->getRelativeBoundsClause();
RelativeBoundsClause::Kind CK = R->getClauseKind();
if (CK == RelativeBoundsClause::Kind::Type) {
Copy link

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.

@kkjeer kkjeer merged commit da2b542 into master Oct 9, 2019
@kkjeer kkjeer deleted the issue331-stmtprofile-missing-bounds-info branch October 9, 2019 17:41
mgrang pushed a commit that referenced this pull request Oct 11, 2019
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
Machiry pushed a commit to Machiry/checkedc-clang that referenced this pull request Jan 21, 2022
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.
Machiry pushed a commit to Machiry/checkedc-clang that referenced this pull request Jan 21, 2022
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.
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.

4 participants