Skip to content

C17 and C23 support #8620

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
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ansi-c/ansi_c_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class ansi_c_parsert:public parsert
typedef configt::ansi_ct::flavourt modet;
modet mode;

// recognize C++98 and C++11 keywords
bool cpp98, cpp11;
// recognize C++98, C++11, C17, C23 keywords
bool cpp98, cpp11, c17, c23;

// in C99 and upwards, for(;;) has a scope
bool for_has_scope;
Expand Down
33 changes: 32 additions & 1 deletion src/ansi-c/c_preprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,24 @@
#endif
argv.push_back("-std=gnu11");
break;

case configt::ansi_ct::c_standardt::C17:

Check warning on line 593 in src/ansi-c/c_preprocess.cpp

View check run for this annotation

Codecov / codecov/patch

src/ansi-c/c_preprocess.cpp#L593

Added line #L593 was not covered by tests
#if defined(__OpenBSD__)
if(preprocessor == configt::ansi_ct::preprocessort::CLANG)
argv.push_back("-std=c17");
else
#endif
argv.push_back("-std=gnu17");
break;

Check warning on line 600 in src/ansi-c/c_preprocess.cpp

View check run for this annotation

Codecov / codecov/patch

src/ansi-c/c_preprocess.cpp#L599-L600

Added lines #L599 - L600 were not covered by tests

case configt::ansi_ct::c_standardt::C23:

Check warning on line 602 in src/ansi-c/c_preprocess.cpp

View check run for this annotation

Codecov / codecov/patch

src/ansi-c/c_preprocess.cpp#L602

Added line #L602 was not covered by tests
#if defined(__OpenBSD__)
if(preprocessor == configt::ansi_ct::preprocessort::CLANG)
argv.push_back("-std=c23");
else
#endif
argv.push_back("-std=gnu23");
break;

Check warning on line 609 in src/ansi-c/c_preprocess.cpp

View check run for this annotation

Codecov / codecov/patch

src/ansi-c/c_preprocess.cpp#L608-L609

Added lines #L608 - L609 were not covered by tests
}
}

Expand Down Expand Up @@ -672,16 +690,29 @@
argv.push_back("--signed_chars");

// Set the standard
// https://developer.arm.com/documentation/101458/2404/Standards-support/Supported-C-C---standards-in-Arm-C-C---Compiler
switch(config.ansi_c.c_standard)
{
case configt::ansi_ct::c_standardt::C89:
argv.push_back("--c90");
break;

case configt::ansi_ct::c_standardt::C99:
case configt::ansi_ct::c_standardt::C11:
argv.push_back("--c99");
break;

case configt::ansi_ct::c_standardt::C11:
argv.push_back("--c11");
break;

Check warning on line 706 in src/ansi-c/c_preprocess.cpp

View check run for this annotation

Codecov / codecov/patch

src/ansi-c/c_preprocess.cpp#L704-L706

Added lines #L704 - L706 were not covered by tests

case configt::ansi_ct::c_standardt::C17:
argv.push_back("--c17");
break;

Check warning on line 710 in src/ansi-c/c_preprocess.cpp

View check run for this annotation

Codecov / codecov/patch

src/ansi-c/c_preprocess.cpp#L708-L710

Added lines #L708 - L710 were not covered by tests

case configt::ansi_ct::c_standardt::C23:

Check warning on line 712 in src/ansi-c/c_preprocess.cpp

View check run for this annotation

Codecov / codecov/patch

src/ansi-c/c_preprocess.cpp#L712

Added line #L712 was not covered by tests
// C23 is not yet supported by armcc
argv.push_back("--c17");
break;

Check warning on line 715 in src/ansi-c/c_preprocess.cpp

View check run for this annotation

Codecov / codecov/patch

src/ansi-c/c_preprocess.cpp#L714-L715

Added lines #L714 - L715 were not covered by tests
}

for(const auto &define : config.ansi_c.defines)
Expand Down
22 changes: 22 additions & 0 deletions src/ansi-c/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,28 @@
return make_identifier();
}

int c17_keyword(int token)

Check warning on line 174 in src/ansi-c/scanner.l

View check run for this annotation

Codecov / codecov/patch

src/ansi-c/scanner.l#L174

Added line #L174 was not covered by tests
{
if(PARSER.c17)
{
loc();
return token;

Check warning on line 179 in src/ansi-c/scanner.l

View check run for this annotation

Codecov / codecov/patch

src/ansi-c/scanner.l#L178-L179

Added lines #L178 - L179 were not covered by tests
}
else
return make_identifier();

Check warning on line 182 in src/ansi-c/scanner.l

View check run for this annotation

Codecov / codecov/patch

src/ansi-c/scanner.l#L182

Added line #L182 was not covered by tests
}

int c23_keyword(int token)

Check warning on line 185 in src/ansi-c/scanner.l

View check run for this annotation

Codecov / codecov/patch

src/ansi-c/scanner.l#L185

Added line #L185 was not covered by tests
{
if(PARSER.c23)
{
loc();
return token;

Check warning on line 190 in src/ansi-c/scanner.l

View check run for this annotation

Codecov / codecov/patch

src/ansi-c/scanner.l#L189-L190

Added lines #L189 - L190 were not covered by tests
}
else
return make_identifier();

Check warning on line 193 in src/ansi-c/scanner.l

View check run for this annotation

Codecov / codecov/patch

src/ansi-c/scanner.l#L193

Added line #L193 was not covered by tests
}

int MSC_cpp_keyword(int token)
{
if(PARSER.cpp98 && PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO)
Expand Down
20 changes: 19 additions & 1 deletion src/util/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class symbol_table_baset;
: configt::ansi_ct::default_c_standard() == \
configt::ansi_ct::c_standardt::C11 \
? "c11" \
: configt::ansi_ct::default_c_standard() == \
configt::ansi_ct::c_standardt::C17 \
? "c17" \
: configt::ansi_ct::default_c_standard() == \
configt::ansi_ct::c_standardt::C23 \
? "c23" \
: "") + \
")\n" \
" {y--cpp98}, {y--cpp03}, {y--cpp11} \t " \
Expand Down Expand Up @@ -166,7 +172,9 @@ class configt
{
C89,
C99,
C11
C11,
C17,
C23
} c_standard;
static c_standardt default_c_standard();

Expand All @@ -185,6 +193,16 @@ class configt
c_standard = c_standardt::C11;
for_has_scope = true;
}
void set_c17()
{
c_standard = c_standardt::C17;
for_has_scope = true;
}
void set_c23()
{
c_standard = c_standardt::C23;
for_has_scope = true;
}

ieee_floatt::rounding_modet rounding_mode;

Expand Down
Loading