Skip to content

Commit 0ce86c4

Browse files
committed
Compound assign
1 parent b6274d2 commit 0ce86c4

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,7 @@ class ScalarExprEmitter
898898
return result; \
899899
} \
900900
Value *VisitBin##OP##Assign(const CompoundAssignOperator *E) { \
901+
ApplyAtomGroup Grp(CGF.getDebugInfo()); \
901902
return EmitCompoundAssign(E, &ScalarExprEmitter::Emit##OP); \
902903
}
903904
HANDLEBINOP(Mul)
@@ -5850,6 +5851,7 @@ LValue CodeGenFunction::EmitObjCIsaExpr(const ObjCIsaExpr *E) {
58505851

58515852
LValue CodeGenFunction::EmitCompoundAssignmentLValue(
58525853
const CompoundAssignOperator *E) {
5854+
ApplyAtomGroup Grp(getDebugInfo());
58535855
ScalarExprEmitter Scalar(*this);
58545856
Value *Result = nullptr;
58555857
switch (E->getOpcode()) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %clang -gkey-instructions -x c++ %s -gmlt -gcolumn-info -S -emit-llvm -o - -Wno-unused-variable \
2+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
3+
4+
// RUN: %clang -gkey-instructions -x c %s -gmlt -gcolumn-info -S -emit-llvm -o - -Wno-unused-variable \
5+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
6+
7+
unsigned long long g;
8+
void fun() {
9+
// CHECK: store i64 0, ptr @g{{.*}}, !dbg [[G1R1:!.*]]
10+
g = 0;
11+
12+
// Treat the two assignments as two atoms.
13+
//
14+
// FIXME: Because of the atomGroup implementation the load can only be
15+
// associated with one of the two stores, despite being a good backup
16+
// loction for both.
17+
// CHECK-NEXT: %0 = load i64, ptr @g{{.*}}, !dbg [[G2R2:!.*]]
18+
// CHECK-NEXT: store i64 %0, ptr @g{{.*}}, !dbg [[G3R1:!.*]]
19+
// CHECK-NEXT: store i64 %0, ptr @g{{.*}}, !dbg [[G2R1:!.*]]
20+
g = g = g;
21+
22+
// Compound assignment.
23+
// CHECK: %1 = load i64, ptr @g
24+
// CHECK: %add = add i64 %1, 50, !dbg [[G4R2:!.*]]
25+
// CHECK: store i64 %add, ptr @g{{.*}}, !dbg [[G4R1:!.*]]
26+
g += 50;
27+
}
28+
29+
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
30+
// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
31+
// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
32+
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
33+
// CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2)
34+
// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)

clang/test/DebugInfo/KeyInstructions/assign.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: %clang -gkey-instructions %s -gmlt -gcolumn-info -S -emit-llvm -o - -Wno-unused-variable \
1+
// RUN: %clang -gkey-instructions -x c++ %s -gmlt -gcolumn-info -S -emit-llvm -o - -Wno-unused-variable \
2+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
3+
4+
// RUN: %clang -gkey-instructions -x c %s -gmlt -gcolumn-info -S -emit-llvm -o - -Wno-unused-variable \
25
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
36

47
unsigned long long g;
@@ -15,9 +18,17 @@ void fun() {
1518
// CHECK-NEXT: store i64 %0, ptr @g{{.*}}, !dbg [[G3R1:!.*]]
1619
// CHECK-NEXT: store i64 %0, ptr @g{{.*}}, !dbg [[G2R1:!.*]]
1720
g = g = g;
21+
22+
// Compound assignment.
23+
// CHECK: %1 = load i64, ptr @g
24+
// CHECK: %add = add i64 %1, 50, !dbg [[G4R2:!.*]]
25+
// CHECK: store i64 %add, ptr @g{{.*}}, !dbg [[G4R1:!.*]]
26+
g += 50;
1827
}
1928

2029
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
2130
// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
2231
// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
2332
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
33+
// CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2)
34+
// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)

0 commit comments

Comments
 (0)