File tree Expand file tree Collapse file tree 5 files changed +29
-5
lines changed Expand file tree Collapse file tree 5 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -10412,9 +10412,8 @@ class Sema final {
10412
10412
bool Diagnose = true);
10413
10413
10414
10414
// 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.
10418
10417
ExprResult DefaultLvalueConversion(Expr *E);
10419
10418
10420
10419
// DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
Original file line number Diff line number Diff line change @@ -569,6 +569,10 @@ ExprResult Sema::DefaultLvalueConversion(Expr *E) {
569
569
QualType T = E->getType();
570
570
assert(!T.isNull() && "r-value conversion on typeless expression?");
571
571
572
+ // lvalue-to-rvalue conversion cannot be applied to function or array types.
573
+ if (T->isFunctionType() || T->isArrayType())
574
+ return E;
575
+
572
576
// We don't want to throw lvalue-to-rvalue casts on top of
573
577
// expressions of certain types in C++.
574
578
if (getLangOpts().CPlusPlus &&
Original file line number Diff line number Diff line change @@ -367,7 +367,10 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S) {
367
367
}
368
368
}
369
369
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 ()) {
371
374
Diag (Loc, diag::warn_unused_volatile) << R1 << R2;
372
375
return ;
373
376
}
Original file line number Diff line number Diff line change @@ -44,3 +44,12 @@ void f2(volatile int *x) {
44
44
refcall ();
45
45
1 ? refcall () : *x;
46
46
}
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
+ }
Original file line number Diff line number Diff line change @@ -41,4 +41,13 @@ void j() {
41
41
(void )noexcept (s.g () = 5 ); // Ok
42
42
}
43
43
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
+ }
You can’t perform that action at this time.
0 commit comments