Author: Jan Svoboda Date: 2021-04-06T09:24:42+02:00 New Revision: cc26943313def7a985f72eadc7499ac981daabc6
URL: https://github.com/llvm/llvm-project/commit/cc26943313def7a985f72eadc7499ac981daabc6 DIFF: https://github.com/llvm/llvm-project/commit/cc26943313def7a985f72eadc7499ac981daabc6.diff LOG: [clang][cli] Ensure plugin args are generated in deterministic order The '-plugin-arg' command-line arguments are not being generated in deterministic order. This patch changes the storage from `std::unordered_map` to `std::map` to enforce ordering. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D99879 Added: Modified: clang/include/clang/Frontend/FrontendOptions.h clang/unittests/Frontend/CompilerInvocationTest.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Frontend/FrontendOptions.h b/clang/include/clang/Frontend/FrontendOptions.h index 5c9a21813b62..d7f9039872e6 100644 --- a/clang/include/clang/Frontend/FrontendOptions.h +++ b/clang/include/clang/Frontend/FrontendOptions.h @@ -16,9 +16,9 @@ #include "clang/Serialization/ModuleFileExtension.h" #include "llvm/ADT/StringRef.h" #include <cassert> +#include <map> #include <memory> #include <string> -#include <unordered_map> #include <vector> namespace llvm { @@ -404,7 +404,7 @@ class FrontendOptions { std::string ActionName; /// Args to pass to the plugins - std::unordered_map<std::string,std::vector<std::string>> PluginArgs; + std::map<std::string, std::vector<std::string>> PluginArgs; /// The list of plugin actions to run in addition to the normal action. std::vector<std::string> AddPluginActions; diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp index b846e6ead28c..066d02b02fa9 100644 --- a/clang/unittests/Frontend/CompilerInvocationTest.cpp +++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp @@ -877,4 +877,15 @@ TEST_F(CommandLineTest, RoundTrip) { ShowIncludesDestination::Stdout); ASSERT_TRUE(Invocation.getDependencyOutputOpts().ShowHeaderIncludes); } + +TEST_F(CommandLineTest, PluginArgsRoundTripDeterminism) { + const char *Args[] = { + "-plugin-arg-blink-gc-plugin", "no-members-in-stack-allocated", + "-plugin-arg-find-bad-constructs", "checked-ptr-as-trivial-member", + "-plugin-arg-find-bad-constructs", "check-ipc", + // Enable round-trip to ensure '-plugin-arg' generation is deterministic. + "-round-trip-args"}; + + ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags)); +} } // anonymous namespace _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits