diff options
Diffstat (limited to 'source/opt/scalar_replacement_pass.h')
-rw-r--r-- | source/opt/scalar_replacement_pass.h | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/source/opt/scalar_replacement_pass.h b/source/opt/scalar_replacement_pass.h index 0928830c..6a66dfb8 100644 --- a/source/opt/scalar_replacement_pass.h +++ b/source/opt/scalar_replacement_pass.h @@ -15,6 +15,7 @@ #ifndef SOURCE_OPT_SCALAR_REPLACEMENT_PASS_H_ #define SOURCE_OPT_SCALAR_REPLACEMENT_PASS_H_ +#include <cassert> #include <cstdio> #include <memory> #include <queue> @@ -23,23 +24,34 @@ #include <vector> #include "source/opt/function.h" -#include "source/opt/pass.h" +#include "source/opt/mem_pass.h" #include "source/opt/type_manager.h" namespace spvtools { namespace opt { // Documented in optimizer.hpp -class ScalarReplacementPass : public Pass { +class ScalarReplacementPass : public MemPass { private: static const uint32_t kDefaultLimit = 100; public: ScalarReplacementPass(uint32_t limit = kDefaultLimit) : max_num_elements_(limit) { - name_[0] = '\0'; - strcat(name_, "scalar-replacement="); - sprintf(&name_[strlen(name_)], "%d", max_num_elements_); + const auto num_to_write = snprintf( + name_, sizeof(name_), "scalar-replacement=%u", max_num_elements_); + assert(size_t(num_to_write) < sizeof(name_)); + (void)num_to_write; // Mark as unused + +#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION + // ClusterFuzz/OSS-Fuzz is likely to yield examples with very large arrays. + // This can cause timeouts and memouts during fuzzing that + // are not classed as bugs. To avoid this noise, we set the + // max_num_elements_ to a smaller value for fuzzing. + max_num_elements_ = + (max_num_elements_ > 0 && max_num_elements_ < 100 ? max_num_elements_ + : 100); +#endif } const char* name() const override { return name_; } @@ -234,10 +246,8 @@ class ScalarReplacementPass : public Pass { std::unique_ptr<std::unordered_set<int64_t>> GetUsedComponents( Instruction* inst); - // Returns an instruction defining a null constant with type |type_id|. If - // one already exists, it is returned. Otherwise a new one is created. - // Returns |nullptr| if the new constant could not be created. - Instruction* CreateNullConstant(uint32_t type_id); + // Returns an instruction defining an undefined value type |type_id|. + Instruction* GetUndef(uint32_t type_id); // Maps storage type to a pointer type enclosing that type. std::unordered_map<uint32_t, uint32_t> pointee_to_pointer_; @@ -255,7 +265,10 @@ class ScalarReplacementPass : public Pass { // Limit on the number of members in an object that will be replaced. // 0 means there is no limit. uint32_t max_num_elements_; - char name_[55]; + // This has to be big enough to fit "scalar-replacement=" followed by a + // uint32_t number written in decimal (so 10 digits), and then a + // terminating nul. + char name_[30]; }; } // namespace opt |