llvm/clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp

//== BitwiseShiftChecker.cpp ------------------------------------*- C++ -*--==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines BitwiseShiftChecker, which is a path-sensitive checker
// that looks for undefined behavior when the operands of the bitwise shift
// operators '<<' and '>>' are invalid (negative or too large).
//
//===----------------------------------------------------------------------===//

#include "clang/AST/ASTContext.h"
#include "clang/AST/CharUnits.h"
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
#include "llvm/Support/FormatVariadic.h"
#include <memory>

usingnamespaceclang;
usingnamespaceento;
formatv;

namespace {
enum class OperandSide {};

BugReportPtr;

struct NoteTagTemplate {};

constexpr NoteTagTemplate NoteTagTemplates[] =;

/// An implementation detail class which is introduced to split the checker
/// logic into several methods while maintaining a consistently updated state
/// and access to other contextual data.
class BitwiseShiftValidator {};

void BitwiseShiftValidator::run() {}

/// This method checks a requirement that must be satisfied by the value on the
/// given Side of a bitwise shift operator in well-defined code. If the
/// requirement is incompatible with prior knowledge, this method reports
/// failure by returning false.
bool BitwiseShiftValidator::assumeRequirement(OperandSide Side,
                                              BinaryOperator::Opcode Comparison,
                                              unsigned Limit) {}

BugReportPtr BitwiseShiftValidator::checkOvershift() {}

// Before C++20, at 5.8 [expr.shift] (N4296, 2014-11-19) the standard says
// 1. "... The behaviour is undefined if the right operand is negative..."
// 2. "The value of E1 << E2 ...
//     if E1 has a signed type and non-negative value ...
//     otherwise, the behavior is undefined."
// 3. "The value of E1 >> E2 ...
//     If E1 has a signed type and a negative value,
//     the resulting value is implementation-defined."
// However, negative left arguments work in practice and the C++20 standard
// eliminates conditions 2 and 3.
BugReportPtr BitwiseShiftValidator::checkOperandNegative(OperandSide Side) {}

BugReportPtr BitwiseShiftValidator::checkLeftShiftOverflow() {}

void BitwiseShiftValidator::recordAssumption(OperandSide Side,
                                             BinaryOperator::Opcode Comparison,
                                             unsigned Limit) {}

const NoteTag *BitwiseShiftValidator::createNoteTag() const {}

std::unique_ptr<PathSensitiveBugReport>
BitwiseShiftValidator::createBugReport(StringRef ShortMsg, StringRef Msg) const {}
} // anonymous namespace

class BitwiseShiftChecker : public Checker<check::PreStmt<BinaryOperator>> {};

void ento::registerBitwiseShiftChecker(CheckerManager &Mgr) {}

bool ento::shouldRegisterBitwiseShiftChecker(const CheckerManager &mgr) {}