Skip to content

Conversation

@lb90
Copy link

@lb90 lb90 commented Jul 18, 2025

This uncovers a small issue when compiling with CLang:

/bin/sh ../libtool  --tag=CC   --mode=link clang  -g -O2   -o stage1flex stage1flex-scan.o stage1flex-buf.o stage1flex-ccl.o stage1flex-dfa.o stage1flex-ecs.o stage1flex-filter.o stage1flex-gen.o stage1flex-main.o stage1flex-misc.o stage1flex-nfa.o stage1flex-options.o stage1flex-parse.o stage1flex-regex.o stage1flex-scanflags.o stage1flex-scanopt.o stage1flex-skeletons.o stage1flex-sym.o stage1flex-tables.o stage1flex-tables_shared.o stage1flex-tblcmp.o stage1flex-yylex.o     -lm 
libtool: link: clang -g -O2 -o stage1flex stage1flex-scan.o stage1flex-buf.o stage1flex-ccl.o stage1flex-dfa.o stage1flex-ecs.o stage1flex-filter.o stage1flex-gen.o stage1flex-main.o stage1flex-misc.o stage1flex-nfa.o stage1flex-options.o stage1flex-parse.o stage1flex-regex.o stage1flex-scanflags.o stage1flex-scanopt.o stage1flex-skeletons.o stage1flex-sym.o stage1flex-tables.o stage1flex-tables_shared.o stage1flex-tblcmp.o stage1flex-yylex.o  -lm
( cd . && /mnt/store/flex-clang/src/stage1flex \
    -o scan.c -t scan.l ) >stage1scan.c || \
{ s=$?; rm -f stage1scan.c; exit $s; }
depbase=`echo stage1scan.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
clang -DHAVE_CONFIG_H -I.  -DLOCALEDIR=\"/usr/share/locale\"   -g -O2 -MT stage1scan.o -MD -MP -MF $depbase.Tpo -c -o stage1scan.o stage1scan.c &&\
mv -f $depbase.Tpo $depbase.Po
scan.c:5240:2: error: fallthrough annotation does not directly precede switch label
 5240 |         __attribute__((fallthrough));
      |         ^

Here's the generated code:

stage1scan.c:

	case YY_STATE_EOF(OPTION):

	#ifdef __clang__
	__attribute__((fallthrough));
	#endif
	/* FALLTHROUGH */

	case YY_STATE_EOF(LINEDIR):

	#ifdef __clang__
	__attribute__((fallthrough));
	#endif
	/* FALLTHROUGH */                 /* issue: FALLTHROUGH but there's a statement below */

		yyterminate();

			case YY_END_OF_BUFFER:
			{
				/* Amount of text matched not including the EOB char. */
				int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;

The error should happen also with GCC should we use [[fallthrough]] (since C++17, C23)

Fixes #427

@lb90 lb90 force-pushed the attribute-fallthrough-clang branch from f60ea3d to 8875d23 Compare July 18, 2025 20:14
@lb90 lb90 changed the title WIP: Use __attribute__((fallthrough)) on CLang WIP: [C99, CPP]: Use fallthrough attribute if available Jul 18, 2025
@Mightyjo
Copy link
Contributor

Please use the hooks instead of defining new yy* functions in C. We're in the process of making the skeleton code generation language agnostic.

You can still include the feature check in the macro definition. Quoting can be a little is all.

@lb90 lb90 force-pushed the attribute-fallthrough-clang branch from 8875d23 to f85c324 Compare July 19, 2025 09:30
@lb90 lb90 changed the title WIP: [C99, CPP]: Use fallthrough attribute if available [c99, cpp]: Use fallthrough attribute Jul 19, 2025
@lb90
Copy link
Author

lb90 commented Jul 19, 2025

Thanks! I have also fixed the build error by not emitting EOF_STATE_CASE_FALLTHROUGH before EOF_STATE_CASE_TERMINATE: 0aac7c32.

An other way is to add an explicit EOF_STATE_CASE_FALLTHROUGH_TO_TERMINATE

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.

Flex should use '__attribute__((fallthrough))' instead of /*FALLTHROUGH*/

3 participants