Skip to content

Commit 3e97444

Browse files
committed
Add -Wimplicit-fallthrough to CFLAGS and CXXFLAGS
Use it at level 4, a bit more restrictive than the default level, and tweak our commanding comments to FALLTHROUGH. (However, leave zic.c alone, since it's external code; to avoid the warnings that would appear there, change CFLAGS for that file in the Makefile.) Author: Julien Rouhaud <rjuju123@gmail.com> Author: Álvaro Herrera <alvherre@alvh.no-ip.org> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/20200412081825.qyo5vwwco3fv4gdo@nol Discussion: https://postgr.es/m/flat/E1fDenm-0000C8-IJ@gemulon.postgresql.org
1 parent 6a918c3 commit 3e97444

File tree

33 files changed

+269
-171
lines changed

33 files changed

+269
-171
lines changed

configure

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5552,6 +5552,97 @@ if test x"$pgac_cv_prog_CXX_cxxflags__Wmissing_format_attribute" = x"yes"; then
55525552
fi
55535553

55545554

5555+
5556+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wimplicit-fallthrough=4, for CFLAGS" >&5
5557+
$as_echo_n "checking whether ${CC} supports -Wimplicit-fallthrough=4, for CFLAGS... " >&6; }
5558+
if ${pgac_cv_prog_CC_cflags__Wimplicit_fallthrough_4+:} false; then :
5559+
$as_echo_n "(cached) " >&6
5560+
else
5561+
pgac_save_CFLAGS=$CFLAGS
5562+
pgac_save_CC=$CC
5563+
CC=${CC}
5564+
CFLAGS="${CFLAGS} -Wimplicit-fallthrough=4"
5565+
ac_save_c_werror_flag=$ac_c_werror_flag
5566+
ac_c_werror_flag=yes
5567+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
5568+
/* end confdefs.h. */
5569+
5570+
int
5571+
main ()
5572+
{
5573+
5574+
;
5575+
return 0;
5576+
}
5577+
_ACEOF
5578+
if ac_fn_c_try_compile "$LINENO"; then :
5579+
pgac_cv_prog_CC_cflags__Wimplicit_fallthrough_4=yes
5580+
else
5581+
pgac_cv_prog_CC_cflags__Wimplicit_fallthrough_4=no
5582+
fi
5583+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
5584+
ac_c_werror_flag=$ac_save_c_werror_flag
5585+
CFLAGS="$pgac_save_CFLAGS"
5586+
CC="$pgac_save_CC"
5587+
fi
5588+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__Wimplicit_fallthrough_4" >&5
5589+
$as_echo "$pgac_cv_prog_CC_cflags__Wimplicit_fallthrough_4" >&6; }
5590+
if test x"$pgac_cv_prog_CC_cflags__Wimplicit_fallthrough_4" = x"yes"; then
5591+
CFLAGS="${CFLAGS} -Wimplicit-fallthrough=4"
5592+
fi
5593+
5594+
5595+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports -Wimplicit-fallthrough=4, for CXXFLAGS" >&5
5596+
$as_echo_n "checking whether ${CXX} supports -Wimplicit-fallthrough=4, for CXXFLAGS... " >&6; }
5597+
if ${pgac_cv_prog_CXX_cxxflags__Wimplicit_fallthrough_4+:} false; then :
5598+
$as_echo_n "(cached) " >&6
5599+
else
5600+
pgac_save_CXXFLAGS=$CXXFLAGS
5601+
pgac_save_CXX=$CXX
5602+
CXX=${CXX}
5603+
CXXFLAGS="${CXXFLAGS} -Wimplicit-fallthrough=4"
5604+
ac_save_cxx_werror_flag=$ac_cxx_werror_flag
5605+
ac_cxx_werror_flag=yes
5606+
ac_ext=cpp
5607+
ac_cpp='$CXXCPP $CPPFLAGS'
5608+
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
5609+
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
5610+
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
5611+
5612+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
5613+
/* end confdefs.h. */
5614+
5615+
int
5616+
main ()
5617+
{
5618+
5619+
;
5620+
return 0;
5621+
}
5622+
_ACEOF
5623+
if ac_fn_cxx_try_compile "$LINENO"; then :
5624+
pgac_cv_prog_CXX_cxxflags__Wimplicit_fallthrough_4=yes
5625+
else
5626+
pgac_cv_prog_CXX_cxxflags__Wimplicit_fallthrough_4=no
5627+
fi
5628+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
5629+
ac_ext=c
5630+
ac_cpp='$CPP $CPPFLAGS'
5631+
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
5632+
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
5633+
ac_compiler_gnu=$ac_cv_c_compiler_gnu
5634+
5635+
ac_cxx_werror_flag=$ac_save_cxx_werror_flag
5636+
CXXFLAGS="$pgac_save_CXXFLAGS"
5637+
CXX="$pgac_save_CXX"
5638+
fi
5639+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CXX_cxxflags__Wimplicit_fallthrough_4" >&5
5640+
$as_echo "$pgac_cv_prog_CXX_cxxflags__Wimplicit_fallthrough_4" >&6; }
5641+
if test x"$pgac_cv_prog_CXX_cxxflags__Wimplicit_fallthrough_4" = x"yes"; then
5642+
CXXFLAGS="${CXXFLAGS} -Wimplicit-fallthrough=4"
5643+
fi
5644+
5645+
55555646
# This was included in -Wall/-Wformat in older GCC versions
55565647

