-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb][X86] Fix setting target features in ClangExpressionParser #82364
[lldb][X86] Fix setting target features in ClangExpressionParser #82364
Conversation
Currently, for x86 and x86_64 triples, "+sse" and "+sse2" are appended to `Features` vector of `TargetOptions` unconditionally. This vector is later reset in `TargetInfo::CreateTargetInfo` and filled using info from `FeaturesAsWritten` vector, so previous modifications of the `Features` vector have no effect. For x86_64 triple, we append "sse2" unconditionally in `X86TargetInfo::initFeatureMap`, so despite the `Features` vector reset, we still have the desired sse features enabled. The corresponding code in `X86TargetInfo::initFeatureMap` is marked as FIXME, so we should not probably rely on it and should set desired features properly in `ClangExpressionParser`. This patch changes the vector the features are appended to from `Features` to `FeaturesAsWritten`. It's not reset later and is used to compute resulting `Features` vector.
@llvm/pr-subscribers-lldb Author: Daniil Kovalev (kovdan01) ChangesCurrently, for x86 and x86_64 triples, "+sse" and "+sse2" are appended to This patch changes the vector the features are appended to from Full diff: https://github.com/llvm/llvm-project/pull/82364.diff 1 Files Affected:
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 574d661e2a215e..822d286cd6c3c4 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -445,8 +445,8 @@ ClangExpressionParser::ClangExpressionParser(
// Supported subsets of x86
if (target_machine == llvm::Triple::x86 ||
target_machine == llvm::Triple::x86_64) {
- m_compiler->getTargetOpts().Features.push_back("+sse");
- m_compiler->getTargetOpts().Features.push_back("+sse2");
+ m_compiler->getTargetOpts().FeaturesAsWritten.push_back("+sse");
+ m_compiler->getTargetOpts().FeaturesAsWritten.push_back("+sse2");
}
// Set the target CPU to generate code for. This will be empty for any CPU
|
Would this change be observable by a test? |
@adrian-prantl Theoretically, it should be: in Unfortunately, I'm not sure where and how this could be tested. I suppose the proper place for such a test is somewhere in lldb/unittests/Expression, but I don't see existing tests which check similar stuff. Please let me know if I miss something. @Michael137 would be glad to see your thoughts on this. |
I'll defer to @Michael137 but if he's okay with this, I'm fine with it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using FeaturesAsWritten
makes sense here, thanks! We really should change this logic to derive all the compiler options using the driver, but that's a bigger change for the future
Currently, for x86 and x86_64 triples, "+sse" and "+sse2" are appended to
Features
vector ofTargetOptions
unconditionally. This vector is later reset inTargetInfo::CreateTargetInfo
and filled using info fromFeaturesAsWritten
vector, so previous modifications of theFeatures
vector have no effect. For x86_64 triple, we append "sse2" unconditionally inX86TargetInfo::initFeatureMap
, so despite theFeatures
vector reset, we still have the desired sse features enabled. The corresponding code inX86TargetInfo::initFeatureMap
is marked as FIXME, so we should not probably rely on it and should set desired features properly inClangExpressionParser
.This patch changes the vector the features are appended to from
Features
toFeaturesAsWritten
. It's not reset later and is used to compute resultingFeatures
vector.