Index: llvm/include/llvm/ADT/SmallVector.h =================================================================== --- llvm/include/llvm/ADT/SmallVector.h +++ llvm/include/llvm/ADT/SmallVector.h @@ -49,7 +49,7 @@ void grow_pod(void *FirstEl, size_t MinCapacity, size_t TSize); public: - size_t size() const { return Size; } + LLVM_USED_FOR_DEBUG size_t size() const { return Size; } size_t capacity() const { return Capacity; } LLVM_NODISCARD bool empty() const { return !Size; } @@ -145,11 +145,11 @@ /// Return a pointer to the vector's buffer, even if empty(). const_pointer data() const { return const_pointer(begin()); } - reference operator[](size_type idx) { + LLVM_USED_FOR_DEBUG reference operator[](size_type idx) { assert(idx < size()); return begin()[idx]; } - const_reference operator[](size_type idx) const { + LLVM_USED_FOR_DEBUG const_reference operator[](size_type idx) const { assert(idx < size()); return begin()[idx]; } Index: llvm/include/llvm/Support/Compiler.h =================================================================== --- llvm/include/llvm/Support/Compiler.h +++ llvm/include/llvm/Support/Compiler.h @@ -503,6 +503,20 @@ #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE #endif +/// This macro will mark the function as used if the host compiler supports it +/// and the build has asserts enabled. Functions marked with this macro can be +/// called from the debugger during debugging. This macro should be used on +/// function that are useful for debugging and wouldn't be emitted unless they +/// are used, usually getter-like member function of template classes. Example: +/// SmallVectors's operator[] is usefull for debugging, doesn't change the state +/// of the SmallVector and will not be generated it is used because it is +/// templated. +#if !defined(NDEBUG) +#define LLVM_USED_FOR_DEBUG LLVM_ATTRIBUTE_USED +#else +#define LLVM_USED_FOR_DEBUG +#endif + /// \macro LLVM_PRETTY_FUNCTION /// Gets a user-friendly looking function signature for the current scope /// using the best available method on each platform. The exact format of the