[clang] a28e482 - Reserve unused bits in struct CXIndexOptions; NFC

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 10 06:26:52 PST 2023


Author: Igor Kushnir
Date: 2023-03-10T09:26:10-05:00
New Revision: a28e4821829e2d5c68fc652f1db5db6e02284c3d

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

LOG: Reserve unused bits in struct CXIndexOptions; NFC

Differential Revision: https://reviews.llvm.org/D145783

Added: 
    

Modified: 
    clang/include/clang-c/Index.h
    clang/tools/libclang/CIndex.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 7c662c002c26b..7cd35e9b2a7d4 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -372,6 +372,8 @@ typedef struct CXIndexOptions {
    * \see clang_createIndex()
    */
   unsigned DisplayDiagnostics : 1;
+  unsigned /*Reserved*/ : 14;
+
   /**
    * The path to a directory, in which to store temporary PCH files. If null or
    * empty, the default system temporary directory is used. These PCH files are

diff  --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 959646707d8f4..8a23679beeb6d 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -3724,6 +3724,13 @@ CXIndex clang_createIndexWithOptions(const CXIndexOptions *options) {
   // if (options->Size >= offsetof(CXIndexOptions, RecentlyAddedMember))
   //   do_something(options->RecentlyAddedMember);
 
+  // An exception: if a new option is small enough, it can be squeezed into the
+  // /*Reserved*/ bits in CXIndexOptions. Since the default value of each option
+  // is guaranteed to be 0 and the callers are advised to zero out the struct,
+  // programs built against older libclang versions would implicitly set the new
+  // options to default values, which should keep the behavior of previous
+  // libclang versions and thus be backward-compatible.
+
   // If options->Size > sizeof(CXIndexOptions), the user may have set an option
   // we can't handle, in which case we return nullptr to report failure.
   // Replace `!=` with `>` here to support older struct versions. `!=` has the


        


More information about the cfe-commits mailing list