Bug Summary

File:root/firefox-clang/obj-x86_64-pc-linux-gnu/third_party/angle/translator_gn/./../../../../third_party/angle/src/compiler/translator/tree_util/RunAtTheEndOfShader.cpp
Warning:line 116, column 9
Value stored to 'replaced' 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_angle_translator_gn6.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/third_party/angle/translator_gn -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/third_party/angle/translator_gn -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 ANGLE_DISABLE_POOL_ALLOC -D ANGLE_ENABLE_CONTEXT_MUTEX=1 -U ANGLE_ENABLE_DEBUG_ANNOTATIONS -D ANGLE_ENABLE_ESSL -D ANGLE_ENABLE_GLSL -D ANGLE_ENABLE_KEYEDMUTEX -D ANGLE_ENABLE_SHARE_CONTEXT_LOCK=1 -D ANGLE_PLATFORM_EXPORT= -D ANGLE_SKIP_DXGI_1_2_CHECK -D ANGLE_DEBUG_LAYERS_ENABLED -D DYNAMIC_ANNOTATIONS_ENABLED=1 -D ANGLE_IS_LINUX -D ANGLE_USE_VULKAN_DISPLAY -D ANGLE_VULKAN_DISPLAY_MODE_HEADLESS -D USE_AURA=1 -D USE_GLIB=1 -D USE_OZONE=1 -D USE_UDEV -D _FILE_OFFSET_BITS=64 -D _LARGEFILE64_SOURCE -D _LARGEFILE_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D _DEBUG -D ANGLE_USE_X11 -D _GNU_SOURCE -I /root/firefox-clang/third_party/angle/translator_gn -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/third_party/angle/translator_gn -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /root/firefox-clang/ipc/chromium/src -I /root/firefox-clang/third_party/angle/include -I /root/firefox-clang/third_party/angle/src -I /root/firefox-clang/third_party/angle/src/common/base -I /root/firefox-clang/third_party/angle/src/common/third_party/xxhash -I /root/firefox-clang/tools/profiler/public -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -D MOZILLA_CLIENT -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 -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_angle_translator_gn6.cpp
1//
2// Copyright 2017 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6// RunAtTheEndOfShader.cpp: Add code to be run at the end of the shader. In case main() contains a
7// return statement, this is done by replacing the main() function with another function that calls
8// the old main, like this:
9//
10// void main() { body }
11// =>
12// void main0() { body }
13// void main()
14// {
15// main0();
16// codeToRun
17// }
18//
19// This way the code will get run even if the return statement inside main is executed.
20//
21// This is done if main ends in an unconditional |discard| as well, to help with SPIR-V generation
22// that expects no dead-code to be present after branches in a block. To avoid bugs when |discard|
23// is wrapped in unconditional blocks, any |discard| in main() is used as a signal to wrap it.
24//
25
26#include "compiler/translator/tree_util/RunAtTheEndOfShader.h"
27
28#include "compiler/translator/Compiler.h"
29#include "compiler/translator/IntermNode.h"
30#include "compiler/translator/StaticType.h"
31#include "compiler/translator/SymbolTable.h"
32#include "compiler/translator/tree_util/FindMain.h"
33#include "compiler/translator/tree_util/IntermNode_util.h"
34#include "compiler/translator/tree_util/IntermTraverse.h"
35
36namespace sh
37{
38
39namespace
40{
41
42constexpr const ImmutableString kMainString("main");
43
44class ContainsReturnOrDiscardTraverser : public TIntermTraverser
45{
46 public:
47 ContainsReturnOrDiscardTraverser()
48 : TIntermTraverser(true, false, false), mContainsReturnOrDiscard(false)
49 {}
50
51 bool visitBranch(Visit visit, TIntermBranch *node) override
52 {
53 if (node->getFlowOp() == EOpReturn || node->getFlowOp() == EOpKill)
54 {
55 mContainsReturnOrDiscard = true;
56 }
57 return false;
58 }
59
60 bool containsReturnOrDiscard() { return mContainsReturnOrDiscard; }
61
62 private:
63 bool mContainsReturnOrDiscard;
64};
65
66bool ContainsReturnOrDiscard(TIntermNode *node)
67{
68 ContainsReturnOrDiscardTraverser traverser;
69 node->traverse(&traverser);
70 return traverser.containsReturnOrDiscard();
71}
72
73void WrapMainAndAppend(TIntermBlock *root,
74 TIntermFunctionDefinition *main,
75 TIntermNode *codeToRun,
76 TSymbolTable *symbolTable)
77{
78 // Replace main() with main0() with the same body.
79 TFunction *oldMain =
80 new TFunction(symbolTable, kEmptyImmutableString, SymbolType::AngleInternal,
81 StaticType::GetBasic<EbtVoid, EbpUndefined>(), false);
82 TIntermFunctionDefinition *oldMainDefinition =
83 CreateInternalFunctionDefinitionNode(*oldMain, main->getBody());
84
85 bool replaced = root->replaceChildNode(main, oldMainDefinition);
86 ASSERT(replaced)(replaced ? static_cast<void>(0) : (!((::gl::priv::ShouldCreatePlatformLogMessage
(::gl::LOG_FATAL))) ? static_cast<void>(0) : ::gl::priv
::LogMessageVoidify() & (::gl::LogMessage("./../../../../third_party/angle/src/compiler/translator/tree_util/RunAtTheEndOfShader.cpp"
, __FUNCTION__, 86, ::gl::LOG_FATAL).stream()) << "\t! Assert failed in "
<< __FUNCTION__ << " (" << "./../../../../third_party/angle/src/compiler/translator/tree_util/RunAtTheEndOfShader.cpp"
<< ":" << 86 << "): " << "replaced")
)
;
87
88 // void main()
89 TFunction *newMain = new TFunction(symbolTable, kMainString, SymbolType::UserDefined,
90 StaticType::GetBasic<EbtVoid, EbpUndefined>(), false);
91 TIntermFunctionPrototype *newMainProto = new TIntermFunctionPrototype(newMain);
92
93 // {
94 // main0();
95 // codeToRun
96 // }
97 TIntermBlock *newMainBody = new TIntermBlock();
98 TIntermSequence emptySequence;
99 TIntermAggregate *oldMainCall = TIntermAggregate::CreateFunctionCall(*oldMain, &emptySequence);
100 newMainBody->appendStatement(oldMainCall);
101 newMainBody->appendStatement(codeToRun);
102
103 // Add the new main() to the root node.
104 TIntermFunctionDefinition *newMainDefinition =
105 new TIntermFunctionDefinition(newMainProto, newMainBody);
106 root->appendStatement(newMainDefinition);
107
108 // If a function prototype of main() also exists, it will need to be replaced. Otherwise it will
109 // continue to internally reference the TFunction of the replaced 'main' function definition.
110 TIntermFunctionPrototype *oldMainProto = FindMainPrototype(root);
111 if (oldMainProto)
112 {
113 // Replace the prototype node but initialize it with the newMain TFunction; now this newly
114 // created main() prototype will reference the new TFunction of newMain.
115 newMainProto = new TIntermFunctionPrototype(newMain);
116 replaced = root->replaceChildNode(oldMainProto, newMainProto);
Value stored to 'replaced' is never read
117 }
118}
119
120} // anonymous namespace
121
122bool RunAtTheEndOfShader(TCompiler *compiler,
123 TIntermBlock *root,
124 TIntermNode *codeToRun,
125 TSymbolTable *symbolTable)
126{
127 TIntermFunctionDefinition *main = FindMain(root);
128 if (ContainsReturnOrDiscard(main))
129 {
130 WrapMainAndAppend(root, main, codeToRun, symbolTable);
131 }
132 else
133 {
134 main->getBody()->appendStatement(codeToRun);
135 }
136
137 return compiler->validateAST(root);
138}
139
140} // namespace sh