Skip to content

Commit 91ea044

Browse files
author
git apple-llvm automerger
committed
Merge commit '67ab3d0df520' from swift/release/5.3 into swift/master
2 parents 30833f0 + 67ab3d0 commit 91ea044

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10412,9 +10412,8 @@ class Sema final {
1041210412
bool Diagnose = true);
1041310413

1041410414
// DefaultLvalueConversion - performs lvalue-to-rvalue conversion on
10415-
// the operand. This is DefaultFunctionArrayLvalueConversion,
10416-
// except that it assumes the operand isn't of function or array
10417-
// type.
10415+
// the operand. This function is a no-op if the operand has a function type
10416+
// or an array type.
1041810417
ExprResult DefaultLvalueConversion(Expr *E);
1041910418

1042010419
// DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that

clang/lib/Sema/SemaExpr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ ExprResult Sema::DefaultLvalueConversion(Expr *E) {
569569
QualType T = E->getType();
570570
assert(!T.isNull() && "r-value conversion on typeless expression?");
571571

572+
// lvalue-to-rvalue conversion cannot be applied to function or array types.
573+
if (T->isFunctionType() || T->isArrayType())
574+
return E;
575+
572576
// We don't want to throw lvalue-to-rvalue casts on top of
573577
// expressions of certain types in C++.
574578
if (getLangOpts().CPlusPlus &&

clang/lib/Sema/SemaStmt.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,10 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S) {
367367
}
368368
}
369369

370-
if (E->isGLValue() && E->getType().isVolatileQualified()) {
370+
// Tell the user to assign it into a variable to force a volatile load if this
371+
// isn't an array.
372+
if (E->isGLValue() && E->getType().isVolatileQualified() &&
373+
!E->getType()->isArrayType()) {
371374
Diag(Loc, diag::warn_unused_volatile) << R1 << R2;
372375
return;
373376
}

clang/test/CXX/expr/p10-0x.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,12 @@ void f2(volatile int *x) {
4444
refcall();
4545
1 ? refcall() : *x;
4646
}
47+
48+
// CHECK: define void @_Z2f3v()
49+
// CHECK-NOT: load
50+
// CHECK-NOT: memcpy
51+
52+
void f3(void) {
53+
volatile char a[10];
54+
a;
55+
}

clang/test/SemaCXX/warn-unused-value-cxx11.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,13 @@ void j() {
4141
(void)noexcept(s.g() = 5); // Ok
4242
}
4343

44-
}
44+
}
45+
46+
namespace volatile_array {
47+
void test() {
48+
char a[10];
49+
volatile char b[10];
50+
a; // expected-warning-re {{expression result unused{{$}}}}
51+
b; // expected-warning-re {{expression result unused{{$}}}}
52+
}
53+
}

0 commit comments

Comments
 (0)