Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/lib/Serialization/ASTReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,10 @@ static bool checkTargetOptions(const TargetOptions &TargetOpts,
SmallVector<StringRef, 4> ReadFeatures(TargetOpts.FeaturesAsWritten.begin(),
TargetOpts.FeaturesAsWritten.end());
llvm::sort(ExistingFeatures);
ExistingFeatures.erase(llvm::unique(ExistingFeatures),
ExistingFeatures.end());
llvm::sort(ReadFeatures);
ReadFeatures.erase(llvm::unique(ReadFeatures), ReadFeatures.end());
Comment on lines 497 to +501

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer we unique these during AST writing, or even in the CompilerInvocation directly. That would also handle the case for dependency scanning.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #187624 (comment) for the reasoning I did it like this. I don't have strong feelings but wanted to do the minimal change here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess implicit in this was: I don't think we should dedup in a member called AsWritten

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to remove the AsWritten member entirely, perform this canonicalization during command-line parsing and switch to using Features everywhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the linked comment, that is an option but makes the error messages more verbose

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why? Do targets inject features enabled by default into TargetOptions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my (cursory) understanding is that e.g. +sse2 also implicitly +sse


// We compute the set difference in both directions explicitly so that we can
// diagnose the differences differently.
Expand Down
21 changes: 21 additions & 0 deletions clang/test/Modules/merge-target-features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
// RUN: -target-cpu i386 -target-feature +sse2 \
// RUN: Inputs/merge-target-features/module.modulemap
//
// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
// RUN: -iquote Inputs/merge-target-features \
// RUN: -fno-implicit-modules \
// RUN: -fmodule-map-file-home-is-cwd \
// RUN: -emit-module -fmodule-name=foo -o %t/foo-double.pcm \
// RUN: -triple i386-unknown-unknown \
// RUN: -target-cpu i386 -target-feature +sse2 -target-feature +sse2 \
// RUN: Inputs/merge-target-features/module.modulemap
//
// RUN: not %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
// RUN: -iquote Inputs/merge-target-features \
// RUN: -fno-implicit-modules \
Expand Down Expand Up @@ -60,6 +69,18 @@
// MISMATCH: error: precompiled file '{{.*}}foo.pcm' was compiled with the target feature '+sse2' but the current translation unit is not
// MISMATCH: error: current translation unit is compiled with the target feature '+cx16' but the precompiled file '{{.*}}foo.pcm' was not
// MISMATCH: error: {{.*}} configuration mismatch
//
// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
// RUN: -iquote Inputs/merge-target-features \
// RUN: -fno-implicit-modules \
// RUN: -fmodule-map-file-home-is-cwd \
// RUN: -fmodule-map-file=Inputs/merge-target-features/module.modulemap \
// RUN: -fmodule-file=%t/foo-double.pcm \
// RUN: -triple i386-unknown-unknown \
// RUN: -target-cpu i386 -target-feature +sse2 \
// RUN: -fsyntax-only merge-target-features.cpp 2>&1 \
// RUN: | FileCheck --allow-empty --check-prefix=DOUBLE %s
// DOUBLE-NOT: error:

#include "foo.h"

Expand Down