Skip to content
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

Support compiler-agnostic annotations #2456

Merged
merged 1 commit into from Sep 29, 2020

Conversation

erimatnor
Copy link
Contributor

@erimatnor erimatnor commented Sep 28, 2020

This change adds a compiler-agnostic annotation for fall-throughs in
switch statements. The definition is put in annotations.h, which can
be expanded to hold definitions for similar functionality in the
future.

The clang compiler (as of version 12) seems to have have dropped
support for the previous comment-based annotations to allow
fall-throughs in favor of native annotations or GCC-style attributes.

@erimatnor erimatnor force-pushed the compiler-agnostic-annotations branch 4 times, most recently from 824b44d to bd8a003 Compare September 28, 2020 10:28
@erimatnor
Copy link
Contributor Author

Recently updated my Mac, which now has LLVM/Clang 12.0, which could no longer compile TimescaleDB since it seems to no longer accept /* FALLTHROUGH */

@codecov
Copy link

codecov bot commented Sep 28, 2020

Codecov Report

Merging #2456 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2456      +/-   ##
==========================================
+ Coverage   90.10%   90.12%   +0.01%     
==========================================
  Files         213      213              
  Lines       34336    34356      +20     
==========================================
+ Hits        30940    30964      +24     
+ Misses       3396     3392       -4     
Impacted Files Coverage Δ
src/copy.c 87.86% <ø> (-0.20%) ⬇️
src/indexing.c 94.87% <ø> (ø)
src/planner.c 93.80% <ø> (ø)
tsl/src/remote/dist_ddl.c 98.66% <ø> (ø)
src/cache_invalidate.c 84.44% <100.00%> (+0.72%) ⬆️
src/loader/bgw_launcher.c 89.53% <100.00%> (ø)
src/process_utility.c 93.70% <100.00%> (+0.05%) ⬆️
tsl/src/continuous_aggs/invalidation.c 98.18% <100.00%> (+0.02%) ⬆️
src/loader/bgw_message_queue.c 87.09% <0.00%> (-0.65%) ⬇️
tsl/src/fdw/shippable.c 94.28% <0.00%> (+11.42%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6cc9871...fb7fa7f. Read the comment docs.

@erimatnor erimatnor marked this pull request as ready for review September 28, 2020 11:28
@erimatnor erimatnor requested a review from a team as a code owner September 28, 2020 11:28
Comment on lines 21 to 22
#else
#error "unsupported compiler"
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you should generate an error if there is no way to annotate a fall-through. Either the compile will complain about that, or not, but there is no reason to prevent it from compiling.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

/* Fall-through annotation */
#if defined(__clang__)
#if (__clang_major__ >= 12) || (__clang_analyzer__)
#define TS_FALLTHROUGH __attribute__((fallthrough))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to note that it is also possible to write /* fallthough */ comment which will be recognized, maybe it could be easier to support in some sense

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the issue. It seems to no longer be supported in clang 12 (at least on the mac)

This change adds a compiler-agnostic annotation for fall-throughs in
switch statements. The definition is put in `annotations.h`, which can
be expanded to hold definitions for similar functionality in the
future.

The `clang` compiler (as of version 12) seems to have have dropped
support for the previous comment-based annotations to allow
fall-throughs in favor of native annotations or GCC-style attributes.
#if (__clang_major__ >= 12) || (__clang_analyzer__)
#define TS_FALLTHROUGH __attribute__((fallthrough))
#else
#define TS_FALLTHROUGH /* FALLTHROUGH */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that worries me here is that both comments and macros symbols are handled by the preprocessor. Have you tested this with a compiler that uses the /* FALLTHROUGH */ syntax? I think that the standard builds-on-push do that but can you please verify before pushing.

Copy link
Contributor Author

@erimatnor erimatnor Sep 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used the /* FALLTHROUGH */ syntax prior to this PR. But clang seems to have dropped support for it in favor of the GCC-compatible attribute. AFAIK, the CI still runs a pre 12 clang, so should still use /* FALLTHROUGH */.

@erimatnor erimatnor merged commit 882a247 into timescale:master Sep 29, 2020
@erimatnor erimatnor deleted the compiler-agnostic-annotations branch September 29, 2020 04:54
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.

None yet

3 participants