[clang-tools-extra] [clang-reorder-fields] Prevent rewriting unsupported cases (PR #142149)
Alexander Shaposhnikov via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 17 13:39:29 PDT 2025
================
@@ -50,6 +51,63 @@ static const RecordDecl *findDefinition(StringRef RecordName,
return selectFirst<RecordDecl>("recordDecl", Results);
}
+static bool isSafeToRewrite(const RecordDecl *Decl, const ASTContext &Context) {
+ // All following checks expect at least one field declaration.
+ if (Decl->field_empty())
+ return true;
+
+ // Don't attempt to rewrite if there is a declaration like 'int a, b;'.
+ SourceLocation LastTypeLoc;
+ for (const auto &Field : Decl->fields()) {
+ SourceLocation TypeLoc =
+ Field->getTypeSourceInfo()->getTypeLoc().getBeginLoc();
+ if (LastTypeLoc.isValid() && TypeLoc == LastTypeLoc)
+ return false;
+ LastTypeLoc = TypeLoc;
+ }
+
+ // Don't attempt to rewrite if a single macro expansion creates multiple
----------------
alexander-shaposhnikov wrote:
LastMacroLoc is not used after this check,
perhaps, it'd be good to factor out this logic into a helper function (lines 70-80)
https://github.com/llvm/llvm-project/pull/142149
More information about the cfe-commits
mailing list