Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 30212b7

Browse files
johnstiles-googleSkia Commit-Bot
authored and
Skia Commit-Bot
committed
Fix implicit fallthroughs throughout Skia.
This CL is not fully comprehensive; for instance, it does not contain fixes for backends that don't compile on Mac. But it does resolve the vast majority of cases that trigger -Wimplicit-fallthrough. A few minor bugs were found and fixed, but none that were likely to affect normal operation. Change-Id: I43487602b0d56200ce8b42702e04f66390d82f60 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/295916 Reviewed-by: Mike Klein <[email protected]> Commit-Queue: John Stiles <[email protected]>
1 parent 77968f0 commit 30212b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+303
-204
lines changed

dm/DMSrcSink.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ Result CodecSrc::draw(SkCanvas* canvas) const {
512512
return Result::Skip(
513513
"Cannot decode frame %i to 565 (%s).", i, fPath.c_str());
514514
}
515-
// Fall through.
515+
[[fallthrough]];
516516
default:
517517
return Result::Fatal(
518518
"Couldn't getPixels for frame %i in %s.", i, fPath.c_str());

fuzz/FuzzMain.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ static void fuzz_img(sk_sp<SkData> bytes, uint8_t scale, uint8_t mode) {
464464
SkDebugf("Incompatible colortype conversion\n");
465465
// Crash to allow afl-fuzz to know this was a bug.
466466
raise(SIGSEGV);
467+
break;
467468
default:
468469
SkDebugf("[terminated] Couldn't getPixels.\n");
469470
return;
@@ -594,15 +595,15 @@ static void fuzz_img(sk_sp<SkData> bytes, uint8_t scale, uint8_t mode) {
594595
return;
595596
}
596597
// If the first subset succeeded, a later one should not fail.
597-
// fall through to failure
598+
[[fallthrough]];
598599
case SkCodec::kUnimplemented:
599600
if (0 == (x|y)) {
600601
// First subset is okay to return unimplemented.
601602
SkDebugf("[terminated] subset codec not supported\n");
602603
return;
603604
}
604605
// If the first subset succeeded, why would a later one fail?
605-
// fall through to failure
606+
[[fallthrough]];
606607
default:
607608
SkDebugf("[terminated] subset codec failed to decode (%d, %d, %d, %d) "
608609
"with dimensions (%d x %d)\t error %d\n",

gm/dstreadshuffle.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class DstReadShuffle : public GM {
100100
SkFont font(ToolUtils::create_portable_typeface(), 100);
101101
font.setEmbolden(true);
102102
canvas->drawString(text, 0.f, 100.f, font, *paint);
103+
break;
103104
}
104105
default:
105106
break;

gm/xfermodes.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class XfermodesGM : public skiagm::GM {
154154
canvas->saveLayer(&bounds, &p);
155155
restoreNeeded = true;
156156
p.setBlendMode(SkBlendMode::kSrcOver);
157-
// Fall through.
157+
[[fallthrough]];
158158
}
159159
case kQuarterClear_SrcType: {
160160
SkScalar halfW = SkIntToScalar(W) / 2;
@@ -175,7 +175,7 @@ class XfermodesGM : public skiagm::GM {
175175
SkScalar h = SkIntToScalar(H);
176176
SkRect r = SkRect::MakeXYWH(x, y + h / 4, w, h * 23 / 60);
177177
canvas->clipRect(r);
178-
// Fall through.
178+
[[fallthrough]];
179179
}
180180
case kRectangle_SrcType: {
181181
SkScalar w = SkIntToScalar(W);
@@ -188,10 +188,10 @@ class XfermodesGM : public skiagm::GM {
188188
}
189189
case kSmallRectangleImageWithAlpha_SrcType:
190190
m.postScale(SK_ScalarHalf, SK_ScalarHalf, x, y);
191-
// Fall through.
191+
[[fallthrough]];
192192
case kRectangleImageWithAlpha_SrcType:
193193
p.setAlpha(0x88);
194-
// Fall through.
194+
[[fallthrough]];
195195
case kRectangleImage_SrcType: {
196196
SkAutoCanvasRestore acr(canvas, true);
197197
canvas->concat(m);

modules/skparagraph/src/ParagraphImpl.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,8 +1055,12 @@ void ParagraphImpl::setState(InternalState state) {
10551055
fBidiRegions.reset();
10561056
fGraphemes16.reset();
10571057
fCodepoints.reset();
1058+
[[fallthrough]];
1059+
10581060
case kShaped:
10591061
fClusters.reset();
1062+
[[fallthrough]];
1063+
10601064
case kClusterized:
10611065
case kMarked:
10621066
case kLineBroken:
@@ -1065,12 +1069,15 @@ void ParagraphImpl::setState(InternalState state) {
10651069
this->computeEmptyMetrics();
10661070
this->resetShifts();
10671071
fLines.reset();
1072+
[[fallthrough]];
1073+
10681074
case kFormatted:
10691075
fPicture = nullptr;
1076+
[[fallthrough]];
1077+
10701078
case kDrawn:
1079+
default:
10711080
break;
1072-
default:
1073-
break;
10741081
}
10751082
}
10761083

samplecode/SampleAAGeometry.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ static void set_path_verb(int index, SkPath::Verb v, SkPath* path, SkScalar w) {
278278
switch (v) {
279279
case SkPath::kConic_Verb:
280280
weight = w;
281+
[[fallthrough]];
281282
case SkPath::kQuad_Verb:
282283
pts[2] = pts[1];
283284
pts[1].fX = (pts[0].fX + pts[2].fX) / 2;
@@ -303,6 +304,7 @@ static void set_path_verb(int index, SkPath::Verb v, SkPath* path, SkScalar w) {
303304
break;
304305
case SkPath::kConic_Verb:
305306
weight = w;
307+
[[fallthrough]];
306308
case SkPath::kQuad_Verb:
307309
break;
308310
case SkPath::kCubic_Verb: {
@@ -325,6 +327,7 @@ static void set_path_verb(int index, SkPath::Verb v, SkPath* path, SkScalar w) {
325327
break;
326328
case SkPath::kConic_Verb:
327329
weight = w;
330+
[[fallthrough]];
328331
case SkPath::kQuad_Verb: {
329332
SkDCubic dCubic;
330333
dCubic.set(pts);

samplecode/SampleAnimatedImage.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,10 @@ class SampleAnimatedImage : public Sample {
104104
switch (uni) {
105105
case kPauseKey:
106106
fRunning = !fRunning;
107-
if (fImage->isFinished()) {
108-
// fall through
109-
} else {
107+
if (!fImage->isFinished()) {
110108
return true;
111109
}
110+
[[fallthrough]];
112111
case kResetKey:
113112
fImage->reset();
114113
fCurrentTime = fLastWallTime;

src/codec/SkBmpCodec.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ SkCodec::Result SkBmpCodec::ReadHeader(SkStream* stream, bool inIco,
394394
inputFormat = kRLE_BmpInputFormat;
395395
break;
396396
}
397-
// Fall through
397+
[[fallthrough]];
398398
case kPng_BmpCompressionMethod:
399399
// TODO: Decide if we intend to support this.
400400
// It is unsupported in the previous version and

src/codec/SkPngCodec.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,8 +1018,7 @@ SkCodec::Result SkPngCodec::initializeXforms(const SkImageInfo& dstInfo, const O
10181018
if (this->getEncodedInfo().bitsPerComponent() != 16) {
10191019
break;
10201020
}
1021-
1022-
// Fall through
1021+
[[fallthrough]];
10231022
case SkEncodedInfo::kRGBA_Color:
10241023
case SkEncodedInfo::kGray_Color:
10251024
skipFormatConversion = this->colorXform();

src/codec/SkWebpCodec.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ std::unique_ptr<SkCodec> SkWebpCodec::MakeFromStream(std::unique_ptr<SkStream> s
143143
// sense to guess kBGRA which is likely closer to the final
144144
// output. Otherwise, we might end up converting
145145
// BGRA->YUVA->BGRA.
146-
// Fallthrough:
146+
[[fallthrough]];
147147
case 2:
148148
// This is the lossless format (BGRA).
149149
if (hasAlpha) {

src/core/SkBitmapProcState_matrixProcs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static void decal_nofilter_scale(uint32_t dst[], SkFixed fx, SkFixed dx, int cou
6464

6565
SkASSERT(count <= 2);
6666
switch (count) {
67-
case 2: ((uint16_t*)dst)[1] = SkToU16((fx + dx) >> 16);
67+
case 2: ((uint16_t*)dst)[1] = SkToU16((fx + dx) >> 16); [[fallthrough]];
6868
case 1: ((uint16_t*)dst)[0] = SkToU16((fx + 0) >> 16);
6969
}
7070
}
@@ -475,7 +475,7 @@ SkBitmapProcState::MatrixProc SkBitmapProcState::chooseMatrixProc(bool translate
475475
// Check for our special case translate methods when there is no scale/affine/perspective.
476476
if (translate_only_matrix && kNone_SkFilterQuality == fFilterQuality) {
477477
switch (fTileModeX) {
478-
default: SkASSERT(false);
478+
default: SkASSERT(false); [[fallthrough]];
479479
case SkTileMode::kClamp: return clampx_nofilter_trans<int_clamp>;
480480
case SkTileMode::kRepeat: return repeatx_nofilter_trans<int_repeat>;
481481
case SkTileMode::kMirror: return mirrorx_nofilter_trans<int_mirror>;

src/core/SkBlurMF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ SkBlurMaskFilterImpl::filterRRectToNine(const SkRRect& rrect, const SkMatrix& ma
436436
case SkRRect::kRect_Type:
437437
// We should have caught this earlier.
438438
SkASSERT(false);
439-
// Fall through.
439+
[[fallthrough]];
440440
case SkRRect::kOval_Type:
441441
// The nine patch special case does not handle ovals, and we
442442
// already have code for rectangles.

src/core/SkClipStack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ void SkClipStack::Element::combineBoundsXOR(int combination, const SkRect& prevF
392392
// The only pixels that can survive are within the
393393
// union of the two bounding boxes since the extensions
394394
// to infinity of both clips cancel out
395-
// fall through!
395+
[[fallthrough]];
396396
case kPrev_Cur_FillCombo:
397397
// The most conservative bound for xor is the
398398
// union of the two bounds. If the two clips exactly overlapped
@@ -830,7 +830,7 @@ void SkClipStack::pushElement(const Element& element) {
830830
}
831831
break;
832832
}
833-
// fallthrough
833+
[[fallthrough]];
834834
default:
835835
if (!SkRect::Intersects(prior->getBounds(), element.getBounds())) {
836836
prior->setEmpty();

src/core/SkDraw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ void SkDraw::drawPoints(SkCanvas::PointMode mode, size_t count,
511511
break;
512512
}
513513
}
514-
// couldn't take fast path so fall through!
514+
[[fallthrough]]; // couldn't take fast path
515515
case SkCanvas::kPolygon_PointMode: {
516516
count -= 1;
517517
SkPath path;

src/core/SkImageInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
9090
if (kUnpremul_SkAlphaType == alphaType) {
9191
alphaType = kPremul_SkAlphaType;
9292
}
93-
// fall-through
93+
[[fallthrough]];
9494
case kARGB_4444_SkColorType:
9595
case kRGBA_8888_SkColorType:
9696
case kBGRA_8888_SkColorType:

src/core/SkMaskFilter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ bool SkMaskFilterBase::filterPath(const SkPath& devPath, const SkMatrix& matrix,
255255

256256
case kUnimplemented_FilterReturn:
257257
SkASSERT(nullptr == patch.fMask.fImage);
258-
// fall through
258+
// fall out
259259
break;
260260
}
261261
}

src/core/SkModeColorFilter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ uint32_t SkModeColorFilter::getFlags() const {
4444
case SkBlendMode::kDst: //!< [Da, Dc]
4545
case SkBlendMode::kSrcATop: //!< [Da, Sc * Da + (1 - Sa) * Dc]
4646
flags |= kAlphaUnchanged_Flag;
47+
break;
4748
default:
4849
break;
4950
}

src/core/SkPath.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ SkPath::Verb SkPath::Iter::next(SkPoint ptsParam[4]) {
18151815
break;
18161816
case kConic_Verb:
18171817
fConicWeights += 1;
1818-
// fall-through
1818+
[[fallthrough]];
18191819
case kQuad_Verb:
18201820
pts[0] = this->cons_moveTo();
18211821
memcpy(&pts[1], srcPts, 2 * sizeof(SkPoint));
@@ -2351,7 +2351,7 @@ void ContourIter::next() {
23512351
break;
23522352
case SkPath::kConic_Verb:
23532353
fCurrConicWeight += 1;
2354-
// fall-through
2354+
[[fallthrough]];
23552355
case SkPath::kQuad_Verb:
23562356
ptCount += 2;
23572357
break;
@@ -3348,6 +3348,7 @@ bool SkPathPriv::IsRectContour(const SkPath& path, bool allowPartial, int* currV
33483348
savePts = pts;
33493349
autoClose = true;
33503350
insertClose = false;
3351+
[[fallthrough]];
33513352
case SkPath::kLine_Verb: {
33523353
if (SkPath::kClose_Verb != verb) {
33533354
lastPt = pts;

src/core/SkPathRef.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,12 @@ SkPoint* SkPathRef::growForRepeatedVerb(int /*SkPath::Verb*/ verb,
394394
break;
395395
case SkPath::kDone_Verb:
396396
SkDEBUGFAIL("growForRepeatedVerb called for kDone");
397-
// fall through
397+
pCnt = 0;
398+
break;
398399
default:
399400
SkDEBUGFAIL("default should not be reached");
400401
pCnt = 0;
402+
break;
401403
}
402404

403405
fBoundsIsDirty = true; // this also invalidates fIsFinite
@@ -444,10 +446,12 @@ SkPoint* SkPathRef::growForVerb(int /* SkPath::Verb*/ verb, SkScalar weight) {
444446
break;
445447
case SkPath::kDone_Verb:
446448
SkDEBUGFAIL("growForVerb called for kDone");
447-
// fall through
449+
pCnt = 0;
450+
break;
448451
default:
449452
SkDEBUGFAIL("default is not reached");
450453
pCnt = 0;
454+
break;
451455
}
452456

453457
fSegmentMask |= mask;
@@ -596,7 +600,7 @@ uint8_t SkPathRef::Iter::next(SkPoint pts[4]) {
596600
break;
597601
case SkPath::kConic_Verb:
598602
fConicWeights += 1;
599-
// fall-through
603+
[[fallthrough]];
600604
case SkPath::kQuad_Verb:
601605
pts[0] = srcPts[-1];
602606
pts[1] = srcPts[0];

src/core/SkPath_serial.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ size_t SkPath::readFromMemory_EQ4Or5(const void* storage, size_t length) {
211211
case SerializationType::kRRect:
212212
return this->readAsRRect(storage, length);
213213
case SerializationType::kGeneral:
214-
break; // fall through
214+
break; // fall out
215215
default:
216216
return 0;
217217
}

src/core/SkPicture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, const SkDeserialPro
185185
}
186186
return procs.fPictureProc(data->data(), size, procs.fPictureCtx);
187187
}
188-
default: // fall through to error return
188+
default: // fall out to error return
189189
break;
190190
}
191191
return nullptr;

src/core/SkVM.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,32 +1234,35 @@ namespace skvm {
12341234
};
12351235

12361236
switch (mode) {
1237-
default: SkASSERT(false); /*but also, for safety, fallthrough*/
1237+
default:
1238+
SkASSERT(false);
1239+
[[fallthrough]]; /*but also, for safety, fallthrough*/
12381240

12391241
case SkBlendMode::kClear: return { splat(0.0f), splat(0.0f), splat(0.0f), splat(0.0f) };
12401242

12411243
case SkBlendMode::kSrc: return src;
12421244
case SkBlendMode::kDst: return dst;
12431245

1244-
case SkBlendMode::kDstOver: std::swap(src, dst); // fall-through
1246+
case SkBlendMode::kDstOver: std::swap(src, dst); [[fallthrough]];
12451247
case SkBlendMode::kSrcOver:
12461248
return apply_rgba([&](auto s, auto d) {
12471249
return mad(d,1-src.a, s);
12481250
});
12491251

1250-
case SkBlendMode::kDstIn: std::swap(src, dst); // fall-through
1252+
case SkBlendMode::kDstIn: std::swap(src, dst); [[fallthrough]];
12511253
case SkBlendMode::kSrcIn:
12521254
return apply_rgba([&](auto s, auto d) {
12531255
return s * dst.a;
12541256
});
12551257

1256-
case SkBlendMode::kDstOut: std::swap(src, dst); // fall-through
1258+
case SkBlendMode::kDstOut: std::swap(src, dst); [[fallthrough]];
1259+
12571260
case SkBlendMode::kSrcOut:
12581261
return apply_rgba([&](auto s, auto d) {
12591262
return s * (1-dst.a);
12601263
});
12611264

1262-
case SkBlendMode::kDstATop: std::swap(src, dst); // fall-through
1265+
case SkBlendMode::kDstATop: std::swap(src, dst); [[fallthrough]];
12631266
case SkBlendMode::kSrcATop:
12641267
return apply_rgba([&](auto s, auto d) {
12651268
return mma(s, dst.a, d, 1-src.a);

src/effects/Sk1DPathEffect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static void morphpath(SkPath* dst, const SkPath& src, SkPathMeasure& meas,
127127
srcP[2] = srcP[1];
128128
srcP[1].set(SkScalarAve(srcP[0].fX, srcP[2].fX),
129129
SkScalarAve(srcP[0].fY, srcP[2].fY));
130-
// fall through to quad
130+
[[fallthrough]];
131131
case SkPath::kQuad_Verb:
132132
if (morphpoints(dstP, &srcP[1], 2, meas, dist)) {
133133
dst->quadTo(dstP[0], dstP[1]);

src/gpu/GrCaps.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,11 @@ GrCaps::SupportedRead GrCaps::supportedReadPixelsColorType(GrColorType srcColorT
358358
// offset alignment is a multiple of 2 but not 4.
359359
case 2:
360360
read.fOffsetAlignmentForTransferBuffer *= 2;
361+
break;
361362
// offset alignment is not a multiple of 2.
362363
default:
363364
read.fOffsetAlignmentForTransferBuffer *= 4;
365+
break;
364366
}
365367
}
366368
return read;

0 commit comments

Comments
 (0)