55575648
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wformat-security, for CFLAGS" >&5

configure.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ if test "$GCC" = yes -a "$ICC" = no; then
496496
PGAC_PROG_CXX_CFLAGS_OPT([-Wendif-labels])
497497
PGAC_PROG_CC_CFLAGS_OPT([-Wmissing-format-attribute])
498498
PGAC_PROG_CXX_CFLAGS_OPT([-Wmissing-format-attribute])
499+
PGAC_PROG_CC_CFLAGS_OPT([-Wimplicit-fallthrough=4])
500+
PGAC_PROG_CXX_CFLAGS_OPT([-Wimplicit-fallthrough=4])
499501
# This was included in -Wall/-Wformat in older GCC versions
500502
PGAC_PROG_CC_CFLAGS_OPT([-Wformat-security])
501503
PGAC_PROG_CXX_CFLAGS_OPT([-Wformat-security])

src/backend/access/heap/heapam_handler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ heapam_relation_copy_for_cluster(Relation OldHeap, Relation NewHeap,
814814
break;
815815
case HEAPTUPLE_RECENTLY_DEAD:
816816
*tups_recently_dead += 1;
817-
/* fall through */
817+
/* FALLTHROUGH */
818818
case HEAPTUPLE_LIVE:
819819
/* Live or recently dead, must copy it */
820820
isdead = false;

src/backend/catalog/dependency.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ findDependentObjects(const ObjectAddress *object,
615615
break;
616616

617617
/* Otherwise, treat this like an internal dependency */
618-
/* FALL THRU */
618+
/* FALLTHROUGH */
619619

620620
case DEPENDENCY_INTERNAL:
621621

src/backend/commands/tablecmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12467,7 +12467,7 @@ ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, LOCKMODE lock
1246712467
case RELKIND_TOASTVALUE:
1246812468
if (recursing)
1246912469
break;
12470-
/* FALL THRU */
12470+
/* FALLTHROUGH */
1247112471
default:
1247212472
ereport(ERROR,
1247312473
(errcode(ERRCODE_WRONG_OBJECT_TYPE),

src/backend/commands/trigger.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3877,7 +3877,7 @@ AfterTriggerExecute(EState *estate,
38773877
trig_tuple_slot2))
38783878
elog(ERROR, "failed to fetch tuple2 for AFTER trigger");
38793879
}
3880-
/* fall through */
3880+
/* FALLTHROUGH */
38813881
case AFTER_TRIGGER_FDW_REUSE:
38823882

38833883
/*

src/backend/executor/nodeHash.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ MultiExecParallelHash(HashState *node)
256256
* way, wait for everyone to arrive here so we can proceed.
257257
*/
258258
BarrierArriveAndWait(build_barrier, WAIT_EVENT_HASH_BUILD_ALLOCATING);
259-
/* Fall through. */
259+
/* FALLTHROUGH */
260260

261261
case PHJ_BUILD_HASHING_INNER:
262262

@@ -1181,13 +1181,13 @@ ExecParallelHashIncreaseNumBatches(HashJoinTable hashtable)
11811181
/* All other participants just flush their tuples to disk. */
11821182
ExecParallelHashCloseBatchAccessors(hashtable);
11831183
}
1184-
/* Fall through. */
1184+
/* FALLTHROUGH */
11851185

11861186
case PHJ_GROW_BATCHES_ALLOCATING:
11871187
/* Wait for the above to be finished. */
11881188
BarrierArriveAndWait(&pstate->grow_batches_barrier,
11891189
WAIT_EVENT_HASH_GROW_BATCHES_ALLOCATING);
1190-
/* Fall through. */
1190+
/* FALLTHROUGH */
11911191

11921192
case PHJ_GROW_BATCHES_REPARTITIONING:
11931193
/* Make sure that we have the current dimensions and buckets. */
@@ -1200,7 +1200,7 @@ ExecParallelHashIncreaseNumBatches(HashJoinTable hashtable)
12001200
/* Wait for the above to be finished. */
12011201
BarrierArriveAndWait(&pstate->grow_batches_barrier,
12021202
WAIT_EVENT_HASH_GROW_BATCHES_REPARTITIONING);
1203-
/* Fall through. */
1203+
/* FALLTHROUGH */
12041204

12051205
case PHJ_GROW_BATCHES_DECIDING:
12061206

@@ -1255,7 +1255,7 @@ ExecParallelHashIncreaseNumBatches(HashJoinTable hashtable)
12551255
dsa_free(hashtable->area, pstate->old_batches);
12561256
pstate->old_batches = InvalidDsaPointer;
12571257
}
1258-
/* Fall through. */
1258+
/* FALLTHROUGH */
12591259

