[clang] e678656 - Add bounds checking assertions to APValue, NFC

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 19 11:15:14 PST 2021


Author: Reid Kleckner
Date: 2021-01-19T11:15:02-08:00
New Revision: e678656625a3e2b6a5f2849f4a6f7612ceeaed07

URL: https://github.com/llvm/llvm-project/commit/e678656625a3e2b6a5f2849f4a6f7612ceeaed07
DIFF: https://github.com/llvm/llvm-project/commit/e678656625a3e2b6a5f2849f4a6f7612ceeaed07.diff

LOG: Add bounds checking assertions to APValue, NFC

These checks help find llvm.org/pr48582 without ASan

Added: 
    

Modified: 
    clang/include/clang/AST/APValue.h

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/AST/APValue.h b/clang/include/clang/AST/APValue.h
index f9b189926c76..5f4ac02f53c9 100644
--- a/clang/include/clang/AST/APValue.h
+++ b/clang/include/clang/AST/APValue.h
@@ -537,10 +537,12 @@ class APValue {
   }
   APValue &getStructBase(unsigned i) {
     assert(isStruct() && "Invalid accessor");
+    assert(i < getStructNumBases() && "base class index OOB");
     return ((StructData *)(char *)&Data)->Elts[i];
   }
   APValue &getStructField(unsigned i) {
     assert(isStruct() && "Invalid accessor");
+    assert(i < getStructNumFields() && "field index OOB");
     return ((StructData *)(char *)&Data)->Elts[getStructNumBases() + i];
   }
   const APValue &getStructBase(unsigned i) const {


        


More information about the cfe-commits mailing list