Skip to content

Commit 4ec3661

Browse files
committed
Merge from 'master' to 'sycl-web' (intel#16)
CONFLICT (content): Merge conflict in clang/lib/CodeGen/CGExpr.cpp
2 parents a1fdff2 + 8a5b7c3 commit 4ec3661

File tree

82 files changed

+1689
-924
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1689
-924
lines changed

clang-tools-extra/clangd/Selection.cpp

Lines changed: 285 additions & 135 deletions
Large diffs are not rendered by default.

clang-tools-extra/clangd/Selection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class SelectionTree {
7676
unsigned Start, unsigned End);
7777

7878
// Describes to what extent an AST node is covered by the selection.
79-
enum Selection {
79+
enum Selection : unsigned char {
8080
// The AST node owns no characters covered by the selection.
8181
// Note that characters owned by children don't count:
8282
// if (x == 0) scream();

clang-tools-extra/clangd/unittests/SelectionTests.cpp

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ TEST(SelectionTest, CommonAncestor) {
134134
)cpp",
135135
"IfStmt",
136136
},
137+
{
138+
R"cpp(
139+
int x(int);
140+
#define M(foo) x(foo)
141+
int a = 42;
142+
int b = M([[^a]]);
143+
)cpp",
144+
"DeclRefExpr",
145+
},
137146
{
138147
R"cpp(
139148
void foo();
@@ -378,6 +387,7 @@ TEST(SelectionTest, Selected) {
378387
$C[[return]];
379388
}]] else [[{^
380389
}]]]]
390+
char z;
381391
}
382392
)cpp",
383393
R"cpp(
@@ -386,10 +396,10 @@ TEST(SelectionTest, Selected) {
386396
void foo(^$C[[unique_ptr<$C[[unique_ptr<$C[[int]]>]]>]]^ a) {}
387397
)cpp",
388398
R"cpp(int a = [[5 >^> 1]];)cpp",
389-
R"cpp([[
399+
R"cpp(
390400
#define ECHO(X) X
391-
ECHO(EC^HO([[$C[[int]]) EC^HO(a]]));
392-
]])cpp",
401+
ECHO(EC^HO($C[[int]]) EC^HO(a));
402+
)cpp",
393403
R"cpp( $C[[^$C[[int]] a^]]; )cpp",
394404
R"cpp( $C[[^$C[[int]] a = $C[[5]]^]]; )cpp",
395405
};
@@ -428,6 +438,56 @@ TEST(SelectionTest, PathologicalPreprocessor) {
428438
EXPECT_EQ("WhileStmt", T.commonAncestor()->Parent->kind());
429439
}
430440