12601260
case PHJ_GROW_BATCHES_FINISHING:
12611261
/* Wait for the above to complete. */
@@ -1533,13 +1533,13 @@ ExecParallelHashIncreaseNumBuckets(HashJoinTable hashtable)
15331533
/* Clear the flag. */
15341534
pstate->growth = PHJ_GROWTH_OK;
15351535
}
1536-
/* Fall through. */
1536+
/* FALLTHROUGH */
15371537

15381538
case PHJ_GROW_BUCKETS_ALLOCATING:
15391539
/* Wait for the above to complete. */
15401540
BarrierArriveAndWait(&pstate->grow_buckets_barrier,
15411541
WAIT_EVENT_HASH_GROW_BUCKETS_ALLOCATING);
1542-
/* Fall through. */
1542+
/* FALLTHROUGH */
15431543

15441544
case PHJ_GROW_BUCKETS_REINSERTING:
15451545
/* Reinsert all tuples into the hash table. */

src/backend/executor/nodeHashjoin.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ ExecHashJoinImpl(PlanState *pstate, bool parallel)
340340
else
341341
node->hj_JoinState = HJ_NEED_NEW_OUTER;
342342

343-
/* FALL THRU */
343+
/* FALLTHROUGH */
344344

345345
case HJ_NEED_NEW_OUTER:
346346

@@ -413,7 +413,7 @@ ExecHashJoinImpl(PlanState *pstate, bool parallel)
413413
/* OK, let's scan the bucket for matches */
414414
node->hj_JoinState = HJ_SCAN_BUCKET;
415415

416-
/* FALL THRU */
416+
/* FALLTHROUGH */
417417

418418
case HJ_SCAN_BUCKET:
419419

@@ -1137,13 +1137,13 @@ ExecParallelHashJoinNewBatch(HashJoinState *hjstate)
11371137
if (BarrierArriveAndWait(batch_barrier,
11381138
WAIT_EVENT_HASH_BATCH_ELECTING))
11391139
ExecParallelHashTableAlloc(hashtable, batchno);
1140-
/* Fall through. */
1140+
/* FALLTHROUGH */
11411141

11421142
case PHJ_BATCH_ALLOCATING:
11431143
/* Wait for allocation to complete. */
11441144
BarrierArriveAndWait(batch_barrier,
11451145
WAIT_EVENT_HASH_BATCH_ALLOCATING);
1146-
/* Fall through. */
1146+
/* FALLTHROUGH */
11471147

11481148
case PHJ_BATCH_LOADING:
11491149
/* Start (or join in) loading tuples. */
@@ -1163,7 +1163,7 @@ ExecParallelHashJoinNewBatch(HashJoinState *hjstate)
11631163
sts_end_parallel_scan(inner_tuples);
11641164
BarrierArriveAndWait(batch_barrier,
11651165
WAIT_EVENT_HASH_BATCH_LOADING);
1166-
/* Fall through. */
1166+
/* FALLTHROUGH */
11671167

11681168
case PHJ_BATCH_PROBING:
11691169

src/backend/executor/nodeLimit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ ExecLimit(PlanState *pstate)
6969
*/
7070
recompute_limits(node);
7171

72-
/* FALL THRU */
72+
/* FALLTHROUGH */
7373

