llvm.org GIT mirror llvm / 57c9c44
[RISCV] Fix uninitialized variable after call to evaluateConstantImm For llvm/test/MC/RISCV/rv64i-aliases-invalid.s, UBSan reports: lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:371:9: runtime error: load of value 3879186881, which is not a valid value for type 'RISCVMCExpr::VariantKind' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:371:9 in It turns out that evaluateConstantImm does not set `VK` and it remains unitialized when doing comparisons in `isImmXLenLI()`. Differential Revision: https://reviews.llvm.org/D65347 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367230 91177308-0d34-0410-b5e6-96231b3b80d8 Francis Visoiu Mistrih 1 year, 17 days ago
1 changed file(s) with 22 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
275275 // modifiers and isShiftedInt(Op).
276276 template bool isBareSimmNLsb0() const {
277277 int64_t Imm;
278 RISCVMCExpr::VariantKind VK;
278 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
279279 if (!isImm())
280280 return false;
281281 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
291291
292292 bool isBareSymbol() const {
293293 int64_t Imm;
294 RISCVMCExpr::VariantKind VK;
294 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
295295 // Must be of 'immediate' type but not a constant.
296296 if (!isImm() || evaluateConstantImm(getImm(), Imm, VK))
297297 return false;
301301
302302 bool isCallSymbol() const {
303303 int64_t Imm;
304 RISCVMCExpr::VariantKind VK;
304 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
305305 // Must be of 'immediate' type but not a constant.
306306 if (!isImm() || evaluateConstantImm(getImm(), Imm, VK))
307307 return false;
312312
313313 bool isTPRelAddSymbol() const {
314314 int64_t Imm;
315 RISCVMCExpr::VariantKind VK;
315 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
316316 // Must be of 'immediate' type but not a constant.
317317 if (!isImm() || evaluateConstantImm(getImm(), Imm, VK))
318318 return false;
363363
364364 bool isImmXLenLI() const {
365365 int64_t Imm;
366 RISCVMCExpr::VariantKind VK;
366 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
367367 if (!isImm())
368368 return false;
369369 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
377377
378378 bool isUImmLog2XLen() const {
379379 int64_t Imm;
380 RISCVMCExpr::VariantKind VK;
380 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
381381 if (!isImm())
382382 return false;
383383 if (!evaluateConstantImm(getImm(), Imm, VK) ||
388388
389389 bool isUImmLog2XLenNonZero() const {
390390 int64_t Imm;
391 RISCVMCExpr::VariantKind VK;
391 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
392392 if (!isImm())
393393 return false;
394394 if (!evaluateConstantImm(getImm(), Imm, VK) ||
401401
402402 bool isUImm5() const {
403403 int64_t Imm;
404 RISCVMCExpr::VariantKind VK;
404 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
405405 if (!isImm())
406406 return false;
407407 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
410410
411411 bool isUImm5NonZero() const {
412412 int64_t Imm;
413 RISCVMCExpr::VariantKind VK;
413 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
414414 if (!isImm())
415415 return false;
416416 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
421421 bool isSImm6() const {
422422 if (!isImm())
423423 return false;
424 RISCVMCExpr::VariantKind VK;
424 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
425425 int64_t Imm;
426426 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
427427 return IsConstantImm && isInt<6>(Imm) &&
431431 bool isSImm6NonZero() const {
432432 if (!isImm())
433433 return false;
434 RISCVMCExpr::VariantKind VK;
434 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
435435 int64_t Imm;
436436 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
437437 return IsConstantImm && isInt<6>(Imm) && (Imm != 0) &&
442442 if (!isImm())
443443 return false;
444444 int64_t Imm;
445 RISCVMCExpr::VariantKind VK;
445 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
446446 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
447447 return IsConstantImm && (Imm != 0) &&
448448 (isUInt<5>(Imm) || (Imm >= 0xfffe0 && Imm <= 0xfffff)) &&
453453 if (!isImm())
454454 return false;
455455 int64_t Imm;
456 RISCVMCExpr::VariantKind VK;
456 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
457457 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
458458 return IsConstantImm && isShiftedUInt<5, 2>(Imm) &&
459459 VK == RISCVMCExpr::VK_RISCV_None;
463463 if (!isImm())
464464 return false;
465465 int64_t Imm;
466 RISCVMCExpr::VariantKind VK;
466 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
467467 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
468468 return IsConstantImm && isShiftedUInt<6, 2>(Imm) &&
469469 VK == RISCVMCExpr::VK_RISCV_None;
473473 if (!isImm())
474474 return false;
475475 int64_t Imm;
476 RISCVMCExpr::VariantKind VK;
476 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
477477 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
478478 return IsConstantImm && isShiftedUInt<5, 3>(Imm) &&
479479 VK == RISCVMCExpr::VK_RISCV_None;
485485 if (!isImm())
486486 return false;
487487 int64_t Imm;
488 RISCVMCExpr::VariantKind VK;
488 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
489489 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
490490 return IsConstantImm && isShiftedUInt<6, 3>(Imm) &&
491491 VK == RISCVMCExpr::VK_RISCV_None;
495495 if (!isImm())
496496 return false;
497497 int64_t Imm;
498 RISCVMCExpr::VariantKind VK;
498 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
499499 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
500500 return IsConstantImm && isShiftedUInt<8, 2>(Imm) && (Imm != 0) &&
501501 VK == RISCVMCExpr::VK_RISCV_None;
502502 }
503503
504504 bool isSImm12() const {
505 RISCVMCExpr::VariantKind VK;
505 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
506506 int64_t Imm;
507507 bool IsValid;
508508 if (!isImm())
526526 if (!isImm())
527527 return false;
528528 int64_t Imm;
529 RISCVMCExpr::VariantKind VK;
529 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
530530 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
531531 return IsConstantImm && (Imm != 0) && isShiftedInt<6, 4>(Imm) &&
532532 VK == RISCVMCExpr::VK_RISCV_None;
533533 }
534534
535535 bool isUImm20LUI() const {
536 RISCVMCExpr::VariantKind VK;
536 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
537537 int64_t Imm;
538538 bool IsValid;
539539 if (!isImm())
551551 }
552552
553553 bool isUImm20AUIPC() const {
554 RISCVMCExpr::VariantKind VK;
554 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
555555 int64_t Imm;
556556 bool IsValid;
557557 if (!isImm())
663663 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
664664 assert(Expr && "Expr shouldn't be null!");
665665 int64_t Imm = 0;
666 RISCVMCExpr::VariantKind VK;
666 RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
667667 bool IsConstant = evaluateConstantImm(Expr, Imm, VK);
668668
669669 if (IsConstant)