441+
TEST(SelectionTest, IncludedFile) {
442+
const char *Case = R"cpp(
443+
void test() {
444+
#include "Exp^and.inc"
445+
break;
446+
}
447+
)cpp";
448+
Annotations Test(Case);
449+
auto TU = TestTU::withCode(Test.code());
450+
TU.AdditionalFiles["Expand.inc"] = "while(1)\n";
451+
auto AST = TU.build();
452+
auto T = makeSelectionTree(Case, AST);
453+
454+
EXPECT_EQ("WhileStmt", T.commonAncestor()->kind());
455+
}
456+
457+
TEST(SelectionTest, MacroArgExpansion) {
458+
// If a macro arg is expanded several times, we consider them all selected.
459+
const char *Case = R"cpp(
460+
int mul(int, int);
461+
#define SQUARE(X) mul(X, X);
462+
int nine = SQUARE(^3);
463+
)cpp";
464+
Annotations Test(Case);
465+
auto AST = TestTU::withCode(Test.code()).build();
466+
auto T = makeSelectionTree(Case, AST);
467+
// Unfortunately, this makes the common ancestor the CallExpr...
468+
// FIXME: hack around this by picking one?
469+
EXPECT_EQ("CallExpr", T.commonAncestor()->kind());
470+
EXPECT_FALSE(T.commonAncestor()->Selected);
471+
EXPECT_EQ(2u, T.commonAncestor()->Children.size());
472+
for (const auto* N : T.commonAncestor()->Children) {
473+
EXPECT_EQ("IntegerLiteral", N->kind());
474+
EXPECT_TRUE(N->Selected);
475+
}
476+
477+
// Verify that the common assert() macro doesn't suffer from this.
478+
// (This is because we don't associate the stringified token with the arg).
479+
Case = R"cpp(
480+
void die(const char*);
481+
#define assert(x) (x ? (void)0 : die(#x)
482+
void foo() { assert(^42); }
483+
)cpp";
484+
Test = Annotations(Case);
485+
AST = TestTU::withCode(Test.code()).build();
486+
T = makeSelectionTree(Case, AST);
487+
488+
EXPECT_EQ("IntegerLiteral", T.commonAncestor()->kind());
489+
}
490+
431491
TEST(SelectionTest, Implicit) {
432492
const char* Test = R"cpp(
433493
struct S { S(const char*); };

clang-tools-extra/clangd/unittests/TweakTests.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ TEST_F(ExtractVariableTest, Test) {
269269
EXPECT_UNAVAILABLE(UnavailableCases);
270270

271271
// vector of pairs of input and output strings
272-
const std::vector<std::pair<llvm::StringLiteral, llvm::StringLiteral>>
272+
const std::vector<std::pair<std::string, std::string>>
273273
InputOutputs = {
274274
// extraction from variable declaration/assignment
275275
{R"cpp(void varDecl() {
@@ -321,17 +321,10 @@ TEST_F(ExtractVariableTest, Test) {
321321
if(1)
322322
LOOP(5 + [[3]])
323323
})cpp",
324-
/*FIXME: It should be extracted like this. SelectionTree needs to be
325-
* fixed for macros.
326324
R"cpp(#define LOOP(x) while (1) {a = x;}
327-
void f(int a) {
328-
auto dummy = 3; if(1)
329-
LOOP(5 + dummy)
330-
})cpp"},*/
331-
R"cpp(#define LOOP(x) while (1) {a = x;}
332325
void f(int a) {
333-
auto dummy = LOOP(5 + 3); if(1)
334-
dummy
326+
auto dummy = 3; if(1)
327+
LOOP(5 + dummy)
335328
})cpp"},
336329
{R"cpp(#define LOOP(x) do {x;} while(1);
337330
void f(int a) {
@@ -644,13 +637,18 @@ void f(const int c) {
644637
)cpp";
645638
EXPECT_EQ(apply(TemplateFailInput), "unavailable");
646639

647-
// FIXME: This should be extractable after selectionTree works correctly for
648-
// macros (currently it doesn't select anything for the following case)
649-
std::string MacroFailInput = R"cpp(
640+
std::string MacroInput = R"cpp(
650641
#define F(BODY) void f() { BODY }
651642
F ([[int x = 0;]])
652643
)cpp";
653-
EXPECT_EQ(apply(MacroFailInput), "unavailable");
644+
std::string MacroOutput = R"cpp(
645+
#define F(BODY) void f() { BODY }
646+
void extracted() {
647+
int x = 0;
648+
}
649+
F (extracted();)
650+
)cpp";
651+
EXPECT_EQ(apply(MacroInput), MacroOutput);
654652

655653
// Shouldn't crash.
656654
EXPECT_EQ(apply("void f([[int a]]);"), "unavailable");

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,9 @@ the configuration (without a prefix: ``Auto``).
23282328
true: false:
23292329
x = ( int32 )y vs. x = (int32)y
23302330

2331+
**SpacesInConditionalStatement** (``bool``)
2332+
If ``true``, spaces will be inserted around if/for/while (and similar) conditions.
2333+
23312334
**SpacesInContainerLiterals** (``bool``)
23322335
If ``true``, spaces are inserted inside container literals (e.g.
23332336
ObjC and Javascript array and dict literals).

clang/include/clang/AST/JSONNodeDumper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class JSONNodeDumper
126126
ASTNameGenerator ASTNameGen;
127127
PrintingPolicy PrintPolicy;
128128
const comments::CommandTraits *Traits;
129-
StringRef LastLocFilename;
129+
StringRef LastLocFilename, LastLocPresumedFilename;
130130
unsigned LastLocLine, LastLocPresumedLine;
131131

132132
using InnerAttrVisitor = ConstAttrVisitor<JSONNodeDumper>;

clang/include/clang/Format/Format.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,15 @@ struct FormatStyle {
19531953
/// \endcode
19541954
bool SpacesInAngles;
19551955

1956+
/// If ``true``, spaces will be inserted around if/for/switch/while
1957+
/// conditions.
1958+
/// \code
1959+
/// true: false:
1960+
/// if ( a ) { ... } vs. if (a) { ... }
1961+
/// while ( i < 5 ) { ... } while (i < 5) { ... }
1962+
/// \endcode
1963+
bool SpacesInConditionalStatement;
1964+
19561965
/// If ``true``, spaces are inserted inside container literals (e.g.
19571966
/// ObjC and Javascript array and dict literals).
19581967
/// \code{.js}
@@ -2155,6 +2164,7 @@ struct FormatStyle {
21552164
SpaceInEmptyParentheses == R.SpaceInEmptyParentheses &&
21562165
SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
21572166
SpacesInAngles == R.SpacesInAngles &&
2167+
SpacesInConditionalStatement == R.SpacesInConditionalStatement &&
21582168
SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
21592169
SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses &&
21602170
SpacesInParentheses == R.SpacesInParentheses &&

clang/include/clang/Tooling/Syntax/Tokens.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,18 @@ class TokenBuffer {
175175
/// All tokens produced by the preprocessor after all macro replacements,
176176
/// directives, etc. Source locations found in the clang AST will always
177177
/// point to one of these tokens.
178+
/// Tokens are in TU order (per SourceManager::isBeforeInTranslationUnit()).
178179
/// FIXME: figure out how to handle token splitting, e.g. '>>' can be split
179180
/// into two '>' tokens by the parser. However, TokenBuffer currently
180181
/// keeps it as a single '>>' token.
181182
llvm::ArrayRef<syntax::Token> expandedTokens() const {
182183
return ExpandedTokens;
183184
}
184185

186+
/// Returns the subrange of expandedTokens() corresponding to the closed
187+
/// token range R.
188+
llvm::ArrayRef<syntax::Token> expandedTokens(SourceRange R) const;
189+
185190
/// Find the subrange of spelled tokens that produced the corresponding \p
186191
/// Expanded tokens.
187192
///

clang/lib/AST/JSONNodeDumper.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,22 +202,29 @@ void JSONNodeDumper::writeBareSourceLocation(SourceLocation Loc,
202202
PresumedLoc Presumed = SM.getPresumedLoc(Loc);
203203
unsigned ActualLine = IsSpelling ? SM.getSpellingLineNumber(Loc)
204204
: SM.getExpansionLineNumber(Loc);
205+
StringRef ActualFile = SM.getBufferName(Loc);
206+
205207
if (Presumed.isValid()) {
206208
JOS.attribute("offset", SM.getDecomposedLoc(Loc).second);
207-
if (LastLocFilename != Presumed.getFilename()) {
208-
JOS.attribute("file", Presumed.getFilename());
209+
if (LastLocFilename != ActualFile) {
210+
JOS.attribute("file", ActualFile);
209211
JOS.attribute("line", ActualLine);
210212
} else if (LastLocLine != ActualLine)
211213
JOS.attribute("line", ActualLine);
212214

215+
StringRef PresumedFile = Presumed.getFilename();
216+
if (PresumedFile != ActualFile && LastLocPresumedFilename != PresumedFile)
217+
JOS.attribute("presumedFile", PresumedFile);
218+
213219
unsigned PresumedLine = Presumed.getLine();
214220
if (ActualLine != PresumedLine && LastLocPresumedLine != PresumedLine)
215221
JOS.attribute("presumedLine", PresumedLine);
216222

217223
JOS.attribute("col", Presumed.getColumn());
218224
JOS.attribute("tokLen",
219225
Lexer::MeasureTokenLength(Loc, SM, Ctx.getLangOpts()));
220-
LastLocFilename = Presumed.getFilename();
226+
LastLocFilename = ActualFile;
227+
LastLocPresumedFilename = PresumedFile;
221228
LastLocPresumedLine = PresumedLine;
222229
LastLocLine = ActualLine;
223230

clang/lib/CodeGen/CGAtomic.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ namespace {
139139
const LValue &getAtomicLValue() const { return LVal; }
140140
llvm::Value *getAtomicPointer() const {
141141
if (LVal.isSimple())
142-
return LVal.getPointer();
142+
return LVal.getPointer(CGF);
143143
else if (LVal.isBitField())
144144
return LVal.getBitFieldPointer();
145145
else if (LVal.isVectorElt())
@@ -343,7 +343,7 @@ bool AtomicInfo::requiresMemSetZero(llvm::Type *type) const {
343343

344344
bool AtomicInfo::emitMemSetZeroIfNecessary() const {
345345
assert(LVal.isSimple());
346-
llvm::Value *addr = LVal.getPointer();
346+
llvm::Value *addr = LVal.getPointer(CGF);
347347
if (!requiresMemSetZero(addr->getType()->getPointerElementType()))
348348
return false;
349349

@@ -1628,7 +1628,7 @@ Address AtomicInfo::materializeRValue(RValue rvalue) const {
16281628
LValue TempLV = CGF.MakeAddrLValue(CreateTempAlloca(), getAtomicType());
16291629
AtomicInfo Atomics(CGF, TempLV);
16301630
Atomics.emitCopyIntoMemory(rvalue);
1631-
return TempLV.getAddress();
1631+
return TempLV.getAddress(CGF);
16321632
}
16331633

16341634
llvm::Value *AtomicInfo::convertRValueToInt(RValue RVal) const {
@@ -1975,8 +1975,8 @@ void CodeGenFunction::EmitAtomicStore(RValue rvalue, LValue dest,
19751975
// If this is an aggregate r-value, it should agree in type except
19761976
// maybe for address-space qualification.
19771977
assert(!rvalue.isAggregate() ||
1978-
rvalue.getAggregateAddress().getElementType()
1979-
== dest.getAddress().getElementType());
1978+
rvalue.getAggregateAddress().getElementType() ==
1979+
dest.getAddress(*this).getElementType());
19801980

19811981
AtomicInfo atomics(*this, dest);
19821982
LValue LVal = atomics.getAtomicLValue();
@@ -2043,10 +2043,10 @@ std::pair<RValue, llvm::Value *> CodeGenFunction::EmitAtomicCompareExchange(
20432043
// maybe for address-space qualification.
20442044
assert(!Expected.isAggregate() ||
20452045
Expected.getAggregateAddress().getElementType() ==
2046-
Obj.getAddress().getElementType());
2046+
Obj.getAddress(*this).getElementType());
20472047
assert(!Desired.isAggregate() ||
20482048
Desired.getAggregateAddress().getElementType() ==
2049-
Obj.getAddress().getElementType());
2049+
Obj.getAddress(*this).getElementType());
20502050
AtomicInfo Atomics(*this, Obj);
20512051

20522052
return Atomics.EmitAtomicCompareExchange(Expected, Desired, Success, Failure,
@@ -2086,13 +2086,11 @@ void CodeGenFunction::EmitAtomicInit(Expr *init, LValue dest) {
20862086
}
20872087

20882088
// Evaluate the expression directly into the destination.
2089-
AggValueSlot slot = AggValueSlot::forLValue(dest,
2090-
AggValueSlot::IsNotDestructed,
2091-
AggValueSlot::DoesNotNeedGCBarriers,
2092-
AggValueSlot::IsNotAliased,
2093-
AggValueSlot::DoesNotOverlap,
2094-
Zeroed ? AggValueSlot::IsZeroed :
2095-
AggValueSlot::IsNotZeroed);
2089+
AggValueSlot slot = AggValueSlot::forLValue(
2090+
dest, *this, AggValueSlot::IsNotDestructed,
2091+
AggValueSlot::DoesNotNeedGCBarriers, AggValueSlot::IsNotAliased,
2092+
AggValueSlot::DoesNotOverlap,
2093+
Zeroed ? AggValueSlot::IsZeroed : AggValueSlot::IsNotZeroed);
20962094

20972095
EmitAggExpr(init, slot);
20982096
return;

0 commit comments

Comments
 (0)