7474
case LIMIT_RESCAN:
7575

@@ -216,7 +216,7 @@ ExecLimit(PlanState *pstate)
216216
}
217217

218218
Assert(node->lstate == LIMIT_WINDOWEND_TIES);
219-
/* FALL THRU */
219+
/* FALLTHROUGH */
220220

221221
case LIMIT_WINDOWEND_TIES:
222222
if (ScanDirectionIsForward(direction))

src/backend/libpq/auth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2123,7 +2123,7 @@ pam_passwd_conv_proc(int num_msg, const struct pam_message **msg,
21232123
ereport(LOG,
21242124
(errmsg("error from underlying PAM layer: %s",
21252125
msg[i]->msg)));
2126-
/* FALL THROUGH */
2126+
/* FALLTHROUGH */
21272127
case PAM_TEXT_INFO:
21282128
/* we don't bother to log TEXT_INFO messages */
21292129
if ((reply[i].resp = strdup("")) == NULL)

src/backend/optimizer/util/clauses.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,7 @@ find_nonnullable_rels_walker(Node *node, bool top_level)
15821582
* the intersection of the sets of nonnullable rels, just as
15831583
* for OR. Fall through to share code.
15841584
*/
1585-
/* FALL THRU */
1585+
/* FALLTHROUGH */
15861586
case OR_EXPR:
15871587

15881588
/*
@@ -1807,7 +1807,7 @@ find_nonnullable_vars_walker(Node *node, bool top_level)
18071807
* the intersection of the sets of nonnullable vars, just as
18081808
* for OR. Fall through to share code.
18091809
*/
1810-
/* FALL THRU */
1810+
/* FALLTHROUGH */
18111811
case OR_EXPR:
18121812

18131813
/*

src/backend/parser/parse_utilcmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
737737
errmsg("primary key constraints are not supported on foreign tables"),
738738
parser_errposition(cxt->pstate,
739739
constraint->location)));
740-
/* FALL THRU */
740+
/* FALLTHROUGH */
741741

742742
case CONSTR_UNIQUE:
743743
if (cxt->isforeign)

src/backend/partitioning/partprune.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2571,7 +2571,7 @@ get_matching_list_bounds(PartitionPruneContext *context,
25712571

25722572
case BTGreaterEqualStrategyNumber:
25732573
inclusive = true;
2574-
/* fall through */
2574+
/* FALLTHROUGH */
25752575
case BTGreaterStrategyNumber:
25762576
off = partition_list_bsearch(partsupfunc,
25772577
partcollation,
@@ -2606,7 +2606,7 @@ get_matching_list_bounds(PartitionPruneContext *context,
26062606

26072607
case BTLessEqualStrategyNumber:
26082608
inclusive = true;
2609-
/* fall through */
2609+
/* FALLTHROUGH */
26102610
case BTLessStrategyNumber:
26112611
off = partition_list_bsearch(partsupfunc,
26122612
partcollation,
@@ -2853,7 +2853,7 @@ get_matching_range_bounds(PartitionPruneContext *context,
28532853

28542854
case BTGreaterEqualStrategyNumber:
28552855
inclusive = true;
2856-
/* fall through */
2856+
/* FALLTHROUGH */
28572857
case BTGreaterStrategyNumber:
28582858

28592859
/*
@@ -2934,7 +2934,7 @@ get_matching_range_bounds(PartitionPruneContext *context,
29342934

29352935
case BTLessEqualStrategyNumber:
29362936
inclusive = true;
2937-
/* fall through */
2937+
/* FALLTHROUGH */
29382938
case BTLessStrategyNumber:
29392939

29402940
/*

src/backend/postmaster/postmaster.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5902,19 +5902,19 @@ bgworker_should_start_now(BgWorkerStartTime start_time)
59025902
case PM_RUN:
59035903
if (start_time == BgWorkerStart_RecoveryFinished)
59045904
return true;
5905-
/* fall through */
5905+
/* FALLTHROUGH */
59065906

59075907
case PM_HOT_STANDBY:
59085908
if (start_time == BgWorkerStart_ConsistentState)
59095909
return true;
5910-
/* fall through */
5910+
/* FALLTHROUGH */
59115911

59125912
case PM_RECOVERY:
59135913
case PM_STARTUP:
59145914
case PM_INIT:
59155915
if (start_time == BgWorkerStart_PostmasterStart)
59165916
return true;
5917-
/* fall through */
5917+
/* FALLTHROUGH */
59185918

59195919
}
59205920

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy