Bug Summary

File:root/firefox-clang/obj-x86_64-pc-linux-gnu/gfx/skia/./../../../gfx/skia/skia/src/core/SkMipmapAccessor.cpp
Warning:line 103, column 21
Value stored to 'resolvedMode' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_cpp_gfx_skia7.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/gfx/skia -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/gfx/skia -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -D _GLIBCXX_ASSERTIONS=1 -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D MOZ_SKIA -D SKIA_IMPLEMENTATION=1 -D SK_PDF_USE_HARFBUZZ_SUBSET=1 -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /root/firefox-clang/gfx/skia -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/gfx/skia -I /root/firefox-clang/gfx/skia/skia -I /root/firefox-clang/gfx/harfbuzz/src -I /root/firefox-clang/gfx/cairo/cairo/src -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/pango-1.0 -I /usr/include/harfbuzz -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/pixman-1 -I /usr/include/sysprof-6 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/x86_64-linux-gnu/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16/backward -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=pessimizing-move -Wno-error=large-by-value-copy=128 -Wno-error=implicit-int-float-conversion -Wno-error=thread-safety-analysis -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -Wno-character-conversion -Wno-deprecated-declarations -Wno-overloaded-virtual -Wno-sign-compare -Wno-unreachable-code -Wno-unused-function -Wno-implicit-fallthrough -Wno-inconsistent-missing-override -Wno-macro-redefined -Wno-unused-private-field -std=gnu++20 -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c++ Unified_cpp_gfx_skia7.cpp
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "src/core/SkMipmapAccessor.h"
9
10#include "include/core/SkBitmap.h"
11#include "include/core/SkMatrix.h"
12#include "include/core/SkSamplingOptions.h"
13#include "include/core/SkScalar.h"
14#include "include/core/SkSize.h"
15#include "include/private/base/SkFloatingPoint.h"
16#include "src/base/SkArenaAlloc.h"
17#include "src/core/SkBitmapCache.h"
18#include "src/core/SkMipmap.h"
19#include "src/image/SkImage_Base.h"
20
21class SkImage;
22
23// Try to load from the base image, or from the cache
24static sk_sp<const SkMipmap> try_load_mips(const SkImage_Base* image) {
25 sk_sp<const SkMipmap> mips = image->refMips();
26 if (!mips) {
27 mips.reset(SkMipmapCache::FindAndRef(SkBitmapCacheDesc::Make(image)));
28 }
29 if (!mips) {
30 mips.reset(SkMipmapCache::AddAndRef(image));
31 }
32 return mips;
33}
34
35SkMipmapAccessor::SkMipmapAccessor(const SkImage_Base* image, const SkMatrix& inv,
36 SkMipmapMode requestedMode) {
37 SkMipmapMode resolvedMode = requestedMode;
38 fLowerWeight = 0;
39
40 auto load_upper_from_base = [&]() {
41 // only do this once
42 if (fBaseStorage.getPixels() == nullptr) {
43 auto dContext = as_IB(image)->directContext();
44 (void)image->getROPixels(dContext, &fBaseStorage);
45 fUpper.reset(fBaseStorage.info(), fBaseStorage.getPixels(), fBaseStorage.rowBytes());
46 }
47 };
48
49 float level = 0;
50 if (requestedMode != SkMipmapMode::kNone) {
51 SkSize scale;
52 if (!inv.decomposeScale(&scale, nullptr)) {
53 resolvedMode = SkMipmapMode::kNone;
54 } else {
55 level = SkMipmap::ComputeLevel({1/scale.width(), 1/scale.height()});
56 if (level <= 0) {
57 resolvedMode = SkMipmapMode::kNone;
58 level = 0;
59 }
60 }
61 }
62
63 auto scale = [image](const SkPixmap& pm) {
64 return SkMatrix::Scale(SkIntToScalar(pm.width())static_cast<SkScalar>(pm.width()) / image->width(),
65 SkIntToScalar(pm.height())static_cast<SkScalar>(pm.height()) / image->height());
66 };
67
68 // Nearest mode uses this level, so we round to pick the nearest. In linear mode we use this
69 // level as the lower of the two to interpolate between, so we take the floor.
70 int levelNum = resolvedMode == SkMipmapMode::kNearest ? sk_float_round2int(level)sk_float_saturate2int((float)(std::floor(((double)(level)) + 0.5
)))
71 : sk_float_floor2int(level)sk_float_saturate2int(std::floor(level));
72 float lowerWeight = level - levelNum; // fract(level)
73 SkASSERT(levelNum >= 0)static_cast<void>( __builtin_expect(static_cast<bool
>(levelNum >= 0), 1) ? static_cast<void>(0) : []{
do { if (sk_abort_is_enabled()) { do { SkDebugf("%s:%d" ": fatal error: \""
"check(%s)" "\"\n", "./../../../gfx/skia/skia/src/core/SkMipmapAccessor.cpp"
, 73, "levelNum >= 0"); ; sk_abort_no_print(); } while (false
); } } while(false); }() )
;
74
75 if (levelNum == 0) {
76 load_upper_from_base();
77 }
78 // load fCurrMip if needed
79 if (levelNum > 0 || (resolvedMode == SkMipmapMode::kLinear && lowerWeight > 0)) {
80 fCurrMip = try_load_mips(image);
81 if (!fCurrMip) {
82 load_upper_from_base();
83 resolvedMode = SkMipmapMode::kNone;
84 } else {
85 SkMipmap::Level levelRec;
86
87 SkASSERT(resolvedMode != SkMipmapMode::kNone)static_cast<void>( __builtin_expect(static_cast<bool
>(resolvedMode != SkMipmapMode::kNone), 1) ? static_cast<
void>(0) : []{ do { if (sk_abort_is_enabled()) { do { SkDebugf
("%s:%d" ": fatal error: \"" "check(%s)" "\"\n", "./../../../gfx/skia/skia/src/core/SkMipmapAccessor.cpp"
, 87, "resolvedMode != SkMipmapMode::kNone"); ; sk_abort_no_print
(); } while (false); } } while(false); }() )
;
88 if (levelNum > 0) {
89 if (fCurrMip->getLevel(levelNum - 1, &levelRec)) {
90 fUpper = levelRec.fPixmap;
91 } else {
92 load_upper_from_base();
93 resolvedMode = SkMipmapMode::kNone;
94 }
95 }
96
97 if (resolvedMode == SkMipmapMode::kLinear) {
98 if (fCurrMip->getLevel(levelNum, &levelRec)) {
99 fLower = levelRec.fPixmap;
100 fLowerWeight = lowerWeight;
101 fLowerInv = scale(fLower);
102 } else {
103 resolvedMode = SkMipmapMode::kNearest;
Value stored to 'resolvedMode' is never read
104 }
105 }
106 }
107 }
108 fUpperInv = scale(fUpper);
109}
110
111SkMipmapAccessor* SkMipmapAccessor::Make(SkArenaAlloc* alloc, const SkImage* image,
112 const SkMatrix& inv, SkMipmapMode mipmap) {
113 auto* access = alloc->make<SkMipmapAccessor>(as_IB(image), inv, mipmap);
114 // return null if we failed to get the level (so the caller won't try to use it)
115 return access->fUpper.addr() ? access : nullptr;
116}