From b9df48ead8a6a46ab45b0a3a718d37d2c4d19586 Mon Sep 17 00:00:00 2001 From: Nicolai Haehnle Date: Wed, 31 Oct 2018 17:46:21 +0000 Subject: [PATCH] TableGen: Fix ASAN error Summary: As a bonus, this arguably improves the code by making it simpler. gcc 8 on Ubuntu 18.10 reports the following: ==39667==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7fffffff8ae0 at pc 0x555555dbfc68 bp 0x7fffffff8760 sp 0x7fffffff8750 WRITE of size 8 at 0x7fffffff8ae0 thread T0 #0 0x555555dbfc67 in std::__cxx11::basic_string, std::allocator >::_Alloc_hider::_Alloc_hider(char*, std::allocator&&) /usr/include/c++/8/bits/basic_string.h:149 #1 0x555555dbfc67 in std::__cxx11::basic_string, std::allocator >::basic_string(std::__cxx11::basic_string, std::allocator >&&) /usr/include/c++/8/bits/basic_string.h:542 #2 0x555555dbfc67 in std::__cxx11::basic_string, std::allocator > std::operator+, std::allocator >(char const*, std::__cxx11::basic_string, std::allocator >&&) /usr/include/c++/8/bits/basic_string.h:6009 #3 0x555555dbfc67 in searchableFieldType /home/nha/amd/build/san/llvm-src/utils/TableGen/SearchableTableEmitter.cpp:168 (...) Address 0x7fffffff8ae0 is located in stack of thread T0 at offset 864 in frame #0 0x555555dbef3f in searchableFieldType /home/nha/amd/build/san/llvm-src/utils/TableGen/SearchableTableEmitter.cpp:148 Reviewers: fhahn, simon_tatham, kparzysz Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D53931 --- .../utils/TableGen/SearchableTableEmitter.cpp | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/llvm/utils/TableGen/SearchableTableEmitter.cpp b/llvm/utils/TableGen/SearchableTableEmitter.cpp index 61c918bd014c..f98a7c74bf0c 100644 --- a/llvm/utils/TableGen/SearchableTableEmitter.cpp +++ b/llvm/utils/TableGen/SearchableTableEmitter.cpp @@ -155,17 +155,15 @@ class SearchableTableEmitter { } else if (BitsRecTy *BI = dyn_cast(Field.RecType)) { unsigned NumBits = BI->getNumBits(); if (NumBits <= 8) - NumBits = 8; - else if (NumBits <= 16) - NumBits = 16; - else if (NumBits <= 32) - NumBits = 32; - else if (NumBits <= 64) - NumBits = 64; - else - PrintFatalError(Twine("bitfield '") + Field.Name + - "' too large to search"); - return "uint" + utostr(NumBits) + "_t"; + return "uint8_t"; + if (NumBits <= 16) + return "uint16_t"; + if (NumBits <= 32) + return "uint32_t"; + if (NumBits <= 64) + return "uint64_t"; + PrintFatalError(Twine("bitfield '") + Field.Name + + "' too large to search"); } else if (Field.Enum || Field.IsIntrinsic || Field.IsInstruction) return "unsigned"; PrintFatalError(Twine("Field '") + Field.Name + "' has unknown type '" +